Monday, January 17, 2011

jython script to uninstall , install Application and sync nodes

import sys,java
from java.util import Properties
from java.io import FileInputStream
from org.python.modules import time
lineSep = java.lang.System.getProperty('line.separator')


def appinstall(appfile,apppath,cluster,map_modules_cluster,map_modules_vh,mapresref):

global AdminApp
global AdminConfig
global AdminControl

print " Getting Cell Name .."
cell = AdminControl.getCell()
print " Cell name is --> "+ cell
print " ----------------------------------------------------------------------------------------- "

###############################################################################################

## checking for the existence of application , is application exists then updating it and if it does not exists then installing it
application = AdminConfig.getid("/Deployment:"+appfile+"/")
if len(application) > 0:
print " ----------------------------------------------------------------------------------------- "
print " Application ---> " +appfile+ " is installed on cluster --> " + cluster
print " ----------------------------------------------------------------------------------------- "
print " uninstalling application --> " + appfile
AdminApp.uninstall(appfile)
print " ----------------------------------------------------------------------------------------- "
print "application uninstalled .. "
AdminConfig.save()
print " ----------------------------------------------------------------------------------------- "
print " Installing App on cluster --> " + cluster
print AdminApp.install(apppath , '[-appname '+appfile+' -cell '+cell+' -cluster '+cluster+' -MapModulesToServers '+map_modules_cluster+' -MapWebModToVH '+map_modules_vh+']')
print " ----------------------------------------------------------------------------- "
print " Application --> " +appfile+ " installed on cluster--> " +cluster
print " ----------------------------------------------------------------------------- "
print " Saving Configuration "
print " ----------------------------------------------------------------------------- "
AdminConfig.save()
print " ----------------------------------------------------------------------------- "
application = AdminConfig.getid("/Deployment:"+appfile+"/")
if len(application) > 0:
print " ----------------------------------------------------------------------------------------- "
print " Application ---> " +appfile+ " is successfully installed on cluster --> " + cluster
print " ----------------------------------------------------------------------------------------- "

#####################Waiting for the application to expand and then starting the server################
print " Sleeping for 60 seconds after deploying application "
time.sleep(60)
app = AdminApp.isAppReady(appfile)
while (app == 'false'):
app = AdminApp.isAppReady(appfile)
if (app == 'true'):
print " Expansion of ear completed "


###########################Syncronizing Node######################
nodelist = AdminTask.listManagedNodes().split(lineSep)
for nodename in nodelist :
print " Syncronizing node.......... "
####################Identifying the ConfigRepository MBean and assign it to variable######################
repo = AdminControl.completeObjectName('type=ConfigRepository,process=nodeagent,node='+ nodename +',*')
AdminControl.invoke(repo, 'refreshRepositoryEpoch')
sync = AdminControl.completeObjectName('cell='+ cell +',node='+ nodename +',type=NodeSync,*')
AdminControl.invoke(sync , 'sync')
print " ----------------------------------------------------------------------------------------- "
print " Full Resyncronization completed "
print "



arglen=len(sys.argv)
num_exp_args=2
if (arglen != num_exp_args):
print "Three arguments are required. Two arguments should be a properties file."
print " ----------------------------------------------------------------------------------------- "
sys.exit(-1)
propFile=sys.argv[1]
properties=Properties();

try:
properties.load(FileInputStream(propFile))
print " ----------------------------------------------------------------------------------------- "
print "Succesfully read property file "+propFile
print " ----------------------------------------------------------------------------------------- "
except:
print "Cannot read property file "+propFile
sys.exit(-1)
print " ----------------------------------------------------------------------------------------- "
apppath = sys.argv[0]
cluster = str(properties.getProperty("ENV_CLUSTER_NAME"))
map_modules_cluster = str(properties.getProperty("ENV_PCS_MAP_MODULES_TO_SERVER"))
map_modules_vh = str(properties.getProperty("PCS_MAP_MODULES_TO_VIRTUAL_HOST"))
appfile = str(properties.getProperty("ENV_PCS_APP_NAME"))
mapresref = str(properties.getProperty("MAP_RESOURCE_REF"))

appinstall(appfile,apppath,cluster,map_modules_cluster,map_modules_vh,mapresref)

7 comments:

  1. Thanks a lot for sharing your knowledge.

    Best Regards,
    Vamsi Krishna Kunasani
    vamsi.kunasani@gmail.com

    ReplyDelete
  2. What could be a valid value for the "mapresref"??
    Thnx

    ReplyDelete
  3. commendable doc '' We appreciate and are thankful for the same

    ReplyDelete
  4. Great job! Do you only supply the property file as the argument?

    ReplyDelete
  5. yes . you need to supply 2 argument . one is the ear full path from where it will pick up the ear file to deploy and then the property file.

    ReplyDelete
  6. can u please post me the properties file as well..

    ReplyDelete