Search in sources :

Example 1 with GetNodesToLabelsResponse

use of org.apache.hadoop.yarn.api.protocolrecords.GetNodesToLabelsResponse in project hadoop by apache.

the class ClientRMService method getNodeToLabels.

@Override
public GetNodesToLabelsResponse getNodeToLabels(GetNodesToLabelsRequest request) throws YarnException, IOException {
    RMNodeLabelsManager labelsMgr = rmContext.getNodeLabelManager();
    GetNodesToLabelsResponse response = GetNodesToLabelsResponse.newInstance(labelsMgr.getNodeLabels());
    return response;
}
Also used : GetNodesToLabelsResponse(org.apache.hadoop.yarn.api.protocolrecords.GetNodesToLabelsResponse) RMNodeLabelsManager(org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager)

Example 2 with GetNodesToLabelsResponse

use of org.apache.hadoop.yarn.api.protocolrecords.GetNodesToLabelsResponse in project hadoop by apache.

the class TestClientRMService method testGetNodeLabels.

@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();
    NodeLabel labelX = NodeLabel.newInstance("x", false);
    NodeLabel labelY = NodeLabel.newInstance("y");
    RMNodeLabelsManager labelsMgr = rm.getRMContext().getNodeLabelManager();
    labelsMgr.addToCluserNodeLabels(ImmutableSet.of(labelX, labelY));
    NodeId node1 = NodeId.newInstance("host1", 1234);
    NodeId node2 = NodeId.newInstance("host2", 1234);
    Map<NodeId, Set<String>> map = new HashMap<NodeId, Set<String>>();
    map.put(node1, ImmutableSet.of("x"));
    map.put(node2, 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.getNodeLabelList().containsAll(Arrays.asList(labelX, labelY)));
    // Get node labels mapping
    GetNodesToLabelsResponse response1 = client.getNodeToLabels(GetNodesToLabelsRequest.newInstance());
    Map<NodeId, Set<String>> nodeToLabels = response1.getNodeToLabels();
    Assert.assertTrue(nodeToLabels.keySet().containsAll(Arrays.asList(node1, node2)));
    Assert.assertTrue(nodeToLabels.get(node1).containsAll(Arrays.asList(labelX.getName())));
    Assert.assertTrue(nodeToLabels.get(node2).containsAll(Arrays.asList(labelY.getName())));
    // Below label "x" is not present in the response as exclusivity is true
    Assert.assertFalse(nodeToLabels.get(node1).containsAll(Arrays.asList(NodeLabel.newInstance("x"))));
    rpc.stopProxy(client, conf);
    rm.stop();
}
Also used : EnumSet(java.util.EnumSet) Set(java.util.Set) ImmutableSet(com.google.common.collect.ImmutableSet) HashSet(java.util.HashSet) CapacitySchedulerConfiguration(org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) InetSocketAddress(java.net.InetSocketAddress) Matchers.anyString(org.mockito.Matchers.anyString) YarnRPC(org.apache.hadoop.yarn.ipc.YarnRPC) GetClusterNodeLabelsResponse(org.apache.hadoop.yarn.api.protocolrecords.GetClusterNodeLabelsResponse) ApplicationClientProtocol(org.apache.hadoop.yarn.api.ApplicationClientProtocol) NodeLabel(org.apache.hadoop.yarn.api.records.NodeLabel) NodeId(org.apache.hadoop.yarn.api.records.NodeId) GetNodesToLabelsResponse(org.apache.hadoop.yarn.api.protocolrecords.GetNodesToLabelsResponse) RMNodeLabelsManager(org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager) Test(org.junit.Test)

Aggregations

GetNodesToLabelsResponse (org.apache.hadoop.yarn.api.protocolrecords.GetNodesToLabelsResponse)2 RMNodeLabelsManager (org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 InetSocketAddress (java.net.InetSocketAddress)1 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Configuration (org.apache.hadoop.conf.Configuration)1 ApplicationClientProtocol (org.apache.hadoop.yarn.api.ApplicationClientProtocol)1 GetClusterNodeLabelsResponse (org.apache.hadoop.yarn.api.protocolrecords.GetClusterNodeLabelsResponse)1 NodeId (org.apache.hadoop.yarn.api.records.NodeId)1 NodeLabel (org.apache.hadoop.yarn.api.records.NodeLabel)1 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)1 YarnRPC (org.apache.hadoop.yarn.ipc.YarnRPC)1 CapacitySchedulerConfiguration (org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1