You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aurora.apache.org by mc...@apache.org on 2014/04/04 20:41:41 UTC

git commit: Add the "open" command to clientv2, and fix an error case in v1.

Repository: incubator-aurora
Updated Branches:
  refs/heads/master 8846655e8 -> 3bcbc8831


Add the "open" command to clientv2, and fix an error case in v1.

Clientv2 didn't have an "open" command, which it needed. Clientv1
had an open command, but if you used it and you forgot to specify
the parameter, it dropped its cookies.

Bugs closed: aurora-307

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


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

Branch: refs/heads/master
Commit: 3bcbc8831774359631c3ca54f8e7dbe115c95799
Parents: 8846655
Author: Mark Chu-Carroll <mc...@twopensource.com>
Authored: Fri Apr 4 14:38:55 2014 -0400
Committer: Mark Chu-Carroll <mc...@twitter.com>
Committed: Fri Apr 4 14:38:55 2014 -0400

----------------------------------------------------------------------
 .../python/apache/aurora/client/cli/context.py  |  6 ++
 .../python/apache/aurora/client/cli/jobs.py     | 26 ++++++++
 .../apache/aurora/client/commands/core.py       |  3 +
 src/test/python/apache/aurora/client/cli/BUILD  |  1 +
 .../apache/aurora/client/cli/test_open.py       | 65 ++++++++++++++++++++
 5 files changed, 101 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/3bcbc883/src/main/python/apache/aurora/client/cli/context.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/cli/context.py b/src/main/python/apache/aurora/client/cli/context.py
index 83f7b6a..957c788 100644
--- a/src/main/python/apache/aurora/client/cli/context.py
+++ b/src/main/python/apache/aurora/client/cli/context.py
@@ -83,6 +83,12 @@ class AuroraCommandContext(Context):
     self.open_page(synthesize_url(api.scheduler_proxy.scheduler_client().url, jobkey.role,
         jobkey.env, jobkey.name))
 
+  def open_scheduler_page(self, cluster, role, env, name):
+    """Open a scheduler page"""
+    api = self.get_api(cluster)
+    self.open_page(synthesize_url(api.scheduler_proxy.scheduler_client().url,
+        role, env, name))
+
   def check_and_log_response(self, resp):
     self.print_log(logging.INFO, 'Response from scheduler: %s (message: %s)'
         % (ResponseCode._VALUES_TO_NAMES[resp.responseCode], resp.message))

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/3bcbc883/src/main/python/apache/aurora/client/cli/jobs.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/cli/jobs.py b/src/main/python/apache/aurora/client/cli/jobs.py
index 798f54d..0793a1a 100644
--- a/src/main/python/apache/aurora/client/cli/jobs.py
+++ b/src/main/python/apache/aurora/client/cli/jobs.py
@@ -394,6 +394,31 @@ class ListJobsCommand(Verb):
     context.print_out(result)
     return EXIT_OK
 
+class OpenCommand(Verb):
+  # TODO(mchucarroll): this is awkward in the noun/verb framework: where does it actually belong?
+  @property
+  def name(self):
+    return 'open'
+
+  @property
+  def help(self):
+    return "Open a job's scheduler page in the web browser."
+
+  def get_options(self):
+    return [
+      CommandOption('key', type=str, metavar='cluster[/role[/env[/job]]]',
+        help='A key for the cluster, role, env, or job whose scheduler page should be opened.')
+    ]
+
+  def execute(self, context):
+    key_parts = context.options.key.split('/')
+    while len(key_parts) < 4:
+      key_parts.append(None)
+    (cluster, role, env, name) = key_parts
+    api = context.get_api(cluster)
+    context.open_scheduler_page(cluster, role, env, name)
+    return EXIT_OK
+
 
 class RestartCommand(Verb):
   @property
@@ -615,6 +640,7 @@ class Job(Noun):
     self.register_verb(KillCommand())
     self.register_verb(KillAllJobCommand())
     self.register_verb(ListJobsCommand())
