aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject incubator-aurora git commit: Adding cron check into aurora beta-update start.
Date Tue, 25 Nov 2014 18:01:06 GMT
Repository: incubator-aurora
Updated Branches:
  refs/heads/master 9514a63c0 -> a2fc81803


Adding cron check into aurora beta-update start.

Bugs closed: AURORA-921

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


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

Branch: refs/heads/master
Commit: a2fc818037c860dd29623887f0e9da21d219fb12
Parents: 9514a63
Author: Maxim Khutornenko <maxim@apache.org>
Authored: Tue Nov 25 10:00:40 2014 -0800
Committer: Maxim Khutornenko <maxim@apache.org>
Committed: Tue Nov 25 10:00:40 2014 -0800

----------------------------------------------------------------------
 docs/clientv2.md                                |  3 +-
 docs/cron-jobs.md                               |  3 +-
 .../thrift/SchedulerThriftInterface.java        |  5 +-
 .../python/apache/aurora/client/cli/cron.py     | 10 +++-
 .../python/apache/aurora/client/cli/update.py   |  7 ++-
 .../thrift/SchedulerThriftInterfaceTest.java    |  3 +-
 .../apache/aurora/client/cli/test_supdate.py    | 48 +++++++++++++-------
 7 files changed, 56 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/a2fc8180/docs/clientv2.md
----------------------------------------------------------------------
diff --git a/docs/clientv2.md b/docs/clientv2.md
index 6e69af3..471d80c 100644
--- a/docs/clientv2.md
+++ b/docs/clientv2.md
@@ -227,7 +227,8 @@ Cron is a scheduler adjunct that periodically runs a job on a
 schedule. The cron commands all manipulate cron schedule entries. The
 schedules are specified as a part of the job configuration.
 
