IBM WebSphere:如何使用 wsadmin 脚本将应用程序映射到多个集群?

IBM WebSphere: How to map an application to multiple clusters using wsadmin scripting?

我正在尝试使用 wsadmin 脚本自动部署映射到一个单元中的两个集群的应用程序。但无论我如何尝试,应用程序都只能映射到一个集群。结果,应用程序根本没有启动。

我收到以下错误消息:

Application helloteam_07062019_1956 is not deployed on the cluster SPPAbcd
Exception: exceptions.AttributeError WASL6048E: The helloteam_07062019_1956 application is not deployed on the SPPAbcd target.  
WASX7017E: Exception received while running file "/app/was_scripts/main_scripts/deploy_mutlitest.py"; exception information: com.ibm.bsf.BSFException: exception from Jython:
Traceback (innermost last):
  File "<string>", line 175, in ?
  File "/app/service/IBM/WebSphere/AppServer/scriptLibraries/application/V70/AdminApplication.py", line 4665, in startApplicationOnCluster
ScriptLibraryException: : 'exceptions.AttributeError WASL6048E: The helloteam_07062019_1956 application is not deployed on the SPPAbcd target. '

从报错信息可以看出app只映射到SRVApp集群,没有映射到SPPAbcd集群。结果,它无法启动该应用程序。

这是脚本:

targetServerOne = "WebSphere:cell=DIGIAPP1Cell02,cluster=SPPAbcd"
targetServerTwo = "WebSphere:cell=DIGIAPP1Cell02,cluster=SRVApp"

AdminApp.install(location, ['-appname',"hellotest",'-defaultbinding.virtual.host',virtualHost,'-usedefaultbindings','-contextroot',ctxRoot,'-MapModulesToServers',[["EchoApp",URI,targetServerOne],["EchoApp",URI,targetServerTwo]]])
AdminConfig.save()

cell=AdminConfig.list('Cell')
cellName=AdminConfig.showAttribute(cell, 'name')
clusters=AdminConfig.list('ServerCluster').split('\n')
print("The clusters in "+cellName+" are...")
print(clusters)

for name in startClusters:
    startapp = AdminApplication.startApplicationOnCluster(newWar, name)
    print(startapp)

如前所述,无论我尝试什么,该应用程序都只会映射到 SRVApp 集群(在 DMGR 控制台中检查应用程序的管理模块部分之后)。它没有映射到 SPPAbcd 集群。

如何实现正确的模块映射到多集群? adminapp.install 命令中提到了模块映射部分。这是映射模块的正确方法吗?

提前致谢和问候。

-克里斯

为了解决这个问题,我利用了 Jenkins 的 EnvInject 插件在构建时注入属性。

我没有使用两个目标服务器(targetServerOne 和 targetServerTwo),而是只使用目标服务器,并从属性文件中调用它。

这是我的属性文件:

moduleMapping=WebSphere:cell=cell1,cluster=cluster1+WebSphere:cell=cell1,cluster=cluster2

我的脚本修改如下:

from os import getenv as env

targetServer = env(‘moduleMapping’)

AdminApp.install(filename, [ ‘-MapModulesToServers, [[‘moduleName’, ‘uri’, targetServer]]])

这已将我的应用程序映射到一个单元内的两个集群。