Example #1
0
    def _dispatch(self, ctxt, message, executor_callback=None):
        """Dispatch an RPC message to the appropriate endpoint method.

        :param ctxt: the request context
        :type ctxt: dict
        :param message: the message payload
        :type message: dict
        """
        ctxt = self.serializer.deserialize_context(ctxt)

        publisher_id = message.get("publisher_id")
        event_type = message.get("event_type")
        metadata = {"message_id": message.get("message_id"), "timestamp": message.get("timestamp")}
        priority = message.get("priority", "").lower()
        if priority not in PRIORITIES:
            LOG.warning('Unknown priority "%s"', priority)
            return

        payload = self.serializer.deserialize_entity(ctxt, message.get("payload"))

        for screen, callback in self._callbacks_by_priority.get(priority, []):
            if screen and not screen.match(ctxt, publisher_id, event_type, metadata, payload):
                continue
            localcontext._set_local_context(ctxt)
            try:
                if executor_callback:
                    ret = executor_callback(callback, ctxt, publisher_id, event_type, payload, metadata)
                else:
                    ret = callback(ctxt, publisher_id, event_type, payload, metadata)
                ret = NotificationResult.HANDLED if ret is None else ret
                if self.allow_requeue and ret == NotificationResult.REQUEUE:
                    return ret
            finally:
                localcontext._clear_local_context()
        return NotificationResult.HANDLED
Example #2
0
 def _exec_callback(self, executor_callback, callback, messages):
     localcontext._set_local_context(messages[0]["ctxt"])
     try:
         return super(NotificationDispatcher, self)._exec_callback(
             executor_callback, callback, messages[0]["ctxt"],
             messages[0]["publisher_id"], messages[0]["event_type"],
             messages[0]["payload"], messages[0]["metadata"])
     finally:
         localcontext._clear_local_context()
Example #3
0
 def _exec_callback(self, callback, messages):
     localcontext._set_local_context(
         messages[0]["ctxt"])
     try:
         return super(NotificationDispatcher, self)._exec_callback(
             callback,
             messages[0]["ctxt"],
             messages[0]["publisher_id"],
             messages[0]["event_type"],
             messages[0]["payload"],
             messages[0]["metadata"])
     finally:
         localcontext._clear_local_context()
Example #4
0
    def _exec_callback(self, callback, message):
        localcontext._set_local_context(message["ctxt"])

        try:
            return callback(message["ctxt"],
                            message["publisher_id"],
                            message["event_type"],
                            message["payload"],
                            message["metadata"])
        except Exception:
            LOG.exception("Callback raised an exception.")
            return NotificationResult.REQUEUE
        finally:
            localcontext._clear_local_context()
Example #5
0
    def _dispatch(self, ctxt, message, executor_callback=None):
        """Dispatch an RPC message to the appropriate endpoint method.

        :param ctxt: the request context
        :type ctxt: dict
        :param message: the message payload
        :type message: dict
        """
        ctxt = self.serializer.deserialize_context(ctxt)

        publisher_id = message.get('publisher_id')
        event_type = message.get('event_type')
        metadata = {
            'message_id': message.get('message_id'),
            'timestamp': message.get('timestamp')
        }
        priority = message.get('priority', '').lower()
        if priority not in PRIORITIES:
            LOG.warning('Unknown priority "%s"', priority)
            return

        payload = self.serializer.deserialize_entity(ctxt,
                                                     message.get('payload'))

        for screen, callback in self._callbacks_by_priority.get(priority, []):
            if screen and not screen.match(ctxt, publisher_id, event_type,
                                           metadata, payload):
                continue
            localcontext._set_local_context(ctxt)
            try:
                if executor_callback:
                    ret = executor_callback(callback, ctxt, publisher_id,
                                            event_type, payload, metadata)
                else:
                    ret = callback(ctxt, publisher_id, event_type, payload,
                                   metadata)
                ret = NotificationResult.HANDLED if ret is None else ret
                if self.allow_requeue and ret == NotificationResult.REQUEUE:
                    return ret
            finally:
                localcontext._clear_local_context()
        return NotificationResult.HANDLED
