Java Code Examples for org.apache.hadoop.yarn.ipc.YarnRPC#stopProxy()

The following examples show how to use org.apache.hadoop.yarn.ipc.YarnRPC#stopProxy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestContainerManagerSecurity.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private void stopContainer(YarnRPC rpc, Token nmToken,
    List<ContainerId> containerId, ApplicationAttemptId appAttemptId,
    NodeId nodeId) throws Exception {
  StopContainersRequest request =
      StopContainersRequest.newInstance(containerId);
  ContainerManagementProtocol proxy = null;
  try {
    proxy =
        getContainerManagementProtocolProxy(rpc, nmToken, nodeId,
            appAttemptId.toString());
    StopContainersResponse response = proxy.stopContainers(request);
    if (response.getFailedRequests() != null &&
        response.getFailedRequests().containsKey(containerId)) {
      parseAndThrowException(response.getFailedRequests().get(containerId)
          .deSerialize());
    }
  } catch (Exception e) {
    if (proxy != null) {
      rpc.stopProxy(proxy, conf);
    }
  }
}
 
Example 2
Source File: TestContainerManagerSecurity.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private void startContainer(final YarnRPC rpc,
    org.apache.hadoop.yarn.api.records.Token nmToken,
    org.apache.hadoop.yarn.api.records.Token containerToken,
    NodeId nodeId, String user) throws Exception {

  ContainerLaunchContext context =
      Records.newRecord(ContainerLaunchContext.class);
  StartContainerRequest scRequest =
      StartContainerRequest.newInstance(context,containerToken);
  List<StartContainerRequest> list = new ArrayList<StartContainerRequest>();
  list.add(scRequest);
  StartContainersRequest allRequests =
      StartContainersRequest.newInstance(list);
  ContainerManagementProtocol proxy = null;
  try {
    proxy = getContainerManagementProtocolProxy(rpc, nmToken, nodeId, user);
    StartContainersResponse response = proxy.startContainers(allRequests);
    for(SerializedException ex : response.getFailedRequests().values()){
      parseAndThrowException(ex.deSerialize());
    }
  } finally {
    if (proxy != null) {
      rpc.stopProxy(proxy, conf);
    }
  }
}
 
Example 3
Source File: TestContainerManagerSecurity.java    From big-c with Apache License 2.0 6 votes vote down vote up
private void stopContainer(YarnRPC rpc, Token nmToken,
    List<ContainerId> containerId, ApplicationAttemptId appAttemptId,
    NodeId nodeId) throws Exception {
  StopContainersRequest request =
      StopContainersRequest.newInstance(containerId);
  ContainerManagementProtocol proxy = null;
  try {
    proxy =
        getContainerManagementProtocolProxy(rpc, nmToken, nodeId,
            appAttemptId.toString());
    StopContainersResponse response = proxy.stopContainers(request);
    if (response.getFailedRequests() != null &&
        response.getFailedRequests().containsKey(containerId)) {
      parseAndThrowException(response.getFailedRequests().get(containerId)
          .deSerialize());
    }
  } catch (Exception e) {
    if (proxy != null) {
      rpc.stopProxy(proxy, conf);
    }
  }
}
 
Example 4
Source File: TestContainerManagerSecurity.java    From big-c with Apache License 2.0 6 votes vote down vote up
private void startContainer(final YarnRPC rpc,
    org.apache.hadoop.yarn.api.records.Token nmToken,
    org.apache.hadoop.yarn.api.records.Token containerToken,
    NodeId nodeId, String user) throws Exception {

  ContainerLaunchContext context =
      Records.newRecord(ContainerLaunchContext.class);
  StartContainerRequest scRequest =
      StartContainerRequest.newInstance(context,containerToken);
  List<StartContainerRequest> list = new ArrayList<StartContainerRequest>();
  list.add(scRequest);
  StartContainersRequest allRequests =
      StartContainersRequest.newInstance(list);
  ContainerManagementProtocol proxy = null;
  try {
    proxy = getContainerManagementProtocolProxy(rpc, nmToken, nodeId, user);
    StartContainersResponse response = proxy.startContainers(allRequests);
    for(SerializedException ex : response.getFailedRequests().values()){
      parseAndThrowException(ex.deSerialize());
    }
  } finally {
    if (proxy != null) {
      rpc.stopProxy(proxy, conf);
    }
  }
}
 
