aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject git commit: Allow optional initial and desired states.
Date Tue, 23 Sep 2014 21:12:22 GMT
Repository: incubator-aurora
Updated Branches:
  refs/heads/master 79e7ec512 -> f0660a547


Allow optional initial and desired states.

Bugs closed: AURORA-741

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


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

Branch: refs/heads/master
Commit: f0660a547599b738d02eef5d2412d1eae7155bc8
Parents: 79e7ec5
Author: Maxim Khutornenko <maxim@apache.org>
Authored: Tue Sep 23 14:12:06 2014 -0700
Committer: Maxim Khutornenko <maxim@apache.org>
Committed: Tue Sep 23 14:12:06 2014 -0700

----------------------------------------------------------------------
 .../scheduler/storage/db/DBJobUpdateStore.java  | 42 +++++++----
 .../storage/db/JobUpdateDetailsMapper.xml       | 28 ++++----
 .../storage/db/DBJobUpdateStoreTest.java        | 76 ++++++++++++++++----
 3 files changed, 102 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/f0660a54/src/main/java/org/apache/aurora/scheduler/storage/db/DBJobUpdateStore.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/db/DBJobUpdateStore.java b/src/main/java/org/apache/aurora/scheduler/storage/db/DBJobUpdateStore.java
index 361d3b8..15a9e2b 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/db/DBJobUpdateStore.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/db/DBJobUpdateStore.java
@@ -21,6 +21,7 @@ import javax.inject.Inject;
 import com.google.common.base.Function;
 import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableSet;
+import com.twitter.common.base.MorePreconditions;
 
 import org.apache.aurora.gen.JobUpdate;
 import org.apache.aurora.gen.JobUpdateInstructions;
