Index by: file name | procedure name | procedure call | annotation
startCluster_proc.tcl (annotations | original source)

# 
# start a cluster. 
####################################################################
# Patrick Finnegan 18/05/2007.  V1. 
####################################################################

namespace eval startCluster {

    proc startCluster { 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 is running.  

       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.running" } {

	       putsLog "$clusterName is already started."
	       return 

           } else {

	       putsLog "starting $clusterName......."

	       if { [ catch { $AdminControl invoke $clusterId start } 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 

	       putsLog "terminate if cluster does not start in 60 seconds"

	       while { $elapsedTime < 60000 } {

		  after 10000 

                  incr elapsedTime 10000

		  set state [ $AdminControl getAttribute $clusterId state ]

                  if { $state == "websphere.cluster.running"  } {

		      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" ]
		      putsLog [ format "%-10s %s" " " "elapsed time is $elapsedTime milliseconds" ]

	          }

	       }
               
           }
       }

   }
}

Index by: file name | procedure name | procedure call | annotation
File generated 2007-08-07 at 13:42.