Example 5
Source File: TestContainerManagerSecurity.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private void
    getContainerStatus(YarnRPC rpc,
        org.apache.hadoop.yarn.api.records.Token nmToken,
        ContainerId containerId,
        ApplicationAttemptId appAttemptId, NodeId nodeId,
        boolean isExceptionExpected) throws Exception {
  List<ContainerId> containerIds = new ArrayList<ContainerId>();
  containerIds.add(containerId);
  GetContainerStatusesRequest request =
      GetContainerStatusesRequest.newInstance(containerIds);
  ContainerManagementProtocol proxy = null;
  try {
    proxy =
        getContainerManagementProtocolProxy(rpc, nmToken, nodeId,
            appAttemptId.toString());
    GetContainerStatusesResponse statuses = proxy.getContainerStatuses(request);
    if (statuses.getFailedRequests() != null
        && statuses.getFailedRequests().containsKey(containerId)) {
      parseAndThrowException(statuses.getFailedRequests().get(containerId)
        .deSerialize());
    }
  } finally {
    if (proxy != null) {
      rpc.stopProxy(proxy, conf);
    }
  }
}
 
Example 6
Source File: TestContainerManagerSecurity.java    From big-c with Apache License 2.0 5 votes vote down vote up
private void
    getContainerStatus(YarnRPC rpc,
        org.apache.hadoop.yarn.api.records.Token nmToken,
        ContainerId containerId,
        ApplicationAttemptId appAttemptId, NodeId nodeId,
        boolean isExceptionExpected) throws Exception {
  List<ContainerId> containerIds = new ArrayList<ContainerId>();
  containerIds.add(containerId);
  GetContainerStatusesRequest request =
      GetContainerStatusesRequest.newInstance(containerIds);
  ContainerManagementProtocol proxy = null;
  try {
    proxy =
        getContainerManagementProtocolProxy(rpc, nmToken, nodeId,
            appAttemptId.toString());
    GetContainerStatusesResponse statuses = proxy.getContainerStatuses(request);
    if (statuses.getFailedRequests() != null
        && statuses.getFailedRequests().containsKey(containerId)) {
      parseAndThrowException(statuses.getFailedRequests().get(containerId)
        .deSerialize());
    }
  } finally {
    if (proxy != null) {
      rpc.stopProxy(proxy, conf);
    }
  }
}
 
