aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject aurora git commit: AURORA-1725 Expose tier configurations as a debug page
Date Tue, 28 Jun 2016 22:56:46 GMT
Repository: aurora
Updated Branches:
  refs/heads/master 499b11bde -> 102f5f0a9


AURORA-1725 Expose tier configurations as a debug page

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


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

Branch: refs/heads/master
Commit: 102f5f0a98ee38b9637d1962d4e5d6a2171fb75f
Parents: 499b11b
Author: Mehrdad Nurolahzade <mehrdad@nurolahzade.com>
Authored: Tue Jun 28 15:56:38 2016 -0700
Committer: Maxim Khutornenko <maxim@apache.org>
Committed: Tue Jun 28 15:56:38 2016 -0700

----------------------------------------------------------------------
 .../aurora/scheduler/base/TaskTestUtil.java     |  9 +++
 .../scheduler/http/JettyServerModule.java       |  2 +
 .../org/apache/aurora/scheduler/http/Tiers.java | 54 ++++++++++++++++++
 src/main/resources/scheduler/assets/index.html  |  1 +
 .../aurora/scheduler/TierManagerTest.java       |  8 +--
 .../scheduler/http/AbstractJettyTest.java       |  2 +
 .../apache/aurora/scheduler/http/TiersTest.java | 60 ++++++++++++++++++++
 7 files changed, 130 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aurora/blob/102f5f0a/src/main/java/org/apache/aurora/scheduler/base/TaskTestUtil.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/base/TaskTestUtil.java b/src/main/java/org/apache/aurora/scheduler/base/TaskTestUtil.java
index 4089b79..8103163 100644
--- a/src/main/java/org/apache/aurora/scheduler/base/TaskTestUtil.java
+++ b/src/main/java/org/apache/aurora/scheduler/base/TaskTestUtil.java
@@ -160,6 +160,15 @@ public final class TaskTestUtil {
     return IScheduledTask.build(builder);
   }
 
