aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject aurora git commit: Removing Resources and ResourceSlot classes.
Date Mon, 16 May 2016 19:21:54 GMT
Repository: aurora
Updated Branches:
  refs/heads/master 5699c959f -> 8c900e585


Removing Resources and ResourceSlot classes.

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


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

Branch: refs/heads/master
Commit: 8c900e5850469784c084567369d8577441f2b2a6
Parents: 5699c95
Author: Maxim Khutornenko <maxim@apache.org>
Authored: Mon May 16 12:21:40 2016 -0700
Committer: Maxim Khutornenko <maxim@apache.org>
Committed: Mon May 16 12:21:40 2016 -0700

----------------------------------------------------------------------
 .../org/apache/aurora/benchmark/Offers.java     |  37 ++-
 .../apache/aurora/scheduler/base/Numbers.java   |   9 +
 .../scheduler/mesos/MesosTaskFactory.java       |   9 +-
 .../scheduler/mesos/TestExecutorSettings.java   |   6 +-
 .../scheduler/resources/AcceptedOffer.java      |   2 +-
 .../resources/MesosResourceConverter.java       |   6 +-
 .../aurora/scheduler/resources/ResourceBag.java |  18 --
 .../scheduler/resources/ResourceManager.java    |   9 +
 .../scheduler/resources/ResourceSlot.java       | 275 -------------------
 .../aurora/scheduler/resources/Resources.java   | 110 --------
 .../aurora/scheduler/app/SchedulerIT.java       |  18 +-
 .../mesos/MesosTaskFactoryImplTest.java         |  38 +--
 .../aurora/scheduler/mesos/TaskExecutors.java   |  16 +-
 .../preemptor/PreemptionVictimFilterTest.java   |  18 +-
 .../resources/MesosResourceConverterTest.java   |   4 +-
 .../scheduler/resources/ResourceSlotTest.java   | 137 ---------
 .../scheduler/resources/ResourceTestUtil.java   |  18 ++
 .../scheduler/resources/ResourcesTest.java      |  76 -----
 18 files changed, 136 insertions(+), 670 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aurora/blob/8c900e58/src/jmh/java/org/apache/aurora/benchmark/Offers.java
----------------------------------------------------------------------
diff --git a/src/jmh/java/org/apache/aurora/benchmark/Offers.java b/src/jmh/java/org/apache/aurora/benchmark/Offers.java
index c22b791..1dabe15 100644
--- a/src/jmh/java/org/apache/aurora/benchmark/Offers.java
+++ b/src/jmh/java/org/apache/aurora/benchmark/Offers.java
@@ -14,18 +14,25 @@
 package org.apache.aurora.benchmark;
 
 import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
 
 import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
 
 import org.apache.aurora.common.quantity.Amount;
 import org.apache.aurora.common.quantity.Data;
 import org.apache.aurora.scheduler.HostOffer;
+import org.apache.aurora.scheduler.base.Numbers;
 import org.apache.aurora.scheduler.offers.OfferManager;
-import org.apache.aurora.scheduler.resources.ResourceSlot;
+import org.apache.aurora.scheduler.resources.ResourceType;
 import org.apache.aurora.scheduler.storage.entities.IHostAttributes;
 import org.apache.mesos.Protos;
 
-import static org.apache.aurora.scheduler.base.TaskTestUtil.DEV_TIER;
+import static org.apache.aurora.scheduler.resources.ResourceType.CPUS;
+import static org.apache.aurora.scheduler.resources.ResourceType.DISK_MB;
+import static org.apache.aurora.scheduler.resources.ResourceType.PORTS;
+import static org.apache.aurora.scheduler.resources.ResourceType.RAM_MB;
 
 /**
  * Offer factory.
@@ -90,8 +97,13 @@ final class Offers {
       int id = 0;
       for (IHostAttributes attributes : hostAttributes) {
         Protos.Offer offer = Protos.Offer.newBuilder()
-            .addAllResources(new ResourceSlot(cpu, ram, disk, ports)
-                .toResourceList(DEV_TIER))
+            .addAllResources(ImmutableSet.of(
+                makeScalar(CPUS, cpu),
+                makeScalar(RAM_MB, ram.getValue()),
+                makeScalar(DISK_MB, disk.getValue()),
+                makeRange(
+                    PORTS,
+                    IntStream.range(1, ports).boxed().collect(Collectors.toSet()))))
             .setId(Protos.OfferID.newBuilder().setValue(String.format(OFFER_ID_FORMAT, id++)))
             .setFrameworkId(Protos.FrameworkID.newBuilder().setValue(FRAMEWORK_ID))
             .setSlaveId(Protos.SlaveID.newBuilder().setValue(attributes.getSlaveId()))
@@ -103,5 +115,22 @@ final class Offers {
 
       return offers.build();
     }
+
+    private static Protos.Resource makeScalar(ResourceType type, double value) {
+      return Protos.Resource.newBuilder()
+          .setType(Protos.Value.Type.SCALAR)
+          .setName(type.getMesosName())
+          .setScalar(Protos.Value.Scalar.newBuilder().setValue(value).build())
+          .build();
+    }
+
+    private static Protos.Resource makeRange(ResourceType type, Iterable<Integer> values) {
+      return Protos.Resource.newBuilder()
+          .setType(Protos.Value.Type.RANGES)
+          .setName(type.getMesosName())
+          .setRanges(Protos.Value.Ranges.newBuilder().addAllRange(
+              Iterables.transform(Numbers.toRanges(values), Numbers.RANGE_TRANSFORM)))
+          .build();
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/aurora/blob/8c900e58/src/main/java/org/apache/aurora/scheduler/base/Numbers.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/base/Numbers.java b/src/main/java/org/apache/aurora/scheduler/base/Numbers.java
index e84070c..1b278e2 100644
--- a/src/main/java/org/apache/aurora/scheduler/base/Numbers.java
+++ b/src/main/java/org/apache/aurora/scheduler/base/Numbers.java
@@ -16,6 +16,7 @@ package org.apache.aurora.scheduler.base;
 import java.util.Set;
 
 import com.google.common.base.Function;
+import com.google.common.collect.ContiguousSet;
 import com.google.common.collect.DiscreteDomain;
 import com.google.common.collect.ImmutableRangeSet;
 import com.google.common.collect.ImmutableSet;
@@ -41,6 +42,14 @@ public final class Numbers {
           .setEnd(input.upperEndpoint())
           .build();
 
+  /**
+   * Convert {@link org.apache.mesos.Protos.Value.Range} to set of integers.
+   */
+  public static final Function<org.apache.mesos.Protos.Value.Range, Set<Integer>> RANGE_TO_MEMBERS =
+      range -> ContiguousSet.create(
+          Range.closed((int) range.getBegin(), (int) range.getEnd()),
+          DiscreteDomain.integers());
+
   private Numbers() {
     // Utility class.
   }

