wsadmin - Jython 脚本在未指定时获取 PWD
wsadmin - Jython script picking up PWD when its not specified
长话短说;博士,
当前工作目录是如何添加到 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 位置中,它一直在当前工作目录之前。那是从哪里来的?这让我一整天都快发疯了,我别无选择。
签名是:
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)
长话短说;博士, 当前工作目录是如何添加到 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 位置中,它一直在当前工作目录之前。那是从哪里来的?这让我一整天都快发疯了,我别无选择。
签名是:
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)