Creating cluster using Jython wsadmin
Pre requisites
As per todays experiment what I understood is we need the following are the pre-requisites for the Cluster configuration in WebSphere Environment:
1) Cell created with a DMGR Profile
2) Nodeagents created and added to the cell.
3) Dmgr, Nodeagent must be running.
Jython Script for Cluster
As per todays experiment what I understood is we need the following are the pre-requisites for the Cluster configuration in WebSphere Environment:
1) Cell created with a DMGR Profile
2) Nodeagents created and added to the cell.
3) Dmgr, Nodeagent must be running.
Jython Script for Cluster
import sys
import os
import socket
#Get the operating system line separator from the linesep method of the os object
nl = os.linesep
# Store the Cell identifier for the specified Cell
cellID = AdminConfig.list('Cell')
cellName = AdminConfig.showAttribute(cellID, 'name')
#derives the environment type from the cellName
sName = cellName.replace("Cell","")
sName = sName.replace("Demo","")
# Store the Node identifier for the specified Node
nodeIDs = AdminConfig.list('Node').split(nl)
nodeNames = AdminTask.listNodes().split(nl)
nodeNames.sort()
# Identify each node and it's purpose so we can start creating servers and clusters on the
# appropriate nodes
for nid in nodeIDs:
nname=AdminConfig.showAttribute(nid, 'name')
nname=nname.replace(sName, "")
if nname == "AppSrvNode":
NID01=nid
elif nname == "AppSrvNode02":
NID02=nid
continue
# Store the node names
Node1Name = AdminConfig.showAttribute(NID01, 'name')
Node2Name = AdminConfig.showAttribute(NID02, 'name')
print Node1Name,Node2Name
# Create the cluster and store the cluster name
print "\nCreating the Demo cluster"
clusterID = AdminTask.createCluster('[-clusterConfig [-clusterName Demo' + sName + 'Cluster -preferLocal true]]')
clusterName = AdminConfig.showAttribute(clusterID, 'name')
# Creates all of the cluster members on the specified nodes
print "\nCreating the cluster members for the Demo cluster"
def createClusterMembers(nn01, nn02, clustName):
i = 1
while i <= 2:
if i == 1:
AdminTask.createClusterMember('[-clusterName ' + clustName + ' -memberConfig [-memberNode ' + nn01 + ' -memberName Demo' + sName + 'CM' + str(i) + ' -memberWeight 2 -genUniquePorts true -replicatorEntry false] -firstMember [-templateName default -nodeGroup DefaultNodeGroup -coreGroup DefaultCoreGroup]]')
elif i > 1:
AdminTask.createClusterMember('[-clusterName ' + clustName + ' -memberConfig [-memberNode ' + nn01 + ' -memberName Demo' + sName + 'CM' + str(i) + ' -memberWeight 2 -genUniquePorts true -replicatorEntry false]]')
i+=1
continue
while i <=4:
AdminTask.createClusterMember('[-clusterName ' + clustName + ' -memberConfig [-memberNode ' + nn02 + ' -memberName Demo' + sName + 'CM' + str(i) + ' -memberWeight 2 -genUniquePorts true -replicatorEntry false]]')
i+=1
continue
createClusterMembers(Node1Name, Node2Name, clusterName)
# Gets a list of all the newly created cluster members
cmIDs = AdminConfig.list('ClusterMember', clusterID).split(nl)
#Lists all of the application servers
serverName = []
serverID = AdminTask.listServers('-serverType APPLICATION_SERVER').split(nl)
for sid in serverID:
serverName.append(AdminConfig.showAttribute(sid, 'name'))
serverName.sort()
# This function saves any configuration changes to the master respository
def saveConfig():
print ""
print "Saving changes to the master repository"
AdminConfig.save()
print ""
print "DONE!"
# The following function Syncs all of the nodes with an active/started nodeagent task
def syncNodes():
nodelist = AdminConfig.list('Node').split(nl)
print "\n\n########################################"
print "### Synchronizing the Nodes"
print "########################################\n"
for n in nodelist:
nodename = AdminConfig.showAttribute(n, 'name')
objname = "type=NodeSync,node=" + nodename + ",*"
Syncl = AdminControl.completeObjectName(objname)
if Syncl != "":
if AdminControl.invoke(Syncl, 'isNodeSynchronized') == "true":
print "\n!! " + nodename + " is already synchronized"
else:
AdminControl.invoke(Syncl, 'sync')
print "\n)) " + nodename + " synchronized"
continue
print "Save the configuration changes?\n\n"
saveConfig()
syncNodes()
This was given me great learning oppurtunity the output makes me THRILLED!!
O/P
wsadmin>execfile('/home/krish/jython/cluster.py')
AppSrvNode AppSrvNode02
Creating the Demo cluster
Creating the cluster members for the Demo cluster
Save the configuration changes?
Saving changes to the master repository
DONE!
########################################
### Synchronizing the nodes
########################################
)) AppSrvNode synchronized
)) AppSrvNode02 synchronized
Comments
Post a Comment