-* `aurora cron schedule jobkey config`: schedule a job to run by cron.
+* `aurora cron schedule jobkey config`: schedule a job to run by cron. If a cron job already
exists
+replaces its template with a new one.
 * `aurora cron deschedule jobkey`: removes a jobs entry from the cron schedule.
 * `aurora cron status jobkey`: query for a scheduled job's status.
 

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/a2fc8180/docs/cron-jobs.md
----------------------------------------------------------------------
diff --git a/docs/cron-jobs.md b/docs/cron-jobs.md
index 7d04bcd..c3e8eed 100644
--- a/docs/cron-jobs.md
+++ b/docs/cron-jobs.md
@@ -76,7 +76,8 @@ Most interaction with cron jobs takes place using the `cron` subcommand.
See `au
 for up-to-date usage instructions.
 
 ### cron schedule
-Schedules a new cron job on the Aurora cluster for later runs, or updates an existing job.
+Schedules a new cron job on the Aurora cluster for later runs or replaces the existing cron
template
+with a new one. Only future runs will be affected, any existing active tasks are left intact.
 
     $ aurora2 cron schedule devcluster/www-data/test/cron_hello_world /vagrant/examples/jobs/cron_hello_world.aurora
 

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/a2fc8180/src/main/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterface.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterface.java
b/src/main/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterface.java
index a5e869f..9087eb2 100644
--- a/src/main/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterface.java
+++ b/src/main/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterface.java
@@ -1400,7 +1400,7 @@ class SchedulerThriftInterface implements AuroraAdmin.Iface {
               ITaskConfig.build(mutableRequest.getTaskConfig())).newBuilder()));
 
       if (cronJobManager.hasJob(job)) {
-        return invalidResponse("Cron jobs may only be updated by calling replaceCronTemplate.");
+        return invalidResponse(NO_CRON_UPDATES);
       }
     } catch (AuthFailedException e) {
       return errorResponse(AUTH_FAILED, e);
@@ -1594,6 +1594,9 @@ class SchedulerThriftInterface implements AuroraAdmin.Iface {
   @VisibleForTesting
   static final String NOOP_JOB_UPDATE_MESSAGE = "Job is unchanged by proposed update.";
 
+  @VisibleForTesting
+  static final String NO_CRON_UPDATES = "Cron jobs may only be updated by calling scheduleCronJob.";
+
   private static Response okEmptyResponse()  {
     return emptyResponse().setResponseCode(OK);
   }

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/a2fc8180/src/main/python/apache/aurora/client/cli/cron.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/cli/cron.py b/src/main/python/apache/aurora/client/cli/cron.py
index cfd957c..1f1efdb 100644
--- a/src/main/python/apache/aurora/client/cli/cron.py
+++ b/src/main/python/apache/aurora/client/cli/cron.py
@@ -16,6 +16,8 @@
 
 from __future__ import print_function
 
+import textwrap
+
 from apache.aurora.client.cli import (
     EXIT_COMMAND_FAILURE,
     EXIT_INVALID_PARAMETER,
@@ -41,7 +43,9 @@ class Schedule(Verb):
 
   @property
   def help(self):
-    return "Create a cron schedule for a job."
+    return textwrap.dedent("""\
+       Create a cron schedule for a job or replace the existing cron template with a new
one.
+       Only future runs will be affected, any existing active tasks are left intact.""")
 
   def get_options(self):
     return [BIND_OPTION, JSON_READ_OPTION, JOBSPEC_ARGUMENT, CONFIG_ARGUMENT]
@@ -71,7 +75,9 @@ class Deschedule(Verb):
 
   @property
   def help(self):
-    return "Remove the cron schedule for a job."
+    return textwrap.dedent("""\
+        Remove the cron schedule for a job. Any active tasks are not affected.
+        Use \"aurora job kill\" command to terminate active tasks.""")
 
   def get_options(self):
     return [JOBSPEC_ARGUMENT]

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/a2fc8180/src/main/python/apache/aurora/client/cli/update.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/cli/update.py b/src/main/python/apache/aurora/client/cli/update.py
index 12774af..d1d0b29 100644
--- a/src/main/python/apache/aurora/client/cli/update.py
+++ b/src/main/python/apache/aurora/client/cli/update.py
@@ -17,7 +17,7 @@ from __future__ import print_function
 import json
 import textwrap
 
-from apache.aurora.client.cli import EXIT_API_ERROR, EXIT_OK, Noun, Verb
+from apache.aurora.client.cli import EXIT_API_ERROR, EXIT_COMMAND_FAILURE, EXIT_OK, Noun,
Verb
 from apache.aurora.client.cli.context import AuroraCommandContext
 from apache.aurora.client.cli.options import (
     ALL_INSTANCES,
@@ -74,6 +74,11 @@ class StartUpdate(Verb):
     if instances is not None and context.options.strict:
       context.verify_shards_option_validity(job, instances)
     config = context.get_job_config(job, context.options.config_file)
+    if config.raw().has_cron_schedule():
+      raise context.CommandError(
+          EXIT_COMMAND_FAILURE,
+          "Cron jobs may only be updated with \"aurora cron schedule\" command")
+
     api = context.get_api(config.cluster())
     resp = api.start_job_update(config, instances)
     context.check_and_log_response(resp, err_code=EXIT_API_ERROR,

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/a2fc8180/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
b/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
index de5f21a..c602b30 100644
--- a/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
@@ -171,6 +171,7 @@ import static org.apache.aurora.scheduler.storage.backup.Recovery.RecoveryExcept
 import static org.apache.aurora.scheduler.thrift.SchedulerThriftInterface.MAX_TASKS_PER_JOB;
 import static org.apache.aurora.scheduler.thrift.SchedulerThriftInterface.MAX_TASK_ID_LENGTH;
 import static org.apache.aurora.scheduler.thrift.SchedulerThriftInterface.NOOP_JOB_UPDATE_MESSAGE;
+import static org.apache.aurora.scheduler.thrift.SchedulerThriftInterface.NO_CRON_UPDATES;
 import static org.apache.aurora.scheduler.thrift.SchedulerThriftInterface.killedByMessage;
 import static org.apache.aurora.scheduler.thrift.SchedulerThriftInterface.noCronScheduleMessage;
 import static org.apache.aurora.scheduler.thrift.SchedulerThriftInterface.notScheduledCronMessage;
@@ -2700,7 +2701,7 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
     expect(cronJobManager.hasJob(JOB_KEY)).andReturn(true);
 
     control.replay();
-    assertResponse(INVALID_REQUEST, thrift.startJobUpdate(request, SESSION));
+    assertEquals(invalidResponse(NO_CRON_UPDATES), thrift.startJobUpdate(request, SESSION));
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/a2fc8180/src/test/python/apache/aurora/client/cli/test_supdate.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_supdate.py b/src/test/python/apache/aurora/client/cli/test_supdate.py
index 7637352..eafb909 100644
--- a/src/test/python/apache/aurora/client/cli/test_supdate.py
+++ b/src/test/python/apache/aurora/client/cli/test_supdate.py
@@ -49,29 +49,45 @@ from gen.apache.aurora.api.ttypes import (
 
 class TestStartUpdateCommand(unittest.TestCase):
 
+  def setUp(self):
+    self._command = StartUpdate()
+    self._job_key = AuroraJobKey("cluster", "role", "env", "job")
+    self._mock_options = mock_verb_options(self._command)
+    self._mock_options.instance_spec = TaskInstanceKey(self._job_key, [])
+    self._fake_context = FakeAuroraCommandContext()
+    self._fake_context.set_options(self._mock_options)
+    self._mock_api = self._fake_context.get_api("test")
+
+  @classmethod
+  def create_mock_config(cls, is_cron=False):
+    mock_config = create_autospec(spec=AuroraConfig, spec_set=True, instance=True)
+    mock_raw_config = Mock()
+    mock_raw_config.has_cron_schedule.return_value = is_cron
+    mock_config.raw = Mock(return_value=mock_raw_config)
+    return mock_config
+
   def test_start_update_with_lock(self):
-    command = StartUpdate()
+    mock_config = self.create_mock_config()
+    self._fake_context.get_job_config = Mock(return_value=mock_config)
+    self._mock_api.start_job_update.return_value = AuroraClientCommandTest.create_blank_response(
+        ResponseCode.LOCK_ERROR,
+        "Error.")
 
-    jobkey = AuroraJobKey("cluster", "role", "env", "job")
-    mock_options = mock_verb_options(command)
-    mock_options.instance_spec = TaskInstanceKey(jobkey, [])
+    with pytest.raises(Context.CommandError):
+      self._command.execute(self._fake_context)
 
-    fake_context = FakeAuroraCommandContext()
-    fake_context.set_options(mock_options)
+    self._mock_api.start_job_update.assert_called_once_with(
+        mock_config,
+        self._mock_options.instance_spec.instance)
 
-    mock_config = create_autospec(spec=AuroraConfig, spec_set=True, instance=True)
-    fake_context.get_job_config = Mock(return_value=mock_config)
+    assert self._fake_context.get_err()[0] == self._fake_context.LOCK_ERROR_MSG
 
-    mock_api = fake_context.get_api("test")
-    mock_api.start_job_update.return_value = AuroraClientCommandTest.create_blank_response(
-      ResponseCode.LOCK_ERROR, "Error.")
+  def test_update_cron_job_fails(self):
+    mock_config = self.create_mock_config(is_cron=True)
+    self._fake_context.get_job_config = Mock(return_value=mock_config)
 
     with pytest.raises(Context.CommandError):
-      command.execute(fake_context)
-
-    mock_api.start_job_update.assert_called_once_with(mock_config,
-      mock_options.instance_spec.instance)
-    assert fake_context.get_err()[0] == fake_context.LOCK_ERROR_MSG
+      self._command.execute(self._fake_context)
 
 
 class TestUpdateCommand(AuroraClientCommandTest):


Mime
View raw message