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

This commit is contained in:
Jason Lowe 2017-12-01 15:37:36 -06:00
parent c83fe44917
commit 25df505421
2 changed files with 15 additions and 7 deletions

View File

@ -102,9 +102,12 @@ public abstract class Resource implements Comparable<Resource> {
@Stable
public static Resource newInstance(long memory, int vCores,
Map<String, Long> 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

View File

@ -313,15 +313,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;
}
@ -332,6 +330,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) {
@ -641,6 +644,8 @@ public class ResourceUtils {
*/
public static ResourceInformation[] createResourceTypesArray(Map<String,
Long> res) {
initializeResourceTypesIfNeeded();
ResourceInformation[] info = new ResourceInformation[resourceTypes.size()];
for (Entry<String, Integer> entry : RESOURCE_NAME_TO_INDEX.entrySet()) {