aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jco...@apache.org
Subject aurora git commit: Filter out resources that Aurora does not yet support to avoid crashing.
Date Thu, 17 Nov 2016 18:36:55 GMT
Repository: aurora
Updated Branches:
  refs/heads/master 85e249390 -> 44ab4c5db


Filter out resources that Aurora does not yet support to avoid crashing.

Placed filter when creating resource bags from Mesos resources in to avoid trying to conver
unsupported resources which leads to the scheduler crashing.

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


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

Branch: refs/heads/master
Commit: 44ab4c5dbf58cf32394503e0a6427e9435bd0637
Parents: 85e2493
Author: Renan DelValle <rdelval1@binghamton.edu>
Authored: Thu Nov 17 12:36:34 2016 -0600
Committer: Joshua Cohen <jcohen@apache.org>
Committed: Thu Nov 17 12:36:34 2016 -0600

----------------------------------------------------------------------
 .../aurora/scheduler/resources/ResourceManager.java     | 10 +++++++++-
 .../apache/aurora/scheduler/resources/ResourceType.java |  4 ++--
 .../aurora/scheduler/resources/ResourceManagerTest.java | 12 ++++++++++++
 3 files changed, 23 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aurora/blob/44ab4c5d/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 caacc58..589288d 100644
--- a/src/main/java/org/apache/aurora/scheduler/resources/ResourceManager.java
+++ b/src/main/java/org/apache/aurora/scheduler/resources/ResourceManager.java
@@ -69,6 +69,8 @@ public final class ResourceManager {
 
   private static final BinaryOperator<Double> REDUCE_VALUES = (l, r) -> l + r;
 
+  private static final Predicate<Resource> SUPPORTED_RESOURCE =
+      r -> ResourceType.BY_MESOS_NAME.containsKey(r.getName());
   /**
    * Gets offer resources matching specified {@link ResourceType}.
    *
@@ -236,7 +238,12 @@ public final class ResourceManager {
    * @return A {@link ResourceBag} instance.
    */
   public static ResourceBag bagFromMesosResources(Iterable<Resource> resources) {
-    return bagFromResources(resources, MESOS_RESOURCE_TO_TYPE, QUANTIFY_MESOS_RESOURCE);
+    // 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,
+        QUANTIFY_MESOS_RESOURCE);
   }
 
   /**
@@ -289,4 +296,5 @@ public final class ResourceManager {
       super(message);
     }
   }
+
 }

http://git-wip-us.apache.org/repos/asf/aurora/blob/44ab4c5d/src/main/java/org/apache/aurora/scheduler/resources/ResourceType.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/resources/ResourceType.java b/src/main/java/org/apache/aurora/scheduler/resources/ResourceType.java
index 915c83d..178466f 100644
--- a/src/main/java/org/apache/aurora/scheduler/resources/ResourceType.java
+++ b/src/main/java/org/apache/aurora/scheduler/resources/ResourceType.java
@@ -174,7 +174,7 @@ public enum ResourceType implements TEnum {
   private static ImmutableMap<Integer, ResourceType> byField =
       Maps.uniqueIndex(EnumSet.allOf(ResourceType.class),  ResourceType::getValue);
 
-  private static ImmutableMap<String, ResourceType> byMesosName =
+  public static final ImmutableMap<String, ResourceType> BY_MESOS_NAME =
       Maps.uniqueIndex(EnumSet.allOf(ResourceType.class), ResourceType::getMesosName);
 
   /**
@@ -355,7 +355,7 @@ public enum ResourceType implements TEnum {
    */
   public static ResourceType fromResource(Resource resource) {
     return requireNonNull(
-        byMesosName.get(resource.getName()),
+        BY_MESOS_NAME.get(resource.getName()),
         "Unknown Mesos resource: " + resource);
   }
 }

http://git-wip-us.apache.org/repos/asf/aurora/blob/44ab4c5d/src/test/java/org/apache/aurora/scheduler/resources/ResourceManagerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/resources/ResourceManagerTest.java
b/src/test/java/org/apache/aurora/scheduler/resources/ResourceManagerTest.java
index 14ac547..133cd23 100644
--- a/src/test/java/org/apache/aurora/scheduler/resources/ResourceManagerTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/resources/ResourceManagerTest.java
@@ -177,6 +177,18 @@ public class ResourceManagerTest {
   }
 
   @Test
+  public void testBagFromMesosResourcesUnsupportedResources() {
+    Protos.Resource unsupported = Protos.Resource.newBuilder()
+        .setName("unknown")
+        .setType(SCALAR)
+        .setScalar(Scalar.newBuilder().setValue(1.0).build()).build();
+    assertEquals(
+        new ResourceBag(ImmutableMap.of(CPUS, 3.0)),
+        ResourceManager.bagFromMesosResources(
+            ImmutableSet.of(mesosScalar(CPUS, 3.0), unsupported)));
+  }
+
+  @Test
   public void testBagFromAggregate() {
     assertEquals(bag(1.0, 32, 64), ResourceManager.bagFromAggregate(aggregate(1.0, 32, 64)));
   }


Mime
View raw message