2016-06-23 23 views
0

TL; DR, Einige, wie das Present Working Directory dem EAR-Standort vorangestellt wird.wsadmin - Jython-Skript, das PWD abholt, wenn es nicht angegeben wird

Ich versuche, ein Jython-Skript für IBM WebSphere ND auszuführen, um eine Stapelinstallation einiger Anwendungen in einem Verzeichnis durchzuführen. Das Skript benötigt zwei Argumente, den Pfad zu den EARs und dann die Modulzuordnungen. Beim Durchlaufen dieses Skripts führt es die Erkennung der Apps korrekt aus und druckt den richtigen AdminApp.install() - Befehl, aber wenn ich den eigentlichen Befehl ausführe, wird das PWD irgendwie in das EAR-Verzeichnis verschoben.

# 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 

Dann führe ich das Skript mit diesen Befehlen. Ich habe einen Run_wsadmin.sh-Wrapper erstellt, um den Benutzernamen und die Kennwörter neben anderen Optionen zu maskieren, um die wsadmin-Konsole zu starten und Skripts auszuführen.

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 ]]]'" 

Also, ich bin nicht sicher, wo die PWD herkommt, aber in der EAR Lage, es hält voranstellt, die vorliegende Arbeitsverzeichnis. Woher kommt das? Das hat mich den ganzen Tag verrückt gemacht, und ich habe keine Optionen mehr.

Antwort

1

Die Signatur ist:

AdminApp.install(earFile,options) 

So wie es ist wahrscheinlich einfacher zu versuchen, sie auseinander in zwei separate args brechen:

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)