##################################################################################
# Common Variables Section
# The variables defined below are shared global variables used throughout the procedures. Only
# procedures that define them using a Global statement can see them.
#
##################################################################################
#Include Application specific setttings sourced from application.jacl
#
############################################################################
set CURR_DIR [exec /usr/bin/pwd]
set nodeName [exec /usr/bin/hostname]
#set OUTPUT [open /tmp/was5deploylog.txt w]
set CELL [$AdminControl getCell]
#Define Directories
set SOURCE_DIRECTORY $CURR_DIR
##################################################################################
# Start main processing Procedures
##################################################################################
##################################################################################
# Description: This procedure acts as a wrapper procedure which calls the functionality to deploy the
# complete application and performs necessary error handling and logging.
#
##################################################################################
proc deployAll {} {
global AdminConfig NODE errorInfo OUTPUT
if [catch {deployAllMain} Output ] {
log $errorInfo
log "Application deployment to node $NODE failed. Please review logs files for errors"
set rc 1
} else {
set rc 0
}
log "Finished Deployment Process at [exec date]"
if {$OUTPUT != "stdout"} {
close $OUTPUT
}
exit $rc
}
##################################################################################
# Description: This procedure acts as a wrapper procedure which calls the functionality to deploy the
# complete application and performs necessary error handling and logging.
#
##################################################################################
proc deployApponly {} {
global AdminConfig NODE errorInfo OUTPUT
if [catch {deployApponlyMain} Output ] {
log $errorInfo
log "Application deployment to node $NODE failed. Please review logs files for errors"
set rc 1
} else {
set rc 0
}
log "Finished Deployment Process at [exec date]"
if {$OUTPUT != "stdout"} {
close $OUTPUT
}
exit $rc
}
##################################################################################
# Description: This procedure acts as a process flow procedure for deploying an application.
##################################################################################
proc deployAllMain {} {
global AdminConfig NODE
stopServerMain
removeAllMain
createAllMain
saveConfig
#regenPlugin
set message "Application has been configured on the Websphere Deployment Mangager."
append message "Websphere will now distribute the application to the correct servers."
log $message
startAfterDeploy
}
##################################################################################
#Description: This procedure acts as a process flow procedure for deploying an Enterprise application.
###################################################################################
proc deployApponlyMain {} {
global AdminConfig NODE
stopServerMain
removeApp
installAppEARs
saveConfig
#regenPlugin
set message "Application has been configured on the Websphere Deployment Mangager."
append message "Websphere will now distribute the application to the correct servers."
log $message
startAfterDeploy
}
##################################################################################
# Description: This procedure acts as a wrapper procedure which calls the functionality to create the
# Websphere resource definitions and performs necessary error handling and logging.
###################################################################################
proc createAll {} {
global errorInfo
if [catch {createAllMain} Output ] {
log $errorInfo
error "createAll failed"
} else {
log "createAll was successful"
}
}
##################################################################################
# Description: This procedure acts as a process flow procedure for creating the Websphere resources.
#
##################################################################################
proc createAllMain {} {
global RESOURCE_SCOPE SHAREDLIBRARY
if {[string match $SHAREDLIBRARY "yes"]} {
createSharedLibrary
}
createServer
installAppEARs
createCluster
createClones
}
##################################################################################
# Description: This procedure acts as a wrapper procedure which calls the functionality to removethe
# Websphere resource definitions and performs necessary error handling and logging.
#
##################################################################################
proc removeAll {} {
global errorInfo
if [catch {removeAllMain} Output ] {
log $errorInfo
log "removeAll failed"
} else {
log "removeAll was successful"
}
}
##################################################################################
# Description: This procedure acts as a process flow procedure for removing the Websphere resources.
#
##################################################################################
proc removeAllMain {} {
removeApp
removeServer
removeClones
removeSharedLibrary
removeCluster
}
#################################################################################
# Description: The operation that are performed through wsadmin would go into
# WebSphere master repository
################################################################################
proc saveConfig {} {
global AdminConfig AdminControl
set procName [ lindex [ info level 0 ] 0 ]
debug "## Proc - $procName"
foreach i [ info args $procName ] {
upvar 0 $i ilocal
set propertiesArray($i) $ilocal
}
debug "Properties are.................."
foreach { a b } [ array get propertiesArray ] {
debug [ format "%-35s %s" "$a" "$b" ]
}
log "The changes that were performed will be saved"
if { [ catch { $AdminConfig save } r ] == 0 } {
log "Changes saved to repository."
} else {
log "ERROR: failed to save changes"
log $r
return -code error $r
}
if { [ $AdminConfig list NodeAgent ] == {} } {
return
} else {
# sync changes to nodes
# get a list of configured nodes
set cellId [ $AdminConfig list Cell ]
set nodeList [ $AdminConfig list Node $cellId ]
debug "Configured nodes are ......................"
foreach nodeId $nodeList {
set name [ $AdminConfig showAttribute $nodeId name ]
debug $name
lappend nameList $name
}
# all the nodes may not be running.
# get a list of running nodes.
foreach nodeName $nameList {
if {[ lsearch $nodeName *Manager* ] == 0} {
debug "Skip Manager node"
continue
}
set nodeAgentMbean [ $AdminControl queryNames type=NodeAgent,node=$nodeName,* ]
if { $nodeAgentMbean == {} } {
lappend stoppedNodeList $nodeName
} else {
lappend startedNodeList $nodeName
}
}
debug "Running nodes are ...................."
if { [ info exist startedNodeList ] == 0 } {
log "ERROR: no started nodes"
log "ERROR: at least one node must be started for sync"
return -code error $r
} else {
foreach i $startedNodeList { debug $i }
}
debug "Stopped nodes are ...................."
if { [ info exist stoppedNodeList ] == 0 } {
debug "No stopped nodes"
} else {
foreach i $stoppedNodeList { debug $i }
}
# only started nodes can be synced.
log "Syncing nodes ...................."
foreach nodeName $startedNodeList {
set nodeSyncId [ $AdminControl completeObjectName type=NodeSync,node=$nodeName,* ]
if { [ catch { $AdminControl invoke $nodeSyncId sync } r ] == 0 } {
log "$nodeName sync successfull"
debug $r
} else {
log "ERROR: $nodeName sync failed"
return -code error $r
}
}
}
}
##################################################################################
# Description: This procedure is called after the deployment has taken place. I will wait for 2 minutes and
# try to start the application server. If the application server fails to start, it will wait another 2
# minutes and then try again. It will try a total of 3 times
##################################################################################
proc startAfterDeploy {} {
global AdminConfig AdminControl AdminApp
global NODE SERVER
#################################################################
## The following code tries to start a server after application deployment.
## It will retry 5 times
#################################################################
for {set counter 1} {$counter < 5} {incr counter} {
##Wait for deployment
log "Waiting 2 minutes for Websphere to distribute the application"
set waitTime [expr 120 * 1000]
after $waitTime
log "Attempt #$counter to start Server $SERVER"
if { [ catch {startServerMain} r ] != 0 } {
set isRunning FALSE
} else {
set isRunning TRUE
break
}
}
if {[string match $isRunning "FALSE"]} {
log "After issuing start Server command, the server is still not STARTED"
return -code error $r
}
log "Successfully started server: $SERVER"
}
##################################################################################
# Description: Call resource specific procedures
# to install resources such as datasources, JMS Configuration, etc.
##################################################################################
proc installAppResources {} {
global USE_JMS USE_IMS_CONNECTOR
log " Started Installing JDBCDrivers"
installJDBCProviders
log " Started Installing Datasources"
createDataSources
log " Finished Installing Datasources"
if {[string match [string toupper $USE_JMS] "TRUE"]} {
log " Started Installing JMS Configuration"
createJMSConfigurations
log " Finished Installing JMS Configuration"
}
if {[string match [string toupper $USE_IMS_CONNECTOR] "TRUE"]} {
log " Started Installing IMS Configuration"
createIMSConnectionFactories
log " Finished Installing IMS Configuration"
}
}
###################################################################################
# InstallJDBCProviders
##################################################################################
proc installJDBCProviders {} {
global AdminConfig RESOURCE_SCOPE SERVER NODE CELL JDBC_PROVIDER
global DB2UNIVERSAL_JDBC_DRIVER_PATH DB2UNIVERSAL_JDBC_DRIVER_NATIVEPATH
##Get scope for this data source
if {[string match $RESOURCE_SCOPE "CELL"]} {
debug " Installing JDBC Driver at CELL"
set parentString "/Cell:$CELL/"
}
if {[string match $RESOURCE_SCOPE "NODE"]} {
debug " Installing JDBC Driver at NODE"
set parentString "/Cell:$CELL/Node:$NODE/"
}
if {[string match $RESOURCE_SCOPE "SERVER"]} {
debug " Installing JDBC Driver at Server"
set parentString "/Cell:$CELL/Node:$NODE/Server:$SERVER/"
}
set objectLevel [$AdminConfig getid $parentString]
set name [findPropertyValue $JDBC_PROVIDER "name"]
if {[isJDBCDriverInstalled $name]} {
log " JDBC Driver $name already exists."
} else {
log " Started installing the JDBC Driver for $SERVER at $RESOURCE_SCOPE level"
$AdminConfig create JDBCProvider $objectLevel $JDBC_PROVIDER
log " Finished installing JDBC Driver $name at $RESOURCE_SCOPE level."
}
# Edit the DB2 variables at node level
log " Set DB2 WebSphere Variables"
set vm [$AdminConfig getid ${parentString}VariableMap:/]
set vmEntryList [$AdminConfig list VariableSubstitutionEntry $vm]
foreach vmEntryID $vmEntryList {
set vname [$AdminConfig showAttribute $vmEntryID symbolicName]
#print "Variable Name is " + vname
if { $vname == "DB2UNIVERSAL_JDBC_DRIVER_PATH"} {
log " Modifying Node level DB2 Variable $vname"
$AdminConfig modify $vmEntryID [subst {{value "$DB2UNIVERSAL_JDBC_DRIVER_PATH"}}]
#vvalue = AdminConfig.showAttribute(vmEntryID, "value")
#print " Value is " + vvalue
continue
}
if { $vname == "DB2UNIVERSAL_JDBC_DRIVER_NATIVEPATH"} {
log " Modifying Node level DB2 Variable $vname"
$AdminConfig modify $vmEntryID [subst {{value "$DB2UNIVERSAL_JDBC_DRIVER_NATIVEPATH"}}]
#vvalue = AdminConfig.showAttribute(vmEntryID, "value")
#print " Value is " + vvalue
}
}
}
##################################################################################
# Description: This procedure will remove a JDBC Driver.
##################################################################################
proc removeJDBCProviders {} {
global AdminConfig JDBC_PROVIDER
set name [findPropertyValue $JDBC_PROVIDER "name"]
# puts $name
set jdbcObjectID [getJDBCDriverID $name]
# puts $jdbcObjectID
log " Started removing JDBC Driver: $jdbcObjectID"
if {[isJDBCDriverInstalled $name]} {
$AdminConfig remove $jdbcObjectID
log " Finished removing JDBC Driver: $jdbcObjectID"
} else {
log " JDBC Driver $name is not installed."
}
}
##################################################################################
# Procedure Name: getJDBCDriverID
# Description: This procedure will return the object configuration id for a JDBC Driver
#
##################################################################################
proc getJDBCDriverID {name} {
global AdminConfig CELL NODE SERVER RESOURCE_SCOPE
##Get scope for this data source
if {[string match $RESOURCE_SCOPE "CELL"]} {
debug "Checking for JDBC Driver at CELL"
set parentString "/Cell:$CELL/"
}
if {[string match $RESOURCE_SCOPE "NODE"]} {
debug "Checking for JDBC Driver at NODE"
set parentString "/Cell:$CELL/Node:$NODE/"
}
if {[string match $RESOURCE_SCOPE "SERVER"]} {
debug "Checking for JDBC Driver at SERVER"
set parentString "/Cell:$CELL/Node:$NODE/Server:$SERVER/"
}
set jdbcObject "${parentString}JDBCProvider:$name/"
set jdbcObjectID [$AdminConfig getid $jdbcObject]
return $jdbcObjectID
}
##################################################################################
# Description: This procedure checks to see if a JDBC driver is installed.
##################################################################################
proc isJDBCDriverInstalled {name} {
set jdbcObjectID [getJDBCDriverID $name]
#set jdbcObjectID $name
return [expr [isNULL $jdbcObjectID] == 0]
}
##################################################################################
# Description: Call resource specific procedures
# to remove resources such as datasources, JMS Configuration, etc.
##################################################################################
proc removeAppResources {} {
global USE_JMS USE_IMS_CONNECTOR
log "Started Removing Datasources"
removeDataSources
# Don't remove jdbc provider if exits. Used by other apps.
#log "Started Removing JDBCDrivers"
#removeJDBCProviders
log "Finished Removing Datasources"
if {[string match [string toupper $USE_JMS] "TRUE"]} {
log "Started Removing JMS Configuration"
removeJMSConfigurations
log "Finished Removing JMS Configuration"
}
if {[string match [string toupper $USE_IMS_CONNECTOR] "TRUE"]} {
log "Started Removing IMS Configuration"
removeIMSConnectionFactories
log "Finished Removing IMS Configuration"
}
}
##################################################################################
# End main processing Procedures
##################################################################################
#################################################################################
# Description: This procedure checks if the datasource and JDBC drivers are installed
# and creates them if not installed
###############################################################################
proc createDataSources {} {
global AdminConfig CELL SERVER NODE RESOURCE_SCOPE JDBC_PROVIDER
global DSDESC DBCPNAME DBJNDINAME DBSTATEMENTCACHESIZE DBMAXCONNECTIONS
global DBMINCONNECTIONS DBUSERNAME DBPASSWD DBNAME
global DBDRIVERTYPE DBSERVERNAME DBPORTNUMBER
global APPNAME SYSPLEX maxTO
set dataSourceName $DBCPNAME
set dataSourceID [getDataSourceID $dataSourceName]
set jdbcDriverName [findPropertyValue $JDBC_PROVIDER "name"]
# Check whether the JDBC driver is installed first
if {[isJDBCDriverInstalled $jdbcDriverName]} {
log " Started installing WAS Data Source: $dataSourceName"
# Check whether the DataSource already exist
if {![isDataSourceInstalled $DBNAME]} {
if {[string match $RESOURCE_SCOPE "CELL"]} {
debug " Installing Data Source definition at CELL scope"
set parentString "/Cell:$CELL/JDBCProvider:$jdbcDriverName/"
}
if {[string match $RESOURCE_SCOPE "NODE"]} {
debug " Installing Data Source definition at NODE scope"
set parentString "/Cell:$CELL/Node:$NODE/JDBCProvider:$jdbcDriverName/"
}
if {[string match $RESOURCE_SCOPE "SERVER"]} {
debug " Installing Data Source definition at SERVER scope"
set parentString "/Cell:$CELL/Node:$NODE/Server:$SERVER/JDBCProvider:$jdbcDriverName/"
}
set objectLevelID [$AdminConfig getid $parentString]
####################################################################
# Create DB connection Id.
# Must exist before assignment to datasource.
####################################################################
set alias "$NODE"
append alias "/" "$DBCPNAME" "_CI"
log " Alias for connection id is set to $alias"
set userid $DBUSERNAME
set password $DBPASSWD
set description "DB2 Connection ID for $APPNAME"
# set up general properties
set authDataAliasList [list authDataAlias $alias]
set authMechanismPreferenceList [list authMechanismPreference BASIC_PASSWORD]
set descriptionList [list description "$DSDESC"]
set nameList [list name "$DBCPNAME"]
set jndiNameList [list jndiName "$DBJNDINAME"]
set providerList [list provider "$objectLevelID"]
set statementCacheSizeList [list statementCacheSize "$DBSTATEMENTCACHESIZE"]
set datasourceHelperClassnameList [list datasourceHelperClassname com.ibm.websphere.rsadapter.DB2UniversalDataStoreHelper]
# set up connection pool
set agedTimeout [list agedTimeout 1800 ]
set connectionTimeout [list connectionTimeout 1800 ]
set maxConnections [list maxConnections "$DBMAXCONNECTIONS"]
set minConnections [list minConnections "$DBMINCONNECTIONS"]
set purgePolicy [list purgePolicy EntirePool ]
set reapTime [list reapTime 180 ]
set unusedTimeout [list unusedTimeout 1800 ]
set connectionPoolList [list $agedTimeout \
$connectionTimeout \
$maxConnections \
$minConnections \
$purgePolicy \
$reapTime \
$unusedTimeout \
]
# set up mapping properties
set authDataAliasList [ list authDataAlias $alias ]
set mappingConfigAliasList [ list mappingConfigAlias DefaultPrincipalMapping ]
set mappingList [ list $authDataAliasList $mappingConfigAliasList]
createSecurityObj $alias $userid $password $description
# set up custom properties
#set user_attr [list [list name user] [list value $DBUSERNAME] [list type java.lang.String]]
#set password_attr [list [list name password] [list value $DBPASSWD] [list type java.lang.String]]
set dbName_attr [list [list name databaseName] [list value $DBNAME] [list type java.lang.String]]
set dbDriverType_attr [list [list name driverType] [list value $DBDRIVERTYPE] [list type java.lang.Integer]]
if { $DBDRIVERTYPE == 4 } {
set dbServerName_attr [list [list name serverName] [list value $DBSERVERNAME] [list type java.lang.String]]
set dbPortNumber_attr [list [list name portNumber] [list value $DBPORTNUMBER] [list type java.lang.String]]
set dbSysplex [list [list name enableSysplexWLB] [list value $SYSPLEX] [list type java.lang.Boolean]]
set dbSysplexMaxTO [list [list name maxTransportObjects] [list value $maxTO] [list type java.lang.Integer]]
set newprops [list $dbName_attr $dbDriverType_attr $dbServerName_attr $dbPortNumber_attr $dbSysplex $dbSysplexMaxTO]
#set newprops [list $dbName_attr $dbDriverType_attr $dbServerName_attr $dbPortNumber_attr]
} else {
set newprops [list $dbName_attr $dbDriverType_attr ]
}
set resprops [list resourceProperties $newprops]
#set resprops [list resourceProperties $dbName_attr]
set attrs [list $nameList \
$jndiNameList \
$descriptionList \
$authDataAliasList \
$authMechanismPreferenceList \
$statementCacheSizeList \
$datasourceHelperClassnameList \
$providerList \
[ list mapping $mappingList ] \
[ list connectionPool $connectionPoolList ] \
[ list propertySet [list $resprops]] \
]
set newDataSource [$AdminConfig create DataSource $objectLevelID $attrs]
log " Installed the WAS datasource $dataSourceName for $SERVER using $jdbcDriverName as the JDBC provider"
} else {
log " DataSource $dataSourceName already exist. Please remove first"
}
}
}
####################################################################
# Create Security Object for database connection.
####################################################################
proc createSecurityObj {alias userid password description} {
log " Create Security Object"
global AdminConfig
debug "\nList installed JAASAuthData authentication entries\n"
set JAASentries [ $AdminConfig list JAASAuthData ]
foreach e $JAASentries {
set subList [ $AdminConfig show $e ]
foreach e $subList {
debug [ format "%-5s %-30s %-20s" " " [ lindex $e 0 ] [ lindex $e 1 ] ]
}
debug "\n"
}
log " remove duplicate entries if any"
set i 0
while { $i < [llength $JAASentries] } {
debug " index is [ lindex [ $AdminConfig show [lindex $JAASentries $i ] ] 0 ]"
catch { lsearch [ lindex [ $AdminConfig show [lindex $JAASentries $i ] ] 0 ] $alias } r
if { $r == -1 } {
debug " no match for $alias"
} else {
log " **** Delete $alias ****"
catch { $AdminConfig remove [ lindex $JAASentries $i ] } r
log $r
}
incr i
}
# set attributes for userid
set alias [list alias $alias ]
set description [list description $description ]
set userid [list userId $userid ]
set password [list password $password ]
set jaasAttrs [list $alias $description $userid $password]
# create JAASAuthData object under security parent
$AdminConfig create JAASAuthData [$AdminConfig list Security] $jaasAttrs
log " List installed JAASAuthData authentication entries - confirming change"
foreach e [ $AdminConfig list JAASAuthData ] {
set subList [ $AdminConfig show $e ]
foreach e $subList {
log [ format "%-5s %-30s %-20s" " " [ lindex $e 0 ] [ lindex $e 1 ] ]
}
log "\n"
}
}
####################################################################
# List JAAS authentication entries.
####################################################################
proc listJAAS {} {
global AdminConfig
set JAASentries [ $AdminConfig list JAASAuthData ]
foreach e $JAASentries {
set subList [ $AdminConfig show $e ]
log $subList
#foreach e $subList {
# log [ format "%-5s %-30s %-20s" " " [ lindex $e 0 ] [ lindex $e 1 ] ]
#}
log "\n"
}
}
##################################################################################
# Description: This procedure will return Websphere ID for the datasource name passed in.
##################################################################################
proc getDataSourceID {dataSourceName} {
global AdminConfig
debug "Enter getDataSourceID"
set list [$AdminConfig list DataSource]
foreach dataSource $list {
if {[regexp $dataSourceName $dataSource==1]} {
debug "Exit getDataSourceID"
return $dataSource
}
}
debug "Exit getDataSourceID"
}
##################################################################################
# Description: Determines if the data source is installed. Returns '1' if server
# installed else '0'
##################################################################################
proc isDataSourceInstalled {dataSourceName} {
global AdminConfig
set dataSourceID [getDataSourceID $dataSourceName]
set dataSourceList [$AdminConfig list DataSource]
return [expr [lsearch -exact $dataSourceList $dataSourceID] != -1]
}
##################################################################################
# Description: This procedure will remove the datasource installed for a given application.
##################################################################################
proc removeDataSources {} {
global AdminConfig APPSERVER_NAME DBCPNAME
set dataSourceName $DBCPNAME
set dataSourceID [getDataSourceID $dataSourceName]
removeDataSource $dataSourceID $dataSourceName
}
##################################################################################
# Description: This procedure will remove a data source
##################################################################################
proc removeDataSource {dataSourceId dataSourceName} {
global AdminConfig
debug "Datasource id = $dataSourceId"
if {[isDataSourceInstalled $dataSourceName]} {
log " Started removing Data Source: $dataSourceId"
$AdminConfig remove $dataSourceId
log " Finished removing Data Source: $dataSourceId."
} else {
log " DataSource $dataSourceName is not installed."
}
}
#################################################################################
# Start Enterprise Application(EAR) Procedures
##################################################################################
##################################################################################
# Description: Determines if the Enterprise Application is installed. Returns
# '1' if application installed else '0'
##################################################################################
proc isAppInstalled {appName} {
global AdminApp
set app_list [$AdminApp list]
return [expr [lsearch -exact $app_list $appName] != -1]
}
##################################################################################
# Description: Determines if the server is running. Returns '1' if server running else 0.
##################################################################################
proc isAppRunning {appName} {
global $AdminControl
set runningApp [$AdminControl completeObjectName type=Application,name=$appName,*]
return [expr {$runningApp != "" } ]
}
##################################################################################
# Description: Stops the Enterprise application. If the Enterprise Application is not
# installed, a message stating "Enterprise Application not installed."
# will get displayed and the script will stop processing. If the
# Enterprise Application is installed but is not running, the message
# "Enterprise Application already stopped." and the script continues.
##################################################################################
proc stopApp {appName} {
global AdminControl
if [ isAppInstalled ] {
if [ isAppRunning ] {
$AdminControl invoke $appManager stopApplication $appName
log "Enterprise Application $determined_app_name stopped."
} else {
log "Enterprise Application $determined_app_name already stopped."
}
} else {
error "Enterprise Application $determined_app_name not installed."
}
}
##################################################################################
# Procedure Name: startApp
# Description: Starts the Enterprise Application. If the Enterprise Application is not
# installed, a message stating "Enterprise Application not installed."
# will get displayed and the script will stop processing. If the
# Enterprise Application is installed but running, the message
# "Enterprise Application already started." and the script continue.
#
##################################################################################
proc startApp {} {
global AdminControl
if [ isAppInstalled ] {
if ![ isAppRunning ] {
$AdminControl invoke $appManager startApplication myApplication
log "Enterprise Application $determined_app_name started."
} else {
log "Enterprise Application $determined_app_name already started."
}
} else {
error "Enterprise Application $determined_app_name not installed."
}
}
##################################################################################
# Description: Removes the Enterprise Applications. If the
# application is installed but running, an error will be raised with
# the message "Please stop Enterprise Application first."
# and the script will stop.
##################################################################################
proc removeApp {} {
global AdminApp APPSERVER_NAME SERVER APP_NAME
if [ isServerRunning ] {
error "Please stop $SERVER server first."
} else {
#for {set counter 1} {$counter < 10} {incr counter} {
# set appName ""
# append appName $APP_NAME "_" $counter
# if {[isAppInstalled $appName]} {
# log "Started removing application $appName"
# $AdminApp uninstall $appName
# log "Finished removing application $appName"
# } # else {
# #break
# #}
#}
if {[isAppInstalled $APP_NAME]} {
log "Started removing application $APP_NAME"
$AdminApp uninstall $APP_NAME
log "Finished removing application $APP_NAME"
}
}
}
##################################################################################
# Description: This procedure will install an EAR into an existing server.
##################################################################################
proc installEAR {filename appName} {
global AdminConfig AdminControl AdminApp
global NODE SERVER VIRTUAL APPSERVER_NAME INSTALL_DIRECTORY APP_NAME CELL CLUSTER
global PRECOMPILE_JSPS GENERATE_EJB_CODE ENABLE_RELOADING DBJNDINAME APP_NAME_UP
if {[isAppInstalled $appName]} {
error "Application $appName is already installed. Please remove first"
}
if {[string match "TRUE" [string toupper $PRECOMPILE_JSPS]]} {
set preCompileFlag "preCompileJSPs"
} else {
set preCompileFlag "nopreCompileJSPs"
}
set GENERATE_EJB_CODE "FALSE"
if {[string match "TRUE" [string toupper $GENERATE_EJB_CODE]]} {
set generateEJBCodeFlag "deployejb"
} else {
set generateEJBCodeFlag "nodeployejb"
}
set ENABLE_RELOADING "FALSE"
if {[string match "TRUE" [string toupper $ENABLE_RELOADING]]} {
set enableReloadingFlag "reloadEnabled"
} else {
set enableReloadingFlag "noreloadEnabled"
}
set resreftoejb [list ${APP_NAME_UP} "" ${appName}.war,WEB-INF/web.xml ${APP_NAME}_db_resource javax.sql.DataSource $DBJNDINAME]
debug "resreftoejb set to $resreftoejb"
if { ![ isClusterInstalled ] } {
#set webToVHMapping [generateWebModuleToVHList $filename]
log "Installing the Ent. App $appName to server $SERVER"
catch { $AdminApp install $filename " -node $NODE -server $SERVER -appname $appName -$preCompileFlag -distributeApp -$generateEJBCodeFlag -createMBeansForResources -$enableReloadingFlag"} r
log $r
#set resreftoejb2 [list ${APP_NAME_UP} ${appName}.war,WEB-INF/web.xml WebSphere:cell=$CELL,node=$NODE,server=$SERVER]
#set appattrs [list -MapResRefToEJB [list $resreftoejb] -MapModulesToServers [list $resreftoejb2] -node $NODE -server $SERVER -appname $appName -$preCompileFlag -distributeApp -$generateEJBCodeFlag -createMBeansForResources -$enableReloadingFlag -usedefaultbindings -deployws]
}
if [ isClusterInstalled ] {
#set webToVHMapping [generateWebModuleToVHList $filename]
log "Installing the Ent. App $appName to cluster $CLUSTER"
catch {$AdminApp install $filename " -cell $CELL -cluster $CLUSTER -appname $appName -$preCompileFlag -distributeApp -$generateEJBCodeFlag -createMBeansForResources -$enableReloadingFlag"} r
log $r
#set resreftoejb2 [list ${APP_NAME_UP} ${appName}.war,WEB-INF/web.xml WebSphere:cell=$CELL,node=$NODE,cluster=$CLUSTER]
#set appattrs [list -MapResRefToEJB [list $resreftoejb] -MapModulesToServers [list $resreftoejb2] -cell $CELL -cluster $CLUSTER -appname $appName -$preCompileFlag -distributeApp -$generateEJBCodeFlag -createMBeansForResources -$enableReloadingFlag -usedefaultbindings -deployws]
}
#debug "appattrs is $appattrs"
#debug "filename is $filename"
#catch { $AdminApp install $filename $appattrs} r
#log $r
}
##################################################################################
# Description: This procedure will get a list of ears located in the application project space and install each
# of them. It appends the properties directory at root of each EAR to JVM classpath. It also
# configures any settings on the application.
##################################################################################
proc installAppEARs {} {
global SOURCE_DIRECTORY APPSERVER_NAME APP_NAME
##append earList [getListOfEARS $SOURCE_DIRECTORY]
##set counter 1
##log "The following ears will get installed: $earList"
##foreach ear $earList {
## set appName ""
## append appName $APP_NAME "_" $counter
## installEAR $ear $appName
## addPropertiesDirToJVM $appName
## incr counter
##}
set ear ""
append ear $APP_NAME ".ear"
installEAR $ear $APP_NAME
return
}
#################################################################################
# End Enterprise Application(EAR) Procedures
##################################################################################
#################################################################################
# Start Application Server Procedures
##################################################################################
##################################################################################
# Description: This procedures create an application server definition based on settings either using the
# default values specified in procedure setDefaultValuesForGlobalVariables, in mainproc.jacl, or
# application specified values provided in application.jacl
###################################################################################
proc createServer {} {
global AdminConfig AdminControl AdminApp
#Global variable defined in common.jacl
global NODE SERVER STDOUT STDERR
global SERVER_ARGS WORKING_DIRECTORY
#Global variable defined in main.jacl
global INITIAL_HEAP_SIZE ENGINE_PORT MAX_HEAP_SIZE INITIAL_STATE
global APPSERVER_NAME
#Global variable defined in application.jacl
global SYSTEM_PROPERTIES VERBOSE_GC_ON MAX_WEB_CONTAINER_CONNECTIONS
global MAX_HTTP_SESSIONS SESSION_INVALIDATION_TIME MAX_EJB_CACHE_SIZE
global SERVER_CLASSLOADER_POLICY SERVER_CLASSLOADER_MODE TRAN_TIMEOUT
global ENVIRONMENT NONSTANDARD_CLASSPATHS EIPPATH ECLIENTHOME
global INTLIB CMCOMMON DB2ZIPFILE MAXSTART AUTORESTART RESTARTSTATE
global PINGINT PINGTIMEOUT PROCPRIORITY TRANTIMEOUT TRANINACTIVETO
global THREADISGROWABLE THREADINACTTO THREADMINSIZE THREADMAXSIZE
global ALLOW_OVERFLOW COOKIEMAXAGE COOKIENAME
global TRANMAXKA TRANMAXKAR TRANBACKLOG TRANCONCIOTO TRANCONCKSTO
global ProcessDef_IBMCMROOT libName jvmClassPath
#append adjusted_System_Properties " " "{APPSERVER_NAME $APPSERVER_NAME}"
log "Started Creating Application Server $SERVER."
if ![ isServerInstalled ] {
set nodeID [$AdminConfig getid /Node:$NODE/]
set host [$AdminControl getHost]
debug "(createServer) Hostname= $host"
set name_attribute [list name $SERVER]
set attributes [list $name_attribute]
set id [$AdminConfig create Server $nodeID $attributes]
debug "(createServer) New Server = $id"
#set transactionservice
set TransactionServiceId [$AdminConfig list TransactionService $id]
$AdminConfig modify $TransactionServiceId [subst {{clientInactivityTimeout "$TRANTIMEOUT"} {totalTranLifetimeTimeout "$TRANINACTIVETO"}}]
#Modify Process Definition Attributes
set processDefID [$AdminConfig list ProcessDef $id ]
$AdminConfig modify $processDefID [subst {{workingDirectory "$WORKING_DIRECTORY"}}]
# get any exiting name value pairs from ProcessDef environment
set existing [$AdminConfig showAttribute $processDefID environment]
# remove {}
set existing [lindex $existing 0]
# replace space delimited with lf
regsub -all " " $existing "\n" existing
foreach item $existing {
$AdminConfig remove $item
}
$AdminConfig modify $processDefID [subst {{environment {{{name "IBMCMROOT"} {value "$ProcessDef_IBMCMROOT"}}}}}]
#Modify Process Execution Attributes
set processExecutionID [$AdminConfig list ProcessExecution $id ]
$AdminConfig modify $processExecutionID [subst {{runAsGroup ""} {runAsUser ""} {processPriority "$PROCPRIORITY"}}]
#Modify Monitoring Policy Attributes
set monitoringPolicyID [$AdminConfig list MonitoringPolicy $id ]
$AdminConfig modify $monitoringPolicyID [subst {{maximumStartupAttempts "$MAXSTART"} {autoRestart "$AUTORESTART"} {nodeRestartState "$RESTARTSTATE"} {pingInterval "$PINGINT"} {pingTimeout "$PINGTIMEOUT"}}]
#Modify Web Container Thread Pool attributes
set threadPoolList [$AdminConfig list ThreadPool $id]
debug "(createServer) threadPoolList is $threadPoolList"
set oI [lsearch -glob $threadPoolList "*WebContainer*"]
set threadPoolID [lindex $threadPoolList $oI]
debug "(createServer) threadPoolID is $threadPoolID"
$AdminConfig modify $threadPoolID [subst {{minimumSize "$THREADMINSIZE"} {maximumSize "$THREADMAXSIZE"} {inactivityTimeout "$THREADINACTTO"} {isGrowable "$THREADISGROWABLE"}}]
#Modify Session Manager attributes
set sessionManagerID [$AdminConfig list SessionManager $id ]
$AdminConfig modify $sessionManagerID [subst {{defaultCookieSettings {{maximumAge "$COOKIEMAXAGE"}{name "$COOKIENAME"}{path /}{secure false}}}{enableCookies true}}]
set tuningParamsID [$AdminConfig list TuningParams $id ]
$AdminConfig modify $tuningParamsID [subst {{allowOverflow "$ALLOW_OVERFLOW"} {invalidationTimeout "$SESSION_INVALIDATION_TIME"} {maxInMemorySessionCount "$MAX_HTTP_SESSIONS"} {scheduleInvalidation "false"}}]
#Modify JVM attributes
set jvmID [$AdminConfig list JavaVirtualMachine $id ]
$AdminConfig modify $jvmID [subst {{bootClasspath ""} {classpath "$jvmClassPath"} {debugMode "false"} {disableJIT "false"} {hprofArguments ""} {initialHeapSize "$INITIAL_HEAP_SIZE"} {maximumHeapSize "$MAX_HEAP_SIZE"} {runHProf "false"} {verboseModeClass "false"} {verboseModeGarbageCollection "$VERBOSE_GC_ON"} {verboseModeJNI "false"}}]
#--------------------------------------------------------------
# Identify the application server from the server and assign it to the appServer variable
#--------------------------------------------------------------
set appServer [$AdminConfig list ApplicationServer $id]
if {[isSharedLibraryInstalled $nodeID $libName] == 1} {
if {[isClassLoaderInstalled $appServer $libName] == 0} {
#--------------------------------------------------------------
# Create a new class loader
#--------------------------------------------------------------
set classLoader [$AdminConfig create Classloader $appServer {{mode PARENT_FIRST}}]
log "Creating classloader for $appServer to load $libName"
#--------------------------------------------------------------
# Associate the created shared library with the application server through the class loader.
#--------------------------------------------------------------
$AdminConfig create LibraryRef $classLoader [subst {{libraryName $libName} {sharedClassloader true}}]
}
}
#Add generic jvm args to server
setJvmArguments "$SERVER_ARGS" $NODE $SERVER
#Add additional classpaths onto JVM
foreach classpathEntry $NONSTANDARD_CLASSPATHS {
$AdminConfig modify $jvmID [subst {{classpath "$classpathEntry"}}]
}
##Add system properties onto JVM.
#append adjusted_System_Properties " " $SYSTEM_PROPERTIES
#foreach system_property $adjusted_System_Properties {
# set name [lindex $system_property 0]
# set description $name
# set value [lindex $system_property 1]
# set attrs [list "name $name" "value $value" "description $description"]
# $AdminConfig create Property $jvmID $attrs
#}
#debug "(createServer) Set jvm systemProperties"
#$AdminConfig modify $jvmID [subst {{systemProperties {{{name "LD_LIBRARY_PATH"} {value ".:/lib:/usr/lib:\$LD_LIBRARY_PATH"}} {{name "NLSPATH"} {value "/usr/lib/nls/msg/%L/%N:/usr/lib/nls/%L/%N.cat:\${NLSPATH}:$EIPPATH/msg/en_US/%N"}}}}}]
#Modify Stderr & Stdout file attributes
#Implemenation Note: I set these from the Server type instead of StreamRedirect type
# because using the StreamRedirect type did not allow me to specify by
# name(std/err) which file I was setting. I thought setting it by the
# Server type seemed clearer.
debug "(createServer) Set server logs."
debug "(createServer) stdout = $STDOUT"
debug "(createServer) stderr = $STDERR"
set serverID [$AdminConfig list Server $id ]
debug "(createServer) serverID is set to $serverID"
set log [$AdminConfig showAttribute $serverID outputStreamRedirect]
$AdminConfig modify $log [subst {{baseHour "24"} {fileName "$STDOUT"} {formatWrites "true"} {maxNumberOfBackupFiles "1"} {messageFormatKind "BASIC"} {rolloverPeriod "24"} {rolloverSize "1"} {rolloverType "NONE"} {suppressStackTrace "false"} {suppressWrites "false"}}]
set log [$AdminConfig showAttribute $serverID errorStreamRedirect]
$AdminConfig modify $log [subst {{baseHour "24"} {fileName "$STDERR"} {formatWrites "true"} {maxNumberOfBackupFiles "1"} {messageFormatKind "BASIC"} {rolloverPeriod "24"} {rolloverSize "1"} {rolloverType "NONE"} {suppressStackTrace "false"} {suppressWrites "false"}}]
##Set default trace settings
debug "(createServer) Set default trace settings."
set traceServiceID [$AdminConfig list TraceService $serverID]
$AdminConfig modify $traceServiceID {{enable true} {memoryBufferSize "300"} {startupTraceSpecification "*=all=disabled"} {traceOutputType "MEMORY_BUFFER"}}
##Set bootStrap port for Name Server
#log "Setting the Name Server port = $BOOTSTRAP_PORT"
#set nameServerID [$AdminConfig list NameServer $serverID]
#$AdminConfig modify $nameServerID [subst {{BOOTSTRAP_ADDRESS {{{port "$BOOTSTRAP_PORT"}}}}}]"
##Set SOAP Connector Port
#log "Setting the SOAP Connector port = $SOAP_CONNECTOR_PORT"
#set SOAPConnectorID [$AdminConfig list SOAPConnector $serverID]
#$AdminConfig modify $SOAPConnectorID [subst {{SOAP_CONNECTOR_ADDRESS {{{port "$SOAP_CONNECTOR_PORT"}}}}}]"
##Set default PMI settings
set PMIServiceID [$AdminConfig list PMIService $serverID]
$AdminConfig modify $PMIServiceID {{enable "true"} {initialSpecLevel beanModule=N:cacheModule=N:connectionPoolModule=M:j2cModule=N:jvmRuntimeModule=L:orbPerfModule=N:servletSessionsModule=H:systemModule=L:threadPoolModule=H:transactionModule=N:webAppModule=M:webServicesModule=N:wlmModule=N:wsgwModule=N}}
#Modify Transaction Service attributes
set transactionServiceID [$AdminConfig list TransactionService $id ]
$AdminConfig modify $transactionServiceID [subst {{totalTranLifetimeTimeout "$TRAN_TIMEOUT"}}]
#Modify Application Server attributes
#set applicationServerID [$AdminConfig list ApplicationServer $id ]
#$AdminConfig modify $applicationServerID [subst {{stateManagement {{initialState "$INITIAL_STATE"}}} {applicationClassLoaderPolicy "$SERVER_CLASSLOADER_POLICY"} {applicationClassLoadingMode "$SERVER_CLASSLOADER_MODE"}}
#Modify EJB Cache attributes
set ejbCacheID [$AdminConfig list EJBCache $id ]
$AdminConfig modify $ejbCacheID [subst {{cacheSize "$MAX_EJB_CACHE_SIZE"} {cleanupInterval "3000"}}]
log "Application Server $SERVER created."
} else {
error "Application Server $SERVER already installed."
}
}
#################################################################################
# Description: Sets JVM generic arguments on an AppServer
#################################################################################
proc setJvmArguments {jvmArguments nodeName servName} {
global AdminConfig
log "Resetting jvm genericArgs"
set server [$AdminConfig getid /Node:$nodeName/Server:$servName/]
set pd [$AdminConfig list ProcessDef $server]
set jvm [$AdminConfig list JavaVirtualMachine $pd]
set jvmargs [$AdminConfig showAttribute $jvm genericJvmArguments]
debug "(setJvmArguments) Existing jvm genericArgs are $jvmargs"
debug "(setJvmArguments) Adding jvm genericArgs are $jvmArguments"
regsub -all " " $jvmargs "\n" jvmargs
foreach item $jvmargs {
debug "(setJvmArguments) Checking for existing genericArgument $item"
set itembase ""
regsub "=.*" $item "" itembase
debug "(setJvmArguments) Item base is $itembase"
if {[lsearch $jvmArguments $itembase* ] == -1} {
debug "(setJvmArguments) JVM argument $item doesn't exist in new genericArgument list, adding."
append jvmArguments " $item"
} else {
debug "(setJvmArguments) JVM argument $item already exists in new genericArgument list"
}
}
debug "(setJvmArguments) delete existing jvm args"
$AdminConfig modify $jvm {{genericJvmArguments ""}}
debug "(setJvmArguments) Apply the new jvm args"
$AdminConfig modify $jvm [subst {{genericJvmArguments "$jvmArguments"}}]
log "jvmArguments now set to $jvmArguments"
}
#################################################################################
# Description: Creates the cluster keeping the AppServer created above
# as the model. Before attempting to create it checks whether
# AppServer and Cluster are already installed.
#################################################################################
proc createCluster {} {
global AdminConfig AdminControl
global NODE SERVER CELL CLUSTER CLONES
if { $CLONES != 0 } {
if [ isServerInstalled ] {
if { ![ isClusterInstalled ] } {
set id [$AdminConfig getid /Node:$NODE/Server:$SERVER/]
log "Attempting to create cluster: $CLUSTER"
set clusterid [$AdminConfig convertToCluster $id $CLUSTER]
log "Finished creating cluster: $CLUSTER"
} else {
log "Cluster $CLUSTER already exist. Please remove it first and try again."
}
} else {
log "Application Server $SERVER doesn't exist. Please create the Server first."
}
} else {
log "No cluster set for this environment"
}
}
#################################################################################
# Description: Creates the clones using the cluster created above.
#################################################################################
proc createClones {} {
global AdminConfig AdminControl
global NODE SERVER CELL CLUSTER CLONES JAVA_TMP_ARG JAVA_TMP
set nodeid [$AdminConfig getid /Node:$NODE/]
set clusterid [$AdminConfig getid /ServerCluster:$CLUSTER/]
# get id for first server created to use as template
set name "/Node:$NODE/Server:$SERVER/"
set id [$AdminConfig getid $name]
if { $CLONES != 0 } {
if [ isClusterInstalled ] {
for {set count 1} {$count <= $CLONES} {incr count} {
set cloneName ""
append cloneName $SERVER "_" $count
set attrs [list "memberName $cloneName"]
log "Attempting to create Clone $cloneName"
set cloneid [$AdminConfig createClusterMember $clusterid $nodeid $attrs $id]
set JAVA_TMP_CLONE ""
append JAVA_TMP_CLONE $JAVA_TMP_ARG $count
debug "Java tmp for clone $cloneName set to $JAVA_TMP_CLONE"
setJvmArguments $JAVA_TMP_CLONE $NODE $cloneName
set base_directory ""
append base_directory "$JAVA_TMP" $count
if {[file exists $base_directory]} {
debug "Directory '$base_directory' exists"
} else {
file mkdir $base_directory
debug "Created directory $base_directory"
}
log "Finished creating clone $count of $CLONES"
}
} else {
log "Cluster $CLUSTER doesn't exist. Install the cluster first."
}
} else {
log "No clones are set for this environment."
}
}
#################################################################################
# Description: This procedure checks if the shared library is installed
# and creates it if not installed
###############################################################################
proc createSharedLibrary {} {
global AdminConfig NODE libName classPath nativePath
debug "(createSharedLibrary) Entry"
set nodeId [$AdminConfig getid /Node:$NODE/]
if {[isSharedLibraryInstalled $nodeId $libName] == 0} {
log "Creating Shared Library $libName"
$AdminConfig create Library $nodeId [subst {{name "$libName"} {classPath "$classPath"} {nativePath "$nativePath"}}]
} else {
debug "(createSharedLibrary) The Shared Library $libName, already exists"
}
debug "(createSharedLibrary) Exit"
}
##################################################################################
# Description: Removes the Application Server. If the application server is not
# installed, a message stating "Application Server not installed." will get
# displayed and the script will continue to process. If the
# application server is installed but running, an error will be raised with
# the message "Please stop application server first." and the script will stop.
##################################################################################
proc removeServer {} {
global AdminConfig AdminControl AdminApp
global NODE SERVER
set name "/Node:$NODE/Server:$SERVER/"
set id [$AdminConfig getid $name]
if {[isServerInstalled]} {
if {![ isServerRunning ]} {
$AdminConfig remove $id
log "Application Server $SERVER removed."
} else {
error "Please stop Application Server $SERVER first."
}
} else {
debug "Application Server $SERVER is not installed."
}
}
##################################################################################
# Description: Removes all the Clones associated with the Cluster.
##################################################################################
proc removeClones {} {
global AdminConfig AdminControl AdminApp
global NODE SERVER CLUSTER CELL CURRENTCLONES
#In case is removeServer wasn't performed before running removeClones
#this one will make sure model AppServer is removed.
if [ isServerInstalled ] {
removeServer
}
if {[isClusterInstalled]} {
for {set count 1} {$count <= $CURRENTCLONES} {incr count} {
set cloneName ""
append cloneName $SERVER "_" $count
set name "/Node:$NODE/Server:$cloneName/"
set id [$AdminConfig getid $name]
$AdminConfig remove $id
log "Application Server/Clone $cloneName removed."
}
} else {
debug "Cluster $CLUSTER is not installed."
}
}
#################################################################################
# Description: Removes the cluster of an application. For this to work,
# all the clones associated to this cluster should have been removed
# already.
#################################################################################
proc removeCluster {} {
global AdminConfig AdminControl AdminApp
global NODE SERVER CLUSTER CELL
set id [$AdminConfig getid /ServerCluster:$CLUSTER/]
if [ isClusterInstalled ] {
log "Attempting to remove cluster $CLUSTER"
$AdminConfig remove $id
log "Finished removing cluster $CLUSTER"
} else {
debug "Cluster $CLUSTER doesn't exist"
}
}
##################################################################################
# Description: This procedure will remove a shared library
##################################################################################
proc removeSharedLibrary {} {
global AdminConfig NODE libName
debug "(removeSharedLibrary) Entry"
set nodeId [$AdminConfig getid /Node:$NODE/]
if {[isSharedLibraryInstalled $nodeId $libName] == 1} {
puts "Removing Shared Library $libName"
set SharedLibraryID [getSharedLibraryID $nodeId $libName]
$AdminConfig remove $SharedLibraryID
} else {
debug "(removeSharedLibrary) The Shared Library $libName is not installed"
}
debug "(removeSharedLibrary) Exit"
}
##################################################################################
# Description: Determines if the server is installed. Returns '1' if server
# installed else '0'
##################################################################################
proc isServerInstalled {} {
global AdminConfig AdminControl AdminApp
global NODE SERVER
##Query for object id based on names. If result string is "" then server is not installed
set name "/Node:$NODE/Server:$SERVER/"
set id [$AdminConfig getid $name]
return [expr [isNULL $id] == 0]
}
##################################################################################
# Description: Determines if the Cluster is installed. Returns '1' if Cluster
# installed else '0'
##################################################################################
proc isClusterInstalled {} {
global AdminConfig AdminControl AdminApp
global NODE SERVER CLUSTER
##Query for object id based on names. If result string is "" then server is not installed
set name "/ServerCluster:$CLUSTER/"
set id [$AdminConfig getid $name]
return [expr [isNULL $id] == 0]
}
##################################################################################
# Description: Determines if the server is running. First checks if server is
# installed. Return '1' if server running. If the server is not
# running or not installed return '0'.
##################################################################################
proc isServerRunning {} {
global AdminConfig AdminControl AdminApp
global NODE SERVER CELL
#Default isServerRunning to FALSE
set returnCode 0
if [ isServerInstalled ] {
set runningServer [$AdminControl completeObjectName cell=$CELL,node=$NODE,name=$SERVER,type=Server,*]
if {[llength $runningServer] == 0} {
log "Server $SERVER is not running"
set returnCode 0
} else {
set result [$AdminControl getAttribute $runningServer state]
log "State for server $SERVER: $result"
#If the server is running the state of the server shoudl equal "STARTED"
set returnCode [ expr {$result =="STARTED"}]
}
}
return $returnCode
}
##################################################################################
# Description: Determines if the passed node id has the passed shared library
# configured.
##################################################################################
proc isSharedLibraryInstalled {nodeId libName} {
global AdminConfig
debug "(isSharedLibraryInstalled) Entry"
set isSharedLibraryInstalled 0
set libList [$AdminConfig list Library $nodeId]
set libCount [llength $libList]
debug "(isSharedLibraryInstalled) libList is $libList"
for {set i 0} {$i < $libCount} {incr i} {
set curLibName [$AdminConfig showAttribute [lindex $libList $i] name]
if {[string compare $libName $curLibName] == 0} {
debug "(isSharedLibraryInstalled) The Shared Library, $libName, already exists"
debug "(isSharedLibraryInstalled) curLibName is $curLibName"
set isSharedLibraryInstalled 1
break
}
}
debug "(isSharedLibraryInstalled) Exit"
return $isSharedLibraryInstalled
}
##################################################################################
# Description: Determines if the passed appserver id has a classloader that
# points to the passed shared library name.
##################################################################################
proc isClassLoaderInstalled {appServer libName} {
global AdminConfig
debug "(isClassLoaderInstalled) Entry"
set isClassLoaderInstalled 0
set classList [lindex [$AdminConfig showAttribute $appServer classloaders] 0]
set classCount [llength $classList]
for {set i 0} {$i < $classCount} {incr i} {
set curClassID [lindex [$AdminConfig showAttribute [lindex $classList $i] libraries] 0 ]
set curClassName [$AdminConfig showAttribute $curClassID libraryName]
if {[string compare $libName $curClassName] == 0} {
debug "(isClassLoaderInstalled) The ClassLoader already exists"
set isClassLoaderInstalled 1
break
}
}
debug "(isClassLoaderInstalled) Exit"
return $isClassLoaderInstalled
}
##################################################################################
# Description: This procedure will return Websphere ID for the shared library
# name passed in.
##################################################################################
proc getSharedLibraryID {nodeId libName} {
global AdminConfig NODE
debug "(getSharedLibraryID) Entry"
set libList [$AdminConfig list Library $nodeId]
set libCount [llength $libList]
for {set i 0} {$i < $libCount} {incr i} {
set curLibName [$AdminConfig showAttribute [lindex $libList $i] name]
if {[string compare $libName $curLibName] == 0} {
log "Getting the configuration id for shared library $libName"
set SharedLibraryID [$AdminConfig getid /Node:$NODE/Library:$curLibName/]
break
}
}
debug "(getSharedLibraryID) Exit"
return $SharedLibraryID
}
##################################################################################
# Description: This procedure acts as a wrapper procedure which calls the
# stopServer and startServer to restart the application server
##################################################################################
proc restartServer {} {
global AdminConfig NODE errorInfo OUTPUT
stopServer
startServer
}
##################################################################################
# Description: This procedure acts as a wrapper procedure which calls the functionality to start a server
# and handles any error conditions.
##################################################################################
proc startServer {} {
global errorInfo
if { [ catch {startServerMain} r ] != 0 } {
log "$r"
log "Application Server start failed"
return -code error $r
} else {
log "Application Server start successful"
}
}
##################################################################################
# Description: This procedures will issues a start server command, wait 10 seconds for Websphere to
# acknowledge that the server started then query to see if it is running. If the server is not
# running, it will retry 6 additional times.
##################################################################################
proc startServerMain {} {
global AdminConfig AdminControl AdminApp
global NODE SERVER CLUSTER CELL
global errorInfo
set clkcounter 10
if [ isClusterInstalled ] {
#It takes a lot time to start all clones if the cluster is installed
#setting the clock counter
set nodeid [$AdminConfig getid /Node:$NODE/]
set clusterid [$AdminConfig getid /ServerCluster:$CLUSTER/]
set clusterlist [$AdminConfig list ClusterMember $clusterid]
set appservercnt [ llength $clusterlist ]
set clkcounter [expr $appservercnt * 10]
set clusterid [$AdminControl completeObjectName cell=$CELL,type=Cluster,name=$CLUSTER,*]
log "Attempting to start the Cluster $CLUSTER"
$AdminControl invoke $clusterid start
} else {
log "Cluster $CLUSTER doesn't exist"
}
if { ![ isClusterInstalled ] } {
if { ![ isServerRunning ] } {
log "Attempting to start $SERVER"
$AdminControl startServer $SERVER $NODE
}
}
#################################################################
## The following "think" time is required for Websphere to register that the application started
## properly. It is currently set to 20 seconds.
for {set counter 0} {$counter < $clkcounter} {incr counter} {
set waitTime [expr 20 * 1000]
after $waitTime
##################################################################
log "Checking to see if server $SERVER is running"
if { [ isServerRunning ] } {
set isRunning TRUE
break
} else {
set isRunning FALSE
}
}
if {[string match $isRunning "FALSE"]} {
log "After issuing startServer command, the server/cluster is still not in STARTED state"
return 1
}
}
##################################################################################
# Description: This procedure acts as a wrapper procedure which calls the functionality to stop a server and
# handles an error conditions
##################################################################################
proc stopServer {} {
global errorInfo
if [catch {stopServerMain} Output ] {
log $errorInfo
error "Application Server stop failed"
} else {
log "Application Server stop successful"
}
}
##################################################################################
# Description: This procedures will issues a stop server command, wait 60 seconds for Websphere to
# acknowledge that the server stopped then query to see if it is running. If the server is
# running, it will retry 5 additional times.
##################################################################################
proc stopServerMain {} {
global AdminConfig AdminControl AdminApp
global NODE SERVER CLUSTER CELL
set clkcounter 10
#The following code checks whether Cluster is installed. Then it sends the stop
#command to stop the cluster and waits for some time.
if [ isClusterInstalled ] {
set nodeid [$AdminConfig getid /Node:$NODE/]
set clusterid [$AdminConfig getid /ServerCluster:$CLUSTER/]
set clusterlist [$AdminConfig list ClusterMember $clusterid]
set appservercnt [ llength $clusterlist ]
set clkcounter [expr $appservercnt * 5]
set clusterid [$AdminControl completeObjectName cell=$CELL,type=Cluster,name=$CLUSTER,*]
log "Attempting to stop Cluster $CLUSTER"
$AdminControl invoke $clusterid stop
log "Waiting for the cluster to get stopped"
#################################################################
## The following "think" time is required for Websphere to register that the cluster stopped
## properly. It is currently set to multiple of 10 seconds and clkcounter.
set waitTime [expr $appservercnt * 10 * 1000]
after $waitTime
log "Checking whether the Server/Cluster is stopped."
}
#################################################################
## The following code tries to stop a server. Then queries to make
## sure that it stopped. It will retry 5 times then throw an error
## if it is not stopped
#####################
for {set counter 0} {$counter < $clkcounter} {incr counter} {
if [ isServerRunning ] {
log "Attempting to stop server: $SERVER"
$AdminControl stopServer $SERVER $NODE
} else {
set isRunning FALSE
break
}
set waitTime [expr 60 * 1000]
after $waitTime
}
if {[string match $isRunning "TRUE"]} {
log "After issuing stopServer command, the server is still in STARTED state"
error "After issuing stopServer command, the server is still in STARTED state"
}
log "Successfully stopped server: $SERVER"
}
##################################################################################
# Description: This procedure acts as a wrapper procedure which calls the functionality to stop a server with
# the immediate flag and handles an error conditions
##################################################################################
proc stopServerWithForce {} {
global errorInfo
if [catch {stopServerWithForceMain} Output ] {
log $errorInfo
log "Application Server stop failed"
} else {
log "Application Server stop successful"
}
}
##################################################################################
# Description: This procedures will issues a stop server command, wait 60 seconds for Websphere to
# acknowledge that the server stopped then query to see if it is running. If the server is
# running, it will retry 5 additional times.
#
##################################################################################
proc stopServerWithForceMain {} {
global AdminConfig AdminControl AdminApp
global NODE SERVER
if [ isServerRunning ] {
$AdminControl stopServer $SERVER $NODE immediate
}
#################################################################
## The following "think" time is required for Websphere to register that the application started
## properly. It is currently set to 10 seconds.
set waitTime [expr 10 * 1000]
after $waitTime
##################################################################
if { [ isServerRunning ] } {
error "After issuing stopServer command, the server is still in STARTED state"
}
}
##################################################################################
# Description: Displays the configuration for the Application Server
###############################################################################
proc showRunningServer {} {
global AdminConfig AdminControl AdminApp
global NODE SERVER
if { [ isServerRunning ] } {
set runningServer [$AdminControl completeObjectName type=Server,name=$SERVER,node=$NODE,*]
$AdminControl getAttributes $runningServer
} else {
log "Server is not running."
}
}
##################################################################################
# Description: Displays the configuration for the Application Server
###################################################################################
proc showServer {} {
global AdminConfig AdminControl AdminApp
global NODE SERVER
set name "/Node:$NODE/Server:$SERVER/"
set id [$AdminConfig getid $name]
if [ isServerInstalled ] {
$AdminConfig show $id
} else {
log "Server not installed: $name"
}
}
##################################################################################
#Description: Displays the configuration for the Application Server with the
#showall action. This will show the extended information for the
#application server like JVM configuration.
###################################################################################
proc showServerAll {} {
global AdminConfig AdminControl AdminApp
global NODE SERVER
set name "/Node:$NODE/Server:$SERVER/"
set id [$AdminConfig getid $name]
if [ isServerInstalled ] {
$AdminConfig showall $id
} else {
log "Server not installed: $name"
}
}
##################################################################################
#Description: Displays a list of all servers
##################################################################################
proc listAllServers {} {
global AdminConfig
global NODE
set scopeid [$AdminConfig getid /Node:$NODE/]
$AdminConfig list Server $scopeid
}
#################################################################################
# End Application Server Procedures
##################################################################################
#################################################################################
#Datasource Procedures
##################################################################################
##################################################################################
# Description: This procedure will return a list of Data sources installed on the Cell.
#
##################################################################################
proc showAllDataSources {} {
global AdminConfig
log [$AdminConfig list DataSource]
}
##################################################################################
# Description: Displays the configuration for a data source
###################################################################################
proc showDataSource {dataSourceName} {
global AdminConfig
set dataSourceID [getDataSourceID $dataSourceName]
debug "(showDataSource) dataSourceID set to $dataSourceID"
if {[isDataSourceInstalled $dataSourceName]} {
log [$AdminConfig showall $dataSourceID]
} else {
puts "Data Source $dataSourceID is not installed."
}
}
##################################################################################
#Description: This procedure will list all JDBC Drivers configure for the Cell
##################################################################################
proc showAllJDBCDrivers {} {
global AdminConfig
log [$AdminConfig list JDBCProvider]
}
##################################################################################
# Description: Displays the configuration for a JDBC Driver
##################################################################################
proc showJDBCDriver {jdbcDriverId} {
global AdminConfig
if {[isJDBCDriverInstalled $jdbcDriverId]} {
log [$AdminConfig show $jdbcDriverId]
} else {
puts "JDBC Driver $jdbcDriverId is not installed."
}
}
################################################################################
#Description: Finds and displays the description of all DataSources configured
#in WAS
###############################################################################
proc showAllDataSourceDesc {} {
global AdminConfig
foreach datasrc [$AdminConfig list DataSource] {
set dsDetail [$AdminConfig show "$datasrc"]
log [findPropertyValue $dsDetail "description"]
}
}
################################################################################
#Description: Finds and displays the DataSource detail using DataSource
#description in WAS
###############################################################################
proc showDataSourceUsingDesc {dataDesc} {
global AdminConfig
foreach datasrc [$AdminConfig list DataSource] {
set dsDetail [$AdminConfig show "$datasrc"]
set wasDsDescName [findWASValueMatch $dsDetail $dataDesc]
debug "(showDataSourceUsingDesc) Value returned from findWASValueMatch function is $wasDsDescName"
if {$wasDsDescName != "VALUE_NOT_FOUND_123456890"} {
debug "(showDataSourceUsingDesc) Found a DataSource in WAS with description = $wasDsDescName"
set dsName [findPropertyValue $dsDetail "name"]
showDataSource $dsName
}
}
}
#################################################################################
# Begin Node Procedures
##################################################################################
##################################################################################
#Description: This procedure will regenerate the Websphere Plugin.
#
# Implementation Note: This procedure hard codes the path to the Deployment Manager directory
# and plug-in configuration directory
###################################################################################
proc regenPlugin {} {
global AdminControl CELL NODE WASDMHOME
set installRootDirectory "$WASDMHOME"
set configRootDirectory "${WASDMHOME}/config/cells"
set pluginGen [$AdminControl completeObjectName type=PluginCfgGenerator,*]
$AdminControl invoke $pluginGen generate "$installRootDirectory $configRootDirectory $CELL $NODE null plugin-cfg.xml"
puts "Plugin regeneration is complete."
}
#################################################################################
# End Node Procedures
##################################################################################
##################################################################################
#Description: This procedure returns the active trace string
#
##################################################################################
proc getTraceString {} {
global AdminControl SERVER
log "Started Getting Trace String"
set ts [$AdminControl completeObjectName type=TraceService,process=$SERVER,*]
set traceString [$AdminControl invoke $ts getTraceSpecification]
log "Trace String = $traceString"
log "Finished Getting Trace String"
}
#################################################################################
# End Application Administration Procedures
##################################################################################
set NO_VALUE_FOUND_CONSTANT "VALUE_NOT_FOUND_123456890"
#################################################################################
# Start Utility Procedures
##################################################################################
##################################################################################
# Description: This procedure will set default values for the global variables used by the deployment
# framework
#
#
##################################################################################
proc setDefaultValuesForGlobalVariables {} {
global SERVER
global USE_JMS
global VERBOSE_GC_ON MAX_WEB_CONTAINER_CONNECTIONS MAX_HTTP_SESSIONS
global SESSION_INVALIDATION_TIME MAX_EJB_CACHE_SIZE SYSTEM_PROPERTIES
global APPSERVER_NAME
global ENVIRONMENT TRAN_TIMEOUT
global SERVER_ARGS INITIAL_HEAP_SIZE MAX_HEAP_SIZE DEBUG
global USE_IMS_CONNECTOR JMS_DEFINITIONS IMS_CONNECTION_FACTORY_DEFINITIONS
global PRECOMPILE_JSPS SERVER_CLASSLOADER_POLICY
global SERVER_CLASSLOADER_MODE INITIAL_STATE NONSTANDARD_CLASSPATHS
global WAR_CLASSLOADER_POLICY APP_CLASSLOADER_MODE ENABLE_SECURITY_DEBUGGING
#application.jacl defaults
set SERVER_ARGS ""
set DEBUG FALSE
set TRAN_TIMEOUT "60"
set ENVIRONMENT ""
set SYSTEM_PROPERTIES ""
set USE_JMS FALSE
set USE_CONFIGURATION_SERVICE FALSE
set VERBOSE_GC_ON FALSE
set MAX_WEB_CONTAINER_CONNECTIONS 50
set MAX_HTTP_SESSIONS 1000
set SESSION_INVALIDATION_TIME 20
set MAX_EJB_CACHE_SIZE 2047
set USE_IMS_CONNECTOR ""
set JMS_DEFINITIONS ""
set IMS_CONNECTION_FACTORY_DEFINITIONS ""
set PRECOMPILE_JSPS "FALSE"
set SERVER_CLASSLOADER_POLICY "MULTIPLE"
set SERVER_CLASSLOADER_MODE "PARENT_FIRST"
set INITIAL_STATE "START"
set WAR_CLASSLOADER_POLICY "SINGLE"
set APP_CLASSLOADER_MODE "PARENT_FIRST"
set ENABLE_SECURITY_DEBUGGING "FALSE"
set NONSTANDARD_CLASSPATHS ""
}
##################################################################################
# Description: This procedure give a list of {name value} pair and a wanted name will search the list
# and return the value if found. If not found it will return the NO_VALUE_FOUND_CONSTANT
#
##################################################################################
proc findPropertyValue {aList aMatch} {
global NO_VALUE_FOUND_CONSTANT
debug "aList is $aList"
debug "aMatch is $aMatch"
set index [lsearch -regexp $aList "^$aMatch .*"]
if {[expr $index != -1]} {
set value [lindex [lindex $aList $index] 1]
debug "(findPropertyValue) Found Property: $aMatch = $value"
} else {
debug "(findPropertyValue) No value found for Property: $aMatch"
set value "$NO_VALUE_FOUND_CONSTANT"
}
return $value
}
##################################################################################
# Description: This procedure give a list of {name value} pair and a wanted name will search the list
# and return the value if found. If not found it will return the NO_VALUE_FOUND_CONSTANT
###################################################################################
proc findWASValueMatch {aList aMatch} {
global NO_VALUE_FOUND_CONSTANT
set index [lsearch -regexp $aList ".* $aMatch"]
if {[expr $index != -1]} {
set value [lindex [lindex $aList $index] 1]
debug "(findWASValueMatch) Found Property: $aMatch = $value"
} else {
debug "(findWASValueMatch) No value found for Property: $aMatch"
set value "$NO_VALUE_FOUND_CONSTANT"
}
return $value
}
##################################################################################
# Description: This procedure checks to see if a value was found. It's only intended to be used with
# the find PropertyValue procedure.
#
##################################################################################
proc WasValueFound {field} {
global NO_VALUE_FOUND_CONSTANT
set ValueNotFound [string match $field "$NO_VALUE_FOUND_CONSTANT"]
return [expr !$ValueNotFound]
}
##################################################################################
# Description: This procedures checks to see if the field passed in is null or "".
#
##################################################################################
proc isNULL {field} {
set trimmedField [string trim $field]
return [expr [string length $trimmedField] == 0]
}
##################################################################################
# Description: This procedures checks to see if the field passed in is not null or "".
#
##################################################################################
proc isNotNULL {field} {
set trimmedField [string trim $field]
return [expr [string length $trimmedField] != 0]
}
##################################################################################
# Description: This procedure dumps out the following information to the log:
# Deployment start time, directory listing of project space, and contents of application.jacl
#
##################################################################################
proc displayDeployInfo {} {
global APPSERVER_NAME
log "Started Deployment Process at [exec date]"
log "Using [version]"
log $output
log ""
log "#######################################################"
log "Contents of Application.jacl used to deploy application"
log "#######################################################"
log ""
set output [exec cat $CURR_DIR/application.jacl]
log $output
}
##################################################################################
# Description: This procedure checks to see if debugging is enable and if so
# logs the message passed in with "DEBUG:" appended to the front of
# the message.
##################################################################################
proc debug {message} {
global DEBUG
if {[string match [string toupper $DEBUG] "TRUE"]} {
log "DEBUG: $message"
}
}
##################################################################################
# Description: This procedure writes the message passed in to the stream defined
# by the variable OUTPUT.
#
##################################################################################
proc log {message} {
global OUTPUT
puts $OUTPUT "[exec date +'%m-%d-%Y:%H%M'] - $message"
puts "$message"
}
##################################################################################
# Description: This procedure accepts a list and will print out the content of
# the list with linefeed after each element
##################################################################################
proc print {attributes} {
log ""
foreach item $attributes {
log "$item"
}
log ""
}
##################################################################################
# Description: This function returns the version of the common library,
##################################################################################
proc version {} {
log "Websphere 5.0 Deployment Framework 1.3"
}
#################################################################################
# End Utility Procedures
##################################################################################
#Initialize Global Variables with Default Values just in case
#application teams do not set them in application.jacl
setDefaultValuesForGlobalVariables
###########################################################################
No comments:
Post a Comment