From 06a70311b90a7bc676af86e778ec7bcd8dd6ea82 Mon Sep 17 00:00:00 2001 From: Jason Lowe Date: Thu, 12 Nov 2015 14:49:06 +0000 Subject: [PATCH] YARN-4345. yarn rmadmin -updateNodeResource doesn't work. Contributed by Junping Du --- hadoop-yarn-project/CHANGES.txt | 3 ++ .../hadoop/yarn/client/cli/RMAdminCLI.java | 3 +- .../yarn/client/cli/TestRMAdminCLI.java | 32 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index 5ee2eae426..33b4c24bea 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -1048,6 +1048,9 @@ Release 2.8.0 - UNRELEASED YARN-3840. Resource Manager web ui issue when sorting application by id (with application having id > 9999) (Mohammad Shahid Khan via jianhe) + YARN-4345. yarn rmadmin -updateNodeResource doesn't work (Junping Du via + jlowe) + Release 2.7.3 - UNRELEASED INCOMPATIBLE CHANGES 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 92cb934223..21ba7a828a 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 @@ -415,7 +415,7 @@ private int refreshClusterMaxPriority() throws IOException, YarnException { adminProtocol.refreshClusterMaxPriority(request); return 0; } - + private int updateNodeResource(String nodeIdStr, int memSize, int cores, int overCommitTimeout) throws IOException, YarnException { // Refresh the nodes @@ -428,6 +428,7 @@ private int updateNodeResource(String nodeIdStr, int memSize, new HashMap(); resourceMap.put( nodeId, ResourceOption.newInstance(resource, overCommitTimeout)); + request.setNodeResourceMap(resourceMap); adminProtocol.updateNodeResource(request); return 0; } 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 74ed848d7e..085cf02c8f 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 @@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; @@ -35,6 +36,7 @@ import java.io.IOException; import java.io.PrintStream; import java.util.HashSet; +import java.util.Map; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.ha.HAServiceProtocol; @@ -43,6 +45,8 @@ import org.apache.hadoop.service.Service.STATE; import org.apache.hadoop.yarn.api.records.DecommissionType; import org.apache.hadoop.yarn.api.records.NodeId; +import org.apache.hadoop.yarn.api.records.Resource; +import org.apache.hadoop.yarn.api.records.ResourceOption; import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.exceptions.YarnException; import org.apache.hadoop.yarn.nodelabels.CommonNodeLabelsManager; @@ -59,9 +63,13 @@ import org.apache.hadoop.yarn.server.api.protocolrecords.RefreshServiceAclsRequest; import org.apache.hadoop.yarn.server.api.protocolrecords.RefreshSuperUserGroupsConfigurationRequest; import org.apache.hadoop.yarn.server.api.protocolrecords.RefreshUserToGroupsMappingsRequest; +import org.apache.hadoop.yarn.server.api.protocolrecords.UpdateNodeResourceRequest; +import org.apache.hadoop.yarn.util.ConverterUtils; import org.apache.hadoop.yarn.util.Records; +import org.apache.hadoop.yarn.util.resource.Resources; import org.junit.Before; import org.junit.Test; +import org.mockito.ArgumentCaptor; import org.mockito.ArgumentMatcher; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -186,6 +194,30 @@ public void testRefreshServiceAcl() throws Exception { verify(admin).refreshServiceAcls(any(RefreshServiceAclsRequest.class)); } + @Test(timeout=500) + public void testUpdateNodeResource() throws Exception { + String nodeIdStr = "0.0.0.0:0"; + int memSize = 2048; + int cores = 2; + String[] args = { "-updateNodeResource", nodeIdStr, + Integer.toString(memSize), Integer.toString(cores) }; + assertEquals(0, rmAdminCLI.run(args)); + ArgumentCaptor argument = + ArgumentCaptor.forClass(UpdateNodeResourceRequest.class); + verify(admin).updateNodeResource(argument.capture()); + UpdateNodeResourceRequest request = argument.getValue(); + Map resourceMap = request.getNodeResourceMap(); + NodeId nodeId = ConverterUtils.toNodeId(nodeIdStr); + Resource expectedResource = Resources.createResource(memSize, cores); + ResourceOption resource = resourceMap.get(nodeId); + assertNotNull("resource for " + nodeIdStr + " shouldn't be null.", + resource); + assertEquals("resource value for " + nodeIdStr + " is not as expected.", + ResourceOption.newInstance(expectedResource, + ResourceOption.OVER_COMMIT_TIMEOUT_MILLIS_DEFAULT), + resource); + } + @Test(timeout=500) public void testRefreshNodes() throws Exception { String[] args = { "-refreshNodes" };