WAS and JACL scripting

Ever wondered how you could automate the processes of configuring WebSphere application server? If so I am going to give you two simple examples.

How to change some variables in WAS?

In this script we are going to change the initialHeapSize and maximumHeapSize of the JVM. Look at the script belove:

set serverName "server1"
set nodeName "testwas"
set initialHeapSize [list initialHeapSize 256]
set maximumHeapSize [list maximumHeapSize 1024]
set server [$AdminConfig getid /Node:$nodeName/Server:$serverName/]
set jvm [$AdminConfig list JavaVirtualMachine $server]
set jvmAttrs [list $initialHeapSize $maximumHeapSize]
$AdminConfig modify $jvm $jvmAttrs
$AdminConfig save

What are we doing actually, lets break down the script. Here we are just initializing some variables just like other languages.

set serverName "server1"
set nodeName "testwas"
set initialHeapSize [list initialHeapSize 256]
set maximumHeapSize [list maximumHeapSize 1024

With the AdminConfig object in WAS we are getting the configuration ID of the server.

set server [$AdminConfig getid /Node:$nodeName/Server:$serverName/

Here we are looking up the JVM belonging to the server and storing the configuration ID.

set jvm [$AdminConfig list JavaVirtualMachine $server

Creating a new array with our variables we had.

set jvmAttrs [list $initialHeapSize $maximumHeapSize

With the help of AdminConfig object we are editing our found JVM with the options we have stored in our variables.

$AdminConfig modify $jvm $jvmAttrs

At the end we save the modified settings.

$AdminConfig save

How to stop an Enterprise Application in WAS using a JACL script?

With this script we are going to stop an running application in WAS.

set appName "someApp"
set node "tmp_node"
set server "server1"
set cell "tmp_cell";
set appManager [$AdminControl queryNames cell=$cell,node=$node,type=ApplicationManager,process=$server,*]
$AdminControl invoke $appManager stopApplication $appName

The first four lines initialize variables, the second line queries configuration ID of the ApplicationManager object.

set appManager [$AdminControl queryNames cell=$cell,node=$node,type=ApplicationManager,process=$server,*

The last line is actually executing the command to stop the application.

$AdminControl invoke $appManager stopApplication $appName

Now that we have two scripts what do we do with them?

Save the two scripts for example like, SetVars.jacl and StopApp.jacl. To use the scripts we need to make use of the /WAS_INSTALL_MAP/bin/wsadmin.sh. It is importen to keep in mind that the WAS server has to be running to be able to do this.

Execute one of the scripts:

/opt/WAS/bin/wsadmin.sh -f /home/tmp/tmpscripts/SetVars.jacl -profileName TmpProfile

If you want to learn more about JACL scripts and wsadmin look here.