Date Created: Mon 08-Nov-2010

Related Document Categories:

Get my WebSphere Application Server course here >> http://www.themiddlewareshop.com/products/


WebSphere Jython functions for Cluster Management


############################################################
# cluster-related methods
############################################################

def getServerClusterByName( name ):
"""Return the config object id for the named server cluster
TODO: get rid of either this or getClusterId"""
return getObjectByName( 'ServerCluster', name )

def getClusterId(clustername):
"""Return the config object id for the named server cluster.
TODO: get rid of either this or getServerClusterByName"""
return getServerClusterByName(clustername)

def createCluster( cellname, clustername, createReplicationDomain = False ):
"""Create a new cluster without a cluster member. Return its id.
If createReplicationDomain is True, create a replication domain for it."""
m = "createCluster:"
sop(m,"Entry. cellname=%s clustername=%s createReplicationDomain=%s" % ( cellname, clustername, createReplicationDomain ))
if createReplicationDomain:
sop(m,'Calling AdminTask.createCluster([-clusterConfig [-clusterName %s] -replicationDomain [-createDomain true]]' % clustername)
return AdminTask.createCluster('[-clusterConfig [-clusterName %s] -replicationDomain [-createDomain true]]' % clustername)
else:
sop(m,'Calling AdminTask.createCluster([-clusterConfig [-clusterName %s]]' % clustername)
return AdminTask.createCluster('[-clusterConfig [-clusterName %s]]' % clustername)

def createServerInCluster( clustername, nodename, servername,sessionReplication = False):
"""Create a new server in a cluster, return its id.
Turn on session replication if sessionReplication is True"""
m = "createServerInCluster:"
sop(m,"Entry. clustername=%s nodename=%s servername=%s sessionReplication=%s" % ( clustername, nodename, servername, sessionReplication ))
if sessionReplication:
sop(m,'Calling AdminTask.createClusterMember([-clusterName %s -memberConfig[-memberNode %s -memberName %s -memberWeight 2 -replicatorEntry true]])' % (clustername,nodename,servername))
AdminTask.createClusterMember('[-clusterName %s -memberConfig[-memberNode %s -memberName %s -memberWeight 2 -replicatorEntry true]]' % (clustername,nodename,servername))
else:
sop(m,'Calling AdminTask.createClusterMember([-clusterName %s -memberConfig[-memberNode %s -memberName %s -memberWeight 2]])' % (clustername,nodename,servername))
AdminTask.createClusterMember('[-clusterName %s -memberConfig[-memberNode %s -memberName %s -memberWeight 2]]' % (clustername,nodename,servername))

def deleteServerClusterByName( name ):
"""Delete the named server cluster"""
m = "deleteServerClusterByName:"
sid = getServerClusterByName( name )
if not sid:
raise m + " Could not find cluster %s to delete" % name
stopCluster( name )
sop(m,"remove cluster: %s" % name)
AdminConfig.remove( sid )

def listServerClusters():
"""Return list of names of server clusters"""
cluster_ids = _splitlines(AdminConfig.list( 'ServerCluster' ))
cellname = getCellName()
result = []
for cluster_id in cluster_ids:
result.append(AdminConfig.showAttribute(cluster_id,"name"))
return result

def stopAllServerClusters():
"""Stop all server clusters"""
clusternames = listServerClusters()
for name in clusternames:
stopCluster( name )

def startAllServerClusters():
"""Start all server clusters"""
clusternames = listServerClusters()
for name in clusternames:
startCluster( name )

def deleteAllServerClusters():
"""Delete all server clusters (including their servers)"""
m = "deleteAllServerClusters:"
stopAllServerClusters()
clusternames = listServerClusters()
for name in clusternames:
sop(m,"Delete cluster: %s" % name)
id = getClusterId(name)
AdminConfig.remove( id )

def stopCluster( clustername ):
"""Stop the named server cluster"""
m = "stopCluster:"
sop(m,"Stop cluster %s" % clustername)
cellname = getCellName() # e.g. 'poir1Cell01'
cluster = AdminControl.completeObjectName( 'cell=%s,type=Cluster,name=%s,*' % ( cellname, clustername ) )
state = AdminControl.getAttribute( cluster, 'state' )
if state != 'websphere.cluster.partial.stop' and state != 'websphere.cluster.stopped':
AdminControl.invoke( cluster, 'stop' )
# Wait for it to stop
maxwait = 300 # wait about 5 minutes at most
count = 0
sop(m,"wait for cluster %s to stop" % clustername)
while state != 'websphere.cluster.stopped':
time.sleep( 30 )
state = AdminControl.getAttribute( cluster, 'state' )
sop(m,"state of %s: %s" % ( clustername, state ))
count += 1
if count > ( maxwait / 30 ):
sop(m,"Giving up")
break

