#------------------------------------------------------------------------------ # Swagger UI applications deployment/undeployment script # See usage below # # This is a servicable file. This file may be changed or overwritten when a # new fixpack is installed. If you need to modify this file, make a copy and # make changes to the copy only. #------------------------------------------------------------------------------ import sys #------------------------------------------------------------------------------ # Get the directory, as a string, where WAS is installed. #------------------------------------------------------------------------------ def getWASHome(cell, node): varMap = AdminConfig.getid("/Cell:" + cell + "/Node:" + node + "/VariableMap:/") entries = AdminConfig.list("VariableSubstitutionEntry", varMap) eList = entries.splitlines() for entry in eList: name = AdminConfig.showAttribute(entry, "symbolicName") if name == "WAS_INSTALL_ROOT": value = AdminConfig.showAttribute(entry, "value") return value #failover return java.lang.System.getenv('WAS_HOME') #------------------------------------------------------------------------------ # Get the WAS systemApps directory. # # The WAS systemApps directory is always located at /systemApps #------------------------------------------------------------------------------ def getSystemAppsDir(cell, node): fileSep = getFileSep(node) return getWASHome(cell, node) + fileSep + "systemApps" #------------------------------------------------------------------------------ # Get the directory, as a string, of the SwaggerUI.ear application. # # The isclite.ear is located in /systemApps/SwaggerUI.ear #------------------------------------------------------------------------------ def getSwaggerUIDir(cell, node): fileSep = getFileSep(node) return getSystemAppsDir(cell, node) + fileSep + "SwaggerUI.ear" #------------------------------------------------------------------------------ # Get the directory, as a string, of the RESTAPIDocs.ear application. # # The isclite.ear is located in /systemApps/RESTAPIDocs.ear #------------------------------------------------------------------------------ def getRESTAPIDocsDir(cell, node): fileSep = getFileSep(node) return getSystemAppsDir(cell, node) + fileSep + "RESTAPIDocs.ear" #------------------------------------------------------------------------------ # Get the file separator character # # This gets the file separator for the node in which we plan to install the # console. Therefore we can't just use the value that python on Java gives # us. Instead, check the platform of the node, and use "\" for windows and # "/" for everything else. #------------------------------------------------------------------------------ def getFileSep(node): os = AdminTask.getNodePlatformOS("-nodeName " + node) if os == 'windows': return '\\' else: return '/' #------------------------------------------------------------------------------ # Get a tuple containing the cell, node, server name, and type #------------------------------------------------------------------------------ def getCellNodeServer(): servers = AdminConfig.list("Server").splitlines() for serverId in servers: serverName = serverId.split("(")[0] server = serverId.split("(")[1] #remove name( from id server = server.split("/") cell = server[1] node = server[3] return (cell, node, serverName) return None #------------------------------------------------------------------------------ # Install SwaggerUI.ear and RESTAPIDocs.ear #------------------------------------------------------------------------------ def doInstall(targets): topology = getCellNodeServer() if topology == None: sys.stderr.write("Could not find suitable server\n") sys.exit(105) else: cell = topology[0] node = topology[1] server = topology[2] swaggerUIDir = getSwaggerUIDir(cell, node) restAPIDocsDir = getRESTAPIDocsDir(cell, node) sysAppDir = getSystemAppsDir(cell, node) try: print "Deploying SwggerUI.ear" AdminApp.install(swaggerUIDir, ['-appname', 'SwaggerUI', '-zeroEarCopy', '-installed.ear.destination', '$(WAS_INSTALL_ROOT)/systemApps', '-CtxRootForWebMod', [['.*', '.*', '/ibm/api/explorer']], '-MapModulesToServers', [[ 'SwaggerUI', 'SwaggerUI.war,WEB-INF/web.xml', targets]]]) print "Deploying RESTAPIDocs.ear" AdminApp.install(restAPIDocsDir, ['-appname', 'RESTAPIDocs', '-zeroEarCopy', '-installed.ear.destination', '$(WAS_INSTALL_ROOT)/systemApps', '-CtxRootForWebMod', [['.*', '.*', '/ibm/api/docs']], '-MapModulesToServers', [[ 'RESTAPIDocs', 'RESTAPIDocs.war,WEB-INF/web.xml', targets]]]) AdminConfig.save() except: error = str(sys.exc_info()[1]) if error.count("7279E") > 0: # catch WASX7279E (app with given name already exists) print "Swagger UI is already installed." else: print "Exception occurred during installing Swagger UI(" + targetCell +", " + targetNode + ", " + targetServer + "):", error return 0 return 1 #------------------------------------------------------------------------------ # Print script usage #------------------------------------------------------------------------------ def printUsage(): print "Usage:" print " To install SwaggerUI on a single server:" print " wsadmin deploySwaggerUI.py install 'WebSphere:cell=cellName,node=nodeName,server=serverName'" print " wsadmin deploySwaggerUI.py install 'WebSphere:cell=cellName,cluster=clusterName'" print " To remove SwaggerUI on a cluster:" print " wsadmin deploySwaggerUI.py remove" print "" print "For example:" print " wsadmin deploySwaggerUI.py install 'WebSphere:cell=myCell,node=myCellNode01,server=server1'" print " wsadmin deploySwaggerUI.py install 'WebSphere:cell=myCell04,cluster=cluster1'" print "" #------------------------------------------------------------------------------ # Uninstall the admin console #------------------------------------------------------------------------------ def doRemove(): AdminApp.uninstall("SwaggerUI") AdminApp.uninstall("RESTAPIDocs") AdminConfig.save() #------------------------------------------------------------------------------ # Main entry point #------------------------------------------------------------------------------ print "Starting..." if len(sys.argv) < 1 or len(sys.argv) > 2: sys.stderr.write("Invalid number of arguments\n") printUsage() sys.exit(101) else: mode = sys.argv[0] if mode == "install" and len(sys.argv) == 2: print "Installing Swagger UI applications..." doInstall(sys.argv[1]) elif mode == "remove" and len(sys.argv) == 1: print "Removing Swagger UI applications..." doRemove() else: sys.stderr.write("Invalid command: " + mode + "\n") printUsage() sys.exit(102)