You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aurora.apache.org by ma...@apache.org on 2014/02/03 23:13:07 UTC
git commit: Adding DRAINING state into api.thrift.
Updated Branches:
refs/heads/master 01eda7531 -> 9dce3b3d1
Adding DRAINING state into api.thrift.
Splitting this work into 2 steps to ensure schema compatibility between releases.
Step1: Adding DRAINING state into api.thrift and rewriting DRAINING to RESTARTING in StorageBackfill.
To come:
Step2: Implement support for DRAINING in state machine.
Testing Done:
gradle clean build
Reviewed at https://reviews.apache.org/r/17666/
Project: http://git-wip-us.apache.org/repos/asf/incubator-aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-aurora/commit/9dce3b3d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-aurora/tree/9dce3b3d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-aurora/diff/9dce3b3d
Branch: refs/heads/master
Commit: 9dce3b3d15ac509c6aa390b6539b1370acf767a6
Parents: 01eda75
Author: Maxim Khutornenko <ma...@apache.org>
Authored: Mon Feb 3 14:11:41 2014 -0800
Committer: Maxim Khutornenko <mk...@twitter.com>
Committed: Mon Feb 3 14:11:41 2014 -0800
----------------------------------------------------------------------
.../scheduler/storage/StorageBackfill.java | 13 +++
.../thrift/org/apache/aurora/gen/api.thrift | 2 +
.../scheduler/state/TaskStateMachineTest.java | 8 +-
.../scheduler/storage/StorageBackfillTest.java | 87 ++++++++++++++++++++
.../org/apache/aurora/gen/api.thrift.md5 | 2 +-
5 files changed, 110 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9dce3b3d/src/main/java/org/apache/aurora/scheduler/storage/StorageBackfill.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/StorageBackfill.java b/src/main/java/org/apache/aurora/scheduler/storage/StorageBackfill.java
index 3ce5bd3..aa54659 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/StorageBackfill.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/StorageBackfill.java
@@ -102,6 +102,18 @@ public final class StorageBackfill {
}
/**
+ * Ensures backwards-compatibility of the DRAINING state, which exists in this version but is
+ * not handled.
+ *
+ * @param task Task to possibly rewrite.
+ */
+ private static void rewriteDrainingState(ScheduledTask task) {
+ if (ScheduleStatus.DRAINING == task.getStatus()) {
+ task.setStatus(ScheduleStatus.RESTARTING);
+ }
+ }
+
+ /**
* Backfills the storage to make it match any assumptions that may have changed since
* the structs were first written.
*
@@ -119,6 +131,7 @@ public final class StorageBackfill {
// TODO(ksweeney): Guarantee tasks pass current validation code here and quarantine if they
// don't.
guaranteeShardUniqueness(builder, storeProvider.getUnsafeTaskStore(), clock);
+ rewriteDrainingState(builder);
return IScheduledTask.build(builder);
}
});
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9dce3b3d/src/main/thrift/org/apache/aurora/gen/api.thrift
----------------------------------------------------------------------
diff --git a/src/main/thrift/org/apache/aurora/gen/api.thrift b/src/main/thrift/org/apache/aurora/gen/api.thrift
index 94569f9..77cd09e 100644
--- a/src/main/thrift/org/apache/aurora/gen/api.thrift
+++ b/src/main/thrift/org/apache/aurora/gen/api.thrift
@@ -245,6 +245,8 @@ enum ScheduleStatus {
PREEMPTING = 13,
// The task is being restarted in response to a user request.
RESTARTING = 12,
+ // The task is being restarted in response to a host maintenance request.
+ DRAINING = 17,
// The task terminated with a non-zero exit code.
FAILED = 4,
// Execution of the task was terminated by the system.
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9dce3b3d/src/test/java/org/apache/aurora/scheduler/state/TaskStateMachineTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/state/TaskStateMachineTest.java b/src/test/java/org/apache/aurora/scheduler/state/TaskStateMachineTest.java
index 153f82c..cc7d59d 100644
--- a/src/test/java/org/apache/aurora/scheduler/state/TaskStateMachineTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/state/TaskStateMachineTest.java
@@ -39,6 +39,7 @@ import org.junit.Before;
import org.junit.Test;
import static org.apache.aurora.gen.ScheduleStatus.ASSIGNED;
+import static org.apache.aurora.gen.ScheduleStatus.DRAINING;
import static org.apache.aurora.gen.ScheduleStatus.FAILED;
import static org.apache.aurora.gen.ScheduleStatus.FINISHED;
import static org.apache.aurora.gen.ScheduleStatus.INIT;
@@ -510,8 +511,13 @@ public class TaskStateMachineTest {
machine = new TaskStateMachine("name");
}
+ // TODO(maximk): Drop when DRAINING support is implemented.
+ if (from == DRAINING || to == DRAINING) {
+ continue;
+ }
+
assertEquals(
- "Unexpected behavor for " + testCase,
+ "Unexpected behavior for " + testCase,
expectation,
machine.updateState(to));
}
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9dce3b3d/src/test/java/org/apache/aurora/scheduler/storage/StorageBackfillTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/StorageBackfillTest.java b/src/test/java/org/apache/aurora/scheduler/storage/StorageBackfillTest.java
new file mode 100644
index 0000000..f6ece9c
--- /dev/null
+++ b/src/test/java/org/apache/aurora/scheduler/storage/StorageBackfillTest.java
@@ -0,0 +1,87 @@
+/**
+ * Copyright 2014 Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.aurora.scheduler.storage;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+import com.twitter.common.util.testing.FakeClock;
+
+import org.apache.aurora.gen.AssignedTask;
+import org.apache.aurora.gen.Constraint;
+import org.apache.aurora.gen.Identity;
+import org.apache.aurora.gen.LimitConstraint;
+import org.apache.aurora.gen.ScheduleStatus;
+import org.apache.aurora.gen.ScheduledTask;
+import org.apache.aurora.gen.TaskConfig;
+import org.apache.aurora.gen.TaskConstraint;
+import org.apache.aurora.scheduler.base.Query;
+import org.apache.aurora.scheduler.storage.entities.IScheduledTask;
+import org.apache.aurora.scheduler.storage.mem.MemStorage;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class StorageBackfillTest {
+
+ private Storage storage;
+ private FakeClock clock;
+
+ @Before
+ public void setUp() {
+ storage = MemStorage.newEmptyStorage();
+ clock = new FakeClock();
+ }
+
+ @Test
+ public void testRewriteDrainingState() {
+ final String taskId = "id";
+ final IScheduledTask savedTask =
+ IScheduledTask.build(makeTask(taskId).newBuilder().setStatus(ScheduleStatus.DRAINING));
+
+ storage.write(new Storage.MutateWork.NoResult.Quiet() {
+ @Override protected void execute(Storage.MutableStoreProvider storeProvider) {
+ storeProvider.getUnsafeTaskStore().saveTasks(ImmutableSet.of(savedTask));
+ StorageBackfill.backfill(storeProvider, clock);
+ }
+ });
+
+ assertEquals(
+ IScheduledTask.build(savedTask.newBuilder().setStatus(ScheduleStatus.RESTARTING)),
+ Iterables.getOnlyElement(Storage.Util.consistentFetchTasks(
+ storage,
+ Query.taskScoped(taskId))));
+ }
+
+ private static IScheduledTask makeTask(String id) {
+ TaskConfig config = new TaskConfig()
+ .setOwner(new Identity("user", "role"))
+ .setEnvironment("test")
+ .setJobName("jobName")
+ .setProduction(false)
+ .setRequestedPorts(ImmutableSet.<String>of())
+ .setTaskLinks(ImmutableMap.<String, String>of())
+ .setMaxTaskFailures(1)
+ .setConstraints(ImmutableSet.of(
+ new Constraint("host", TaskConstraint.limit(new LimitConstraint(1)))));
+
+ ScheduledTask task = new ScheduledTask().setAssignedTask(new AssignedTask().setTask(config));
+ task.getAssignedTask().setTaskId(id);
+
+ return IScheduledTask.build(task);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9dce3b3d/src/test/resources/org/apache/aurora/gen/api.thrift.md5
----------------------------------------------------------------------
diff --git a/src/test/resources/org/apache/aurora/gen/api.thrift.md5 b/src/test/resources/org/apache/aurora/gen/api.thrift.md5
index e88d297..10fcf08 100644
--- a/src/test/resources/org/apache/aurora/gen/api.thrift.md5
+++ b/src/test/resources/org/apache/aurora/gen/api.thrift.md5
@@ -1 +1 @@
-28ec7c76c1f5d4ed162fc7f13cf0d0ff
+5eb4a77a6a99b6836e099825fafd56e2