2

I have written wlst script to achieve the below tasks recursively

  • Stopping the applications
  • Undeploying the applications
  • Deploying the appliactions

When ever i execute the script, Either undeploy or Deploy happens only for 1 application. For other applications it fails with below error message.Can you please help me to fix the issue?

File "<iostream>", line 1116, in domainConfig
  File "<iostream>", line 1848, in raiseWLSTException
WLSTException: Error cding to the MBean
<Feb 20, 2014 11:28:44 AM IST> <Warning> <JNDI> <BEA-050001> <WLContext.close() was called in a different thread than the one in which it was created.>

WLST Script what i have written

import sys
import os
import getopt
#========================
#Usage Section
#========================
def usage():
    print "Usage:"
    print "java weblogic.WLST manageApplication.py -u username -p password -a adminUrl [<hostname>:<port>] -t deploymentTarget\n"
    print "java weblogic.WLST manageApplication.py -u weblogic -p weblogic1 -a t3://localhost:7001 -t AdminServer\n"
    sys.exit(2)
#========================
#Connect To Domain
#========================
def connectToDomain():
    try:
        connect('weblogic','weblogic1','t3://localhost:7001')
        print 'Successfully connected to the domain\n'
    except:
        print 'The domain is unreacheable. Please try again\n'
        exit()
#========================
#Application undeployment Section
#========================

def undeployApplication():
    cd ('AppDeployments')
    myapps=cmo.getAppDeployments()
    for appName in myapps:
        domainConfig()
        cd ('/AppDeployments/'+appName.getName()+'/Targets')
        mytargets = ls(returnMap='true')
        domainRuntime()
        cd('AppRuntimeStateRuntime')
        cd('AppRuntimeStateRuntime')
        for targetinst in mytargets:
            curstate4=cmo.getCurrentState(appName.getName(),targetinst)
            print '-----------', curstate4, '-----------', appName.getName()
            deploymentName=appName.getName()
            deploymentTarget=targetinst
            print deploymentName
            print deploymentTarget
            stopApplication(deploymentName, targets=deploymentTarget)
            undeploy(deploymentName, targets=deploymentTarget)

#========================
#Input Values Validation Section
#========================

if __name__=='__main__' or __name__== 'main':
    try:
        opts, args = getopt.getopt(sys.argv[1:], "u:p:a:t:", ["username=", "password=", "adminUrl=", "deploymentTarget="])
    except getopt.GetoptError, err:
            print str(err)

username = ''
password = ''
adminUrl = ''
deploymentTarget = ''

for opt, arg in opts:
    if opt == "-u":
        username = arg
    elif opt == "-p":
        password = arg
    elif opt == "-a":
        adminUrl = arg
    elif opt == "-t":
        deploymentTarget = arg

if username == "":
    print "Missing \"-u username\" parameter.\n"
    usage()
elif password == "":
    print "Missing \"-p password\" parameter.\n"
    usage()
elif adminUrl == "":
    print "Missing \"-a adminUrl\" parameter.\n"
    usage()
elif deploymentTarget == "":
    print "Missing \"-c deploymentTarget\" parameter.\n"
    usage()
#========================
#Main Control Block For Operations
#========================

def deployMain():
    for line in open("c:\\wlst\\applicationsList.txt"):
        temp_line = line
        fields = temp_line.strip().split(",")
        print(fields[0]+" "+fields[1])
        deploymentName = fields[0]
        deploymentFile = fields[1]
        print deploymentName+" "+deploymentFile+" "+deploymentTarget+"/n"
        deploy(deploymentName,deploymentFile,targets=deploymentTarget)        
#==================
#main block
#=====================    
connectToDomain()
undeployApplication()
deployMain()
disconnect()
user1041177
  • 275
  • 1
  • 6
  • 17
  • Could you put the entire content under undeployApplication() method under a try except block. except block should have: dumpStack() traceback.print_exc(file=sys.stdout) print sys.exc_info() This will from which "cd" the exception is coming. – Mani Feb 21 '14 at 06:47
  • Have you seen this link http://wlstbyexamples.blogspot.in/2010/09/deployment-script-using-wlst.html You could handle the exception... at stopApplication(deploymentName, targets=deploymentTarget) and also at undeploy(deploymentName, targets=deploymentTarget) – PavanDevarakonda Feb 21 '14 at 07:45
  • @Mani - I added the entire undeployApplication() script in try except block. I didnt get much error info from that. First application is stopped and undeployed. For 2nd application its giving the error [ File "", line 1848, in raiseWLSTException WLSTException: Error cding to the MBean (, , ) – user1041177 Feb 21 '14 at 11:19

1 Answers1

1

WLContext.close() is probably not the real problem (it's even in some of the Oracle examples). What error messages do you see when deploy and undeploy are being called?

You should see something like:

Deploying application from /tmp/something/myapp.ear
Current Status of your Deployment:
Deployment command type: deploy
Deployment State       : completed
Deployment Message     : no message

I also see that you never call activate() at the very end of your script so that could be the issue if you are running in production mode.

Try adding the following at the very end of your script after deployMain():

save()
status = activate(300000, "block='true'")
status.getStatusByServer()
status.getDetails()

UPDATE:

The activation error occurs because you have not called edit() before the undeploy:

# Get edit/lock for upcoming changes
edit()
startEdit(120000, 120000, 'false')
undeployApplication()

I think you will be better off greatly simplifying your undeploy. You don't need to go through the complexity of determining targets because you are already undeploying from ALL targets. Try this instead and see if you can make progress:

cd ('AppDeployments')
myapps=cmo.getAppDeployments()
for appName in myapps:
   try:
      appPath = "/AppDeployments/" + appName.getName()
      cd(appPath)
      print "Stopping deployment " + appName.getName()
      stopApplication(appName.getName())
      print "Undeploying " + appName.getName()
      undeploy(appName.getName(), timeout=60000)
   except Exception , e:
      print "Deployment " + appName.getName() + " removal failed."
Display Name is missing
  • 6,197
  • 3
  • 34
  • 46
  • when i added the above script at the end of deployMain() method. I am geting the below error [WLSTException: Error occured while performing activate : Cannot call Edit functions when you are not in the Edit tree.] iam using weblogic 11g(wls1033_oepe111150_win32.exe). – user1041177 Feb 21 '14 at 09:36
  • I have 2 ear applications needs to be deployed. If one application is in active state and other in failed state , when iam trying to undeploy, iam getting the error [WLST Exception:Error Cding to Mbean]. Undeploy stops there and script execution stops. If i run the script again for 2nd time, again undeploy happens for the 2nd time. – user1041177 Feb 21 '14 at 09:37
  • My requirement is to undeploy the 2 EAR applications in what ever the state(active, failed, prepared,new) present in weblogic and deploy the 2 ear recursively. I am adding the ear to be deployed in text file. Please help to achieve the same – user1041177 Feb 21 '14 at 09:40
  • Updated the answer - see if making your undeploy simpler helps. – Display Name is missing Feb 21 '14 at 16:39
  • I tried your undeploy script, appPath = "/AppDeployments/" + appName giving an error as [TypeError: cannot concatenate 'str' and 'javainstance' objects] . Am i missing some thing here? I copied your undeploy script as is – user1041177 Feb 21 '14 at 19:57
  • 2
    @user1041177: In the above answer, I think you have to replace appName with appName.getName() except in that "for" statement. – Mani Feb 24 '14 at 05:07
  • @better_use_mkstemp - Thank You. Stop and Undeploy is happening fine now – user1041177 Feb 24 '14 at 08:47