http://git-wip-us.apache.org/repos/asf/aurora/blob/8c900e58/src/main/java/org/apache/aurora/scheduler/mesos/MesosTaskFactory.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/mesos/MesosTaskFactory.java b/src/main/java/org/apache/aurora/scheduler/mesos/MesosTaskFactory.java
index cbe2721..3b01801 100644
--- a/src/main/java/org/apache/aurora/scheduler/mesos/MesosTaskFactory.java
+++ b/src/main/java/org/apache/aurora/scheduler/mesos/MesosTaskFactory.java
@@ -33,8 +33,7 @@ import org.apache.aurora.scheduler.base.SchedulerException;
 import org.apache.aurora.scheduler.base.Tasks;
 import org.apache.aurora.scheduler.configuration.executor.ExecutorSettings;
 import org.apache.aurora.scheduler.resources.AcceptedOffer;
-import org.apache.aurora.scheduler.resources.ResourceSlot;
-import org.apache.aurora.scheduler.resources.Resources;
+import org.apache.aurora.scheduler.resources.ResourceManager;
 import org.apache.aurora.scheduler.storage.entities.IAppcImage;
 import org.apache.aurora.scheduler.storage.entities.IAssignedTask;
 import org.apache.aurora.scheduler.storage.entities.IDockerContainer;
@@ -150,7 +149,7 @@ public interface MesosTaskFactory {
             task,
             executorSettings.getExecutorOverhead(),
             tierManager.getTier(task.getTask()));
-      } catch (Resources.InsufficientResourcesException e) {
+      } catch (ResourceManager.InsufficientResourcesException e) {
         throw new SchedulerException(e);
       }
       Iterable<Resource> resources = acceptedOffer.getTaskResources();
