0
votes

I have some applications running on WebSphere - Java 8.

Is there a way, using just jython commands, to get the cluster an application is running giving an app name as input?

For example app name: myApp Cluster myApp runs: ?

The goal is to create a script to make a ripplestart on the cluster just giving the app name as input.

2

2 Answers

0
votes

It's quite a lot of nested config elements to chase in jython to get there, but wsadminlib.py has a method getClusterTargetsForApplication you can call that makes it super easy:

https://github.com/wsadminlib/wsadminlib/blob/master/bin/wsadminlib.py#L3456

If you've never used wsadminlib.py, just 'execfile' it from a script or the REPL and then you can use any of the functions.

0
votes

Using functions from wsadminlib.py is the easiest option, as pointed out by covener. It comes with a host of other util functions as well.

However, if you don't want to use wsadminlib.py in your project and is looking for a quick solution, below snippet would work:

#Define the app name here or pass it as input
appName='DUMMY_APP_NAME'

#Get the app deployment ID
depId = AdminConfig.getid('/Deployment:%s/' % ( appName ))

#Get the deployment target details and convert it to a list
depTargetList = AdminUtilities.convertToList(AdminConfig.showAttribute(depId, 'deploymentTargets'))

#iterate the list and find the target details and print the result
for depTarget in depTargetList:
    targetName = AdminConfig.showAttribute(depTarget, 'name')
    print 'App %s is deployed to %s' %(appName, targetName)
#end for

You may further refine the result by checking if the target is a cluster or a server as given below:

for depTarget in depTargetList:
    targetName = AdminConfig.showAttribute(depTarget, 'name')
    if depTarget.find('ClusteredTarget') != -1:
        targetType = 'Cluster'
    else:
        targetType = 'Server'
    #end if

    print 'App %s is deployed to %s: %s' %(appName, targetType, targetName)

#end for