Monday, November 9, 2009

Cluster Start and Stop Scripts

This Script will start the Cluster on Websphere Application Server:
Script to start Cluster and check for existence of application
Written By Charanjeet Singh

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,appfile):

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 " ---------------------------------------------------------------------------------------------- "

application = AdminConfig.getid("/Deployment:"+appfile+"/")

if len(application) > 0:

print " Deployment completed succesfully ........... "


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)

propFile=sys.argv[0]

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 " ----------------------------------------------------------------------------------------- "


appfile = str(properties.getProperty("APPLICATION_NAME"))

cluster = str(properties.getProperty("CLUSTER_NAME"))

startcluster(cluster,appfile)

This Script will stop Cluster :

Script to stop Cluster
Written By Charanjeet Singh

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

global AdminApp
global AdminConfig
global AdminControl

cell = AdminControl.getCell()

print " Cell name is --> "+ cell

Serverid = AdminConfig.getid('/Cell:'+ cell +'/ServerCluster:'+ cluster +'/')

memberlist = AdminConfig.showAttribute(Serverid, "members" )

print "test is:"+ memberlist

members = memberlist[1:len(memberlist)-1]

for member in members.split():

node = AdminConfig.showAttribute(member, "nodeName" )

server = AdminConfig.showAttribute(member, "memberName" )

serverId = AdminConfig.getid("/Cell:"+cell+"/Node:"+node+"/Server:"+server+"/")

s1 = AdminControl.completeObjectName('cell='+ cell +',node='+ node +',name='+ server +',type=Server,*')

print " Checking for the running Mbean of server :"+ server

if len(s1) > 0:

print " Server : "+ server +" is running"

print " Stopping Server :"+ server

AdminControl.stopServer(server, node, 'immediate' )

print " Server : "+ server +" stopped"

else :

print "Server : "+ server +" is stopped "

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)

propFile=sys.argv[0]

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 " ----------------------------------------------------------------------------------------- "



cluster = str(properties.getProperty("CLUSTER_NAME"))

stopcluster(cluster)

1 comment:

  1. Can you please give little bit overview about how you are peforming this cluster restart. Did you found new inventions on properties. Is there any other way to load the properties? Using java way is lengthy :)

    ReplyDelete