diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/ResourceInformation.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/ResourceInformation.java index 4209ca78ce..e83ea72977 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/ResourceInformation.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/ResourceInformation.java @@ -59,7 +59,11 @@ public class ResourceInformation implements Comparable { public static final ResourceInformation FPGAS = ResourceInformation.newInstance(FPGA_URI); - public static final Map MANDATORY_RESOURCES = + /** + * Special resources that should be treated separately + * from arbitrary resource types. + */ + public static final Map SPECIAL_RESOURCES = ImmutableMap.of(MEMORY_URI, MEMORY_MB, VCORES_URI, VCORES, GPU_URI, GPUS, FPGA_URI, FPGAS); /** diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/util/resource/ResourceUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/util/resource/ResourceUtils.java index 13a872cb41..9aaff15f46 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/util/resource/ResourceUtils.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/util/resource/ResourceUtils.java @@ -93,14 +93,28 @@ public class ResourceUtils { private ResourceUtils() { } - private static void checkMandatoryResources( + /** + * Ensures that historical resource types (like {@link + * ResourceInformation#MEMORY_URI}, {@link ResourceInformation#VCORES_URI}) + * are not getting overridden in the resourceInformationMap. + * + * Also checks whether {@link ResourceInformation#SPECIAL_RESOURCES} are not + * configured poorly: having their proper units and types. + * + * @param resourceInformationMap Map object having keys as resources names + * and {@link ResourceInformation} objects as + * values + * @throws YarnRuntimeException if either of the two above + * conditions do not hold + */ + private static void checkSpecialResources( Map resourceInformationMap) throws YarnRuntimeException { /* - * Supporting 'memory', 'memory-mb', 'vcores' also as invalid resource names, in addition to - * 'MEMORY' for historical reasons + * Supporting 'memory', 'memory-mb', 'vcores' also as invalid resource + * names, in addition to 'MEMORY' for historical reasons */ - String keys[] = { "memory", ResourceInformation.MEMORY_URI, + String[] keys = { "memory", ResourceInformation.MEMORY_URI, ResourceInformation.VCORES_URI }; for(String key : keys) { if (resourceInformationMap.containsKey(key)) { @@ -111,7 +125,7 @@ private static void checkMandatoryResources( } for (Map.Entry mandatoryResourceEntry : - ResourceInformation.MANDATORY_RESOURCES.entrySet()) { + ResourceInformation.SPECIAL_RESOURCES.entrySet()) { String key = mandatoryResourceEntry.getKey(); ResourceInformation mandatoryRI = mandatoryResourceEntry.getValue(); @@ -134,6 +148,13 @@ private static void checkMandatoryResources( } } + /** + * Ensures that {@link ResourceUtils#MEMORY} and {@link ResourceUtils#VCORES} + * resources are contained in the map received as parameter. + * + * @param res Map object having keys as resources names + * and {@link ResourceInformation} objects as values + */ private static void addMandatoryResources( Map res) { ResourceInformation ri; @@ -272,7 +293,7 @@ private static Map getResourceInformationMapFromCon validateNameOfResourceNameAndThrowException(name); } - checkMandatoryResources(resourceInformationMap); + checkSpecialResources(resourceInformationMap); addMandatoryResources(resourceInformationMap); setAllocationForMandatoryResources(resourceInformationMap, conf); @@ -522,7 +543,7 @@ public static Map getNodeResourceInformation( if (!initializedNodeResources) { Map nodeResources = initializeNodeResourceInformation( conf); - checkMandatoryResources(nodeResources); + checkSpecialResources(nodeResources); addMandatoryResources(nodeResources); setAllocationForMandatoryResources(nodeResources, conf); readOnlyNodeResources = Collections.unmodifiableMap(nodeResources);