首页 > 解决方案 > WebSphere 8 获取 ClusterName,将 AppName 作为输入

问题描述

我有一些在 WebSphere - Java 8 上运行的应用程序。

有没有办法只使用 jython 命令来获取应用程序正在运行的集群,并将应用程序名称作为输入?

例如应用程序名称:myApp Cluster myApp 运行:?

目标是创建一个脚本来在集群上进行涟漪启动,只需将应用程序名称作为输入。

标签: webspherejython

解决方案


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

但是,如果您不想在项目中使用 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

推荐阅读