deployConsole.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. #------------------------------------------------------------------------------
  2. # Admin console deployment/undeployment script
  3. #
  4. # Installing the console:
  5. # wsadmin.sh -f deployConsole.py install
  6. #
  7. # Uninstalling the console:
  8. # wsadmin.sh -f deployConsole.py remove
  9. #------------------------------------------------------------------------------
  10. import sys
  11. #------------------------------------------------------------------------------
  12. # Get the directory, as a string, where WAS is installed.
  13. #------------------------------------------------------------------------------
  14. def getWASHome(cell, node):
  15. varMap = AdminConfig.getid("/Cell:" + cell + "/Node:" + node + "/VariableMap:/")
  16. entries = AdminConfig.list("VariableSubstitutionEntry", varMap)
  17. eList = entries.splitlines()
  18. for entry in eList:
  19. name = AdminConfig.showAttribute(entry, "symbolicName")
  20. if name == "WAS_INSTALL_ROOT":
  21. value = AdminConfig.showAttribute(entry, "value")
  22. return value
  23. #failover
  24. return java.lang.System.getenv('WAS_HOME')
  25. #------------------------------------------------------------------------------
  26. # Get the WAS systemApps directory.
  27. #
  28. # The WAS systemApps directory is always located at <WAS_HOME>/systemApps
  29. #------------------------------------------------------------------------------
  30. def getSystemAppsDir(cell, node):
  31. fileSep = getFileSep(node)
  32. return getWASHome(cell, node) + fileSep + "systemApps"
  33. #------------------------------------------------------------------------------
  34. # Get the directory, as a string, of the isclite.ear application.
  35. #
  36. # The isclite.ear is located in <WAS_HOME>/systemApps/isclite.ear
  37. #------------------------------------------------------------------------------
  38. def getISCDir(cell, node):
  39. fileSep = getFileSep(node)
  40. return getSystemAppsDir(cell, node) + fileSep + "isclite.ear"
  41. #------------------------------------------------------------------------------
  42. # Get the file separator character
  43. #
  44. # This gets the file separator for the node in which we plan to install the
  45. # console. Therefore we can't just use the value that python on Java gives
  46. # us. Instead, check the platform of the node, and use "\" for windows and
  47. # "/" for everything else.
  48. #------------------------------------------------------------------------------
  49. def getFileSep(node):
  50. os = AdminTask.getNodePlatformOS("-nodeName " + node)
  51. if os == 'windows':
  52. return '\\'
  53. else:
  54. return '/'
  55. #------------------------------------------------------------------------------
  56. # updateDeploymentXml
  57. # sharedLibBypass = true
  58. # enableSecurityIntegration=true
  59. # Default cookie path should be /ibm
  60. #------------------------------------------------------------------------------
  61. def updateDeploymentXml():
  62. try:
  63. print "Updating deployment.xml"
  64. isclite = AdminConfig.getid("/Deployment:isclite/")
  65. iscliteDepObject = AdminConfig.showAttribute(isclite, "deployedObject")
  66. prop = [['name', 'com.ibm.ws.classloader.sharedLibBypass'], ['value', 'true'], ['required', 'false']]
  67. AdminConfig.create("Property", iscliteDepObject, prop)
  68. attr1 = ['enableSecurityIntegration', 'true']
  69. attrs = [attr1]
  70. sessionMgr = [['sessionManagement', attrs]]
  71. configs = AdminConfig.showAttribute (iscliteDepObject, "configs")
  72. appConfig = configs[1:len(configs)-1]
  73. SM = AdminConfig.showAttribute (appConfig, 'sessionManagement')
  74. AdminConfig.modify (SM, attrs)
  75. kuke = AdminConfig.showAttribute (SM, 'defaultCookieSettings')
  76. kukeAttrs = [['path', '/ibm']]
  77. AdminConfig.modify(kuke, kukeAttrs)
  78. return 1
  79. except:
  80. print "Error during updateDeploymentXml():", sys.exc_info()
  81. return 0
  82. #------------------------------------------------------------------------------
  83. # updateServerXml to setup KC_HOME JVM custom property
  84. #------------------------------------------------------------------------------
  85. def updateServerXml(cell, node, server):
  86. try:
  87. print "Updating server.xml"
  88. fileSep = getFileSep(node)
  89. lineSep = java.lang.System.getProperty('line.separator')
  90. iscliteHelpDir = getISCDir(cell, node) + fileSep + "isclite.war" + fileSep + "help"
  91. prop = [['name', 'KC_HOME'], ['value', iscliteHelpDir], ['required', 'false']]
  92. serverXml = AdminConfig.getid("/Cell:" + cell + "/Node:" + node + "/Server:" + server + "/")
  93. serverPds = AdminConfig.list("JavaProcessDef", serverXml)
  94. serverPdList = serverPds.split(lineSep)
  95. for serverPd in serverPdList:
  96. jvmEntries = AdminConfig.list("JavaVirtualMachine", serverPd)
  97. jvmEntryList = jvmEntries.split(lineSep)
  98. for jvmEntry in jvmEntryList:
  99. AdminConfig.create("Property", jvmEntry, prop)
  100. return 1
  101. except:
  102. print "Error during updateServerXml(" + cell + ", " + node + ", " + server + "):", sys.exc_info()
  103. return 0
  104. #------------------------------------------------------------------------------
  105. # setupKCClassloader
  106. # Set the classloader for kc.war to PARENT_LAST
  107. #------------------------------------------------------------------------------
  108. def setupKCClassloader():
  109. print "Setting kc.war classloader to PARENT_LAST"
  110. isclite = AdminConfig.getid("/Deployment:isclite/")
  111. iscliteDepObject = AdminConfig.showAttribute(isclite, "deployedObject")
  112. modules = AdminConfig.list("WebModuleDeployment", iscliteDepObject).splitlines()
  113. for module in modules:
  114. if AdminConfig.showAttribute(module, "uri") == "kc.war":
  115. AdminConfig.modify(module, [['classloaderMode', 'PARENT_LAST']])
  116. return 1
  117. #return 0 for failure
  118. return 0
  119. #------------------------------------------------------------------------------
  120. # setCellVar
  121. #------------------------------------------------------------------------------
  122. def setCellVar(cell):
  123. try:
  124. varMap = AdminConfig.getid("/Cell:" + cell + "/VariableMap:/")
  125. prop = [[['symbolicName', 'WAS_CELL_NAME'], ['value', cell]]]
  126. AdminConfig.modify(varMap, [['entries', prop]])
  127. return 1
  128. except:
  129. print "Error during setCellVar(" + cell + "):", sys.exc_info()
  130. return 0
  131. #------------------------------------------------------------------------------
  132. # deployAdminConsole
  133. # Deploy the isclite.ear using the AdminApp install command, and then map it
  134. # to the admin_host virtual host.
  135. #------------------------------------------------------------------------------
  136. def deployAdminConsole(cell, node, server, type):
  137. iscDir = getISCDir(cell, node)
  138. sysAppDir = getSystemAppsDir(cell, node)
  139. try:
  140. print "Deploying isclite.ear"
  141. AdminApp.install(iscDir, ['-node', node, '-server', server, '-appname', 'isclite', '-usedefaultbindings', '-copy.sessionmgr.servername', server, '-zeroEarCopy', '-skipPreparation', '-installed.ear.destination', '$(WAS_INSTALL_ROOT)/systemApps'])
  142. #Do virtual host mapping
  143. print "Mapping isclite to admin_host"
  144. AdminApp.edit('isclite', ['-MapWebModToVH', [['.*', '.*', 'admin_host']]])
  145. except:
  146. error = str(sys.exc_info()[1])
  147. if error.count("7279E") > 0: # catch WASX7279E (app with given name already exists)
  148. print "Admin console is already installed."
  149. else:
  150. print "Exception occurred during deployAdminConsole(" + cell +", " + node + ", " + server + "):", error
  151. return 0
  152. return 1
  153. #------------------------------------------------------------------------------
  154. # Get a tuple containing the cell, node, server name, and type
  155. #------------------------------------------------------------------------------
  156. def getCellNodeServer():
  157. servers = AdminConfig.list("Server").splitlines()
  158. for serverId in servers:
  159. serverName = serverId.split("(")[0]
  160. server = serverId.split("(")[1] #remove name( from id
  161. server = server.split("/")
  162. cell = server[1]
  163. node = server[3]
  164. cellId = AdminConfig.getid("/Cell:" + cell + "/")
  165. cellType = AdminConfig.showAttribute(cellId, "cellType")
  166. if cellType == "DISTRIBUTED":
  167. if AdminConfig.showAttribute(serverId, "serverType") == "DEPLOYMENT_MANAGER":
  168. return (cell, node, serverName, "DEPLOYMENT_MANAGER")
  169. elif cellType == "STANDALONE":
  170. if AdminConfig.showAttribute(serverId, "serverType") == "APPLICATION_SERVER":
  171. return (cell, node, serverName, "APPLICATION_SERVER")
  172. elif AdminConfig.showAttribute(serverId, "serverType") == "ADMIN_AGENT":
  173. return (cell, node, serverName, "ADMIN_AGENT")
  174. return None
  175. #------------------------------------------------------------------------------
  176. # Print script usage
  177. #------------------------------------------------------------------------------
  178. def printUsage():
  179. print "Usage: wsadmin deployConsole.py install"
  180. print " or: wsadmin deployConsole.py remove"
  181. print ""
  182. #------------------------------------------------------------------------------
  183. # Install the admin console
  184. #------------------------------------------------------------------------------
  185. def doInstall():
  186. topology = getCellNodeServer()
  187. if topology == None:
  188. sys.stderr.write("Could not find suitable server\n")
  189. if failOnError == "true":
  190. sys.exit(105)
  191. else:
  192. cell = topology[0]
  193. node = topology[1]
  194. server = topology[2]
  195. type = topology[3]
  196. retVal = deployAdminConsole(cell, node, server, type)
  197. if retVal == 1:
  198. retVal = updateDeploymentXml()
  199. if retVal == 1:
  200. retVal = updateServerXml(cell, node, server)
  201. #if retVal == 1:
  202. # retVal = setCellVar(cell)
  203. if retVal == 1:
  204. retVal = setupKCClassloader()
  205. if retVal == 1:
  206. AdminConfig.save()
  207. else:
  208. print "Skipping Config Save"
  209. if failOnError == "true":
  210. sys.exit(109)
  211. #------------------------------------------------------------------------------
  212. # Uninstall the admin console
  213. #------------------------------------------------------------------------------
  214. def doRemove():
  215. AdminApp.uninstall("isclite")
  216. AdminConfig.save()
  217. #------------------------------------------------------------------------------
  218. # Main entry point
  219. #------------------------------------------------------------------------------
  220. failOnError = "false"
  221. if len(sys.argv) < 1 or len(sys.argv) > 2:
  222. sys.stderr.write("Invalid number of arguments\n")
  223. printUsage()
  224. sys.exit(101)
  225. else:
  226. if len(sys.argv) == 2:
  227. if sys.argv[1] == "-failonerror":
  228. failOnError = "true"
  229. print "failonerror is enabled"
  230. else:
  231. sys.stderr.write("Invalid option: " + sys.argv[1] + "\n")
  232. printUsage()
  233. sys.exit(102)
  234. mode = sys.argv[0]
  235. if mode == "install":
  236. print "Installing Admin Console..."
  237. doInstall()
  238. elif mode == "remove":
  239. print "Removing Admin Console..."
  240. doRemove()
  241. else:
  242. sys.stderr.write("Invalid command: " + mode + "\n")
  243. printUsage()
  244. if failOnError == "true":
  245. sys.exit(103)