Wednesday, April 21, 2010

How to create a cluster and servers?

Use wsadminlib methods createCluster() and createServerInCluster().

First create a cluster, specifying the cell name and cluster name:

createCluster( 'cell1', 'cluster1')

Then create servers, specifying the cluster name, node name, and server name:

createServerInCluster( 'cluster1', 'node1', 'server1')
createServerInCluster( 'cluster1', 'node1', 'server2')

That was easy. We created one cluster with two servers. This screenshot shows the two servers with the cluster name in the Admin Console.

It's also easy to create a replication domain and enable session replication with these same commands. If you look at the two method signatures in, you'll see optional parameters for replication. They are disabled by default, and you can override them as follows:

createCluster( 'cell1', 'cluster1', createReplicationDomain=True )
createServerInCluster( 'cluster1', 'node1', 'server1', sessionReplication=True )
createServerInCluster( 'cluster1', 'node1', 'server2', sessionReplication=True )

Note: True and False are set to 1 and 0 in as a convenience.

This creates a replication domain with the same name as the cluster.

Finally, I created a python file to do all of the above. I named it I invoked it like this:

/opt/WAS70/bin/ -lang jython -host ding6 -port 8879 -f

And here are the contents. Feel free to copy, paste, and tweak.

# This python script demonstrates how
# to create a cluster with two servers
# using
# AD 2010-0421-0800
m = ""

# Define variable names
clustername = "cluster1"
server1name = "server1"
server2name = "server2"

# Debug
sop(m,"clustername=" + clustername)
sop(m,"server1name=" + server1name)
sop(m,"server2name=" + server2name)

# Specify replication
createReplicationDomain = True
sessionReplication = True

# Query the cell name.
cellname = getCellName()
sop(m,"cellname=" + cellname)

# Query the first node name.
nodelist = listAppServerNodes()
nodename = nodelist[0]
sop(m,"nodename=" + nodename)

# Create the cluster.
createCluster( cellname, clustername, createReplicationDomain )

# Create each server within the cluster.
createServerInCluster( clustername, nodename, server1name, sessionReplication )
createServerInCluster( clustername, nodename, server2name, sessionReplication )

# Save and synchronize