Using Jython to find an appServer's profile

Posted on 2011-05-09
Last Modified: 2013-12-10
Given an appServer name and the name of the node that appServer is on, how would I best go about gettnig the profile name that appServer is a part of?

I'm running WebSphere 7.0.x
Question by:Bbouch
    LVL 1

    Author Comment

    a little extra info.

    I want to update the classpath of an appServer to include a directory that is under the profile directory. Since our profile directories are different on each server, i need a way to programatically (preferably in jython) determine which profile a given application server is in before updating the classpath
    LVL 41

    Expert Comment

    Interesting question.

    Unfortunately, there appears to be no "easy" way to determine this programatically from within a Jython script.

    I would probably do something like have some kind of input file that identifies the configured nodes and servers for a given profileName, and use this as input to the Jython script.

    Does this make sense?
    LVL 41

    Expert Comment

    Even using the WebSphere command scripts, we can't list the nodeName and serverName for the servers in a given profile.

    For exampe, we can list the configured profiles using:

    ./ -listProfiles

    and then list the names of the servers in each of the profiles using:

    ./ -all -profileName <profileName>


    ./ -all -profileName AppSrv01

    But that will only list the names of the servers, not the name of the node.

    So, I believe that the simple answer to your question is:

    No, this can't be done.

    LVL 1

    Author Comment

    It does, Honorgod, but I think I may have found something you could probably help with  that may work...

    It looks like the profile directory is stored in the variables.xml file for a given node under the variable name "USER_INSTALL_ROOT"

    I believe I should be able to access this WebSphere variable (at the node's scope), but I'm not sure exactly how. I've been poking around this morning and found a script that will get the VariableMap for a cell's scope, but I'm having trouble translating that to my particular node.

    The Example code I'm working with is included here:
    import sys
    def wsadminToList(inStr):
            if (len(inStr)>0 and inStr[0]=='[' and inStr[-1]==']'):
                    tmpList = inStr[1:-1].split(" ")
                    tmpList = inStr.split("\n")  #splits for Windows or Linux
            for item in tmpList:
                    item = item.rstrip();        #removes any Windows "\r"
                    if (len(item)>0):
            return outList
    cell = AdminConfig.list("Cell")
    cellName = AdminConfig.showAttribute(cell, "name")
    cellWebSphereVariableMap = AdminConfig.getid("/Cell:"+cellName+"/VariableMap:/")
    cellEntries = AdminConfig.showAttribute(cellWebSphereVariableMap, "entries")
    entryList = wsadminToList(cellEntries)
    if (len(cellEntries) != '[]'):
            for cellEntry in entryList:
                    varName = AdminConfig.showAttribute(cellEntry, "symbolicName")
                    print "var Name is : "+varName
                    varVal = AdminConfig.showAttribute(cellEntry, "value")
                    print " var value is : "+varVal

    Open in new window

    I think all I essentially need to do is add something to the line:

    cellWebSphereVariableMap = AdminConfig.getid("/Cell:"+cellName+"/VariableMap:/")

    Open in new window

    but I haven't quite got it nailed down yet.  Any insight would be appreciated.
    LVL 41

    Expert Comment

    ooh, we're into WebSphere variables now.

    Another interesting topic.  ;-)

    The way that I resolve a WebSphere variable into a complete value is a multi-step process that depends upon the scope.

    So I use code to:
    - build a scope specific variables dictionary
    - loop over the string, looking for '${variable}', and looking in the dictionary for "variable" values

    Does this help?  Or do you want / need my non-trivial code?
    LVL 41

    Expert Comment

    Example interactive use of my code results in the following, so it may we may need to massage the result.

    Does that make sense?
    wsadmin>for server in AdminConfig.list( 'Server' ).splitlines() :
    wsadmin>  print '%10s : %s' % ( AdminConfig.showAttribute( server, 'name' ), WAuJ.unravel( '${USER_INSTALL_ROOT}', server ) )
       Member1 : /opt/IBM/WebSphere/AppServer70/profiles/AppSrv01
          dmgr : /opt/IBM/WebSphere/AppServer70/profiles/Dmgr01
     nodeagent : /opt/IBM/WebSphere/AppServer70/profiles/AppSrv01
       server1 : /opt/IBM/WebSphere/AppServer70/profiles/AppSrv01

    Open in new window

    LVL 41

    Accepted Solution

    So, I guess the answer is yes. ;-)

    Column 1 == Node Name
    Column 2 == Server Name
    Column 3 == profileName
    wsadmin>for server in AdminConfig.list( 'Server' ).splitlines() :
    wsadmin>  cfgDict = WAuJ.configIdAsDict( server )
    wsadmin>  profile = WAuJ.unravel( '${USER_INSTALL_ROOT}', server )
    wsadmin>  profName =  profile.split( '/' )[ -1 ]
    wsadmin>  print '%20s %-10s %s' % ( cfgDict[ 'nodes' ], cfgDict[ 'servers' ], profName )
           ragdollNode03 Member1    AppSrv01
    ragdollCellManager02 dmgr       Dmgr01
           ragdollNode03 nodeagent  AppSrv01
           ragdollNode03 server1    AppSrv01

    Open in new window

    LVL 41

    Assisted Solution

    ah. instead of:

      profName =  profile.split( '/' )[ -1 ]

    we should really use:

    import os

      profName =  profile.split( os.sep )[ -1 ]
    LVL 1

    Author Closing Comment

    Toko me a little while to work through it in my head, but I think I understand this code now :)

    Thanks again!
    LVL 41

    Expert Comment

    You are very welcome.

    Thank you for the grade and points.

    Good luck & have a great day.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Join & Write a Comment

    -Xmx and -Xms are the two JVM options often used to tune JVM heap size.   Here are some common mistakes made when using them:   Assume BigApp is a java class file for the below examples. 1.         Missing m, M, g or G at the end …
    This exercise is about for the following scenario: Dmgr and One node with 2 application server. Each application server contains it owns application. Application server name as follows server1 contains app1 server2 contains app1 Prereq…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now