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-1710 Make 'tier' required and remove support for 'production' flag in Job configuration - Backfill portion
Date Mon, 20 Jun 2016 17:34:15 GMT
Repository: aurora
Updated Branches:
  refs/heads/master e0d64851b -> f6ac13b16


AURORA-1710 Make 'tier' required and remove support for 'production'
flag in Job configuration - Backfill portion

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


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

Branch: refs/heads/master
Commit: f6ac13b169aaad5aad73ef3cc72873781e30a705
Parents: e0d6485
Author: Mehrdad Nurolahzade <mehrdad@nurolahzade.com>
Authored: Mon Jun 20 09:58:51 2016 -0700
Committer: Maxim Khutornenko <maxim@apache.org>
Committed: Mon Jun 20 09:58:51 2016 -0700

----------------------------------------------------------------------
 .../aurora/benchmark/SchedulingBenchmarks.java  |   2 +-
 .../aurora/benchmark/StatusUpdateBenchmark.java |   2 +-
 .../apache/aurora/scheduler/TierManager.java    |  12 +-
 .../aurora/scheduler/base/TaskTestUtil.java     |  47 ++---
 .../configuration/ConfigurationManager.java     |  10 +-
 .../storage/backup/TemporaryStorage.java        |  15 +-
 .../db/migration/V006_PopulateTierField.java    |  51 ++++++
 .../scheduler/storage/log/LogStorage.java       |  17 +-
 .../storage/log/SnapshotStoreImpl.java          |  11 +-
 .../scheduler/storage/log/ThriftBackfill.java   |  47 ++++-
 .../aurora/scheduler/TierManagerTest.java       |  54 ++----
 .../aurora/scheduler/app/SchedulerIT.java       |   2 +-
 .../configuration/ConfigurationManagerTest.java |   9 +-
 .../scheduler/storage/backup/RecoveryTest.java  |   2 +-
 .../scheduler/storage/log/LogStorageTest.java   |   3 +-
 .../storage/log/SnapshotStoreImplIT.java        |   3 +-
 .../storage/log/ThriftBackfillTest.java         | 179 +++++++++++++++++--
 .../aurora/scheduler/thrift/Fixtures.java       |   2 +
 .../thrift/ReadOnlySchedulerImplTest.java       |  26 +--
 .../thrift/SchedulerThriftInterfaceTest.java    |   1 +
 .../aurora/scheduler/thrift/ThriftIT.java       |   3 +-
 21 files changed, 360 insertions(+), 138 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aurora/blob/f6ac13b1/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 65f5edc..9d0d40b 100644
