Ejemplo n.º 1
0
    def call(self, ctxt, method, **kwargs):
        """Invoke a method and wait for a reply. See RPCClient.call()."""
        if self.target.fanout:
            raise exceptions.InvalidTarget('A call cannot be used with fanout',
                                           self.target)

        msg = self._make_message(ctxt, method, kwargs)
        msg_ctxt = self.serializer.serialize_context(ctxt)

        span_host = tomograph.getHost()

        ser_name = "%s[%s]" % ("RPC_call", self.target.topic)
        tomograph.start(ser_name, self.target.topic, span_host, 0)
        trace_info = tomograph.get_trace_info()
        msg_ctxt["trace_id"] = trace_info[0]
        msg_ctxt["span_id"] = trace_info[1]

        timeout = self.timeout
        if self.timeout is None:
            timeout = self.conf.rpc_response_timeout

        if self.version_cap:
            self._check_version_cap(msg.get('version'))

        try:
            result = self.transport._send(self.target, msg_ctxt, msg,
                                          wait_for_reply=True, timeout=timeout,
                                          retry=self.retry)

            tomograph.stop(self.target.topic)
        except driver_base.TransportDriverError as ex:
            raise ClientSendError(self.target, ex)
        return self.serializer.deserialize_entity(ctxt, result)
Ejemplo n.º 2
0
    def call(self, ctxt, method, **kwargs):
        """Invoke a method and wait for a reply. See RPCClient.call()."""
        if self.target.fanout:
            raise exceptions.InvalidTarget('A call cannot be used with fanout',
                                           self.target)

        msg = self._make_message(ctxt, method, kwargs)
        msg_ctxt = self.serializer.serialize_context(ctxt)

        timeout = self.timeout
        if self.timeout is None:
            timeout = self.conf.rpc_response_timeout

        cm_timeout = self.call_monitor_timeout

        self._check_version_cap(msg.get('version'))

        try:
            result = \
                self.transport._send(self.target, msg_ctxt, msg,
                                     wait_for_reply=True, timeout=timeout,
                                     call_monitor_timeout=cm_timeout,
                                     retry=self.retry,
                                     transport_options=self.transport_options)
        except driver_base.TransportDriverError as ex:
            raise ClientSendError(self.target, ex)

        return self.serializer.deserialize_entity(ctxt, result)
Ejemplo n.º 3
0
 def _listen(self, target, on_incoming_callback, batch_size, batch_timeout):
     if not (target.topic and target.server):
         raise exceptions.InvalidTarget('A server\'s target must have '
                                        'topic and server names specified',
                                        target)
     return self._driver.listen(target, on_incoming_callback, batch_size,
                                batch_timeout)
Ejemplo n.º 4
0
 def _send(self, target, ctxt, message, wait_for_reply=None, timeout=None,
           retry=None):
     if not target.topic:
         raise exceptions.InvalidTarget('A topic is required to send',
                                        target)
     return self._driver.send(target, ctxt, message,
                              wait_for_reply=wait_for_reply,
                              timeout=timeout, retry=retry)
Ejemplo n.º 5
0
 def _listen_for_notifications(self, targets_and_priorities, pool):
     for target, priority in targets_and_priorities:
         if not target.topic:
             raise exceptions.InvalidTarget(
                 'A target must have '
                 'topic specified', target)
     return self._driver.listen_for_notifications(targets_and_priorities,
                                                  pool)
Ejemplo n.º 6
0
 def _send_notification(self, target, ctxt, message, version, retry=None):
     if not target.topic:
         raise exceptions.InvalidTarget('A topic is required to send',
                                        target)
     self._driver.send_notification(target,
                                    ctxt,
                                    message,
                                    version,
                                    retry=retry)
Ejemplo n.º 7
0
 def _listen_for_notifications(self, targets_and_priorities, pool,
                               on_incoming_callback, batch_size,
                               batch_timeout):
     for target, priority in targets_and_priorities:
         if not target.topic:
             raise exceptions.InvalidTarget('A target must have '
                                            'topic specified',
                                            target)
     return self._driver.listen_for_notifications(
         targets_and_priorities, pool, on_incoming_callback, batch_size,
         batch_timeout
     )
Ejemplo n.º 8
0
    def call(self, ctxt, method, **kwargs):
        """Invoke a method and wait for a reply. See RPCClient.call()."""
        if self.target.fanout:
            raise exceptions.InvalidTarget('A call cannot be used with fanout',
                                           self.target)

        msg = self._make_message(ctxt, method, kwargs)
        msg_ctxt = self.serializer.serialize_context(ctxt)

        timeout = self.timeout
        if self.timeout is None:
            timeout = self.conf.rpc_response_timeout

        cm_timeout = self.call_monitor_timeout

        self._check_version_cap(msg.get('version'))

        with metrics.get_collector(self.conf,
                                   "rpc_client",
                                   target=self.target,
                                   method=method,
                                   call_type="call") as metrics_collector:
            try:
                result = self.transport._send(
                    self.target,
                    msg_ctxt,
                    msg,
                    wait_for_reply=True,
                    timeout=timeout,
                    call_monitor_timeout=cm_timeout,
                    retry=self.retry,
                    transport_options=self.transport_options)
            except driver_base.TransportDriverError as ex:
                self._metrics_api.rpc_client_exception_total(
                    self.target, method, "call", ex.__class__.__name__)
                raise ClientSendError(self.target, ex)
            except Exception as ex:
                if self.conf.oslo_messaging_metrics.metrics_enabled:
                    metrics_collector.rpc_client_exception_total(
                        self.target, method, "call", ex.__class__.__name__)
                raise
            return self.serializer.deserialize_entity(ctxt, result)
Ejemplo n.º 9
0
 def _listen(self, target):
     if not (target.topic and target.server):
         raise exceptions.InvalidTarget(
             'A server\'s target must have '
             'topic and server names specified', target)
     return self._driver.listen(target)