+    self.register_verb(OpenCommand())
     self.register_verb(RestartCommand())
     self.register_verb(StatusCommand())
     self.register_verb(UpdateCommand())

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/3bcbc883/src/main/python/apache/aurora/client/commands/core.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/commands/core.py b/src/main/python/apache/aurora/client/commands/core.py
index b1abc9e..67c061e 100644
--- a/src/main/python/apache/aurora/client/commands/core.py
+++ b/src/main/python/apache/aurora/client/commands/core.py
@@ -225,6 +225,9 @@ def do_open(args, _):
   Opens the scheduler page for a cluster, role or job in the default web browser.
   """
   cluster_name = role = env = job = None
+  if len(args) == 0:
+    print('Open command requires a jobkey parameter.')
+    exit(1)
   args = args[0].split("/")
   if len(args) > 0:
     cluster_name = args[0]

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/3bcbc883/src/test/python/apache/aurora/client/cli/BUILD
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/BUILD b/src/test/python/apache/aurora/client/cli/BUILD
index d93a2df..34fdb47 100644
--- a/src/test/python/apache/aurora/client/cli/BUILD
+++ b/src/test/python/apache/aurora/client/cli/BUILD
@@ -75,6 +75,7 @@ python_tests(
     'test_create.py',
     'test_diff.py',
     'test_kill.py',
+    'test_open.py',
     'test_restart.py',
     'test_status.py',
     'test_update.py',

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/3bcbc883/src/test/python/apache/aurora/client/cli/test_open.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_open.py b/src/test/python/apache/aurora/client/cli/test_open.py
new file mode 100644
index 0000000..ef816ad
--- /dev/null
+++ b/src/test/python/apache/aurora/client/cli/test_open.py
@@ -0,0 +1,65 @@
+#
+# Copyright 2013 Apache Software Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+import contextlib
+
+from apache.aurora.client.cli import EXIT_OK, EXIT_INVALID_PARAMETER
+from apache.aurora.client.cli.client import AuroraCommandLine
+from apache.aurora.client.cli.util import AuroraClientCommandTest, FakeAuroraCommandContext
+from mock import Mock, patch
+
+class TestClientOpenCommand(AuroraClientCommandTest):
+
+  def test_open_cluster(self):
+    mock_context = FakeAuroraCommandContext()
+    with patch('apache.aurora.client.cli.jobs.Job.create_context', return_value=mock_context):
+      cmd = AuroraCommandLine()
+      result = cmd.execute(['job', 'open', 'west'])
+      assert mock_context.showed_urls == ['http://something_or_other/scheduler']
+      assert result == EXIT_OK
+
+  def test_open_role(self):
+    mock_context = FakeAuroraCommandContext()
+    with patch('apache.aurora.client.cli.jobs.Job.create_context', return_value=mock_context):
+      cmd = AuroraCommandLine()
+      result = cmd.execute(['job', 'open', 'west/bozo'])
+      assert mock_context.showed_urls == ['http://something_or_other/scheduler/bozo']
+      assert result == EXIT_OK
+
+  def test_open_env(self):
+    mock_context = FakeAuroraCommandContext()
+    with patch('apache.aurora.client.cli.jobs.Job.create_context', return_value=mock_context):
+      cmd = AuroraCommandLine()
+      result = cmd.execute(['job', 'open', 'west/bozo/devel'])
+      assert mock_context.showed_urls == ['http://something_or_other/scheduler/bozo/devel']
+      assert result == EXIT_OK
+
+  def test_open_job(self):
+    mock_context = FakeAuroraCommandContext()
+    with patch('apache.aurora.client.cli.jobs.Job.create_context', return_value=mock_context):
+      cmd = AuroraCommandLine()
+      result = cmd.execute(['job', 'open', 'west/bozo/devel/foo'])
+      assert mock_context.showed_urls == ['http://something_or_other/scheduler/bozo/devel/foo']
+      assert result == EXIT_OK
+
+  def test_open_noparam(self):
+    mock_context = FakeAuroraCommandContext()
+    with patch('apache.aurora.client.cli.jobs.Job.create_context', return_value=mock_context):
+      cmd = AuroraCommandLine()
+      self.assertRaises(SystemExit, cmd.execute, (['job', 'open']))
+      assert mock_context.showed_urls == []
+
+