コード例 #1
0
    def test_call_fanout(self):
        transport = _FakeTransport(self.conf)
        client = oslo_messaging.RPCClient(transport,
                                          oslo_messaging.Target(**self.target))

        if self.prepare is not _notset:
            client = client.prepare(**self.prepare)

        self.assertRaises(exceptions.InvalidTarget,
                          client.call, {}, 'foo')
コード例 #2
0
 def conductor_client(self):
     if self._conductor_client is None:
         target = om.Target(
             topic=self.conductor_topic,
             version=self.API_VERSION,
         )
         self._conductor_client = om.RPCClient(self.transport,
                                               target,
                                               serializer=self.serializer)
     return self._conductor_client
コード例 #3
0
ファイル: driver.py プロジェクト: ytsai-a10/a10-octavia
 def __init__(self):
     super(A10ProviderDriver, self).__init__()
     self._args = {}
     self.transport = messaging.get_rpc_transport(cfg.CONF)
     self._args['fanout'] = False
     self._args['namespace'] = constants.RPC_NAMESPACE_CONTROLLER_AGENT
     self._args['topic'] = "a10_octavia"
     self._args['version'] = '1.0'
     self.target = messaging.Target(**self._args)
     self.client = messaging.RPCClient(self.transport, target=self.target)
コード例 #4
0
 def test_invalid_version_type(self):
     target = oslo_messaging.Target(topic='sometopic')
     transport = _FakeTransport(self.conf)
     client = oslo_messaging.RPCClient(transport, target)
     self.assertRaises(exceptions.MessagingException,
                       client.prepare, version='5')
     self.assertRaises(exceptions.MessagingException,
                       client.prepare, version='5.a')
     self.assertRaises(exceptions.MessagingException,
                       client.prepare, version='5.5.a')
コード例 #5
0
 def client(self, context):
     transport = context.mq_connection
     if transport:
         cmt = self.default_client.call_monitor_timeout
         return messaging.RPCClient(transport, self.target,
                                    version_cap=self.version_cap,
                                    serializer=self.serializer,
                                    call_monitor_timeout=cmt)
     else:
         return self.default_client
