def stop(self):
        """ trigger to stop the GC
        cannot be undone
        should only be called right before shutdown """

        LOG.info("Stopping GC")
        self.__runGC = False
        self.__rejectRequest = True
        # dump thread status to json
        killStatus = {}
        killStatus["httpStatus"] = 500
        killStatus["error"] = Errors.THREAD_KILLED_AGENT_RESTART
        killStatus["errorMsg"] = "thread killed, agent restart"

        data = self.getInfo(killLiveWithStatus=killStatus, withLock=True)
        manifestutil.writeJson("agent", ".threadmgr", data)
Exemple #2
0
    def stop(self):
        """ trigger to stop the GC
        cannot be undone
        should only be called right before shutdown """

        LOG.info("Stopping GC")
        self.__runGC = False
        self.__rejectRequest = True
        # dump thread status to json
        killStatus = {}
        killStatus['httpStatus'] = 500
        killStatus['error'] = Errors.THREAD_KILLED_AGENT_RESTART
        killStatus['errorMsg'] = 'thread killed, agent restart'
        
        data = self.getInfo(killLiveWithStatus = killStatus, withLock=True)
        manifestutil.writeJson('agent', '.threadmgr', data)
 def snapshot(self, killLiveWithStatus=None, withLock=False):
     """ take a snapshot of the current threadmap """
     data = self.getInfo(killLiveWithStatus, withLock)
     manifestutil.writeJson("agent", ".threadmgr", data)
