继续介绍演示……
连接到管理服务器之后,我运行了一个使我导航到编辑树的脚本。启动了与服务器的编辑会话,配置服务器、一个集群,并启动集群。我们来看一下脚本:
# 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"
在WLST中有一个全局变量cmo,它代表Current Managed Object(当前托管对象)。该变量总是被设为用户导航到的MBean代理对象。因为编辑树/驱动程序的根目录是DomainMBean,所以cmo被设为DomainMBean代理。Jython或任何Java脚本编写工具的一个我最喜欢的特性就是,能够在脚本中对Java对象调用任何的公共方法。可以动态地声明变量,并将java对象赋值给这些变量。在上面的脚本中,我对DomainMBean的代理(cmo)调用了createServer方法,并将返回值(ServerMBean)赋值给svr1变量。然后我对存储在svr1变量中的ServerMBean Proxy调用setListenPort方法。可以使用showChanges命令验证所有更改。一旦执行save(),您就会发现,更改被写入DOMAIN_DIR/pending目录中,而且一经激活,更改就会应用于运行中的服务器,挂起目录中的文件就会被删除。使用activate命令激活更改后,我启动了集群。在后台,WLST调用管理服务器,后者又发送启动服务器的命令给Node Manager。Node Manager启动服务器,并监控这些服务器的状态。
在演示中,我选择启动集群,这有点偏执,因为要启动集群机器上需要有网络连接。如果没有网络连接,就只好使用下面所示的后备脚本启动服务器而不是启动集群了:
# 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"
start('ms1', block='false')使脚本可以继续执行下一条命令而不阻塞。下面是运行脚本后的WLST控制台输出:
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>
此外,如果启动编辑会话时处于交互模式,就可以发现提示符中包含一个“!”(wls:/mydomain/edit !>),这表示有一个编辑会话正在进行。一旦激活或停止编辑会话,“!”就会从提示符中消失。
我将在下一篇文章中继续介绍该演示。
单击此处,可获得有关BEAWorld上的所有演讲的更多信息。北京BEAWorld请点击这里。
原文出处:http://dev2dev.bea.com/blog/sghattu/archive/2005/10/wlst_beaworld_s_1.html