コード例 #6
0
    def invoke_service_rpc(self,
                           service_id,
                           method,
                           kwargs=None,
                           timeout=None,
                           local=False,
                           retry=None):
        """Invoke RPC method on a DSE Service.

        :param: service_id: The ID of the data service on which to invoke the
            call.
        :param: method: The method name to call.
        :param: 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.RpcTargetNotFound(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.Unavailable(msg % service_id)
        LOG.trace("<%s> RPC call returned: %s", self.node_id, result)
        return result
コード例 #7
0
 def call(self, topic, server, api_name, timeout=2, retry=0, **api_kwargs):
     target = oslo_messaging.Target(
         topic=topic,
         server=server,
         version=self.broker_endpoint.Version,
         namespace=self.broker_endpoint.Namespace)
     queryclient = oslo_messaging.RPCClient(self.transport,
                                            target,
                                            timeout=timeout,
                                            retry=retry)
     return queryclient.call({}, api_name, **api_kwargs)
コード例 #8
0
ファイル: rpc.py プロジェクト: stackhpc/magnum
def get_client(target, version_cap=None, serializer=None, timeout=None):
    assert TRANSPORT is not None
    if profiler:
        serializer = ProfilerRequestContextSerializer(serializer)
    else:
        serializer = RequestContextSerializer(serializer)
    return messaging.RPCClient(TRANSPORT,
                               target,
                               version_cap=version_cap,
                               serializer=serializer,
                               timeout=timeout)
コード例 #9
0
ファイル: rpc.py プロジェクト: eilatc/vitrage
def get_client(transport, target, version_cap=None, serializer=None):
    assert transport is not None

    if profiler:
        LOG.info('profiler enabled for RPC client')
        serializer = ProfilerContextSerializer(serializer=serializer)

    return messaging.RPCClient(transport,
                               target,
                               version_cap=version_cap,
                               serializer=serializer)
コード例 #10
0
 def cast(self, topic, api_name, timeout=None, retry=None, **api_kwargs):
     target = oslo_messaging.Target(
         topic=topic,
         fanout=True,
         version=self.broker_endpoint.Version,
         namespace=self.broker_endpoint.Namespace)
     queryclient = oslo_messaging.RPCClient(self.transport,
                                            target,
                                            timeout=timeout,
                                            retry=retry)
     queryclient.cast({}, api_name, **api_kwargs)
コード例 #11
0
    def __init__(self, conf):
        super(OsloRPCClient, self).__init__(conf)
        self.topic = conf.topic

        serializer = auth_ctx.RpcContextSerializer()

        self._client = messaging.RPCClient(
            rpc.get_transport(),
            messaging.Target(topic=self.topic),
            serializer=serializer
        )
コード例 #12
0
ファイル: yarma.py プロジェクト: Itxaka/yarma
 def __init__(self, transport):
     super(YarmaPublisherService, self).__init__()
     self.publisher_target = messaging.Target(
         topic=cfg.CONF.default.publisher_queue,
     )
     self.transport = transport
     self.server = messaging.RPCClient(
         self.transport,
         self.publisher_target,
         serializer=messaging.JsonPayloadSerializer()
     )
コード例 #13
0
ファイル: service.py プロジェクト: maniacs-ops/solum
 def __init__(self, transport=None, context=None, topic=None):
     serializer = RequestContextSerializer(JsonPayloadSerializer())
     if transport is None:
         transport = messaging.get_transport(cfg.CONF)
     self._context = context
     if topic is None:
         topic = ''
     target = messaging.Target(topic=topic)
     self._client = messaging.RPCClient(transport,
                                        target,
                                        serializer=serializer)
コード例 #14
0
ファイル: driver.py プロジェクト: phonglh79/octavia
 def __init__(self):
     super(AmphoraProviderDriver, self).__init__()
     topic = cfg.CONF.oslo_messaging.topic
     self.transport = messaging.get_rpc_transport(cfg.CONF)
     self.target = messaging.Target(
         namespace=consts.RPC_NAMESPACE_CONTROLLER_AGENT,
         topic=topic,
         version="1.0",
         fanout=False)
     self.client = messaging.RPCClient(self.transport, target=self.target)
     self.repositories = repositories.Repositories()
コード例 #15
0
ファイル: amphora.py プロジェクト: BoTranVan/octavia
 def __init__(self, amp_id):
     super(FailoverController, self).__init__()
     topic = cfg.CONF.oslo_messaging.topic
     self.transport = messaging.get_rpc_transport(cfg.CONF)
     self.target = messaging.Target(
         namespace=constants.RPC_NAMESPACE_CONTROLLER_AGENT,
         topic=topic,
         version="1.0",
         fanout=False)
     self.client = messaging.RPCClient(self.transport, target=self.target)
     self.amp_id = amp_id
コード例 #16
0
ファイル: rpc.py プロジェクト: tucows/designate
def get_client(target, version_cap=None, serializer=None):
    if TRANSPORT is None:
        raise AssertionError("'TRANSPORT' must not be None")
    if serializer is None:
        serializer = DesignateObjectSerializer()
    serializer = RequestContextSerializer(serializer)
    return messaging.RPCClient(
        TRANSPORT,
        target,
        version_cap=version_cap,
        serializer=serializer
    )
コード例 #17
0
ファイル: rpc.py プロジェクト: yochow/nova
def get_cell_client(context, default_client):
    """Get a RPCClient object based on a RequestContext.

    :param context: The RequestContext that can contain a Transport
    :param default_client: The default RPCClient
    """
    if context.mq_connection:
        return messaging.RPCClient(context.mq_connection,
                                   default_client.target,
                                   version_cap=default_client.version_cap,
                                   serializer=default_client.serializer)
    return default_client
コード例 #18
0
ファイル: rpc.py プロジェクト: rocky11030/mistral
    def __init__(self, transport):
        """Constructs an RPC client for engine.

        :param transport: Messaging transport.
        """
        serializer = auth_ctx.RpcContextSerializer(
            auth_ctx.JsonPayloadSerializer())

        self._client = messaging.RPCClient(
            transport,
            messaging.Target(topic=cfg.CONF.engine.topic),
            serializer=serializer)
コード例 #19
0
 def __init__(self, transport_url, fake_server=False):
     if not fake_server:
         transport = messaging.get_transport(
             cfg.CONF, transport_url, allowed_remote_exmods=ALLOWED_EXMODS)
     else:
         from . import rpc
         fake_rpc_server = rpc.start_fake_server()
         transport = fake_rpc_server.transport
     target = messaging.Target(topic=self.topic, namespace=self.namespace,
                               version=self.version)
     self.client = messaging.RPCClient(transport, target,
                                       serializer=RPCSerializer())
コード例 #20
0
    def __init__(self):
        """Initialize the driver plugin RPC client."""
        self.environment_prefix = 'Project'
        self.topic = '%s_%s' % (f5_const.TOPIC_PROCESS_ON_HOST_V2,
                                self.environment_prefix)

        messaging.set_transport_defaults('neutron')
        self.transport = messaging.get_transport(
            CONF, url=CONF.f5_lbaasv2_driver.transport_url)
        self.target = messaging.Target(topic=self.topic)
        self.client = messaging.RPCClient(self.transport, self.target)
        self.context = context.get_admin_context().to_dict()
コード例 #21
0
    def test_call_serializer(self):
        self.config(rpc_response_timeout=None)

        transport = oslo_messaging.get_rpc_transport(self.conf, url='fake:')
        serializer = msg_serializer.NoOpSerializer()

        client = oslo_messaging.RPCClient(transport,
                                          oslo_messaging.Target(),
                                          serializer=serializer)

        transport._send = mock.Mock()
        kwargs = dict(wait_for_reply=True, timeout=None) if self.call else {}
        kwargs['retry'] = None
        if self.call:
            kwargs['call_monitor_timeout'] = None

        transport._send.return_value = self.retval

        serializer.serialize_entity = mock.Mock()
        serializer.deserialize_entity = mock.Mock()
        serializer.serialize_context = mock.Mock()

        def _stub(ctxt, arg):
            return 's' + arg

        msg = dict(method='foo', args=dict())
        for k, v in self.args.items():
            msg['args'][k] = 's' + v
        serializer.serialize_entity.side_effect = _stub

        if self.call:
            serializer.deserialize_entity.return_value = 'd' + self.retval

        serializer.serialize_context.return_value = dict(user='******')

        method = client.call if self.call else client.cast
        retval = method(self.ctxt, 'foo', **self.args)
        if self.retval is not None:
            self.assertEqual('d' + self.retval, retval)

        transport._send.assert_called_once_with(oslo_messaging.Target(),
                                                dict(user='******'),
                                                msg,
                                                transport_options=None,
                                                **kwargs)
        expected_calls = [mock.call(self.ctxt, arg) for arg in self.args]
        self.assertEqual(expected_calls,
                         serializer.serialize_entity.mock_calls)
        if self.call:
            serializer.deserialize_entity.assert_called_once_with(
                self.ctxt, self.retval)
        serializer.serialize_context.assert_called_once_with(self.ctxt)
コード例 #22
0
    def __init__(self):
        target = messaging.Target(topic=self.TOPIC,
                                  version=self.RPC_API_VERSION)
        #obj_version_cap = self._determine_obj_version_cap()
        #serializer = base.WaterfallObjectSerializer(obj_version_cap)

        #rpc_version_cap = self._determine_rpc_version_cap()
        #self.client = get_client(target, version_cap=rpc_version_cap,
        #                         serializer=serializer)
        #serializer = RequestContextSerializer(serializer)
        self.client = messaging.RPCClient(TRANSPORT,
                                          target,
                                          version_cap='2.0')
コード例 #23
0
ファイル: utils.py プロジェクト: mark-xiett/oslo.messaging
 def setUp(self):
     super(RpcServerFixture, self).setUp()
     endpoints = [self.endpoint, self]
     transport = self.useFixture(TransportFixture(self.conf, self.url))
     self.server = oslo_messaging.get_rpc_server(
         transport=transport.transport,
         target=self.target,
         endpoints=endpoints,
         executor=self.executor)
     self._ctrl = oslo_messaging.RPCClient(transport.transport,
                                           self.ctrl_target)
     self._start()
     transport.wait()
コード例 #24
0
 def __init__(self, transport=None, context=None, topic=None, server=None,
              timeout=None):
     serializer = _init_serializer()
     if transport is None:
         exmods = rpc.get_allowed_exmods()
         transport = messaging.get_rpc_transport(
             CONF, allowed_remote_exmods=exmods)
     self._context = context
     if topic is None:
         topic = ''
     target = messaging.Target(topic=topic, server=server)
     self._client = messaging.RPCClient(transport, target,
                                        serializer=serializer,
                                        timeout=timeout)
コード例 #25
0
 def __init__(self):
     topic = cfg.CONF.oslo_messaging.event_stream_topic
     if cfg.CONF.oslo_messaging.event_stream_transport_url:
         # Use custom URL
         self.transport = oslo_messaging.get_rpc_transport(
             cfg.CONF, cfg.CONF.oslo_messaging.event_stream_transport_url)
     else:
         self.transport = oslo_messaging.get_rpc_transport(cfg.CONF)
     self.target = oslo_messaging.Target(topic=topic,
                                         exchange="common",
                                         namespace='control',
                                         fanout=False,
                                         version='1.0')
     self.client = oslo_messaging.RPCClient(self.transport, self.target)
コード例 #26
0
def create_client(component_name):
    topic = topics.CASCADING_SERVICE
    target = oslo_messaging.Target(
        exchange="tricircle",
        topic=topic,
        namespace=component_name,
        version='1.0',
    )

    return oslo_messaging.RPCClient(
        TRANSPORT,
        target,
        serializer=Serializer(),
    )
コード例 #27
0
ファイル: client.py プロジェクト: lk668/openstack_oslo
 def __init__(self):
     """
     RPC mode has two function for sending message
     1.cast(ctxt, method, **kwargs): Do not have return value
     2.call(ctxt, method, **kwargs): Have return value
     :param ctxt: (dict) A request context dict
     :param method: (str) The remote method
     :param **kwargs: (dict) The params of the remote method
     """
     super(RPCClient, self).__init__()
     self.transport = oslo_messaging.get_transport(cfg.CONF)
     self.target = oslo_messaging.Target(topic=self.topic, exchange='common',
             namespace='control', fanout=False, version='1.0')
     self.client = oslo_messaging.RPCClient(self.transport, self.target)
コード例 #28
0
ファイル: utils.py プロジェクト: yungjinzhou/oslo.messaging
 def __init__(self,
              transport,
              target,
              cast=False,
              name=None,
              transport_options=None,
              **kwargs):
     self.name = name or "functional-tests"
     self.cast = cast
     self.client = oslo_messaging.RPCClient(
         transport=transport,
         target=target,
         transport_options=transport_options,
         **kwargs)
コード例 #29
0
def get_client(topic=None):
    """Get a RPC client instance.

    :param topic: The topic of the message will be delivered to. This argument
                  is ignored if CONF.standalone is True.
    """
    assert TRANSPORT is not None
    if CONF.standalone:
        target = messaging.Target(topic=manager.MANAGER_TOPIC,
                                  server=CONF.host,
                                  version='1.3')
    else:
        target = messaging.Target(topic=topic, version='1.3')
    return messaging.RPCClient(TRANSPORT, target)
コード例 #30
0
def saygood():
    try:
            transport_url = 'rabbit://*****:*****@10.0.0.108:5672/'  
	    #transport_url = 'rabbit://*****:*****@10.1.101.36:5672/'  
	    transport = oslo_messaging.get_transport(cfg.CONF,transport_url)  
	    #mac = request.args.get("mac")
	    mac = request.json.get("mac")
	    #mac = request.form["mac"]
	    target = oslo_messaging.Target(topic='test', server=getCid(mac))  
	    client = oslo_messaging.RPCClient(transport, target)  
	    r = client.prepare(timeout=2).call({}, 'sayGood')  
    except:
        return ("error", 400)
    else:
        return 'success'