Date Created: Wed 11-Feb-2009

Related Document Categories:

Get my WebSphere Application Server course here >> http://www.themiddlewareshop.com/products/


Example JACL script to show how to deployment an EAR file on WebSphere ND Cluster

logview.propslogview_deployear.jacl

<was_root>bin/wsadmin.sh -f ./logview_deployear.jacl

------------------------ JACL file/logview_deployear.jacl -------------------------

#################################################################
# Declare Java classes for getting property pairs from props file
#################################################################
proc loadProperties {propFileName} {
puts "loading prop file $propFileName"
java::import java.io.FileInputStream
java::import java.util.Properties

set fileprop [java::new Properties]
set fileStream [java::new FileInputStream $propFileName]

$fileprop load $fileStream
return $fileprop
}

########################################
# Load script properties
########################################
set log_props [loadProperties logview.props]
#-----------------------------------------------------------------
# Func delJvm(jvmEntry)
#-----------------------------------------------------------------
proc delJvm {jvmEntry} {
global AdminConfig jvm
set listProp [$AdminConfig list Property $jvm]
foreach eListProp $listProp {
set name [$AdminConfig showAttribute $eListProp name]

if { $name == $jvmEntry } {
puts "Info : - Deleting JVM Parameter : $name"
$AdminConfig remove $eListProp
#break
}
}
}
#-----------------------------------------------------------------
# Func modifyJvm {jvmEntry}
#-----------------------------------------------------------------
proc modifyJvm {jvmEntry jvmValue} {
global AdminConfig jvm
delJvm $jvmEntry
puts "Info - setting $jvmEntry with $jvmValue"
$AdminConfig modify $jvm [subst {{systemProperties {{{name {$jvmEntry}} {value {$jvmValue}}} }}} ]
}
#-----------------------------------------------------------------
# End of the function
#-----------------------------------------------------------------
set createMsg "Creating JVM Property"
set successMsg "Success creating JVM Properties"
#--------------------------------------------------------------


########################################
# Set script attributes
########################################
puts "-------------------------"
puts "setting script attributes"
puts "-------------------------"
set earFileLocation [$log_props getProperty log.app.ear.location]
set clusterName [$log_props getProperty com.log.was.cluster.name]
set earFileName [$log_props getProperty log.app.ear.name]
set warFileName [$log_props getProperty log.app.war.name]
set warModuleName [$log_props getProperty log.app.war.module.name]
set virtualHost [$log_props getProperty com.log.was.vhost]
set cell [$log_props getProperty com.log.was.cell.name]
#----------------------------------------------------------------
# change the following line if you want to install it on a node
set appServer WebSphere:cell=$cell,cluster=$clusterName
#----------------------------------------------------------------
set generator [$AdminControl completeObjectName type=PluginCfgGenerator,*]
puts "-------------------------"
puts "setting clusterId"
puts "-------------------------"
set clusterId [$AdminConfig getid /ServerCluster:$clusterName/]
set adminControlClusterId [$AdminControl completeObjectName type=Cluster,name=$clusterName,*]
set clusterMembers [$AdminConfig list ClusterMember $clusterId]
set installedApps [$AdminApp list]

########################################
# Display script attributes
########################################
puts "-------------------------"
puts "Listing script attributes"
puts "-------------------------"
puts "earFileLocation: $earFileLocation"
puts "warFileName: $warFileName"
puts "warModuleName: $warModuleName"
puts "clusterName: $clusterName"
puts "earFileName: $earFileName"
puts "virtualHost: $virtualHost"
puts "cell: $cell"
puts "appServer: $appServer"
puts "generator: $generator"
puts "clusterId: $clusterId"
puts "adminControlClusterId: $adminControlClusterId"
puts "clusterMembers: $clusterMembers"
puts "installedApps: $installedApps"

