【问题标题】:wsadmin - Jython script picking up PWD when its not specifiedwsadmin - Jython 脚本在未指定时拾取 PWD
【发布时间】:2016-06-23 20:57:21
【问题描述】:

TL;DR, 一些如何将当前工作目录添加到 EAR 位置。

我正在尝试为 IBM WebSphere ND 运行 Jython 脚本,以便在目录中批量安装一些应用程序。该脚本采用两个参数,即 EAR 的路径,然后是模块映射。通过这个脚本,它正确地发现了应用程序,并打印了正确的 AdminApp.install() 命令,但是当我运行实际命令时,它以某种方式将 PWD 放在了 EAR 目录中。

# This script takes a batch list of EAR names with the extension .ear
# example:
#   script.py "/path/to/ear/files" "WebSphere:cell=CELL,stuff=..."
#

import os
import sys 

# Gets the Cell Name for the environment
cell_name = AdminControl.getCell()

# Get DMGR Name
dmgr_name = "DMGRDEV" # Needs to not be hardcoded

# The location where the EARs will be stored to be installed. 
#ear_location = "/home/wasadmin/ears"
ear_location = sys.argv[0]

# Gets list of files in a directory
dirs = os.listdir( ear_location )

# JVMs and clusters to map the application to. 
map_to_modules = sys.argv[1]

for app_name in dirs :
  install_app = "'%s/%s', '[ -MapModulesToServers [[ %s ]]]'" % ( ear_location, app_name, map_to_modules )
  print("Installing " + app_name + ".")
  print("AdminApp.install( %s )" % ( install_app ) )
  AdminApp.install( install_app )
  print("Saving Changes.")
  AdminConfig.save()
  print("Synching Changes.")
  AdminControl.invoke('' + AdminControl.completeObjectName(""+ dmgr_name +",type=DeploymentManager,*") + '', 'multiSync', '[false]', '[java.lang.Boolean]')
# End of for app_name in applicaiton_array

然后我使用这些命令运行该脚本。我制作了一个 Run_wsadmin.sh 包装器来屏蔽用户名和密码以及启动 wsadmin 控制台和运行脚本的其他选项。

Run_wsadmin.sh -f installEAR.py "/opt/IBM/WebSphere/AppExports3" "WebSphere:cell=wsibpmpsdev00Cell01,cluster=DEV00_DE_1.AppCluster+WebSphere:cell=wsibpmpsdev00Cell01,node=WPS00,server=DEV00IHS00"
WASX7209I: Connected to process "dmgr" on node DMGRDEV using SOAP connector;  The type of process is: DeploymentManager
WASX7303I: The following options are passed to the scripting environment and are available as arguments that are stored in the argv variable: "[/opt/IBM/WebSphere/AppExports3, WebSphere:cell=wsibpmpsdev00Cell01,cluster=DEV00_DE_1.AppCluster+WebSphere:cell=wsibpmpsdev00Cell01,node=WPS00,server=DEV00IHS00]"
Installing Solution_ChangeApp.ear.
AdminApp.install( '/opt/IBM/WebSphere/AppExports3/Solution_ChangeApp.ear', '[ -MapModulesToServers [[ WebSphere:cell=wsibpmpsdev00Cell01,cluster=DEV00_DE_1.AppCluster+WebSphere:cell=wsibpmpsdev00Cell01,node=WPS00,server=DEV00IHS00 ]]]' )
WASX7017E: Exception received while running file "installEAR.py"; exception information: com.ibm.ws.scripting.ScriptingException: WASX7115E: Cannot read input file "/home/wasadmin/ContinuousIntegrationScripts/'/opt/IBM/WebSphere/AppExports3/Solution_ChangeApp.ear', '[ -MapModulesToServers [[ WebSphere:cell=wsibpmpsdev00Cell01,cluster=DEV00_DE_1.AppCluster+WebSphere:cell=wsibpmpsdev00Cell01,node=WPS00,server=DEV00IHS00 ]]]'" 

所以,我不确定 PWD 来自哪里,但在 EAR 位置中,它一直在当前工作目录前面。那是从哪里来的?这让我一整天都发疯了,我别无选择。

【问题讨论】:

    标签: python websphere jython wsadmin


    【解决方案1】:

    签名是:

    AdminApp.install(earFile,options)
    

    因此,尝试将其拆分为两个单独的参数可能更容易,例如:

    for app_name in dirs :
        install_app_loc = "%s/%s" % ( ear_location, app_name)
        install_app_opts = "'[ -MapModulesToServers [[ %s ]]]'" % ( map_to_modules )
        # ...
        AdminApp.install( install_app_loc, install_app_opts)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-12
      • 2021-01-11
      • 1970-01-01
      • 2015-05-01
      • 2019-02-19
      • 2019-06-26
      • 1970-01-01
      相关资源
      最近更新 更多