### ### createcluster.jacl ### ### ### Creates a server group onto the server ### Starts the server. ### ### Usage: ### ### wsadmin -username system \ ### -password \ ### -f createcluster.jacl clustername "node1 node2 node3" clserv 1 10 ### ### ### Arguments: ### ### arg1 - cluster name ### arg2 - list of node names ### arg3 - prefix to be used on server names ### arg5 - weight of each server in the group ### arg4 - number of servers to be created per node ### ### proc createcluster {clusterName nodes namePrefix serversPerNode weight} { ### ### set up globals ### global AdminConfig global AdminControl global AdminApp ### ### We assume that there is only one cell, and we are on it ### set cellname [$AdminControl getCell] set cell [$AdminConfig getid /Cell:$cellname/] ### ### Construct the attribute list to be used in creating a ServerCluster attribute ### set name_attr [list name $clusterName] set desc_attr [list description "test cluster"] set pref_attr [list preferLocal true] set statem_attr [list stateManagement [list [list initialState STOP]]] set attrs [list $name_attr $desc_attr $pref_attr $statem_attr] ### ### Create the server cluster ### puts "createcluster: creating the ServerCluster $clusterName" set cluster [$AdminConfig create ServerCluster $cell $attrs] ### ### For each node, create the required number of servers ### ### set index 1 foreach nodeName $nodes { set node [$AdminConfig getid /Node:$nodeName/] for {set i 1} {$i <= $serversPerNode} {incr i} { set uid "" append uid $index _ $i set servName "" append servName $namePrefix _ $uid set name_attr [list memberName $servName] set weight_attr [list weight $weight] set attrs [list $name_attr $weight_attr] puts "createcluster: creating server $servName on node $nodeName" set server [$AdminConfig createClusterMember $cluster $node $attrs] } incr index } ### ### save changes ### ### puts "createcluster: saving config changes." $AdminConfig save ### ### Ask the ClusterMgr to refresh its list of clusters ### ### set clusterMgr [$AdminControl completeObjectName type=ClusterMgr,cell=$cellname,*] if {[llength $clusterMgr] == 0} { puts "createcluster: Error -- clusterMgr MBean not found for cell $cellname" return } $AdminControl invoke $clusterMgr retrieveClusters ### ### For each node, invoke a sync if necessary ### -- Is a nodeSync MBean available on this node? ### -- Find out if serverStartupSyncEnabled is true for this node ### We just created this server, so if this attribute is set to ### "false" we have to perform a sync. If we do not, the node we ### are installing on may have an out-of-date copy of the config ### data. ### set index 1 foreach nodeName $nodes { set node [$AdminConfig getid /Node:$nodeName/] puts "createcluster: checking for the existence of a NodeSync MBean on node $nodeName" set nodeSync [$AdminControl completeObjectName type=NodeSync,node=$nodeName,*] if {[llength $nodeSync] == 0} { puts "createcluster: Error -- NodeSync MBean not found for name $nodeName" return } set enabled [$AdminControl getAttribute $nodeSync serverStartupSyncEnabled] if {[string compare $enabled "false"] == 0} { puts "createcluster: Invoking synchronization for node $nodeSync because serverStartupSyncEnabled is set to false..." $AdminControl invoke $nodeSync sync puts "createcluster: Done with synchronization." } } ### ### Ask the Cluster MBean to start the cluster ### ### set cluster [$AdminControl completeObjectName type=Cluster,name=$clusterName,*] puts "createcluster: Invoking start for cluster $clusterName" $AdminControl invoke $cluster start } ### ### Main ### if { !($argc == 5) } { puts "" puts "createcluster.jacl " puts "" puts "Args include: " puts " Cluster name " puts " Node names " puts " Server name prefix" puts " Weight of each server" puts " Number of servers per node " puts " " puts "For example:" puts " " puts " wsadmin -username system \ " puts " -password password \ " puts " -f createcluster.jacl clustername \"node1 node2 node3\" serverprefix 1 1 " puts " " } else { set clusterName [lindex $argv 0] set nodes [lindex $argv 1] set prefix [lindex $argv 2] set weight [lindex $argv 3] set perNode [lindex $argv 4] createcluster $clusterName $nodes $prefix $perNode $weight }