get partial running status of application using jython

5k Views Asked by At

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

2

There are 2 best solutions below

1
On BEST ANSWER

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.

1
On

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"