def __activateManifest(self): """ activate a manifest """ LOG.info("Activate Manifest %s - %s" % (self.__service, self.__manifest)) # make sure manifest to be activated exist manifestPath = manifestutil.manifestPath(self.__service, self.__manifest) if (not os.path.exists(manifestPath)): LOG.error('Manifest %s does not exist, fail activation' % self.__manifest) raise AgentException(Errors.MANIFEST_NOT_FOUND, 'Manifest %s does not exist' % self.__manifest) # check to see if the manifest already active activeManifest = manifestutil.activeManifestPath(self.__service) if activeManifest == self.__manifest: LOG.info('Manifest %s already active, skip activation' % self.__manifest) return # activating new agent is going to kill agent process, update progress to 100% and flush all progress now self._updateProgress(100) status = self.status2msg() msg = json.dumps(status) UUIDLOG.info('%s output start %s %s output end' % (self.getUuid(), msg, self.getUuid())) from agent.lib.agent_thread.activate_manifest import ActivateManifest activateThread = ActivateManifest(self._threadMgr, self.__service, self.__manifest, parentId = self.getUuid()) contextutils.copycontexts(self, activateThread, contextutils.CTX_NAMES) activateThread.run() self._addChildExeThreadId(activateThread.getChildExeThreadIds()) status = activateThread.getStatus() if (status.has_key('error') and status['error']): raise AgentException(status['error'], status['errorMsg'])
def doRun(self): """ Main body of the thread """ self._updateProgress(1) errorMsg = "" errorCode = None failed = False try: # create manifest if not already exist mpath = manifestutil.manifestPath(self._service, self._manifest) if (not os.path.exists(mpath) or not os.path.isdir(mpath)): self._LOG.debug('pkgs = %s', self.__packages) # parse the package list for idx, package in enumerate(self.__packages): if package.startswith('/'): packageRef = package tokens = package.split('/') pkgnamePrefix = tokens[-1].rstrip() fullPkgLoc = manifestutil.getPackageFullLocByName(self._service, manifest = None, pkgnamePrefix = pkgnamePrefix) if fullPkgLoc is None: raise AgentException(Errors.MANIFEST_PACKAGE_DOES_NOT_EXIST, 'manifest (%s/%s) package (%s) does not exist' % (self._service, self._manifest, self.__packages)) else: self._LOG.info('expanding package reuse ref %s with full package location %s' % (packageRef, fullPkgLoc)) self.__packages[idx] = fullPkgLoc # start a thread to create the package manThread = ManifestCreate(self._threadMgr, self._service, self._manifest, self.__packages, parentId = self.getUuid()) contextutils.copyJobContexts(self, manThread) manThread.run() self._addChildExeThreadId(manThread.getChildExeThreadIds()) status = manThread.getStatus() if (status['error'] != None): raise AgentException(status['error'], status['errorMsg']) self._updateProgress(60) if (not os.path.exists(mpath)): raise AgentException(Errors.ACTIVEMANIFEST_MANIFEST_MISSING, 'Manifest(%s, %s) path missing' % (self._service, self._manifest)) # activate manifest if not already activated activateThread = ActivateManifest(self._threadMgr, self._service, self._manifest, parentId = self.getUuid()) contextutils.copyJobContexts(self, activateThread) activateThread.run() self._addChildExeThreadId(activateThread.getChildExeThreadIds()) status = activateThread.getStatus() if (status['error'] != None): raise AgentException(status['error'], status['errorMsg']) if manifestutil.getActiveManifest(self._service) != self._manifest: raise AgentException(Errors.ACTIVEMANIFEST_MANIFEST_MISSING, 'Manifest(%s, %s) path missing' % (self._service, self._manifest)) except SystemExit as exc: failed = True if (len(exc.args) == 2): # ok we got {err code, err msg} errorCode = exc.args[0] errorMsg = exc.args[1] except AgentException as exc: failed = True errorMsg = 'Deploy Service - Agent Exception - %s' % exc.getMsg() errorCode = exc.getCode() except Exception as exc: failed = True errorMsg = 'Deploy Service - Unknown error - (%s/%s) - %s - %s' \ % (self._service, self._manifest, str(exc), traceback.format_exc(5)) errorCode = Errors.UNKNOWN_ERROR finally: if failed: self._LOG.warning(errorMsg) self._updateStatus(httpStatus = 500, error = errorCode, errorMsg = errorMsg) else: self._updateProgress(100)