YARN-7589. TestPBImplRecords fails with NullPointerException. Contributed by Daniel Templeton
(cherry picked from commit 25df505421
)
This commit is contained in:
parent
a9f51e0372
commit
dbbe23f269
|
@ -99,9 +99,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
|
||||
|
|
|
@ -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<String,
|
||||
Long> res) {
|
||||
initializeResourceTypesIfNeeded();
|
||||
|
||||
ResourceInformation[] info = new ResourceInformation[resourceTypes.size()];
|
||||
|
||||
for (Entry<String, Integer> entry : RESOURCE_NAME_TO_INDEX.entrySet()) {
|
||||
|
|
Loading…
Reference in New Issue