Example #6
0
    def _dispatch(self, ctxt, message, executor_callback=None):
        """Dispatch an RPC message to the appropriate endpoint method.

        :param ctxt: the request context
        :type ctxt: dict
        :param message: the message payload
        :type message: dict
        :raises: NoSuchMethod, UnsupportedVersion
        """
        method = message.get('method')
        args = message.get('args', {})
        namespace = message.get('namespace')
        version = message.get('version', '1.0')

        found_compatible = False
        for endpoint in self.endpoints:
            target = getattr(endpoint, 'target', None)
            if not target:
                target = self._default_target

            if not (self._is_namespace(target, namespace)
                    and self._is_compatible(target, version)):
                continue

            if hasattr(endpoint, method):
                localcontext._set_local_context(ctxt)
                try:
                    return self._do_dispatch(endpoint, method, ctxt, args,
                                             executor_callback)
                finally:
                    localcontext._clear_local_context()

            found_compatible = True

        if found_compatible:
            raise NoSuchMethod(method)
        else:
            raise UnsupportedVersion(version, method=method)
    def _dispatch(self, ctxt, message, executor_callback=None):
        """Dispatch an RPC message to the appropriate endpoint method.

        :param ctxt: the request context
        :type ctxt: dict
        :param message: the message payload
        :type message: dict
        :raises: NoSuchMethod, UnsupportedVersion
        """
        method = message.get('method')
        args = message.get('args', {})
        namespace = message.get('namespace')
        version = message.get('version', '1.0')

        found_compatible = False
        for endpoint in self.endpoints:
            target = getattr(endpoint, 'target', None)
            if not target:
                target = self._default_target

            if not (self._is_namespace(target, namespace) and
                    self._is_compatible(target, version)):
                continue

            if hasattr(endpoint, method):
                localcontext._set_local_context(ctxt)
                try:
                    return self._do_dispatch(endpoint, method, ctxt, args,
                                             executor_callback)
                finally:
                    localcontext._clear_local_context()

            found_compatible = True

        if found_compatible:
            raise NoSuchMethod(method)
        else:
            raise UnsupportedVersion(version, method=method)
    def dispatch(self, incoming):
        """Dispatch an RPC message to the appropriate endpoint method.

        :param incoming: incoming message
        :type incoming: IncomingMessage
        :raises: NoSuchMethod, UnsupportedVersion
        """
        message = incoming.message
        ctxt = incoming.ctxt

        method = message.get('method')
        args = message.get('args', {})
        namespace = message.get('namespace')
        version = message.get('version', '1.0')

        found_compatible = False
        for endpoint in self.endpoints:
            target = getattr(endpoint, 'target', None)
            if not target:
                target = self._default_target

            if not (self._is_namespace(target, namespace) and
                    self._is_compatible(target, version)):
                continue

            if hasattr(endpoint, method):
                localcontext._set_local_context(ctxt)
                try:
                    return self._do_dispatch(endpoint, method, ctxt, args)
                finally:
                    localcontext._clear_local_context()

            found_compatible = True

        if found_compatible:
            raise NoSuchMethod(method)
        else:
            raise UnsupportedVersion(version, method=method)
Example #9
0
    def dispatch(self, incoming):
        """Dispatch an RPC message to the appropriate endpoint method.

        :param incoming: incoming message
        :type incoming: IncomingMessage
        :raises: NoSuchMethod, UnsupportedVersion
        """
        message = incoming.message
        ctxt = incoming.ctxt

        method = message.get('method')
        args = message.get('args', {})
        namespace = message.get('namespace')
        version = message.get('version', '1.0')

        found_compatible = False
        for endpoint in self.endpoints:
            target = getattr(endpoint, 'target', None)
            if not target:
                target = self._default_target

            if not (self._is_namespace(target, namespace)
                    and self._is_compatible(target, version)):
                continue

            if hasattr(endpoint, method):
                localcontext._set_local_context(ctxt)
                try:
                    return self._do_dispatch(endpoint, method, ctxt, args)
                finally:
                    localcontext._clear_local_context()

            found_compatible = True

        if found_compatible:
            raise NoSuchMethod(method)
        else:
            raise UnsupportedVersion(version, method=method)