예제 #1
0
    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

        from agent.lib.agent_thread.activate_manifest import ActivateManifest
        activateThread = ActivateManifest(self._threadMgr, self.__service,
                                          self.__manifest)
        contextutils.copycontexts(self, activateThread, contextutils.CTX_NAMES)
        activateThread.run()

        status = activateThread.getStatus()
        if (status.has_key('error') and status['error']):
            raise AgentException(status['error'], status['errorMsg'])
예제 #2
0
    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
        
        from agent.lib.agent_thread.activate_manifest import ActivateManifest
        activateThread = ActivateManifest(self._threadMgr, self.__service, self.__manifest)
        contextutils.copycontexts(self, activateThread, contextutils.CTX_NAMES)
        activateThread.run()
        
        status = activateThread.getStatus()
        if (status.has_key('error') and status['error']):
            raise AgentException(status['error'], status['errorMsg'])
예제 #3
0
    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'])
예제 #4
0
    def _getBuiltThread(self, service, manifest, package, exeName):
        """ here """
        # figure out the path to the cronus scripts
        uname = pylons.config['app_user_account']
        execPath = os.path.join(ManifestController.manifestPath(service, manifest), package, 'cronus', 'scripts', exeName)
        if (isHigherPrivilegeService(service)):
            cmd = execPath
        else:
            cmd = utils.sudoCmd([execPath], uname)

        dummy = not os.path.exists(execPath)
        execThread = ExecThread(self._threadMgr, cmd)
        copycontexts(self, execThread, contextutils.CTX_NAMES)
        return execThread, dummy
예제 #5
0
    def _getBuiltThread(self, scriptName):
        """ build lcm script exec thread """
        # figure out the path to the cronus scripts
        uname = pylons.config['app_user_account']
        execPath = os.path.join(manifestutil.modulePath(self.__service, self.__module), self.__package, 'cronus', 'scripts', scriptName)
        if (isHigherPrivilegeService(self.__service)):
            cmd = execPath
        else:
            cmd = utils.sudoCmd([execPath], uname)

        dummy = not os.path.exists(execPath)
        execThread = ExecThread(self._threadMgr, cmd)
        copycontexts(self, execThread, ['service', 'guid'])
        return execThread, dummy
예제 #6
0
    def _getBuiltThread(self, service, manifest, package, exeName):
        """ here """
        # figure out the path to the cronus scripts
        uname = pylons.config['app_user_account']
        execPath = os.path.join(
            ManifestController.manifestPath(service, manifest), package,
            'cronus', 'scripts', exeName)
        if (isHigherPrivilegeService(service)):
            cmd = execPath
        else:
            cmd = utils.sudoCmd([execPath], uname)

        dummy = not os.path.exists(execPath)
        execThread = ExecThread(self._threadMgr, cmd)
        copycontexts(self, execThread, contextutils.CTX_NAMES)
        return execThread, dummy
예제 #7
0
    def _getBuiltThread(self, scriptName):
        """ build lcm script exec thread """
        # figure out the path to the cronus scripts
        uname = pylons.config['app_user_account']
        execPath = os.path.join(
            manifestutil.modulePath(self.__service, self.__module),
            self.__package, 'cronus', 'scripts', scriptName)
        if (isHigherPrivilegeService(self.__service)):
            cmd = execPath
        else:
            cmd = utils.sudoCmd([execPath], uname)

        dummy = not os.path.exists(execPath)
        execThread = ExecThread(self._threadMgr, cmd)
        copycontexts(self, execThread, ['service', 'guid'])
        return execThread, dummy
예제 #8
0
    def __createManifest(self):
        """ create a manifest
        """
        service = 'agent'
        LOG.info("Create Manifest %s - %s - %s" % (service, self.__manifest, str(self.__packages)))
        path = manifestutil.manifestPath(service, self.__manifest)
        # check to see if the manifest already exists
        if (os.path.isdir(path)):
            LOG.info('Manifest %s already exist, skip creating' % self.__manifest)
            return

        from agent.lib.agent_thread.manifest_create import ManifestCreate
        manThread = ManifestCreate(self._threadMgr, service, self.__manifest, self.__packages, skipProp = self.__skipProp)
        contextutils.copycontexts(self, manThread, contextutils.CTX_NAMES)
        manThread.run()
        status = manThread.getStatus()
        if (status.has_key('error') and status['error']):
            raise AgentException(status['error'], status['errorMsg'])