Example 7
Source File: TestClientRMService.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetClusterNodes() throws Exception {
  MockRM rm = new MockRM() {
    protected ClientRMService createClientRMService() {
      return new ClientRMService(this.rmContext, scheduler,
        this.rmAppManager, this.applicationACLsManager, this.queueACLsManager,
        this.getRMContext().getRMDelegationTokenSecretManager());
    };
  };
  rm.start();
  RMNodeLabelsManager labelsMgr = rm.getRMContext().getNodeLabelManager();
  labelsMgr.addToCluserNodeLabels(ImmutableSet.of("x", "y"));

  // Add a healthy node with label = x
  MockNM node = rm.registerNode("host1:1234", 1024);
  Map<NodeId, Set<String>> map = new HashMap<NodeId, Set<String>>();
  map.put(node.getNodeId(), ImmutableSet.of("x"));
  labelsMgr.replaceLabelsOnNode(map);
  rm.sendNodeStarted(node);
  node.nodeHeartbeat(true);
  
  // Add and lose a node with label = y
  MockNM lostNode = rm.registerNode("host2:1235", 1024);
  rm.sendNodeStarted(lostNode);
  lostNode.nodeHeartbeat(true);
  rm.NMwaitForState(lostNode.getNodeId(), NodeState.RUNNING);
  rm.sendNodeLost(lostNode);

  // Create a client.
  Configuration conf = new Configuration();
  YarnRPC rpc = YarnRPC.create(conf);
  InetSocketAddress rmAddress = rm.getClientRMService().getBindAddress();
  LOG.info("Connecting to ResourceManager at " + rmAddress);
  ApplicationClientProtocol client =
      (ApplicationClientProtocol) rpc
        .getProxy(ApplicationClientProtocol.class, rmAddress, conf);

  // Make call
  GetClusterNodesRequest request =
      GetClusterNodesRequest.newInstance(EnumSet.of(NodeState.RUNNING));
  List<NodeReport> nodeReports =
      client.getClusterNodes(request).getNodeReports();
  Assert.assertEquals(1, nodeReports.size());
  Assert.assertNotSame("Node is expected to be healthy!", NodeState.UNHEALTHY,
      nodeReports.get(0).getNodeState());
  
  // Check node's label = x
  Assert.assertTrue(nodeReports.get(0).getNodeLabels().contains("x"));

  // Now make the node unhealthy.
  node.nodeHeartbeat(false);

  // Call again
  nodeReports = client.getClusterNodes(request).getNodeReports();
  Assert.assertEquals("Unhealthy nodes should not show up by default", 0,
      nodeReports.size());
  
  // Change label of host1 to y
  map = new HashMap<NodeId, Set<String>>();
  map.put(node.getNodeId(), ImmutableSet.of("y"));
  labelsMgr.replaceLabelsOnNode(map);
  
  // Now query for UNHEALTHY nodes
  request = GetClusterNodesRequest.newInstance(EnumSet.of(NodeState.UNHEALTHY));
  nodeReports = client.getClusterNodes(request).getNodeReports();
  Assert.assertEquals(1, nodeReports.size());
  Assert.assertEquals("Node is expected to be unhealthy!", NodeState.UNHEALTHY,
      nodeReports.get(0).getNodeState());
  
  Assert.assertTrue(nodeReports.get(0).getNodeLabels().contains("y"));
  
  // Remove labels of host1
  map = new HashMap<NodeId, Set<String>>();
  map.put(node.getNodeId(), ImmutableSet.of("y"));
  labelsMgr.removeLabelsFromNode(map);
  
  // Query all states should return all nodes
  rm.registerNode("host3:1236", 1024);
  request = GetClusterNodesRequest.newInstance(EnumSet.allOf(NodeState.class));
  nodeReports = client.getClusterNodes(request).getNodeReports();
  Assert.assertEquals(3, nodeReports.size());
  
  // All host1-3's label should be empty (instead of null)
  for (NodeReport report : nodeReports) {
    Assert.assertTrue(report.getNodeLabels() != null
        && report.getNodeLabels().isEmpty());
  }
  
  rpc.stopProxy(client, conf);
  rm.close();
}
 
