private int updateNodeResource(String nodeIdStr, Resource resource,
      int overCommitTimeout, String subClusterId) throws YarnException, IOException {

    ResourceManagerAdministrationProtocol adminProtocol = createAdminProtocol();
    UpdateNodeResourceRequest request =
      recordFactory.newRecordInstance(UpdateNodeResourceRequest.class);
    NodeId nodeId = NodeId.fromString(nodeIdStr);

    Map<NodeId, ResourceOption> resourceMap = new HashMap<>();
    resourceMap.put(
        nodeId, ResourceOption.newInstance(resource, overCommitTimeout));
    request.setNodeResourceMap(resourceMap);
    if (StringUtils.isNotBlank(subClusterId)) {
      request.setSubClusterId(subClusterId);
    }
    adminProtocol.updateNodeResource(request);
    return 0;
  }
@Test
  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 = NodeId.fromString(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);
  }