def startCluster( clustername ):
"""Start the named server cluster"""
m = "startCluster:"
sop(m,"Start cluster %s" % clustername)
cellname = getCellName() # e.g. 'poir1Cell01'
cluster = AdminControl.completeObjectName( 'cell=%s,type=Cluster,name=%s,*' % ( cellname, clustername ) )
state = AdminControl.getAttribute( cluster, 'state' )
if state != 'websphere.cluster.partial.start' and state != 'websphere.cluster.running':
AdminControl.invoke( cluster, 'start' )
# Wait for it to start
maxwait = 300 # wait about 5 minutes at most
count = 0
sop(m,"wait for cluster %s to start" % clustername)
while state != 'websphere.cluster.running':
time.sleep( 30 )
state = AdminControl.getAttribute( cluster, 'state' )
sop(m,"state of %s: %s" % ( clustername, state ))
count += 1
if count > ( maxwait / 30 ):
sop(m,"Giving up")
break

def listServersInCluster(clusterName):
"""Return a list of all servers (members) that are in the specified cluster"""
m = "listServersInCluster:"
sop(m,"clusterName = %s" % clusterName)
clusterId = AdminConfig.getid("/ServerCluster:" + clusterName + "/")
clusterMembers = _splitlines(AdminConfig.list("ClusterMember", clusterId ))
return clusterMembers

def startAllServersInCluster(clusterName):
"""Start all servers (members) that are in the specified cluster"""
m = "startAllServersInCluster:"
sop(m,"clusterName = %s" % clusterName)
clusterMembers = listServersInCluster(clusterName)
for clusterMember in clusterMembers:
nodeName = AdminConfig.showAttribute( clusterMember, "nodeName" )
serverName = AdminConfig.showAttribute( clusterMember, "memberName" )
sop(m, "Starting Server %s on Node %s" % (serverName, nodeName ))
startServer(nodeName, serverName)

def stopAllServersInCluster(clusterName):
"""Stop all servers (members) that are in the specified cluster"""
m = "stopAllServersInCluster:"
sop(m,"clusterName = %s" % clusterName)
clusterMembers = listServersInCluster(clusterName)
for clusterMember in clusterMembers:
nodeName = AdminConfig.showAttribute( clusterMember, "nodeName" )
serverName = AdminConfig.showAttribute( clusterMember, "memberName" )
sop(m, "Stoping Server %s on Node %s" % (serverName, nodeName ))
stopServer(nodeName, serverName)

############################################################
# generic_server_cluster - related methods
############################################################

def getGenericServerClusterIdByName( name ):
"""Return the config object id for the named server GenericServerCluster"""
return getObjectByName( 'GenericServerCluster', name )

def createGenericServerCluster( clustername, protocol ):
"""Create a new generic server cluster without a cluster member. Return its id"""
m = "createGenericServerCluster:"
cellname = getCellName()
sop(m,"Creating GSC. clustername=" + clustername + " protocol=" + protocol)
return AdminConfig.create( 'GenericServerCluster', getCellId(cellname), [['name', clustername], ['protocol', protocol]] )

def listGenericServerClusters():
"""Return list of names of generic server clusters"""
return getObjectNameList( 'GenericServerCluster' )

def deleteAllGenericServerClusters():
"""Delete all generic server clusters"""
deleteAllObjectsByName( 'GenericServerCluster' )

Get my WebSphere Application Server course here >> http://www.themiddlewareshop.com/products/


Steve Robinson - IBM Champion 2013

About Me

Steve Robinson has been working in IT for over 20 years and has provided solutions for many large-enterprise corporate companies across the world. Steve specialises in Java and Middleware.

In January 2013, I was awarded the prestigous 'IBM Champion' accolade.


  • Linked In
  • Twitter
  • About Me
  • My Blog
  • Contact Me

Read my books?

IBM WebSphere Application Server 8.0 Administration Guide

IBM WebSphere Application Server 8.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Categories

Other Categories