WLST – BEAWorld session – part 2

Continuing with the demo …
After connecting to the Administration server, I ran a script that navigated me to the edit tree. Started an edit session with the server, configured servers, a Cluster and started the cluster. Lets take a look at the script.

# start the edit session, configure servers, cluster and start the cluster
print “configuring servers and cluster”
edit()
startEdit()
print cmo
svr1 = cmo.createServer(“ms1″)
svr2 = cmo.createServer(“ms2″)
clus = cmo.createCluster(“mycluster”)
svr1.setListenPort(8001)
svr2.setListenPort(9001)
svr1.setCluster(clus)
svr2.setCluster(clus)
save()
activate()
print “Done configuring servers and cluster”
print “start the cluster”
start(“mycluster”,”Cluster”)
print “Done starting the Cluster”

There is a global variable in WLST called ‘cmo‘ that stands for ‘Current Managed Object‘. This variable is always set to the MBean proxy object that the user navigated to. Since the root of edit tree/drive is DomainMBean, the cmo is set to the DomainMBean proxy. One of the best features of Jython or in fact any Java scripting tool I like the most is to be able to invoke any of the public methods on Java objects in a script. You can declare variables on the fly and assign java objects to these variables. In the script shown above I invoked the method ‘createServer‘ on DomainMBean’s proxy (cmo) and assigned the return value (which is the ServerMBean) to the variable ‘svr1‘. Later I invoked the method ‘setListenPort‘ on the ServerMBean Proxy stored in the variable ‘svr1‘. You can also verify all you changes with the ‘showChanges‘ command. Once you do a save(), you will notice that the changes are written to the DOMAIN_DIR/pending directory and once you do an activate the changes are applied to the running server and the files in the pending directory are removed. After activating my changes with the command ‘activate‘, I started the Cluster. Under the covers WLST invokes the Administration Server which inturn sends the command to start the Servers to Node Manager. Node Manager starts the servers and monitors the state of these servers.
···For the demo I chose to start a Cluster but I was little paranoid because to start a Cluster you will need a network connection to your machine. If in case I did not have a network connection I thought I would just start the servers without a cluster with the backup script as shown below.

# start the edit session, configure serversand start the servers
print “configuring servers “
edit()
startEdit()
print cmo
svr1 = cmo.createServer(“ms1″)
svr2 = cmo.createServer(“ms2″)
svr1.setListenPort(8001)
svr2.setListenPort(9001)
save()
activate()
print “Done configuring servers”
print “start the servers”
start(“ms1″, block=”false”)
start(“ms2″)
print “Done starting the servers”

In my script I had start(‘ms1′, block=’false’) which will let the script to execute the next command after that without blocking. Here’s the WLST console output after running the script.

wls:/mydomain/serverConfig> execfile(“d:/bea/cs.py”)
Already Connected!
configuring servers and cluster

Location changed to edit tree. This is a writable tree
with DomainMBean as the root. To make changes you will
need to start an edit session via startEdit().
For more help, use help(‘edit’)

Starting an edit session …
Started edit session, please be sure to save and activate your
changes once you are done.
[MBeanServerInvocationHandler]com.bea:Name=mydomain,Type=Domain
Saving all your changes …
Saved all your changes successfully.
Activating all your changes, this may take a while …
The edit lock associated with this edit session is released
once the activation is completed.
Activation completed
Done configuring servers and cluster
start the cluster

Starting the following servers in Cluster, mycluster: ms2,ms1
……………………………………………………………………………………
All servers in the cluster mycluster are started successfully.
Done starting the Cluster
wls:/mydomain/edit>

Also, if you are in the interactive mode when you start an edit session, you will notice that the prompt contains a ‘!’ (wls:/mydomain/edit !>) indicating an edit session is in progress. As soon as you activate or stop your edit session the ‘!’ is gone from the prompt.

I will continue the demo in my next blog entry.

_uacct = “UA-2684269-2″;
urchinTracker();

One Response to “WLST – BEAWorld session – part 2”

  1. Mohan says:

    Hi Satya

    These are great stuff.

    Quick question, while running ConfigToScript, a config and key file was created which has multiple username passwords for various jdbc datasources, would you happen to know how create this file. I want to use the scripts generated by wlst to recreate a domain on a different environment, which means i have to change the database name it connects to and also the database password, which is where i am having the problem, since all the jdbc, nodemanager, password seems to be stored in a single config file. I am not sure how to store multiple id and passord in this file. I have used STOREUSERCONFIG, but it only stores the weblogic admin username and password.

    thanks for your help
    Mohan