예제 #1
0
 def loadModuleOnAgentStartup():
     """
     when agent is restarted,
     load agent modules
     """
     if os.path.exists(manifestutil.moduleRootPath('agent')):
         for module in manifestutil.getModules():
             try:
                 manifestutil.processModule('agent', module, True)
             except Exception as excep:
                 LOG.error('Unknown error loading module (%s) - %s - %s' % (module, str(excep), traceback.format_exc(2)))
예제 #2
0
 def loadModuleOnAgentStartup():
     """
     when agent is restarted,
     load agent modules
     """
     if os.path.exists(manifestutil.moduleRootPath('agent')):
         for module in manifestutil.getModules():
             try:
                 manifestutil.processModule('agent', module, True)
             except Exception as excep:
                 LOG.error('Unknown error loading module (%s) - %s - %s' %
                           (module, str(excep), traceback.format_exc(2)))
예제 #3
0
    def doRun(self):
        """ Main body of the thread

        Progress Info:
        Look at the list of packages this manifest has and figure out the progress of this manifest
        Progress 1 = manifest directory created
        Progress 2-80 = all packages downloaded
        Progress 81-99 = all packages untarred
        Progress 100 = all links done
        """
        try:
            if self.__service != 'agent':
                utils.checkDiskFull()

            installedPkgPath = manifestutil.installedPkgRootPath(self.__service)

            # figure out which of the packages are already there
            remainingPackages = {}
            pkgDict = PackageUtil.parseUri(self.__package)
            pkgPath = os.path.join(installedPkgPath, pkgDict['packageName'], pkgDict['packageVersion'])
            remainingPackages[self.__package] = pkgDict

            if (not os.path.exists(pkgPath)):
                # now make sure all the packages are downloaded
                try:
                    self._downloadPackages([self.__package])
                except AgentException as exc:
                    # check if it is download error, then modify exception appropriately
                    if exc.getCode() == Errors.DC_FAILED_DOWNLOAD:
                        exc = AgentException(Errors.MANIFEST_PACKAGE_DOWNLOAD_FAILED,
                                            'Manifest (%s/%s) failed downloading package - %s'
                                            % (self.__service, self.__module, exc.getMsg()))
                    raise exc

                LOG.info('Completed download packages for (%s/%s)' % (self.__service, self.__module))

                # now untar the packages
                self._untarPackages(remainingPackages, self.__service, ServiceController.installedPkgPath(self.__service))
                LOG.info('Completed untar all packages for (%s/%s)' % (self.__service, self.__module))

            # now create the links
            for pkgDict in remainingPackages.itervalues():
                pkgPath = os.path.join(installedPkgPath, pkgDict['packageName'], pkgDict['packageVersion'])
                modulePath = os.path.join(manifestutil.moduleRootPath(self.__service), self.__module)
                    
                # validate target folder does exist
                if not os.path.exists(pkgPath):
                    raise AgentException(Errors.PACKAGE_PATH_ERROR, 'invalid untarred package at %s' % pkgPath)
                    
                # remove existing module 
                isExistingModule = os.path.exists(modulePath) 
                if isExistingModule:
                    execThread = self._getBuiltThread('deactivate')
                    if execThread:
                        super(ModuleCreate, self)._runExeThread(execThread)
                    rmlink(modulePath)
                    
                execThread = self._getBuiltThread('activate')
                if execThread:
                    super(ModuleCreate, self)._runExeThread(execThread)
                symlink(pkgPath, modulePath)
                
                # load controllers from package
                manifestutil.processModule(self.__service, self.__module, not isExistingModule)
                

            LOG.info('Completed create module for (%s/%s)' % (self.__service, self.__module))
            self._updateStatus(progress = 100)

        except AgentException as exc:
            LOG.info(exc.getMsg())
            self._updateStatus(httpStatus = 500, error = exc.getCode(), errorMsg = exc.getMsg())
            
        except Exception as exc:
            errCode = Errors.UNKNOWN_ERROR
            msg = 'Unknown error for (%s/%s) - %s - %s' % (self.__service, self.__module,
                                                           str(exc), traceback.format_exc(2))
            LOG.info(msg)
            self._updateStatus(httpStatus = 500, error = errCode, errorMsg = msg)
예제 #4
0
    def doRun(self):
        """ Main body of the thread

        Progress Info:
        Look at the list of packages this manifest has and figure out the progress of this manifest
        Progress 1 = manifest directory created
        Progress 2-80 = all packages downloaded
        Progress 81-99 = all packages untarred
        Progress 100 = all links done
        """
        try:
            if self.__service != 'agent':
                utils.checkDiskFull()

            installedPkgPath = manifestutil.installedPkgRootPath(
                self.__service)

            # figure out which of the packages are already there
            remainingPackages = {}
            pkgDict = PackageUtil.parseUri(self.__package)
            pkgPath = os.path.join(installedPkgPath, pkgDict['packageName'],
                                   pkgDict['packageVersion'])
            remainingPackages[self.__package] = pkgDict

            if (not os.path.exists(pkgPath)):
                # now make sure all the packages are downloaded
                try:
                    self._downloadPackages([self.__package])
                except AgentException as exc:
                    # check if it is download error, then modify exception appropriately
                    if exc.getCode() == Errors.DC_FAILED_DOWNLOAD:
                        exc = AgentException(
                            Errors.MANIFEST_PACKAGE_DOWNLOAD_FAILED,
                            'Manifest (%s/%s) failed downloading package - %s'
                            % (self.__service, self.__module, exc.getMsg()))
                    raise exc

                LOG.info('Completed download packages for (%s/%s)' %
                         (self.__service, self.__module))

                # now untar the packages
                self._untarPackages(
                    remainingPackages, self.__service,
                    ServiceController.installedPkgPath(self.__service))
                LOG.info('Completed untar all packages for (%s/%s)' %
                         (self.__service, self.__module))

            # now create the links
            for pkgDict in remainingPackages.itervalues():
                pkgPath = os.path.join(installedPkgPath,
                                       pkgDict['packageName'],
                                       pkgDict['packageVersion'])
                modulePath = os.path.join(
                    manifestutil.moduleRootPath(self.__service), self.__module)

                # validate target folder does exist
                if not os.path.exists(pkgPath):
                    raise AgentException(
                        Errors.PACKAGE_PATH_ERROR,
                        'invalid untarred package at %s' % pkgPath)

                # remove existing module
                isExistingModule = os.path.exists(modulePath)
                if isExistingModule:
                    execThreadTuple = self._getBuiltThread('deactivate')
                    super(ModuleCreate,
                          self)._runExeThread(self, execThreadTuple)
                    rmlink(modulePath)

                execThreadTuple = self._getBuiltThread('activate')
                super(ModuleCreate, self)._runExeThread(execThreadTuple)
                symlink(pkgPath, modulePath)

                # load controllers from package
                manifestutil.processModule(self.__service, self.__module,
                                           not isExistingModule)

            LOG.info('Completed create module for (%s/%s)' %
                     (self.__service, self.__module))
            self._updateStatus(progress=100)

        except AgentException as exc:
            LOG.info(exc.getMsg())
            self._updateStatus(httpStatus=500,
                               error=exc.getCode(),
                               errorMsg=exc.getMsg())

        except Exception as exc:
            errCode = Errors.UNKNOWN_ERROR
            msg = 'Unknown error for (%s/%s) - %s - %s' % (
                self.__service, self.__manifest, str(exc),
                traceback.format_exc(2))
            LOG.info(msg)
            self._updateStatus(httpStatus=500, error=errCode, errorMsg=msg)