diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/Resource.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/Resource.java index 7182da5d240..bd6b31572cb 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/Resource.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/Resource.java @@ -99,9 +99,12 @@ public abstract class Resource implements Comparable { @Stable public static Resource newInstance(long memory, int vCores, Map others) { - ResourceInformation[] info = ResourceUtils.createResourceTypesArray(others); - - return new LightWeightResource(memory, vCores, info); + if (others != null) { + return new LightWeightResource(memory, vCores, + ResourceUtils.createResourceTypesArray(others)); + } else { + return newInstance(memory, vCores); + } } @InterfaceAudience.Private 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 0b909a60da5..d1beb1e6bcf 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 @@ -341,15 +341,13 @@ public class ResourceUtils { } public static ResourceInformation[] getResourceTypesArray() { - initializeResourceTypesIfNeeded(null, - YarnConfiguration.RESOURCE_TYPES_CONFIGURATION_FILE); + initializeResourceTypesIfNeeded(); return resourceTypesArray; } public static int getNumberOfKnownResourceTypes() { if (numKnownResourceTypes < 0) { - initializeResourceTypesIfNeeded(null, - YarnConfiguration.RESOURCE_TYPES_CONFIGURATION_FILE); + initializeResourceTypesIfNeeded(); } return numKnownResourceTypes; } @@ -360,6 +358,11 @@ public class ResourceUtils { YarnConfiguration.RESOURCE_TYPES_CONFIGURATION_FILE); } + private static void initializeResourceTypesIfNeeded() { + initializeResourceTypesIfNeeded(null, + YarnConfiguration.RESOURCE_TYPES_CONFIGURATION_FILE); + } + private static void initializeResourceTypesIfNeeded(Configuration conf, String resourceFile) { if (!initializedResources) { @@ -631,6 +634,8 @@ public class ResourceUtils { */ public static ResourceInformation[] createResourceTypesArray(Map res) { + initializeResourceTypesIfNeeded(); + ResourceInformation[] info = new ResourceInformation[resourceTypes.size()]; for (Entry entry : RESOURCE_NAME_TO_INDEX.entrySet()) {