【发布时间】:2012-01-01 10:05:24
【问题描述】:
我可以获得已安装应用程序的列表,但如何使用 Jython 获得状态?
【问题讨论】:
-
我还将扩展您的问题以查看每个应用程序服务器的应用程序状态。那么我们应该会得到一些更有趣的答案。
我可以获得已安装应用程序的列表,但如何使用 Jython 获得状态?
【问题讨论】:
我认为没有任何直接的方法可以获取应用程序运行状态,您可以使用以下代码从 AdminControl 中获取对象
serverstatus = AdminControl.completeObjectName('type=Application,name='your_application_name',*')
print serverstatus
如果serverstatus返回null,那么应用程序没有运行,如果应用程序正在运行,那么将打印应用程序的详细信息。
【讨论】:
server=WPS00 或类似的东西吗?
process=WPS00,它将查看特定的 AppServer。
这是我根据 Snehan 的回答使用的。
import string
def getAppStatus(appName):
# If objectName is blank, then the application is not running.
objectName = AdminControl.completeObjectName('type=Application,name=' + appName + ',*')
if objectName == "":
appStatus = 'Stopped'
else:
appStatus = 'Running'
return appStatus
def appStatusInfo():
appsString = AdminApp.list()
appList = string.split(appsString, '\r\n')
print '============================'
print ' Status | Application '
print '============================'
# Print apps and their status
for x in appList:
print getAppStatus(x) + ' | ' + x
print '============================'
appStatusInfo()
样本输出
============================
Status | Application
============================
Running | DefaultApplication
Running | IBMUTC
Stopped | some-ear
Running | another-ear
============================
【讨论】:
以下 IBM 文档应该会有所帮助:
WAS 信息中心:Querying the application state using wsadmin scripting
IBM 技术说明:Listing enterprise application status using wsadmin script
总而言之,如果应用程序在应用程序服务器上运行,则会注册一个Application MBean。为了确定应用程序是否正在运行,您可以查询这些 MBean 是否存在。
【讨论】:
Cormier 的脚本 Matthieu 需要进行更多修改。
我们开始吧。
它适用于任何行分隔符。一般AdminApp.list()会使用“\”作为行分隔符
import string
def getAppStatus(appName):
# If objectName is blank, then the application is not running.
objectName = AdminControl.completeObjectName('type=Application,name='+ appName+',*')
if objectName == "":
appStatus = 'Stopped'
else:
appStatus = 'Running'
return appStatus
def appStatusInfo():
Apps=AdminApp.list().split(java.lang.System.getProperty("line.separator"))
print '============================'
print ' Status | Application '
print '============================'
# Print apps and their status
for x in Apps:
print "X value", x
print getAppStatus(x) + ' | ' + x
print '============================'
appStatusInfo()
【讨论】: