# # stop a cluster. #################################################################### # Patrick Finnegan 18/04/2007. V1. #################################################################### namespace eval stopCluster { proc stopCluster { clusterName } { global AdminControl global AdminConfig global AdminTask # display procedure arguments. set procName [ lindex [ info level 0 ] 0 ] putsLog "## proc - $procName" foreach i [ info args $procName ] { upvar 0 $i ilocal set propertiesArray($i) $ilocal } putsLog "procedure arguments are................." foreach { a b } [ array get propertiesArray ] { putsLog [ format "%-35s %s" "$a" "$b" ] } # get and display the existing Clusters. putsLog "existing configured clusters are:............" if { [ catch { $AdminConfig list ServerCluster } r ] == 0 } { set configClusterList $r if { $configClusterList == {} } { putsLog "no existing clusters" } else { foreach i $configClusterList { set objClusterName [ $AdminConfig showAttribute $i name ] putsLog [ format "%-5s %s" " " $objClusterName ] } } } else { return -code error $r } # list the running clusters. foreach i [ $AdminControl queryNames type=Cluster,* ] { # get the object id of the target cluster. set x [ $AdminControl getAttribute $i clusterName ] if { $clusterName == "$x" } { set clusterId $i } lappend clusterList [ list $x [ $AdminControl getAttribute $i state ] ] } putsLog "cluster state .............." foreach i $clusterList { putsLog [ format "%-5s %-s" " " "[ lindex $i 0 ] [ lindex $i 1 ]" ] } # check whether the cluster exists and whether it's running. # eval concat to flatten the list into a single list for searching. set clusterListFlat [ eval concat $clusterList ] if { [ lsearch $clusterListFlat $clusterName ] == -1 } { putsLog "ERROR: $clusterName does not exist" return -code error } else { set stateIndex [ expr [ lsearch $clusterListFlat $clusterName ] +1 ] set state [ lindex $clusterListFlat $stateIndex ] if { $state == "websphere.cluster.stopped" } { putsLog "$clusterName is already stopped." return } else { putsLog "stopping $clusterName......." if { [ catch { $AdminControl invoke $clusterId stop } r ] == 0 } { putsLog "[ string range $r [ string first WAS $r ] end ]" } else { putsLog "[ string range $r [ string first WAS $r ] end ]" putsLog "$r" return -code error $r } # the cluster start/stop is asynchronous so poll the cluster every 10 seconds to make sure it starts. set elapsedTime 0 while { 1 | $elapsedTime >= 60000 } { after 10000 incr elapsedTime 10000 set state [ $AdminControl getAttribute $clusterId state ] if { $state == "websphere.cluster.stopped" } { putsLog [ format "%-10s %s" " " "state is $state" ] break } else { putsLog "polling cluster $clusterName every 10 seconds to check start status" putsLog [ format "%-10s %s" " " "state is $state" ] } } } } } }