YARN-9124. Resolve contradiction in ResourceUtils: addMandatoryResources / checkMandatoryResources work differently (#1121)
(cherry picked from commit cbcada804d
)
This commit is contained in:
parent
02d0e54596
commit
4c4f7d9c80
|
@ -53,7 +53,11 @@ public class ResourceInformation implements Comparable<ResourceInformation> {
|
||||||
public static final ResourceInformation FPGAS =
|
public static final ResourceInformation FPGAS =
|
||||||
ResourceInformation.newInstance(FPGA_URI);
|
ResourceInformation.newInstance(FPGA_URI);
|
||||||
|
|
||||||
public static final Map<String, ResourceInformation> MANDATORY_RESOURCES =
|
/**
|
||||||
|
* Special resources that should be treated separately
|
||||||
|
* from arbitrary resource types.
|
||||||
|
*/
|
||||||
|
public static final Map<String, ResourceInformation> SPECIAL_RESOURCES =
|
||||||
ImmutableMap.of(MEMORY_URI, MEMORY_MB, VCORES_URI, VCORES, GPU_URI, GPUS, FPGA_URI, FPGAS);
|
ImmutableMap.of(MEMORY_URI, MEMORY_MB, VCORES_URI, VCORES, GPU_URI, GPUS, FPGA_URI, FPGAS);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -81,14 +81,28 @@ public class ResourceUtils {
|
||||||
private 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<String, ResourceInformation> resourceInformationMap)
|
Map<String, ResourceInformation> resourceInformationMap)
|
||||||
throws YarnRuntimeException {
|
throws YarnRuntimeException {
|
||||||
/*
|
/*
|
||||||
* Supporting 'memory', 'memory-mb', 'vcores' also as invalid resource names, in addition to
|
* Supporting 'memory', 'memory-mb', 'vcores' also as invalid resource
|
||||||
* 'MEMORY' for historical reasons
|
* names, in addition to 'MEMORY' for historical reasons
|
||||||
*/
|
*/
|
||||||
String keys[] = { "memory", ResourceInformation.MEMORY_URI,
|
String[] keys = { "memory", ResourceInformation.MEMORY_URI,
|
||||||
ResourceInformation.VCORES_URI };
|
ResourceInformation.VCORES_URI };
|
||||||
for(String key : keys) {
|
for(String key : keys) {
|
||||||
if (resourceInformationMap.containsKey(key)) {
|
if (resourceInformationMap.containsKey(key)) {
|
||||||
|
@ -99,7 +113,7 @@ public class ResourceUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<String, ResourceInformation> mandatoryResourceEntry :
|
for (Map.Entry<String, ResourceInformation> mandatoryResourceEntry :
|
||||||
ResourceInformation.MANDATORY_RESOURCES.entrySet()) {
|
ResourceInformation.SPECIAL_RESOURCES.entrySet()) {
|
||||||
String key = mandatoryResourceEntry.getKey();
|
String key = mandatoryResourceEntry.getKey();
|
||||||
ResourceInformation mandatoryRI = mandatoryResourceEntry.getValue();
|
ResourceInformation mandatoryRI = mandatoryResourceEntry.getValue();
|
||||||
|
|
||||||
|
@ -122,6 +136,13 @@ public class ResourceUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(
|
private static void addMandatoryResources(
|
||||||
Map<String, ResourceInformation> res) {
|
Map<String, ResourceInformation> res) {
|
||||||
ResourceInformation ri;
|
ResourceInformation ri;
|
||||||
|
@ -259,7 +280,7 @@ public class ResourceUtils {
|
||||||
validateNameOfResourceNameAndThrowException(name);
|
validateNameOfResourceNameAndThrowException(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
checkMandatoryResources(resourceInformationMap);
|
checkSpecialResources(resourceInformationMap);
|
||||||
addMandatoryResources(resourceInformationMap);
|
addMandatoryResources(resourceInformationMap);
|
||||||
|
|
||||||
setAllocationForMandatoryResources(resourceInformationMap, conf);
|
setAllocationForMandatoryResources(resourceInformationMap, conf);
|
||||||
|
@ -488,7 +509,7 @@ public class ResourceUtils {
|
||||||
if (!initializedNodeResources) {
|
if (!initializedNodeResources) {
|
||||||
Map<String, ResourceInformation> nodeResources = initializeNodeResourceInformation(
|
Map<String, ResourceInformation> nodeResources = initializeNodeResourceInformation(
|
||||||
conf);
|
conf);
|
||||||
checkMandatoryResources(nodeResources);
|
checkSpecialResources(nodeResources);
|
||||||
addMandatoryResources(nodeResources);
|
addMandatoryResources(nodeResources);
|
||||||
setAllocationForMandatoryResources(nodeResources, conf);
|
setAllocationForMandatoryResources(nodeResources, conf);
|
||||||
readOnlyNodeResources = Collections.unmodifiableMap(nodeResources);
|
readOnlyNodeResources = Collections.unmodifiableMap(nodeResources);
|
||||||
|
|
Loading…
Reference in New Issue