Share it

Monday, January 17, 2011

Jython Script to Start Cluster

This Jython script starts cluster if it is stopped and ripple starts cluster if cluster is already running.

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 startcluster(cluster):

global AdminApp
global AdminConfig
global AdminControl

cell = AdminControl.getCell()
print " Cell name is --> "+ cell
Cluster = AdminControl.completeObjectName('cell='+ cell +',type=Cluster,name='+ cluster +',*')
state = AdminControl.getAttribute(Cluster, 'state')

if (state == 'websphere.cluster.running'):
print "Cluster --> " + cluster + " is running .......... "
print "Ripple starting cluster ............."
clusterMgr = AdminControl.completeObjectName('cell='+ cell +',type=ClusterMgr,*')
print AdminControl.invoke(clusterMgr, 'retrieveClusters')
Cluster = AdminControl.completeObjectName('cell='+ cell +',type=Cluster,name='+ cluster +',*')
print AdminControl.invoke(Cluster ,'rippleStart')

else:
print "Cluster --> " + cluster + " is stopped "
print "Starting cluster ............... "
clusterMgr = AdminControl.completeObjectName('cell='+ cell +',type=ClusterMgr,*')
AdminControl.invoke(clusterMgr, 'retrieveClusters')
Cluster = AdminControl.completeObjectName('cell='+ cell +',type=Cluster,name='+ cluster +',*')
print AdminControl.invoke(Cluster ,'start')
print " ---------------------------------------------------------------------------------------------- "

arglen=len(sys.argv)
num_exp_args=1
if (arglen != num_exp_args):
print "One argument is required. This argument should be a properties file."
print " ----------------------------------------------------------------------------------------- "
sys.exit(-1)
cluster = sys.argv[0]
startcluster(cluster)

No comments:

Post a Comment