#################################################################### # Install App. #################################################################### # Patrick Finnegan 15/02/2005. V1. #################################################################### namespace eval installApp { proc installApp { propertiesFile earFile } { global AdminConfig global AdminTask global AdminApp global AdminControl # 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 applicatons. putsLog "existing applications are:............" set apps [ $AdminApp list ] if { [ catch { $AdminApp list } r ] == 0 } { set appList $r if { $appList == {} } { putsLog "no existing applications" set noApps "true" } else { set noApps "false" foreach i $appList { putsLog [ format "%-5s %s" " " $i ] } } } 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 Application properties are:............" if { [ catch { hashMapList $propertiesFile } r ] == 0 } { set propertiesList $r foreach a $propertiesList { putsLog [ format "%-5s %-50s %-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 } { variable PropertyI $r } else { return -code error $r } # check if the application already exists. If so delete. # the application name is set to the root part of the ear file name. set appName [ file root [ file tail $earFile ] ] if { $noApps != true } { if { [ lsearch -glob $apps $appName ] == -1 } { putsLog "$appName is not installed" } else { putsLog "deleting $appName ..............." if { [ catch { $AdminApp uninstall $appName } r ] == 0 } { putsLog "$appName deleted successfully" } } } variable serverName [ string trim [ $PropertyI getProperty serverName ] ] # determine if the target environmentis a server or cluster. # Admin config returns null if the server does not exist. if { [ catch { $AdminConfig getid /ServerCluster:$serverName/ } r ] == 0 } { if { $r == {} } { if { [ catch { $AdminConfig getid /Server:$serverName/ } r ] == 0 } { if { $r == {} } { putsLog "ERROR: $serverName does not exist as a cluster or server" return -code error $r } else { variable serverIsCluster "false" putsLog "Deployment target is server: $r" } } } else { putsLog "Deployment target is cluster: $r" variable serverIsCluster "true" } } set serverId $r # check for web module definitions # 23/04/2007 After running this code on lot's of different installations # I realized that most apps and their modules are deployed to a single # virtual host i.e the # virtual host mappings just need to default to # the cluster/server/virtual host name supplied by the properties file. # If the deployment is to a cluster the individual web module to server # mappings are not required but they are required for a single server # installation. Procs that mapped the individual web modules to virtual # hosts now just write the output to the log for information only but # can easily be adapted to explicitly map the modules if required. # use taskInfo to scan the EAR for mappable resources. # display virtual host mappings. set output [ $AdminApp taskInfo $earFile MapWebModToVH ] set searchString "webModule:" set matchString "virtualHost" putsLog "Virtual host modules are ............" displayModList $output $searchString $matchString # display server mappings and return the mapping details. set output [ $AdminApp taskInfo $earFile MapModulesToServers ] set searchString "module:" set matchString "server" putsLog "Web modules are ............" set resRefList [ displayModList $output $searchString $matchString ] # if the web module to server mappings exist AND the deployment is to a # server rather than a cluster set up the server mappings in the correct # format. if { $resRefList != {} && $serverIsCluster == "false" } { set serverModList [ mapServerMod $PropertyI $resRefList ] } # display EJB resource references and return the mapping details. set output [ $AdminApp taskInfo $earFile MapResRefToEJB ] set searchString "module:" set matchString "MapResRefToEJB" putsLog "EJB Resource References are: ............" set resRefList [ displayModList $output $searchString $matchString ] # if EJB resource refs exist map the EJB resource references to the datasource JNDI reference. # NB we assume that the JNDI reference in the EAR will be overridden by the supplied JNDI reference. # NB the JNDI reference must exist in the DM cell or the deployment will fail with "WASX7111E: Cannot find a match for supplied option" if { $resRefList == {} } { set continue true } else { set ejbResRefList [ MapResRefToEJB $PropertyI $resRefList ] } set groupRoleList [ getRoleMappings $propertiesList ] # The installApplication proc is called with a variable number of # arguments depending on the options we set for the install app command. # Create the install options list using the available options. As # mentioned above application modules are not individually mapped to # virtual hosts or servers. # remove an option by commenting it out. #-MapModulesToServers $webModList lappend optionList -appname $appName # leading or trailing spaces can cause problems during the install. Zap them. lappend optionList -defaultbinding.virtual.host [ string trim [ $PropertyI getProperty virtualHost ] ] if { $serverIsCluster == "true" } { lappend optionList -cluster $serverName } else { lappend optionList -server $serverName } if { [ info exist serverModList ] == 1 } { lappend optionList -MapModulesToServers $serverModList } if { [ info exist ejbResRefList ] == 1 } { lappend optionList -MapResRefToEJB $ejbResRefList } if { $groupRoleList == {} } { set continue true } else { lappend optionList -MapRolesToUsers $groupRoleList } #lappend optionList -contextroot $contextRoot lappend optionList -noreloadEnabled #lappend optionList -preCompileJSPs lappend optionList -verbose if { [ catch { installApplication $earFile $optionList } r ] == 0 } { putsLog "$appName installed successfully" putsLog $r } else { putsLog "ERROR: $appName failed to install" return -code error $r } if { [ catch { modifyEnterpriseApp $PropertyI $appName } r ] == 0 } { putsLog "$appName properties modifiled successfully" putsLog $r } else { putsLog "ERROR: failed to modify $appName proerties" return -code error $r } } #################################################################### # Set application properties. #################################################################### proc setAppProperties { PropertyI propertiesList } { global serverName 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 "properties are.................." foreach { a b } [ array get propertiesArray ] { putsLog [ format "%-35s %s" "$a" "$b" ] } # build role mapping list. # the Active Directory roles are keyed on application roles on a many to one relationship. # extract the unique application roles and then match the Active Directory roles to the keys. } #################################################################### # Get the role mappings. # Some applications may not have role mappings. If so return null. #################################################################### proc getRoleMappings { propertiesList } { set procName [ lindex [ info level 0 ] 0 ] putsLog "## proc - $procName" foreach i [ info args $procName ] { upvar 0 $i ilocal set propertiesArray($i) $ilocal } putsLog "properties are.................." foreach { a b } [ array get propertiesArray ] { putsLog [ format "%-35s %s" "$a" "$b" ] } # build role mapping list. # the Active Directory roles are keyed on application roles on a many to one relationship. # extract the unique application roles and then match the Active Directory roles to the keys. # get the list of the application roles. foreach i $propertiesList { # extract the app roles if { [ lsearch -glob [ string toupper [ join $i ] ] "*ROLE*" ] != -1 } { lappend appRoles [ lindex [ lindex $i 1 ] 0 ] } # extract the user app role to AD user mappings if { [ lsearch -glob [ string toupper [ join $i ] ] "*USERROLE*" ] != -1 } { lappend userAppRolesKeyed [ list [ lindex $i 0 ] [ lindex [ lindex $i 1 ] 0 ] [ lindex [ lindex $i 1 ] 1 ] ] } # extract the group app roles to AD group mappings if { [ lsearch -glob [ string toupper [ join $i ] ] "*GROUPROLE*" ] != -1 } { lappend groupAppRolesKeyed [ list [ lindex $i 0 ] [ lindex [ lindex $i 1 ] 0 ] [ lindex [ lindex $i 1 ] 1 ] ] } } # if there are no roles return. if { [ info exist appRoles ] == 0 } { putsLog "***** no roles defined for the application *****" return } # delete the duplicate entries from the app roles list. set templist {} foreach item $appRoles { if { [ lsearch $templist $item ] == -1 } { lappend templist $item } } # sort roles set appRoles [ lsort $templist ] # build the user roles and group roles list. foreach i $appRoles { foreach e $userAppRolesKeyed { if { [ lsearch -glob $e "*$i*" ] != -1 } { set user [ lindex $e 2 ] append users $user| } } foreach e $groupAppRolesKeyed { if { [ lsearch -glob $e "*$i*" ] != -1 } { set group [ lindex $e 2 ] append groups $group| } } lappend usersGroupRoleList [ list "$i" no no "$users" "$groups" ] unset users unset groups } return $usersGroupRoleList } #################################################################### # Get the web module list. #################################################################### proc displayModList { output searchString matchString } { global AdminConfig global AdminControl global AdminApp variable serverName variable serverIsCluster variable PropertyI set procName [ lindex [ info level 0 ] 0 ] putsLog "## proc - $procName" foreach i [ info args $procName ] { upvar 0 $i ilocal set propertiesArray($i) $ilocal } #putsLog "properties are.................." #foreach { a b } [ array get propertiesArray ] { # #putsLog [ format "%-35s %s" "$a" "$b" ] #} if { [ string first $searchString $output ] == -1 } { putsLog "No $matchString host definitions in EarFile" return } #get local mapping targets. These over-ride targets defined in the ear/war. set localJndi [ string trim [ $PropertyI getProperty jndi ] ] set localVirtualHost [ string trim [ $PropertyI getProperty virtualHost ] ] # truncate the leading section of the output string. set moduleStart [ string first $searchString $output ] set outputString [ string replace $output 0 [ expr { $moduleStart -1 } ] ] #chop the output string up into clumps delimited by "module:" while { 1 } { if { [ string first $searchString $outputString 8 ] == -1 } { set moduleBody [ string range $outputString 0 end ] lappend moduleList $moduleBody break } else { set moduleEnd [ expr [ string first $searchString $outputString 8 ] -1 ] set moduleBody [ string range $outputString 0 $moduleEnd ] } lappend moduleList $moduleBody set outputString [ string replace $outputString 0 $moduleEnd ] } # split the list then flatten by newline. set moduleList [ eval concat [ split $moduleList \n ] ] foreach i $moduleList { switch -exact -- $matchString { MapResRefToEJB { regexp {.+: ([^ ]+) EJB:([ ]|[ ][^ ]+[ ])uri: ([^ ]+) .+: ([^ ]+) .+: ([^ ]+) JNDI: ([^ ]+)} $i a module ejb uri referenceBinding resRefType JNDI putsLog [ format "%-5s %-20s %-s" " " "module:" [ string trim $module ] ] putsLog [ format "%-10s %-20s %-s" " " "EJB:" [ string trim $ejb ] ] putsLog [ format "%-10s %-20s %-s" " " "uri:" [ string trim $uri ] ] putsLog [ format "%-10s %-20s %-s" " " "referenceBinding:" [ string trim $referenceBinding ] ] putsLog [ format "%-10s %-20s %-s" " " "resRefType:" [ string trim $resRefType ] ] putsLog [ format "%-10s %-20s %-s" " " "JNDI:" $localJndi ] # set up the resource ref list for later mapping set module [ list module [ string trim $module ] ] set ejb [ list ejb [ string trim $ejb ] ] set uri [ list uri [ string trim $uri ] ] set referenceBinding [ list referenceBinding [ string trim $referenceBinding ] ] set resRefType [ list resRefType [ string trim $resRefType ] ] set jndi [ list jndi $localJndi ] lappend resRefList [ list $module $ejb $uri $referenceBinding $resRefType $jndi ] unset module unset ejb unset uri unset referenceBinding unset resRefType unset JNDI } virtualHost { regexp {.+:(.+)uri: ([^ ]+) .+: ([^ ]+)} $i a module uri target putsLog [ format "%-5s %-10s %-s" " " "module:" [ string trim $module ] ] putsLog [ format "%-10s %-10s %-s" " " "uri: " [ string trim $uri ] ] #putsLog [ format "%-10s %-10s %-s" " " "target:" [ string trim $target ] ] putsLog [ format "%-10s %-10s %-s" " " "target:" $localVirtualHost ] unset module unset uri unset target } server { regexp {.+:(.+)uri: ([^ ]+) .+: ([^ ]+)} $i a module uri target putsLog [ format "%-5s %-10s %-s" " " "module:" [ string trim $module ] ] putsLog [ format "%-10s %-10s %-s" " " "uri: " [ string trim $uri ] ] putsLog [ format "%-10s %-10s %-s" " " "target:" $serverName ] # if the target deployment environment is a server and not a cluster return the mappings. if { $serverIsCluster == "true" } { set continue true } else { set module [ list module [ string trim $module ] ] set uri [ list uri [ string trim $uri ] ] set target [ list target [ string trim $serverName ] ] lappend resRefList [ list $module $uri $target ] } unset module unset uri unset target } default { putsLog [ format "%-5s %-s" " " "####### no match #########" ] } } } if { [ info exist resRefList ] == 1 } { return $resRefList } } #################################################################### # Get the map web module to server list. #################################################################### proc mapServerMod { PropertyI resRefList } { global AdminControl global AdminConfig variable serverName set procName [ lindex [ info level 0 ] 0 ] putsLog "## proc - $procName" foreach i [ info args $procName ] { upvar 0 $i ilocal set propertiesArray($i) $ilocal } putsLog "properties are.................." foreach { a b } [ array get propertiesArray ] { putsLog [ format "%-35s %s" "$a" "$b" ] } set cellName [ $AdminControl getCell ] # get the node name for the target server if { [ catch { $AdminConfig getid /Server:$serverName/ } r ] == 0 } { set serverId $r } else { putsLog "ERROR: $serverName does not exist" return -code error $r } regexp {(.*nodes\/)(.*)(\/servers.*)} $serverId a b c d set nodeId [ $AdminConfig getid /Node:$c/ ] set nodeName [ $AdminConfig showAttribute $nodeId name ] set serverString "WebSphere:cell=$cellName,node=$nodeName,server=$serverName" foreach i $resRefList { array set moduleArray [ eval concat $i ] lappend resRefReturnList [ list $moduleArray(module) $moduleArray(uri) $serverString ] } return $resRefReturnList } #################################################################### # Get the resource reference list. #################################################################### proc MapResRefToEJB { PropertyI resRefList } { global AdminControl set procName [ lindex [ info level 0 ] 0 ] putsLog "## proc - $procName" foreach i [ info args $procName ] { upvar 0 $i ilocal set propertiesArray($i) $ilocal } putsLog "properties are.................." foreach { a b } [ array get propertiesArray ] { putsLog [ format "%-35s %s" "$a" "$b" ] } set jndi [ string trim [ $PropertyI getProperty jndi ] ] set jndiNet [ string trim [ $PropertyI getProperty jndiNet ] ] # use the wild card mapping set the foreach i $resRefList { #puts " i = $i" array set moduleArray [ eval concat $i ] append mappingString $moduleArray(module) append mappingString " .* .* .* .* " #append mappingString $moduleArray(jndi) if { $moduleArray(resRefType) == "javax.sql.DataSource" } { append mappingString $jndi } elseif { $moduleArray(resRefType) == "java.net.URL" } { append mappingString $jndiNet } else { append mappingString $moduleArray(jndi) } lappend resRefReturnList $mappingString puts $mappingString unset mappingString } return $resRefReturnList } #################################################################### # Install the applicaton. #################################################################### proc installApplication { earFile optionList } { global AdminApp global AdminControl set procName [ lindex [ info level 0 ] 0 ] putsLog "## proc - $procName" foreach i [ info args $procName ] { upvar 0 $i ilocal set propertiesArray($i) $ilocal } putsLog "properties are.................." foreach { a b } [ array get propertiesArray ] { putsLog [ format "%-35s %s" "$a" "$b" ] } if { [ catch { $AdminApp install $earFile $optionList } result_var] == 0 } { putsLog $result_var #putsLog "$appName deployed sucessfully" } else { putsLog $result_var #putsLog "ERROR: $appName failed to deploy" return -code error $result_var } } ###################################################### # Proc - modify enterprise app. # Modify the enterprise app settings after the application has been installed. ###################################################### proc modifyEnterpriseApp { PropertyI appName } { global AdminConfig global AdminApp global AdminControl set procName [ lindex [ info level 0 ] 0 ] putsLog "## proc - $procName" foreach i [ info args $procName ] { upvar 0 $i ilocal set propertiesArray($i) $ilocal } putsLog "properties are.................." foreach { a b } [ array get propertiesArray ] { putsLog [ format "%-35s %s" "$a" "$b" ] } set appId [ $AdminConfig getid /Deployment:$appName ] if { $appId == {} } { putsLog "ERROR: $appName is not installed" return -code error } # get deployed object characteristics. set depObject [ $AdminConfig showAttribute $appId deployedObject ] # set new attributes. set aArray(newWarClassLoaderPolicy) [ $PropertyI getProperty classLoader.newWarClassLoaderPolicy ] set aArray(newWarClassLoaderMode) [ $PropertyI getProperty classLoader.newWarClassLoaderMode ] set aArray(reloadEnabled) [ $PropertyI getProperty classLoader.reloadEnabled ] set aArray(classloaderAttr) [ $PropertyI getProperty classLoader.classloaderAttr ] set aArray(newAllowSerializedSessionAccess) [ $PropertyI getProperty sessionManagement.newAllowSerializedSessionAccess ] set aArray(newAccessSessionOnTimeOut) [ $PropertyI getProperty sessionManagement.newAccessSessionOnTimeOut ] set aArray(newMaxWaitTime) [ $PropertyI getProperty sessionManagement.newMaxWaitTime ] set aArray(allowOverflow) [ $PropertyI getProperty sessionManagement.allowOverflow ] set aArray(invalidationTimeout) [ $PropertyI getProperty sessionManagement.invalidationTimeout ] set aArray(maxInMemorySessionCount) [ $PropertyI getProperty sessionManagement.maxInMemorySessionCount ] # modify the class loader attributes set classloaderId [ $AdminConfig showAttribute $depObject classloader ] if { [ catch { $AdminConfig modify $classloaderId [ list $aArray(classloaderAttr) ] } r ] == 0 } { putsLog "Class loader properties are............." set classloaderProps [ $AdminConfig showAttribute $classloaderId mode ] putsLog [ format "%-5s %s" " " $classloaderProps ] } else { putsLog "ERROR: failed to modify class loader properties" return -code error $r } #modify the war classloader proerties set attributes [ list $aArray(newWarClassLoaderPolicy) \ $aArray(reloadEnabled) \ ] if { [ catch { $AdminConfig modify $depObject $attributes } r ] == 0 } { # puts $result_var set warClassLoader [ $AdminConfig showAttribute $depObject warClassLoaderPolicy ] set reloadEnabled [ $AdminConfig showAttribute $depObject reloadEnabled ] set reloadInterval [ $AdminConfig showAttribute $depObject reloadInterval ] putsLog "WAR class loader properties are............." putsLog [ format "%-5s %s" " " $warClassLoader ] putsLog [ format "%-5s %s" " " $reloadEnabled ] putsLog [ format "%-5s %s" " " $reloadInterval ] } else { putsLog "ERROR: $appName - Modification failed" return -code error $r } #modify the war classloader mode # WAS 6.1 only. Commented out for WAS 5.1. set moduleList [ $AdminConfig showAttribute $depObject modules ] #foreach i $moduleList { # if { [ catch { $AdminConfig modify $i [ list $aArray(newWarClassLoaderMode) ] } r ] == 0 } { # putsLog "new war module classloader mode is............." # set newWarClassLoaderMode [ $AdminConfig showAttribute $i classloaderMode ] # putsLog [ format "%-5s %s" " " $newWarClassLoaderMode ] # } else { # putsLog "ERROR: failed to modify war classloader mode properties" # return -code error $r # } #} # modify the session parameters set tuningParamsList [ list $aArray(allowOverflow) \ $aArray(invalidationTimeout) \ $aArray(maxInMemorySessionCount) \ ] set tuningParams [ list tuningParams $tuningParamsList ] set sessionManagerAttr [ list $aArray(newAllowSerializedSessionAccess) \ $aArray(newAccessSessionOnTimeOut) \ $aArray(newMaxWaitTime) \ $tuningParams \ ] set newSessionManagement [ list [ list sessionManagement $sessionManagerAttr ] ] if { [ catch { $AdminConfig create ApplicationConfig $depObject $newSessionManagement } r ] == 0 } { putsLog "New Session Manager Attributes for $appName are:" foreach i $sessionManagerAttr { foreach { a b } $i { putsLog [ format "%-5s %-30s %s" " " $a $b ] } } } else { putsLog "ERROR: failed to modify class loader properties" return -code error $r } } }