使用jython获取应用程序的部分运行状态

时间:2011-10-11 07:35:17

标签: websphere jython wsadmin

您好我需要知道应用程序是否部分运行。使用以下命令,我可以在应用程序运行时获取信息。

serverstatus = AdminControl.completeObjectName('type=Application,name='+n1+',*')
print serverstatus

是否还有其他人要检查应用程序的当前状态是否部分运行。??

此致 Snehan Solomon

2 个答案:

答案 0 :(得分:2)

为了准确确定应用程序是否已部分启动/停止,您必须首先确定部署应用程序的部署目标,然后确定该应用程序是否在该服务器上运行:

def isApplicationRunning(applicationName, serverName, nodeName) :
    return AdminControl.completeObjectName("type=Application,name=%s,process=%s,node=%s,*" % (applicationName, serverName, nodeName)) != ""

def printApplicationStatus(applicationName) :

    servers = started = 0
    targets = AdminApplication.getAppDeploymentTarget(applicationName)
    for target in targets :
        type = AdminConfig.getObjectType(target)
        if (type == "ClusteredTarget") :
            clusterName = AdminConfig.showAttribute(target, "name")
            members = AdminUtilities.convertToList(AdminConfig.getid("/ServerCluster:%s/ClusterMember:/" % clusterName))
            for member in members :
                serverName = AdminConfig.showAttribute(target, "name")
                nodeName = AdminConfig.showAttribute(member, "nodeName")
                started += isApplicationRunning(applicationName, serverName, nodeName)
                servers += 1
        elif (type == "ServerTarget") :
            serverName = AdminConfig.showAttribute(target, "name")
            nodeName = AdminConfig.showAttribute(target, "nodeName")
            started += isApplicationRunning(applicationName, serverName, nodeName)
            servers += 1

    if (started == 0) :
        print "The application [%s] is NOT RUNNING." % applicationName
    elif (started != servers) :
        print "The application [%s] is PARTIALLY RUNNING." % applicationName
    else :
        print "The application [%s] is RUNNING." % applicationName

if (__name__ == "__main__"):
    printApplicationStatus(sys.argv[0]);

请注意,AdminApplication script library仅适用于WAS 7+,因此如果您运行的是旧版本,则需要自行获取部署目标。

答案 1 :(得分:1)

我能够根据节点数获得应用程序的部分状态。我只是对节点数量进行了硬编码,然后将它们与它们返回的MBean数量进行了比较。

import sys
appName = sys.argv[0]
appCount=0
nodeCount=2
appMBeans = AdminControl.queryNames('type=Application,name='+appName+',*').split("\n")
for mbean in appMBeans:
if mbean != "":
    appCount=appCount+1
print "Count of Applications is %s" %(appCount)
if appCount == 0:
    print "----!!!ALERT!!!!---- The Application "+appName+" is Not Running"
elif appCount > 0 and appCount < nodeCount:
    print "----!!!ALERT!!!!---- The Application "+appName+" is Partially Running"
elif appCount == nodeCount:
    print "The Application "+appName+" is Running"