###################################
# Check if application is installed
###################################
set applicationFound 0
foreach appId $installedApps {
set existingApp $appId

if {[string compare $earFileName $existingApp] == 0} {
set applicationFound 1
break
}
}

puts "applicationFound for $earFileName: $applicationFound"

if {$applicationFound == 1} {
########################################
# Stop the log application if it is installed
#######################################
puts "-------------------------"
puts "Stopping the application: $earFileName on cluster $clusterName"
puts "-------------------------"
foreach m_id $clusterMembers {
set currentServer [$AdminConfig showAttribute $m_id memberName]
set currentNodeName [$AdminConfig showAttribute $m_id nodeName]
set query cell=$cell,node=$currentNodeName,type=ApplicationManager,
append query process=$currentServer,*
set appManager [$AdminControl queryNames $query]
puts "Stopping $earFileName on node $currentNodeName, server $currentServer."
if {[catch "$AdminControl invoke $appManager stopApplication $earFileName"]} {
# Exception is thrown don't do any thing
puts "Info: Exception is thrown while stopping application, this could be due to the fact that application is already stopped"
}
}

########################################
# Uninstall the current application if it is installed
########################################
puts "-------------------------"
puts "Uninstalling the application: $earFileName"
puts "-------------------------"
$AdminApp uninstall $earFileName

########################################
# Save the configuration if it is installed
########################################
puts "-------------------------"
puts "Saving the configuration"
puts "-------------------------"
$AdminConfig save
}

########################################
# Stop the cluster
########################################
puts "-------------------------"
puts "Stopping the cluster: $clusterName"
puts "-------------------------"
$AdminControl invoke $adminControlClusterId stop

########################################
# MapModulesToServers
########################################
puts "Setting MapModulesToServers attributes"
set module_log [list "$warModuleName" "$warFileName,WEB-INF/web.xml" $appServer]

########################################
# MapWebModToVH
########################################
puts "Setting MapWebModToVH attributes"
set virtualhost_log [list "$warModuleName" "$warFileName,WEB-INF/web.xml" $virtualHost]

########################################
# MapRolesToUsers
########################################
puts "Setting MapRolesToUsers attributes"

set opts [list -appname $earFileName]

set optss $opts
set webservers 0
set httpServer ""
for {set nodeIndx 1} {[string length [set nodeName [$log_props getProperty com.log.was.node$nodeIndx.name]]] != 0} {incr nodeIndx} {
puts "Info: checking for the web server name in $nodeName"
for {set httpServerIndx 1} {[string length [set httpServerName [$log_props getProperty loadmanager.http.node$nodeIndx.server$httpServerIndx]]] != 0} {incr httpServerIndx} {
set webservers 1
if {$httpServer == ""} {
set httpServer WebSphere:cell=$cell,node=$nodeName,server=$httpServerName
} else {
set httpServer $httpServer+WebSphere:cell=$cell,node=$nodeName,server=$httpServerName
}
}
}

puts "Info: - Web Server status $webservers now deploy to $appServer and $httpServer "

if {$webservers == 1} {
set module_log_web [list "$warModuleName" "$warFileName,WEB-INF/web.xml" $appServer+$httpServer]
lappend opts -MapModulesToServers [list $module_log_web $module_log]
} else {
set module_log_web [list "$warModuleName" "$warFileName,WEB-INF/web.xml" $appServer]
puts "-------------------------"
puts "module_log_web = $module_log_web"
puts "-------------------------"
puts "module_log = $module_log"
puts "-------------------------"

lappend opts -MapModulesToServers [list $module_log_web $module_log]

}

lappend opts -MapWebModToVH [list $virtualhost_log]

########################################
# Install the Enterprise Application (EAR)
########################################
puts "-------------------------"
puts "Installing $earFileLocation using $opts"
puts "-------------------------"
$AdminApp install $earFileLocation $opts

########################################
# Regenerate the node plug-in config
########################################

