You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aurora.apache.org by wf...@apache.org on 2016/03/30 21:18:51 UTC

aurora git commit: Use correct query to serve /maintenance.

Repository: aurora
Updated Branches:
  refs/heads/master ec29ac16f -> c3a3e5ccb


Use correct query to serve /maintenance.

Fixes the 2 issues identified in AURORA-1652.

Bugs closed: AURORA-1652

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


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

Branch: refs/heads/master
Commit: c3a3e5ccba89ab583aeb7381a19445ae32991ba9
Parents: ec29ac1
Author: Bill Farner <wf...@apache.org>
Authored: Wed Mar 30 12:15:17 2016 -0700
Committer: Bill Farner <bi...@docker.com>
Committed: Wed Mar 30 12:15:17 2016 -0700

----------------------------------------------------------------------
 config/legacy_untested_classes.txt              |  4 -
 .../aurora/scheduler/http/Maintenance.java      | 25 +++---
 .../aurora/scheduler/http/MaintenanceTest.java  | 86 ++++++++++++++++++++
 3 files changed, 100 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aurora/blob/c3a3e5cc/config/legacy_untested_classes.txt
----------------------------------------------------------------------
diff --git a/config/legacy_untested_classes.txt b/config/legacy_untested_classes.txt
index afe954f..00e1666 100644
--- a/config/legacy_untested_classes.txt
+++ b/config/legacy_untested_classes.txt
@@ -19,10 +19,6 @@ org/apache/aurora/scheduler/http/AbortCallback
 org/apache/aurora/scheduler/http/JerseyTemplateServlet
 org/apache/aurora/scheduler/http/LogConfig
 org/apache/aurora/scheduler/http/LogConfig$LoggerConfig
-org/apache/aurora/scheduler/http/Maintenance
-org/apache/aurora/scheduler/http/Maintenance$1
-org/apache/aurora/scheduler/http/Maintenance$2
-org/apache/aurora/scheduler/http/Maintenance$3
 org/apache/aurora/scheduler/http/Offers
 org/apache/aurora/scheduler/http/Offers$1
 org/apache/aurora/scheduler/http/Offers$2

http://git-wip-us.apache.org/repos/asf/aurora/blob/c3a3e5cc/src/main/java/org/apache/aurora/scheduler/http/Maintenance.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/http/Maintenance.java b/src/main/java/org/apache/aurora/scheduler/http/Maintenance.java
index 72c8c3e..f928405 100644
--- a/src/main/java/org/apache/aurora/scheduler/http/Maintenance.java
+++ b/src/main/java/org/apache/aurora/scheduler/http/Maintenance.java
@@ -23,9 +23,10 @@ import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
-import com.google.common.base.Function;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableMultimap;
 import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Maps;
+import com.google.common.collect.Iterables;
 import com.google.common.collect.Multimap;
 import com.google.common.collect.Multimaps;
 
@@ -62,24 +63,26 @@ public class Maintenance {
             Multimaps.index(
                 storeProvider.getAttributeStore().getHostAttributes(),
                 IHostAttributes::getMode),
-            HOST_NAME);
+              IHostAttributes::getHost);
 
-      Map<MaintenanceMode, Object> hosts = Maps.newHashMap();
-      hosts.put(DRAINED, ImmutableSet.copyOf(hostsByMode.get(DRAINED)));
-      hosts.put(SCHEDULED, ImmutableSet.copyOf(hostsByMode.get(SCHEDULED)));
-      hosts.put(DRAINING, getTasksByHosts(storeProvider, hostsByMode.get(DRAINING)).asMap());
+      Map<MaintenanceMode, Object> hosts = ImmutableMap.of(
+          DRAINED, ImmutableSet.copyOf(hostsByMode.get(DRAINED)),
+          SCHEDULED, ImmutableSet.copyOf(hostsByMode.get(SCHEDULED)),
+          DRAINING, getTasksByHosts(storeProvider, hostsByMode.get(DRAINING)).asMap());
       return Response.ok(hosts).build();
     });
   }
 
   private Multimap<String, String> getTasksByHosts(StoreProvider provider, Iterable<String> hosts) {
+    if (Iterables.isEmpty(hosts)) {
+      return ImmutableMultimap.of();
+    }
+
     ImmutableSet.Builder<IScheduledTask> drainingTasks = ImmutableSet.builder();
-    drainingTasks.addAll(provider.getTaskStore().fetchTasks(Query.slaveScoped(hosts).active()));
+    drainingTasks.addAll(provider.getTaskStore()
+        .fetchTasks(Query.slaveScoped(hosts).byStatus(Tasks.SLAVE_ASSIGNED_STATES)));
     return Multimaps.transformValues(
         Multimaps.index(drainingTasks.build(), Tasks::scheduledToSlaveHost),
         Tasks::id);
   }
