YARN-6781. [YARN-3926] ResourceUtils#initializeResourcesMap takes an unnecessary Map parameter. Contributed by Yu-Tang Lin.

(cherry picked from commit 758b771943)
This commit is contained in:
Sunil G 2017-08-18 19:00:49 +05:30 committed by Jonathan Hung
parent c69dd9eea6
commit 7c37fbef12
2 changed files with 11 additions and 11 deletions

View File

@ -201,9 +201,9 @@ public class ResourceUtils {
}
@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 @@ public class ResourceUtils {
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 @@ public class ResourceUtils {
}
@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) {

View File

@ -183,8 +183,9 @@ public class TestResourceUtils {
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 class TestResourceUtils {
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