YARN-6781. [YARN-3926] ResourceUtils#initializeResourcesMap takes an unnecessary Map parameter. Contributed by Yu-Tang Lin.
This commit is contained in:
parent
df3855541a
commit
758b771943
@ -201,9 +201,9 @@ private static void setMaximumAllocationForMandatoryResources(
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static void initializeResourcesMap(Configuration conf,
|
||||
Map<String, ResourceInformation> resourceInformationMap) {
|
||||
static void initializeResourcesMap(Configuration conf) {
|
||||
|
||||
Map<String, ResourceInformation> resourceInformationMap = new HashMap<>();
|
||||
String[] resourceNames = conf.getStrings(YarnConfiguration.RESOURCE_TYPES);
|
||||
|
||||
if (resourceNames != null && resourceNames.length != 0) {
|
||||
@ -339,19 +339,18 @@ private static void initializeResourceTypesIfNeeded(Configuration conf,
|
||||
if (!initializedResources) {
|
||||
synchronized (ResourceUtils.class) {
|
||||
if (!initializedResources) {
|
||||
Map<String, ResourceInformation> resources = new HashMap<>();
|
||||
if (conf == null) {
|
||||
conf = new YarnConfiguration();
|
||||
}
|
||||
try {
|
||||
addResourcesFileToConf(resourceFile, conf);
|
||||
LOG.debug("Found " + resourceFile + ", adding to configuration");
|
||||
initializeResourcesMap(conf, resources);
|
||||
initializeResourcesMap(conf);
|
||||
initializedResources = true;
|
||||
} catch (FileNotFoundException fe) {
|
||||
LOG.info("Unable to find '" + resourceFile
|
||||
+ "'. Falling back to memory and vcores as resources", fe);
|
||||
initializeResourcesMap(conf, resources);
|
||||
initializeResourcesMap(conf);
|
||||
initializedResources = true;
|
||||
}
|
||||
}
|
||||
@ -414,11 +413,12 @@ synchronized static void resetResourceTypes() {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public static void resetResourceTypes(Configuration conf) {
|
||||
public static Map<String, ResourceInformation>
|
||||
resetResourceTypes(Configuration conf) {
|
||||
synchronized (ResourceUtils.class) {
|
||||
initializedResources = false;
|
||||
}
|
||||
getResourceTypes(conf);
|
||||
return getResourceTypes(conf);
|
||||
}
|
||||
|
||||
public static String getUnits(String resourceValue) {
|
||||
|
@ -183,8 +183,9 @@ public void testInitializeResourcesMap() throws Exception {
|
||||
YarnConfiguration.RESOURCE_TYPES + "." + resources[0] + ".units";
|
||||
conf.set(name, resources[1]);
|
||||
}
|
||||
Map<String, ResourceInformation> ret = new HashMap<>();
|
||||
ResourceUtils.initializeResourcesMap(conf, ret);
|
||||
Map<String, ResourceInformation> ret =
|
||||
ResourceUtils.resetResourceTypes(conf);
|
||||
|
||||
// for test1, 4 - length will be 1, 4
|
||||
// for the others, len will be 3
|
||||
int len = 3;
|
||||
@ -248,9 +249,8 @@ public void testInitializeResourcesMapErrors() throws Exception {
|
||||
YarnConfiguration.RESOURCE_TYPES + "." + resources[0] + ".units";
|
||||
conf.set(name, resources[1]);
|
||||
}
|
||||
Map<String, ResourceInformation> ret = new HashMap<>();
|
||||
try {
|
||||
ResourceUtils.initializeResourcesMap(conf, ret);
|
||||
ResourceUtils.initializeResourcesMap(conf);
|
||||
Assert.fail("resource map initialization should fail");
|
||||
} catch (Exception e) {
|
||||
// do nothing
|
||||
|
Loading…
Reference in New Issue
Block a user