YARN-7589. TestPBImplRecords fails with NullPointerException. Contributed by Daniel Templeton

(cherry picked from commit 25df505421)
This commit is contained in:
Jason Lowe 2017-12-01 15:37:36 -06:00 committed by Jonathan Hung
parent a9f51e0372
commit dbbe23f269
2 changed files with 15 additions and 7 deletions

View File

@ -99,9 +99,12 @@ public abstract class Resource implements Comparable<Resource> {
@Stable @Stable
public static Resource newInstance(long memory, int vCores, public static Resource newInstance(long memory, int vCores,
Map<String, Long> others) { Map<String, Long> others) {
ResourceInformation[] info = ResourceUtils.createResourceTypesArray(others); if (others != null) {
return new LightWeightResource(memory, vCores,
return new LightWeightResource(memory, vCores, info); ResourceUtils.createResourceTypesArray(others));
} else {
return newInstance(memory, vCores);
}
} }
@InterfaceAudience.Private @InterfaceAudience.Private

View File

@ -341,15 +341,13 @@ public class ResourceUtils {
} }
public static ResourceInformation[] getResourceTypesArray() { public static ResourceInformation[] getResourceTypesArray() {
initializeResourceTypesIfNeeded(null, initializeResourceTypesIfNeeded();
YarnConfiguration.RESOURCE_TYPES_CONFIGURATION_FILE);
return resourceTypesArray; return resourceTypesArray;
} }
public static int getNumberOfKnownResourceTypes() { public static int getNumberOfKnownResourceTypes() {
if (numKnownResourceTypes < 0) { if (numKnownResourceTypes < 0) {
initializeResourceTypesIfNeeded(null, initializeResourceTypesIfNeeded();
YarnConfiguration.RESOURCE_TYPES_CONFIGURATION_FILE);
} }
return numKnownResourceTypes; return numKnownResourceTypes;
} }
@ -360,6 +358,11 @@ public class ResourceUtils {
YarnConfiguration.RESOURCE_TYPES_CONFIGURATION_FILE); YarnConfiguration.RESOURCE_TYPES_CONFIGURATION_FILE);
} }
private static void initializeResourceTypesIfNeeded() {
initializeResourceTypesIfNeeded(null,
YarnConfiguration.RESOURCE_TYPES_CONFIGURATION_FILE);
}
private static void initializeResourceTypesIfNeeded(Configuration conf, private static void initializeResourceTypesIfNeeded(Configuration conf,
String resourceFile) { String resourceFile) {
if (!initializedResources) { if (!initializedResources) {
@ -631,6 +634,8 @@ public class ResourceUtils {
*/ */
public static ResourceInformation[] createResourceTypesArray(Map<String, public static ResourceInformation[] createResourceTypesArray(Map<String,
Long> res) { Long> res) {
initializeResourceTypesIfNeeded();
ResourceInformation[] info = new ResourceInformation[resourceTypes.size()]; ResourceInformation[] info = new ResourceInformation[resourceTypes.size()];
for (Entry<String, Integer> entry : RESOURCE_NAME_TO_INDEX.entrySet()) { for (Entry<String, Integer> entry : RESOURCE_NAME_TO_INDEX.entrySet()) {