Example 8
Source File: TestClientRMService.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetNodeLabels() throws Exception {
  MockRM rm = new MockRM() {
    protected ClientRMService createClientRMService() {
      return new ClientRMService(this.rmContext, scheduler,
          this.rmAppManager, this.applicationACLsManager,
          this.queueACLsManager, this.getRMContext()
              .getRMDelegationTokenSecretManager());
    };
  };
  rm.start();
  RMNodeLabelsManager labelsMgr = rm.getRMContext().getNodeLabelManager();
  labelsMgr.addToCluserNodeLabels(ImmutableSet.of("x", "y"));

  Map<NodeId, Set<String>> map = new HashMap<NodeId, Set<String>>();
  map.put(NodeId.newInstance("host1", 0), ImmutableSet.of("x"));
  map.put(NodeId.newInstance("host2", 0), ImmutableSet.of("y"));
  labelsMgr.replaceLabelsOnNode(map);

  // Create a client.
  Configuration conf = new Configuration();
  YarnRPC rpc = YarnRPC.create(conf);
  InetSocketAddress rmAddress = rm.getClientRMService().getBindAddress();
  LOG.info("Connecting to ResourceManager at " + rmAddress);
  ApplicationClientProtocol client =
      (ApplicationClientProtocol) rpc.getProxy(
          ApplicationClientProtocol.class, rmAddress, conf);

  // Get node labels collection
  GetClusterNodeLabelsResponse response =
      client.getClusterNodeLabels(GetClusterNodeLabelsRequest.newInstance());
  Assert.assertTrue(response.getNodeLabels().containsAll(
      Arrays.asList("x", "y")));

  // Get node labels mapping
  GetNodesToLabelsResponse response1 =
      client.getNodeToLabels(GetNodesToLabelsRequest.newInstance());
  Map<NodeId, Set<String>> nodeToLabels = response1.getNodeToLabels();
  Assert.assertTrue(nodeToLabels.keySet().containsAll(
      Arrays.asList(NodeId.newInstance("host1", 0),
          NodeId.newInstance("host2", 0))));
  Assert.assertTrue(nodeToLabels.get(NodeId.newInstance("host1", 0))
      .containsAll(Arrays.asList("x")));
  Assert.assertTrue(nodeToLabels.get(NodeId.newInstance("host2", 0))
      .containsAll(Arrays.asList("y")));
  
  rpc.stopProxy(client, conf);
  rm.close();
}
 
Example 9
Source File: TestClientRMService.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetLabelsToNodes() throws Exception {
  MockRM rm = new MockRM() {
    protected ClientRMService createClientRMService() {
      return new ClientRMService(this.rmContext, scheduler,
          this.rmAppManager, this.applicationACLsManager,
          this.queueACLsManager, this.getRMContext()
              .getRMDelegationTokenSecretManager());
    };
  };
  rm.start();
  RMNodeLabelsManager labelsMgr = rm.getRMContext().getNodeLabelManager();
  labelsMgr.addToCluserNodeLabels(ImmutableSet.of("x", "y", "z"));

  Map<NodeId, Set<String>> map = new HashMap<NodeId, Set<String>>();
  map.put(NodeId.newInstance("host1", 0), ImmutableSet.of("x"));
  map.put(NodeId.newInstance("host1", 1), ImmutableSet.of("z"));
  map.put(NodeId.newInstance("host2", 0), ImmutableSet.of("y"));
  map.put(NodeId.newInstance("host3", 0), ImmutableSet.of("y"));
  map.put(NodeId.newInstance("host3", 1), ImmutableSet.of("z"));
  labelsMgr.replaceLabelsOnNode(map);

  // Create a client.
  Configuration conf = new Configuration();
  YarnRPC rpc = YarnRPC.create(conf);
  InetSocketAddress rmAddress = rm.getClientRMService().getBindAddress();
  LOG.info("Connecting to ResourceManager at " + rmAddress);
  ApplicationClientProtocol client =
      (ApplicationClientProtocol) rpc.getProxy(
          ApplicationClientProtocol.class, rmAddress, conf);

  // Get node labels collection
  GetClusterNodeLabelsResponse response =
      client.getClusterNodeLabels(GetClusterNodeLabelsRequest.newInstance());
  Assert.assertTrue(response.getNodeLabels().containsAll(
      Arrays.asList("x", "y", "z")));

  // Get labels to nodes mapping
  GetLabelsToNodesResponse response1 =
      client.getLabelsToNodes(GetLabelsToNodesRequest.newInstance());
  Map<String, Set<NodeId>> labelsToNodes = response1.getLabelsToNodes();
  Assert.assertTrue(
      labelsToNodes.keySet().containsAll(Arrays.asList("x", "y", "z")));
  Assert.assertTrue(
      labelsToNodes.get("x").containsAll(Arrays.asList(
      NodeId.newInstance("host1", 0))));
  Assert.assertTrue(
      labelsToNodes.get("y").containsAll(Arrays.asList(
      NodeId.newInstance("host2", 0), NodeId.newInstance("host3", 0))));
  Assert.assertTrue(
      labelsToNodes.get("z").containsAll(Arrays.asList(
      NodeId.newInstance("host1", 1), NodeId.newInstance("host3", 1))));

  // Get labels to nodes mapping for specific labels
  Set<String> setlabels =
      new HashSet<String>(Arrays.asList(new String[]{"x", "z"}));
  GetLabelsToNodesResponse response2 =
      client.getLabelsToNodes(GetLabelsToNodesRequest.newInstance(setlabels));
  labelsToNodes = response2.getLabelsToNodes();
  Assert.assertTrue(
      labelsToNodes.keySet().containsAll(Arrays.asList("x", "z")));
  Assert.assertTrue(
      labelsToNodes.get("x").containsAll(Arrays.asList(
      NodeId.newInstance("host1", 0))));
  Assert.assertTrue(
      labelsToNodes.get("z").containsAll(Arrays.asList(
      NodeId.newInstance("host1", 1), NodeId.newInstance("host3", 1))));
  Assert.assertEquals(labelsToNodes.get("y"), null);

  rpc.stopProxy(client, conf);
  rm.close();
}
 
