YARN-7410. Cleanup FixedValueResource to avoid dependency to ResourceUtils. Contributed by Wangda Tan.
This commit is contained in:
parent
ad0fff2b41
commit
1700adc6f7
|
@ -364,7 +364,7 @@ public abstract class Resource implements Comparable<Resource> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void throwExceptionWhenArrayOutOfBound(int index) {
|
protected void throwExceptionWhenArrayOutOfBound(int index) {
|
||||||
String exceptionMsg = String.format(
|
String exceptionMsg = String.format(
|
||||||
"Trying to access ResourceInformation for given index=%d. "
|
"Trying to access ResourceInformation for given index=%d. "
|
||||||
+ "Acceptable index range is [0,%d), please check double check "
|
+ "Acceptable index range is [0,%d), please check double check "
|
||||||
|
|
|
@ -267,6 +267,7 @@ public class ResourceUtils {
|
||||||
updateKnownResources();
|
updateKnownResources();
|
||||||
updateResourceTypeIndex();
|
updateResourceTypeIndex();
|
||||||
initializedResources = true;
|
initializedResources = true;
|
||||||
|
numKnownResourceTypes = resourceTypes.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void updateKnownResources() {
|
private static void updateKnownResources() {
|
||||||
|
|
|
@ -118,6 +118,65 @@ public class Resources {
|
||||||
throw new RuntimeException(name + " cannot be modified!");
|
throw new RuntimeException(name + " cannot be modified!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* FixedValueResource cannot be updated when any resource types refresh
|
||||||
|
* by using approach introduced by YARN-7307 and do operations like
|
||||||
|
* Resources.compare(resource_x, Resources.none()) will throw exceptions.
|
||||||
|
*
|
||||||
|
* That's why we do reinitialize resource maps for following methods.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceInformation getResourceInformation(int index)
|
||||||
|
throws ResourceNotFoundException {
|
||||||
|
ResourceInformation ri = null;
|
||||||
|
try {
|
||||||
|
ri = super.getResourceInformation(index);
|
||||||
|
} catch (ResourceNotFoundException e) {
|
||||||
|
// Retry once to reinitialize resource information.
|
||||||
|
initResourceMap();
|
||||||
|
try {
|
||||||
|
return super.getResourceInformation(index);
|
||||||
|
} catch (ResourceNotFoundException ee) {
|
||||||
|
throwExceptionWhenArrayOutOfBound(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ri;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceInformation getResourceInformation(String resource)
|
||||||
|
throws ResourceNotFoundException {
|
||||||
|
ResourceInformation ri;
|
||||||
|
try {
|
||||||
|
ri = super.getResourceInformation(resource);
|
||||||
|
} catch (ResourceNotFoundException e) {
|
||||||
|
// Retry once to reinitialize resource information.
|
||||||
|
initResourceMap();
|
||||||
|
try {
|
||||||
|
return super.getResourceInformation(resource);
|
||||||
|
} catch (ResourceNotFoundException ee) {
|
||||||
|
throw ee;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ri;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceInformation[] getResources() {
|
||||||
|
if (resources.length != ResourceUtils.getNumberOfKnownResourceTypes()) {
|
||||||
|
// Retry once to reinitialize resource information.
|
||||||
|
initResourceMap();
|
||||||
|
if (resources.length != ResourceUtils.getNumberOfKnownResourceTypes()) {
|
||||||
|
throw new ResourceNotFoundException("Failed to reinitialize "
|
||||||
|
+ "FixedValueResource to get number of resource types same "
|
||||||
|
+ "as configured");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return resources;
|
||||||
|
}
|
||||||
|
|
||||||
private void initResourceMap() {
|
private void initResourceMap() {
|
||||||
ResourceInformation[] types = ResourceUtils.getResourceTypesArray();
|
ResourceInformation[] types = ResourceUtils.getResourceTypesArray();
|
||||||
if (types != null) {
|
if (types != null) {
|
||||||
|
|
Loading…
Reference in New Issue