YARN-4345. yarn rmadmin -updateNodeResource doesn't work. Contributed by Junping Du

This commit is contained in:
Jason Lowe 2015-11-12 14:49:06 +00:00
parent 9ad708a0df
commit 06a70311b9
3 changed files with 37 additions and 1 deletions

View File

@ -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

View File

@ -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<NodeId, ResourceOption>();
resourceMap.put(
nodeId, ResourceOption.newInstance(resource, overCommitTimeout));
request.setNodeResourceMap(resourceMap);
adminProtocol.updateNodeResource(request);
return 0;
}

View File

@ -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<UpdateNodeResourceRequest> argument =
ArgumentCaptor.forClass(UpdateNodeResourceRequest.class);
verify(admin).updateNodeResource(argument.capture());
UpdateNodeResourceRequest request = argument.getValue();
Map<NodeId, ResourceOption> 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" };