Example 10
Source File: TestClientRMService.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetClusterNodes() throws Exception {
  MockRM rm = new MockRM() {
    protected ClientRMService createClientRMService() {
      return new ClientRMService(this.rmContext, scheduler,
        this.rmAppManager, this.applicationACLsManager, this.queueACLsManager,
        this.getRMContext().getRMDelegationTokenSecretManager());
    };
  };
  rm.start();
  RMNodeLabelsManager labelsMgr = rm.getRMContext().getNodeLabelManager();
  labelsMgr.addToCluserNodeLabels(ImmutableSet.of("x", "y"));

  // Add a healthy node with label = x
  MockNM node = rm.registerNode("host1:1234", 1024);
  Map<NodeId, Set<String>> map = new HashMap<NodeId, Set<String>>();
  map.put(node.getNodeId(), ImmutableSet.of("x"));
  labelsMgr.replaceLabelsOnNode(map);
  rm.sendNodeStarted(node);
  node.nodeHeartbeat(true);
  
  // Add and lose a node with label = y
  MockNM lostNode = rm.registerNode("host2:1235", 1024);
  rm.sendNodeStarted(lostNode);
  lostNode.nodeHeartbeat(true);
  rm.NMwaitForState(lostNode.getNodeId(), NodeState.RUNNING);
  rm.sendNodeLost(lostNode);

  // Create a client.
  Configuration conf = new Configuration();
  YarnRPC rpc = YarnRPC.create(conf);
  InetSocketAddress rmAddress = rm.getClientRMService().getBindAddress();
  LOG.info("Connecting to ResourceManager at " + rmAddress);
  ApplicationClientProtocol client =
      (ApplicationClientProtocol) rpc
        .getProxy(ApplicationClientProtocol.class, rmAddress, conf);

  // Make call
  GetClusterNodesRequest request =
      GetClusterNodesRequest.newInstance(EnumSet.of(NodeState.RUNNING));
  List<NodeReport> nodeReports =
      client.getClusterNodes(request).getNodeReports();
  Assert.assertEquals(1, nodeReports.size());
  Assert.assertNotSame("Node is expected to be healthy!", NodeState.UNHEALTHY,
      nodeReports.get(0).getNodeState());
  
  // Check node's label = x
  Assert.assertTrue(nodeReports.get(0).getNodeLabels().contains("x"));

  // Now make the node unhealthy.
  node.nodeHeartbeat(false);

  // Call again
  nodeReports = client.getClusterNodes(request).getNodeReports();
  Assert.assertEquals("Unhealthy nodes should not show up by default", 0,
      nodeReports.size());
  
  // Change label of host1 to y
  map = new HashMap<NodeId, Set<String>>();
  map.put(node.getNodeId(), ImmutableSet.of("y"));
  labelsMgr.replaceLabelsOnNode(map);
  
  // Now query for UNHEALTHY nodes
  request = GetClusterNodesRequest.newInstance(EnumSet.of(NodeState.UNHEALTHY));
  nodeReports = client.getClusterNodes(request).getNodeReports();
  Assert.assertEquals(1, nodeReports.size());
  Assert.assertEquals("Node is expected to be unhealthy!", NodeState.UNHEALTHY,
      nodeReports.get(0).getNodeState());
  
  Assert.assertTrue(nodeReports.get(0).getNodeLabels().contains("y"));
  
  // Remove labels of host1
  map = new HashMap<NodeId, Set<String>>();
  map.put(node.getNodeId(), ImmutableSet.of("y"));
  labelsMgr.removeLabelsFromNode(map);
  
  // Query all states should return all nodes
  rm.registerNode("host3:1236", 1024);
  request = GetClusterNodesRequest.newInstance(EnumSet.allOf(NodeState.class));
  nodeReports = client.getClusterNodes(request).getNodeReports();
  Assert.assertEquals(3, nodeReports.size());
  
  // All host1-3's label should be empty (instead of null)
  for (NodeReport report : nodeReports) {
    Assert.assertTrue(report.getNodeLabels() != null
        && report.getNodeLabels().isEmpty());
  }
  
  rpc.stopProxy(client, conf);
  rm.close();
}
 