-
-  private static final Function<IHostAttributes, String> HOST_NAME =
-      IHostAttributes::getHost;
 }

http://git-wip-us.apache.org/repos/asf/aurora/blob/c3a3e5cc/src/test/java/org/apache/aurora/scheduler/http/MaintenanceTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/http/MaintenanceTest.java b/src/test/java/org/apache/aurora/scheduler/http/MaintenanceTest.java
new file mode 100644
index 0000000..f94b58b
--- /dev/null
+++ b/src/test/java/org/apache/aurora/scheduler/http/MaintenanceTest.java
@@ -0,0 +1,86 @@
+/**
+ * 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.http;
+
+import java.util.Map;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+
+import org.apache.aurora.gen.HostAttributes;
+import org.apache.aurora.gen.MaintenanceMode;
+import org.apache.aurora.gen.ScheduleStatus;
+import org.apache.aurora.gen.ScheduledTask;
+import org.apache.aurora.scheduler.base.TaskTestUtil;
+import org.apache.aurora.scheduler.storage.Storage;
+import org.apache.aurora.scheduler.storage.Storage.MutateWork.NoResult.Quiet;
+import org.apache.aurora.scheduler.storage.db.DbUtil;
+import org.apache.aurora.scheduler.storage.entities.IHostAttributes;
+import org.apache.aurora.scheduler.storage.entities.IScheduledTask;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.apache.aurora.gen.MaintenanceMode.DRAINED;
+import static org.apache.aurora.gen.MaintenanceMode.DRAINING;
+import static org.apache.aurora.gen.MaintenanceMode.SCHEDULED;
+import static org.junit.Assert.assertEquals;
+
+public class MaintenanceTest {
+
+  private Storage storage;
+  private Maintenance maintenance;
+
+  @Before
+  public void setUp() {
+    storage = DbUtil.createStorage();
+    maintenance = new Maintenance(storage);
+  }
+
+  @Test
+  public void testNoDrainingHosts() {
+    // Test for regression of AURORA-1652.
+
+    storage.write((Quiet) storeProvider -> {
+      ScheduledTask pending = TaskTestUtil.makeTask("a", TaskTestUtil.JOB)
+          .newBuilder()
+          .setStatus(ScheduleStatus.PENDING);
+
+      storeProvider.getAttributeStore().saveHostAttributes(IHostAttributes.build(
+          new HostAttributes()
+              .setHost("b")
+              .setSlaveId("b")
+              .setMode(MaintenanceMode.NONE)
+      ));
+      ScheduledTask assigned = TaskTestUtil.makeTask("b", TaskTestUtil.JOB)
+          .newBuilder()
+          .setStatus(ScheduleStatus.ASSIGNED);
+      assigned.getAssignedTask()
+          .setInstanceId(0)
+          .setSlaveHost("b")
+          .setSlaveId("b");
+
+      storeProvider.getUnsafeTaskStore().saveTasks(
+          IScheduledTask.setFromBuilders(ImmutableList.of(pending, assigned)));
+    });
+
+    @SuppressWarnings("unchecked")
+    Map<MaintenanceMode, Object> result =
+        (Map<MaintenanceMode, Object>) maintenance.getHosts().getEntity();
+
+    assertEquals(ImmutableSet.of(), result.get(SCHEDULED));
+    assertEquals(ImmutableSet.of(), result.get(DRAINED));
+    assertEquals(ImmutableMap.of(), result.get(DRAINING));
+  }
+}