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 confirm(action, distDir, wasRoot): log(VERBOSE_, "confirm: " + action + " " + distDir) log(VERBOSE_, "confirm: " + wasRoot + " ...") ############### FIND APPLICATIONS #################### applicationModels = getApplications(distDir, "*.xml.done") applicationModels.extend(getApplications(distDir, "*.xml.confirmed")) for applicationModel in applicationModels: log(INFO_, "confirm: Deployment applicationModel=" + `applicationModel.name`) ################## PRE-VALIDATE APPLICATIONS (exists) #################### PreValidateApplicationsExist(applicationModels) ############### CALCULATE AFFECTED NODES #################### calculateAffectedNodes(action, wasRoot, applicationModels) ################## PRE-VALIDATE NODES and SERVERS #################### PreValidateNodesAndServers(Globals.uniqueNodesContainedServers) ################## TEST #################### testApplication(applicationModels) nodeSyncStatus = {} for nodeContainedServers in Globals.uniqueNodesContainedServers: node = nodeContainedServers[0] if not node in nodeSyncStatus.keys(): nodeSync = WebSphere.AdminControl.completeObjectName("type=NodeSync,node=%s,*" % node) nodeSyncStatus[node] = WebSphere.AdminControl.invoke(nodeSync, "isNodeSynchronized") print "NODE SYNC STATUS: %s" % nodeSyncStatus highlight(MAJOR_, "confirm: 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 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 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 confirm(action, distDir, wasRoot): log(VERBOSE_, "confirm: " + action + " " + distDir) log(VERBOSE_, "confirm: " + wasRoot + " ...") ############### FIND APPLICATIONS #################### applicationModels = getApplications(distDir, "*.xml.done") applicationModels.extend(getApplications(distDir, "*.xml.confirmed")) for applicationModel in applicationModels: log( INFO_, "confirm: Deployment applicationModel=" + ` applicationModel.name `) ################## PRE-VALIDATE APPLICATIONS (exists) #################### PreValidateApplicationsExist(applicationModels) ############### CALCULATE AFFECTED NODES #################### calculateAffectedNodes(action, wasRoot, applicationModels) ################## PRE-VALIDATE NODES and SERVERS #################### PreValidateNodesAndServers(Globals.uniqueNodesContainedServers) ################## TEST #################### testApplication(applicationModels) nodeSyncStatus = {} for nodeContainedServers in Globals.uniqueNodesContainedServers: node = nodeContainedServers[0] if not node in nodeSyncStatus.keys(): nodeSync = WebSphere.AdminControl.completeObjectName( "type=NodeSync,node=%s,*" % node) nodeSyncStatus[node] = WebSphere.AdminControl.invoke( nodeSync, "isNodeSynchronized") print "NODE SYNC STATUS: %s" % nodeSyncStatus highlight(MAJOR_, "confirm: DONE.")
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 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 installOrUpdate(action, distDir, wasRoot): log(VERBOSE_, "installOrUpdate: " + action + " " + distDir) log(VERBOSE_, "installOrUpdate: " + wasRoot + " ...") applicationModels = getApplications(distDir) ################## PRE-VALIDATE Application TARGETS+SETTINGS files #################### if action == "install": PreValidateApplicationsAbsent(applicationModels) else: PreValidateApplicationsExist(applicationModels) #endElse ############### CALCULATE AFFECTED NODES #################### calculateAffectedNodes(action, wasRoot, applicationModels) ################## PRE-VALIDATE NODES and SERVERS #################### PreValidateNodesAndServers(Globals.uniqueNodesContainedServers) ############### PREPARE AFFECTED NODES #################### #if ((action == "update")): # Globals.nodesAutosyncs = saveAndDisableAutosync(action, Globals.uniqueNodesContainedServers) # log(INFO_, "installOrUpdate: RESULT: nodesAutosyncs="+`Globals.nodesAutosyncs`) #endIf ############### INSTALL APPLICATION AND CONFIGURE #################### applicationModels = installAndConfigureApps(action, distDir, wasRoot, applicationModels) calculateAffectedNodes(action, wasRoot, applicationModels) for item in Globals.appsNodesServers: for nodeServer in item[1]: nodeName = nodeServer.nodeName serverName = nodeServer.serverName if len(nodeServer.jvmAttributes) > 0: jvmAttributes = [] for jvmAttribute in nodeServer.jvmAttributes: log(INFO_, "jvmAttribute " + nodeName + ":" + serverName + "(" + jvmAttribute.name + ")=" + jvmAttribute.value) jvmAttributes.append([jvmAttribute.name, jvmAttribute.value]) jvmID = getJvmID(nodeName, serverName) modifyJvmAttrs(jvmID, jvmAttributes) configSave() ################## SYNC NODES (DISTRIBUTE APPS) #################### log(MAJOR_, "installOrUpdate: syncRippleStart of affected nodes ...") syncRippleStart(action, applicationModels) log(MAJOR_, "installOrUpdate: syncRippleStart of affected nodes DONE.") ################## START INSTALLED APPLICATIONS #################### if action == "install": for item in Globals.appsNodesServers: applicationModel = item[0] StartApplicationOnNodesAndServers(applicationModel, item[1]) #endFor #endIf ############### RESTORE AFFECTED NODES #################### #if ((action == "update")): # log(DEBUG_, "installOrUpdate: nodesAutosyncs="+`Globals.nodesAutosyncs`) # restoreAutosync(action, Globals.nodesAutosyncs) #endIf configSave() ################## TEST: Skipped for now, only on confirm ## testApplication(applicationModels) highlight(MAJOR_, "installOrUpdate: DONE.")
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.")
version = "4.0 $Revision: 480 $" LogConfig.syslogTag = "deploy:WebSphere" import sys print "@@ sys.path=" + ` sys.path ` print "@@ sys.prefix=" + ` sys.prefix ` #print "registry_all="+`sys.registry` debugHighlight(INFO_, "sys.argv[0]=" + ` sys.argv[0] `) print "" print "" SCRIPTNAME = "automatedDeploy.py - Version " + version highlight(MAJOR_, "running " + SCRIPTNAME) print "" wasRoot = Globals.wasRoot log(INFO_, "envar was.install.root=" + wasRoot) action = "" failOnError = "" distDir = "" base = 0 if len(sys.argv) > 0: param1 = sys.argv[0] param1 = param1[len(param1) - 3:].lower() if param1 == ".py" or param1 == ".jy": base = 1
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)
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) #endFor listApplications() highlight(MAJOR_, "installAndConfigureApps DONE. (ready to distribute to nodes/servers)") return result #endDef
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.")
################ 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) #endFor listApplications() highlight( MAJOR_, "installAndConfigureApps DONE. (ready to distribute to nodes/servers)") return result #endDef
def installOrUpdate(action, distDir, wasRoot): log(VERBOSE_, "installOrUpdate: " + action + " " + distDir) log(VERBOSE_, "installOrUpdate: " + wasRoot + " ...") applicationModels = getApplications(distDir) ################## PRE-VALIDATE Application TARGETS+SETTINGS files #################### if action == "install": PreValidateApplicationsAbsent(applicationModels) else: PreValidateApplicationsExist(applicationModels) #endElse ############### CALCULATE AFFECTED NODES #################### calculateAffectedNodes(action, wasRoot, applicationModels) ################## PRE-VALIDATE NODES and SERVERS #################### PreValidateNodesAndServers(Globals.uniqueNodesContainedServers) ############### PREPARE AFFECTED NODES #################### #if ((action == "update")): # Globals.nodesAutosyncs = saveAndDisableAutosync(action, Globals.uniqueNodesContainedServers) # log(INFO_, "installOrUpdate: RESULT: nodesAutosyncs="+`Globals.nodesAutosyncs`) #endIf ############### INSTALL APPLICATION AND CONFIGURE #################### applicationModels = installAndConfigureApps(action, distDir, wasRoot, applicationModels) calculateAffectedNodes(action, wasRoot, applicationModels) for item in Globals.appsNodesServers: for nodeServer in item[1]: nodeName = nodeServer.nodeName serverName = nodeServer.serverName if len(nodeServer.jvmAttributes) > 0: jvmAttributes = [] for jvmAttribute in nodeServer.jvmAttributes: log( INFO_, "jvmAttribute " + nodeName + ":" + serverName + "(" + jvmAttribute.name + ")=" + jvmAttribute.value) jvmAttributes.append( [jvmAttribute.name, jvmAttribute.value]) jvmID = getJvmID(nodeName, serverName) modifyJvmAttrs(jvmID, jvmAttributes) configSave() ################## SYNC NODES (DISTRIBUTE APPS) #################### log(MAJOR_, "installOrUpdate: syncRippleStart of affected nodes ...") syncRippleStart(action, applicationModels) log(MAJOR_, "installOrUpdate: syncRippleStart of affected nodes DONE.") ################## START INSTALLED APPLICATIONS #################### if action == "install": for item in Globals.appsNodesServers: applicationModel = item[0] StartApplicationOnNodesAndServers(applicationModel, item[1]) #endFor #endIf ############### RESTORE AFFECTED NODES #################### #if ((action == "update")): # log(DEBUG_, "installOrUpdate: nodesAutosyncs="+`Globals.nodesAutosyncs`) # restoreAutosync(action, Globals.nodesAutosyncs) #endIf configSave() ################## TEST: Skipped for now, only on confirm ## testApplication(applicationModels) highlight(MAJOR_, "installOrUpdate: 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)
version = "4.0 $Revision: 480 $" LogConfig.syslogTag = "deploy:WebSphere" import sys print "@@ sys.path=" + `sys.path` print "@@ sys.prefix=" + `sys.prefix` #print "registry_all="+`sys.registry` debugHighlight(INFO_, "sys.argv[0]=" + `sys.argv[0]`) print "" print "" SCRIPTNAME = "automatedDeploy.py - Version " + version highlight(MAJOR_, "running " + SCRIPTNAME) print "" wasRoot = Globals.wasRoot log(INFO_, "envar was.install.root=" + wasRoot) action = "" failOnError = "" distDir = "" base = 0 if len(sys.argv) > 0: param1 = sys.argv[0] param1 = param1[len(param1) - 3:].lower() if param1 == ".py" or param1 == ".jy": base = 1