dev2dev.bea.com.cn
首页 资源中心 dev2dev学堂 在线技术论坛 专家Blog User Group CodeShare

WLST——BEAWorld大会,第二部分

2005-12-05 00:00:00 | 评论 (0) | 被访问(386)次

Satya Ghattu
  Satya Ghattu加入BEA公司已经有4年多了,担任软件工程师,专门负责WebLogic Platform的Operations Administration以及Management方面。Satya拥有将近8年的软件开发经验,主要是在应用服务器、核心java以及相关的(J2EE)技术方面。他还领导着dev2dev上CodeShare中的几个开源项目,并向dev2dev社区贡献了大量的代码示例。Satya是WebLogic Scripting Tool (WLST)的最初设计者,该工具是BEA官方支持的WebLogic Server命令行工具。在加入BEA之前,他曾在许多软件公司担任各种不同的职务,做过高级Java开发人员、软件分析师,还做过Oracle数据库管理员。Satya持有俄亥俄州Akron大学的工程学硕士学位。


  继续介绍演示……
  连接到管理服务器之后,我运行了一个使我导航到编辑树的脚本。启动了与服务器的编辑会话,配置服务器、一个集群,并启动集群。我们来看一下脚本:

# 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



Tags: WLST BEAWorld script demo 脚本 演示
文章评论:(以下网友留言只代表个人观点,不代表BEA观点和立场)
暂时没有评论!

2005年12月

      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  
             
RSS订阅

Satya Ghattu's Blog搜索