示例#1
0
    def _setup_all(self, ids):
        """
        Initializing of all the circuits.

        @param ids: circuits ids
        @type ids: int

        @return: list of setup results
        @rtype: DeferredList
        """
        dl = []
        for id in ids :
            if any([True for c in self._circuits if c.id == id]):
                circuit = self.get(id)
                if circuit.initialised :
                    self._run_one(circuit)
                else :
                    circuit.install_dispatcher(self)
                    d = circuit.setup()
                    dl.append(d)
            else :
                circuit = Circuit(id, self.installed_phases, self.config)
                circuit.install_dispatcher(self)
                d = circuit.setup()
                dl.append(d)

        return DeferredList(dl)
示例#2
0
    def _circuit_pre_setup(self, id):
        """
	Circuit pre-setup step.

	This method encapsuled as deferred avoids to go directly on the setup
	without terminating all the operations in the Circuit's constructor,
	especialy the creation oh CohQuery object needed for setup.

	@param id: circuit id
        @type id: int

        @return: initialized Circuit object
        @rtype: Circuit
        """
        circuit = Circuit(id, self.installed_phases, self.config)
        circuit.install_dispatcher(self)
        return circuit
示例#3
0
    def _circuit_pre_setup(self, id):
        """
	Circuit pre-setup step.

	This method encapsuled as deferred avoids to go directly on the setup
	without terminating all the operations in the Circuit's constructor,
	especialy the creation oh CohQuery object needed for setup.

	@param id: circuit id
        @type id: int

        @return: initialized Circuit object
        @rtype: Circuit
        """
        circuit = Circuit(id, self.installed_phases, self.config)
        circuit.install_dispatcher(self)
        return circuit
示例#4
0
    def run_proxymethod(self, launcher, id, name, args, from_dlp):
        """
        Calls the proxy method.

        This call is invoked by proxy processing the parsing results
        from the launcher or download provider.
        Invoked method tagged as @launcher_proxymethod

        @param launcher: launcher which calls this method
        @type launcher: str

        @param id: commands_on_host id
        @type id: int

        @param args: argumets of called method
        @type args: list

        @param from_dlp: if True, response is coming from DLP
        @type from_dlp: bool
        """
        circuit = self.get(id)
        if circuit:
            return self._run_proxymethod(launcher, id, name, args, circuit)
        else:
            self.logger.info("probably recurrent phase or stopped circuit #%s" % (id))
            # Recurrent phase parsing which does not exists in the container
            # The circuit is created out of container
            circuit = Circuit(id, self.installed_phases, self.config, from_dlp)
            if not circuit:
                self.logger.warn("Circuit #%s: not found" % id)
                return False
            circuit.install_dispatcher(self)
            d = circuit.setup(True)

            @d.addCallback
            def _setup(result):
                dth = deferToThread(circuit.run)
                return dth

            @d.addCallback
            def _post_setup(result):
                if not circuit.running_phase:
                    self.logger.warn("Method <%s> call for current phase is not valid" % name)
                    return False
                if from_dlp:
                    valid_method_name = get_dlp_method(circuit.running_phase.name)

                    if valid_method_name != name:
                        self.logger.warn("Recurrent phase %s ignored" % name)
                        return False
                dps = maybeDeferred(self._run_proxymethod, launcher, id, name, args, circuit)

                @dps.addCallback
                def result_proxy(res):
                    return True

                @dps.addErrback
                def failed_proxy(failure):
                    self.logger.warn("Proxymethod execution failed: %s" % failure)
                    return False

                return dps

            @d.addErrback
            def _eb(result):
                self.logger.warn("Recurrent phase result parsing failed: %s" % result)
                return False

            return d
示例#5
0
    def run_proxymethod(self, launcher, id, name, args, from_dlp):
        """
        Calls the proxy method.

        This call is invoked by proxy processing the parsing results
        from the launcher or download provider.
        Invoked method tagged as @launcher_proxymethod

        @param launcher: launcher which calls this method
        @type launcher: str

        @param id: commands_on_host id
        @type id: int

        @param args: argumets of called method
        @type args: list

        @param from_dlp: if True, response is coming from DLP
        @type from_dlp: bool
        """
        circuit = self.get(id)
        if circuit:
            return self._run_proxymethod(launcher, id, name, args, circuit)
        else:
            self.logger.info(
                "probably recurrent phase or stopped circuit #%s" % (id))
            # Recurrent phase parsing which does not exists in the container
            # The circuit is created out of container
            circuit = Circuit(id, self.installed_phases, self.config, from_dlp)
            if not circuit:
                self.logger.warn("Circuit #%s: not found" % id)
                return False
            circuit.install_dispatcher(self)
            d = circuit.setup(True)

            @d.addCallback
            def _setup(result):
                dth = deferToThread(circuit.run)
                return dth

            @d.addCallback
            def _post_setup(result):
                if not circuit.running_phase:
                    self.logger.warn(
                        "Method <%s> call for current phase is not valid" %
                        name)
                    return False
                if from_dlp:
                    valid_method_name = get_dlp_method(
                        circuit.running_phase.name)

                    if valid_method_name != name:
                        self.logger.warn("Recurrent phase %s ignored" % name)
                        return False
                dps = maybeDeferred(self._run_proxymethod, launcher, id, name,
                                    args, circuit)

                @dps.addCallback
                def result_proxy(res):
                    return True

                @dps.addErrback
                def failed_proxy(failure):
                    self.logger.warn("Proxymethod execution failed: %s" %
                                     failure)
                    return False

                return dps

            @d.addErrback
            def _eb(result):
                self.logger.warn("Recurrent phase result parsing failed: %s" %
                                 result)
                return False

            return d