Return-Path: X-Original-To: apmail-aurora-commits-archive@minotaur.apache.org Delivered-To: apmail-aurora-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9251D10FD1 for ; Mon, 3 Feb 2014 22:13:51 +0000 (UTC) Received: (qmail 10901 invoked by uid 500); 3 Feb 2014 22:13:50 -0000 Delivered-To: apmail-aurora-commits-archive@aurora.apache.org Received: (qmail 10866 invoked by uid 500); 3 Feb 2014 22:13:50 -0000 Mailing-List: contact commits-help@aurora.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@aurora.incubator.apache.org Delivered-To: mailing list commits@aurora.incubator.apache.org Received: (qmail 10859 invoked by uid 99); 3 Feb 2014 22:13:50 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Feb 2014 22:13:50 +0000 X-ASF-Spam-Status: No, hits=-2000.5 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 03 Feb 2014 22:13:46 +0000 Received: (qmail 4804 invoked by uid 99); 3 Feb 2014 22:13:08 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Feb 2014 22:13:08 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id DB4A2918A2F; Mon, 3 Feb 2014 22:13:07 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: maxim@apache.org To: commits@aurora.incubator.apache.org Message-Id: <42ff2da1564443f6a37eca2bd6c4ae99@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: Adding DRAINING state into api.thrift. Date: Mon, 3 Feb 2014 22:13:07 +0000 (UTC) X-Virus-Checked: Checked by ClamAV on apache.org 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 Authored: Mon Feb 3 14:11:41 2014 -0800 Committer: Maxim Khutornenko 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.of()) + .setTaskLinks(ImmutableMap.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