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-1616: [part 2] make tier_config mandatory argument when starting up the scheduler.
Date Fri, 04 Mar 2016 22:47:19 GMT
Repository: aurora
Updated Branches:
  refs/heads/master c624414b5 -> a91a759d0


AURORA-1616: [part 2] make tier_config mandatory argument when starting up the scheduler.

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


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

Branch: refs/heads/master
Commit: a91a759d0a92727a8b0434bbe5d581b8a5289bf3
Parents: c624414
Author: Amol Deshmukh <amol@apache.org>
Authored: Fri Mar 4 14:42:44 2016 -0800
Committer: Maxim Khutornenko <maxim@apache.org>
Committed: Fri Mar 4 14:42:44 2016 -0800

----------------------------------------------------------------------
 docs/deploying-aurora-scheduler.md              |  2 +-
 .../upstart/aurora-scheduler-kerberos.conf      |  2 +-
 examples/vagrant/upstart/aurora-scheduler.conf  |  2 +-
 .../aurora/benchmark/SchedulingBenchmarks.java  |  9 +--
 .../aurora/benchmark/StatusUpdateBenchmark.java |  8 +--
 .../apache/aurora/scheduler/TierManager.java    | 19 +++---
 .../org/apache/aurora/scheduler/TierModule.java | 46 ++++++++-------
 .../aurora/scheduler/base/TaskTestUtil.java     |  3 +
 .../org/apache/aurora/scheduler/tiers.json      | 13 +++++
 .../aurora/scheduler/SchedulerModuleTest.java   | 44 --------------
 .../aurora/scheduler/TierManagerTest.java       | 35 ++++-------
 .../apache/aurora/scheduler/TierModuleTest.java | 61 ++++++++++++++++++++
 .../aurora/scheduler/app/SchedulerIT.java       |  3 +-
 .../org/apache/aurora/scheduler/tiers.json      |  9 ---
 14 files changed, 131 insertions(+), 125 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aurora/blob/a91a759d/docs/deploying-aurora-scheduler.md
----------------------------------------------------------------------
diff --git a/docs/deploying-aurora-scheduler.md b/docs/deploying-aurora-scheduler.md
index 883e0f3..10952ef 100644
--- a/docs/deploying-aurora-scheduler.md
+++ b/docs/deploying-aurora-scheduler.md
@@ -250,7 +250,7 @@ Specify a tier configuration file path:
 
     -tier_config=path/to/tiers/config.json
 
-Example [tier configuration file](../src/test/resources/org/apache/aurora/scheduler/tiers.json).
+Default [tier configuration file](../src/main/resources/org/apache/aurora/scheduler/tiers.json).
 
 ### Maintaining an Aurora Installation
 

http://git-wip-us.apache.org/repos/asf/aurora/blob/a91a759d/examples/vagrant/upstart/aurora-scheduler-kerberos.conf
----------------------------------------------------------------------
diff --git a/examples/vagrant/upstart/aurora-scheduler-kerberos.conf b/examples/vagrant/upstart/aurora-scheduler-kerberos.conf
index d57ef37..eec5ee3 100644
--- a/examples/vagrant/upstart/aurora-scheduler-kerberos.conf
+++ b/examples/vagrant/upstart/aurora-scheduler-kerberos.conf
@@ -53,4 +53,4 @@ exec bin/aurora-scheduler \
   -kerberos_server_keytab=/home/vagrant/krb5-1.13.1/build/testdir/HTTP-aurora.local.keytab
\
   -kerberos_server_principal=HTTP/aurora.local@KRBTEST.COM \
   -enable_h2_console=true \
-  -tier_config=/home/vagrant/aurora/src/test/resources/org/apache/aurora/scheduler/tiers.json
+  -tier_config=/home/vagrant/aurora/src/main/resources/org/apache/aurora/scheduler/tiers.json

http://git-wip-us.apache.org/repos/asf/aurora/blob/a91a759d/examples/vagrant/upstart/aurora-scheduler.conf
----------------------------------------------------------------------
diff --git a/examples/vagrant/upstart/aurora-scheduler.conf b/examples/vagrant/upstart/aurora-scheduler.conf
index 54fcde6..7e10b2c 100644
--- a/examples/vagrant/upstart/aurora-scheduler.conf
+++ b/examples/vagrant/upstart/aurora-scheduler.conf
@@ -46,6 +46,6 @@ exec bin/aurora-scheduler \
   -use_beta_db_task_store=true \
   -shiro_ini_path=etc/shiro.example.ini \
   -enable_h2_console=true \
