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:
parent
c69dd9eea6
commit
7c37fbef12
|
@ -201,9 +201,9 @@ public class ResourceUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static void initializeResourcesMap(Configuration conf,
|
static void initializeResourcesMap(Configuration conf) {
|
||||||
Map<String, ResourceInformation> resourceInformationMap) {
|
|
||||||
|
|
||||||
|
Map<String, ResourceInformation> resourceInformationMap = new HashMap<>();
|
||||||
String[] resourceNames = conf.getStrings(YarnConfiguration.RESOURCE_TYPES);
|
String[] resourceNames = conf.getStrings(YarnConfiguration.RESOURCE_TYPES);
|
||||||
|
|
||||||
if (resourceNames != null && resourceNames.length != 0) {
|
if (resourceNames != null && resourceNames.length != 0) {
|
||||||
|
@ -339,19 +339,18 @@ public class ResourceUtils {
|
||||||
if (!initializedResources) {
|
if (!initializedResources) {
|
||||||
synchronized (ResourceUtils.class) {
|
synchronized (ResourceUtils.class) {
|
||||||
if (!initializedResources) {
|
if (!initializedResources) {
|
||||||
Map<String, ResourceInformation> resources = new HashMap<>();
|
|
||||||
if (conf == null) {
|
if (conf == null) {
|
||||||
conf = new YarnConfiguration();
|
conf = new YarnConfiguration();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
addResourcesFileToConf(resourceFile, conf);
|
addResourcesFileToConf(resourceFile, conf);
|
||||||
LOG.debug("Found " + resourceFile + ", adding to configuration");
|
LOG.debug("Found " + resourceFile + ", adding to configuration");
|
||||||
initializeResourcesMap(conf, resources);
|
initializeResourcesMap(conf);
|
||||||
initializedResources = true;
|
initializedResources = true;
|
||||||
} catch (FileNotFoundException fe) {
|
} catch (FileNotFoundException fe) {
|
||||||
LOG.info("Unable to find '" + resourceFile
|
LOG.info("Unable to find '" + resourceFile
|
||||||
+ "'. Falling back to memory and vcores as resources", fe);
|
+ "'. Falling back to memory and vcores as resources", fe);
|
||||||
initializeResourcesMap(conf, resources);
|
initializeResourcesMap(conf);
|
||||||
initializedResources = true;
|
initializedResources = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -414,11 +413,12 @@ public class ResourceUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public static void resetResourceTypes(Configuration conf) {
|
public static Map<String, ResourceInformation>
|
||||||
|
resetResourceTypes(Configuration conf) {
|
||||||
synchronized (ResourceUtils.class) {
|
synchronized (ResourceUtils.class) {
|
||||||
initializedResources = false;
|
initializedResources = false;
|
||||||
}
|
}
|
||||||
getResourceTypes(conf);
|
return getResourceTypes(conf);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getUnits(String resourceValue) {
|
public static String getUnits(String resourceValue) {
|
||||||
|
|
|
@ -183,8 +183,9 @@ public class TestResourceUtils {
|
||||||
YarnConfiguration.RESOURCE_TYPES + "." + resources[0] + ".units";
|
YarnConfiguration.RESOURCE_TYPES + "." + resources[0] + ".units";
|
||||||
conf.set(name, resources[1]);
|
conf.set(name, resources[1]);
|
||||||
}
|
}
|
||||||
Map<String, ResourceInformation> ret = new HashMap<>();
|
Map<String, ResourceInformation> ret =
|
||||||
ResourceUtils.initializeResourcesMap(conf, ret);
|
ResourceUtils.resetResourceTypes(conf);
|
||||||
|
|
||||||
// for test1, 4 - length will be 1, 4
|
// for test1, 4 - length will be 1, 4
|
||||||
// for the others, len will be 3
|
// for the others, len will be 3
|
||||||
int len = 3;
|
int len = 3;
|
||||||
|
@ -248,9 +249,8 @@ public class TestResourceUtils {
|
||||||
YarnConfiguration.RESOURCE_TYPES + "." + resources[0] + ".units";
|
YarnConfiguration.RESOURCE_TYPES + "." + resources[0] + ".units";
|
||||||
conf.set(name, resources[1]);
|
conf.set(name, resources[1]);
|
||||||
}
|
}
|
||||||
Map<String, ResourceInformation> ret = new HashMap<>();
|
|
||||||
try {
|
try {
|
||||||
ResourceUtils.initializeResourcesMap(conf, ret);
|
ResourceUtils.initializeResourcesMap(conf);
|
||||||
Assert.fail("resource map initialization should fail");
|
Assert.fail("resource map initialization should fail");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// do nothing
|
// do nothing
|
||||||
|
|
Loading…
Reference in New Issue