# # Install a new Cluster. # The new cluster must have one member which is an existing server #################################################################### # Patrick Finnegan 31/01/2007. V1. #################################################################### namespace eval cluster { proc installCluster { propertiesFile } { 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 Clusters are:............" if { [ catch { $AdminConfig list ServerCluster } r ] == 0 } { set ClusterList $r if { $ClusterList == {} } { putsLog "no existing clusters" } else { foreach i $ClusterList { set ClusterName [ $AdminConfig showAttribute $i name ] putsLog [ format "%-5s %s" " " $ClusterName ] } } } else { return -code error $r } # call the hashMapList proc which returns a sorted list from the Property object loaded from the properties file. putsLog "new Cluster properties are:............" if { [ catch { hashMapList $propertiesFile } r ] == 0 } { set propertiesList $r foreach a $propertiesList { putsLog [ format "%-5s %-40s %-s" " " [ lindex $a 0 ] [ lindex $a 1 ] ] } } else { return -code error $r } # call the hashMap proc which returns a Property object populated with property file values. if { [ catch { hashMap $propertiesFile } r ] == 0 } { set PropertyI $r } else { return -code error $r } # check if the target Cluster already exists. If so delete. set clusterName [ $PropertyI getProperty serverCluster.name ] foreach i $ClusterList { set name [ $AdminConfig showAttribute $i name ] if { [ string match -nocase $name $clusterName ] == 1 } { if { [ catch { $AdminConfig remove $i } r ] == 0 } { putsLog "Cluster removed successfully: $ClusterName" } else { putsLog "ERROR: error removing Cluster: $ClusterName" return -code error $r } } } # set the Cluster properties. set attrList [ setClusterProperties $propertiesList ] # get the cell parent. Assume singel cell. set cellId [ $AdminConfig list Cell ] if { [ catch { $AdminConfig create ServerCluster $cellId $attrList } r ] == 0 } { putsLog "************************************" putsLog "Cluster created successfully:" putsLog $r putsLog "************************************" } else { putsLog "************************************" putsLog "ERROR: problem creating Cluster" putsLog $r putsLog "************************************" return -code error $r } } ###################################### # set Cluster attributes. ###################################### proc setClusterProperties { propertiesList } { global AdminConfig 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" ] } foreach a $propertiesList { # the first list element contains the property name. # the first segment of the property name is the type. # the second segment of the property name is the attribute. set propertyName [ lindex $a 0 ] #puts "property name is $propertyName" set lengthFirstName [ string first "." $propertyName ] set firstName [ string range $propertyName 0 [ expr { $lengthFirstName - 1 } ] ] set secondName [ string range $propertyName [ expr { $lengthFirstName + 1 } ] end ] #puts "firstname is $firstName" #puts "secondName is $secondName" # Build the attribute lists switch -exact -- $secondName { name { set nameList [ list $secondName [ lindex $a 1 ] ] } description { set descriptionList [ list $secondName [ lindex $a 1 ] ] } enableHA { set enableHAList [ list $secondName [ lindex $a 1 ] ] } preferLocal { set preferLocalList [ list $secondName [ lindex $a 1 ] ] } serverType { set serverTypeList [ list $secondName [ lindex $a 1 ] ] } } } # 17/04/2007 # make the proc more flexible by only setting attributes that exist in the properties file. # check if each list variable exists. ## set transaction properties. if { [ info exist nameList ] == 1 } { lappend attrList $nameList } if { [ info exist descriptionList ] == 1 } { lappend attrList $descriptionList } if { [ info exist enableHAList ] == 1 } { lappend attrList $enableHAList } if { [ info exist preferLocalList ] == 1 } { lappend attrList $preferLocalList } if { [ info exist serverTypeList ] == 1 } { lappend attrList $serverTypeList } return $attrList } }