コード例 #1
0
    def getCheckJobFromPool(self):
        if self.jobPool:
            job, expireDC = self.jobPool.pop(0)
            expireDC.cancel()
            self.debug('running check in already-running job %s', job.avatarId)
            return defer.succeed(job)

        avatarId = 'check-%d' % (self._checkCount, )
        self._checkCount += 1

        self.debug('spawning new job %s to run a check', avatarId)
        d = self._startSet.createStart(avatarId)

        p = base.JobProcessProtocol(self, avatarId, self._startSet)
        executable = os.path.join(configure.bindir, 'flumotion-job')
        argv = [executable, avatarId, self._socketPath]

        childFDs = {0: 0, 1: 1, 2: 2}
        env = {}
        env.update(os.environ)
        env['FLU_DEBUG'] = log.getDebug()
        process = reactor.spawnProcess(p,
                                       executable,
                                       env=env,
                                       args=argv,
                                       childFDs=childFDs)

        p.setPid(process.pid)
        jobInfo = base.JobInfo(process.pid, avatarId, type, None, None, None,
                               [])
        self._jobInfos[process.pid] = jobInfo

        def haveMind(_):
            # we have a mind, in theory; return the job avatar
            return self.avatars[avatarId]

        d.addCallback(haveMind)
        return d
コード例 #2
0
ファイル: component.py プロジェクト: offlinehacker/flumotion
    def setup(self):
        """
        Sets up the component.  Called during __init__, so be sure not
        to raise exceptions, instead adding messages to the component
        state.
        """

        def run_setups():
            setups = common.get_all_methods(self, 'do_setup', False)
            return _maybeDeferredChain(setups, self)

        def setup_complete(_):
            self.debug('setup completed')
            self.setup_completed()

        def got_error(failure):
            txt = log.getFailureMessage(failure)
            self.debug('got_error: %s', txt)
            if not failure.check(errors.ComponentSetupHandledError):
                self.warning('Setup failed: %s', txt)
                m = messages.Error(T_(N_("Could not setup component.")),
                                   debug=txt,
                                   mid="component-setup-%s" % self.name)
                # will call setMood(moods.sad)
                self.addMessage(m)

            # swallow
            return None

        self.setMood(moods.waking)
        self.uiState.set('start-time', time.time())

        self.uiState.set('total-memory', self._getTotalMemory())
        self.uiState.set('num-cpus', self._getNumberOfCPUs())
        self.uiState.set('flu-debug', log.getDebug())

        d = run_setups()
        d.addCallbacks(setup_complete, got_error)
コード例 #3
0
    def setup(self):
        """
        Sets up the component.  Called during __init__, so be sure not
        to raise exceptions, instead adding messages to the component
        state.
        """
        def run_setups():
            setups = common.get_all_methods(self, 'do_setup', False)
            return _maybeDeferredChain(setups, self)

        def setup_complete(_):
            self.debug('setup completed')
            self.setup_completed()

        def got_error(failure):
            txt = log.getFailureMessage(failure)
            self.debug('got_error: %s', txt)
            if not failure.check(errors.ComponentSetupHandledError):
                self.warning('Setup failed: %s', txt)
                m = messages.Error(T_(N_("Could not setup component.")),
                                   debug=txt,
                                   mid="component-setup-%s" % self.name)
                # will call setMood(moods.sad)
                self.addMessage(m)

            # swallow
            return None

        self.setMood(moods.waking)
        self.uiState.set('start-time', time.time())

        self.uiState.set('total-memory', self._getTotalMemory())
        self.uiState.set('num-cpus', self._getNumberOfCPUs())
        self.uiState.set('flu-debug', log.getDebug())

        d = run_setups()
        d.addCallbacks(setup_complete, got_error)
コード例 #4
0
ファイル: job.py プロジェクト: offlinehacker/flumotion
    def getCheckJobFromPool(self):
        if self.jobPool:
            job, expireDC = self.jobPool.pop(0)
            expireDC.cancel()
            self.debug('running check in already-running job %s',
                       job.avatarId)
            return defer.succeed(job)

        avatarId = 'check-%d' % (self._checkCount, )
        self._checkCount += 1

        self.debug('spawning new job %s to run a check', avatarId)
        d = self._startSet.createStart(avatarId)

        p = base.JobProcessProtocol(self, avatarId, self._startSet)
        executable = os.path.join(configure.bindir, 'flumotion-job')
        argv = [executable, avatarId, self._socketPath]

        childFDs = {0: 0, 1: 1, 2: 2}
        env = {}
        env.update(os.environ)
        env['FLU_DEBUG'] = log.getDebug()
        process = reactor.spawnProcess(p, executable, env=env, args=argv,
                                       childFDs=childFDs)

        p.setPid(process.pid)
        jobInfo = base.JobInfo(process.pid, avatarId, type, None, None,
                               None, [])
        self._jobInfos[process.pid] = jobInfo

        def haveMind(_):
            # we have a mind, in theory; return the job avatar
            return self.avatars[avatarId]

        d.addCallback(haveMind)
        return d
