3

I am trying to create a simple python script that deploys my EAR file to the AdminServer of Weblogic. I have searched the internet and the documentation provided by Oracle, but I cannot find a way to determine if the application has been previously deployed. I would like my script to check if it has been, and if so, issue a redeploy command. If not, issue a deploy command.

I have tried to modify example scripts I've found, and although they've worked, they are not behaving as intended. One of the things I was trying to do was check (using the cd command) if my EAR was in the deployments folder of WebLogic and if it was, issue the redeploy. If not, it should throw an Exception, where I would issue the deploy. However, an Exception is thrown everytime when I issue the cd command in my script:

try:
    print 'Checking for the existence of the ' + applicationName + ' application.....'
    cd('C:\\Oracle\\Middleware\\user_projects\\domains\\base_domain\\config\\deployments\\MyTestEAR.ear\\')
    print 'Redeploying....'
    #Commands to redeploy....

except WLSTException:
    #Commands to deploy

I'm running this script on Windows using execfile("C:\MyTestDeployer.py") command after setting my environment variables using the WLST Scripting Tool. Any ideas? I've also tried to use a different path in my cd command, but to no avail. Any ideas?

JPM
  • 1,482
  • 5
  • 18
  • 25

3 Answers3

3

It works for me:

print 'stopping and undeploying ...'

try:
    stopApplication('WebApplication')
    undeploy('WebApplication')
    print 'Redeploying...'

except Exception:
    print 'Deploy...'

deploy('WebApplication', '/home/saeed/project/test/WebApplication/dist/WebApplication.war')
startApplication('WebApplication2')
Saeed Zarinfam
  • 9,818
  • 7
  • 59
  • 72
2

I've done something like that in the past, but with a different approach...

I've used the weblogic.Deployer interface with the -listapps option to list the apps/libraries deployed to the domain, which I would then compare to the the display-name element of application.xml generated in the archive

The problem I've found using plain file-names, in my case, was that archives came with the date in which they were generated. Which would lead to a always false comparison.

Using the display-name, I've standardized the app name that would be deployed, and later on compared to a new archive to be redeployed.

vhnd
  • 51
  • 5
  • Hi vhnd. Can you elaborate some more? I am not sure what you mean exactly. – JPM Sep 28 '11 at 01:41
  • on my case, I've used just bash... weblogic.Deployer interface saving outputs on plain files for later greping, and unzip commands for checking the application.xml file inside the .ear. The same script would do this for a number of different domains, so I would just connect to a given domain, check deployed apps and then would check if what I had to deploy was there or not. I was just saying that I started to check for something that wouldn't change regardless of the filename of an archive for the same app. Sorry, not sure where exactly you want me to be more specific. – vhnd Sep 28 '11 at 15:19
0

Use the command listApplications() in Online mode to list all applications that are currently deployed in the WebLogic domain.

In the event of an error, the command returns a WLSTException.

Example :

wls:/mydomain/serverConfig> listApplications() 
SamplesSearchWebApp
asyncServletEar
jspSimpleTagEar
ejb30
webservicesJwsSimpleEar
ejb20BeanMgedEar
xmlBeanEar
extServletAnnotationsEar
examplesWebApp
apache_xbean.jar
mainWebApp
jdbcRowSetsEar

Source : link

AbD_Riz
  • 415
  • 5
  • 7