@@ -67,6 +68,11 @@ public class DBJobUpdateStore implements JobUpdateStore.Mutable {
   @Override
   public void saveJobUpdate(IJobUpdate update, Optional<String> lockToken) {
     requireNonNull(update);
+    if (!update.getInstructions().isSetDesiredState()
+        && update.getInstructions().getInitialState().isEmpty()) {
+      throw new IllegalArgumentException(
+          "Missing both initial and desired states. At least one is required.");
+    }
 
     jobKeyMapper.merge(update.getSummary().getJobKey().newBuilder());
     detailsMapper.insert(update.newBuilder());
@@ -85,23 +91,29 @@ public class DBJobUpdateStore implements JobUpdateStore.Mutable {
     }
 
     // Insert desired state task config and instance mappings.
-    IInstanceTaskConfig desired = update.getInstructions().getDesiredState();
-    detailsMapper.insertTaskConfig(
-        updateId,
-        desired.getTask().newBuilder(),
-        true,
-        new InsertResult());
-
-    detailsMapper.insertDesiredInstances(updateId, IRange.toBuildersSet(desired.getInstances()));
+    if (update.getInstructions().isSetDesiredState()) {
+      IInstanceTaskConfig desired = update.getInstructions().getDesiredState();
+      detailsMapper.insertTaskConfig(
+          updateId,
+          desired.getTask().newBuilder(),
+          true,
+          new InsertResult());
+
+      detailsMapper.insertDesiredInstances(
+          updateId,
+          IRange.toBuildersSet(MorePreconditions.checkNotBlank(desired.getInstances())));
+    }
 
     // Insert initial state task configs and instance mappings.
-    for (IInstanceTaskConfig config : update.getInstructions().getInitialState()) {
-      InsertResult result = new InsertResult();
-      detailsMapper.insertTaskConfig(updateId, config.getTask().newBuilder(), false, result);
-
-      detailsMapper.insertTaskConfigInstances(
-          result.getId(),
-          IRange.toBuildersSet(config.getInstances()));
+    if (!update.getInstructions().getInitialState().isEmpty()) {
+      for (IInstanceTaskConfig config : update.getInstructions().getInitialState()) {
+        InsertResult result = new InsertResult();
+        detailsMapper.insertTaskConfig(updateId, config.getTask().newBuilder(), false, result);
+
+        detailsMapper.insertTaskConfigInstances(
+            result.getId(),
+            IRange.toBuildersSet(MorePreconditions.checkNotBlank(config.getInstances())));
+      }
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/f0660a54/src/main/resources/org/apache/aurora/scheduler/storage/db/JobUpdateDetailsMapper.xml
----------------------------------------------------------------------
diff --git a/src/main/resources/org/apache/aurora/scheduler/storage/db/JobUpdateDetailsMapper.xml
b/src/main/resources/org/apache/aurora/scheduler/storage/db/JobUpdateDetailsMapper.xml
index 8053543..e1179b4 100644
--- a/src/main/resources/org/apache/aurora/scheduler/storage/db/JobUpdateDetailsMapper.xml
+++ b/src/main/resources/org/apache/aurora/scheduler/storage/db/JobUpdateDetailsMapper.xml
@@ -298,7 +298,7 @@
       u.max_wait_to_instance_running_ms AS jui_juse_max_wait_to_instance_running_ms,
       u.min_wait_in_instance_running_ms AS jui_juse_min_wait_in_instance_running_ms,
       u.rollback_on_failure AS jui_juse_rollback_on_failure,
-      cn.id AS jui_id,
+      u.id AS jui_id,
       cn.id AS jui_ditc_id,
       cn.task_config AS jui_ditc_task,
       di.id AS jui_ditc_r_id,
@@ -314,16 +314,16 @@
       io.last AS jui_juse_r_last
   </sql>
 
-  <sql id="job_update_to_configs_inner_joins">
+  <sql id="job_update_inner_joins">
     FROM job_updates AS u
     INNER JOIN job_keys AS j ON j.id = u.job_key_id
-    INNER JOIN job_update_configs AS cn ON cn.update_id = u.id AND cn.is_new = TRUE
-    INNER JOIN job_update_configs AS co ON co.update_id = u.id AND co.is_new = FALSE
-    INNER JOIN job_update_configs_to_instances AS ci ON ci.config_id = co.id
-    INNER JOIN job_updates_to_desired_instances AS di ON di.update_id = u.id
   </sql>
 
-  <sql id="job_update_to_instance_overrides_outer_join">
+  <sql id="job_update_outer_joins">
+    LEFT OUTER JOIN job_update_configs AS cn ON cn.update_id = u.id AND cn.is_new = TRUE
+    LEFT OUTER JOIN job_update_configs AS co ON co.update_id = u.id AND co.is_new = FALSE
+    LEFT OUTER JOIN job_update_configs_to_instances AS ci ON ci.config_id = co.id
+    LEFT OUTER JOIN job_updates_to_desired_instances AS di ON di.update_id = u.id
     LEFT OUTER JOIN job_updates_to_instance_overrides AS io ON io.update_id = u.id
   </sql>
 
@@ -338,9 +338,9 @@
       i.instance_id AS i_instance_id,
       i.timestamp_ms AS i_timestamp_ms,
       l.lock_token AS lock_token
-    <include refid="job_update_to_configs_inner_joins" />
+    <include refid="job_update_inner_joins" />
     <include refid="timestamps_inner_joins" />
-    <include refid="job_update_to_instance_overrides_outer_join" />
+    <include refid="job_update_outer_joins" />
     LEFT OUTER JOIN job_update_events AS e ON e.update_id = u.id
     LEFT OUTER JOIN job_instance_update_events AS i ON i.update_id = u.id
     LEFT OUTER JOIN job_update_locks AS l on l.update_id = u.id
@@ -358,7 +358,7 @@
       u.max_wait_to_instance_running_ms AS juse_max_wait_to_instance_running_ms,
       u.min_wait_in_instance_running_ms AS juse_min_wait_in_instance_running_ms,
       u.rollback_on_failure AS juse_rollback_on_failure,
-      cn.id AS id,
+      u.id AS id,
       cn.id AS ditc_id,
       cn.task_config AS ditc_task,
       di.id AS ditc_r_id,
@@ -372,17 +372,17 @@
       io.id AS juse_r_id,
       io.first AS juse_r_first,
       io.last AS juse_r_last
-    <include refid="job_update_to_configs_inner_joins" />
-    <include refid="job_update_to_instance_overrides_outer_join" />
+    <include refid="job_update_inner_joins" />
+    <include refid="job_update_outer_joins" />
     WHERE u.update_id = #{id}
   </select>
 
   <select id="selectUpdate" resultMap="jobUpdateMap">
     SELECT
       <include refid="job_update_columns" />
-    <include refid="job_update_to_configs_inner_joins" />
+    <include refid="job_update_inner_joins" />
     <include refid="timestamps_inner_joins" />
-    <include refid="job_update_to_instance_overrides_outer_join" />
+    <include refid="job_update_outer_joins" />
     WHERE u.update_id = #{id}
   </select>
 

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/f0660a54/src/test/java/org/apache/aurora/scheduler/storage/db/DBJobUpdateStoreTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/db/DBJobUpdateStoreTest.java
b/src/test/java/org/apache/aurora/scheduler/storage/db/DBJobUpdateStoreTest.java
index aa7feb9..553ef4d 100644
--- a/src/test/java/org/apache/aurora/scheduler/storage/db/DBJobUpdateStoreTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/storage/db/DBJobUpdateStoreTest.java
@@ -108,12 +108,69 @@ public class DBJobUpdateStoreTest {
     assertUpdate(update2);
   }
 
-  @Test(expected = StorageException.class)
-  public void testSaveWithEmptyDesiredStateInstancesThrows() {
+  @Test
+  public void testSaveNullInitialState() {
+    JobUpdate builder = makeJobUpdate(JOB, "u1").newBuilder();
+    builder.getInstructions().unsetInitialState();
+
+    // Save with null initial state instances.
+    saveUpdate(IJobUpdate.build(builder), Optional.of("lock"));
+
+    builder.getInstructions().setInitialState(ImmutableSet.<InstanceTaskConfig>of());
+    assertUpdate(IJobUpdate.build(builder));
+  }
+
+  @Test
+  public void testSaveNullDesiredState() {
+    JobUpdate builder = makeJobUpdate(JOB, "u1").newBuilder();
+    builder.getInstructions().unsetDesiredState();
+
+    // Save with null desired state instances.
+    saveUpdate(IJobUpdate.build(builder), Optional.of("lock"));
+
+    assertUpdate(IJobUpdate.build(builder));
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testSaveBothInitialAndDesiredMissingThrows() {
+    JobUpdate builder = makeJobUpdate(JOB, "u1").newBuilder();
+    builder.getInstructions().unsetInitialState();
+    builder.getInstructions().unsetDesiredState();
+
+    saveUpdate(IJobUpdate.build(builder), Optional.of("lock"));
+  }
+
+  @Test(expected = NullPointerException.class)
+  public void testSaveNullInitialStateTaskThrows() {
+    JobUpdate builder = makeJobUpdate(JOB, "u1").newBuilder();
+    builder.getInstructions().getInitialState().add(
+        new InstanceTaskConfig(null, ImmutableSet.<Range>of()));
+
+    saveUpdate(IJobUpdate.build(builder), Optional.of("lock"));
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testSaveEmptyInitialStateRangesThrows() {
+    JobUpdate builder = makeJobUpdate(JOB, "u1").newBuilder();
+    builder.getInstructions().getInitialState().add(
+        new InstanceTaskConfig(new TaskConfig(), ImmutableSet.<Range>of()));
+
+    saveUpdate(IJobUpdate.build(builder), Optional.of("lock"));
+  }
+
+  @Test(expected = NullPointerException.class)
+  public void testSaveNullDesiredStateTaskThrows() {
+    JobUpdate builder = makeJobUpdate(JOB, "u1").newBuilder();
+    builder.getInstructions().getDesiredState().setTask(null);
+
+    saveUpdate(IJobUpdate.build(builder), Optional.of("lock"));
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testSaveEmptyDesiredStateRangesThrows() {
     JobUpdate builder = makeJobUpdate(JOB, "u1").newBuilder();
     builder.getInstructions().getDesiredState().setInstances(ImmutableSet.<Range>of());
 
-    // Save with empty desired state instances.
     saveUpdate(IJobUpdate.build(builder), Optional.of("lock"));
   }
 
@@ -480,22 +537,11 @@ public class DBJobUpdateStoreTest {
         getSummaries(new JobUpdateQuery().setRole("no_match")));
   }
 
-  @Test
-  public void testGetConfiguration() {
-    String updateId = "u1";
-
-    IJobUpdate update = makeJobUpdate(JobKeys.from("role", "env", "name1"), updateId);
-
-    assertEquals(Optional.<IJobUpdateInstructions>absent(), getUpdateInstructions(updateId));
-
-    saveUpdate(update, Optional.of("lock1"));
-    assertEquals(Optional.of(makeJobUpdateInstructions()), getUpdateInstructions(updateId));
-  }
-
   private void assertUpdate(IJobUpdate expected) {
     String updateId = expected.getSummary().getUpdateId();
     assertEquals(populateExpected(expected), getUpdate(updateId).get());
     assertEquals(getUpdate(updateId).get(), getUpdateDetails(updateId).get().getUpdate());
+    assertEquals(getUpdateInstructions(updateId).get(), expected.getInstructions());
   }
 
   private Optional<IJobUpdate> getUpdate(final String updateId) {


Mime
View raw message