示例#1
0
    def invoke_service_rpc(self,
                           service_id,
                           method,
                           kwargs=None,
                           timeout=None,
                           local=False,
                           retry=None):
        """Invoke RPC method on a DSE Service.

        Args:
            service_id: The ID of the data service on which to invoke the call.
            method: The method name to call.
            kwargs: A dict of method arguments.

        Returns:
            The result of the method invocation.

        Raises: MessagingTimeout, RemoteError, MessageDeliveryFailure, NotFound
        """
        target = self.service_rpc_target(
            service_id, server=(self.node_id if local else None))
        LOG.trace("<%s> Preparing to invoking RPC '%s' on %s", self.node_id,
                  method, target)
        client = messaging.RPCClient(self.transport,
                                     target,
                                     timeout=timeout,
                                     retry=retry)
        if not self.is_valid_service(service_id):
            try:
                # First ping the destination to fail fast if unresponsive
                LOG.trace(
                    "<%s> Checking responsiveness before invoking RPC "
                    "'%s' on %s", self.node_id, method, target)
                client.prepare(timeout=cfg.CONF.dse.ping_timeout).call(
                    self.context, 'ping')
            except (messaging_exceptions.MessagingTimeout,
                    messaging_exceptions.MessageDeliveryFailure):
                msg = "service '%s' could not be found"
                raise exception.NotFound(msg % service_id)
        if kwargs is None:
            kwargs = {}
        try:
            LOG.trace("<%s> Invoking RPC '%s' on %s", self.node_id, method,
                      target)
            result = client.call(self.context, method, **kwargs)
        except dispatcher.NoSuchMethod:
            msg = "Method %s not supported for datasource %s"
            LOG.exception(msg, method, service_id)
            raise exception.BadRequest(msg % (method, service_id))
        except (messaging_exceptions.MessagingTimeout,
                messaging_exceptions.MessageDeliveryFailure):
            msg = "Request to service '%s' timed out"
            raise exception.NotFound(msg % service_id)
        LOG.trace("<%s> RPC call returned: %s", self.node_id, result)
        return result
示例#2
0
    def json_ingester_webhook_handler(self, table_name, body):
        def get_exactly_one_jsonpath_match(jsonpath, jsondata,
                                           custom_error_msg):
            jsonpath_expr = parser.parse(jsonpath)
            matches = jsonpath_expr.find(jsondata)
            if len(matches) != 1:
                raise exception.BadRequest(
                    custom_error_msg.format(jsonpath, jsondata))
            return matches[0].value

        try:
            webhook_config = self._config['tables'][table_name]['webhook']
        except KeyError:
            raise exception.NotFound(
                'In JSON Ingester: "{}", the table "{}" either does not exist '
                'or is not configured for webhook.'.format(
                    self.name, table_name))

        json_record = get_exactly_one_jsonpath_match(
            webhook_config['record_jsonpath'], body,
            'In identifying JSON record from webhook body, the configured '
            'jsonpath expression "{}" fails to obtain exactly one match on '
            'webhook body "{}".')
        json_id = get_exactly_one_jsonpath_match(
            webhook_config['id_jsonpath'], json_record,
            'In identifying ID from JSON record, the configured jsonpath '
            'expression "{}" fails to obtain exactly one match on JSON record'
            ' "{}".')
        self._webhook_update_table(table_name, key=json_id, data=json_record)
        self.exec_manager.evaluate_and_execute_actions()
示例#3
0
    def broadcast_service_rpc(self, service_id, method, kwargs=None):
        """Invoke RPC method on all instances of service_id.

        Args:
            service_id: The ID of the data service on which to invoke the call.
            method: The method name to call.
            kwargs: A dict of method arguments.

        Returns:
            None - Methods are invoked asynchronously and results are dropped.

        Raises: RemoteError, MessageDeliveryFailure
        """
        if kwargs is None:
            kwargs = {}
        if not self.is_valid_service(service_id):
            msg = "service '%s' is not a registered service"
            raise exception.NotFound(msg % service_id)

        target = self.service_rpc_target(service_id, fanout=True)
        LOG.trace("<%s> Casting RPC '%s' on %s", self.node_id, method, target)
        client = messaging.RPCClient(self.transport, target)
        client.cast(self.context, method, **kwargs)
示例#4
0
 def get_rule(self, ident):
     for p in self.policy():
         if hasattr(p, 'id') and str(p.id) == str(ident):
             return p
     raise exception.NotFound('rule_id %s  is not found.' % ident)