-  -tier_config=/home/vagrant/aurora/src/test/resources/org/apache/aurora/scheduler/tiers.json
\
+  -tier_config=/home/vagrant/aurora/src/main/resources/org/apache/aurora/scheduler/tiers.json
\
   -mesos_role=aurora-role \
   -receive_revocable_resources=true

http://git-wip-us.apache.org/repos/asf/aurora/blob/a91a759d/src/jmh/java/org/apache/aurora/benchmark/SchedulingBenchmarks.java
----------------------------------------------------------------------
diff --git a/src/jmh/java/org/apache/aurora/benchmark/SchedulingBenchmarks.java b/src/jmh/java/org/apache/aurora/benchmark/SchedulingBenchmarks.java
index 45ab76b..1d725c0 100644
--- a/src/jmh/java/org/apache/aurora/benchmark/SchedulingBenchmarks.java
+++ b/src/jmh/java/org/apache/aurora/benchmark/SchedulingBenchmarks.java
@@ -35,9 +35,10 @@ import org.apache.aurora.common.util.Clock;
 import org.apache.aurora.common.util.testing.FakeClock;
 import org.apache.aurora.scheduler.HostOffer;
 import org.apache.aurora.scheduler.TaskIdGenerator;
-import org.apache.aurora.scheduler.TierManager;
+import org.apache.aurora.scheduler.TierModule;
 import org.apache.aurora.scheduler.async.AsyncModule;
 import org.apache.aurora.scheduler.async.DelayExecutor;
+import org.apache.aurora.scheduler.base.TaskTestUtil;
 import org.apache.aurora.scheduler.configuration.executor.ExecutorSettings;
 import org.apache.aurora.scheduler.events.EventSink;
 import org.apache.aurora.scheduler.filter.SchedulingFilter;
