You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aurora.apache.org by ma...@apache.org on 2014/09/12 20:37:34 UTC
git commit: Adding "get_scheduler" admin command.
Repository: incubator-aurora
Updated Branches:
refs/heads/master 3c5dd76f3 -> e42f4f046
Adding "get_scheduler" admin command.
Bugs closed: AURORA-692
Reviewed at https://reviews.apache.org/r/25519/
Project: http://git-wip-us.apache.org/repos/asf/incubator-aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-aurora/commit/e42f4f04
Tree: http://git-wip-us.apache.org/repos/asf/incubator-aurora/tree/e42f4f04
Diff: http://git-wip-us.apache.org/repos/asf/incubator-aurora/diff/e42f4f04
Branch: refs/heads/master
Commit: e42f4f0469f10dd02c24fcb373b56a120394e90e
Parents: 3c5dd76
Author: Maxim Khutornenko <ma...@apache.org>
Authored: Fri Sep 12 11:37:10 2014 -0700
Committer: Maxim Khutornenko <ma...@apache.org>
Committed: Fri Sep 12 11:37:10 2014 -0700
----------------------------------------------------------------------
.../aurora/client/api/scheduler_client.py | 8 +++
.../apache/aurora/client/commands/admin.py | 13 +++++
.../aurora/client/api/test_scheduler_client.py | 2 +
.../apache/aurora/client/commands/test_admin.py | 54 ++++++++++++--------
.../apache/aurora/client/commands/util.py | 6 +++
.../sh/org/apache/aurora/e2e/test_end_to_end.sh | 16 ++++++
.../org/apache/aurora/e2e/test_end_to_end_v2.sh | 16 ++++++
7 files changed, 95 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/e42f4f04/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 02222ba..ec63251 100644
--- a/src/main/python/apache/aurora/client/api/scheduler_client.py
+++ b/src/main/python/apache/aurora/client/api/scheduler_client.py
@@ -153,6 +153,10 @@ class ZookeeperSchedulerClient(SchedulerClient):
proxy_url = self._cluster.proxy_url
if proxy_url:
return proxy_url
+ return self.raw_url
+
+ @property
+ def raw_url(self):
if self._uri is None:
self._resolve()
if self._uri:
@@ -171,6 +175,10 @@ class DirectSchedulerClient(SchedulerClient):
def url(self):
return self._uri
+ @property
+ def raw_url(self):
+ return self._uri
+
class SchedulerProxy(object):
"""
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/e42f4f04/src/main/python/apache/aurora/client/commands/admin.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/commands/admin.py b/src/main/python/apache/aurora/client/commands/admin.py
index bc9a9ee..deee025 100644
--- a/src/main/python/apache/aurora/client/commands/admin.py
+++ b/src/main/python/apache/aurora/client/commands/admin.py
@@ -510,3 +510,16 @@ def get_cluster_config(cluster):
else:
for line in shellify(cluster, options.export, prefix="AURORA_CLUSTER_"):
print(line)
+
+
+@app.command
+@requires.exactly('cluster')
+def get_scheduler(cluster):
+ """usage: get_scheduler CLUSTER
+
+ Dumps the leading scheduler endpoint URL.
+ """
+ options = app.get_options()
+ print("Found leading scheduler at: %s" % AuroraClientAPI(
+ CLUSTERS[cluster],
+ options.verbosity).scheduler_proxy.scheduler_client().raw_url)
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/e42f4f04/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 630f662..527448f 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
@@ -316,10 +316,12 @@ def test_url_when_not_connected_and_cluster_has_no_proxy_url(scheme):
client = make_mock_client(proxy_url=None)
assert client.url == '%s://%s:%d' % (scheme, host, port)
+ assert client.url == client.raw_url
client._connect_scheduler.assert_has_calls([])
client = make_mock_client(proxy_url='https://scheduler.proxy')
assert client.url == 'https://scheduler.proxy'
+ assert client.raw_url == '%s://%s:%d' % (scheme, host, port)
client._connect_scheduler.assert_has_calls([])
client = make_mock_client(proxy_url=None)
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/e42f4f04/src/test/python/apache/aurora/client/commands/test_admin.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/test_admin.py b/src/test/python/apache/aurora/client/commands/test_admin.py
index 94e736f..f2bf7b5 100644
--- a/src/test/python/apache/aurora/client/commands/test_admin.py
+++ b/src/test/python/apache/aurora/client/commands/test_admin.py
@@ -14,10 +14,17 @@
import contextlib
-from mock import Mock, patch
+from mock import Mock, patch, PropertyMock
from apache.aurora.client.api import AuroraClientAPI
-from apache.aurora.client.commands.admin import get_locks, increase_quota, query, set_quota
+from apache.aurora.client.api.scheduler_client import SchedulerClient, SchedulerProxy
+from apache.aurora.client.commands.admin import (
+ get_locks,
+ get_scheduler,
+ increase_quota,
+ query,
+ set_quota
+)
from apache.aurora.client.commands.util import AuroraClientCommandTest
from gen.apache.aurora.api.constants import ACTIVE_STATES, TERMINAL_STATES
@@ -115,12 +122,6 @@ class TestQueryCommand(AuroraClientCommandTest):
class TestIncreaseQuotaCommand(AuroraClientCommandTest):
@classmethod
- def setup_mock_options(cls):
- mock_options = Mock(spec=['verbosity'])
- mock_options.verbosity = 'verbose'
- return mock_options
-
- @classmethod
def create_response(cls, quota, prod, non_prod, response_code=None):
response_code = ResponseCode.OK if response_code is None else response_code
resp = Response(responseCode=response_code, messageDEPRECATED='test')
@@ -157,12 +158,6 @@ class TestIncreaseQuotaCommand(AuroraClientCommandTest):
class TestSetQuotaCommand(AuroraClientCommandTest):
@classmethod
- def setup_mock_options(cls):
- mock_options = Mock(spec=['verbosity'])
- mock_options.verbosity = 'verbose'
- return mock_options
-
- @classmethod
def create_response(cls, quota, prod, non_prod, response_code=None):
response_code = ResponseCode.OK if response_code is None else response_code
resp = Response(responseCode=response_code, messageDEPRECATED='test')
@@ -203,12 +198,6 @@ class TestGetLocksCommand(AuroraClientCommandTest):
message=MESSAGE)]
@classmethod
- def setup_mock_options(cls):
- mock_options = Mock(spec=['verbosity'])
- mock_options.verbosity = 'verbose'
- return mock_options
-
- @classmethod
def create_response(cls, locks, response_code=None):
response_code = ResponseCode.OK if response_code is None else response_code
resp = Response(responseCode=response_code, messageDEPRECATED='test')
@@ -234,3 +223,28 @@ class TestGetLocksCommand(AuroraClientCommandTest):
assert mock_print_results.call_count == 1
assert "'message': '%s'" % self.MESSAGE in mock_print_results.call_args[0][0][0]
assert "'user': '%s'" % self.USER in mock_print_results.call_args[0][0][0]
+
+
+class TestGetSchedulerCommand(AuroraClientCommandTest):
+
+ def test_get_scheduler(self):
+ """Tests successful execution of the get_scheduler command."""
+ mock_options = self.setup_mock_options()
+ mock_proxy = Mock(spec=SchedulerProxy)
+ mock_scheduler_client = Mock(spec=SchedulerClient)
+ mock_raw_url = PropertyMock(return_value="url")
+ mock_proxy.scheduler_client.return_value = mock_scheduler_client
+ mock_scheduler_client.raw_url = mock_raw_url
+
+ with contextlib.nested(
+ patch('twitter.common.app.get_options', return_value=mock_options),
+ patch('apache.aurora.client.commands.admin.AuroraClientAPI',
+ new=Mock(spec=AuroraClientAPI)),
+ patch('apache.aurora.client.commands.admin.CLUSTERS', new=self.TEST_CLUSTERS),
+ ) as (_, api, _):
+
+ api.return_value.scheduler_proxy = PropertyMock(return_value=mock_proxy)
+
+ get_scheduler([self.TEST_CLUSTER])
+
+ mock_raw_url.assert_called_once()
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/e42f4f04/src/test/python/apache/aurora/client/commands/util.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/commands/util.py b/src/test/python/apache/aurora/client/commands/util.py
index 21b8830..663f2f4 100644
--- a/src/test/python/apache/aurora/client/commands/util.py
+++ b/src/test/python/apache/aurora/client/commands/util.py
@@ -142,3 +142,9 @@ jobs = [HELLO_WORLD]
job = AuroraJobKey.from_path('west/role/env/job-%s' % hostname)
hosts[hostname].append(JobUpTimeDetails(job, predicted, safe, safe_in))
return [hosts]
+
+ @classmethod
+ def setup_mock_options(cls):
+ mock_options = Mock(spec=['verbosity'])
+ mock_options.verbosity = 'verbose'
+ return mock_options
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/e42f4f04/src/test/sh/org/apache/aurora/e2e/test_end_to_end.sh
----------------------------------------------------------------------
diff --git a/src/test/sh/org/apache/aurora/e2e/test_end_to_end.sh b/src/test/sh/org/apache/aurora/e2e/test_end_to_end.sh
index 989801c..324aa4d 100755
--- a/src/test/sh/org/apache/aurora/e2e/test_end_to_end.sh
+++ b/src/test/sh/org/apache/aurora/e2e/test_end_to_end.sh
@@ -56,6 +56,16 @@ test_http_example() {
vagrant ssh -c "aurora killall $jobkey"
}
+test_admin() {
+ local _cluster=$1 _sched_ip=$2
+
+ base_url="http://$_sched_ip:8081"
+
+ echo '== Testing Aurora Admin commands...'
+ echo '== Getting leading scheduler'
+ vagrant ssh -c "aurora_admin get_scheduler $_cluster" | grep "$base_url"
+}
+
RETCODE=1
# Set up shorthands for test
export EXAMPLE_DIR=/vagrant/src/test/sh/org/apache/aurora/e2e/http
@@ -74,9 +84,15 @@ TEST_ARGS=(
$EXAMPLE_DIR/http_example_updated.aurora
)
+TEST_ADMIN_ARGS=(
+ $TEST_CLUSTER
+ $TEST_SCHEDULER_IP
+)
+
trap collect_result EXIT
vagrant up
# wipe the pseudo-deploy dir, and then create it fresh, to guarantee that the
# test runs clean.
test_http_example "${TEST_ARGS[@]}"
+test_admin "${TEST_ADMIN_ARGS[@]}"
RETCODE=0
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/e42f4f04/src/test/sh/org/apache/aurora/e2e/test_end_to_end_v2.sh
----------------------------------------------------------------------
diff --git a/src/test/sh/org/apache/aurora/e2e/test_end_to_end_v2.sh b/src/test/sh/org/apache/aurora/e2e/test_end_to_end_v2.sh
index 0965b5c..8f4d2b0 100755
--- a/src/test/sh/org/apache/aurora/e2e/test_end_to_end_v2.sh
+++ b/src/test/sh/org/apache/aurora/e2e/test_end_to_end_v2.sh
@@ -81,6 +81,16 @@ test_http_example() {
vagrant ssh -c "aurora2 quota get $_cluster/$_role"
}
+test_admin() {
+ local _cluster=$1 _sched_ip=$2
+
+ base_url="http://$_sched_ip:8081"
+
+ echo '== Testing Aurora Admin commands...'
+ echo '== Getting leading scheduler'
+ vagrant ssh -c "aurora_admin get_scheduler $_cluster" | grep "$base_url"
+}
+
RETCODE=1
# Set up shorthands for test
export EXAMPLE_DIR=/vagrant/src/test/sh/org/apache/aurora/e2e/http
@@ -99,6 +109,11 @@ TEST_ARGS=(
$EXAMPLE_DIR/http_example_updated.aurora
)
+TEST_ADMIN_ARGS=(
+ $TEST_CLUSTER
+ $TEST_SCHEDULER_IP
+)
+
trap collect_result EXIT
vagrant up
@@ -106,4 +121,5 @@ vagrant up
# wipe the pseudo-deploy dir, and then create it fresh, to guarantee that the
# test runs clean.
test_http_example "${TEST_ARGS[@]}"
+test_admin "${TEST_ADMIN_ARGS[@]}"
RETCODE=0