aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wfar...@apache.org
Subject incubator-aurora git commit: Prevent multiple active job updates from being inserted into storage.
Date Tue, 03 Feb 2015 00:02:34 GMT
Repository: incubator-aurora
Updated Branches:
  refs/heads/master e2a93af32 -> a67458136


Prevent multiple active job updates from being inserted into storage.

Bugs closed: AURORA-1023

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


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

Branch: refs/heads/master
Commit: a674581364ae9b5527646ef470d9296470c3b836
Parents: e2a93af
Author: Bill Farner <wfarner@apache.org>
Authored: Mon Feb 2 15:58:07 2015 -0800
Committer: Bill Farner <wfarner@apache.org>
Committed: Mon Feb 2 15:58:07 2015 -0800

----------------------------------------------------------------------
 .../updater/JobUpdateControllerImpl.java        |  8 +++
 .../aurora/scheduler/updater/JobUpdaterIT.java  | 73 +++++++++++++++++++-
 2 files changed, 78 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/a6745813/src/main/java/org/apache/aurora/scheduler/updater/JobUpdateControllerImpl.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/updater/JobUpdateControllerImpl.java
b/src/main/java/org/apache/aurora/scheduler/updater/JobUpdateControllerImpl.java
index a992938..ec9d1e0 100644
--- a/src/main/java/org/apache/aurora/scheduler/updater/JobUpdateControllerImpl.java
+++ b/src/main/java/org/apache/aurora/scheduler/updater/JobUpdateControllerImpl.java
@@ -146,6 +146,14 @@ class JobUpdateControllerImpl implements JobUpdateController {
           throw new IllegalArgumentException("Update instruction is a no-op.");
         }
 
+        List<IJobUpdateSummary> activeJobUpdates =
+            storeProvider.getJobUpdateStore().fetchJobUpdateSummaries(queryByJob(job));
+        if (!activeJobUpdates.isEmpty()) {
+          throw new UpdateStateException("An active update already exists for this job, "
+              + "please terminate it before starting another. "
+              + "Active updates are those in states " + ACTIVE_JOB_UPDATE_STATES);
+        }
+
         LOG.info("Starting update for job " + job);
         ILock lock;
         try {

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/a6745813/src/test/java/org/apache/aurora/scheduler/updater/JobUpdaterIT.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/updater/JobUpdaterIT.java b/src/test/java/org/apache/aurora/scheduler/updater/JobUpdaterIT.java
index 4c827b1..41d4229 100644
--- a/src/test/java/org/apache/aurora/scheduler/updater/JobUpdaterIT.java
+++ b/src/test/java/org/apache/aurora/scheduler/updater/JobUpdaterIT.java
@@ -638,6 +638,12 @@ public class JobUpdaterIT extends EasyMockTest {
     assertJobState(JOB, ImmutableMap.of(0, NEW_CONFIG, 1, OLD_CONFIG));
   }
 
+  private void releaseAllLocks() {
+    for (ILock lock : lockManager.getLocks()) {
+      lockManager.releaseLock(lock);
+    }
+  }
+
   @Test
   public void testLostLock() throws Exception {
     expectTaskKilled();
@@ -654,9 +660,7 @@ public class JobUpdaterIT extends EasyMockTest {
 
     // Instance 0 is updated.
     updater.start(update, USER);
-    for (ILock lock : lockManager.getLocks()) {
-      lockManager.releaseLock(lock);
-    }
+    releaseAllLocks();
     clock.advance(RUNNING_TIMEOUT);
     ImmutableMultimap.Builder<Integer, JobUpdateAction> actions = ImmutableMultimap.builder();
     actions.putAll(0, INSTANCE_UPDATING);
@@ -959,6 +963,69 @@ public class JobUpdaterIT extends EasyMockTest {
     updater.pause(JOB, USER);
   }
 
+  @Test
+  public void testAbortAfterLostLock() throws Exception {
+    expectTaskKilled();
+
+    control.replay();
+
+    IJobUpdate update = makeJobUpdate(makeInstanceConfig(0, 0, OLD_CONFIG));
+    insertInitialTasks(update);
+
+    changeState(JOB, 0, ASSIGNED, STARTING, RUNNING);
+    clock.advance(WATCH_TIMEOUT);
+
+    ImmutableMultimap.Builder<Integer, JobUpdateAction> actions = ImmutableMultimap.builder();
+
+    updater.start(update, USER);
+    actions.putAll(0, INSTANCE_UPDATING);
+    assertState(ROLLING_FORWARD, actions.build());
+    releaseAllLocks();
+    updater.abort(update.getSummary().getJobKey(), "test");
+    clock.advance(WATCH_TIMEOUT);
+    assertState(ERROR, actions.build());
+  }
+
+  @Test
+  public void testStartUpdateAfterPausedAndLockLost() throws Exception {
+    // Tests for regression of AURORA-1023, in which a user could paint themselves into a
corner
+    // by starting an update, pausing it, and forcibly releasing the job lock.  The result
in this
+    // behavior should be to prevent further job updates until the user aborts the first
one.
+
+    expectTaskKilled();
+
+    control.replay();
+
+    IJobUpdate update = makeJobUpdate(makeInstanceConfig(0, 0, OLD_CONFIG));
+    insertInitialTasks(update);
+
+    changeState(JOB, 0, ASSIGNED, STARTING, RUNNING);
+    clock.advance(WATCH_TIMEOUT);
+
+    ImmutableMultimap.Builder<Integer, JobUpdateAction> actions = ImmutableMultimap.builder();
+
+    updater.start(update, USER);
+    actions.putAll(0, INSTANCE_UPDATING);
+    assertState(ROLLING_FORWARD, actions.build());
+
+    updater.pause(update.getSummary().getJobKey(), "test");
+    assertState(ROLL_FORWARD_PAUSED, actions.build());
+    clock.advance(WATCH_TIMEOUT);
+
+    releaseAllLocks();
+
+    JobUpdate builder = makeJobUpdate(makeInstanceConfig(0, 0, OLD_CONFIG)).newBuilder();
+    builder.getSummary().setUpdateId("another update");
+    IJobUpdate update2 = IJobUpdate.build(builder);
+
+    try {
+      updater.start(update2, USER);
+      fail();
+    } catch (UpdateStateException e) {
+      // Expected.
+    }
+  }
+
   private static IJobUpdateSummary makeUpdateSummary() {
     return IJobUpdateSummary.build(new JobUpdateSummary()
         .setUser("user")


Mime
View raw message