Repository: aurora
Updated Branches:
  refs/heads/master 0e62780c4 -> 8613f7b40


Fixing scoped update issue.

Bugs closed: AURORA-1549

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


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

Branch: refs/heads/master
Commit: 8613f7b40deeedfe213a0713f6889b958078a3d1
Parents: 0e62780
Author: Maxim Khutornenko <[email protected]>
Authored: Wed Dec 9 15:42:20 2015 -0800
Committer: Maxim Khutornenko <[email protected]>
Committed: Wed Dec 9 15:42:20 2015 -0800

----------------------------------------------------------------------
 .../aurora/scheduler/updater/UpdateFactory.java | 11 ++----
 .../aurora/scheduler/updater/JobUpdaterIT.java  | 35 ++++++++++++++++++--
 .../updater/UpdateFactoryImplTest.java          | 28 ++++++++++------
 3 files changed, 52 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aurora/blob/8613f7b4/src/main/java/org/apache/aurora/scheduler/updater/UpdateFactory.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/aurora/scheduler/updater/UpdateFactory.java 
b/src/main/java/org/apache/aurora/scheduler/updater/UpdateFactory.java
index 44402c1..258151f 100644
--- a/src/main/java/org/apache/aurora/scheduler/updater/UpdateFactory.java
+++ b/src/main/java/org/apache/aurora/scheduler/updater/UpdateFactory.java
@@ -28,7 +28,6 @@ import org.apache.aurora.common.quantity.Amount;
 import org.apache.aurora.common.quantity.Time;
 import org.apache.aurora.common.util.Clock;
 import org.apache.aurora.gen.JobUpdateStatus;
-import org.apache.aurora.scheduler.base.Numbers;
 import org.apache.aurora.scheduler.storage.entities.IInstanceTaskConfig;
 import org.apache.aurora.scheduler.storage.entities.IJobUpdateInstructions;
 import org.apache.aurora.scheduler.storage.entities.IJobUpdateSettings;
@@ -87,18 +86,12 @@ interface UpdateFactory {
           settings.getUpdateGroupSize() > 0,
           "Update group size must be positive.");
 
-      Set<Integer> instances;
       Set<Integer> desiredInstances = instructions.isSetDesiredState()
           ? expandInstanceIds(ImmutableSet.of(instructions.getDesiredState()))
           : ImmutableSet.of();
 
-      if (settings.getUpdateOnlyTheseInstances().isEmpty()) {
-        // In a full job update, the working set is the union of instance IDs 
before and after.
-        instances =  ImmutableSet.copyOf(
-            Sets.union(expandInstanceIds(instructions.getInitialState()), 
desiredInstances));
-      } else {
-        instances = 
Numbers.rangesToInstanceIds(settings.getUpdateOnlyTheseInstances());
-      }
+      Set<Integer> instances = ImmutableSet.copyOf(
+          Sets.union(expandInstanceIds(instructions.getInitialState()), 
desiredInstances));
 
       ImmutableMap.Builder<Integer, StateEvaluator<Optional<IScheduledTask>>> 
evaluators =
           ImmutableMap.builder();