Example 11
Source File: TestClientRMService.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetNodeLabels() throws Exception {
  MockRM rm = new MockRM() {
    protected ClientRMService createClientRMService() {
      return new ClientRMService(this.rmContext, scheduler,
          this.rmAppManager, this.applicationACLsManager,
          this.queueACLsManager, this.getRMContext()
              .getRMDelegationTokenSecretManager());
    };
  };
  rm.start();
  RMNodeLabelsManager labelsMgr = rm.getRMContext().getNodeLabelManager();
  labelsMgr.addToCluserNodeLabels(ImmutableSet.of("x", "y"));

  Map<NodeId, Set<String>> map = new HashMap<NodeId, Set<String>>();
  map.put(NodeId.newInstance("host1", 0), ImmutableSet.of("x"));
  map.put(NodeId.newInstance("host2", 0), ImmutableSet.of("y"));
  labelsMgr.replaceLabelsOnNode(map);

  // Create a client.
  Configuration conf = new Configuration();
  YarnRPC rpc = YarnRPC.create(conf);
  InetSocketAddress rmAddress = rm.getClientRMService().getBindAddress();
  LOG.info("Connecting to ResourceManager at " + rmAddress);
  ApplicationClientProtocol client =
      (ApplicationClientProtocol) rpc.getProxy(
          ApplicationClientProtocol.class, rmAddress, conf);

  // Get node labels collection
  GetClusterNodeLabelsResponse response =
      client.getClusterNodeLabels(GetClusterNodeLabelsRequest.newInstance());
  Assert.assertTrue(response.getNodeLabels().containsAll(
      Arrays.asList("x", "y")));

  // Get node labels mapping
  GetNodesToLabelsResponse response1 =
      client.getNodeToLabels(GetNodesToLabelsRequest.newInstance());
  Map<NodeId, Set<String>> nodeToLabels = response1.getNodeToLabels();
  Assert.assertTrue(nodeToLabels.keySet().containsAll(
      Arrays.asList(NodeId.newInstance("host1", 0),
          NodeId.newInstance("host2", 0))));
  Assert.assertTrue(nodeToLabels.get(NodeId.newInstance("host1", 0))
      .containsAll(Arrays.asList("x")));
  Assert.assertTrue(nodeToLabels.get(NodeId.newInstance("host2", 0))
      .containsAll(Arrays.asList("y")));
  
  rpc.stopProxy(client, conf);
  rm.close();
}
 
