Example 2    -    Deploy Application.

A.    PROPERTY FILE - yourapplication.properties.

####################################################################
# Application Properties.
####################################################################
####################################################################
# User roles.
## NB: ldap users must exist or deployment will fail.
## NB: roles must have unique index in left hand colume for the Property class.
#####################################################################
userRole1 role1          ldapuser1
userRole2 role2          ldapuser1
userRole3 role3          ldapuser1
#
userRole4 role1          ldapuser2
userRole5 role2          ldapuser2
userRole6 role3          ldapuser2
#
userRole7 role1          ldapuser2
userRole8 role2          ldapuser2
userRole9 role3          ldapuser2
#############################################
## Group Roles.
## NB: ldap groups must exist or deployment will fail.
## NB: roles must have unique index in left hand colume for the Property class.
#############################################
groupRole1 role1        ldapgroup1
groupRole2 role2        ldapgroup1
groupRole3 role3        ldapgroup1
#
groupRole4 role1        ldapgroup2
groupRole5 role2        ldapgroup2
groupRole6 role3        ldapgroup2
####################################################################
# Virtual host mappings.
####################################################################
vhostMap .*  .* yourVirtualHost
####################################################################
# Web Module Mappings.
####################################################################
webModule       "yourApp" yourApp.war,WEB-INF/web.xml targetJVM
####################################################################
# Application Names. NB: must match the app name in the web module mapping. 
####################################################################
applicationName yourApp
####################################################################
# Target Server Name.
####################################################################
serverName targetJVM
####################################################################
# Context root.
####################################################################
contextRoot yourContextRoot
####################################################################
# War file.
####################################################################
warFile C:\\xxxx\\xxxx\\yourApp.war
####################################################################
# EJB Resource Reference Mappings.
####################################################################
MapResRefToEJB "yourApp" .* .* .* .* jdbc/yourDb
####################################################################
# Class loader policies.
####################################################################
classLoader.newWarClassLoaderPolicy  warClassLoaderPolicy MULTIPLE
classLoader.newWarClassLoaderMope  classloaderMode         PARENT_LAST
classLoader.reloadEnabled                      reloadEnabled             false  
classLoader.classloaderAttr                     mode                          PARENT_LAST
####################################################################
# Session management.
####################################################################
sessionManagement.newAllowSerializedSessionAccess allowSerializedSessionAccess false
sessionManagement.newAccessSessionOnTimeOut       accessSessionOnTimeout  true 
sessionManagement.newMaxWaitTime                          maxWaitTime             90   
sessionManagement.allowOverflow                                allowOverflow           true
sessionManagement.invalidationTimeout                         invalidationTimeout     30  
sessionManagement.maxInMemorySessionCount           maxInMemorySessionCount 1000 

The properties file is processed by the hashMap proc which returns a java property object loaded with the properties. 

proc hashMap { propertiesFile } {

   java::import java.util.Properties
   java::import java.util.Hashtable
   java::import java.util.Map
   java::import java.io.FileInputStream

   set FileInputStreamI [ java::new FileInputStream $propertiesFile ]
   set PropertiesI      [ java::new Properties ] 

   $PropertiesI load $FileInputStreamI

   return $PropertiesI

}

The properties are accessed using the getProperty method of the Property Object.

set webModList  [ getWebModList   $PropertyI $propertiesList ]
set resRefList      [ MapResRefToEJB  $PropertyI $propertiesList ]

B.    TOP LEVEL SCRIPT - deployYourApp.tcl.   

The script uses "sourceProcs" to load all the jacl procedures from the proclib directory.  "sourceProcs" expects to find the proclib directory one level below the execution directory so you need to use a pushd/popd technique to localize the working directory when using WSAdmin.  Jacl checks the procs for syntax errors at source time so the  proclib directory must be clean.

    pushd C:\WSAdmin\JACL

    wsadmin.bat -lang jacl -f /xxxx/yyyy/installDataSource.tcl

    popd C:\WSAdmin\JACL

The script stops the JVM,  deletes the application,  installs the application using the application properties file then restarts the JVM.  If errors occur at run time the messages and return codes are passed back to the top level script and then to the wsadmin shell.

#
# Deploy the yourApp application.
#
####################################################################
# Patrick Finnegan 08/03/2007.  V1.
####################################################################

####################################################################
# Source the utility procs from the proc directory - jacl/proclib.
####################################################################
proc sourceProcs {} {

   set workingDir [ java::call System getProperty user.dir ]
  
   if { [ catch { file join $workingDir jacl/proclib } r ] == 0 } {
  
       set pwd [pwd]
  
       cd $r
  
       #puts "proc directory is [ pwd ]"
      
       foreach x [ glob *.tcl] {
           #puts $x  
           source $x
       }
  
       cd $pwd
  
   } else {
  
       return -code error $r
  
   }

}

sourceProcs

##############
# Main Control
##############

############################################################################
# Deploy the yourApp Application to a single JVM on the target deployment manager instance.
############################################################################

set appName    "yourApp"
set serverName "targetJVM"     
set propertyFile "C:\\xxxx\\xxxx\\propertyFiles\\yourApp.properties"

# stop the app.

if { [ catch { stopApplication $appName } r ] != 0 } {

    return -code error $r
   
}

# stop the JVM.


if { [ catch { stopServer $serverName } r ] != 0 } {

    return -code error $r
   
}

# delete the application.

if { [ catch { deleteApplication $appName } r ] != 0 } {

    return -code error $r
   
}

# install the application.

if { [ catch { installApp $propertyFile } r ] != 0 } {

    return -code error $r
   
}

# save changes.

if { [ catch { saveChanges } r ] != 0 } {

    return -code error $r
   
}

# start the JVM.

if { [ catch { startServer $serverName } r ] != 0 } {

    return -code error $r
   
}

# start the application.

if { [ catch { startApplication $appName } r ] != 0 } {

    return -code error $r
   
}

C.    Procedure -    installApp_proc.tcl

The proc installs the application on the target JVM and maps the virtual host, web modules, roles and resource references.  Once the app has been installed it's modified with the classloader policies and session management properties.   

installApp_proc.tcl