http://git-wip-us.apache.org/repos/asf/aurora/blob/8613f7b4/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 d987974..12ee5b8 100644
--- a/src/test/java/org/apache/aurora/scheduler/updater/JobUpdaterIT.java
+++ b/src/test/java/org/apache/aurora/scheduler/updater/JobUpdaterIT.java
@@ -767,11 +767,11 @@ public class JobUpdaterIT extends EasyMockTest {
     control.replay();
 
     JobUpdate builder =
-        setInstanceCount(makeJobUpdate(makeInstanceConfig(0, 1, OLD_CONFIG)), 
1).newBuilder();
+        setInstanceCount(makeJobUpdate(makeInstanceConfig(0, 0, OLD_CONFIG)), 
1).newBuilder();
     builder.getInstructions().getSettings().setUpdateOnlyTheseInstances(
         ImmutableSet.of(new Range(0, 0)));
     IJobUpdate update = IJobUpdate.build(builder);
-    insertInitialTasks(update);
+    insertPendingTasks(OLD_CONFIG, ImmutableSet.of(0, 1));
 
     changeState(JOB, 0, ASSIGNED, STARTING, RUNNING);
     changeState(JOB, 1, ASSIGNED, STARTING, RUNNING);
@@ -792,6 +792,37 @@ public class JobUpdaterIT extends EasyMockTest {
   }
 
   @Test
+  public void testUpdateSpecificInstancesSkipUnchanged() throws Exception {
+    control.replay();
+
+    JobUpdate builder = makeJobUpdate().newBuilder();
+
+    
builder.getInstructions().getDesiredState().setInstances(ImmutableSet.of(new 
Range(1, 1)));
+    builder.getInstructions().getSettings().setUpdateOnlyTheseInstances(
+        ImmutableSet.of(new Range(0, 1)));
+    IJobUpdate update = IJobUpdate.build(builder);
+    insertPendingTasks(NEW_CONFIG, ImmutableSet.of(0));
+    insertPendingTasks(OLD_CONFIG, ImmutableSet.of(2));
+
+    changeState(JOB, 0, ASSIGNED, STARTING, RUNNING);
+    changeState(JOB, 2, ASSIGNED, STARTING, RUNNING);
+    clock.advance(WATCH_TIMEOUT);
+
+    // Instance 1 is added, while instance 0 is skipped
+    updater.start(update, AUDIT);
+    changeState(JOB, 1, ASSIGNED, STARTING, RUNNING);
+    clock.advance(WATCH_TIMEOUT);
+
+    ImmutableMultimap.Builder<Integer, JobUpdateAction> actions = 
ImmutableMultimap.builder();
+    assertState(
+        ROLLED_FORWARD,
+        actions.putAll(1, INSTANCE_UPDATING, INSTANCE_UPDATED).build());
+    assertJobState(
+        JOB,
+        ImmutableMap.of(0, NEW_CONFIG, 1, NEW_CONFIG, 2, OLD_CONFIG));
+  }
+
+  @Test
   public void testRollback() throws Exception {
     expectTaskKilled().times(4);
 

http://git-wip-us.apache.org/repos/asf/aurora/blob/8613f7b4/src/test/java/org/apache/aurora/scheduler/updater/UpdateFactoryImplTest.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/aurora/scheduler/updater/UpdateFactoryImplTest.java 
b/src/test/java/org/apache/aurora/scheduler/updater/UpdateFactoryImplTest.java
index 0b193c4..c31e082 100644
--- 
a/src/test/java/org/apache/aurora/scheduler/updater/UpdateFactoryImplTest.java
+++ 
b/src/test/java/org/apache/aurora/scheduler/updater/UpdateFactoryImplTest.java
@@ -30,18 +30,14 @@ import static org.junit.Assert.assertEquals;
 
 /**
  * This test can't exercise much functionality of the output from the factory 
without duplicating
- * test behavior in the job updater integration test.  So instead, we test 
only some basic behavior.
+ * test behavior in the job updater integration test. So instead, we test only 
some basic behavior.
  */
 public class UpdateFactoryImplTest {
 
   private static final IJobUpdateInstructions INSTRUCTIONS = 
IJobUpdateInstructions.build(
       new JobUpdateInstructions()
-          .setDesiredState(new InstanceTaskConfig()
-              .setTask(new TaskConfig())
-              .setInstances(ImmutableSet.of(new Range(0, 2))))
-          .setInitialState(ImmutableSet.of(new InstanceTaskConfig()
-              .setTask(new TaskConfig())
-              .setInstances(ImmutableSet.of(new Range(1, 2)))))
+          .setDesiredState(instanceConfig(new Range(0, 2)))
+          .setInitialState(ImmutableSet.of(instanceConfig(new Range(1, 2))))
           .setSettings(new JobUpdateSettings()
               .setMaxFailedInstances(1)
               .setMaxPerInstanceFailures(1)
@@ -72,19 +68,23 @@ public class UpdateFactoryImplTest {
   @Test
   public void testRollForwardSpecificInstances() throws Exception {
     JobUpdateInstructions config = INSTRUCTIONS.newBuilder();
-    config.getSettings().setUpdateOnlyTheseInstances(ImmutableSet.of(new 
Range(1, 2)));
+    config.setInitialState(ImmutableSet.of());
+    config.setDesiredState(instanceConfig(new Range(1, 1)));
+    config.getSettings().setUpdateOnlyTheseInstances(ImmutableSet.of(new 
Range(0, 1)));
 
     Update update = factory.newUpdate(IJobUpdateInstructions.build(config), 
true);
-    assertEquals(ImmutableSet.of(1, 2), update.getUpdater().getInstances());
+    assertEquals(ImmutableSet.of(1), update.getUpdater().getInstances());
   }
 
   @Test
   public void testRollBackSpecificInstances() throws Exception {
     JobUpdateInstructions config = INSTRUCTIONS.newBuilder();
-    config.getSettings().setUpdateOnlyTheseInstances(ImmutableSet.of(new 
Range(1, 2)));
+    config.setInitialState(ImmutableSet.of());
+    config.setDesiredState(instanceConfig(new Range(1, 1)));
+    config.getSettings().setUpdateOnlyTheseInstances(ImmutableSet.of(new 
Range(0, 1)));
 
     Update update = factory.newUpdate(IJobUpdateInstructions.build(config), 
false);
-    assertEquals(ImmutableSet.of(1, 2), update.getUpdater().getInstances());
+    assertEquals(ImmutableSet.of(1), update.getUpdater().getInstances());
   }
 
   @Test
@@ -95,4 +95,10 @@ public class UpdateFactoryImplTest {
     Update update = factory.newUpdate(IJobUpdateInstructions.build(config), 
true);
     assertEquals(ImmutableSet.of(0, 1, 2), update.getUpdater().getInstances());
   }
+
+  private static InstanceTaskConfig instanceConfig(Range instances) {
+    return new InstanceTaskConfig()
+        .setTask(new TaskConfig())
+        .setInstances(ImmutableSet.of(instances));
+  }
 }

Reply via email to