@@ -198,10 +197,8 @@ public interface MesosTaskFactory {
 
       if (taskBuilder.hasExecutor()) {
         taskBuilder.setData(ByteString.copyFrom(serializeTask(task)));
-        return ResourceSlot.matchResourceTypes(taskBuilder.build());
-      } else {
-        return taskBuilder.build();
       }
+      return taskBuilder.build();
     }
 
     private Optional<ContainerInfo.Builder> configureTaskForImage(IMesosContainer mesosContainer) {

http://git-wip-us.apache.org/repos/asf/aurora/blob/8c900e58/src/main/java/org/apache/aurora/scheduler/mesos/TestExecutorSettings.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/mesos/TestExecutorSettings.java b/src/main/java/org/apache/aurora/scheduler/mesos/TestExecutorSettings.java
index 46973b8..1dfa97e 100644
--- a/src/main/java/org/apache/aurora/scheduler/mesos/TestExecutorSettings.java
+++ b/src/main/java/org/apache/aurora/scheduler/mesos/TestExecutorSettings.java
@@ -15,11 +15,9 @@ package org.apache.aurora.scheduler.mesos;
 
 import com.google.common.collect.ImmutableList;
 
-import org.apache.aurora.scheduler.base.TaskTestUtil;
 import org.apache.aurora.scheduler.configuration.executor.ExecutorConfig;
 import org.apache.aurora.scheduler.configuration.executor.ExecutorSettings;
 import org.apache.aurora.scheduler.configuration.executor.Executors;
-import org.apache.aurora.scheduler.resources.ResourceSlot;
 import org.apache.aurora.scheduler.resources.ResourceType;
 import org.apache.mesos.Protos.CommandInfo;
 import org.apache.mesos.Protos.CommandInfo.URI;
@@ -70,10 +68,10 @@ public final class TestExecutorSettings {
       THERMOS_CONFIG,
       false /* populate discovery info */);
 
-  public static ExecutorSettings thermosOnlyWithOverhead(ResourceSlot overhead) {
+  public static ExecutorSettings thermosOnlyWithOverhead(Iterable<Resource> resources) {
     ExecutorConfig config = THERMOS_EXECUTOR.getExecutorConfig();
     ExecutorInfo.Builder executor = config.getExecutor().toBuilder();
-    executor.clearResources().addAllResources(overhead.toResourceList(TaskTestUtil.DEV_TIER));
+    executor.clearResources().addAllResources(resources);
     return new ExecutorSettings(
         new ExecutorConfig(executor.build(), config.getVolumeMounts()),
         false /* populate discovery info */);

http://git-wip-us.apache.org/repos/asf/aurora/blob/8c900e58/src/main/java/org/apache/aurora/scheduler/resources/AcceptedOffer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/resources/AcceptedOffer.java b/src/main/java/org/apache/aurora/scheduler/resources/AcceptedOffer.java
index b28acd5..c100e80 100644
--- a/src/main/java/org/apache/aurora/scheduler/resources/AcceptedOffer.java
+++ b/src/main/java/org/apache/aurora/scheduler/resources/AcceptedOffer.java
@@ -63,7 +63,7 @@ public final class AcceptedOffer {
       Offer offer,
       IAssignedTask task,
       ResourceBag executorOverhead,
-      TierInfo tierInfo) throws Resources.InsufficientResourcesException {
+      TierInfo tierInfo) throws ResourceManager.InsufficientResourcesException {
 
     ImmutableList.Builder<Resource> taskResources = ImmutableList.builder();
     ImmutableList.Builder<Resource> executorResources = ImmutableList.builder();

http://git-wip-us.apache.org/repos/asf/aurora/blob/8c900e58/src/main/java/org/apache/aurora/scheduler/resources/MesosResourceConverter.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/resources/MesosResourceConverter.java b/src/main/java/org/apache/aurora/scheduler/resources/MesosResourceConverter.java
index 25d56b4..3123506 100644
--- a/src/main/java/org/apache/aurora/scheduler/resources/MesosResourceConverter.java
+++ b/src/main/java/org/apache/aurora/scheduler/resources/MesosResourceConverter.java
@@ -104,7 +104,7 @@ public interface MesosResourceConverter {
         // NOTE: this will not happen as long as Veto logic from TaskAssigner.maybeAssign is
         // consistent.
         // Maybe we should consider implementing resource veto with this class to ensure that.
-        throw new Resources.InsufficientResourcesException(
+        throw new ResourceManager.InsufficientResourcesException(
             "Insufficient resource when allocating from offer");
       }
       return result.build();
@@ -132,7 +132,7 @@ public interface MesosResourceConverter {
       ImmutableList.Builder<Resource> result = ImmutableList.builder();
       for (Resource.Builder r : offerResources) {
         Set<Integer> fromResource = Sets.newHashSet(Iterables.concat(
-            Iterables.transform(r.getRanges().getRangeList(), Resources.RANGE_TO_MEMBERS)));
+            Iterables.transform(r.getRanges().getRangeList(), Numbers.RANGE_TO_MEMBERS)));
         Set<Integer> available = Sets.newHashSet(Sets.intersection(leftOver, fromResource));
         if (available.isEmpty()) {
           continue;
@@ -156,7 +156,7 @@ public interface MesosResourceConverter {
         // NOTE: this will not happen as long as Veto logic from TaskAssigner.maybeAssign is
         // consistent.
         // Maybe we should consider implementing resource veto with this class to ensure that.
-        throw new Resources.InsufficientResourcesException(
+        throw new ResourceManager.InsufficientResourcesException(
             "Insufficient resource for range type when allocating from offer");
       }
       return result.build();

http://git-wip-us.apache.org/repos/asf/aurora/blob/8c900e58/src/main/java/org/apache/aurora/scheduler/resources/ResourceBag.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/resources/ResourceBag.java b/src/main/java/org/apache/aurora/scheduler/resources/ResourceBag.java
index 390654b..3cff946 100644
--- a/src/main/java/org/apache/aurora/scheduler/resources/ResourceBag.java
+++ b/src/main/java/org/apache/aurora/scheduler/resources/ResourceBag.java
@@ -22,14 +22,10 @@ import java.util.stream.Stream;
 import com.google.common.base.MoreObjects;
 import com.google.common.collect.ImmutableMap;
 
-import org.apache.aurora.common.quantity.Amount;
-import org.apache.aurora.common.quantity.Data;
-
 import static java.util.stream.Collectors.toMap;
 
 import static org.apache.aurora.scheduler.resources.ResourceType.CPUS;
 import static org.apache.aurora.scheduler.resources.ResourceType.DISK_MB;
-import static org.apache.aurora.scheduler.resources.ResourceType.PORTS;
 import static org.apache.aurora.scheduler.resources.ResourceType.RAM_MB;
 
 /**
@@ -177,20 +173,6 @@ public class ResourceBag {
         .collect(toMap(Map.Entry::getKey, Map.Entry::getValue)));
   }
 
-  /**
-   * Temporary bridge between bag and slot to facilitate migration.
-   *
-   * TODO(maxim): remove together with ResourceSlot.
-   * @return ResourceSlot.
-   */
-  public ResourceSlot toSlot() {
-    return new ResourceSlot(
-        valueOf(CPUS),
-        Amount.of(valueOf(RAM_MB).longValue(), Data.MB),
-        Amount.of(valueOf(DISK_MB).longValue(), Data.MB),
-        valueOf(PORTS).intValue());
-  }
-
   private ResourceBag binaryOp(ResourceBag other, BinaryOperator<Double> operator) {
     ImmutableMap.Builder<ResourceType, Double> builder = ImmutableMap.builder();
     for (Map.Entry<ResourceType, Double> entry : resourceVectors.entrySet()) {

http://git-wip-us.apache.org/repos/asf/aurora/blob/8c900e58/src/main/java/org/apache/aurora/scheduler/resources/ResourceManager.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/resources/ResourceManager.java b/src/main/java/org/apache/aurora/scheduler/resources/ResourceManager.java
index cc1d758..caacc58 100644
--- a/src/main/java/org/apache/aurora/scheduler/resources/ResourceManager.java
+++ b/src/main/java/org/apache/aurora/scheduler/resources/ResourceManager.java
@@ -280,4 +280,13 @@ public final class ResourceManager {
                 .reduce(REDUCE_VALUES)
                 .orElse(0.0))));
   }
+
+  /**
+   * Thrown when there are insufficient resources to satisfy a request.
+   */
+  public static class InsufficientResourcesException extends RuntimeException {
+    InsufficientResourcesException(String message) {
+      super(message);
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/aurora/blob/8c900e58/src/main/java/org/apache/aurora/scheduler/resources/ResourceSlot.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/resources/ResourceSlot.java b/src/main/java/org/apache/aurora/scheduler/resources/ResourceSlot.java
deleted file mode 100644
index 81a3bf8..0000000
--- a/src/main/java/org/apache/aurora/scheduler/resources/ResourceSlot.java
+++ /dev/null
@@ -1,275 +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.resources;
-
-import java.util.List;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
-import java.util.function.Consumer;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-
-import org.apache.aurora.common.quantity.Amount;
-import org.apache.aurora.common.quantity.Data;
-import org.apache.aurora.scheduler.TierInfo;
-import org.apache.aurora.scheduler.base.Numbers;
-import org.apache.aurora.scheduler.storage.entities.ITaskConfig;
-import org.apache.mesos.Protos;
-import org.apache.mesos.Protos.ExecutorInfo;
-import org.apache.mesos.Protos.Resource;
-import org.apache.mesos.Protos.Resource.Builder;
-import org.apache.mesos.Protos.TaskInfo;
-
-import static java.util.Objects.requireNonNull;
-
-import static org.apache.aurora.common.quantity.Data.BYTES;
-import static org.apache.aurora.scheduler.resources.ResourceType.CPUS;
-import static org.apache.aurora.scheduler.resources.ResourceType.DISK_MB;
-import static org.apache.aurora.scheduler.resources.ResourceType.PORTS;
-import static org.apache.aurora.scheduler.resources.ResourceType.RAM_MB;
-
-/**
- * Represents a single task/host aggregate resource vector unaware of any Mesos resource traits.
- */
-public final class ResourceSlot {
-
-  private final double numCpus;
-  private final Amount<Long, Data> disk;
-  private final Amount<Long, Data> ram;
-  private final int numPorts;
-
-  /**
-   * Empty ResourceSlot value.
-   */
-  public static final ResourceSlot NONE =
-      new ResourceSlot(0, Amount.of(0L, Data.BITS), Amount.of(0L, Data.BITS), 0);
-
-  public ResourceSlot(
-      double numCpus,
-      Amount<Long, Data> ram,
-      Amount<Long, Data> disk,
-      int numPorts) {
-
-    this.numCpus = numCpus;
-    this.ram = requireNonNull(ram);
-    this.disk = requireNonNull(disk);
-    this.numPorts = numPorts;
-  }
-
-  /**
-   * Extracts the resources required from a task.
-   *
-   * @param task Task to get resources from.
-   * @return The resources required by the task.
-   */
-  public static ResourceSlot from(ITaskConfig task) {
-    requireNonNull(task);
-    return new ResourceSlot(
-        task.getNumCpus(),
-        Amount.of(task.getRamMb(), Data.MB),
-        Amount.of(task.getDiskMb(), Data.MB),
-        Iterables.size(ResourceManager.getTaskResources(task, PORTS)));
-  }
-
-  /**
-   * Ensures that the revocable setting on the executor and task CPU resources match.
-   *
-   * @param task Task to check for resource type alignment.
-   * @return A possibly-modified task, with aligned CPU resource types.
-   */
-  public static TaskInfo matchResourceTypes(TaskInfo task) {
-    TaskInfo.Builder taskBuilder = task.toBuilder();
-
-    Optional<Resource> revocableTaskCpu = taskBuilder.getResourcesList().stream()
-        .filter(r -> r.getName().equals(CPUS.getMesosName()))
-        .filter(Resource::hasRevocable)
-        .findFirst();
-    ExecutorInfo.Builder executorBuilder = taskBuilder.getExecutorBuilder();
-
-    Consumer<Builder> matchRevocable = builder -> {
-      if (revocableTaskCpu.isPresent()) {
-        builder.setRevocable(revocableTaskCpu.get().getRevocable());
-      } else {
-        builder.clearRevocable();
-      }
-    };
-
-    executorBuilder.getResourcesBuilderList().stream()
-        .filter(r -> r.getName().equals(CPUS.getMesosName()))
-        .forEach(matchRevocable);
-
-    return taskBuilder.build();
-  }
-
-  /**
-   * Convenience method for adapting to Mesos resources without applying a port range.
-   *
-   * @param tierInfo Task tier info.
-   * @return Mesos resources.
-   */
-  public List<Protos.Resource> toResourceList(TierInfo tierInfo) {
-    return ImmutableList.<Protos.Resource>builder()
-        .add(makeMesosResource(CPUS, numCpus, tierInfo.isRevocable()))
-        .add(makeMesosResource(DISK_MB, disk.as(Data.MB), false))
-        .add(makeMesosResource(RAM_MB, ram.as(Data.MB), false))
-        .build();
-  }
-
-  /**
-   * Creates a mesos resource of integer ranges.
-   *
-   * @param resourceType Resource type.
-   * @param values    Values to translate into ranges.
-   * @return A new mesos ranges resource.
-   */
-  @VisibleForTesting
-  public static Protos.Resource makeMesosRangeResource(
-      ResourceType resourceType,
-      Set<Integer> values) {
-
-    return Protos.Resource.newBuilder()
-        .setName(resourceType.getMesosName())
-        .setType(Protos.Value.Type.RANGES)
-        .setRanges(Protos.Value.Ranges.newBuilder()
-            .addAllRange(Iterables.transform(Numbers.toRanges(values), Numbers.RANGE_TRANSFORM)))
-        .build();
-  }
-
-  /**
-   * Creates a scalar mesos resource.
-   *
-   * @param resourceType Resource type.
-   * @param value Value for the resource.
-   * @param revocable Flag indicating if this resource is revocable.
-   * @return A mesos resource.
-   */
-  @VisibleForTesting
-  static Protos.Resource makeMesosResource(
-      ResourceType resourceType,
-      double value,
-      boolean revocable) {
-
-    Protos.Resource.Builder builder = Protos.Resource.newBuilder()
-        .setName(resourceType.getMesosName())
-        .setType(Protos.Value.Type.SCALAR)
-        .setScalar(Protos.Value.Scalar.newBuilder().setValue(value));
-
-    if (revocable) {
-      builder.setRevocable(Protos.Resource.RevocableInfo.newBuilder());
-    }
-
-    return builder.build();
-  }
-
-  /**
-   * Number of CPUs.
-   *
-   * @return CPUs.
-   */
-  public double getNumCpus() {
-    return numCpus;
-  }
-
-  /**
-   * Disk amount.
-   *
-   * @return Disk.
-   */
-  public Amount<Long, Data> getDisk() {
-    return disk;
-  }
-
-  /**
-   * RAM amount.
-   *
-   * @return RAM.
-   */
-  public Amount<Long, Data> getRam() {
-    return ram;
-  }
-
-  /**
-   * Number of ports.
-   *
-   * @return Port count.
-   */
-  public int getNumPorts() {
-    return numPorts;
-  }
-
-  @Override
-  public boolean equals(Object o) {
-    if (!(o instanceof ResourceSlot)) {
-      return false;
-    }
-
-    ResourceSlot other = (ResourceSlot) o;
-    return Objects.equals(numCpus, other.numCpus)
-        && Objects.equals(ram, other.ram)
-        && Objects.equals(disk, other.disk)
-        && Objects.equals(numPorts, other.numPorts);
-  }
-
-  @Override
-  public int hashCode() {
-    return Objects.hash(numCpus, ram, disk, numPorts);
-  }
-
-  /**
-   * Sums up all resources in {@code slots}.
-   *
-   * @param slots Resource slots to sum up.
-   * @return Sum of all resource slots.
-   */
-  public static ResourceSlot sum(Iterable<ResourceSlot> slots) {
-    ResourceSlot sum = NONE;
-
-    for (ResourceSlot r : slots) {
-      sum = sum.add(r);
-    }
-
-    return sum;
-  }
-
-  /**
-   * Adds {@code other}.
-   *
-   * @param other Resource slot to add.
-   * @return Result.
-   */
-  public ResourceSlot add(ResourceSlot other) {
-    return new ResourceSlot(
-        getNumCpus() + other.getNumCpus(),
-        Amount.of(getRam().as(BYTES) + other.getRam().as(BYTES), BYTES),
-        Amount.of(getDisk().as(BYTES) + other.getDisk().as(BYTES), BYTES),
-        getNumPorts() + other.getNumPorts());
-  }
-
-  /**
-   * Subtracts {@code other}.
-   *
-   * @param other Resource slot to subtract.
-   * @return Result.
-   */
-  public ResourceSlot subtract(ResourceSlot other) {
-    return new ResourceSlot(
-        getNumCpus() - other.getNumCpus(),
-        Amount.of(getRam().as(BYTES) - other.getRam().as(BYTES), BYTES),
-        Amount.of(getDisk().as(BYTES) - other.getDisk().as(BYTES), BYTES),
-        getNumPorts() - other.getNumPorts());
-  }
-}

http://git-wip-us.apache.org/repos/asf/aurora/blob/8c900e58/src/main/java/org/apache/aurora/scheduler/resources/Resources.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/resources/Resources.java b/src/main/java/org/apache/aurora/scheduler/resources/Resources.java
deleted file mode 100644
index 2ced8dd..0000000
--- a/src/main/java/org/apache/aurora/scheduler/resources/Resources.java
+++ /dev/null
@@ -1,110 +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.resources;
-
-import java.util.Set;
-
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.collect.ContiguousSet;
-import com.google.common.collect.DiscreteDomain;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-
-import org.apache.aurora.common.quantity.Amount;
-import org.apache.aurora.common.quantity.Data;
-import org.apache.aurora.scheduler.TierInfo;
-import org.apache.mesos.Protos.Offer;
-import org.apache.mesos.Protos.Resource;
-import org.apache.mesos.Protos.Value.Range;
-
-import static java.util.Objects.requireNonNull;
-
-import static org.apache.aurora.scheduler.resources.ResourceManager.NON_REVOCABLE;
-import static org.apache.aurora.scheduler.resources.ResourceManager.REVOCABLE;
-import static org.apache.aurora.scheduler.resources.ResourceManager.quantityOfMesosResource;
-import static org.apache.aurora.scheduler.resources.ResourceType.CPUS;
-import static org.apache.aurora.scheduler.resources.ResourceType.DISK_MB;
-import static org.apache.aurora.scheduler.resources.ResourceType.PORTS;
-import static org.apache.aurora.scheduler.resources.ResourceType.RAM_MB;
-
-/**
- * A container for multiple Mesos resource vectors.
- */
-public final class Resources {
-  /**
-   * Convert range to set of integers.
-   */
-  public static final Function<Range, Set<Integer>> RANGE_TO_MEMBERS =
-      range -> ContiguousSet.create(
-          com.google.common.collect.Range.closed((int) range.getBegin(), (int) range.getEnd()),
-          DiscreteDomain.integers());
-
-  private final Iterable<Resource> mesosResources;
-
-  private Resources(Iterable<Resource> mesosResources) {
-    this.mesosResources = ImmutableList.copyOf(mesosResources);
-  }
-
-  /**
-   * Extracts the resources available in a slave offer.
-   *
-   * @param offer Offer to get resources from.
-   * @return The resources available in the offer.
-   */
-  public static Resources from(Offer offer) {
-    return new Resources(requireNonNull(offer.getResourcesList()));
-  }
-
-  /**
-   * Filters resources by the provided {@code predicate}.
-   *
-   * @param predicate Predicate filter.
-   * @return A new {@code Resources} object containing only filtered Mesos resources.
-   */
-  public Resources filter(Predicate<Resource> predicate) {
-    return new Resources(Iterables.filter(mesosResources, predicate));
-  }
-
-  /**
-   * Filters resources using the provided {@code tierInfo} instance.
-   *
-   * @param tierInfo Tier info.
-   * @return A new {@code Resources} object containing only filtered Mesos resources.
-   */
-  public Resources filter(TierInfo tierInfo) {
-    return filter(tierInfo.isRevocable() ? REVOCABLE : NON_REVOCABLE);
-  }
-
-  /**
-   * Gets generalized aggregated resource view.
-   *
-   * @return {@code ResourceSlot} instance.
-   */
-  public ResourceSlot slot() {
-    return new ResourceSlot(quantityOfMesosResource(mesosResources, CPUS),
-        Amount.of(quantityOfMesosResource(mesosResources, RAM_MB).longValue(), Data.MB),
-        Amount.of(quantityOfMesosResource(mesosResources, DISK_MB).longValue(), Data.MB),
-        quantityOfMesosResource(mesosResources, PORTS).intValue());
-  }
-
-  /**
-   * Thrown when there are insufficient resources to satisfy a request.
-   */
-  public static class InsufficientResourcesException extends RuntimeException {
-    InsufficientResourcesException(String message) {
-      super(message);
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/aurora/blob/8c900e58/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 1e9e1ae..8c8c793 100644
--- a/src/test/java/org/apache/aurora/scheduler/app/SchedulerIT.java
+++ b/src/test/java/org/apache/aurora/scheduler/app/SchedulerIT.java
@@ -16,6 +16,7 @@ package org.apache.aurora.scheduler.app;
 import java.io.File;
 import java.net.InetSocketAddress;
 import java.util.Arrays;
+import java.util.Set;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -41,8 +42,6 @@ import com.google.inject.Module;
 import org.apache.aurora.GuavaUtils;
 import org.apache.aurora.codec.ThriftBinaryCodec.CodingException;
 import org.apache.aurora.common.application.Lifecycle;
-import org.apache.aurora.common.quantity.Amount;
-import org.apache.aurora.common.quantity.Data;
 import org.apache.aurora.common.stats.Stats;
 import org.apache.aurora.common.zookeeper.Credentials;
 import org.apache.aurora.common.zookeeper.ServerSetImpl;
@@ -73,7 +72,6 @@ import org.apache.aurora.scheduler.log.Log.Stream;
 import org.apache.aurora.scheduler.mesos.DriverFactory;
 import org.apache.aurora.scheduler.mesos.DriverSettings;
 import org.apache.aurora.scheduler.mesos.TestExecutorSettings;
-import org.apache.aurora.scheduler.resources.ResourceSlot;
 import org.apache.aurora.scheduler.storage.backup.BackupModule;
 import org.apache.aurora.scheduler.storage.entities.IHostAttributes;
 import org.apache.aurora.scheduler.storage.entities.IScheduledTask;
@@ -83,6 +81,7 @@ import org.apache.aurora.scheduler.storage.log.LogStorageModule;
 import org.apache.aurora.scheduler.storage.log.SnapshotStoreImpl;
 import org.apache.aurora.scheduler.storage.log.testing.LogOpMatcher;
 import org.apache.aurora.scheduler.storage.log.testing.LogOpMatcher.StreamMatcher;
+import org.apache.mesos.Protos;
 import org.apache.mesos.Protos.FrameworkID;
 import org.apache.mesos.Protos.MasterInfo;
 import org.apache.mesos.Protos.Status;
@@ -99,6 +98,9 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import static org.apache.aurora.common.testing.easymock.EasyMockTest.createCapture;
+import static org.apache.aurora.scheduler.resources.ResourceTestUtil.mesosScalar;
+import static org.apache.aurora.scheduler.resources.ResourceType.CPUS;
+import static org.apache.aurora.scheduler.resources.ResourceType.RAM_MB;
 import static org.apache.mesos.Protos.FrameworkInfo;
 import static org.easymock.EasyMock.capture;
 import static org.easymock.EasyMock.createControl;
@@ -184,13 +186,11 @@ public class SchedulerIT extends BaseZooKeeperClientTest {
         bind(DriverFactory.class).toInstance(driverFactory);
         bind(DriverSettings.class).toInstance(SETTINGS);
         bind(Log.class).toInstance(log);
-        ResourceSlot executorOverhead = new ResourceSlot(
-            0.1,
-            Amount.of(1L, Data.MB),
-            Amount.of(0L, Data.MB),
-            0);
+        Set<Protos.Resource> overhead = ImmutableSet.of(
+            mesosScalar(CPUS, 0.1),
+            mesosScalar(RAM_MB, 1));
         bind(ExecutorSettings.class)
-            .toInstance(TestExecutorSettings.thermosOnlyWithOverhead(executorOverhead));
+            .toInstance(TestExecutorSettings.thermosOnlyWithOverhead(overhead));
         install(new BackupModule(backupDir, SnapshotStoreImpl.class));
 
         bind(IServerInfo.class).toInstance(

http://git-wip-us.apache.org/repos/asf/aurora/blob/8c900e58/src/test/java/org/apache/aurora/scheduler/mesos/MesosTaskFactoryImplTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/mesos/MesosTaskFactoryImplTest.java b/src/test/java/org/apache/aurora/scheduler/mesos/MesosTaskFactoryImplTest.java
index b2dd7ad..58785bf 100644
--- a/src/test/java/org/apache/aurora/scheduler/mesos/MesosTaskFactoryImplTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/mesos/MesosTaskFactoryImplTest.java
@@ -13,6 +13,7 @@
  */
 package org.apache.aurora.scheduler.mesos;
 
+import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
 
@@ -70,8 +71,10 @@ import static org.apache.aurora.scheduler.mesos.TestExecutorSettings.THERMOS_CON
 import static org.apache.aurora.scheduler.mesos.TestExecutorSettings.THERMOS_EXECUTOR;
 import static org.apache.aurora.scheduler.resources.ResourceManager.bagFromMesosResources;
 import static org.apache.aurora.scheduler.resources.ResourceManager.bagFromResources;
-import static org.apache.aurora.scheduler.resources.ResourceSlot.makeMesosRangeResource;
+import static org.apache.aurora.scheduler.resources.ResourceTestUtil.mesosRange;
+import static org.apache.aurora.scheduler.resources.ResourceTestUtil.mesosScalarFromBag;
 import static org.apache.aurora.scheduler.resources.ResourceTestUtil.resetPorts;
+import static org.apache.aurora.scheduler.resources.ResourceType.PORTS;
 import static org.easymock.EasyMock.expect;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -116,19 +119,15 @@ public class MesosTaskFactoryImplTest extends EasyMockTest {
       .setFrameworkId(Protos.FrameworkID.newBuilder().setValue("framework-id"))
       .setSlaveId(SLAVE)
       .setHostname("slave-hostname")
-      .addAllResources(
-          bagFromResources(TASK_CONFIG.getResources()).add(THERMOS_EXECUTOR.getExecutorOverhead())
-              .toSlot()
-              .toResourceList(DEV_TIER))
-      .addResources(makeMesosRangeResource(ResourceType.PORTS, ImmutableSet.of(80)))
+      .addAllResources(mesosScalarFromBag(bagFromResources(
+              TASK_CONFIG.getResources()).add(THERMOS_EXECUTOR.getExecutorOverhead())))
+      .addResources(mesosRange(PORTS, 80))
       .build();
   private static final Offer OFFER_SOME_OVERHEAD_EXECUTOR = OFFER_THERMOS_EXECUTOR.toBuilder()
       .clearResources()
-      .addAllResources(bagFromResources(TASK_CONFIG.getResources())
-          .add(SOME_OVERHEAD_EXECUTOR.getExecutorOverhead())
-          .toSlot()
-          .toResourceList(DEV_TIER))
-      .addResources(makeMesosRangeResource(ResourceType.PORTS, ImmutableSet.of(80)))
+      .addAllResources(mesosScalarFromBag(bagFromResources(
+          TASK_CONFIG.getResources()).add(SOME_OVERHEAD_EXECUTOR.getExecutorOverhead())))
+      .addResources(mesosRange(PORTS, 80))
       .build();
 
   private static final String CLUSTER_NAME = "cluster_name";
@@ -191,12 +190,19 @@ public class MesosTaskFactoryImplTest extends EasyMockTest {
     expect(tierManager.getTier(TASK_CONFIG)).andReturn(REVOCABLE_TIER);
     taskFactory = new MesosTaskFactoryImpl(config, tierManager, SERVER_INFO);
 
-    Resource revocableCPU = OFFER_THERMOS_EXECUTOR.getResources(0).toBuilder()
-        .setRevocable(Resource.RevocableInfo.getDefaultInstance())
-        .build();
+    List<Resource> revocable = OFFER_THERMOS_EXECUTOR.getResourcesList().stream()
+        .map(r -> {
+          ResourceType type = ResourceType.fromResource(r);
+          if (type.isMesosRevocable()) {
+            r = r.toBuilder().setRevocable(Resource.RevocableInfo.getDefaultInstance()).build();
+          }
+          return r;
+        })
+        .collect(Collectors.toList());
+
     Offer withRevocable = OFFER_THERMOS_EXECUTOR.toBuilder()
-        .removeResources(0)
-        .addResources(0, revocableCPU)
+        .clearResources()
+        .addAllResources(revocable)
         .build();
 
     control.replay();

http://git-wip-us.apache.org/repos/asf/aurora/blob/8c900e58/src/test/java/org/apache/aurora/scheduler/mesos/TaskExecutors.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/mesos/TaskExecutors.java b/src/test/java/org/apache/aurora/scheduler/mesos/TaskExecutors.java
index 651cfa7..0ab4659 100644
--- a/src/test/java/org/apache/aurora/scheduler/mesos/TaskExecutors.java
+++ b/src/test/java/org/apache/aurora/scheduler/mesos/TaskExecutors.java
@@ -13,10 +13,13 @@
  */
 package org.apache.aurora.scheduler.mesos;
 
-import org.apache.aurora.common.quantity.Amount;
-import org.apache.aurora.common.quantity.Data;
+import com.google.common.collect.ImmutableSet;
+
 import org.apache.aurora.scheduler.configuration.executor.ExecutorSettings;
-import org.apache.aurora.scheduler.resources.ResourceSlot;
+
+import static org.apache.aurora.scheduler.resources.ResourceTestUtil.mesosScalar;
+import static org.apache.aurora.scheduler.resources.ResourceType.CPUS;
+import static org.apache.aurora.scheduler.resources.ResourceType.RAM_MB;
 
 /**
  * Utility class to contain constants related to setting up executor settings.
@@ -28,9 +31,10 @@ public final class TaskExecutors {
   }
 
   public static final ExecutorSettings NO_OVERHEAD_EXECUTOR =
-      TestExecutorSettings.thermosOnlyWithOverhead(ResourceSlot.NONE);
+      TestExecutorSettings.thermosOnlyWithOverhead(ImmutableSet.of());
 
   public static final ExecutorSettings SOME_OVERHEAD_EXECUTOR =
-      TestExecutorSettings.thermosOnlyWithOverhead(
-          new ResourceSlot(0.01, Amount.of(256L, Data.MB), Amount.of(0L, Data.MB), 0));
+      TestExecutorSettings.thermosOnlyWithOverhead(ImmutableSet.of(
+          mesosScalar(CPUS, 0.01),
+          mesosScalar(RAM_MB, 256)));
 }

http://git-wip-us.apache.org/repos/asf/aurora/blob/8c900e58/src/test/java/org/apache/aurora/scheduler/preemptor/PreemptionVictimFilterTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/preemptor/PreemptionVictimFilterTest.java b/src/test/java/org/apache/aurora/scheduler/preemptor/PreemptionVictimFilterTest.java
index 99a980a..88beda7 100644
--- a/src/test/java/org/apache/aurora/scheduler/preemptor/PreemptionVictimFilterTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/preemptor/PreemptionVictimFilterTest.java
@@ -15,6 +15,7 @@ package org.apache.aurora.scheduler.preemptor;
 
 import java.util.List;
 import java.util.Set;
+import java.util.stream.IntStream;
 
 import com.google.common.base.Optional;
 import com.google.common.collect.FluentIterable;
@@ -41,7 +42,6 @@ import org.apache.aurora.scheduler.filter.SchedulingFilter.Veto;
 import org.apache.aurora.scheduler.filter.SchedulingFilterImpl;
 import org.apache.aurora.scheduler.mesos.TaskExecutors;
 import org.apache.aurora.scheduler.resources.ResourceBag;
-import org.apache.aurora.scheduler.resources.ResourceSlot;
 import org.apache.aurora.scheduler.resources.ResourceTestUtil;
 import org.apache.aurora.scheduler.resources.ResourceType;
 import org.apache.aurora.scheduler.stats.CachedCounters;
@@ -56,6 +56,8 @@ import org.easymock.IExpectationSetters;
 import org.junit.Before;
 import org.junit.Test;
 
+import static java.util.stream.Collectors.toSet;
+
 import static org.apache.aurora.gen.MaintenanceMode.NONE;
 import static org.apache.aurora.gen.ScheduleStatus.RUNNING;
 import static org.apache.aurora.scheduler.base.TaskTestUtil.DEV_TIER;
@@ -65,7 +67,11 @@ import static org.apache.aurora.scheduler.filter.AttributeAggregate.EMPTY;
 import static org.apache.aurora.scheduler.preemptor.PreemptionVictimFilter.PreemptionVictimFilterImpl.ORDER;
 import static org.apache.aurora.scheduler.preemptor.PreemptorMetrics.MISSING_ATTRIBUTES_NAME;
 import static org.apache.aurora.scheduler.resources.ResourceTestUtil.bag;
+import static org.apache.aurora.scheduler.resources.ResourceTestUtil.mesosRange;
+import static org.apache.aurora.scheduler.resources.ResourceTestUtil.mesosScalar;
 import static org.apache.aurora.scheduler.resources.ResourceType.CPUS;
+import static org.apache.aurora.scheduler.resources.ResourceType.DISK_MB;
+import static org.apache.aurora.scheduler.resources.ResourceType.PORTS;
 import static org.apache.aurora.scheduler.resources.ResourceType.RAM_MB;
 import static org.apache.mesos.Protos.Offer;
 import static org.apache.mesos.Protos.Resource;
@@ -560,8 +566,14 @@ public class PreemptionVictimFilterTest extends EasyMockTest {
       int numPorts,
       boolean revocable) {
 
-    List<Resource> resources =
-        new ResourceSlot(cpu, ram, disk, numPorts).toResourceList(DEV_TIER);
+    List<Resource> resources = ImmutableList.of(
+        mesosScalar(CPUS, cpu),
+        mesosScalar(RAM_MB, ram.getValue()),
+        mesosScalar(DISK_MB, disk.getValue()),
+        mesosRange(
+            PORTS,
+            Optional.absent(),
+            IntStream.range(1, numPorts).boxed().collect(toSet())));
     if (revocable) {
       resources = ImmutableList.<Resource>builder()
           .addAll(FluentIterable.from(resources)

http://git-wip-us.apache.org/repos/asf/aurora/blob/8c900e58/src/test/java/org/apache/aurora/scheduler/resources/MesosResourceConverterTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/resources/MesosResourceConverterTest.java b/src/test/java/org/apache/aurora/scheduler/resources/MesosResourceConverterTest.java
index a8c93f9..2f67ef4 100644
--- a/src/test/java/org/apache/aurora/scheduler/resources/MesosResourceConverterTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/resources/MesosResourceConverterTest.java
@@ -83,7 +83,7 @@ public class MesosResourceConverterTest {
     assertEquals(expected, actual);
   }
 
-  @Test(expected = Resources.InsufficientResourcesException.class)
+  @Test(expected = ResourceManager.InsufficientResourcesException.class)
   public void testAllocateRangeInsufficent() {
     RANGES.toMesosResource(
         ImmutableSet.of(mesosRange(PORTS, Optional.absent(), 80, 81, 90, 91, 92).toBuilder()),
@@ -121,7 +121,7 @@ public class MesosResourceConverterTest {
     assertEquals(expected, actual);
   }
 
-  @Test(expected = Resources.InsufficientResourcesException.class)
+  @Test(expected = ResourceManager.InsufficientResourcesException.class)
   public void testAllocateScalarInsufficent() {
     SCALAR.toMesosResource(
         ImmutableSet.of(mesosScalar(RAM_MB, 32.0).toBuilder()),

http://git-wip-us.apache.org/repos/asf/aurora/blob/8c900e58/src/test/java/org/apache/aurora/scheduler/resources/ResourceSlotTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/resources/ResourceSlotTest.java b/src/test/java/org/apache/aurora/scheduler/resources/ResourceSlotTest.java
deleted file mode 100644
index 1f1cb18..0000000
--- a/src/test/java/org/apache/aurora/scheduler/resources/ResourceSlotTest.java
+++ /dev/null
@@ -1,137 +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.resources;
-
-import java.util.Set;
-
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-
-import org.apache.aurora.common.collections.Pair;
-import org.apache.aurora.common.quantity.Amount;
-import org.apache.aurora.common.quantity.Data;
-import org.apache.aurora.gen.TaskConfig;
-import org.apache.aurora.scheduler.storage.entities.ITaskConfig;
-import org.apache.mesos.Protos;
-import org.junit.Test;
-
-import static org.apache.aurora.scheduler.base.TaskTestUtil.DEV_TIER;
-import static org.apache.aurora.scheduler.base.TaskTestUtil.REVOCABLE_TIER;
-import static org.apache.aurora.scheduler.resources.ResourceSlot.makeMesosRangeResource;
-import static org.apache.aurora.scheduler.resources.ResourceSlot.makeMesosResource;
-import static org.apache.aurora.scheduler.resources.ResourceType.CPUS;
-import static org.apache.aurora.scheduler.resources.ResourceType.DISK_MB;
-import static org.apache.aurora.scheduler.resources.ResourceType.PORTS;
-import static org.apache.aurora.scheduler.resources.ResourceType.RAM_MB;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-
-public class ResourceSlotTest {
-
-  private static final ResourceSlot NEGATIVE_ONE =
-      new ResourceSlot(-1.0, Amount.of(-1L, Data.MB), Amount.of(-1L, Data.MB), -1);
-  private static final ResourceSlot ONE =
-      new ResourceSlot(1.0, Amount.of(1L, Data.MB), Amount.of(1L, Data.MB), 1);
-  private static final ResourceSlot TWO =
-      new ResourceSlot(2.0, Amount.of(2L, Data.MB), Amount.of(2L, Data.MB), 2);
-  private static final ResourceSlot THREE =
-      new ResourceSlot(3.0, Amount.of(3L, Data.MB), Amount.of(3L, Data.MB), 3);
-  private static final ITaskConfig TASK = ITaskConfig.build(new TaskConfig()
-      .setNumCpus(1.0)
-      .setRamMb(1024)
-      .setDiskMb(2048)
-      .setRequestedPorts(ImmutableSet.of("http", "debug")));
-
-  @Test
-  public void testSubtract() {
-    assertEquals(ONE, TWO.subtract(ONE));
-    assertEquals(TWO, THREE.subtract(ONE));
-    assertEquals(NEGATIVE_ONE, ONE.subtract(TWO));
-    assertEquals(NEGATIVE_ONE, TWO.subtract(THREE));
-  }
-
-  @Test
-  public void testToResourceListNoRevoca() {
-    ResourceSlot resources = ResourceSlot.from(TASK);
-    assertEquals(
-        ImmutableSet.of(
-            makeMesosResource(CPUS, TASK.getNumCpus(), false),
-            makeMesosResource(RAM_MB, TASK.getRamMb(), false),
-            makeMesosResource(DISK_MB, TASK.getDiskMb(), false)),
-        ImmutableSet.copyOf(resources.toResourceList(DEV_TIER)));
-  }
-
-  @Test
-  public void testToResourceListRevocable() {
-    ResourceSlot resources = ResourceSlot.from(TASK);
-    assertEquals(
-        ImmutableSet.of(
-            makeMesosResource(CPUS, TASK.getNumCpus(), true),
-            makeMesosResource(RAM_MB, TASK.getRamMb(), false),
-            makeMesosResource(DISK_MB, TASK.getDiskMb(), false)),
-        ImmutableSet.copyOf(resources.toResourceList(REVOCABLE_TIER)));
-  }
-
-  @Test
-  public void testToResourceListNoPorts() {
-    ResourceSlot resources = ResourceSlot.from(TASK);
-    assertEquals(
-        ImmutableSet.of(
-            makeMesosResource(CPUS, TASK.getNumCpus(), true),
-            makeMesosResource(RAM_MB, TASK.getRamMb(), false),
-            makeMesosResource(DISK_MB, TASK.getDiskMb(), false)),
-        ImmutableSet.copyOf(resources.toResourceList(REVOCABLE_TIER)));
-  }
-
-  @Test
-  public void testRangeResourceEmpty() {
-    expectRanges(ImmutableSet.of(), ImmutableSet.of());
-  }
-
-  @Test
-  public void testRangeResourceOneEntry() {
-    expectRanges(ImmutableSet.of(Pair.of(5L, 5L)), ImmutableSet.of(5));
-    expectRanges(ImmutableSet.of(Pair.of(0L, 0L)), ImmutableSet.of(0));
-  }
-
-  @Test
-  public void testRangeResourceNonContiguous() {
-    expectRanges(ImmutableSet.of(Pair.of(1L, 1L), Pair.of(3L, 3L), Pair.of(5L, 5L)),
-        ImmutableSet.of(5, 1, 3));
-  }
-
-  @Test
-  public void testRangeResourceContiguous() {
-    expectRanges(ImmutableSet.of(Pair.of(1L, 2L), Pair.of(4L, 5L), Pair.of(7L, 9L)),
-        ImmutableSet.of(8, 2, 4, 5, 7, 9, 1));
-  }
-
-  @Test
-  public void testEqualsBadType() {
-    ResourceSlot resources = ResourceSlot.from(TASK);
-    assertNotEquals(resources, "Hello");
-    assertNotEquals(resources, null);
-  }
-
-  private void expectRanges(Set<Pair<Long, Long>> expected, Set<Integer> values) {
-    Protos.Resource resource = makeMesosRangeResource(PORTS, values);
-    assertEquals(Protos.Value.Type.RANGES, resource.getType());
-    assertEquals(PORTS.getMesosName(), resource.getName());
-
-    Set<Pair<Long, Long>> actual = ImmutableSet.copyOf(Iterables.transform(
-        resource.getRanges().getRangeList(),
-        range -> Pair.of(range.getBegin(), range.getEnd())));
-    assertEquals(expected, actual);
-  }
-}

http://git-wip-us.apache.org/repos/asf/aurora/blob/8c900e58/src/test/java/org/apache/aurora/scheduler/resources/ResourceTestUtil.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/resources/ResourceTestUtil.java b/src/test/java/org/apache/aurora/scheduler/resources/ResourceTestUtil.java
index be7bd32..7dc8c17 100644
--- a/src/test/java/org/apache/aurora/scheduler/resources/ResourceTestUtil.java
+++ b/src/test/java/org/apache/aurora/scheduler/resources/ResourceTestUtil.java
@@ -15,6 +15,7 @@ package org.apache.aurora.scheduler.resources;
 
 import java.util.Map;
 import java.util.Set;
+import java.util.stream.Collectors;
 
 import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableSet;
@@ -114,6 +115,23 @@ public final class ResourceTestUtil {
         .build();
   }
 
+  public static Protos.Resource mesosRange(
+      ResourceType type,
+      Optional<String> role,
+      Iterable<Integer> values) {
+
+    return resourceBuilder(type, role, false)
+        .setRanges(Protos.Value.Ranges.newBuilder().addAllRange(
+            Iterables.transform(Numbers.toRanges(values), Numbers.RANGE_TRANSFORM)))
+        .build();
+  }
+
+  public static Iterable<Protos.Resource> mesosScalarFromBag(ResourceBag bag) {
+    return bag.streamResourceVectors()
+        .map(entry -> mesosScalar(entry.getKey(), entry.getValue()))
+        .collect(Collectors.toSet());
+  }
+
   public static Protos.Offer offer(Protos.Resource... resources) {
     return Protos.Offer.newBuilder()
         .setId(Protos.OfferID.newBuilder().setValue("offer-id"))

http://git-wip-us.apache.org/repos/asf/aurora/blob/8c900e58/src/test/java/org/apache/aurora/scheduler/resources/ResourcesTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/resources/ResourcesTest.java b/src/test/java/org/apache/aurora/scheduler/resources/ResourcesTest.java
deleted file mode 100644
index 716769f..0000000
--- a/src/test/java/org/apache/aurora/scheduler/resources/ResourcesTest.java
+++ /dev/null
@@ -1,76 +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.resources;
-
-import org.apache.aurora.common.quantity.Amount;
-import org.apache.mesos.Protos;
-import org.junit.Test;
-
-import static org.apache.aurora.common.quantity.Data.MB;
-import static org.apache.aurora.scheduler.base.TaskTestUtil.DEV_TIER;
-import static org.apache.aurora.scheduler.base.TaskTestUtil.REVOCABLE_TIER;
-import static org.apache.aurora.scheduler.resources.ResourceTestUtil.mesosRange;
-import static org.apache.aurora.scheduler.resources.ResourceTestUtil.mesosScalar;
-import static org.apache.aurora.scheduler.resources.ResourceTestUtil.offer;
-import static org.apache.aurora.scheduler.resources.ResourceType.CPUS;
-import static org.apache.aurora.scheduler.resources.ResourceType.DISK_MB;
-import static org.apache.aurora.scheduler.resources.ResourceType.PORTS;
-import static org.apache.aurora.scheduler.resources.ResourceType.RAM_MB;
-import static org.junit.Assert.assertEquals;
-
-public class ResourcesTest {
-  @Test
-  public void testGetSlot() {
-    Protos.Offer offer = offer(
-        mesosScalar(CPUS, 8.0, false),
-        mesosScalar(RAM_MB, 1024, false),
-        mesosScalar(DISK_MB, 2048, false),
-        mesosRange(PORTS, 1, 2, 3));
-
-    ResourceSlot expected = new ResourceSlot(8.0, Amount.of(1024L, MB), Amount.of(2048L, MB), 3);
-    assertEquals(expected, Resources.from(offer).slot());
-  }
-
-  @Test
-  public void testMissingResourcesHandledGracefully() {
-    assertEquals(ResourceSlot.NONE, Resources.from(offer()).slot());
-  }
-
-  @Test
-  public void testFilter() {
-    Protos.Offer offer = offer(
-        mesosScalar(CPUS, 8.0, true),
-        mesosScalar(RAM_MB, 1024, false));
-
-    assertEquals(
-        new ResourceSlot(8.0, Amount.of(1024L, MB), Amount.of(0L, MB), 0),
-        Resources.from(offer).filter(ResourceManager.REVOCABLE).slot());
-  }
-
-  @Test
-  public void testFilterByTier() {
-    Protos.Offer offer = offer(
-        mesosScalar(CPUS, 8.0, true),
-        mesosScalar(CPUS, 8.0, false),
-        mesosScalar(RAM_MB, 1024, false));
-
-    assertEquals(
-        new ResourceSlot(8.0, Amount.of(1024L, MB), Amount.of(0L, MB), 0),
-        Resources.from(offer).filter(REVOCABLE_TIER).slot());
-
-    assertEquals(
-        new ResourceSlot(8.0, Amount.of(1024L, MB), Amount.of(0L, MB), 0),
-        Resources.from(offer).filter(DEV_TIER).slot());
-  }
-}


Mime
View raw message