示例#1
0
    def activate(self, service, manifest):
        """ activate manifest, if already active then skip """
        from agent.lib.agent_thread.activate_manifest import ActivateManifest
        LOG.info('activateManifest for service(%s) with body: %s', service, request.body)
        try:
            appGlobal = config['pylons.app_globals']
            
            if manifestutil.getActiveManifest(service) == manifest:
                return doneResult(request, response, controller=self)
            
            else:
                if request.body:
                    pushedData = json.loads(request.body)
                    serviceutil.updateLcmMeta(service, pushedData)
                    
                mf_path = os.path.join(manifestutil.manifestPath(service, manifest))
                if (not os.path.exists(mf_path)):
                    return errorResult(request, response, Errors.ACTIVEMANIFEST_MANIFEST_MISSING,
                                   'Manifest(%s, %s) path missing' % (service, manifest),
                                   controller=self)
                LOG.debug('Manifest path exists: %s' % (mf_path))
                activateThread = ActivateManifest(appGlobal.threadMgr, service, manifest,
                                                  action=ActivateManifest.ACTION_ACTIVATION)
                self.injectJobCtx(activateThread)
                activateThread.start()
                activateThread.threadMgrEvent.wait()

            return statusResult(request, response, activateThread, controller=self)

        except Exception as excep:
            msg = 'Unknown error for activateManifest(%s/%s) - %s - %s' % (service, manifest, str(excep), traceback.format_exc(2))
            return errorResult(request, response, error=Errors.UNKNOWN_ERROR,
                               errorMsg=msg, controller=self)
示例#2
0
    def rollbackservice(self, service):
        """ rollback an existing service """
        LOG.info('rollback to last active manifest for service(%s) ', service)
        manifest = None
        try:
            appGlobal = config['pylons.app_globals']
            manifest = serviceutil.getPastManifest(service, 1)
            
            if manifest:
                activateThread = ActivateManifest(appGlobal.threadMgr, service, manifest,
                                                  action=ActivateManifest.ACTION_ACTIVATION)
                self.injectJobCtx(activateThread)
                activateThread.start()
                activateThread.threadMgrEvent.wait()
            else:
                raise AgentException(Errors.MANIFEST_NOT_FOUND, "No rollback manifest found")

            return statusResult(request, response, activateThread, controller=self)

        except AgentException as excep:
            return errorResult(request, response, error=excep.getCode(), errorMsg=excep.getMsg(), controller=self)

        except Exception as excep:
            msg = 'Unknown error for rollback service(%s) - %s - %s' % (service, str(excep), traceback.format_exc(2))
            return errorResult(request, response, error=Errors.UNKNOWN_ERROR,
                               errorMsg=msg, controller=self)
示例#3
0
    def reset(self, service):
        ''' Controller to reset service '''
        LOG.info('reset for service(%s)', service)

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

            if not os.path.exists(manifestutil.manifestPath(service, 'active')):
                return errorResult(request, response, Errors.ACTIVEMANIFEST_MANIFEST_MISSING,
                                   'Active Manifest(%s) path missing' % (service),
                                   controller = self)
            resetThread = ActivateManifest(appGlobal.threadMgr, service, 
                                           manifestutil.ACTIVE_MANIFEST,
                                           action = ActivateManifest.ACTION_RESET)
            self.injectJobCtx(resetThread)
            resetThread.start()
            resetThread.threadMgrEvent.wait()

            return statusResult(request, response, resetThread, controller = self)

        except Exception as excep:
            return errorResult(request, response, error = Errors.UNKNOWN_ERROR,
                               errorMsg = 'Unknown error for restart service(%s) - %s - %s' %
                               (service, str(excep), traceback.format_exc(2)),
                               controller = self)
