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

发布于 2024-12-09 02:16:57 字数 236 浏览 3 评论 0原文

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

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

是否还有其他方法可以检查应用程序的当前状态是否部分运行。?

问候 斯内汉·所罗门

Hi I need to know if the application is running partially. using the following command I am able to get info if the application is running.

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

Is there any other was to check if the current status of application is partially running.??

Regards
Snehan Solomon

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

奈何桥上唱咆哮 2024-12-16 02:16:57

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

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 脚本库 仅适用于 WAS 7+,因此如果您运行的是旧版本,则需要自行获取部署目标。

In order to accurately determine whether the application is partially started/stopped, you must first determine the deployment targets against which the application is deployed, and then determine whether or not the application is running on that server:

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]);

Note that the AdminApplication script library only exists for WAS 7+, so if you are running an older version, you will need to obtain the deployment targets yourself.

夜巴黎 2024-12-16 02:16:57

我能够根据节点数量获取应用程序的部分状态。我只是对节点数量进行了硬编码,然后将它们与它们返回的 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"

I was able to get the partial status of application based on the number of nodes. I just hardcoded the number of nodes and then compared them against the number of MBeans they returned.

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"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文