+  public static String tierConfigFile() {
+    return "{\"default\": \"preemptible\","
+        + "\"tiers\":{"
+        + "\"preferred\": {\"revocable\": false, \"preemptible\": false},"
+        + "\"preemptible\": {\"revocable\": false, \"preemptible\": true},"
+        + "\"revocable\": {\"revocable\": true, \"preemptible\": true}"
+        + "}}";
+  }
+
   public static Map<String, TierInfo> tierInfos() {
     return ImmutableMap.of(
         "preferred", PREFERRED_TIER,

http://git-wip-us.apache.org/repos/asf/aurora/blob/102f5f0a/src/main/java/org/apache/aurora/scheduler/http/JettyServerModule.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/http/JettyServerModule.java b/src/main/java/org/apache/aurora/scheduler/http/JettyServerModule.java
index 496cd55..12185ec 100644
--- a/src/main/java/org/apache/aurora/scheduler/http/JettyServerModule.java
+++ b/src/main/java/org/apache/aurora/scheduler/http/JettyServerModule.java
@@ -212,6 +212,7 @@ public class JettyServerModule extends AbstractModule {
       "pendingtasks",
       "quotas",
       "slaves",
+      "tiers",
       "utilization"
   );
 
@@ -233,6 +234,7 @@ public class JettyServerModule extends AbstractModule {
           .put(Services.class, "services")
           .put(StructDump.class, "structdump")
           .put(ThreadStackPrinter.class, "threads")
+          .put(Tiers.class, "tiers")
           .put(TimeSeriesDataSource.class, "graphdata")
           .put(Utilization.class, "utilization")
           .put(VarsHandler.class, "vars")

http://git-wip-us.apache.org/repos/asf/aurora/blob/102f5f0a/src/main/java/org/apache/aurora/scheduler/http/Tiers.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/http/Tiers.java b/src/main/java/org/apache/aurora/scheduler/http/Tiers.java
new file mode 100644
index 0000000..8a587ed
--- /dev/null
+++ b/src/main/java/org/apache/aurora/scheduler/http/Tiers.java
@@ -0,0 +1,54 @@
+/**
+ * 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.Objects;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.inject.Inject;
+
+import org.apache.aurora.scheduler.TierManager;
+
+/*
+ * HTTP interface that exposes tier configurations of scheduler.
+ */
+@Path("/tiers")
+public class Tiers {
+
+  private final TierManager tierManager;
+
+  @Inject
+  Tiers(TierManager tierManager) {
+    this.tierManager = Objects.requireNonNull(tierManager);
+  }
+
+  /**
+   * Dumps tier configuration file (tiers.json).
+   *
+   * @return HTTP response.
+   */
+  @GET
+  @Produces(MediaType.APPLICATION_JSON)
+  public Response getTiers() {
+    ImmutableMap<String, Object> tierConfigurations = ImmutableMap.of(
+        "default", tierManager.getDefaultTierName(),
+        "tiers", tierManager.getTiers());
+    return Response.ok(tierConfigurations).build();
+  }
+}

http://git-wip-us.apache.org/repos/asf/aurora/blob/102f5f0a/src/main/resources/scheduler/assets/index.html
----------------------------------------------------------------------
diff --git a/src/main/resources/scheduler/assets/index.html b/src/main/resources/scheduler/assets/index.html
index eca27e0..9bd22a8 100644
--- a/src/main/resources/scheduler/assets/index.html
+++ b/src/main/resources/scheduler/assets/index.html
@@ -64,6 +64,7 @@
       <li><a href='/offers'>/offers</a></li>
       <li><a href='/pendingtasks'>/pendingtasks</a></li>
       <li><a href='/quotas'>/quotas</a></li>
+      <li><a href='/tiers'>/tiers</a></li>
       <li><a href='/utilization'>/utilization</a></li>
     </ul>
 

http://git-wip-us.apache.org/repos/asf/aurora/blob/102f5f0a/src/test/java/org/apache/aurora/scheduler/TierManagerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/TierManagerTest.java b/src/test/java/org/apache/aurora/scheduler/TierManagerTest.java
index 7d9b333..82e40d5 100644
--- a/src/test/java/org/apache/aurora/scheduler/TierManagerTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/TierManagerTest.java
@@ -19,6 +19,7 @@ import com.google.common.collect.ImmutableMap;
 
 import org.apache.aurora.gen.TaskConfig;
 import org.apache.aurora.scheduler.TierManager.TierManagerImpl;
+import org.apache.aurora.scheduler.base.TaskTestUtil;
 import org.apache.aurora.scheduler.storage.entities.ITaskConfig;
 import org.junit.Test;
 
@@ -37,12 +38,7 @@ public class TierManagerTest {
       PREEMPTIBLE_TIER_NAME, DEV_TIER,
       REVOCABLE_TIER_NAME, REVOCABLE_TIER);
   private static final TierManager TIER_MANAGER = new TierManagerImpl(
-      parseTierConfig("{\"default\": \"preemptible\","
-          + "\"tiers\":{"
-          + "\"preferred\": {\"revocable\": false, \"preemptible\": false},"
-          + "\"preemptible\": {\"revocable\": false, \"preemptible\": true},"
-          + "\"revocable\": {\"revocable\": true, \"preemptible\": true}"
-          + "}}"));
+      parseTierConfig(TaskTestUtil.tierConfigFile()));
 
   @Test
   public void testGetTierRevocable() {

http://git-wip-us.apache.org/repos/asf/aurora/blob/102f5f0a/src/test/java/org/apache/aurora/scheduler/http/AbstractJettyTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/http/AbstractJettyTest.java b/src/test/java/org/apache/aurora/scheduler/http/AbstractJettyTest.java
index 561b134..7dbe48b 100644
--- a/src/test/java/org/apache/aurora/scheduler/http/AbstractJettyTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/http/AbstractJettyTest.java
@@ -46,6 +46,7 @@ import org.apache.aurora.common.util.BackoffStrategy;
 import org.apache.aurora.gen.ServerInfo;
 import org.apache.aurora.scheduler.AppStartup;
 import org.apache.aurora.scheduler.SchedulerServicesModule;
+import org.apache.aurora.scheduler.TierManager;
 import org.apache.aurora.scheduler.app.LifecycleModule;
 import org.apache.aurora.scheduler.app.ServiceGroupMonitor;
 import org.apache.aurora.scheduler.async.AsyncModule;
@@ -125,6 +126,7 @@ public abstract class AbstractJettyTest extends EasyMockTest {
             bindMock(OfferManager.class);
             bindMock(RescheduleCalculator.class);
             bindMock(TaskScheduler.class);
+            bindMock(TierManager.class);
             bindMock(Thread.UncaughtExceptionHandler.class);
 
             bind(ServletContextListener.class).toProvider(() -> {

http://git-wip-us.apache.org/repos/asf/aurora/blob/102f5f0a/src/test/java/org/apache/aurora/scheduler/http/TiersTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/http/TiersTest.java b/src/test/java/org/apache/aurora/scheduler/http/TiersTest.java
new file mode 100644
index 0000000..23371fc
--- /dev/null
+++ b/src/test/java/org/apache/aurora/scheduler/http/TiersTest.java
@@ -0,0 +1,60 @@
+/**
+ * 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.io.IOException;
+import java.util.Map;
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.core.Response;
+
+import com.google.gson.Gson;
+
+import org.apache.aurora.common.testing.easymock.EasyMockTest;
+import org.apache.aurora.scheduler.TierManager;
+import org.apache.aurora.scheduler.base.TaskTestUtil;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.easymock.EasyMock.expect;
+import static org.junit.Assert.assertEquals;
+
+public class TiersTest extends EasyMockTest {
+
+  private TierManager tierManager;
+  private Tiers tiers;
+
+  @Before
+  public void setUp() {
+    tierManager = createMock(TierManager.class);
+    tiers = new Tiers(tierManager);
+  }
+
+  @Test
+  public void testGetTiers() throws IOException {
+    expect(tierManager.getDefaultTierName()).andReturn("preemptible");
+    expect(tierManager.getTiers()).andReturn(TaskTestUtil.tierInfos());
+
+    control.replay();
+
+    Response response = tiers.getTiers();
+    assertEquals(HttpServletResponse.SC_OK, response.getStatus());
+    String responseAsString = new ObjectMapper().writeValueAsString(response.getEntity());
+    assertEquals(toMap(TaskTestUtil.tierConfigFile()), toMap(responseAsString));
+  }
+
+  private static Map toMap(String json) {
+    return new Gson().fromJson(json, Map.class);
+  }
+}


Mime
View raw message