Esempio n. 1
0
    def _loadManagerBouncer(self, conf):
        if not (conf.bouncer):
            self.warning('no bouncer defined, nothing can access the '
                         'manager')
            return defer.succeed(None)

        self.debug('going to start manager bouncer %s of type %s',
                   conf.bouncer.name, conf.bouncer.type)

        defs = registry.getRegistry().getComponent(conf.bouncer.type)
        entry = defs.getEntryByType('component')
        # FIXME: use entry.getModuleName() (doesn't work atm?)
        moduleName = defs.getSource()
        methodName = entry.getFunction()
        bouncer = reflectcall.createComponent(moduleName, methodName,
                                              conf.bouncer.getConfigDict())
        d = bouncer.waitForHappy()

        def setupCallback(result):
            bouncer.debug('started')
            self.setBouncer(bouncer)

        def setupErrback(failure):
            self.warning('Error starting manager bouncer')
        d.addCallbacks(setupCallback, setupErrback)
        return d
Esempio n. 2
0
File: job.py Progetto: flyapen/UgFlu
    def _createComponent(self, avatarId, type, moduleName, methodName,
                         nice, conf):
        """
        Create a component of the given type.
        Log in to the manager with the given avatarId.

        @param avatarId:   avatarId component will use to log in to manager
        @type  avatarId:   str
        @param type:       type of component to start
        @type  type:       str
        @param moduleName: name of the module that contains the entry point
        @type  moduleName: str
        @param methodName: name of the factory method to create the component
        @type  methodName: str
        @param nice:       the nice level to run with
        @type  nice:       int
        @param conf:       the component configuration
        @type  conf:       dict
        """
        self.info('Creating component "%s" of type "%s"', avatarId, type)

        self._setNice(nice)
        self._enableCoreDumps()

        try:
            comp = createComponent(moduleName, methodName, conf)
        except Exception, e:
            msg = "Exception %s during createComponent: %s" % (
                e.__class__.__name__, " ".join(e.args))
            # traceback.print_exc()
            # a ComponentCreateError is already formatted
            if isinstance(e, errors.ComponentCreateError):
                msg = e.args[0]
            self.warning(
                "raising ComponentCreateError(%s) and stopping job" % msg)
            # This is a Nasty Hack. We raise ComponentCreateError, which can be
            # caught on the other side and marshalled as a reasonably
            # comprehensible error message. However, if we shutdown
            # immediately, the PB connection won't be available, so
            # the worker will just get an error about that! So, instead,
            # we shut down in a tenth of a second, usually allowing
            # the worker to get scheduled and read the exception over PB.
            # Ick!
            reactor.callLater(0.1, self.shutdown)
            raise errors.ComponentCreateError(msg)
Esempio n. 3
0
    def _createComponent(self, avatarId, type, moduleName, methodName, nice,
                         conf):
        """
        Create a component of the given type.
        Log in to the manager with the given avatarId.

        @param avatarId:   avatarId component will use to log in to manager
        @type  avatarId:   str
        @param type:       type of component to start
        @type  type:       str
        @param moduleName: name of the module that contains the entry point
        @type  moduleName: str
        @param methodName: name of the factory method to create the component
        @type  methodName: str
        @param nice:       the nice level to run with
        @type  nice:       int
        @param conf:       the component configuration
        @type  conf:       dict
        """
        self.info('Creating component "%s" of type "%s"', avatarId, type)

        self._setNice(nice)
        self._enableCoreDumps()

        try:
            comp = createComponent(moduleName, methodName, conf)
        except Exception, e:
            msg = "Exception %s during createComponent: %s" % (
                e.__class__.__name__, " ".join(e.args))
            # traceback.print_exc()
            # a ComponentCreateError is already formatted
            if isinstance(e, errors.ComponentCreateError):
                msg = e.args[0]
            self.warning("raising ComponentCreateError(%s) and stopping job" %
                         msg)
            # This is a Nasty Hack. We raise ComponentCreateError, which can be
            # caught on the other side and marshalled as a reasonably
            # comprehensible error message. However, if we shutdown
            # immediately, the PB connection won't be available, so
            # the worker will just get an error about that! So, instead,
            # we shut down in a tenth of a second, usually allowing
            # the worker to get scheduled and read the exception over PB.
            # Ick!
            reactor.callLater(0.1, self.shutdown)
            raise errors.ComponentCreateError(msg)