aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject aurora git commit: Filter out calls to fromResource for resources that Aurora does not support yet to avoid crashing
Date Wed, 23 Nov 2016 12:16:21 GMT
Repository: aurora
Updated Branches:
  refs/heads/master 320ee0810 -> 4797dfe33


Filter out calls to fromResource for resources that Aurora does not support yet to avoid crashing

Added filters whenever fromResource is called for a Protos.Resource in order to avoid Aurora
crashing.
Previously only bagFromMesosResources was using the SUPPORTED_RESOURCE filter.

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


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

Branch: refs/heads/master
Commit: 4797dfe33ba08183fa9596a46ac8be51a64e08bb
Parents: 320ee08
Author: Renan DelValle <rdelval1@binghamton.edu>
Authored: Wed Nov 23 13:08:51 2016 +0100
Committer: Stephan Erb <serb@apache.org>
Committed: Wed Nov 23 13:08:51 2016 +0100

----------------------------------------------------------------------
 .../scheduler/resources/ResourceManager.java    | 23 +++++++++++++++-----
 1 file changed, 17 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aurora/blob/4797dfe3/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 589288d..d751d01 100644
--- a/src/main/java/org/apache/aurora/scheduler/resources/ResourceManager.java
+++ b/src/main/java/org/apache/aurora/scheduler/resources/ResourceManager.java
@@ -22,6 +22,7 @@ import java.util.stream.Collectors;
 import java.util.stream.StreamSupport;
 
 import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
 import com.google.common.collect.Iterables;
 
 import org.apache.aurora.gen.ResourceAggregate;
@@ -34,6 +35,7 @@ import org.apache.aurora.scheduler.storage.entities.ITaskConfig;
 import org.apache.aurora.scheduler.storage.log.ThriftBackfill;
 import org.apache.mesos.Protos.Resource;
 
+import static org.apache.aurora.scheduler.resources.ResourceType.BY_MESOS_NAME;
 import static org.apache.aurora.scheduler.resources.ResourceType.fromResource;
 import static org.apache.mesos.Protos.Offer;
 
@@ -69,8 +71,12 @@ public final class ResourceManager {
 
   private static final BinaryOperator<Double> REDUCE_VALUES = (l, r) -> l + r;
 
+  /**
+   * TODO(rdelvalle): Remove filters when arbitrary resources are fully supported (AURORA-1328).
+   */
   private static final Predicate<Resource> SUPPORTED_RESOURCE =
-      r -> ResourceType.BY_MESOS_NAME.containsKey(r.getName());
+      r -> BY_MESOS_NAME.containsKey(r.getName());
+
   /**
    * Gets offer resources matching specified {@link ResourceType}.
    *
@@ -79,7 +85,9 @@ public final class ResourceManager {
    * @return Offer resources matching {@link ResourceType}.
    */
   public static Iterable<Resource> getOfferResources(Offer offer, ResourceType type)
{
-    return Iterables.filter(offer.getResourcesList(), r -> fromResource(r).equals(type));
+    return Iterables.filter(
+        Iterables.filter(offer.getResourcesList(), SUPPORTED_RESOURCE),
+        r -> fromResource(r).equals(type));
   }
 
   /**
@@ -89,7 +97,9 @@ public final class ResourceManager {
    * @return Mesos-revocable offer resources.
    */
   public static Iterable<Resource> getRevocableOfferResources(Offer offer) {
-    return Iterables.filter(offer.getResourcesList(), REVOCABLE);
+    return Iterables.filter(
+        offer.getResourcesList(),
+        Predicates.and(SUPPORTED_RESOURCE, REVOCABLE));
   }
 
   /**
@@ -99,7 +109,9 @@ public final class ResourceManager {
    * @return Non-Mesos-revocable offer resources.
    */
   public static Iterable<Resource> getNonRevocableOfferResources(Offer offer) {
-    return Iterables.filter(offer.getResourcesList(), NON_REVOCABLE);
+    return Iterables.filter(
+        offer.getResourcesList(),
+        Predicates.and(SUPPORTED_RESOURCE, NON_REVOCABLE));
   }
 
   /**
@@ -189,6 +201,7 @@ public final class ResourceManager {
    */
   public static Double quantityOfMesosResource(Iterable<Resource> resources, ResourceType
type) {
     return StreamSupport.stream(resources.spliterator(), false)
+        .filter(r -> SUPPORTED_RESOURCE.apply(r))
         .filter(r -> fromResource(r).equals(type))
         .map(QUANTIFY_MESOS_RESOURCE)
         .reduce(REDUCE_VALUES)
@@ -238,8 +251,6 @@ public final class ResourceManager {
    * @return A {@link ResourceBag} instance.
    */
   public static ResourceBag bagFromMesosResources(Iterable<Resource> resources) {
-    // Filter out resources that Aurora does not yet support in order to avoid crashes
-    // TODO(rdelvalle): Remove filter when arbitrary resources are fully supported (AURORA-1328)
     return bagFromResources(
         Iterables.filter(resources, SUPPORTED_RESOURCE),
         MESOS_RESOURCE_TO_TYPE,


Mime
View raw message