Creating a wsadmin script from scratch
When I was gathering up the wsadmin sample/exmple scripts referenced by
the book, I realized that I couldn't find the original "createClusterMember"
script referenced on page 164. Since I referenced it, I really needed to
recreate it, so that it could be available on the book website.
At this point, I thought that it might be a good opportunity for me to
do this in a way to explain the process I tend to use when I decide to go
about creating a wsadmin script. This would allow me to describe each and
every step, including missteps along the way.
- I started by opening the on-line documentation.
To get there, I began by pointing my browser at the WebSphere
Application Server Support page:
http://www.IBM.com/software/webservers/appserv/was/support/
- Then, I clicked on the "Library" link in the left frame, which took
me to:
http://www.IBM.com/software/webservers/appserv/was/library/
- I selected the V 6.1 "tab", which took me to:
http://www.IBM.com/software/webservers/appserv/was/library/v61/
- Scrolling down, I selected the "View page" under the "Network
Deployment - distributed platforms" section, which took me to:
WebSphere Application Server Network Deployment - distributed platforms
http://www.IBM.com/software/webservers/appserv/was/library/v61/nd-dp/info-center.html
- The first entry under which is "WebSphere Application Server Network
Deployment, Version 6.1", so I selected the "View page" link, which
took me to:
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.nd.doc/info/welcome_nd.html
- Clicking on the "Search scope" link (by the "Go" button), opens a
dialog box that lets me narrow the search.
- Clicking on the "New" button, opens another dialog box that shows
all of the various document.
I "select" (check) the "Network Deployment (Distributed platforms...),
Version 6.1 document, and enter "6.1 ND" in the "List name" input box
at the top, then click the "OK"
- This take you back to the "Select Search Scope" dialog box, where
the newly created scope is selected by default. Click the "OK"
button.
- You should now see the "6.1 ND" beside the "Search scope" link.
- Enter "createClusterMember" (without the quotes) in the search input
field, and press Enter, or click on the "Go" button.
- The first match displayed for me is "Creating cluster members using
scripting"
- Clicking on this link takes us to:
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.nd.doc/info/ae/ae/txml_addcluster.html
- Since this script is being recreated for the AdminConfig scripting
object, we'll focus only on that technique.
- Then, we focus on the Jython snippets, and see that they are:
#----------------------------------------------------------------------
# Identify the existing cluster and assign it to the cluster variable:
#----------------------------------------------------------------------
cluster = AdminConfig.getid('/ServerCluster:myCluster1/')
print cluster
#----------------------------------------------------------------------
# Identify the node to create the new server and assign it to the node variable:
#----------------------------------------------------------------------
node = AdminConfig.getid('/Node:mynode/')
print node
#----------------------------------------------------------------------
# (Optional) Identify the cluster member template and assign it to the
# serverTemplate variable:
#----------------------------------------------------------------------
serverTemplate = AdminConfig.listTemplates('Server')
print serverTemplate
#----------------------------------------------------------------------
# Create the new cluster member, by using the createClusterMember command.
#----------------------------------------------------------------------
# The following example creates the new cluster member, passing in the
# existing cluster configuration ID, existing node configuration ID,
# and the new member attributes:
#----------------------------------------------------------------------
AdminConfig.createClusterMember(cluster, node, [['memberName', 'clusterMember1']])
#----------------------------------------------------------------------
# The following example creates the new cluster member with a template,
# passing in the existing cluster configuration ID, existing node
# configuration ID, the new member attributes, and the template ID:
#----------------------------------------------------------------------
print AdminConfig.createClusterMember(cluster, node, [['memberName', 'clusterMember1']], serverTemplate)
#----------------------------------------------------------------------
# Save the configuration changes.
#----------------------------------------------------------------------
AdminConfig.save()
#----------------------------------------------------------------------
# It is kind of amusing to read the first part of step #3 which starts
# with "In a network deployment environment only"... Where else can one
# create a cluster member? ;-)
#----------------------------------------------------------------------
# Synchronize the node
#----------------------------------------------------------------------
Sync1 = AdminControl.completeObjectName('type=NodeSync,node=myNodeName,*')
AdminControl.invoke(Sync1, 'sync')
- Things that this sequence doesn't do:
* Verify that we're connected to an active server
In fact, since the only scripting object with which we are working
(at least up to the node synchronization step) is AdminConfig, we
don't even have to be connected. We could be in local mode.
* Verify, or even select a "unique" & valid template
* Verify that the specified cluster already exists, in which case,
we really can't use the serverTemplate parameter...
? Do we have an easy way to determine if the script is being executed
in "local mode"?
Sure, we could use a simple function like this:
#----------------------------------------------------------------------
# Name: localMode()
# Role: Return true (1) if the script is currently executing in "local
# mode", false (0) otherwise.
# Note: It is possible for the connection to the server to be dropped,
# in which case, this routine will return true
#----------------------------------------------------------------------
def localMode() :
result = 0;
try :
AdminControl.getType();
except :
result = 1;
return result;
This works because when the script is executing in local mode, any
attempts to call an AdminControl method will result in an exception:
--------------------------------------------------------------------------------
WASX7015E: Exception running command: "AdminControl.getType()"; exception information:
com.ibm.ws.scripting.ScriptingException: AdminControl service not available
--------------------------------------------------------------------------------
- So, how do we proceed?
One way would be to simply take the command shown above, and turn
them into a straight-line script. Unfortunately, this isn't as
useful as we would like since the command use "hard coded" values
for the following:
- cluster name: myCluster1 Required
- node name: mynode Optional?
- template name: ? Optional
- member name: clusterMember1 Required
- This seems to be a good list of possible parameters. Let's start by
putting some high level pseudo-code in place to see how things might
fit together:
#----------------------------------------------------------------------
# Pseu