RMAdminCLI extends HAAdmin { private int updateNodeResource(String nodeIdStr, int memSize, int cores, int overCommitTimeout) throws IOException, YarnException { if (invalidResourceValue(memSize, cores)) { throw new IllegalArgumentException("Invalid resource value: " + "(" + memSize + "," + cores + ") for updateNodeResource."); } ResourceManagerAdministrationProtocol adminProtocol = createAdminProtocol(); UpdateNodeResourceRequest request = recordFactory.newRecordInstance(UpdateNodeResourceRequest.class); NodeId nodeId = ConverterUtils.toNodeId(nodeIdStr); Resource resource = Resources.createResource(memSize, cores); Map<NodeId, ResourceOption> resourceMap = new HashMap<NodeId, ResourceOption>(); resourceMap.put( nodeId, ResourceOption.newInstance(resource, overCommitTimeout)); request.setNodeResourceMap(resourceMap); adminProtocol.updateNodeResource(request); return 0; } RMAdminCLI();  RMAdminCLI(Configuration conf); @Override int run(String[] args); @Override void setConf(Configuration conf); static void main(String[] args);  }
@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); }