You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aurora.apache.org by jc...@apache.org on 2016/11/15 16:50:53 UTC
aurora git commit: aurora job inspect should have a --write-json
option
Repository: aurora
Updated Branches:
refs/heads/master 8a9939f9e -> e9a182fa0
aurora job inspect should have a --write-json option
Bugs closed: AURORA-1504
Reviewed at https://reviews.apache.org/r/53114/
Project: http://git-wip-us.apache.org/repos/asf/aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/aurora/commit/e9a182fa
Tree: http://git-wip-us.apache.org/repos/asf/aurora/tree/e9a182fa
Diff: http://git-wip-us.apache.org/repos/asf/aurora/diff/e9a182fa
Branch: refs/heads/master
Commit: e9a182fa02ed42246725a506fb70b54da8f8ff87
Parents: 8a9939f
Author: Jing Chen <mi...@gmail.com>
Authored: Tue Nov 15 10:44:22 2016 -0600
Committer: Joshua Cohen <jc...@apache.org>
Committed: Tue Nov 15 10:44:22 2016 -0600
----------------------------------------------------------------------
.../python/apache/aurora/client/cli/jobs.py | 25 ++++---
.../apache/aurora/client/cli/test_inspect.py | 72 ++++++++++++++++++++
2 files changed, 89 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/aurora/blob/e9a182fa/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 87fbf13..8ba41aa 100644
--- a/src/main/python/apache/aurora/client/cli/jobs.py
+++ b/src/main/python/apache/aurora/client/cli/jobs.py
@@ -230,23 +230,20 @@ class InspectCommand(Verb):
return "inspect"
def get_options(self):
- return [BIND_OPTION, JSON_READ_OPTION,
+ return [BIND_OPTION, JSON_READ_OPTION, JSON_WRITE_OPTION,
CommandOption("--raw", dest="raw", default=False, action="store_true",
help="Show the raw configuration."),
JOBSPEC_ARGUMENT, CONFIG_ARGUMENT]
- def execute(self, context):
- config = context.get_job_config(context.options.jobspec, context.options.config_file)
- if context.options.raw:
- context.print_out(str(config.job()))
- return EXIT_OK
-
+ def _render_config_pretty(self, config, context):
+ """Render the config description in human-friendly format"""
job = config.raw()
job_thrift = config.job()
context.print_out("Job level information")
context.print_out("name: '%s'" % job.name(), indent=2)
context.print_out("role: '%s'" % job.role(), indent=2)
- context.print_out("contact: '%s'" % job.contact(), indent=2)
+ if job.has_contact():
+ context.print_out("contact: '%s'" % job.contact(), indent=2)
context.print_out("cluster: '%s'" % job.cluster(), indent=2)
context.print_out("instances: '%s'" % job.instances(), indent=2)
if job.has_cron_schedule():
@@ -287,6 +284,18 @@ class InspectCommand(Verb):
context.print_out("")
return EXIT_OK
+ def execute(self, context):
+ config = context.get_job_config(context.options.jobspec, context.options.config_file)
+ if context.options.raw:
+ context.print_out(str(config.job()))
+ return EXIT_OK
+
+ if context.options.write_json:
+ context.print_out(config.raw().json_dumps())
+ return EXIT_OK
+ else:
+ return self._render_config_pretty(config, context)
+
class AbstractKillCommand(Verb):
def get_options(self):
http://git-wip-us.apache.org/repos/asf/aurora/blob/e9a182fa/src/test/python/apache/aurora/client/cli/test_inspect.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_inspect.py b/src/test/python/apache/aurora/client/cli/test_inspect.py
index fedc16b..7ef682d 100644
--- a/src/test/python/apache/aurora/client/cli/test_inspect.py
+++ b/src/test/python/apache/aurora/client/cli/test_inspect.py
@@ -13,6 +13,7 @@
#
import contextlib
+import json
from mock import patch
@@ -75,6 +76,77 @@ Process 'process':
ls -la
'''
+ def test_inspect_job_in_json(self):
+ mock_stdout = []
+ def mock_print_out(msg):
+ mock_stdout.append("%s" % msg)
+ with contextlib.nested(
+ patch('apache.aurora.client.cli.context.AuroraCommandContext.print_out',
+ side_effect=mock_print_out),
+ patch('apache.aurora.client.cli.context.AuroraCommandContext.get_job_config',
+ return_value=self.get_job_config())):
+ cmd = AuroraCommandLine()
+ assert cmd.execute([
+ 'job', 'inspect', '--write-json', 'west/bozo/test/hello', 'config.aurora']) == 0
+ output = {
+ "environment": "test",
+ "health_check_config": {
+ "initial_interval_secs": 15.0,
+ "health_checker": {
+ "http": {
+ "expected_response_code": 0,
+ "endpoint": "/health",
+ "expected_response": "ok"}},
+ "interval_secs": 10.0,
+ "timeout_secs": 1.0,
+ "max_consecutive_failures": 0},
+ "cluster": "west",
+ "cron_schedule": "* * * * *",
+ "service": False,
+ "update_config": {
+ "wait_for_batch_completion": False,
+ "batch_size": 1,
+ "watch_secs": 45,
+ "rollback_on_failure": True,
+ "max_per_shard_failures": 0,
+ "max_total_failures": 0},
+ "name": "the_job",
+ "max_task_failures": 1,
+ "cron_collision_policy": "KILL_EXISTING",
+ "enable_hooks": False,
+ "instances": 3,
+ "task": {
+ "processes": [{
+ "daemon": False,
+ "name": "process",
+ "ephemeral": False,
+ "max_failures": 1,
+ "min_duration": 5,
+ "cmdline": "ls -la",
+ "final": False}],
+ "name": "task",
+ "finalization_wait": 30,
+ "max_failures": 1,
+ "max_concurrency": 0,
+ "resources": {
+ "gpu": 0,
+ "disk": 1073741824,
+ "ram": 1073741824,
+ "cpu": 1.0},
+ "constraints": []},
+ "production": False,
+ "role": "bozo",
+ "contact": "bozo@the.clown",
+ "lifecycle": {
+ "http": {
+ "graceful_shutdown_endpoint": "/quitquitquit",
+ "port": "health",
+ "shutdown_endpoint": "/abortabortabort"}},
+ "priority": 0}
+
+ mock_output = "\n".join(mock_stdout)
+ assert output == json.loads(mock_output)
+
def test_inspect_job_raw(self):
mock_stdout = []
def mock_print_out(msg, indent=0):