if {$webservers == 0} {
puts "-------------------------"
puts "No WebServer plugins. No need to regenerate the node plug-in config"
puts "-------------------------"
} else {
puts "-------------------------"
puts "Regenerating the node plug-in config"
puts "-------------------------"
set WASRoot [$log_props getProperty com.log.was.profile.home]
puts "info --- generating plugin for $nodeName ---- $WASRoot"
$AdminControl invoke $generator generate "$WASRoot $WASRoot/config $cell null null plugin-cfg.xml"
puts "info --- plugin generated successfully"
}

########################################
# Save the configuration
########################################
puts "-------------------------"
puts "Saving the configuration"
puts "-------------------------"
$AdminConfig save

########################################
# Syncronizing Nodes
########################################
puts "-------------------------"
puts "Syncronizing Nodes"
puts "-------------------------"
for {set nodeIndx 1} {[string length [set nodeName [$log_props getProperty com.log.was.node$nodeIndx.name]]] != 0} {incr nodeIndx} {
puts "Node name : $nodeName"
set nodeToSync [$AdminControl completeObjectName type=NodeSync,node=$nodeName,*]
$AdminControl invoke $nodeToSync sync
}


#----------------------------------------------------------
# Loop thru the server and node to set the jvm properties
#----------------------------------------------------------

for {set nodeIndex 1} {[string length [set nodeName [$log_props getProperty com.log.was.node$nodeIndex.name]]] !=0} {incr nodeIndex} {

puts "Info : - Node name : $nodeName"
set nodeID [$log_props getProperty com.log.was.node$nodeIndex.id]
puts "Info :- Node id: $nodeID"
set serverName [$log_props getProperty com.log.was.node$nodeID.app.server]
puts "Info : - Server name : $serverName"

#---------------------------------------
# Create the ServerID and AdminConfig
#----------------------------------------


set serverId [$AdminConfig getid "/Node:$nodeName/Server:$serverName/"]
puts "Info : -- Checking for existence of server '/Node:$nodeName/Server:$serverName/'"

if {[llength $serverId] == 0} {
puts "Error: -- Server '/Node:$nodeName/Server:$serverName/' not found"
} else {
puts "Success: -- Server ID '$serverId' found"
}

#------------------------------------------------------
# Start of jvm parameters loop
#-----------------------------------------------------
set jvm [$AdminConfig list JavaVirtualMachine $serverId]
for {set jvmIndx 1} {[string length [set jvmEntry [$log_props getProperty com.log.jvm.param$jvmIndx]]] != 0} {incr jvmIndx} {

# change for only DMS_LOGGING and logLog4j.configuration
set jvmVal [$log_props getProperty $jvmEntry]
if {[llength $jvmVal] == 0} {
set jvmVal [$log_props getProperty "$serverName.$jvmEntry"]
puts "Success: --value -- $jvmVal"
}
modifyJvm $jvmEntry $jvmVal
}
#------------------------------------------------------
# End of jvm parameters loop
#-----------------------------------------------------
#-----------------------------------------------------
# Now print the values that have been created so far
#-----------------------------------------------------
set listProp [$AdminConfig list Property $jvm]
foreach eListProp $listProp {
set name [$AdminConfig showAttribute $eListProp name]
puts "Info : - $name"
}

puts "JVM parameters $successMsg"
}

$AdminConfig save

########################################
# Start the cluster
########################################
puts "-------------------------"
puts "Starting the cluster: $clusterName"
puts "-------------------------"
$AdminControl invoke $adminControlClusterId start
puts "-------------------------"
puts "Please check Admin Console or Server Log for Cluster and Application Status."
puts "-------------------------"

puts "Task Completed..."



--------------------------- Properties file - logview.props --------------------------------


#------------------------------------
#LOG application Profile settings
#------------------------------------
# Enterprise Application name
log.app.ear.name=log Viewer

# Web Application name
log.app.war.name=LogView.war

# Web Module name
log.app.war.module.name=LogView