示例#4
0
    def activatemanifest(self, service):
        """ activate manifest, if already active then skip """
        LOG.info('activateManifest for service(%s) with body: %s', service, request.body)
        try:
            appGlobal = config['pylons.app_globals']
            manifest = ''
            requestjson = json.loads(request.body)
            manifest = requestjson['manifest']
            force = asbool(requestjson['force']) if 'force' in requestjson else False
            
            if not force and manifestutil.getActiveManifest(service) == manifest:
                return doneResult(request, response, controller=self)
            
            else:
                mf_path = os.path.join(ManifestController.manifestPath(service, manifest))
                if (not os.path.exists(mf_path)):
                    return errorResult(request, response, Errors.ACTIVEMANIFEST_MANIFEST_MISSING,
                                   'Manifest(%s, %s) path missing' % (service, manifest),
                                   controller = self)
                LOG.debug('Manifest path exists: %s' % (mf_path))
                activateThread = ActivateManifest(appGlobal.threadMgr, service, manifest)
                self.injectJobCtx(activateThread)
                activateThread.start()
                activateThread.threadMgrEvent.wait()

            return statusResult(request, response, activateThread, controller = self)

        except Exception as excep:
            msg = 'Unknown error for activateManifest(%s/%s) - %s - %s' % (service, manifest, str(excep), traceback.format_exc(2))
            return errorResult(request, response, error = Errors.UNKNOWN_ERROR,
                               errorMsg = msg, controller = self)
示例#5
0
    def activatemanifest(self, service):
        """ activate manifest, if already active then skip """
        LOG.info('activateManifest for service(%s) with body: %s', service,
                 request.body)
        try:
            appGlobal = config['pylons.app_globals']
            manifest = ''
            requestjson = json.loads(request.body)
            manifest = requestjson['manifest']
            force = asbool(
                requestjson['force']) if 'force' in requestjson else False

            if not force and manifestutil.getActiveManifest(
                    service) == manifest:
                return doneResult(request, response, controller=self)

            else:
                mf_path = os.path.join(
                    ManifestController.manifestPath(service, manifest))
                if (not os.path.exists(mf_path)):
                    return errorResult(request,
                                       response,
                                       Errors.ACTIVEMANIFEST_MANIFEST_MISSING,
                                       'Manifest(%s, %s) path missing' %
                                       (service, manifest),
                                       controller=self)
                LOG.debug('Manifest path exists: %s' % (mf_path))
                activateThread = ActivateManifest(appGlobal.threadMgr, service,
                                                  manifest)
                self.injectJobCtx(activateThread)
                activateThread.start()
                activateThread.threadMgrEvent.wait()

            return statusResult(request,
                                response,
                                activateThread,
                                controller=self)

        except Exception as excep:
            msg = 'Unknown error for activateManifest(%s/%s) - %s - %s' % (
                service, manifest, str(excep), traceback.format_exc(2))
            return errorResult(request,
                               response,
                               error=Errors.UNKNOWN_ERROR,
                               errorMsg=msg,
                               controller=self)
示例#6
0
    def deactivatemanifest(self, service):
        """ deactivate a manifest """
        LOG.info('activateManifest for service(%s) with body: %s', service, request.body)
        try:
            appGlobal = config['pylons.app_globals']
            if not os.path.exists(manifestutil.manifestPath(service, 'active')):
                return errorResult(request, response, Errors.ACTIVEMANIFEST_MANIFEST_MISSING,
                                   'Deactivate Manifest(%s) path missing' % (service),
                                   controller = self)

            deactivateThread = ActivateManifest(appGlobal.threadMgr, service,
                                                manifestutil.ACTIVE_MANIFEST,
                                                action=ActivateManifest.ACTION_DEACTIVATION)
            self.injectJobCtx(deactivateThread)
            deactivateThread.start()
            deactivateThread.threadMgrEvent.wait()

            return statusResult(request, response, deactivateThread, controller = self)

        except Exception as excep:
            msg = 'Unknown error for deactivateManifest(%s) - %s - %s' % (service, str(excep), traceback.format_exc(2))
            return errorResult(request, response, error = Errors.UNKNOWN_ERROR,
                               errorMsg = msg, controller = self)