diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RMAdminCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RMAdminCLI.java index a24c39864f..068eaa8de2 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RMAdminCLI.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RMAdminCLI.java @@ -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: " + diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestRMAdminCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestRMAdminCLI.java index 1f4b493f45..4d0aea2b07 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestRMAdminCLI.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestRMAdminCLI.java @@ -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 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.",