This jython Script will Install and Update Application on cluster of Websphere Application Server:
WRITTEN BY Suvash
This Script install Application on cluster and map modules to Virtual Hosts
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):
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 " Updating application --> " + appfile
pathToEAR = apppath
option1 = appfile
option2 = "\'app\'"
option3 = "-operation update -contents " + apppath + " -MapModulesToServers " + map_modules_cluster + " -MapWebModToVH " + map_modules_vh
print AdminApp.update(option1,'app',option3)
AdminConfig.save()
else :
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 " ----------------------------------------------------------------------------- "
#####################Waiting for the application to expand and then starting the server################
print " Sleeping for 300 seconds after deploying application "
time.sleep(300)
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 +',*')
print AdminControl.invoke(repo, 'refreshRepositoryEpoch')
sync = AdminControl.completeObjectName('cell='+ cell +',node='+ nodename +',type=NodeSync,*')
print AdminControl.invoke(sync , 'sync')
print " ----------------------------------------------------------------------------------------- "
print " Full Resyncronization completed "
print " ----------------------------------------------------------------------------------------- "
########################################################################################################
arglen=len(sys.argv)
num_exp_args=3
if (arglen != num_exp_args):
print "Three arguments are required. Two arguments should be a properties file."
print " ----------------------------------------------------------------------------------------- "
sys.exit(-1)
propFile=sys.argv[0]
propFile1=sys.argv[1]
properties=Properties();
try:
properties.load(FileInputStream(propFile))
properties.load(FileInputStream(propFile1))
print " ----------------------------------------------------------------------------------------- "
print "Succesfully read property file "+propFile
print "Succesfully read property file "+propFile1
print " ----------------------------------------------------------------------------------------- "
except:
print "Cannot read property file "+propFile
print "Cannot read property file "+propFile1
sys.exit(-1)
print " ----------------------------------------------------------------------------------------- "
appfile = str(properties.getProperty("APPLICATION_NAME"))
apppath = sys.argv[2]
cluster = str(properties.getProperty("CLUSTER_NAME"))
map_modules_cluster = str(properties.getProperty("MAP_MODULES_TO_SERVER"))
map_modules_vh = str(properties.getProperty("MAP_MODULES_TO_VH"))
print " app file " + appfile
print " apppath " + apppath
print " cluster " + cluster
print " map_modules_cluster " + map_modules_cluster
print " map_modules_vh " + map_modules_vh
appinstall(appfile,apppath,cluster,map_modules_cluster,map_modules_vh)
No comments:
Post a Comment