Просмотр исходного кода

Merged in aznashwan/coriolis-core/rpc-timeouts (pull request #103)

Add RPC timeout configuration options for conductor and worker.
Nashwan Azhari 8 лет назад
Родитель
Сommit
4757b4866b
3 измененных файлов с 36 добавлено и 6 удалено
  1. 14 2
      coriolis/conductor/rpc/client.py
  2. 8 2
      coriolis/rpc.py
  3. 14 2
      coriolis/worker/rpc/client.py

+ 14 - 2
coriolis/conductor/rpc/client.py

@@ -1,17 +1,29 @@
 # Copyright 2016 Cloudbase Solutions Srl
 # All Rights Reserved.
 
+from oslo_config import cfg
 import oslo_messaging as messaging
 
 from coriolis import rpc
 
 VERSION = "1.0"
 
+conductor_opts = [
+    cfg.IntOpt("conductor_rpc_timeout",
+               help="Number of seconds until RPC calls to the "
+                    "conductor timeout.")
+]
+
+CONF = cfg.CONF
+CONF.register_opts(conductor_opts, 'conductor')
+
 
 class ConductorClient(object):
-    def __init__(self):
+    def __init__(self, timeout=None):
         target = messaging.Target(topic='coriolis_conductor', version=VERSION)
-        self._client = rpc.get_client(target)
+        if timeout is None:
+            timeout = CONF.conductor.conductor_rpc_timeout
+        self._client = rpc.get_client(target, timeout=timeout)
 
     def create_endpoint(self, ctxt, name, endpoint_type, description,
                         connection_info):

+ 8 - 2
coriolis/rpc.py

@@ -11,6 +11,9 @@ rpc_opts = [
     cfg.StrOpt('messaging_transport_url',
                default="rabbit://guest:guest@127.0.0.1:5672/",
                help='Messaging transport url'),
+    cfg.IntOpt('default_messaging_timeout',
+               default=60,
+               help='Number of seconds for messaging timeouts.')
 ]
 
 CONF = cfg.CONF
@@ -48,9 +51,12 @@ def _get_transport():
                                    allowed_remote_exmods=ALLOWED_EXMODS)
 
 
-def get_client(target, serializer=None):
+def get_client(target, serializer=None, timeout=None):
     serializer = RequestContextSerializer(serializer)
-    return messaging.RPCClient(_get_transport(), target, serializer=serializer)
+    if timeout is None:
+        timeout = CONF.default_messaging_timeout
+    return messaging.RPCClient(
+        _get_transport(), target, serializer=serializer, timeout=timeout)
 
 
 def get_server(target, endpoints, serializer=None):

+ 14 - 2
coriolis/worker/rpc/client.py

@@ -1,6 +1,7 @@
 # Copyright 2016 Cloudbase Solutions Srl
 # All Rights Reserved.
 
+from oslo_config import cfg
 import oslo_messaging as messaging
 
 from coriolis import rpc
@@ -8,10 +9,21 @@ from coriolis import rpc
 VERSION = "1.0"
 
 
+worker_opts = [
+    cfg.IntOpt("worker_rpc_timeout",
+               help="Number of seconds until RPC calls to the worker timeout.")
+]
+
+CONF = cfg.CONF
+CONF.register_opts(worker_opts, 'worker')
+
+
 class WorkerClient(object):
-    def __init__(self):
+    def __init__(self, timeout=None):
         target = messaging.Target(topic='coriolis_worker', version=VERSION)
-        self._client = rpc.get_client(target)
+        if timeout is None:
+            timeout = CONF.worker.worker_rpc_timeout
+        self._client = rpc.get_client(target, timeout=timeout)
 
     def begin_task(self, ctxt, server, task_id, task_type, origin, destination,
                    instance, task_info):