Example #1
0
    def _handle_message(self, message):
        """
        The Message Handler. 
        
        @type message: amqplib.client_0_8.basic_message.Message 
        @param message: A message containing a pickled dictionary

        This turns off the connection on receipt of a message.
        Once the Task has run the connection is reestablished.

        Response Queue is kept informed of the status
        """

        self._stop_consume()
        self.channel.basic_ack(delivery_tag=message.delivery_tag)
        #
        cmd_msg = unpack_message(message)
        task_id = cmd_msg.task_id
        response_queue = cmd_msg.response_queue
        self._set_log_handler(response_queue)
        self._publish_task_state_change(task_id, response_queue)
        #
        try:
            self._dispatch(cmd_msg)
        except CommandFailed, exc:
            error_msg = "Command %s failed" % cmd_msg.command
            self._log.error(error_msg)

            # We need to send pure OTSException because server does not know
            # about ots.common.command.CommandFailed and unpickle will fail
            exception = OTSException(exc.errno, error_msg)
            exception.task_id = task_id
            self._publish_exception(task_id, response_queue, exception)
Example #2
0
    def _on_message(self, amqp_message):
        """
        Handler for AMQP messages   
        
        Two types of messages:
        
            1. Indication of state changes on the Task 
            2. Feedback from the Task itself

        State change messages trigger a state transition.
        Everything else fires a signal

        @type amqp_message: amqplib.client_0_8.basic_message.Message 
        @param amqp_message: AMQP message
        """
        msg = unpack_message(amqp_message)
        if isinstance(msg, StateChangeMessage):
            LOGGER.debug("Received state change message %s, task %s "\
                             % (msg.condition, msg.task_id))
            self._task_transition(msg)
        else:
            #The message is data. Relay using a signal
            # If message is monitor message, make received timestamp
            if isinstance(msg, Monitor):
                msg.set_received()
            DTO_SIGNAL.send(sender = "TaskRunner", dto = msg)
Example #3
0
    def _on_message(self, amqp_message):
        """
        Handler for AMQP messages   
        
        Two types of messages:
        
            1. Indication of state changes on the Task 
            2. Feedback from the Task itself

        State change messages trigger a state transition.
        Everything else fires a signal

        @type amqp_message: amqplib.client_0_8.basic_message.Message 
        @param amqp_message: AMQP message
        """
        msg = unpack_message(amqp_message)
        if isinstance(msg, StateChangeMessage):
            LOGGER.debug("Received state change message %s, task %s "\
                             % (msg.condition, msg.task_id))
            self._task_transition(msg)
        else:
            #The message is data. Relay using a signal
            # If message is monitor message, make received timestamp
            if isinstance(msg, Monitor):
                msg.set_received()
            DTO_SIGNAL.send(sender="TaskRunner", dto=msg)
Example #4
0
    def _handle_message(self, message):
        """
        The Message Handler. 
        
        @type message: amqplib.client_0_8.basic_message.Message 
        @param message: A message containing a pickled dictionary

        This turns off the connection on receipt of a message.
        Once the Task has run the connection is reestablished.

        Response Queue is kept informed of the status
        """

        self._stop_consume()
        self.channel.basic_ack(delivery_tag=message.delivery_tag)
        #
        cmd_msg = unpack_message(message)
        task_id = cmd_msg.task_id
        response_queue = cmd_msg.response_queue
        self._set_log_handler(response_queue)
        self._publish_task_state_change(task_id, response_queue)
        #
        try:
            self._dispatch(cmd_msg)
        except CommandFailed, exc:
            error_msg = "Command %s failed" % cmd_msg.command
            self._log.error(error_msg)

            # We need to send pure OTSException because server does not know
            # about ots.common.command.CommandFailed and unpickle will fail
            exception = OTSException(exc.errno, error_msg)
            exception.task_id = task_id
            self._publish_exception(task_id, response_queue, exception)
Example #5
0
    def _is_version_compatible(self, message):
        """
        Is the Worker version compatible

        @type message: amqplib.client_0_8.basic_message.Message 
        @param message: A message containing a pickled dictionary

        @rtype: C{bool}
        @return: Returns True if compatible otherwise false
        """
        ret_val = True
        cmd_msg = unpack_message(message)
        min_worker_version = cmd_msg.min_worker_version

        if min_worker_version is not None:
            version = __VERSION__.split(".", 3)
            major_version = version[0] + "." + version[1]
            self._log.debug("Min version: %s. Worker version: %s" % (min_worker_version, major_version))
            ret_val = float(major_version) >= float(min_worker_version)
        return ret_val
Example #6
0
    def _is_version_compatible(self, message):
        """
        Is the Worker version compatible

        @type message: amqplib.client_0_8.basic_message.Message 
        @param message: A message containing a pickled dictionary

        @rtype: C{bool}
        @return: Returns True if compatible otherwise false
        """
        ret_val = True
        cmd_msg = unpack_message(message)
        min_worker_version = cmd_msg.min_worker_version

        if min_worker_version is not None:
            version = __VERSION__.split(".", 3)
            major_version = version[0] + "." + version[1]
            self._log.debug("Min version: %s. Worker version: %s" %
                            (min_worker_version, major_version))
            ret_val = float(major_version) >= float(min_worker_version)
        return ret_val
Example #7
0
 def cb(message):
     channel.basic_ack(delivery_tag = message.delivery_tag)
     records.append(unpack_message(message))