aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wick...@apache.org
Subject git commit: ZookeeperSchedulerClient url property errored when no proxy_url was set, and the client was not connected.
Date Mon, 06 Jan 2014 18:15:10 GMT
Updated Branches:
  refs/heads/master d0b46fc3b -> 704939645


ZookeeperSchedulerClient url property errored when no proxy_url was set, and the client was
not connected.

Squashed commit of the following:

commit 964335686e57b079f28466de502fbebedd5e360c
Merge: d0b46fc 513876c
Author: Brian Wickman <wickman@twitter.com>
Date:   Mon Jan 6 10:11:19 2014 -0800

    Merge 69f4b79e4054b85b36490c04fb569e3f752dca6f to post-rename master.

commit 513876cfce07b005ef6a10ea39480bf181b7dd9b
Author: Joshua Cohen <jcohen@twitter.com>
Date:   Mon Jan 6 10:08:22 2014 -0800

    ZookeeperSchedulerClient url property errored when no proxy_url was set, and the client
was not connected.

    commit 69f4b79e4054b85b36490c04fb569e3f752dca6f
    Author: Joshua Cohen <jcohen@twitter.com>
    Date:   Mon Dec 9 18:09:22 2013 -0600

        ZookeeperSchedulerClient url property errored when no proxy_url was set, and the client
was not connected.

     .../twitter/aurora/client/api/scheduler_client.py  |  3 ++
     .../aurora/client/api/test_scheduler_client.py     | 56 ++++++++++++++++++++++
     2 files changed, 59 insertions(+)

    The original failure is:

      File "twitter/aurora/client/api/scheduler_client.py", line 138, in url
        if self._http:
      AttributeError: 'ZookeeperSchedulerClient' object has no attribute '_http'

    The fix presented here is to implicitly connect if we're not connected though I'm not
sure if this is the desired behavior. The alternative would be to gracefully fail if cluster.proxy_url
is not set and self._http is None, then leave it up to the caller to decide whether or not
to connect. Connecting is generally implicit today though, so I went this way (though connecting
as a result of trying to access the scheduler url may be unexpected).

    Testing Done:
    Added unit test, ./pants src/test/python/twitter/aurora/client:all

    Bugs closed: AURORA-6

    Reviewed at https://reviews.apache.org/r/16144/


Project: http://git-wip-us.apache.org/repos/asf/incubator-aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-aurora/commit/70493964
Tree: http://git-wip-us.apache.org/repos/asf/incubator-aurora/tree/70493964
Diff: http://git-wip-us.apache.org/repos/asf/incubator-aurora/diff/70493964

Branch: refs/heads/master
Commit: 70493964577b4e43aa5927d658957141478c7692
Parents: d0b46fc
Author: Brian Wickman <wickman@twitter.com>
Authored: Mon Jan 6 10:13:02 2014 -0800
Committer: Brian Wickman <wickman@twitter.com>
Committed: Mon Jan 6 10:13:02 2014 -0800

----------------------------------------------------------------------
 .../aurora/client/api/scheduler_client.py       |  3 ++
 .../aurora/client/api/test_scheduler_client.py  | 56 ++++++++++++++++++++
 2 files changed, 59 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/70493964/src/main/python/apache/aurora/client/api/scheduler_client.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/api/scheduler_client.py b/src/main/python/apache/aurora/client/api/scheduler_client.py
index 1b38f7b..fb65aee 100644
--- a/src/main/python/apache/aurora/client/api/scheduler_client.py
+++ b/src/main/python/apache/aurora/client/api/scheduler_client.py
@@ -111,6 +111,7 @@ class ZookeeperSchedulerClient(SchedulerClient):
     self._cluster = cluster
     self._zkport = port
     self._endpoint = None
+    self._http = None
 
   def _connect(self):
     joined = threading.Event()
@@ -133,6 +134,8 @@ class ZookeeperSchedulerClient(SchedulerClient):
     proxy_url = self._cluster.proxy_url
     if proxy_url:
       return proxy_url
+    if self._http is None:
+      self._connect()
     if self._http:
       return 'http://%s:%s' % (self._http.host, self._http.port)
 

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/70493964/src/test/python/apache/aurora/client/api/test_scheduler_client.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/api/test_scheduler_client.py b/src/test/python/apache/aurora/client/api/test_scheduler_client.py
index 339ad9f..f3023d9 100644
--- a/src/test/python/apache/aurora/client/api/test_scheduler_client.py
+++ b/src/test/python/apache/aurora/client/api/test_scheduler_client.py
@@ -1,7 +1,11 @@
 import inspect
 import unittest
 
+from apache.aurora.common.cluster import Cluster
 import apache.aurora.client.api.scheduler_client as scheduler_client
+from twitter.common.quantity import Amount, Time
+from twitter.common.zookeeper.kazoo_client import TwitterKazooClient
+from twitter.common.zookeeper.serverset.endpoint import ServiceInstance
 
 import gen.apache.aurora.AuroraAdmin as AuroraAdmin
 import gen.apache.aurora.AuroraSchedulerManager as AuroraSchedulerManager
@@ -258,3 +262,55 @@ class TestSchedulerProxyAdminInjection(TestSchedulerProxyInjection):
     self.mox.ReplayAll()
 
     self.make_scheduler_proxy().rewriteConfigs(RewriteConfigsRequest())
+
+
+class TestZookeeperSchedulerClient(unittest.TestCase):
+  def setUp(self):
+    self.mox = Mox()
+
+  def tearDown(self):
+    self.mox.UnsetStubs()
+    self.mox.VerifyAll()
+
+  def test_url_when_not_connected_and_cluster_has_no_proxy_url(self):
+    host = 'some-host.example.com'
+    port = 31181
+
+    mock_zk = self.mox.CreateMock(TwitterKazooClient)
+
+    def mock_get_serverset(*args, **kwargs):
+      service_json = '''{
+        "additionalEndpoints": {
+            "http": {
+                "host": "%s",
+                "port": %d
+            }
+        },
+        "serviceEndpoint": {
+            "host": "%s",
+            "port": %d
+        },
+        "shard": 0,
+        "status": "ALIVE"
+    }''' % (host, port, host, port)
+
+      return mock_zk, [ServiceInstance.unpack(service_json)]
+
+    class TestZookeeperSchedulerClient(scheduler_client.ZookeeperSchedulerClient):
+      SERVERSET_TIMEOUT = Amount(10, Time.MILLISECONDS)
+
+    original_method = TestZookeeperSchedulerClient.get_scheduler_serverset
+
+    try:
+      TestZookeeperSchedulerClient.get_scheduler_serverset = mock_get_serverset
+
+      zk_scheduler_client = TestZookeeperSchedulerClient(Cluster(proxy_url=None))
+      self.mox.StubOutWithMock(zk_scheduler_client, '_connect_scheduler')
+      mock_zk.stop()
+      zk_scheduler_client._connect_scheduler(host, port, False)
+
+      self.mox.ReplayAll()
+
+      assert zk_scheduler_client.url == 'http://%s:%d' % (host, port)
+    finally:
+      TestZookeeperSchedulerClient.get_scheduler_serverset = original_method


Mime
View raw message