--- a/src/jmh/java/org/apache/aurora/benchmark/SchedulingBenchmarks.java
+++ b/src/jmh/java/org/apache/aurora/benchmark/SchedulingBenchmarks.java
@@ -113,7 +113,7 @@ public class SchedulingBenchmarks {
       Injector injector = Guice.createInjector(
           new StateModule(),
           new PreemptorModule(true, NO_DELAY, NO_DELAY),
-          new TierModule(TaskTestUtil.DEV_TIER_CONFIG),
+          new TierModule(TaskTestUtil.TIER_CONFIG),
           new PrivateModule() {
             @Override
             protected void configure() {

http://git-wip-us.apache.org/repos/asf/aurora/blob/f6ac13b1/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 6fd9ee2..a649239 100644
--- a/src/jmh/java/org/apache/aurora/benchmark/StatusUpdateBenchmark.java
+++ b/src/jmh/java/org/apache/aurora/benchmark/StatusUpdateBenchmark.java
@@ -175,7 +175,7 @@ public class StatusUpdateBenchmark {
 
     Injector injector = Guice.createInjector(
         new StateModule(),
-        new TierModule(TaskTestUtil.DEV_TIER_CONFIG),
+        new TierModule(TaskTestUtil.TIER_CONFIG),
         new AbstractModule() {
           @Override
           protected void configure() {

http://git-wip-us.apache.org/repos/asf/aurora/blob/f6ac13b1/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 af54cab..d808c4c 100644
--- a/src/main/java/org/apache/aurora/scheduler/TierManager.java
+++ b/src/main/java/org/apache/aurora/scheduler/TierManager.java
@@ -91,8 +91,9 @@ public interface TierManager {
       }
     }
 
+    @VisibleForTesting
     @Inject
-    TierManagerImpl(TierConfig tierConfig) {
+    public TierManagerImpl(TierConfig tierConfig) {
       this.tierConfig = requireNonNull(tierConfig);
     }
 
@@ -102,14 +103,7 @@ public interface TierManager {
           !taskConfig.isSetTier() || tierConfig.tiers.containsKey(taskConfig.getTier()),
           format("Invalid tier '%s' in TaskConfig.", taskConfig.getTier()));
 
-      return taskConfig.isSetTier()
-          ? tierConfig.tiers.get(taskConfig.getTier())
-          : tierConfig.getTiers().values().stream()
-              // Backward compatibility mode until tier is required in TaskConfig (AURORA-1624).
-              .filter(v -> v.isPreemptible() == !taskConfig.isProduction() && !v.isRevocable())
-              .findFirst()
-              .orElseThrow(() -> new IllegalStateException(
-                  format("No matching implicit tier for task of job %s", taskConfig.getJob())));
+      return tierConfig.tiers.get(taskConfig.getTier());
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/aurora/blob/f6ac13b1/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 3ea0992..4089b79 100644
--- a/src/main/java/org/apache/aurora/scheduler/base/TaskTestUtil.java
+++ b/src/main/java/org/apache/aurora/scheduler/base/TaskTestUtil.java
@@ -14,6 +14,7 @@
 package org.apache.aurora.scheduler.base;
 
 import java.util.Map;
+import java.util.Set;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
@@ -45,6 +46,7 @@ import org.apache.aurora.scheduler.configuration.ConfigurationManager.Configurat
 import org.apache.aurora.scheduler.storage.entities.IJobKey;
 import org.apache.aurora.scheduler.storage.entities.IScheduledTask;
 import org.apache.aurora.scheduler.storage.entities.ITaskConfig;
+import org.apache.aurora.scheduler.storage.log.ThriftBackfill;
 
 /**
  * Convenience methods for working with tasks.
@@ -61,25 +63,15 @@ public final class TaskTestUtil {
       new TierInfo(true /* preemptible */, false /* revocable */);
   public static final TierInfo PREFERRED_TIER =
       new TierInfo(false /* preemptible */, false /* revocable */);
+  public static final String PROD_TIER_NAME = "tier-prod";
   public static final String DEV_TIER_NAME = "tier-dev";
-  public static final TierConfig DEV_TIER_CONFIG =
-      new TierConfig(DEV_TIER_NAME, ImmutableMap.of(DEV_TIER_NAME, DEV_TIER));
-  public static final TierManager DEV_TIER_MANAGER = new TierManager() {
-    @Override
-    public TierInfo getTier(ITaskConfig taskConfig) {
-      return DEV_TIER;
-    }
-
-    @Override
-    public String getDefaultTierName() {
-      return DEV_TIER_NAME;
-    }
-
-    @Override
-    public Map<String, TierInfo> getTiers() {
-      return ImmutableMap.of(DEV_TIER_NAME, DEV_TIER);
-    }
-  };
+  public static final TierConfig TIER_CONFIG =
+      new TierConfig(DEV_TIER_NAME, ImmutableMap.of(
+          PROD_TIER_NAME, PREFERRED_TIER,
+          DEV_TIER_NAME, DEV_TIER
+      ));
+  public static final TierManager TIER_MANAGER = new TierManager.TierManagerImpl(TIER_CONFIG);
+  public static final ThriftBackfill THRIFT_BACKFILL = new ThriftBackfill(TIER_MANAGER);
   public static final ConfigurationManagerSettings CONFIGURATION_MANAGER_SETTINGS =
       new ConfigurationManagerSettings(
           ImmutableSet.of(_Fields.MESOS),
@@ -88,7 +80,7 @@ public final class TaskTestUtil {
           true,
           true);
   public static final ConfigurationManager CONFIGURATION_MANAGER =
-      new ConfigurationManager(CONFIGURATION_MANAGER_SETTINGS, DEV_TIER_MANAGER);
+      new ConfigurationManager(CONFIGURATION_MANAGER_SETTINGS, TIER_MANAGER, THRIFT_BACKFILL);
 
   private TaskTestUtil() {
     // Utility class.
@@ -105,7 +97,7 @@ public final class TaskTestUtil {
         .setPriority(1)
         .setMaxTaskFailures(-1)
         .setProduction(true)
-        .setTier(DEV_TIER_NAME)
+        .setTier(PROD_TIER_NAME)
         .setConstraints(ImmutableSet.of(
             new Constraint(
                 "valueConstraint",
@@ -167,4 +159,19 @@ public final class TaskTestUtil {
         .setScheduler("scheduler"));
     return IScheduledTask.build(builder);
   }
+
+  public static Map<String, TierInfo> tierInfos() {
+    return ImmutableMap.of(
+        "preferred", PREFERRED_TIER,
+        "preemptible", DEV_TIER,
+        "revocable", REVOCABLE_TIER);
+  }
+
+  public static Set<org.apache.aurora.gen.TierConfig> tierConfigs() {
+    return ImmutableSet.of(
+        new org.apache.aurora.gen.TierConfig("preferred", PREFERRED_TIER.toMap()),
+        new org.apache.aurora.gen.TierConfig("preemptible", DEV_TIER.toMap()),
+        new org.apache.aurora.gen.TierConfig("revocable", REVOCABLE_TIER.toMap())
+    );
+  }
 }

http://git-wip-us.apache.org/repos/asf/aurora/blob/f6ac13b1/src/main/java/org/apache/aurora/scheduler/configuration/ConfigurationManager.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/configuration/ConfigurationManager.java b/src/main/java/org/apache/aurora/scheduler/configuration/ConfigurationManager.java
index 0e95620..fe18c0f 100644
--- a/src/main/java/org/apache/aurora/scheduler/configuration/ConfigurationManager.java
+++ b/src/main/java/org/apache/aurora/scheduler/configuration/ConfigurationManager.java
@@ -134,11 +134,17 @@ public class ConfigurationManager {
 
   private final ConfigurationManagerSettings settings;
   private final TierManager tierManager;
+  private final ThriftBackfill thriftBackfill;
 
   @Inject
-  public ConfigurationManager(ConfigurationManagerSettings settings, TierManager tierManager) {
+  public ConfigurationManager(
+      ConfigurationManagerSettings settings,
+      TierManager tierManager,
+      ThriftBackfill thriftBackfill) {
+
     this.settings = requireNonNull(settings);
     this.tierManager = requireNonNull(tierManager);
+    this.thriftBackfill = requireNonNull(thriftBackfill);
   }
 
   private static String getRole(IValueConstraint constraint) {
@@ -311,7 +317,7 @@ public class ConfigurationManager {
               + containerType.get().toString());
     }
 
-    ThriftBackfill.backfillTask(builder);
+    thriftBackfill.backfillTask(builder);
 
     String types = config.getResources().stream()
         .collect(Collectors.groupingBy(e -> ResourceType.fromResource(e)))

http://git-wip-us.apache.org/repos/asf/aurora/blob/f6ac13b1/src/main/java/org/apache/aurora/scheduler/storage/backup/TemporaryStorage.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/backup/TemporaryStorage.java b/src/main/java/org/apache/aurora/scheduler/storage/backup/TemporaryStorage.java
index d08873c..3fa408e 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/backup/TemporaryStorage.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/backup/TemporaryStorage.java
@@ -17,6 +17,7 @@ import java.util.Set;
 
 import com.google.common.base.Function;
 import com.google.common.collect.FluentIterable;
+import com.google.inject.Inject;
 
 import org.apache.aurora.common.util.BuildInfo;
 import org.apache.aurora.common.util.testing.FakeClock;
@@ -29,6 +30,9 @@ import org.apache.aurora.scheduler.storage.Storage.MutateWork.NoResult;
 import org.apache.aurora.scheduler.storage.db.DbUtil;
 import org.apache.aurora.scheduler.storage.entities.IScheduledTask;
 import org.apache.aurora.scheduler.storage.log.SnapshotStoreImpl;
+import org.apache.aurora.scheduler.storage.log.ThriftBackfill;
+
+import static java.util.Objects.requireNonNull;
 
 import static org.apache.aurora.common.util.testing.FakeBuildInfo.generateBuildInfo;
 
@@ -64,6 +68,14 @@ interface TemporaryStorage {
    * A factory that creates temporary storage instances, detached from the rest of the system.
    */
   class TemporaryStorageFactory implements Function<Snapshot, TemporaryStorage> {
+
+    private final ThriftBackfill thriftBackfill;
+
+    @Inject
+    TemporaryStorageFactory(ThriftBackfill thriftBackfill) {
+      this.thriftBackfill = requireNonNull(thriftBackfill);
+    }
+
     @Override
     public TemporaryStorage apply(Snapshot snapshot) {
       final Storage storage = DbUtil.createFlaggedStorage();
@@ -79,7 +91,8 @@ interface TemporaryStorage {
           false /** useDbSnapshotForTaskStore */,
           // We can just pass an empty lambda for the MigrationManager as migration is a no-op
           // when restoring from backup.
-          () -> { } /** migrationManager */);
+          () -> { } /** migrationManager */,
+          thriftBackfill);
       snapshotStore.applySnapshot(snapshot);
 
       return new TemporaryStorage() {

http://git-wip-us.apache.org/repos/asf/aurora/blob/f6ac13b1/src/main/java/org/apache/aurora/scheduler/storage/db/migration/V006_PopulateTierField.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/db/migration/V006_PopulateTierField.java b/src/main/java/org/apache/aurora/scheduler/storage/db/migration/V006_PopulateTierField.java
new file mode 100644
index 0000000..ac85b54
--- /dev/null
+++ b/src/main/java/org/apache/aurora/scheduler/storage/db/migration/V006_PopulateTierField.java
@@ -0,0 +1,51 @@
+/**
+ * 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.db.migration;
+
+import java.math.BigDecimal;
+
+import org.apache.ibatis.migration.MigrationScript;
+
+public class V006_PopulateTierField implements MigrationScript {
+
+  private static final String PREFERRED_TIER_NAME = "preferred";
+  private static final String PREEMPTIBLE_TIER_NAME = "preemptible";
+
+  @Override
+  public BigDecimal getId() {
+    return BigDecimal.valueOf(6L);
+  }
+
+  @Override
+  public String getDescription() {
+    return "Populate task_configs.tier field.";
+  }
+
+  @Override
+  public String getUpScript() {
+    return "UPDATE task_configs "
+        + String.format(
+            "SET tier = CASEWHEN(production = 1, '%s', '%s') ",
+            PREFERRED_TIER_NAME,
+            PREEMPTIBLE_TIER_NAME)
+        + "WHERE tier IS NULL;";
+  }
+
+  @Override
+  public String getDownScript() {
+    return "UPDATE task_configs "
+        + "SET production = 1 "
+        + String.format("WHERE tier = '%s';", PREFERRED_TIER_NAME);
+  }
+}

http://git-wip-us.apache.org/repos/asf/aurora/blob/f6ac13b1/src/main/java/org/apache/aurora/scheduler/storage/log/LogStorage.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/log/LogStorage.java b/src/main/java/org/apache/aurora/scheduler/storage/log/LogStorage.java
index c981a05..39924c6 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/log/LogStorage.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/log/LogStorage.java
@@ -185,6 +185,7 @@ public class LogStorage implements NonVolatileStorage, DistributedSnapshotStore
   private final AttributeStore.Mutable writeBehindAttributeStore;
   private final JobUpdateStore.Mutable writeBehindJobUpdateStore;
   private final ReentrantLock writeLock;
+  private final ThriftBackfill thriftBackfill;
 
   private StreamManager streamManager;
   private final WriteAheadStorage writeAheadStorage;
@@ -217,7 +218,8 @@ public class LogStorage implements NonVolatileStorage, DistributedSnapshotStore
       @Volatile AttributeStore.Mutable attributeStore,
       @Volatile JobUpdateStore.Mutable jobUpdateStore,
       EventSink eventSink,
-      ReentrantLock writeLock) {
+      ReentrantLock writeLock,
+      ThriftBackfill thriftBackfill) {
 
     this(logManager,
         new ScheduledExecutorSchedulingService(shutdownRegistry, settings.getShutdownGracePeriod()),
@@ -232,7 +234,8 @@ public class LogStorage implements NonVolatileStorage, DistributedSnapshotStore
         attributeStore,
         jobUpdateStore,
         eventSink,
-        writeLock);
+        writeLock,
+        thriftBackfill);
   }
 
   @VisibleForTesting
@@ -250,7 +253,8 @@ public class LogStorage implements NonVolatileStorage, DistributedSnapshotStore
       AttributeStore.Mutable attributeStore,
       JobUpdateStore.Mutable jobUpdateStore,
       EventSink eventSink,
-      ReentrantLock writeLock) {
+      ReentrantLock writeLock,
+      ThriftBackfill thriftBackfill) {
 
     this.logManager = requireNonNull(logManager);
     this.schedulingService = requireNonNull(schedulingService);
@@ -270,6 +274,7 @@ public class LogStorage implements NonVolatileStorage, DistributedSnapshotStore
     this.writeBehindAttributeStore = requireNonNull(attributeStore);
     this.writeBehindJobUpdateStore = requireNonNull(jobUpdateStore);
     this.writeLock = requireNonNull(writeLock);
+    this.thriftBackfill = requireNonNull(thriftBackfill);
     TransactionManager transactionManager = new TransactionManager() {
       @Override
       public boolean hasActiveTransaction() {
@@ -325,7 +330,7 @@ public class LogStorage implements NonVolatileStorage, DistributedSnapshotStore
         .put(Op._Fields.SAVE_CRON_JOB, op -> {
           SaveCronJob cronJob = op.getSaveCronJob();
           writeBehindJobStore.saveAcceptedJob(
-              ThriftBackfill.backfillJobConfiguration(cronJob.getJobConfig()));
+              thriftBackfill.backfillJobConfiguration(cronJob.getJobConfig()));
         })
         .put(
             Op._Fields.REMOVE_JOB,
@@ -333,7 +338,7 @@ public class LogStorage implements NonVolatileStorage, DistributedSnapshotStore
         .put(
             Op._Fields.SAVE_TASKS,
             op -> writeBehindTaskStore.saveTasks(
-                ThriftBackfill.backfillTasks(op.getSaveTasks().getTasks())))
+                thriftBackfill.backfillTasks(op.getSaveTasks().getTasks())))
         .put(Op._Fields.REWRITE_TASK, op -> {
           RewriteTask rewriteTask = op.getRewriteTask();
           writeBehindTaskStore.unsafeModifyInPlace(
@@ -371,7 +376,7 @@ public class LogStorage implements NonVolatileStorage, DistributedSnapshotStore
             op -> writeBehindLockStore.removeLock(ILockKey.build(op.getRemoveLock().getLockKey())))
         .put(Op._Fields.SAVE_JOB_UPDATE, op ->
           writeBehindJobUpdateStore.saveJobUpdate(
-              ThriftBackfill.backFillJobUpdate(op.getSaveJobUpdate().getJobUpdate()),
+              thriftBackfill.backFillJobUpdate(op.getSaveJobUpdate().getJobUpdate()),
               Optional.fromNullable(op.getSaveJobUpdate().getLockToken())))
         .put(Op._Fields.SAVE_JOB_UPDATE_EVENT, op -> {
           SaveJobUpdateEvent event = op.getSaveJobUpdateEvent();

http://git-wip-us.apache.org/repos/asf/aurora/blob/f6ac13b1/src/main/java/org/apache/aurora/scheduler/storage/log/SnapshotStoreImpl.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/log/SnapshotStoreImpl.java b/src/main/java/org/apache/aurora/scheduler/storage/log/SnapshotStoreImpl.java
index 8eed1fc..b9b3eb0 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/log/SnapshotStoreImpl.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/log/SnapshotStoreImpl.java
@@ -222,7 +222,7 @@ public class SnapshotStoreImpl implements SnapshotStore<Snapshot> {
 
           if (snapshot.isSetTasks()) {
             store.getUnsafeTaskStore()
-                .saveTasks(ThriftBackfill.backfillTasks(snapshot.getTasks()));
+                .saveTasks(thriftBackfill.backfillTasks(snapshot.getTasks()));
           }
         }
       },
@@ -250,7 +250,7 @@ public class SnapshotStoreImpl implements SnapshotStore<Snapshot> {
           if (snapshot.isSetCronJobs()) {
             for (StoredCronJob job : snapshot.getCronJobs()) {
               store.getCronJobStore().saveAcceptedJob(
-                  ThriftBackfill.backfillJobConfiguration(job.getJobConfiguration()));
+                  thriftBackfill.backfillJobConfiguration(job.getJobConfiguration()));
             }
           }
         }
@@ -327,7 +327,7 @@ public class SnapshotStoreImpl implements SnapshotStore<Snapshot> {
             for (StoredJobUpdateDetails storedDetails : snapshot.getJobUpdateDetails()) {
               JobUpdateDetails details = storedDetails.getDetails();
               updateStore.saveJobUpdate(
-                  ThriftBackfill.backFillJobUpdate(details.getUpdate()),
+                  thriftBackfill.backFillJobUpdate(details.getUpdate()),
                   Optional.fromNullable(storedDetails.getLockToken()));
 
               if (details.getUpdateEventsSize() > 0) {
@@ -356,6 +356,7 @@ public class SnapshotStoreImpl implements SnapshotStore<Snapshot> {
   private final Storage storage;
   private final boolean useDbSnapshotForTaskStore;
   private final MigrationManager migrationManager;
+  private final ThriftBackfill thriftBackfill;
 
   /**
    * Identifies if experimental task store is in use.
@@ -371,13 +372,15 @@ public class SnapshotStoreImpl implements SnapshotStore<Snapshot> {
       Clock clock,
       @Volatile Storage storage,
       @ExperimentalTaskStore boolean useDbSnapshotForTaskStore,
-      MigrationManager migrationManager) {
+      MigrationManager migrationManager,
+      ThriftBackfill thriftBackfill) {
 
     this.buildInfo = requireNonNull(buildInfo);
     this.clock = requireNonNull(clock);
     this.storage = requireNonNull(storage);
     this.useDbSnapshotForTaskStore = useDbSnapshotForTaskStore;
     this.migrationManager = requireNonNull(migrationManager);
+    this.thriftBackfill = requireNonNull(thriftBackfill);
   }
 
   @Timed("snapshot_create")

http://git-wip-us.apache.org/repos/asf/aurora/blob/f6ac13b1/src/main/java/org/apache/aurora/scheduler/storage/log/ThriftBackfill.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/log/ThriftBackfill.java b/src/main/java/org/apache/aurora/scheduler/storage/log/ThriftBackfill.java
index 0a307fe..c883843 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/log/ThriftBackfill.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/log/ThriftBackfill.java
@@ -17,6 +17,8 @@ import java.util.EnumSet;
 import java.util.Set;
 import java.util.stream.Collectors;
 
+import com.google.inject.Inject;
+
 import org.apache.aurora.GuavaUtils;
 import org.apache.aurora.gen.JobConfiguration;
 import org.apache.aurora.gen.JobUpdate;
@@ -25,6 +27,8 @@ import org.apache.aurora.gen.Resource;
 import org.apache.aurora.gen.ResourceAggregate;
 import org.apache.aurora.gen.ScheduledTask;
 import org.apache.aurora.gen.TaskConfig;
+import org.apache.aurora.scheduler.TierInfo;
+import org.apache.aurora.scheduler.TierManager;
 import org.apache.aurora.scheduler.quota.QuotaManager;
 import org.apache.aurora.scheduler.resources.ResourceType;
 import org.apache.aurora.scheduler.storage.entities.IJobConfiguration;
@@ -32,6 +36,10 @@ import org.apache.aurora.scheduler.storage.entities.IJobUpdate;
 import org.apache.aurora.scheduler.storage.entities.IResource;
 import org.apache.aurora.scheduler.storage.entities.IResourceAggregate;
 import org.apache.aurora.scheduler.storage.entities.IScheduledTask;
+import org.apache.aurora.scheduler.storage.entities.ITaskConfig;
+
+import static java.lang.String.format;
+import static java.util.Objects.requireNonNull;
 
 import static org.apache.aurora.scheduler.resources.ResourceType.CPUS;
 import static org.apache.aurora.scheduler.resources.ResourceType.DISK_MB;
@@ -42,8 +50,12 @@ import static org.apache.aurora.scheduler.resources.ResourceType.RAM_MB;
  * Helps migrating thrift schema by populating deprecated and/or replacement fields.
  */
 public final class ThriftBackfill {
-  private ThriftBackfill() {
-    // Utility class.
+
+  private final TierManager tierManager;
+
+  @Inject
+  public ThriftBackfill(TierManager tierManager) {
+    this.tierManager = requireNonNull(tierManager);
   }
 
   private static Resource getResource(Set<Resource> resources, ResourceType type) {
@@ -59,7 +71,7 @@ public final class ThriftBackfill {
    * @param config TaskConfig to backfill.
    * @return Backfilled TaskConfig.
    */
-  public static TaskConfig backfillTask(TaskConfig config) {
+  public TaskConfig backfillTask(TaskConfig config) {
     if (!config.isSetResources() || config.getResources().isEmpty()) {
       config.addToResources(Resource.numCpus(config.getNumCpus()));
       config.addToResources(Resource.ramMb(config.getRamMb()));
@@ -81,16 +93,35 @@ public final class ThriftBackfill {
         config.setRequestedPorts(ports);
       }
     }
+    backfillTier(config);
     return config;
   }
 
+  private void backfillTier(TaskConfig config) {
+    ITaskConfig taskConfig = ITaskConfig.build(config);
+    if (config.isSetTier()) {
+      TierInfo tier = tierManager.getTier(taskConfig);
+      config.setProduction(!tier.isPreemptible() && !tier.isRevocable());
+    } else {
+      config.setTier(tierManager.getTiers()
+          .entrySet()
+          .stream()
+          .filter(e -> e.getValue().isPreemptible() == !taskConfig.isProduction()
+              && !e.getValue().isRevocable())
+          .findFirst()
+          .orElseThrow(() -> new IllegalStateException(
+              format("No matching implicit tier for task of job %s", taskConfig.getJob())))
+          .getKey());
+    }
+  }
+
   /**
    * Backfills JobConfiguration. See {@link #backfillTask(TaskConfig)}.
    *
    * @param jobConfig JobConfiguration to backfill.
    * @return Backfilled JobConfiguration.
    */
-  public static IJobConfiguration backfillJobConfiguration(JobConfiguration jobConfig) {
+  public IJobConfiguration backfillJobConfiguration(JobConfiguration jobConfig) {
     backfillTask(jobConfig.getTaskConfig());
     return IJobConfiguration.build(jobConfig);
   }
@@ -101,9 +132,9 @@ public final class ThriftBackfill {
    * @param tasks Set of tasks to backfill.
    * @return Backfilled set of tasks.
    */
-  public static Set<IScheduledTask> backfillTasks(Set<ScheduledTask> tasks) {
+  public Set<IScheduledTask> backfillTasks(Set<ScheduledTask> tasks) {
     return tasks.stream()
-        .map(ThriftBackfill::backfillScheduledTask)
+        .map(t -> backfillScheduledTask(t))
         .map(IScheduledTask::build)
         .collect(GuavaUtils.toImmutableSet());
   }
@@ -138,7 +169,7 @@ public final class ThriftBackfill {
     return IResourceAggregate.build(aggregate);
   }
 
-  private static ScheduledTask backfillScheduledTask(ScheduledTask task) {
+  private ScheduledTask backfillScheduledTask(ScheduledTask task) {
     backfillTask(task.getAssignedTask().getTask());
     return task;
   }
@@ -149,7 +180,7 @@ public final class ThriftBackfill {
    * @param update JobUpdate to backfill.
    * @return Backfilled job update.
    */
-  static IJobUpdate backFillJobUpdate(JobUpdate update) {
+  IJobUpdate backFillJobUpdate(JobUpdate update) {
     JobUpdateInstructions instructions = update.getInstructions();
     if (instructions.isSetDesiredState()) {
       backfillTask(instructions.getDesiredState().getTask());

http://git-wip-us.apache.org/repos/asf/aurora/blob/f6ac13b1/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 d4b71f8..7d9b333 100644
--- a/src/test/java/org/apache/aurora/scheduler/TierManagerTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/TierManagerTest.java
@@ -29,10 +29,13 @@ import static org.apache.aurora.scheduler.base.TaskTestUtil.REVOCABLE_TIER;
 import static org.junit.Assert.assertEquals;
 
 public class TierManagerTest {
+  private static final String PREFERRED_TIER_NAME = "preferred";
+  private static final String PREEMPTIBLE_TIER_NAME = "preemptible";
+  private static final String REVOCABLE_TIER_NAME = "revocable";
   private static final Map<String, TierInfo> TIERS = ImmutableMap.of(
-      "preferred", PREFERRED_TIER,
-      "preemptible", DEV_TIER,
-      "revocable", REVOCABLE_TIER);
+      PREFERRED_TIER_NAME, PREFERRED_TIER,
+      PREEMPTIBLE_TIER_NAME, DEV_TIER,
+      REVOCABLE_TIER_NAME, REVOCABLE_TIER);
   private static final TierManager TIER_MANAGER = new TierManagerImpl(
       parseTierConfig("{\"default\": \"preemptible\","
           + "\"tiers\":{"
@@ -42,63 +45,38 @@ public class TierManagerTest {
           + "}}"));
 
   @Test
-  public void testRevocable() {
+  public void testGetTierRevocable() {
     assertEquals(
         REVOCABLE_TIER,
-        TIER_MANAGER.getTier(ITaskConfig.build(new TaskConfig().setTier("revocable"))));
+        TIER_MANAGER.getTier(ITaskConfig.build(new TaskConfig().setTier(REVOCABLE_TIER_NAME))));
   }
 
   @Test
-  public void testRevocableAndProduction() {
+  public void testGetTierRevocableAndProduction() {
     assertEquals(
         REVOCABLE_TIER,
         TIER_MANAGER.getTier(ITaskConfig.build(new TaskConfig()
-            .setTier("revocable")
+            .setTier(REVOCABLE_TIER_NAME)
             .setProduction(true))));
   }
 
   @Test
-  public void testPreemptibleAndProduction() {
+  public void testGetTierPreemptibleAndProduction() {
     assertEquals(
         DEV_TIER,
         TIER_MANAGER.getTier(ITaskConfig.build(new TaskConfig()
-            .setTier("preemptible")
+            .setTier(PREEMPTIBLE_TIER_NAME)
             .setProduction(true))));
   }
 
   @Test(expected = IllegalArgumentException.class)
-  public void testNameMismatch() {
+  public void testGetTierNameMismatch() {
     TIER_MANAGER.getTier(ITaskConfig.build(new TaskConfig().setTier("Revocable")));
   }
 
   @Test
-  public void testProduction() {
-    assertEquals(
-        PREFERRED_TIER,
-        TIER_MANAGER.getTier(ITaskConfig.build(new TaskConfig().setProduction(true))));
-  }
-
-  @Test
-  public void testNoTierInTaskConfig() {
-    assertEquals(DEV_TIER, TIER_MANAGER.getTier(ITaskConfig.build(new TaskConfig())));
-  }
-
-  @Test(expected = IllegalStateException.class)
-  public void testBadTierConfiguration() {
-    TierManager tierManager = new TierManagerImpl(
-        parseTierConfig("{\"default\": \"revocable\","
-            + "\"tiers\":{"
-            + "\"preferred\": {\"revocable\": false, \"preemptible\": false},"
-            + "\"revocable\": {\"revocable\": true, \"preemptible\": true}"
-            + "}}"));
-    // preemptible: false, revocable: false
-    ITaskConfig taskConfig = ITaskConfig.build(new TaskConfig());
-    tierManager.getTier(taskConfig);
-  }
-
-  @Test
-  public void testDefault() {
-    assertEquals("preemptible", TIER_MANAGER.getDefaultTierName());
+  public void testGetDefaultTierName() {
+    assertEquals(PREEMPTIBLE_TIER_NAME, TIER_MANAGER.getDefaultTierName());
   }
 
   @Test
@@ -113,7 +91,7 @@ public class TierManagerTest {
 
   @Test(expected = IllegalArgumentException.class)
   public void testEmptyTiersInTierConfig() {
-    new TierManagerImpl.TierConfig("preemptible", ImmutableMap.of());
+    new TierManagerImpl.TierConfig(PREEMPTIBLE_TIER_NAME, ImmutableMap.of());
   }
 
   @Test(expected = IllegalArgumentException.class)

http://git-wip-us.apache.org/repos/asf/aurora/blob/f6ac13b1/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 8c8c793..29a3b4a 100644
--- a/src/test/java/org/apache/aurora/scheduler/app/SchedulerIT.java
+++ b/src/test/java/org/apache/aurora/scheduler/app/SchedulerIT.java
@@ -209,7 +209,7 @@ public class SchedulerIT extends BaseZooKeeperClientTest {
     Injector injector = Guice.createInjector(
         ImmutableList.<Module>builder()
             .add(SchedulerMain.getUniversalModule())
-            .add(new TierModule(TaskTestUtil.DEV_TIER_CONFIG))
+            .add(new TierModule(TaskTestUtil.TIER_CONFIG))
             .add(new LogStorageModule())
             .add(new ServiceDiscoveryModule(zkClientConfig, SERVERSET_PATH))
             .add(testModule)

http://git-wip-us.apache.org/repos/asf/aurora/blob/f6ac13b1/src/test/java/org/apache/aurora/scheduler/configuration/ConfigurationManagerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/configuration/ConfigurationManagerTest.java b/src/test/java/org/apache/aurora/scheduler/configuration/ConfigurationManagerTest.java
index 2e322d2..2dff80b 100644
--- a/src/test/java/org/apache/aurora/scheduler/configuration/ConfigurationManagerTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/configuration/ConfigurationManagerTest.java
@@ -119,7 +119,8 @@ public class ConfigurationManagerTest {
           ImmutableMultimap.of(),
           true,
           false),
-      TaskTestUtil.DEV_TIER_MANAGER);
+      TaskTestUtil.TIER_MANAGER,
+      TaskTestUtil.THRIFT_BACKFILL);
   private static final ConfigurationManager DOCKER_CONFIGURATION_MANAGER = new ConfigurationManager(
       new ConfigurationManagerSettings(
           ALL_CONTAINER_TYPES,
@@ -127,7 +128,8 @@ public class ConfigurationManagerTest {
           ImmutableMultimap.of("foo", "bar"),
           false,
           true),
-      TaskTestUtil.DEV_TIER_MANAGER);
+      TaskTestUtil.TIER_MANAGER,
+      TaskTestUtil.THRIFT_BACKFILL);
 
   @Test
   public void testIsGoodIdentifier() {
@@ -287,7 +289,8 @@ public class ConfigurationManagerTest {
             ImmutableMultimap.of("foo", "bar"),
             false,
             false),
-        TaskTestUtil.DEV_TIER_MANAGER).validateAndPopulate(ITaskConfig.build(builder));
+        TaskTestUtil.TIER_MANAGER,
+        TaskTestUtil.THRIFT_BACKFILL).validateAndPopulate(ITaskConfig.build(builder));
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/aurora/blob/f6ac13b1/src/test/java/org/apache/aurora/scheduler/storage/backup/RecoveryTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/backup/RecoveryTest.java b/src/test/java/org/apache/aurora/scheduler/storage/backup/RecoveryTest.java
index e870087..7a11850 100644
--- a/src/test/java/org/apache/aurora/scheduler/storage/backup/RecoveryTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/storage/backup/RecoveryTest.java
@@ -81,7 +81,7 @@ public class RecoveryTest extends EasyMockTest {
     shutDownNow = createMock(Command.class);
     ScheduledExecutorService executor = createMock(ScheduledExecutorService.class);
     clock = FakeScheduledExecutor.scheduleExecutor(executor);
-    TemporaryStorageFactory factory = new TemporaryStorageFactory();
+    TemporaryStorageFactory factory = new TemporaryStorageFactory(TaskTestUtil.THRIFT_BACKFILL);
     storageBackup = new StorageBackupImpl(
         snapshotStore,
         clock,

http://git-wip-us.apache.org/repos/asf/aurora/blob/f6ac13b1/src/test/java/org/apache/aurora/scheduler/storage/log/LogStorageTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/log/LogStorageTest.java b/src/test/java/org/apache/aurora/scheduler/storage/log/LogStorageTest.java
index be1132b..34c24aa 100644
--- a/src/test/java/org/apache/aurora/scheduler/storage/log/LogStorageTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/storage/log/LogStorageTest.java
@@ -181,7 +181,8 @@ public class LogStorageTest extends EasyMockTest {
         storageUtil.attributeStore,
         storageUtil.jobUpdateStore,
         eventSink,
-        new ReentrantLock());
+        new ReentrantLock(),
+        TaskTestUtil.THRIFT_BACKFILL);
 
     stream = createMock(Stream.class);
     streamMatcher = LogOpMatcher.matcherFor(stream);

http://git-wip-us.apache.org/repos/asf/aurora/blob/f6ac13b1/src/test/java/org/apache/aurora/scheduler/storage/log/SnapshotStoreImplIT.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/log/SnapshotStoreImplIT.java b/src/test/java/org/apache/aurora/scheduler/storage/log/SnapshotStoreImplIT.java
index e0cf602..cf0a8f3 100644
--- a/src/test/java/org/apache/aurora/scheduler/storage/log/SnapshotStoreImplIT.java
+++ b/src/test/java/org/apache/aurora/scheduler/storage/log/SnapshotStoreImplIT.java
@@ -100,7 +100,8 @@ public class SnapshotStoreImplIT {
         clock,
         storage,
         dbTaskStore,
-        createStorageInjector(testModuleWithWorkQueue()).getInstance(MigrationManager.class));
+        createStorageInjector(testModuleWithWorkQueue()).getInstance(MigrationManager.class),
+        TaskTestUtil.THRIFT_BACKFILL);
   }
 
   private static Snapshot makeComparable(Snapshot snapshot) {

http://git-wip-us.apache.org/repos/asf/aurora/blob/f6ac13b1/src/test/java/org/apache/aurora/scheduler/storage/log/ThriftBackfillTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/log/ThriftBackfillTest.java b/src/test/java/org/apache/aurora/scheduler/storage/log/ThriftBackfillTest.java
index 0a2cd3d..544c6c2 100644
--- a/src/test/java/org/apache/aurora/scheduler/storage/log/ThriftBackfillTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/storage/log/ThriftBackfillTest.java
@@ -13,34 +13,55 @@
  */
 package org.apache.aurora.scheduler.storage.log;
 
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 
+import org.apache.aurora.common.testing.easymock.EasyMockTest;
 import org.apache.aurora.gen.ResourceAggregate;
 import org.apache.aurora.gen.TaskConfig;
+import org.apache.aurora.scheduler.TierManager;
+import org.apache.aurora.scheduler.base.TaskTestUtil;
 import org.apache.aurora.scheduler.storage.entities.IResourceAggregate;
+import org.apache.aurora.scheduler.storage.entities.ITaskConfig;
+import org.junit.Before;
 import org.junit.Test;
 
 import static org.apache.aurora.gen.Resource.diskMb;
 import static org.apache.aurora.gen.Resource.namedPort;
 import static org.apache.aurora.gen.Resource.numCpus;
 import static org.apache.aurora.gen.Resource.ramMb;
+import static org.easymock.EasyMock.expect;
 import static org.junit.Assert.assertEquals;
 
-public class ThriftBackfillTest {
+public class ThriftBackfillTest extends EasyMockTest {
+
+  private ThriftBackfill thriftBackfill;
+  private TierManager tierManager;
+
+  @Before
+  public void setUp() {
+    tierManager = createMock(TierManager.class);
+    thriftBackfill = new ThriftBackfill(tierManager);
+  }
 
   @Test
   public void testFieldsToSetNoPorts() {
     TaskConfig config = new TaskConfig()
         .setNumCpus(1.0)
         .setRamMb(32)
-        .setDiskMb(64);
+        .setDiskMb(64)
+        .setProduction(false)
+        .setTier("tierName");
+    TaskConfig expected = config.deepCopy()
+        .setResources(ImmutableSet.of(numCpus(1.0), ramMb(32), diskMb(64)));
+
+    expect(tierManager.getTier(ITaskConfig.build(expected))).andReturn(TaskTestUtil.DEV_TIER);
 
-    TaskConfig expected = config.deepCopy();
-    expected.setResources(ImmutableSet.of(numCpus(1.0), ramMb(32), diskMb(64)));
+    control.replay();
 
     assertEquals(
         expected,
-        ThriftBackfill.backfillTask(config));
+        thriftBackfill.backfillTask(config));
   }
 
   @Test
@@ -49,55 +70,74 @@ public class ThriftBackfillTest {
         .setNumCpus(1.0)
         .setRamMb(32)
         .setDiskMb(64)
-        .setRequestedPorts(ImmutableSet.of("http"));
+        .setRequestedPorts(ImmutableSet.of("http"))
+        .setProduction(false)
+        .setTier("tierName");
+    TaskConfig expected = config.deepCopy()
+        .setResources(ImmutableSet.of(numCpus(1.0), ramMb(32), diskMb(64), namedPort("http")));
+
+    expect(tierManager.getTier(ITaskConfig.build(expected))).andReturn(TaskTestUtil.DEV_TIER);
 
-    TaskConfig expected = config.deepCopy();
-    expected.setResources(ImmutableSet.of(numCpus(1.0), ramMb(32), diskMb(64), namedPort("http")));
+    control.replay();
 
     assertEquals(
         expected,
-        ThriftBackfill.backfillTask(config));
+        thriftBackfill.backfillTask(config));
   }
 
   @Test
   public void testSetToFieldsNoPorts() {
     TaskConfig config = new TaskConfig()
-        .setResources(ImmutableSet.of(numCpus(1.0), ramMb(32), diskMb(64)));
-
+        .setResources(ImmutableSet.of(numCpus(1.0), ramMb(32), diskMb(64)))
+        .setProduction(false)
+        .setTier("tierName");
     TaskConfig expected = config.deepCopy()
         .setNumCpus(1.0)
         .setRamMb(32)
         .setDiskMb(64);
 
+    expect(tierManager.getTier(ITaskConfig.build(expected))).andReturn(TaskTestUtil.DEV_TIER);
+
+    control.replay();
+
     assertEquals(
         expected,
-        ThriftBackfill.backfillTask(config));
+        thriftBackfill.backfillTask(config));
   }
 
   @Test
   public void testSetToFieldsWithPorts() {
     TaskConfig config = new TaskConfig()
-        .setResources(ImmutableSet.of(numCpus(1.0), ramMb(32), diskMb(64), namedPort("http")));
-
+        .setResources(ImmutableSet.of(numCpus(1.0), ramMb(32), diskMb(64), namedPort("http")))
+        .setProduction(false)
+        .setTier("tierName");
     TaskConfig expected = config.deepCopy()
         .setNumCpus(1.0)
         .setRamMb(32)
         .setDiskMb(64)
         .setRequestedPorts(ImmutableSet.of("http"));
 
+    expect(tierManager.getTier(ITaskConfig.build(expected))).andReturn(TaskTestUtil.DEV_TIER);
+
+    control.replay();
+
     assertEquals(
         expected,
-        ThriftBackfill.backfillTask(config));
+        thriftBackfill.backfillTask(config));
   }
 
   @Test(expected = IllegalArgumentException.class)
   public void testMissingResourceThrows() {
+    control.replay();
+
     TaskConfig config = new TaskConfig().setResources(ImmutableSet.of(numCpus(1.0), ramMb(32)));
-    ThriftBackfill.backfillTask(config);
+    thriftBackfill.backfillTask(config);
   }
 
   @Test
   public void testResourceAggregateFieldsToSet() {
+    control.replay();
+
     ResourceAggregate aggregate = new ResourceAggregate()
         .setNumCpus(1.0)
         .setRamMb(32)
@@ -111,6 +151,8 @@ public class ThriftBackfillTest {
 
   @Test
   public void testResourceAggregateSetToFields() {
+    control.replay();
+
     ResourceAggregate aggregate = new ResourceAggregate()
         .setResources(ImmutableSet.of(numCpus(1.0), ramMb(32), diskMb(64)));
 
@@ -124,6 +166,8 @@ public class ThriftBackfillTest {
 
   @Test(expected = IllegalArgumentException.class)
   public void testResourceAggregateTooManyResources() {
+    control.replay();
+
     ResourceAggregate aggregate = new ResourceAggregate()
         .setResources(ImmutableSet.of(numCpus(1.0), ramMb(32), diskMb(64), numCpus(2.0)));
     ThriftBackfill.backfillResourceAggregate(aggregate);
@@ -131,6 +175,8 @@ public class ThriftBackfillTest {
 
   @Test(expected = IllegalArgumentException.class)
   public void testResourceAggregateInvalidResources() {
+    control.replay();
+
     ResourceAggregate aggregate = new ResourceAggregate()
         .setResources(ImmutableSet.of(numCpus(1.0), ramMb(32), namedPort("http")));
     ThriftBackfill.backfillResourceAggregate(aggregate);
@@ -138,8 +184,109 @@ public class ThriftBackfillTest {
 
   @Test(expected = IllegalArgumentException.class)
   public void testResourceAggregateMissingResources() {
+    control.replay();
+
     ResourceAggregate aggregate = new ResourceAggregate()
         .setResources(ImmutableSet.of(numCpus(1.0), ramMb(32)));
     ThriftBackfill.backfillResourceAggregate(aggregate);
   }
+
+  @Test
+  public void testBackfillTierProduction() {
+    TaskConfig config = new TaskConfig()
+        .setNumCpus(1.0)
+        .setRamMb(32)
+        .setDiskMb(64)
+        .setProduction(true)
+        .setTier("tierName");
+    TaskConfig expected = config.deepCopy()
+        .setResources(ImmutableSet.of(numCpus(1.0), ramMb(32), diskMb(64)));
+
+    expect(tierManager.getTier(ITaskConfig.build(expected))).andReturn(TaskTestUtil.PREFERRED_TIER);
+
+    control.replay();
+
+    assertEquals(
+        expected,
+        thriftBackfill.backfillTask(config));
+  }
+
+  @Test
+  public void testBackfillTierNotProduction() {
+    TaskConfig config = new TaskConfig()
+        .setNumCpus(1.0)
+        .setRamMb(32)
+        .setDiskMb(64)
+        .setProduction(true)
+        .setTier("tierName");
+    TaskConfig configWithBackfilledResources = config.deepCopy()
+        .setResources(ImmutableSet.of(numCpus(1.0), ramMb(32), diskMb(64)));
+
+    expect(tierManager.getTier(ITaskConfig.build(configWithBackfilledResources)))
+        .andReturn(TaskTestUtil.DEV_TIER);
+
+    control.replay();
+
+    TaskConfig expected = configWithBackfilledResources.deepCopy()
+        .setProduction(false);
+
+    assertEquals(
+        expected,
+        thriftBackfill.backfillTask(config));
+  }
+
+  @Test
+  public void testBackfillTierSetsTierToPreemptible() {
+    TaskConfig config = new TaskConfig()
+        .setNumCpus(1.0)
+        .setRamMb(32)
+        .setDiskMb(64);
+    TaskConfig configWithBackfilledResources = config.deepCopy()
+        .setResources(ImmutableSet.of(numCpus(1.0), ramMb(32), diskMb(64)));
+
+    expect(tierManager.getTiers()).andReturn(TaskTestUtil.tierInfos());
+
+    control.replay();
+
+    TaskConfig expected = configWithBackfilledResources.deepCopy().setTier("preemptible");
+
+    assertEquals(
+        expected,
+        thriftBackfill.backfillTask(config));
+  }
+
+  @Test
+  public void testBackfillTierSetsTierToPreferred() {
+    TaskConfig config = new TaskConfig()
+        .setNumCpus(1.0)
+        .setRamMb(32)
+        .setDiskMb(64)
+        .setProduction(true);
+    TaskConfig configWithBackfilledResources = config.deepCopy()
+        .setResources(ImmutableSet.of(numCpus(1.0), ramMb(32), diskMb(64)));
+
+    expect(tierManager.getTiers()).andReturn(TaskTestUtil.tierInfos());
+
+    control.replay();
+
+    TaskConfig expected = configWithBackfilledResources.deepCopy().setTier("preferred");
+
+    assertEquals(
+        expected,
+        thriftBackfill.backfillTask(config));
+  }
+
+  @Test(expected = IllegalStateException.class)
+  public void testBackfillTierBadTierConfiguration() {
+    TaskConfig config = new TaskConfig()
+        .setNumCpus(1.0)
+        .setRamMb(32)
+        .setDiskMb(64);
+
+    expect(tierManager.getTiers()).andReturn(ImmutableMap.of());
+
+    control.replay();
+
+    thriftBackfill.backfillTask(config);
+  }
 }

http://git-wip-us.apache.org/repos/asf/aurora/blob/f6ac13b1/src/test/java/org/apache/aurora/scheduler/thrift/Fixtures.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/thrift/Fixtures.java b/src/test/java/org/apache/aurora/scheduler/thrift/Fixtures.java
index 4f81585..a883b0e 100644
--- a/src/test/java/org/apache/aurora/scheduler/thrift/Fixtures.java
+++ b/src/test/java/org/apache/aurora/scheduler/thrift/Fixtures.java
@@ -44,6 +44,7 @@ import org.apache.aurora.gen.Result;
 import org.apache.aurora.gen.ScheduledTask;
 import org.apache.aurora.gen.TaskConfig;
 import org.apache.aurora.scheduler.base.JobKeys;
+import org.apache.aurora.scheduler.base.TaskTestUtil;
 import org.apache.aurora.scheduler.quota.QuotaCheckResult;
 import org.apache.aurora.scheduler.resources.ResourceBag;
 import org.apache.aurora.scheduler.resources.ResourceTestUtil;
@@ -106,6 +107,7 @@ final class Fixtures {
         .setRamMb(1024)
         .setDiskMb(1024)
         .setProduction(production)
+        .setTier(production ? TaskTestUtil.PROD_TIER_NAME : TaskTestUtil.DEV_TIER_NAME)
         .setRequestedPorts(ImmutableSet.of())
         .setTaskLinks(ImmutableMap.of())
         .setMaxTaskFailures(1)

http://git-wip-us.apache.org/repos/asf/aurora/blob/f6ac13b1/src/test/java/org/apache/aurora/scheduler/thrift/ReadOnlySchedulerImplTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/thrift/ReadOnlySchedulerImplTest.java b/src/test/java/org/apache/aurora/scheduler/thrift/ReadOnlySchedulerImplTest.java
index 6f355d6..a7d1f74 100644
--- a/src/test/java/org/apache/aurora/scheduler/thrift/ReadOnlySchedulerImplTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/thrift/ReadOnlySchedulerImplTest.java
@@ -15,7 +15,6 @@ package org.apache.aurora.scheduler.thrift;
 
 import java.util.Date;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 
 import javax.annotation.Nullable;
@@ -24,7 +23,6 @@ import com.google.common.base.Function;
 import com.google.common.base.Optional;
 import com.google.common.collect.FluentIterable;
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
@@ -64,8 +62,6 @@ import org.apache.aurora.gen.ScheduleStatus;
 import org.apache.aurora.gen.ScheduledTask;
 import org.apache.aurora.gen.TaskConfig;
 import org.apache.aurora.gen.TaskQuery;
-import org.apache.aurora.gen.TierConfig;
-import org.apache.aurora.scheduler.TierInfo;
 import org.apache.aurora.scheduler.TierManager;
 import org.apache.aurora.scheduler.base.JobKeys;
 import org.apache.aurora.scheduler.base.Query;
@@ -97,9 +93,6 @@ import org.junit.Test;
 import static org.apache.aurora.gen.ResponseCode.INVALID_REQUEST;
 import static org.apache.aurora.scheduler.base.Numbers.convertRanges;
 import static org.apache.aurora.scheduler.base.Numbers.toRanges;
-import static org.apache.aurora.scheduler.base.TaskTestUtil.DEV_TIER;
-import static org.apache.aurora.scheduler.base.TaskTestUtil.PREFERRED_TIER;
-import static org.apache.aurora.scheduler.base.TaskTestUtil.REVOCABLE_TIER;
 import static org.apache.aurora.scheduler.resources.ResourceBag.LARGE;
 import static org.apache.aurora.scheduler.resources.ResourceBag.MEDIUM;
 import static org.apache.aurora.scheduler.resources.ResourceBag.SMALL;
@@ -860,29 +853,14 @@ public class ReadOnlySchedulerImplTest extends EasyMockTest {
   @Test
   public void testGetTierConfig() throws Exception {
     expect(tierManager.getDefaultTierName()).andReturn("preemptible");
-    expect(tierManager.getTiers()).andReturn(tierInfos());
+    expect(tierManager.getTiers()).andReturn(TaskTestUtil.tierInfos());
     control.replay();
 
     GetTierConfigResult expected = new GetTierConfigResult()
         .setDefaultTierName("preemptible")
-        .setTiers(tierConfigs());
+        .setTiers(TaskTestUtil.tierConfigs());
 
     Response response = assertOkResponse(thrift.getTierConfigs());
     assertEquals(expected, response.getResult().getGetTierConfigResult());
   }
-
-  private static Map<String, TierInfo> tierInfos() {
-    return ImmutableMap.of(
-        "preferred", PREFERRED_TIER,
-        "preemptible", DEV_TIER,
-        "revocable", REVOCABLE_TIER);
-  }
-
-  private static Set<TierConfig> tierConfigs() {
-    return ImmutableSet.of(
-        new TierConfig("preferred", PREFERRED_TIER.toMap()),
-        new TierConfig("preemptible", DEV_TIER.toMap()),
-        new TierConfig("revocable", REVOCABLE_TIER.toMap())
-    );
-  }
 }

http://git-wip-us.apache.org/repos/asf/aurora/blob/f6ac13b1/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java b/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
index ecdc62a..c0fe843 100644
--- a/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
@@ -490,6 +490,7 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
         .setDiskMb(1024)
         .setIsService(true)
         .setProduction(true)
+        .setTier(TaskTestUtil.PROD_TIER_NAME)
         .setOwner(IDENTITY)
         .setContainer(Container.mesos(new MesosContainer()))
         .setJob(JOB_KEY.newBuilder());

http://git-wip-us.apache.org/repos/asf/aurora/blob/f6ac13b1/src/test/java/org/apache/aurora/scheduler/thrift/ThriftIT.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/thrift/ThriftIT.java b/src/test/java/org/apache/aurora/scheduler/thrift/ThriftIT.java
index a54d169..ed69996 100644
--- a/src/test/java/org/apache/aurora/scheduler/thrift/ThriftIT.java
+++ b/src/test/java/org/apache/aurora/scheduler/thrift/ThriftIT.java
@@ -94,7 +94,7 @@ public class ThriftIT extends EasyMockTest {
             install(DbModule.testModule());
             install(new QuotaModule());
             install(new CronModule());
-            install(new TierModule(TaskTestUtil.DEV_TIER_CONFIG));
+            install(new TierModule(TaskTestUtil.TIER_CONFIG));
             bind(ExecutorSettings.class).toInstance(TestExecutorSettings.THERMOS_EXECUTOR);
 
             install(new AppModule(configurationManagerSettings));
@@ -164,6 +164,7 @@ public class ThriftIT extends EasyMockTest {
     TaskConfig task = TaskTestUtil.makeConfig(TaskTestUtil.JOB).newBuilder();
     task.unsetExecutorConfig();
     task.setProduction(false)
+        .setTier(TaskTestUtil.DEV_TIER_NAME)
         .setContainer(Container.docker(new DockerContainer()
             .setImage("image")
             .setParameters(


Mime
View raw message