Using Jython to find an appServer's profile

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
Who is Participating?
HonorGodSoftware EngineerCommented:
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

BbouchAuthor Commented:
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
HonorGodSoftware EngineerCommented:
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?
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

HonorGodSoftware EngineerCommented:
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.

BbouchAuthor Commented:
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.
HonorGodSoftware EngineerCommented:
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?
HonorGodSoftware EngineerCommented:
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

HonorGodSoftware EngineerCommented:
ah. instead of:

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

we should really use:

import os

  profName =  profile.split( os.sep )[ -1 ]
BbouchAuthor Commented:
Toko me a little while to work through it in my head, but I think I understand this code now :)

Thanks again!
HonorGodSoftware EngineerCommented:
You are very welcome.

Thank you for the grade and points.

Good luck & have a great day.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.