def notify(engine_id, method, **kwargs): """Send notification to health manager service. Note that the health manager only handles JSON type of parameter passing. :param engine_id: dispatcher to notify; broadcast if value is None :param method: remote method to call """ timeout = cfg.CONF.engine_life_check_timeout client = rpc.get_rpc_client(consts.HEALTH_MANAGER_TOPIC, None) if engine_id: # Notify specific dispatcher identified by engine_id call_context = client.prepare(timeout=timeout, server=engine_id) else: # Broadcast to all disptachers call_context = client.prepare(timeout=timeout) ctx = context.get_admin_context() try: call_context.call(ctx, method, **kwargs) return True except messaging.MessagingTimeout: return False
def test_get_rpc_client_with_serializer(self, mock_target, mock_json_serializer, mock_context_serializer, mock_rpc_client): x_topic = mock.Mock() x_server = mock.Mock() x_target = mock.Mock() x_serializer = mock.Mock() mock_target.return_value = x_target x_context_serializer = mock.Mock() mock_context_serializer.return_value = x_context_serializer x_rpc_client = mock.Mock() mock_rpc_client.return_value = x_rpc_client res = messaging.get_rpc_client(x_topic, x_server, serializer=x_serializer) self.assertEqual(x_rpc_client, res) mock_target.assert_called_once_with( topic=x_topic, server=x_server, version=consts.RPC_API_VERSION_BASE) self.assertEqual(0, mock_json_serializer.call_count) mock_context_serializer.assert_called_once_with(x_serializer) mock_rpc_client.assert_called_once_with( messaging.TRANSPORT, x_target, serializer=x_context_serializer)
def notify(context, method, engine_id, *args, **kwargs): '''Send notification to dispatcher :param context: rpc request context :param method: remote method to call :param engine_id: dispatcher to notify; broadcast if value is None ''' timeout = cfg.CONF.engine_life_check_timeout client = rpc_messaging.get_rpc_client(version=consts.RPC_API_VERSION) if engine_id: # Notify specific dispatcher identified by engine_id call_context = client.prepare( version=consts.RPC_API_VERSION, timeout=timeout, topic=consts.ENGINE_DISPATCHER_TOPIC, server=engine_id) else: # Broadcast to all disptachers call_context = client.prepare( version=consts.RPC_API_VERSION, timeout=timeout, topic=consts.ENGINE_DISPATCHER_TOPIC) try: call_context.call(context, method, *args, **kwargs) return True except oslo_messaging.MessagingTimeout: return False
def notify(method, engine_id=None, **kwargs): '''Send notification to dispatcher :param method: remote method to call :param engine_id: dispatcher to notify; None implies broadcast ''' client = rpc_messaging.get_rpc_client(version=consts.RPC_API_VERSION) if engine_id: # Notify specific dispatcher identified by engine_id call_context = client.prepare( version=consts.RPC_API_VERSION, topic=consts.ENGINE_DISPATCHER_TOPIC, server=engine_id) else: # Broadcast to all disptachers call_context = client.prepare( version=consts.RPC_API_VERSION, topic=consts.ENGINE_DISPATCHER_TOPIC) try: # We don't use ctext parameter in action progress # actually. But since RPCClient.call needs this param, # we use oslo current context here. call_context.call(oslo_context.get_current(), method, **kwargs) return True except oslo_messaging.MessagingTimeout: return False
def notify(method, engine_id=None, **kwargs): """Send notification to dispatcher. Note that dispatcher is an engine internal communication. We are not using versioned object serialization at this level. :param method: remote method to call :param engine_id: dispatcher to notify; None implies broadcast """ client = messaging.get_rpc_client(consts.ENGINE_TOPIC, cfg.CONF.host) if engine_id: # Notify specific dispatcher identified by engine_id call_context = client.prepare(server=engine_id) else: # Broadcast to all disptachers call_context = client.prepare(fanout=True) try: # We don't use ctext parameter in action progress # actually. But since RPCClient.call needs this param, # we use oslo current context here. call_context.cast(oslo_context.get_current(), method, **kwargs) return True except oslo_messaging.MessagingTimeout: return False
def notify(method, engine_id=None, **kwargs): '''Send notification to dispatcher :param method: remote method to call :param engine_id: dispatcher to notify; None implies broadcast ''' client = rpc_messaging.get_rpc_client(version=consts.RPC_API_VERSION) if engine_id: # Notify specific dispatcher identified by engine_id call_context = client.prepare(version=consts.RPC_API_VERSION, topic=consts.ENGINE_DISPATCHER_TOPIC, server=engine_id) else: # Broadcast to all disptachers call_context = client.prepare(version=consts.RPC_API_VERSION, topic=consts.ENGINE_DISPATCHER_TOPIC) try: # We don't use ctext parameter in action progress # actually. But since RPCClient.call needs this param, # we use oslo current context here. call_context.call(oslo_context.get_current(), method, **kwargs) return True except oslo_messaging.MessagingTimeout: return False
def notify(engine_id, method, **kwargs): """Send notification to health manager service. :param engine_id: dispatcher to notify; broadcast if value is None :param method: remote method to call """ timeout = cfg.CONF.engine_life_check_timeout client = rpc_messaging.get_rpc_client(version=consts.RPC_API_VERSION) if engine_id: # Notify specific dispatcher identified by engine_id call_context = client.prepare( version=consts.RPC_API_VERSION, timeout=timeout, topic=consts.ENGINE_HEALTH_MGR_TOPIC, server=engine_id) else: # Broadcast to all disptachers call_context = client.prepare( version=consts.RPC_API_VERSION, timeout=timeout, topic=consts.ENGINE_HEALTH_MGR_TOPIC) ctx = context.get_admin_context() try: call_context.call(ctx, method, **kwargs) return True except oslo_messaging.MessagingTimeout: return False
def __init__(self): if cfg.CONF.rpc_use_object: serializer = object_base.VersionedObjectSerializer() else: serializer = None self._client = messaging.get_rpc_client(consts.ENGINE_TOPIC, cfg.CONF.host, serializer=serializer)
def engine_alive(context, engine_id): client = rpc_messaging.get_rpc_client(version='1.0', topic=engine_id) client_context = client.prepare( timeout=cfg.CONF.engine_life_check_timeout) try: return client_context.call(context, 'listening') except oslo_messaging.MessagingTimeout: return False
def __init__(self): self._client = messaging.get_rpc_client( topic=consts.ENGINE_TOPIC, server=cfg.CONF.host, version=self.BASE_RPC_API_VERSION)
def __init__(self): serializer = object_base.VersionedObjectSerializer() self._client = messaging.get_rpc_client(consts.CONDUCTOR_TOPIC, cfg.CONF.host, serializer=serializer)