Example 12
Source File: TestClientRMService.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetLabelsToNodes() throws Exception {
  MockRM rm = new MockRM() {
    protected ClientRMService createClientRMService() {
      return new ClientRMService(this.rmContext, scheduler,
          this.rmAppManager, this.applicationACLsManager,
          this.queueACLsManager, this.getRMContext()
              .getRMDelegationTokenSecretManager());
    };
  };
  rm.start();
  RMNodeLabelsManager labelsMgr = rm.getRMContext().getNodeLabelManager();
  labelsMgr.addToCluserNodeLabels(ImmutableSet.of("x", "y", "z"));

  Map<NodeId, Set<String>> map = new HashMap<NodeId, Set<String>>();
  map.put(NodeId.newInstance("host1", 0), ImmutableSet.of("x"));
  map.put(NodeId.newInstance("host1", 1), ImmutableSet.of("z"));
  map.put(NodeId.newInstance("host2", 0), ImmutableSet.of("y"));
  map.put(NodeId.newInstance("host3", 0), ImmutableSet.of("y"));
  map.put(NodeId.newInstance("host3", 1), ImmutableSet.of("z"));
  labelsMgr.replaceLabelsOnNode(map);

  // Create a client.
  Configuration conf = new Configuration();
  YarnRPC rpc = YarnRPC.create(conf);
  InetSocketAddress rmAddress = rm.getClientRMService().getBindAddress();
  LOG.info("Connecting to ResourceManager at " + rmAddress);
  ApplicationClientProtocol client =
      (ApplicationClientProtocol) rpc.getProxy(
          ApplicationClientProtocol.class, rmAddress, conf);

  // Get node labels collection
  GetClusterNodeLabelsResponse response =
      client.getClusterNodeLabels(GetClusterNodeLabelsRequest.newInstance());
  Assert.assertTrue(response.getNodeLabels().containsAll(
      Arrays.asList("x", "y", "z")));

  // Get labels to nodes mapping
  GetLabelsToNodesResponse response1 =
      client.getLabelsToNodes(GetLabelsToNodesRequest.newInstance());
  Map<String, Set<NodeId>> labelsToNodes = response1.getLabelsToNodes();
  Assert.assertTrue(
      labelsToNodes.keySet().containsAll(Arrays.asList("x", "y", "z")));
  Assert.assertTrue(
      labelsToNodes.get("x").containsAll(Arrays.asList(
      NodeId.newInstance("host1", 0))));
  Assert.assertTrue(
      labelsToNodes.get("y").containsAll(Arrays.asList(
      NodeId.newInstance("host2", 0), NodeId.newInstance("host3", 0))));
  Assert.assertTrue(
      labelsToNodes.get("z").containsAll(Arrays.asList(
      NodeId.newInstance("host1", 1), NodeId.newInstance("host3", 1))));

  // Get labels to nodes mapping for specific labels
  Set<String> setlabels =
      new HashSet<String>(Arrays.asList(new String[]{"x", "z"}));
  GetLabelsToNodesResponse response2 =
      client.getLabelsToNodes(GetLabelsToNodesRequest.newInstance(setlabels));
  labelsToNodes = response2.getLabelsToNodes();
  Assert.assertTrue(
      labelsToNodes.keySet().containsAll(Arrays.asList("x", "z")));
  Assert.assertTrue(
      labelsToNodes.get("x").containsAll(Arrays.asList(
      NodeId.newInstance("host1", 0))));
  Assert.assertTrue(
      labelsToNodes.get("z").containsAll(Arrays.asList(
      NodeId.newInstance("host1", 1), NodeId.newInstance("host3", 1))));
  Assert.assertEquals(labelsToNodes.get("y"), null);

  rpc.stopProxy(client, conf);
  rm.close();
}