Search This Blog

Monday, March 22, 2010

Side by Side Deployment with WLST



One of my online buddy requested me Python script help for developing Side by Side(SBS) deployment using WLST.

Automate Python Script for Side By Side deployment.

The project is in developing stage, the client need deploying the same applications with different versions must be available for development and testing teams, an automated handy WLST script is requested to develop by buddy WLA.
Add caption

To do this interesting  task, the plan for execution is prepared as following while doing the deployment criteria:
1. If the application is New and the version is new i.e no other version is in the ACTIVE state with the given appName, the script will deploy the application
2. If one of the version of given application is in ACTIVE state visible in the console, then the developer is try to deploy the next version, the script should do DeActivate the old version and deploy the new version.
3. Now already have two versions deployed on the domain one is : ACTIVE state and other is in RETIERED State then undeploy the REITRED versioned application with a timeout interval or deploy the new version so that it will make current ACTIVE application to RETIERED and new deployment to ACTIVE.

Sample Video demonstration from Oracle Weblogic

For implementing the above logic in chronological way. The real challenge lies in the ISSUE with iterations. it was controlled by 'break' statement usually that we do in any C program. And I have used here a flag variable 'appFlags' to indicate the status of the Application status, like that we are able to maintained two version max in the console of the same app.

-->

import sys
#======================================================= 
# Function for fresh plain deployment
#======================================================= 
def newDeploy(appName,ver):
    print 'Deploying .........'
    deploy(appName,'/path/applications/'+appName+'/'+ver , targets='AdminServer')
    startApplication(appName)

#======================================================= 
# Function for finding the  Application Status
#=======================================================  
def appstatus(appName, serverName):
    cd('domainRuntime:/AppRuntimeStateRuntime/AppRuntimeStateRuntime')
    #get current real state for app in specific server
    currentState = cmo.getCurrentState(appName, serverName)
    return currentState
#======================================================  
# Undeploy the given application 
# Target we can change according to domain and application deployed on
#====================================================== 
def unDeploy(appName):
    print 'stopping and undeploying ....'
    stopApplication(appName, targets='AdminServer')
    undeploy(appName, targets='AdminServer')


#======================================================== 
# Main program here...
# Target you can change as per your need
#========================================================  
appName=sys.argv[1]
ver=sys.argv[2]
connect(user, passwd, adminurl)
cd('AppDeployments')
appflag=0
y=ls(returnMap='true')
for i in y :
 if i.startswith(appName )  ==1:
  #Checking for the application existence)
  print i
  print appstatus(i,'AdminServer')
 if appstatus(i,'AdminServer')=='STATE_RETIRED' :
  appflag=1
  break
 elif appstatus(i,'AdminServer')=='STATE_ACTIVE':
  appflag=2
 else:
  print ' other Applications are Running '
  pass


if appflag == 1 :
    print 'application having RETIERED STATE ..'
    unDeploy(i)
    print appstatus(i,'AdminServer')
    newDeploy(appName,ver)
    print appstatus(i,'AdminServer')
elif appflag== 2:
    print 'Application exists in ACTIVE state...'
    newDeploy(appName,ver)
    print appstatus(i,'AdminServer')
else:
    print 'new application'

How to execute the Side by Side deployment script?
Dear novice WLA, you can execute this script by re-defining your connection parameters at line 36. Remember one more thing is the application targeted to AdminServer this may vary for your environment as managed servers or clusters.
prompt$ java weblogic.WLST SBSDeploy.py

If you like the ideas implemented in this script, useful to your environment please share this article.

Reference URLs:

Popular Posts