First python script to list server in websphere

Mohammed Aarif Shaikh
Mohammed Aarif Shaikh used Ask the Experts™
Hi All,

This is my frist python script working on... I would like to list the servers or cluster from websphere. The script contents are below...
run by cmd - wsadmin.bat -lang jython -F
Error -
WASX7209I: Connected to process "dmgr" on node dmgrNode using SOAP connector;  The type of process is: DeploymentManager
WASX7017E: Exception received while running file ""; exception information: exception from Jython:
Traceback (most recent call last):
  File "<string>", line 13, in <module>
ValueError: call stack is not deep enough

Content of the script - this example got from - C:\IBM\WebSphere\AppServer\scriptLibraries\servers\V70

# Set global constants
import sys
import java
import AdminUtilities

# Setting up Global Variable within this script
bundleName = ""
resourceBundle = AdminUtilities.getResourceBundle(bundleName)

# Retrieve scripting objects from local name space
AdminConfig = sys._getframe(1).f_locals['AdminConfig']
AdminApp = sys._getframe(1).f_locals['AdminApp']
AdminControl = sys._getframe(1).f_locals['AdminControl']
AdminTask = sys._getframe(1).f_locals['AdminTask']
Help = sys._getframe(1).f_locals['Help']    

## Example 1 List available servers with given server type and node ##
def listServers(serverType="", nodeName="", failonerror=AdminUtilities._BLANK_):
    if (failonerror==AdminUtilities._BLANK_):
    msgPrefix = "listServers("+`serverType`+", "+`nodeName`+", "+`failonerror`+"): "

        # List servers
        print "---------------------------------------------------------------"
        print " AdminServerManagement:  List servers"
        print " Optional parameters: "
        print "         Server type:    "+serverType
        print "         Node name:      "+nodeName
        print " Usage: AdminServerManagement.listServers(\""+serverType+"\", \""+nodeName+"\") "
        print " Return: List of the servers in the cell. The list is filtered based on the server type and node name parameters if they are provided."
        print "---------------------------------------------------------------"
        print " "
        print " "
        # Construct optional parameters
        optionalParamList = []

        if (len(serverType) > 0):
            optionalParamList = ['-serverType', serverType]

        if (len(nodeName) > 0):
            # check if node exists
            node = AdminConfig.getid("/Node:appNode1" +nodeName+"/")
            if (len(node) == 0):
               raise AttributeError(AdminUtilities._formatNLS(resourceBundle, "WASL6040E", ["nodeName", nodeName]))
            optionalParamList = optionalParamList + ['-nodeName', nodeName]

        # List servers with specified server type
        servers = AdminTask.listServers(optionalParamList)

        # Convert Jython string to list
        servers = AdminUtilities.convertToList(servers)

        # Loop through each server in server list
        newservers = []
        for aServer in servers:
            # Obtain server and node names
            sname = aServer[0:aServer.find("(")]
            nname = aServer[aServer.find("nodes/")+6:aServer.find("servers/")-1]
            # Retrieve the server config id
            sid = AdminConfig.getid("/Node:appNode1"+nname+"/Server:"+sname)
            # convert unicode string to normal string
            sid = str(sid)
            if (newservers.count(sid) <= 0):
            #AdminUtilities.infoNotice("Server: " + sid)  
        return newservers
        typ, val, tb = sys.exc_info()
        if (typ==SystemExit):  raise SystemExit,`val`
        if (failonerror != AdminUtilities._TRUE_):
            print "Exception: %s %s " % (sys.exc_type, sys.exc_value)
            val = "%s %s" % (sys.exc_type, sys.exc_value)
            raise Exception("ScriptLibraryException: " + val)
            return -1
            return, val, tb), failonerror)

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

I don't get it. Why are you running Python on a Java application server?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial