Learn how to a build a cloud-first strategyRegister Now


Using Jython to find an appServer's profile

Posted on 2011-05-09
Medium Priority
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
  • 7
  • 3

Author Comment

ID: 35726189
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

ID: 35729312
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

ID: 35729420
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:

./manageprofiles.sh -listProfiles

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

./serverStatus.sh -all -profileName <profileName>


./serverStatus.sh -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.

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 35729536
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

ID: 35730555
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

ID: 35730710
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

HonorGod earned 2000 total points
ID: 35730797
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

HonorGod earned 2000 total points
ID: 35730970
ah. instead of:

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

we should really use:

import os

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

Author Closing Comment

ID: 35774160
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

ID: 35776429
You are very welcome.

Thank you for the grade and points.

Good luck & have a great day.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Configure Web Service (server application) I. Configure security for Web Services methods First, we need to protect Session bean which implements the service: 1. Open EJB deployment descriptor (ejb-jar.xml) in the EJB project that contains you…
Most of the developers using Tomcat find it easy to configure the datasource in Server.xml and use the JNDI name in the code to get the connection.  So the default connection pool using DBCP (or any other framework) is made available and the life go…
Screencast - Getting to Know the Pipeline
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

810 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