YARN-8843. updateNodeResource does not support units for memory. Contributed by Manikandan R.

This commit is contained in:
Inigo Goiri 2018-10-08 10:05:18 -07:00
parent 7c13872cbb
commit 745f64012a
2 changed files with 14 additions and 2 deletions

View File

@ -77,6 +77,7 @@
import org.apache.hadoop.yarn.server.api.protocolrecords.ReplaceLabelsOnNodeRequest;
import org.apache.hadoop.yarn.server.api.protocolrecords.UpdateNodeResourceRequest;
import org.apache.hadoop.yarn.util.ConverterUtils;
import org.apache.hadoop.yarn.util.UnitsConversionUtil;
import org.apache.hadoop.yarn.util.resource.ResourceUtils;
import org.apache.hadoop.yarn.util.resource.Resources;
@ -930,8 +931,14 @@ private Resource parseCommandAndCreateResource(String resourceTypes) {
if (resourceTypesFromRM.containsKey(resName)) {
String[] resourceValue = ResourceUtils.parseResourceValue(resValue);
if (resourceValue.length == 2) {
long value = Long.parseLong(resourceValue[1]);
if (!resourceTypesFromRM.get(resName).getUnits()
.equals(resourceValue[0])) {
value = UnitsConversionUtil.convert(resourceValue[0],
resourceTypesFromRM.get(resName).getUnits(), value);
}
ResourceInformation ri = ResourceInformation.newInstance(resName,
resourceValue[0], Long.parseLong(resourceValue[1]));
resourceValue[0], value);
resource.setResourceInformation(resName, ri);
} else {
throw new IllegalArgumentException("Invalid resource value: " +

View File

@ -325,7 +325,7 @@ public void testUpdateNodeResourceWithInvalidValue() throws Exception {
public void testUpdateNodeResourceTypes() throws Exception {
String nodeIdStr = "0.0.0.0:0";
String resourceTypes =
"memory-mb=1024Mi,vcores=1,resource1=3Gi,resource2=2m";
"memory-mb=1Gi,vcores=1,resource1=3Gi,resource2=2m";
String[] args = {"-updateNodeResource", nodeIdStr, resourceTypes};
assertEquals(0, rmAdminCLI.run(args));
ArgumentCaptor<UpdateNodeResourceRequest> argument =
@ -342,6 +342,11 @@ public void testUpdateNodeResourceTypes() throws Exception {
ResourceInformation.newInstance("resource2", "m", 2));
ResourceOption resource = resourceMap.get(nodeId);
// Ensure memory-mb has been converted to "Mi"
assertEquals(1024,
resource.getResource().getResourceInformation("memory-mb").getValue());
assertEquals("Mi",
resource.getResource().getResourceInformation("memory-mb").getUnits());
assertNotNull("resource for " + nodeIdStr + " shouldn't be null.",
resource);
assertEquals("resource value for " + nodeIdStr + " is not as expected.",