コード例 #5
0
    def spawn(self, avatarId, type, moduleName, methodName, nice, bundles,
              conf):
        """
        Spawn a new job.

        This will spawn a new flumotion-job process, running under the
        requested nice level. When the job logs in, it will be told to
        load bundles and run a function, which is expected to return a
        component.

        @param avatarId:   avatarId the component should use to log in
        @type  avatarId:   str
        @param type:       type of component to start
        @type  type:       str
        @param moduleName: name of the module to create the component from
        @type  moduleName: str
        @param methodName: the factory method to use to create the component
        @type  methodName: str
        @param nice:       nice level
        @type  nice:       int
        @param bundles:    ordered list of (bundleName, bundlePath) for this
                           component
        @type  bundles:    list of (str, str)
        @param conf:       component configuration
        @type  conf:       dict
        """
        d = self._startSet.createStart(avatarId)

        p = base.JobProcessProtocol(self, avatarId, self._startSet)
        executable = os.path.join(configure.bindir, 'flumotion-job')
        if not os.path.exists(executable):
            self.error(
                "Trying to spawn job process, but '%s' does not "
                "exist", executable)
        argv = [executable, avatarId, self._socketPath]

        realexecutable = executable

        # Run some jobs under valgrind, optionally. Would be nice to have the
        # arguments to run it with configurable, but this'll do for now.
        # FLU_VALGRIND_JOB takes a comma-seperated list of full component
        # avatar IDs.
        if 'FLU_VALGRIND_JOB' in os.environ:
            jobnames = os.environ['FLU_VALGRIND_JOB'].split(',')
            if avatarId in jobnames:
                realexecutable = 'valgrind'
                # We can't just valgrind flumotion-job, we have to valgrind
                # python running flumotion-job, otherwise we'd need
                # --trace-children (not quite sure why), which we don't want
                argv = [
                    'valgrind', '--leak-check=full', '--num-callers=24',
                    '--leak-resolution=high', '--show-reachable=yes', 'python'
                ] + argv

        childFDs = {0: 0, 1: 1, 2: 2}
        env = {}
        env.update(os.environ)
        env['FLU_DEBUG'] = log.getDebug()
        process = reactor.spawnProcess(p,
                                       realexecutable,
                                       env=env,
                                       args=argv,
                                       childFDs=childFDs)

        p.setPid(process.pid)

        self.addJobInfo(
            process.pid,
            ComponentJobInfo(process.pid, avatarId, type, moduleName,
                             methodName, nice, bundles, conf))
        return d
コード例 #6
0
ファイル: job.py プロジェクト: offlinehacker/flumotion
    def spawn(self, avatarId, type, moduleName, methodName, nice,
              bundles, conf):
        """
        Spawn a new job.

        This will spawn a new flumotion-job process, running under the
        requested nice level. When the job logs in, it will be told to
        load bundles and run a function, which is expected to return a
        component.

        @param avatarId:   avatarId the component should use to log in
        @type  avatarId:   str
        @param type:       type of component to start
        @type  type:       str
        @param moduleName: name of the module to create the component from
        @type  moduleName: str
        @param methodName: the factory method to use to create the component
        @type  methodName: str
        @param nice:       nice level
        @type  nice:       int
        @param bundles:    ordered list of (bundleName, bundlePath) for this
                           component
        @type  bundles:    list of (str, str)
        @param conf:       component configuration
        @type  conf:       dict
        """
        d = self._startSet.createStart(avatarId)

        p = base.JobProcessProtocol(self, avatarId, self._startSet)
        executable = os.path.join(configure.bindir, 'flumotion-job')
        if not os.path.exists(executable):
            self.error("Trying to spawn job process, but '%s' does not "
                       "exist", executable)
        argv = [executable, avatarId, self._socketPath]

        realexecutable = executable

        # Run some jobs under valgrind, optionally. Would be nice to have the
        # arguments to run it with configurable, but this'll do for now.
        # FLU_VALGRIND_JOB takes a comma-seperated list of full component
        # avatar IDs.
        if 'FLU_VALGRIND_JOB' in os.environ:
            jobnames = os.environ['FLU_VALGRIND_JOB'].split(',')
            if avatarId in jobnames:
                realexecutable = 'valgrind'
                # We can't just valgrind flumotion-job, we have to valgrind
                # python running flumotion-job, otherwise we'd need
                # --trace-children (not quite sure why), which we don't want
                argv = ['valgrind', '--leak-check=full', '--num-callers=24',
                    '--leak-resolution=high', '--show-reachable=yes',
                    'python'] + argv

        childFDs = {0: 0, 1: 1, 2: 2}
        env = {}
        env.update(os.environ)
        env['FLU_DEBUG'] = log.getDebug()
        process = reactor.spawnProcess(p, realexecutable, env=env, args=argv,
            childFDs=childFDs)

        p.setPid(process.pid)

        self.addJobInfo(process.pid,
                        ComponentJobInfo(process.pid, avatarId, type,
                                         moduleName, methodName, nice,
                                         bundles, conf))
        return d