# vhost name
com.log.was.vhost=default_host

# dmgr name
com.log.was.dmger.node.name=dmgr

#cell name
com.log.was.cell.name=cell01

# Cluster name to install on remeber unix is case sensitive
com.log.was.cluster.name=AdminCluster

# node(s) name if more then one
com.log.was.node1.name=node01
com.log.was.node2.name=node02

com.log.was.node1.id=1
com.log.was.node2.id=2

# server name where to install
com.log.was.node1.app.server=Admin01
com.log.was.node2.app.server=Admin02

com.log.was.profile.home=/apps/was/ws61/profiles/dmgr/bin

#--------------------------------------------------
#--------------------------------------------------------
# JVM Keys
#--------------------------------------------------------
com.log.jvm.param1=log.folder
com.log.jvm.param2=profiles.root
#------------------------------------------------------
# Common JVM para meters
#------------------------------------------------------
log.folder=logs
profiles.root=/apps/was/ws61/profiles
#----------------------------------------------
# log.app.ear.location=location of the ear file
#----------------------------------------------
log.app.ear.location=LogViewEAR_1_5.ear

--------------------------- Sample execution -----------------------------

[root@websphere admin]# ../../wsadmin.sh -f ./logview_deployear.jacl
WASX7209I: Connected to process "dmgr" on node dmgr_node using SOAP connector; The type of process is: DeploymentManager
loading prop file logview.props
-------------------------
setting script attributes
-------------------------
-------------------------
setting clusterId
-------------------------
-------------------------
Listing script attributes
-------------------------
earFileLocation: LogViewEAR_1_5.ear
warFileName: LogView.war
warModuleName: LogView
clusterName: AdminCluster
earFileName: log Viewer
virtualHost: default_host
cell: cell01
appServer: WebSphere:cell=cell01,cluster=AdminCluster
generator: WebSphere:name=PluginCfgGenerator,process=dmgr,platform=common,node=dmgr_node,version=6.1.0.0,type=PluginCfgGenerator,mbeanIdentifier=PluginCfgGenerator,cell=cell01,spec=1.0
clusterId: AdminCluster(cells/cell01/clusters/AdminCluster|cluster.xml#ServerCluster_1197721011095)
adminControlClusterId: WebSphere:name=AdminCluster,process=dmgr,platform=common,node=dmgr_node,version=6.1.0.0,type=Cluster,mbeanIdentifier=AdminCluster,cell=cell01,spec=1.0
clusterMembers: Admin01(cells/cell01/clusters/AdminCluster|cluster.xml#ClusterMember_1197721011146)
Admin02(cells/cell01/clusters/AdminCluster|cluster.xml#ClusterMember_1197721018008)
installedApps: "Log Viewer"
"log Viewer"
applicationFound for log Viewer: 1
-------------------------
Stopping the application: log Viewer on cluster AdminCluster
-------------------------
Stopping log Viewer on node node01, server Admin01.
Info: Exception is thrown while stopping application, this could be due to the fact that application is already stopped
Stopping log Viewer on node node02, server Admin02.
Info: Exception is thrown while stopping application, this could be due to the fact that application is already stopped
-------------------------
Uninstalling the application: log Viewer
-------------------------
ADMA5017I: Uninstallation of log Viewer started.
ADMA5104I: The server index entry for WebSphere:cell=cell01,node=node02+WebSphere:cell=cell01,node=node01 is updated successfully.
ADMA5102I: The configuration data for log Viewer from the configuration repository is deleted successfully.
ADMA5011I: The cleanup of the temp directory for application log Viewer is complete.
ADMA5106I: Application log Viewer uninstalled successfully.
-------------------------
Saving the configuration
-------------------------
-------------------------
Stopping the cluster: AdminCluster
-------------------------
Setting MapModulesToServers attributes
Setting MapWebModToVH attributes
Setting MapRolesToUsers attributes
Info: checking for the web server name in node01
Info: checking for the web server name in node02
Info: - Online status 0 now deploy to WebSphere:cell=cell01,cluster=AdminCluster and
-------------------------
module_log_web = LogView LogView.war,WEB-INF/web.xml WebSphere:cell=cell01,cluster=AdminCluster
-------------------------
module_log = LogView LogView.war,WEB-INF/web.xml WebSphere:cell=cell01,cluster=AdminCluster
-------------------------
-------------------------
Installing LogViewEAR_1_5.ear using -appname {log Viewer} -MapModulesToServers {{LogView LogView.war,WEB-INF/web.xml WebSphere:cell=cell01,cluster=AdminCluster} {LogView LogView.war,WEB-INF/web.xml WebSphere:cell=cell01,cluster=AdminCluster}} -MapWebModToVH {{LogView LogView.war,WEB-INF/web.xml default_host}}
-------------------------
ADMA5016I: Installation of log Viewer started.
ADMA5058I: Application and module versions are validated with versions of deployment targets.
ADMA5005I: The application log Viewer is configured in the WebSphere Application Server repository.
ADMA5053I: The library references for the installed optional package are created.
ADMA5005I: The application log Viewer is configured in the WebSphere Application Server repository.
ADMA5001I: The application binaries are saved in /apps/was/ws61/profiles/dmgr/wstemp/Script117e67c7ff5/workspace/cells/cell01/applications/log Viewer.ear/log Viewer.ear
ADMA5005I: The application log Viewer is configured in the WebSphere Application Server repository.
SECJ0400I: Successfuly updated the application log Viewer with the appContextIDForSecurity information.
ADMA5011I: The cleanup of the temp directory for application log Viewer is complete.
ADMA5013I: Application log Viewer installed successfully.
-------------------------
No WebServer plugins. No need to regenerate the node plug-in config
-------------------------
-------------------------
Saving the configuration
-------------------------
-------------------------
Syncronizing Nodes
-------------------------
Node name : node01
Node name : node02
Info : - Node name : node01
Info :- Node id: 1
Info : - Server name : Admin01
Info : -- Checking for existence of server '/Node:node01/Server:Admin01/'
Success: -- Server ID 'Admin01(cells/cell01/nodes/node01/servers/Admin01|server.xml#Server_1197721004713)' found
Info : - Deleting JVM Parameter : log.folder
Info - setting log.folder with logs
Info : - Deleting JVM Parameter : profiles.root
Info - setting profiles.root with /apps/was/ws61/profiles
Info : - log.folder
Info : - profiles.root
JVM parameters Success creating JVM Properties
Info : - Node name : node02
Info :- Node id: 2
Info : - Server name : Admin02
Info : -- Checking for existence of server '/Node:node02/Server:Admin02/'
Success: -- Server ID 'Admin02(cells/cell01/nodes/node02/servers/Admin02|server.xml#Server_1197721017906)' found
Info : - Deleting JVM Parameter : log.folder
Info - setting log.folder with logs
Info : - Deleting JVM Parameter : profiles.root
Info - setting profiles.root with /apps/was/ws61/profiles
Info : - log.folder
Info : - profiles.root
JVM parameters Success creating JVM Properties
-------------------------
Starting the cluster: AdminCluster
-------------------------

Get my WebSphere Application Server course here >> http://www.themiddlewareshop.com/products/


Steve Robinson - IBM Champion 2013

About Me

Steve Robinson has been working in IT for over 20 years and has provided solutions for many large-enterprise corporate companies across the world. Steve specialises in Java and Middleware.

In January 2013, I was awarded the prestigous 'IBM Champion' accolade.


  • Linked In
  • Twitter
  • About Me
  • My Blog
  • Contact Me

Read my books?

IBM WebSphere Application Server 8.0 Administration Guide

IBM WebSphere Application Server 8.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Categories

Other Categories