WebSphere 8获取以AppName作为输入的ClusterName

WebSphere 8获取以AppName作为输入的ClusterName,websphere,jython,Websphere,Jython,我有一些应用程序在WebSphere-Java8上运行 是否有一种方法,仅使用jython命令,就可以获取应用程序正在运行的集群,并将应用程序名称作为输入 比如说 应用程序名称:myApp 群集myApp运行: 我们的目标是创建一个脚本,在集群上创建一个ripplestart,只需输入应用程序名即可。要在jython中找到很多嵌套的配置元素,但是wsadminlib.py有一个方法getClusterTargetsForApplication,您可以调用该方法,使其非常简单: 如果您从未使用过

我有一些应用程序在WebSphere-Java8上运行

是否有一种方法,仅使用jython命令,就可以获取应用程序正在运行的集群,并将应用程序名称作为输入

比如说 应用程序名称:myApp 群集myApp运行:


我们的目标是创建一个脚本,在集群上创建一个ripplestart,只需输入应用程序名即可。

要在jython中找到很多嵌套的配置元素,但是wsadminlib.py有一个方法
getClusterTargetsForApplication
,您可以调用该方法,使其非常简单:


如果您从未使用过wsadminlib.py,只需从脚本或REPL中“execfile”它,然后您就可以使用任何函数。

正如covener所指出的,使用wsadminlib.py中的函数是最简单的选择。它还附带许多其他util函数

但是,如果您不想在项目中使用wsadminlib.py,并且正在寻找快速解决方案,那么下面的代码段就可以了:

#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
您可以通过检查目标是群集还是服务器来进一步细化结果,如下所示:

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