def saveAndDisableAutosync( action, nodesContainedServers ): if action == "update": pass else: fail("saveAndDisableAutosync: should never be called for action=" + action + " (only for 'install')") #endElse log(INFO_, "") log(MAJOR_, "saveAndDisableAutosync of affectedNodes begin ...") savedNodesAutosyncs = [] for nodeContainedServer in nodesContainedServers: nodeName = nodeContainedServer[0] nodeAgent = WebSphere.AdminConfig.getid("/Node:" + nodeName + "/Server:nodeagent/") syncServ = WebSphere.AdminConfig.list("ConfigSynchronizationService", nodeAgent) syncEnabled = WebSphere.AdminConfig.showAttribute(syncServ, "autoSynchEnabled") synchOnServerStartup = WebSphere.AdminConfig.showAttribute(syncServ, "synchOnServerStartup") log(INFO_, "nodeContainedServers: nodeName=" + nodeName + " syncEnabled=" + syncEnabled + " synchOnServerStartup=" + synchOnServerStartup) if syncEnabled: log(MAJOR_, "saveAndDisableAutosync: temporarily setting AutoSyncEnabled FALSE for node=" + nodeName) WebSphere.AdminConfig.modify(syncServ, [["autoSynchEnabled", "false"]]) #endIf if synchOnServerStartup: log(MAJOR_, "saveAndDisableAutosync: temporarily setting SynchOnServerStartup FALSE for node=" + nodeName) WebSphere.AdminConfig.modify(syncServ, [["synchOnServerStartup", "false"]]) #endIf savedNodeAutosync = [nodeName, syncEnabled, synchOnServerStartup] log(DEBUG_, "saveAndDisableAutosync: nodeName=" + nodeName + " savedNodeAutosync=" + `savedNodeAutosync`) savedNodesAutosyncs.append(savedNodeAutosync) #endFor configSave() log(DEBUG_, "saveAndDisableAutosync: returning node savedNodesAutosyncs=" + `savedNodesAutosyncs`) highlight(MAJOR_, "saveAndDisableAutosync of affectedNodes DONE.") return savedNodesAutosyncs
def validateEAR(appPath): if not os.path.isfile(appPath): fail("File does not exist: %s" % appPath) return 0 else: return 1 log(VERBOSE_, "validateEAR: FUTURE: installed EAR-FILE validation")
def printInformation(): wsadminSvr = WebSphere.AdminControl.queryNames("node=" + WebSphere.AdminControl.getNode() + ",type=Server,*") v = wsadminSvr.find(",version=") serverVers = wsadminSvr[v + 9:] v = serverVers.find(",") serverVers = serverVers[0:v] wsadminSvrId = WebSphere.AdminControl.getConfigId(wsadminSvr) wsadminType = WebSphere.AdminConfig.showAttribute(wsadminSvrId, "serverType") wsadminVers = WebSphere.AdminControl.getAttribute(wsadminSvr, "platformVersion") wsadminConn = WebSphere.AdminControl.getType() wsadminServer = WebSphere.AdminControl.getAttribute(wsadminSvr, "name") wsadminNode = WebSphere.AdminControl.getNode() wsadminHost = WebSphere.AdminControl.getHost() wsadminPort = WebSphere.AdminControl.getPort() if wsadminType != "DEPLOYMENT_MANAGER": fail(" currently only tested for AppServers connected to NetworkDeployment DeploymentManager") #endIf if wsadminConn != "SOAP": fail(" currently only tested for AppServers connected using type=SOAP") #endIf log(MAJOR_, ": WSADMIN: AdminType=" + wsadminType) log(MAJOR_, ": WSADMIN: AdminVers=" + wsadminVers) log(MAJOR_, ": WSADMIN: ServrVers=" + serverVers) log(MAJOR_, ": WSADMIN: AdminCell=" + Globals.wsadminCell) log(MAJOR_, ": WSADMIN: AdminNode=" + wsadminNode) log(MAJOR_, ": WSADMIN: AdminConn=" + wsadminConn) log(MAJOR_, ": WSADMIN: AdminHost=" + wsadminHost) log(MAJOR_, ": WSADMIN: AdminSevr=" + wsadminServer) log(MAJOR_, ": WSADMIN: AdminPort=" + wsadminPort) log(VERBOSE_, "JYTHON vers=" + sys.version[0:3]) log(INFO_, "")
def PreValidateApplicationsExist( applicationModels ): for applicationModel in applicationModels: appExists = checkIfAppExists(applicationModel) if appExists: log(INFO_, "PreValidateApplicationsExist OK applicationModel=" + `applicationModel`) else: fail("PreValidateApplicationsPresent: MISSING application=" + applicationModel.name)
def PreValidateApplicationsAbsent( applicationModels ): for applicationModel in applicationModels: appExists = checkIfAppExists(applicationModel) if appExists: fail("PreValidateApplicationsAbsent: EXISTING application=" + applicationModel.name) else: log(INFO_, "PreValidateApplicationsAbsent: OK applicationModel=" + `applicationModel`)
def validateEAR( appPath ): if not os.path.isfile(appPath): fail("File does not exist: %s" % appPath) return 0 else: return 1 log(VERBOSE_, "validateEAR: FUTURE: installed EAR-FILE validation")
def checkServerStopped(nodeName, serverName): log( DEBUG_, "checkServerStopped: nodeName=" + nodeName + " serverName=" + serverName) desiredState = "STOPPED" serverID = "" try: serverID = WebSphere.AdminControl.completeObjectName("node=" + nodeName + ",name=" + serverName + ",type=Server,*") except: _type_, _value_, _tbck_ = sys.exc_info() log( WARNING_, "checkServerStopped: exception=" + ` _type_ ` + " trying to access " + nodeName + " " + serverName) #endIf if not len(serverID): log( VERBOSE_, "checkServerStopped: cannot access node=" + nodeName + " server=" + serverName + " (STOPPED?)") actualState = desiredState else: actualState = WebSphere.AdminControl.getAttribute(serverID, "state") #endElse actualState = actualState.upper() log( VERBOSE_, "checkServerStopped: " + nodeName + " " + serverName + " actualState=" + actualState + " desiredState=" + desiredState) if actualState != desiredState: msg = "ERROR: checkServerStopped: " + nodeName + " " + serverName + " actualState=" + actualState + " instead of desiredState=" + desiredState fail(msg)
def restoreAutosync( action, savedNodesAutosyncs ): if action == "update": pass else: fail("saveAndDisableAutosync: should never be called for action=" + action + " (only for 'update')") #endElse log(MAJOR_, "restoreAutosync of affectedNodes begin ...") log(DEBUG_, "restoreAutosync: savedNodesAutosyncs=" + `savedNodesAutosyncs`) for savedNodeAutosync in savedNodesAutosyncs: log(VERBOSE_, "restoreAutosync: savedNodeAutosync=" + `savedNodeAutosync`) nodeName = savedNodeAutosync[0] nodeAgent = WebSphere.AdminConfig.getid("/Node:" + nodeName + "/Server:nodeagent/") syncServ = WebSphere.AdminConfig.list("ConfigSynchronizationService", nodeAgent) syncEnabled = savedNodeAutosync[1] synchOnServerStartup = savedNodeAutosync[2] log(INFO_, "restoreAutosync: nodeName=" + nodeName + " syncEnabled=" + syncEnabled + " synchOnServerStartup=" + synchOnServerStartup) if syncEnabled: log(MAJOR_, "saveAndDisableAutosync: restoring AutoSyncEnabled TRUE for node=" + nodeName) WebSphere.AdminConfig.modify(syncServ, [["autoSynchEnabled", "true"]]) else: log(WARNING_, "saveAndDisableAutosync: restoring AutoSyncEnabled FALSE for node=" + nodeName) #endElse if synchOnServerStartup: log(MAJOR_, "saveAndDisableAutosync: restoring SynchOnServerStartup TRUE for node=" + nodeName) WebSphere.AdminConfig.modify(syncServ, [["synchOnServerStartup", "true"]]) else: log(WARNING_, "saveAndDisableAutosync: restoring SynchOnServerStartup FALSE for node=" + nodeName) #endElse #endFor configSave() highlight(MAJOR_, "restoreAutosync of affectedNodes DONE.")
def uninstallEAR( applicationModel ): log(MAJOR_, "UninstallEAR: " + applicationModel.name + "...") uninstalled = WebSphere.AdminApp.uninstall(applicationModel.name) log(INFO_, uninstalled) appExists = checkIfAppExists(applicationModel) if appExists: fail("failed to uninstallEAR application=" + applicationModel.name) #endIf log(VERBOSE_, "UninstallEAR: DONE.")
def uninstallEAR(applicationModel): log(MAJOR_, "UninstallEAR: " + applicationModel.name + "...") uninstalled = WebSphere.AdminApp.uninstall(applicationModel.name) log(INFO_, uninstalled) appExists = checkIfAppExists(applicationModel) if appExists: fail("failed to uninstallEAR application=" + applicationModel.name) #endIf log(VERBOSE_, "UninstallEAR: DONE.")
def saveAndDisableAutosync(action, nodesContainedServers): if action == "update": pass else: fail("saveAndDisableAutosync: should never be called for action=" + action + " (only for 'install')") #endElse log(INFO_, "") log(MAJOR_, "saveAndDisableAutosync of affectedNodes begin ...") savedNodesAutosyncs = [] for nodeContainedServer in nodesContainedServers: nodeName = nodeContainedServer[0] nodeAgent = WebSphere.AdminConfig.getid("/Node:" + nodeName + "/Server:nodeagent/") syncServ = WebSphere.AdminConfig.list("ConfigSynchronizationService", nodeAgent) syncEnabled = WebSphere.AdminConfig.showAttribute( syncServ, "autoSynchEnabled") synchOnServerStartup = WebSphere.AdminConfig.showAttribute( syncServ, "synchOnServerStartup") log( INFO_, "nodeContainedServers: nodeName=" + nodeName + " syncEnabled=" + syncEnabled + " synchOnServerStartup=" + synchOnServerStartup) if syncEnabled: log( MAJOR_, "saveAndDisableAutosync: temporarily setting AutoSyncEnabled FALSE for node=" + nodeName) WebSphere.AdminConfig.modify(syncServ, [["autoSynchEnabled", "false"]]) #endIf if synchOnServerStartup: log( MAJOR_, "saveAndDisableAutosync: temporarily setting SynchOnServerStartup FALSE for node=" + nodeName) WebSphere.AdminConfig.modify(syncServ, [["synchOnServerStartup", "false"]]) #endIf savedNodeAutosync = [nodeName, syncEnabled, synchOnServerStartup] log( DEBUG_, "saveAndDisableAutosync: nodeName=" + nodeName + " savedNodeAutosync=" + ` savedNodeAutosync `) savedNodesAutosyncs.append(savedNodeAutosync) #endFor configSave() log( DEBUG_, "saveAndDisableAutosync: returning node savedNodesAutosyncs=" + ` savedNodesAutosyncs `) highlight(MAJOR_, "saveAndDisableAutosync of affectedNodes DONE.") return savedNodesAutosyncs
def restoreAutosync(action, savedNodesAutosyncs): if action == "update": pass else: fail("saveAndDisableAutosync: should never be called for action=" + action + " (only for 'update')") #endElse log(MAJOR_, "restoreAutosync of affectedNodes begin ...") log(DEBUG_, "restoreAutosync: savedNodesAutosyncs=" + ` savedNodesAutosyncs `) for savedNodeAutosync in savedNodesAutosyncs: log(VERBOSE_, "restoreAutosync: savedNodeAutosync=" + ` savedNodeAutosync `) nodeName = savedNodeAutosync[0] nodeAgent = WebSphere.AdminConfig.getid("/Node:" + nodeName + "/Server:nodeagent/") syncServ = WebSphere.AdminConfig.list("ConfigSynchronizationService", nodeAgent) syncEnabled = savedNodeAutosync[1] synchOnServerStartup = savedNodeAutosync[2] log( INFO_, "restoreAutosync: nodeName=" + nodeName + " syncEnabled=" + syncEnabled + " synchOnServerStartup=" + synchOnServerStartup) if syncEnabled: log( MAJOR_, "saveAndDisableAutosync: restoring AutoSyncEnabled TRUE for node=" + nodeName) WebSphere.AdminConfig.modify(syncServ, [["autoSynchEnabled", "true"]]) else: log( WARNING_, "saveAndDisableAutosync: restoring AutoSyncEnabled FALSE for node=" + nodeName) #endElse if synchOnServerStartup: log( MAJOR_, "saveAndDisableAutosync: restoring SynchOnServerStartup TRUE for node=" + nodeName) WebSphere.AdminConfig.modify(syncServ, [["synchOnServerStartup", "true"]]) else: log( WARNING_, "saveAndDisableAutosync: restoring SynchOnServerStartup FALSE for node=" + nodeName) #endElse #endFor configSave() highlight(MAJOR_, "restoreAutosync of affectedNodes DONE.")
def StopApplicationOnNodesAndServers( applicationModel, uniqueNodeServerPairs ): log(MAJOR_, "StopApplicationOnNodesAndServers: applicationModel=" + applicationModel.name + " nodeServerPairs=" + `uniqueNodeServerPairs` + "...") if not len(uniqueNodeServerPairs): fail("StopApplicationOnNodesAndServers : No nodes/servers/clusters specified") #endIf for nodeServer in uniqueNodeServerPairs: nodeName = nodeServer.nodeName serverName = nodeServer.serverName StopApplication(applicationModel, nodeName, serverName) #endFor highlight(MAJOR_, "StopApplicationOnNodesAndServers DONE.")
def syncNDNode(nodeName): EarExpandDelay = 10 log(MAJOR_, "syncNDNode: ReSync of ND Node=" + nodeName + " (actual application distribution to Server(s) ) ...") ndSync = WebSphere.AdminControl.completeObjectName("type=NodeSync,node=" + nodeName + ",*") if ndSync == "": fail("cannot syncNDNode (stopped?) nodeName=" + nodeName) #endIf sync = WebSphere.AdminControl.invoke(ndSync, "sync") log(INFO_, "syncNDNode: " + nodeName + " invoked sync=" + sync + " DONE.") log(VERBOSE_, "syncNDNode: FUTURE: check for nodeSync EAR expansion complete (for now just delay " + `EarExpandDelay` + " secs)") sleepDelay(EarExpandDelay)
def deploy(action, failOnError, distDir, wasRoot): log(VERBOSE_, "deploy: INPUTS: " + action + " " + distDir + " " + wasRoot) action = action.lower() if action == "install" or action == "update": installOrUpdate(action, distDir, wasRoot) elif action == "confirm": confirm(action, distDir, wasRoot) elif action == "syncripplestart": syncRippleStartDone(distDir, wasRoot) elif action == "uninstall": uninstall(action, distDir, wasRoot) else: msg = "ERROR: deploy: unknown action=" + action + " (must be 'install' or 'update' or 'confirm' or 'syncRippleStart' or 'uninstall'" fail(msg)
def syncNDNode(nodeName): EarExpandDelay = 10 log( MAJOR_, "syncNDNode: ReSync of ND Node=" + nodeName + " (actual application distribution to Server(s) ) ...") ndSync = WebSphere.AdminControl.completeObjectName("type=NodeSync,node=" + nodeName + ",*") if ndSync == "": fail("cannot syncNDNode (stopped?) nodeName=" + nodeName) #endIf sync = WebSphere.AdminControl.invoke(ndSync, "sync") log(INFO_, "syncNDNode: " + nodeName + " invoked sync=" + sync + " DONE.") log( VERBOSE_, "syncNDNode: FUTURE: check for nodeSync EAR expansion complete (for now just delay " + ` EarExpandDelay ` + " secs)") sleepDelay(EarExpandDelay)
def installEAR(action, appPath, applicationModel, clusterName, nodeName, serverName, installOptions): update = "-appname '%s'" % applicationModel.name if action == "update": update = "-update " + update #endIf if serverName != "" and nodeName != "": options = update + " -verbose -node " + nodeName + " -server " + serverName + " -distributeApp " + installOptions options = options + " -MapWebModToVH " + AArrayToOptionString( mapWebModToVH(applicationModel, appPath)) options = options + " -MapModulesToServers " + AArrayToOptionString( mapModulesToServers(applicationModel, appPath)) highlight(MAJOR_, "AdminApp.install(" + appPath + "," + options + ")") installed = WebSphere.AdminApp.install(appPath, options) #endIf elif clusterName != "": options = update + " -verbose -cluster " + clusterName + " -distributeApp " + installOptions options = options + " -MapWebModToVH " + AArrayToOptionString( mapWebModToVH(applicationModel, appPath)) options = options + " -MapModulesToServers " + AArrayToOptionString( mapModulesToServers(applicationModel, appPath)) highlight(MAJOR_, "AdminApp.install(" + appPath + "," + options + ")") installed = WebSphere.AdminApp.install(appPath, options) #endIf else: options = update + " -verbose -distributeApp " + installOptions options = options + " -MapWebModToVH " + AArrayToOptionString( mapWebModToVH(applicationModel, appPath)) options = options + " -MapModulesToServers " + AArrayToOptionString( mapModulesToServers(applicationModel, appPath)) highlight(MAJOR_, "AdminApp.install(" + appPath + "," + options + ")") installed = WebSphere.AdminApp.install(appPath, options) #endElse if len(installed) > 0: log(INFO_, installed) #endIf appExists = checkIfAppExists(applicationModel) if appExists: pass else: fail("failed to installEAR application=" + applicationModel.name) #endElse log(VERBOSE_, "InstallEAR: DONE.")
def getApplications(distDir, pattern="*.xml"): if not os.path.isdir(distDir): msg = "readDistributionDirectory: ERROR: is not a directory, distDir=" + distDir fail(msg) if not os.path.exists(distDir): msg = "readDistributionDirectory: ERROR: does not exist, distDir=" + distDir fail(msg) files = glob.glob(distDir + "/" + pattern) applications = {} impl = xml.dom.javadom.XercesDomImplementation() for file in files: dom = impl.buildDocumentFile(file) model = applicationModel.parseApplication(dom) model.configFile = file applications[model.name] = model extrafiles = glob.glob(distDir + "/*.extraxml") for extrafile in extrafiles: extradom = impl.buildDocumentFile(extrafile) applicationModel.addExtra(applications, extradom) return applications.values()
def installEAR( action, appPath, applicationModel, clusterName, nodeName, serverName, installOptions ): update = "-appname '%s'" % applicationModel.name if action == "update": update = "-update " + update #endIf if serverName != "" and nodeName != "": options = update + " -verbose -node " + nodeName + " -server " + serverName + " -distributeApp " + installOptions options = options + " -MapWebModToVH " + AArrayToOptionString(mapWebModToVH(applicationModel, appPath)) options = options + " -MapModulesToServers " + AArrayToOptionString( mapModulesToServers(applicationModel, appPath)) highlight(MAJOR_, "AdminApp.install(" + appPath + "," + options + ")") installed = WebSphere.AdminApp.install(appPath, options) #endIf elif clusterName != "": options = update + " -verbose -cluster " + clusterName + " -distributeApp " + installOptions options = options + " -MapWebModToVH " + AArrayToOptionString(mapWebModToVH(applicationModel, appPath)) options = options + " -MapModulesToServers " + AArrayToOptionString( mapModulesToServers(applicationModel, appPath)) highlight(MAJOR_, "AdminApp.install(" + appPath + "," + options + ")") installed = WebSphere.AdminApp.install(appPath, options) #endIf else: options = update + " -verbose -distributeApp " + installOptions options = options + " -MapWebModToVH " + AArrayToOptionString(mapWebModToVH(applicationModel, appPath)) options = options + " -MapModulesToServers " + AArrayToOptionString( mapModulesToServers(applicationModel, appPath)) highlight(MAJOR_, "AdminApp.install(" + appPath + "," + options + ")") installed = WebSphere.AdminApp.install(appPath, options) #endElse if len(installed) > 0: log(INFO_, installed) #endIf appExists = checkIfAppExists(applicationModel) if appExists: pass else: fail("failed to installEAR application=" + applicationModel.name) #endElse log(VERBOSE_, "InstallEAR: DONE.")
def checkServerStopped(nodeName, serverName): log(DEBUG_, "checkServerStopped: nodeName=" + nodeName + " serverName=" + serverName) desiredState = "STOPPED" serverID = "" try: serverID = WebSphere.AdminControl.completeObjectName( "node=" + nodeName + ",name=" + serverName + ",type=Server,*") except: _type_, _value_, _tbck_ = sys.exc_info() log(WARNING_, "checkServerStopped: exception=" + `_type_` + " trying to access " + nodeName + " " + serverName) #endIf if not len(serverID): log(VERBOSE_, "checkServerStopped: cannot access node=" + nodeName + " server=" + serverName + " (STOPPED?)") actualState = desiredState else: actualState = WebSphere.AdminControl.getAttribute(serverID, "state") #endElse actualState = actualState.upper() log(VERBOSE_, "checkServerStopped: " + nodeName + " " + serverName + " actualState=" + actualState + " desiredState=" + desiredState) if actualState != desiredState: msg = "ERROR: checkServerStopped: " + nodeName + " " + serverName + " actualState=" + actualState + " instead of desiredState=" + desiredState fail(msg)
def updateApplicationXMLs(distDir): if not os.path.isdir(distDir): msg = "readDistributionDirectory: ERROR: is not a directory, distDir=" + distDir fail(msg) if not os.path.exists(distDir): msg = "readDistributionDirectory: ERROR: does not exist, distDir=" + distDir fail(msg) files = glob.glob(distDir + "/*.xml.in") xml.dom.javadom.Node.namespaceURI = None impl = xml.dom.javadom.XercesDomImplementation() for file in files: dom = impl.buildDocumentFile(file) error = updateApplicationDom(dom) applicationModel = parseApplication(dom) file = file[0:len(file) - 3] stream = open(file, "wt") xml.dom.ext.PrettyPrint(dom, stream) stream.close() if error > 0: os.rename(file, file + ".err") print "GENERATE ERR " + file + ".err for " + applicationModel.name + " at " + applicationModel.file else: print "GENERATE OK " + file + " for " + applicationModel.name + " at " + applicationModel.file print "NODE SYNC STATUS: %s" % nodeSyncStatus
def installAndConfigureApps(action, distDir, wasRoot, applicationModels): log(INFO_, "") log( MAJOR_, "installAndConfigureApps: applicationModels=" + ` applicationModels ` + " ...") listApplications() result = [] ################ INSTALL (or UPDATE) AND CONFIGURE ############## for applicationModel in applicationModels: try: if applicationModel.file.startswith("/"): appPath = applicationModel.file else: appPath = distDir + "/" + applicationModel.file if not validateEAR(appPath): continue ################ READ APP INSTALL OPTIONS (from .settings) ############## installOptions = "" for installOption in applicationModel.installOptions: installOptions = installOptions + " " + installOption ################ INSTALL ############## nodeName = "" serverName = "" if len(applicationModel.servers) > 0: appNodeServerPair = applicationModel.servers[0] nodeName = appNodeServerPair.nodeName serverName = appNodeServerPair.serverName #endIf clusterName = "" if len(applicationModel.clusters) > 0: clusterName = applicationModel.clusters[0].clusterName #endIf if action == "install": appExists = checkIfAppExists(applicationModel) if appExists: msg = "application=" + applicationModel.name + " EXISTS, CANNOT install with same name" fail(msg) highlight( ERROR_, "application=" + applicationModel.name + " EXISTS, will process SETTINGS and TARGETS") else: installEAR(action, appPath, applicationModel, clusterName, nodeName, serverName, installOptions) #endElse elif action == "update": appExists = checkIfAppExists(applicationModel) if appExists: installEAR(action, appPath, applicationModel, clusterName, nodeName, serverName, installOptions) else: msg = "application=" + applicationModel.name + " DOES NOT EXIST, will INSTALL instead of UPDATE" log(WARNING_, msg) installEAR("install", appPath, applicationModel, clusterName, nodeName, serverName, installOptions) #endElse #endIf ################ CONFIG SETTINGS ############## applySettings(applicationModel) ################ VALIDATE INSTALLED APPLICATION ############## validateApplication(applicationModel) except AdminException, e: log(WARNING_, "AdminException=" + e.message) WebSphere.AdminConfig.reset() else: configSave() syslog( "info", "successful %s:%s:%s:%s" % (action, applicationModel.serviceCall, applicationModel.name, applicationModel.version)) execScript(applicationModel, "afterInstall") os.rename(applicationModel.configFile, applicationModel.configFile + '.done') applicationModel.configFile = applicationModel.configFile + '.done' result.append(applicationModel)
def calculateAffectedNodes(action, wasRoot, applicationModels): Globals.appsNodesServers = [] Globals.nodeServerPairs = [] Globals.uniqueNodesContainedServers = [] Globals.nodesAutosyncs = [] Globals.unclusteredNodeServerPairs = [] Globals.clusters = {} Globals.inactiveServers = [] ############### FIND NODES/SERVERS #################### if not len(applicationModels): fail("calculateAffectedNodes: No applicationModels in distDir ") #endIf for applicationModel in applicationModels: ################ READ TARGETS ############## tmpNodeServerPairs = [] applicationClusters = [] applicationClusters.extend(applicationModel.clusters) applicationServers = [] applicationServers.extend(applicationModel.servers) for module in applicationModel.modules: for target in module.targets: if target.targetType() == ApplicationTarget.CLUSTER: applicationClusters.append(target) elif target.targetType() == ApplicationTarget.SERVER: applicationServers.append(target) if action == "update": for target in applicationModel.targets: addExistingTargets(applicationModel.name, target, applicationClusters, applicationServers) ################## PRE-VALIDATE CLUSTERS #################### for cluster in applicationClusters: for server in cluster.inactiveServers: inactiveServerPair = [server.nodeName, server.serverName] if inactiveServerPair not in Globals.inactiveServers: Globals.inactiveServers.append(inactiveServerPair) PreValidateCluster(cluster) #endFor ################## APPEND TOTAL NODES/SERVERS/TESTS ############ for server in applicationServers: if getServerType(server.nodeName, server.serverName) == "APPLICATION_SERVER": Globals.nodeServerPairs.append(server) if not [server.nodeName, server.serverName] in Globals.unclusteredNodeServerPairs: Globals.unclusteredNodeServerPairs.append([server.nodeName, server.serverName]) tmpNodeServerPairs.append(server) #endFor addUniqueClusters(applicationClusters) clusterNodeServerPairs = getNodeServerPairs(applicationClusters) log(DEBUG_, "clusterNodeServerPairs=" + `clusterNodeServerPairs`) for clusterNodeServerPair in clusterNodeServerPairs: Globals.nodeServerPairs.append(clusterNodeServerPair) tmpNodeServerPairs.append(clusterNodeServerPair) #endFor partialClusterNodeServerPairs = getPartialClusterNodeServerPairs(applicationClusters) for server in partialClusterNodeServerPairs: if not [server.nodeName, server.serverName] in Globals.unclusteredNodeServerPairs: Globals.unclusteredNodeServerPairs.append([server.nodeName, server.serverName]) Globals.appsNodesServers.append([applicationModel, tmpNodeServerPairs]) #endFor log(VERBOSE_, "calculateAffectedNodes: RESULT: appsNodesServers=" + `Globals.appsNodesServers`) log(VERBOSE_, "calculateAffectedNodes: RESULT: nodeServerPairs=" + `Globals.nodeServerPairs`) ################## UNIQUE NODES (AND THEIR UNIQUE SERVERS) ############ if not len(Globals.nodeServerPairs): fail("calculateAffectedNodes: No node/server/cluster (Targets) specified") #endIf Globals.uniqueNodesContainedServers = determineUniqueNodesContainedServers(Globals.nodeServerPairs) log(INFO_, "calculateAffectedNodes: RESULT: Globals.uniqueNodesContainedServers=" + `Globals.uniqueNodesContainedServers`) if len(Globals.inactiveServers) > 0: log(INFO_, "calculateAffectedNodes: RESULT: Globals.inactiveServers=" + `Globals.inactiveServers`) highlight(MAJOR_, "calculateAffectedNodes DONE.")
def installAndConfigureApps( action, distDir, wasRoot, applicationModels ): log(INFO_, "") log(MAJOR_, "installAndConfigureApps: applicationModels=" + `applicationModels` + " ...") listApplications() result = [] ################ INSTALL (or UPDATE) AND CONFIGURE ############## for applicationModel in applicationModels: try: if applicationModel.file.startswith("/"): appPath = applicationModel.file else: appPath = distDir + "/" + applicationModel.file if not validateEAR(appPath): continue ################ READ APP INSTALL OPTIONS (from .settings) ############## installOptions = "" for installOption in applicationModel.installOptions: installOptions = installOptions + " " + installOption ################ INSTALL ############## nodeName = "" serverName = "" if len(applicationModel.servers) > 0: appNodeServerPair = applicationModel.servers[0] nodeName = appNodeServerPair.nodeName serverName = appNodeServerPair.serverName #endIf clusterName = "" if len(applicationModel.clusters) > 0: clusterName = applicationModel.clusters[0].clusterName #endIf if action == "install": appExists = checkIfAppExists(applicationModel) if appExists: msg = "application=" + applicationModel.name + " EXISTS, CANNOT install with same name" fail(msg) highlight(ERROR_, "application=" + applicationModel.name + " EXISTS, will process SETTINGS and TARGETS") else: installEAR(action, appPath, applicationModel, clusterName, nodeName, serverName, installOptions) #endElse elif action == "update": appExists = checkIfAppExists(applicationModel) if appExists: installEAR(action, appPath, applicationModel, clusterName, nodeName, serverName, installOptions) else: msg = "application=" + applicationModel.name + " DOES NOT EXIST, will INSTALL instead of UPDATE" log(WARNING_, msg) installEAR("install", appPath, applicationModel, clusterName, nodeName, serverName, installOptions) #endElse #endIf ################ CONFIG SETTINGS ############## applySettings(applicationModel) ################ VALIDATE INSTALLED APPLICATION ############## validateApplication(applicationModel) except AdminException, e: log(WARNING_, "AdminException=" + e.message) WebSphere.AdminConfig.reset() else: configSave() syslog("info", "successful %s:%s:%s:%s" % ( action, applicationModel.serviceCall, applicationModel.name, applicationModel.version)) execScript(applicationModel, "afterInstall") os.rename(applicationModel.configFile, applicationModel.configFile + '.done') applicationModel.configFile = applicationModel.configFile + '.done' result.append(applicationModel)
def calculateAffectedNodes(action, wasRoot, applicationModels): Globals.appsNodesServers = [] Globals.nodeServerPairs = [] Globals.uniqueNodesContainedServers = [] Globals.nodesAutosyncs = [] Globals.unclusteredNodeServerPairs = [] Globals.clusters = {} Globals.inactiveServers = [] ############### FIND NODES/SERVERS #################### if not len(applicationModels): fail("calculateAffectedNodes: No applicationModels in distDir ") #endIf for applicationModel in applicationModels: ################ READ TARGETS ############## tmpNodeServerPairs = [] applicationClusters = [] applicationClusters.extend(applicationModel.clusters) applicationServers = [] applicationServers.extend(applicationModel.servers) for module in applicationModel.modules: for target in module.targets: if target.targetType() == ApplicationTarget.CLUSTER: applicationClusters.append(target) elif target.targetType() == ApplicationTarget.SERVER: applicationServers.append(target) if action == "update": for target in applicationModel.targets: addExistingTargets(applicationModel.name, target, applicationClusters, applicationServers) ################## PRE-VALIDATE CLUSTERS #################### for cluster in applicationClusters: for server in cluster.inactiveServers: inactiveServerPair = [server.nodeName, server.serverName] if inactiveServerPair not in Globals.inactiveServers: Globals.inactiveServers.append(inactiveServerPair) PreValidateCluster(cluster) #endFor ################## APPEND TOTAL NODES/SERVERS/TESTS ############ for server in applicationServers: if getServerType(server.nodeName, server.serverName) == "APPLICATION_SERVER": Globals.nodeServerPairs.append(server) if not [server.nodeName, server.serverName ] in Globals.unclusteredNodeServerPairs: Globals.unclusteredNodeServerPairs.append( [server.nodeName, server.serverName]) tmpNodeServerPairs.append(server) #endFor addUniqueClusters(applicationClusters) clusterNodeServerPairs = getNodeServerPairs(applicationClusters) log(DEBUG_, "clusterNodeServerPairs=" + ` clusterNodeServerPairs `) for clusterNodeServerPair in clusterNodeServerPairs: Globals.nodeServerPairs.append(clusterNodeServerPair) tmpNodeServerPairs.append(clusterNodeServerPair) #endFor partialClusterNodeServerPairs = getPartialClusterNodeServerPairs( applicationClusters) for server in partialClusterNodeServerPairs: if not [server.nodeName, server.serverName ] in Globals.unclusteredNodeServerPairs: Globals.unclusteredNodeServerPairs.append( [server.nodeName, server.serverName]) Globals.appsNodesServers.append([applicationModel, tmpNodeServerPairs]) #endFor log( VERBOSE_, "calculateAffectedNodes: RESULT: appsNodesServers=" + ` Globals.appsNodesServers `) log( VERBOSE_, "calculateAffectedNodes: RESULT: nodeServerPairs=" + ` Globals.nodeServerPairs `) ################## UNIQUE NODES (AND THEIR UNIQUE SERVERS) ############ if not len(Globals.nodeServerPairs): fail( "calculateAffectedNodes: No node/server/cluster (Targets) specified" ) #endIf Globals.uniqueNodesContainedServers = determineUniqueNodesContainedServers( Globals.nodeServerPairs) log( INFO_, "calculateAffectedNodes: RESULT: Globals.uniqueNodesContainedServers=" + ` Globals.uniqueNodesContainedServers `) if len(Globals.inactiveServers) > 0: log( INFO_, "calculateAffectedNodes: RESULT: Globals.inactiveServers=" + ` Globals.inactiveServers `) highlight(MAJOR_, "calculateAffectedNodes DONE.")