Exemple #4
0
 def snapshot(self, killLiveWithStatus = None, withLock = False):
     """ take a snapshot of the current threadmap """
     data = self.getInfo(killLiveWithStatus, withLock)
     manifestutil.writeJson('agent', '.threadmgr', data)
    def doRun(self):
        """ Main body of the thread """
        errorMsg = ""
        errorCode = None
        symlinkSwitched = False
        failed = False
        try:
            activePath = os.path.join(
                ServiceController.manifestPath(self._service), 'active')
            oldManifest = None

            appGlobal = pylons.config['pylons.app_globals']

            # make sure that if the active path exists, it's a link
            # if not log that and delete the link
            if (os.path.exists(activePath) and not os.name == 'nt'
                    and not islink(activePath)):
                self.__LOG.error('%s is not a link.  Attempted to delete' %
                                 activePath)
                shutil.rmtree(activePath)

            if (os.path.exists(activePath)):
                oldManifest = os.path.basename(readlink(activePath))

            self.__installManifest(self._service, self._manifest)
            self.__deactivateManifest(self._service, oldManifest)
            symlinkSwitched = self.__switchSymlink(self._service,
                                                   self._manifest)

            appGlobal = pylons.config['pylons.app_globals']

            if self._service == 'agent':
                # START Jeff  09 19 2012: save the timestamp and old manifestPath to .recover: only for agent service.
                recoveryInfo = {}
                beforeKillTimeHuman = strftime("%Y-%m-%d %H:%M:%S",
                                               localtime())
                beforeKillTimeStamp = int(time.time())
                recoveryInfo['beforeKillTimeHuman'] = str(beforeKillTimeHuman)
                recoveryInfo['beforeKillTimeStamp'] = str(beforeKillTimeStamp)
                # make sure there is always quote: even if null. easy for json parsing in startup
                if self._manifest:
                    recoveryInfo['newManifest'] = self._manifest
                else:
                    recoveryInfo['newManifest'] = 'null'
                if oldManifest:
                    recoveryInfo['oldManifest'] = oldManifest
                else:
                    recoveryInfo['oldManifest'] = 'null'
                manifestutil.writeJson('agent', '.recovery', recoveryInfo)
                # END Jeff  09 19 2012: save the timestamp and .recover files with

                # persist threads result before shutting down
                if (hasattr(appGlobal, 'threadMgr')
                        and appGlobal.threadMgr != None):
                    killStatus = {}
                    killStatus['httpStatus'] = 500
                    killStatus['error'] = Errors.THREAD_KILLED_AGENT_RESTART
                    killStatus['errorMsg'] = 'thread killed, agent restart'
                    appGlobal.threadMgr.snapshot(killStatus, True)

            self.__activateManifest(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]
            raise exc

        except AgentException as exc:
            failed = True
            errorMsg = 'Activate Manifest - Agent Exception - %s' % exc.getMsg(
            )
            errorCode = exc.getCode()

        except Exception as exc:
            failed = True
            errorMsg = 'Activate Manifest - Unknown error - (%s/%s) - %s - %s' \
                        % (self._service, self._manifest, str(exc), traceback.format_exc(5))
            errorCode = Errors.UNKNOWN_ERROR

        finally:
            if failed:
                if not self._skipCleanupOnFailure():
                    self.__cleanup(symlinkSwitched, errorMsg, errorCode)

                self.__LOG.warning(errorMsg)
                self._updateStatus(httpStatus=500,
                                   error=errorCode,
                                   errorMsg=errorMsg)
            else:
                self._updateProgress(100)
    def doRun(self):
        """ Main body of the thread """
        errorMsg = ""
        errorCode = None
        symlinkSwitched = False
        failed = False
        try:
            activePath = os.path.join(ServiceController.manifestPath(self._service), 'active')
            oldManifest = None
            
            appGlobal = pylons.config['pylons.app_globals']

            # make sure that if the active path exists, it's a link
            # if not log that and delete the link
            if (os.path.exists(activePath) and not os.name == 'nt' and not islink(activePath)):
                self.__LOG.error('%s is not a link.  Attempted to delete' % activePath)
                shutil.rmtree(activePath)

            if (os.path.exists(activePath)):
                oldManifest = os.path.basename(readlink(activePath))

            self.__installManifest(self._service, self._manifest)
            self.__deactivateManifest(self._service, oldManifest)
            symlinkSwitched = self.__switchSymlink(self._service, self._manifest)

            appGlobal = pylons.config['pylons.app_globals']

            if self._service == 'agent':
                # START Jeff  09 19 2012: save the timestamp and old manifestPath to .recover: only for agent service.
                recoveryInfo = {}
                beforeKillTimeHuman = strftime("%Y-%m-%d %H:%M:%S", localtime())
                beforeKillTimeStamp = int(time.time())
                recoveryInfo['beforeKillTimeHuman'] = str(beforeKillTimeHuman) 
                recoveryInfo['beforeKillTimeStamp'] = str(beforeKillTimeStamp) 
                # make sure there is always quote: even if null. easy for json parsing in startup
                if self._manifest:
                    recoveryInfo['newManifest'] = self._manifest
                else:
                    recoveryInfo['newManifest'] = 'null'
                if oldManifest:
                    recoveryInfo['oldManifest'] = oldManifest
                else:
                    recoveryInfo['oldManifest'] = 'null'
                manifestutil.writeJson('agent', '.recovery', recoveryInfo)
                # END Jeff  09 19 2012: save the timestamp and .recover files with

                # persist threads result before shutting down
                if (hasattr(appGlobal, 'threadMgr') and appGlobal.threadMgr != None):
                    killStatus = {}
                    killStatus['httpStatus'] = 500
                    killStatus['error'] = Errors.THREAD_KILLED_AGENT_RESTART
                    killStatus['errorMsg'] = 'thread killed, agent restart'
                    appGlobal.threadMgr.snapshot(killStatus, True)

            self.__activateManifest(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]
            raise exc
        
        except AgentException as exc:
            failed = True
            errorMsg = 'Activate Manifest - Agent Exception - %s' % exc.getMsg()
            errorCode = exc.getCode()
        
        except Exception as exc:
            failed = True
            errorMsg = 'Activate Manifest - Unknown error - (%s/%s) - %s - %s' \
                        % (self._service, self._manifest, str(exc), traceback.format_exc(5))
            errorCode = Errors.UNKNOWN_ERROR
        
        finally:
            if failed: 
                if not self._skipCleanupOnFailure():
                    self.__cleanup(symlinkSwitched, errorMsg, errorCode)

                self.__LOG.warning(errorMsg)
                self._updateStatus(httpStatus = 500, error = errorCode, errorMsg = errorMsg)
            else:
                self._updateProgress(100)