예제 #9
0
    def runScript(self, script, timeout, progressTimeout):
        '''
        @param script: script name
        @param timeout: total script timeout
        @param progressTimeout: progress timeout
        @return: ExecThread instance
        @throws PackageScriptNotFound: if script does not exist
        '''
        if not self.hasScript(script):
            raise PackageScriptNotFound('missing package script: ' + self.__scriptPath(script))

        cmd = utils.sudoCmd([], self.__userName) if self.__userName else []
        cmd.append(self.__scriptPath(script))
        execThread = ExecThread(self.__threadMgr, cmd)
        execThread.setTimeout(timeout)
        execThread.setProgressTimeout(progressTimeout)
        copycontexts(self, execThread, ['guid', 'service'])
        execThread.start()

        return execThread
예제 #10
0
    def runScript(self, script, timeout, progressTimeout):
        '''
        @param script: script name
        @param timeout: total script timeout
        @param progressTimeout: progress timeout
        @return: ExecThread instance
        @throws PackageScriptNotFound: if script does not exist
        '''
        if not self.hasScript(script):
            raise PackageScriptNotFound('missing package script: ' +
                                        self.__scriptPath(script))

        cmd = utils.sudoCmd([], self.__userName) if self.__userName else []
        cmd.append(self.__scriptPath(script))
        execThread = ExecThread(self.__threadMgr, cmd)
        execThread.setTimeout(timeout)
        execThread.setProgressTimeout(progressTimeout)
        copycontexts(self, execThread, ['guid', 'service'])
        execThread.start()

        return execThread
예제 #11
0
    def __createManifest(self):
        """ create a manifest
        """
        service = 'agent'
        LOG.info("Create Manifest %s - %s - %s" %
                 (service, self.__manifest, str(self.__packages)))
        path = manifestutil.manifestPath(service, self.__manifest)
        # check to see if the manifest already exists
        if (os.path.isdir(path)):
            LOG.info('Manifest %s already exist, skip creating' %
                     self.__manifest)
            return

        from agent.lib.agent_thread.manifest_create import ManifestCreate
        manThread = ManifestCreate(self._threadMgr,
                                   service,
                                   self.__manifest,
                                   self.__packages,
                                   skipProp=self.__skipProp)
        contextutils.copycontexts(self, manThread, contextutils.CTX_NAMES)
        manThread.run()
        status = manThread.getStatus()
        if (status.has_key('error') and status['error']):
            raise AgentException(status['error'], status['errorMsg'])
예제 #12
0
 def injectJobCtx(self, target):
     ''' inject both guid and callback into an object
         @param target: target
     '''
     contextutils.copycontexts(self, target, CTXNAMES)
예제 #13
0
    def doRun(self):
        """ Main body of the thread """
        spath = manifestutil.servicePath(self._service)

        self._updateProgress(1)

        errorMsg = ""
        errorCode = None
        failed = False
        ctxNames = ['guid', 'service']
        
        try:
            # create service if not already exist
            if not os.path.exists(spath):
                os.makedirs(spath)
                os.makedirs(os.path.join(spath, 'manifests'))
                os.makedirs(os.path.join(spath, 'installed-packages'))
                os.makedirs(os.path.join(spath, 'modules'))
                os.makedirs(os.path.join(spath, 'downloaded-packages'))
                os.makedirs(os.path.join(spath, '.appdata'))
                os.makedirs(os.path.join(spath, '.data'))
                import pwd
                uname = pylons.config['app_user_account']
                uid = pwd.getpwnam(uname).pw_uid
                gid = pwd.getpwnam(uname).pw_gid
                utils.rchown(os.path.join(spath, '.appdata'), uid, gid)

            # verify that the path exists
            if (not os.path.isdir(spath)):
                raise AgentException(Errors.UNKNOWN_ERROR, "Service(%s) was not created" % self._service)

            self._updateProgress(20)

            # 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.getPackageByName(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(threadmgr.NULL_THREADMGR, self._service, self._manifest, self.__packages, skipProp = self.__skipProp)
                contextutils.copycontexts(self, manThread, ctxNames)
                manThread.run()
                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))

            if not self.__skipActivation:                    
                activateThread = ActivateManifest(threadmgr.NULL_THREADMGR, self._service, self._manifest)
                contextutils.copycontexts(self, activateThread, ctxNames)
                activateThread.run()
            
                status = activateThread.getStatus()
                if (status['error'] != None):
                    raise AgentException(status['error'], status['errorMsg'])

                # activte manifest if not already activated
                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)
예제 #14
0
 def injectJobCtx(self, target):
     ''' inject both guid and callback into an object
         @param target: target
     '''
     contextutils.copycontexts(self, target, contextutils.CTX_NAMES)