@@ -109,6 +110,7 @@ public class SchedulingBenchmarks {
       Injector injector = Guice.createInjector(
           new StateModule(),
           new PreemptorModule(true, NO_DELAY, NO_DELAY),
+          new TierModule(TaskTestUtil.DEV_TIER_CONFIG),
           new PrivateModule() {
             @Override
             protected void configure() {
@@ -133,11 +135,6 @@ public class SchedulingBenchmarks {
                   new BiCache.BiCacheSettings(DELAY_FOREVER, ""));
               bind(TaskScheduler.class).to(TaskScheduler.TaskSchedulerImpl.class);
               bind(TaskScheduler.TaskSchedulerImpl.class).in(Singleton.class);
-              bind(TierManager.class).to(TierManager.TierManagerImpl.class);
-              bind(TierManager.TierManagerImpl.class).in(Singleton.class);
-              bind(TierManager.TierManagerImpl.TierConfig.class)
-                  .toInstance(TierManager.TierManagerImpl.TierConfig.EMPTY);
-              expose(TierManager.class);
               expose(TaskScheduler.class);
               expose(OfferManager.class);
             }

http://git-wip-us.apache.org/repos/asf/aurora/blob/a91a759d/src/jmh/java/org/apache/aurora/benchmark/StatusUpdateBenchmark.java
----------------------------------------------------------------------
diff --git a/src/jmh/java/org/apache/aurora/benchmark/StatusUpdateBenchmark.java b/src/jmh/java/org/apache/aurora/benchmark/StatusUpdateBenchmark.java
index f408453..f6c8e9f 100644
--- a/src/jmh/java/org/apache/aurora/benchmark/StatusUpdateBenchmark.java
+++ b/src/jmh/java/org/apache/aurora/benchmark/StatusUpdateBenchmark.java
@@ -49,8 +49,9 @@ import org.apache.aurora.gen.ScheduleStatus;
 import org.apache.aurora.scheduler.TaskIdGenerator;
 import org.apache.aurora.scheduler.TaskStatusHandler;
 import org.apache.aurora.scheduler.TaskStatusHandlerImpl;
-import org.apache.aurora.scheduler.TierManager;
+import org.apache.aurora.scheduler.TierModule;
 import org.apache.aurora.scheduler.base.AsyncUtil;
+import org.apache.aurora.scheduler.base.TaskTestUtil;
 import org.apache.aurora.scheduler.configuration.executor.ExecutorSettings;
 import org.apache.aurora.scheduler.events.EventSink;
 import org.apache.aurora.scheduler.events.PubsubEvent;
@@ -172,6 +173,7 @@ public class StatusUpdateBenchmark {
 
     Injector injector = Guice.createInjector(
         new StateModule(),
+        new TierModule(TaskTestUtil.DEV_TIER_CONFIG),
         new AbstractModule() {
           @Override
           protected void configure() {
@@ -215,10 +217,6 @@ public class StatusUpdateBenchmark {
                 .toInstance(1000);
             bind(TaskStatusHandler.class).to(TaskStatusHandlerImpl.class);
             bind(TaskStatusHandlerImpl.class).in(Singleton.class);
-            bind(TierManager.class).to(TierManager.TierManagerImpl.class);
-            bind(TierManager.TierManagerImpl.class).in(Singleton.class);
-            bind(TierManager.TierManagerImpl.TierConfig.class)
-                .toInstance(TierManager.TierManagerImpl.TierConfig.EMPTY);
           }
         }
     );

http://git-wip-us.apache.org/repos/asf/aurora/blob/a91a759d/src/main/java/org/apache/aurora/scheduler/TierManager.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/TierManager.java b/src/main/java/org/apache/aurora/scheduler/TierManager.java
index fce6e51..480c485 100644
--- a/src/main/java/org/apache/aurora/scheduler/TierManager.java
+++ b/src/main/java/org/apache/aurora/scheduler/TierManager.java
@@ -24,9 +24,10 @@ import org.apache.aurora.scheduler.storage.entities.ITaskConfig;
 import org.codehaus.jackson.annotate.JsonCreator;
 import org.codehaus.jackson.annotate.JsonProperty;
 
+import static java.lang.String.format;
 import static java.util.Objects.requireNonNull;
 
-import static org.apache.aurora.scheduler.TierInfo.DEFAULT;
+import static com.google.common.base.Preconditions.checkArgument;
 
 /**
  * Translates job tier configuration into a set of task traits/attributes.
@@ -46,14 +47,12 @@ public interface TierManager {
 
     @VisibleForTesting
     public static class TierConfig {
-      @VisibleForTesting
-      public static final TierConfig EMPTY = new TierConfig(ImmutableMap.of());
-
       private final Map<String, TierInfo> tiers;
 
       @VisibleForTesting
       @JsonCreator
       public TierConfig(@JsonProperty("tiers") Map<String, TierInfo> tiers) {
+        checkArgument(!tiers.isEmpty(), "Tiers cannot be empty.");
         this.tiers = ImmutableMap.copyOf(tiers);
       }
 
@@ -70,14 +69,12 @@ public interface TierManager {
 
     @Override
     public TierInfo getTier(ITaskConfig taskConfig) {
-      if (taskConfig.isSetTier()) {
-        // The default behavior in case of tier config file absence or tier name mismatch
is to use
-        // non-revocable resources. This is subject to change once the feature is ready.
-        // Tracked by AURORA-1443.
-        return tierConfig.tiers.getOrDefault(taskConfig.getTier(), DEFAULT);
-      }
+      checkArgument(
+          !taskConfig.isSetTier() || tierConfig.tiers.containsKey(taskConfig.getTier()),
+          format("Invalid tier '%s' in TaskConfig.", taskConfig.getTier()));
 
-      return DEFAULT;
+      // Backward compatibility mode until tier is required in TaskConfig (AURORA-1624).
+      return taskConfig.isSetTier() ? tierConfig.tiers.get(taskConfig.getTier()) : TierInfo.DEFAULT;
     }
   }
 }

http://git-wip-us.apache.org/repos/asf/aurora/blob/a91a759d/src/main/java/org/apache/aurora/scheduler/TierModule.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/TierModule.java b/src/main/java/org/apache/aurora/scheduler/TierModule.java
index b5f065e..d956664 100644
--- a/src/main/java/org/apache/aurora/scheduler/TierModule.java
+++ b/src/main/java/org/apache/aurora/scheduler/TierModule.java
@@ -18,9 +18,10 @@ import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Optional;
+import com.google.common.base.Strings;
 import com.google.common.base.Throwables;
 import com.google.common.io.Files;
+import com.google.common.io.Resources;
 import com.google.inject.AbstractModule;
 
 import org.apache.aurora.common.args.Arg;
@@ -34,12 +35,17 @@ import org.slf4j.LoggerFactory;
 
 import static java.util.Objects.requireNonNull;
 
+import static com.google.common.base.Preconditions.checkArgument;
+
 /**
  * Binding module for tier management.
  */
 public class TierModule extends AbstractModule {
   private static final Logger LOG = LoggerFactory.getLogger(TierModule.class);
 
+  @VisibleForTesting
+  static final String TIER_CONFIG_PATH = "org/apache/aurora/scheduler/tiers.json";
+
   @CanRead
   @CmdLine(name = "tier_config",
       help = "Configuration file defining supported task tiers, task traits and behaviors.")
@@ -61,29 +67,27 @@ public class TierModule extends AbstractModule {
     bind(TierManager.class).toInstance(new TierManagerImpl(tierConfig));
   }
 
-  static Optional<String> readTierFile() {
-    if (TIER_CONFIG_FILE.hasAppliedValue()) {
-      try {
-        return Optional.of(Files.toString(TIER_CONFIG_FILE.get(), StandardCharsets.UTF_8));
-      } catch (IOException e) {
-        LOG.error("Error loading tier configuration file.");
-        throw Throwables.propagate(e);
-      }
+  static String readTierFile() {
+    try {
+      return TIER_CONFIG_FILE.hasAppliedValue()
+          ? Files.toString(TIER_CONFIG_FILE.get(), StandardCharsets.UTF_8)
+          : Resources.toString(
+              TierModule.class.getClassLoader().getResource(TIER_CONFIG_PATH),
+              StandardCharsets.UTF_8);
+    } catch (IOException e) {
+      LOG.error("Error loading tier configuration file.");
+      throw Throwables.propagate(e);
     }
-
-    return Optional.<String>absent();
   }
 
   @VisibleForTesting
-  static TierConfig parseTierConfig(Optional<String> config) {
-    Optional<TierConfig> map = config.transform(input -> {
-      try {
-        return new ObjectMapper().readValue(input, TierConfig.class);
-      } catch (IOException e) {
-        LOG.error("Error parsing tier configuration file.");
-        throw Throwables.propagate(e);
-      }
-    });
-    return map.or(TierConfig.EMPTY);
+  static TierConfig parseTierConfig(String config) {
+    checkArgument(!Strings.isNullOrEmpty(config), "configuration cannot be empty");
+    try {
+      return new ObjectMapper().readValue(config, TierConfig.class);
+    } catch (IOException e) {
+      LOG.error("Error parsing tier configuration file.");
+      throw Throwables.propagate(e);
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/aurora/blob/a91a759d/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 4c64a1c..1de6966 100644
--- a/src/main/java/org/apache/aurora/scheduler/base/TaskTestUtil.java
+++ b/src/main/java/org/apache/aurora/scheduler/base/TaskTestUtil.java
@@ -35,6 +35,7 @@ import org.apache.aurora.gen.TaskConstraint;
 import org.apache.aurora.gen.TaskEvent;
 import org.apache.aurora.gen.ValueConstraint;
 import org.apache.aurora.scheduler.TierInfo;
+import org.apache.aurora.scheduler.TierManager.TierManagerImpl.TierConfig;
 import org.apache.aurora.scheduler.configuration.ConfigurationManager;
 import org.apache.aurora.scheduler.storage.entities.IJobKey;
 import org.apache.aurora.scheduler.storage.entities.IScheduledTask;
@@ -50,6 +51,8 @@ public final class TaskTestUtil {
 
   public static final IJobKey JOB = JobKeys.from("role", "env", "job");
   public static final TierInfo REVOCABLE_TIER = new TierInfo(true);
+  public static final TierConfig DEV_TIER_CONFIG =
+      new TierConfig(ImmutableMap.of("tier-dev", new TierInfo(false)));
   public static final ConfigurationManager CONFIGURATION_MANAGER =
       new ConfigurationManager(ImmutableSet.of(_Fields.MESOS), false, ImmutableMultimap.of());
 

http://git-wip-us.apache.org/repos/asf/aurora/blob/a91a759d/src/main/resources/org/apache/aurora/scheduler/tiers.json
----------------------------------------------------------------------
diff --git a/src/main/resources/org/apache/aurora/scheduler/tiers.json b/src/main/resources/org/apache/aurora/scheduler/tiers.json
new file mode 100644
index 0000000..1870105
--- /dev/null
+++ b/src/main/resources/org/apache/aurora/scheduler/tiers.json
@@ -0,0 +1,13 @@
+{
+  "tiers":
+  {
+    "preferred":
+    {
+      "revocable": false
+    },
+    "revocable":
+    {
+      "revocable": true
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/aurora/blob/a91a759d/src/test/java/org/apache/aurora/scheduler/SchedulerModuleTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/SchedulerModuleTest.java b/src/test/java/org/apache/aurora/scheduler/SchedulerModuleTest.java
deleted file mode 100644
index aa6e035..0000000
--- a/src/test/java/org/apache/aurora/scheduler/SchedulerModuleTest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * 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;
-
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableMap;
-
-import org.junit.Test;
-
-import static org.apache.aurora.scheduler.TierModule.parseTierConfig;
-import static org.apache.aurora.scheduler.base.TaskTestUtil.REVOCABLE_TIER;
-import static org.junit.Assert.assertEquals;
-
-public class SchedulerModuleTest {
-  @Test
-  public void testNoTierConfigFile() {
-    assertEquals(ImmutableMap.of(), parseTierConfig(Optional.absent()).getTiers());
-  }
-
-  @Test
-  public void testTierConfigFile() {
-    assertEquals(
-        ImmutableMap.of("revocable", REVOCABLE_TIER),
-        parseTierConfig(Optional.of("{\"tiers\":{\"revocable\": {\"revocable\": true}}}"))
-            .getTiers());
-  }
-
-  @Test(expected = RuntimeException.class)
-  public void testTierConfigExtraKeysNotAllowed() {
-    parseTierConfig(
-        Optional.of("{\"tiers\":{\"revocable\": {\"revocable\": true, \"foo\": false}}}"));
-  }
-}

http://git-wip-us.apache.org/repos/asf/aurora/blob/a91a759d/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 4da829f..a662100 100644
--- a/src/test/java/org/apache/aurora/scheduler/TierManagerTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/TierManagerTest.java
@@ -13,52 +13,39 @@
  */
 package org.apache.aurora.scheduler;
 
-import com.google.common.base.Optional;
-
 import org.apache.aurora.gen.TaskConfig;
 import org.apache.aurora.scheduler.TierManager.TierManagerImpl;
-import org.apache.aurora.scheduler.TierManager.TierManagerImpl.TierConfig;
 import org.apache.aurora.scheduler.storage.entities.ITaskConfig;
 import org.junit.Test;
 
-import static org.apache.aurora.scheduler.TierInfo.DEFAULT;
 import static org.apache.aurora.scheduler.TierModule.parseTierConfig;
 import static org.apache.aurora.scheduler.base.TaskTestUtil.REVOCABLE_TIER;
 import static org.junit.Assert.assertEquals;
 
 public class TierManagerTest {
-
   @Test
   public void testRevocable() {
     TierManager manager = new TierManagerImpl(
-        parseTierConfig(Optional.of("{\"tiers\":{\"revocable\": {\"revocable\": true}}}")));
+        parseTierConfig("{\"tiers\":{"
+            + "\"revocable\": {\"revocable\": true},"
+            + "\"preferred\": {\"revocable\": false}"
+            + "}}"));
     assertEquals(
         REVOCABLE_TIER,
         manager.getTier(ITaskConfig.build(new TaskConfig().setTier("revocable"))));
   }
 
-  @Test
+  @Test(expected = IllegalArgumentException.class)
   public void testNameMismatch() {
     TierManager manager = new TierManagerImpl(
-        parseTierConfig(Optional.of("{\"tiers\":{\"revocable\": {\"revocable\": true}}}")));
-    assertEquals(
-        DEFAULT,
-        manager.getTier(ITaskConfig.build(new TaskConfig().setTier("Revocable"))));
+        parseTierConfig("{\"tiers\":{\"revocable\": {\"revocable\": true}}}"));
+    manager.getTier(ITaskConfig.build(new TaskConfig().setTier("Revocable")));
   }
 
   @Test
-  public void testDefaultTier() {
-    TierManager manager = new TierManagerImpl(TierConfig.EMPTY);
-    assertEquals(
-        DEFAULT,
-        manager.getTier(ITaskConfig.build(new TaskConfig().setTier("revocable"))));
-  }
-
-  @Test
-  public void testNoTier() {
-    TierManager manager = new TierManagerImpl(TierConfig.EMPTY);
-    assertEquals(
-        DEFAULT,
-        manager.getTier(ITaskConfig.build(new TaskConfig())));
+  public void testNoTierInTaskConfig() {
+    TierManager manager = new TierManagerImpl(
+        parseTierConfig("{\"tiers\":{\"revocable\": {\"revocable\": true}}}"));
+    assertEquals(TierInfo.DEFAULT, manager.getTier(ITaskConfig.build(new TaskConfig())));
   }
 }

http://git-wip-us.apache.org/repos/asf/aurora/blob/a91a759d/src/test/java/org/apache/aurora/scheduler/TierModuleTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/TierModuleTest.java b/src/test/java/org/apache/aurora/scheduler/TierModuleTest.java
new file mode 100644
index 0000000..e0601c8
--- /dev/null
+++ b/src/test/java/org/apache/aurora/scheduler/TierModuleTest.java
@@ -0,0 +1,61 @@
+/**
+ * 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;
+
+import java.io.File;
+import java.nio.charset.StandardCharsets;
+
+import com.google.common.base.Strings;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.io.Files;
+
+import org.junit.Test;
+
+import static org.apache.aurora.scheduler.TierModule.TIER_CONFIG_PATH;
+import static org.apache.aurora.scheduler.TierModule.parseTierConfig;
+import static org.apache.aurora.scheduler.TierModule.readTierFile;
+import static org.apache.aurora.scheduler.base.TaskTestUtil.REVOCABLE_TIER;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+public class TierModuleTest {
+
+  @Test
+  public void testTierConfigArgumentNotSpecified() throws Exception {
+    String tierFileContents = readTierFile();
+    assertFalse(Strings.isNullOrEmpty(tierFileContents));
+    assertEquals(
+        tierFileContents,
+        Files.toString(
+            new File(TierModule.class.getClassLoader().getResource(TIER_CONFIG_PATH).getFile()),
+            StandardCharsets.UTF_8));
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testEmptyTierConfigFile() {
+    parseTierConfig("");
+  }
+
+  @Test
+  public void testTierConfigFile() {
+    assertEquals(
+        ImmutableMap.of("revocable", REVOCABLE_TIER),
+        parseTierConfig("{\"tiers\":{\"revocable\": {\"revocable\": true}}}").getTiers());
+  }
+
+  @Test(expected = RuntimeException.class)
+  public void testTierConfigExtraKeysNotAllowed() {
+    parseTierConfig("{\"tiers\":{\"revocable\": {\"revocable\": true, \"foo\": false}}}");
+  }
+}

http://git-wip-us.apache.org/repos/asf/aurora/blob/a91a759d/src/test/java/org/apache/aurora/scheduler/app/SchedulerIT.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/app/SchedulerIT.java b/src/test/java/org/apache/aurora/scheduler/app/SchedulerIT.java
index 7ee31fd..918a3da 100644
--- a/src/test/java/org/apache/aurora/scheduler/app/SchedulerIT.java
+++ b/src/test/java/org/apache/aurora/scheduler/app/SchedulerIT.java
@@ -61,7 +61,6 @@ import org.apache.aurora.gen.storage.Transaction;
 import org.apache.aurora.gen.storage.storageConstants;
 import org.apache.aurora.scheduler.AppStartup;
 import org.apache.aurora.scheduler.ResourceSlot;
-import org.apache.aurora.scheduler.TierManager.TierManagerImpl.TierConfig;
 import org.apache.aurora.scheduler.TierModule;
 import org.apache.aurora.scheduler.base.TaskTestUtil;
 import org.apache.aurora.scheduler.configuration.executor.ExecutorSettings;
@@ -202,7 +201,7 @@ public class SchedulerIT extends BaseZooKeeperTest {
     Injector injector = Guice.createInjector(
         ImmutableList.<Module>builder()
             .add(SchedulerMain.getUniversalModule())
-            .add(new TierModule(TierConfig.EMPTY))
+            .add(new TierModule(TaskTestUtil.DEV_TIER_CONFIG))
             .add(new LogStorageModule())
             .add(new ZooKeeperClientModule(zkClientConfig))
             .add(new ServiceDiscoveryModule(SERVERSET_PATH, credentials))

http://git-wip-us.apache.org/repos/asf/aurora/blob/a91a759d/src/test/resources/org/apache/aurora/scheduler/tiers.json
----------------------------------------------------------------------
diff --git a/src/test/resources/org/apache/aurora/scheduler/tiers.json b/src/test/resources/org/apache/aurora/scheduler/tiers.json
deleted file mode 100644
index 2140773..0000000
--- a/src/test/resources/org/apache/aurora/scheduler/tiers.json
+++ /dev/null
@@ -1,9 +0,0 @@
-{
-  "tiers":
-  {
-    "revocable":
-    {
-      "revocable": true
-    }
-  }
-}


Mime
View raw message