Search in sources :

Example 11 with NodeLabel

use of org.apache.hadoop.yarn.api.records.NodeLabel in project hadoop by apache.

the class TestClientRMService method testGetLabelsToNodes.

@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();
    NodeLabel labelX = NodeLabel.newInstance("x", false);
    NodeLabel labelY = NodeLabel.newInstance("y", false);
    NodeLabel labelZ = NodeLabel.newInstance("z", false);
    RMNodeLabelsManager labelsMgr = rm.getRMContext().getNodeLabelManager();
    labelsMgr.addToCluserNodeLabels(ImmutableSet.of(labelX, labelY, labelZ));
    NodeId node1A = NodeId.newInstance("host1", 1234);
    NodeId node1B = NodeId.newInstance("host1", 5678);
    NodeId node2A = NodeId.newInstance("host2", 1234);
    NodeId node3A = NodeId.newInstance("host3", 1234);
    NodeId node3B = NodeId.newInstance("host3", 5678);
    Map<NodeId, Set<String>> map = new HashMap<NodeId, Set<String>>();
    map.put(node1A, ImmutableSet.of("x"));
    map.put(node1B, ImmutableSet.of("z"));
    map.put(node2A, ImmutableSet.of("y"));
    map.put(node3A, ImmutableSet.of("y"));
    map.put(node3B, 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.getNodeLabelList().containsAll(Arrays.asList(labelX, labelY, labelZ)));
    // 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(labelX.getName(), labelY.getName(), labelZ.getName())));
    Assert.assertTrue(labelsToNodes.get(labelX.getName()).containsAll(Arrays.asList(node1A)));
    Assert.assertTrue(labelsToNodes.get(labelY.getName()).containsAll(Arrays.asList(node2A, node3A)));
    Assert.assertTrue(labelsToNodes.get(labelZ.getName()).containsAll(Arrays.asList(node1B, node3B)));
    // 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(labelX.getName(), labelZ.getName())));
    Assert.assertTrue(labelsToNodes.get(labelX.getName()).containsAll(Arrays.asList(node1A)));
    Assert.assertTrue(labelsToNodes.get(labelZ.getName()).containsAll(Arrays.asList(node1B, node3B)));
    Assert.assertEquals(labelsToNodes.get(labelY.getName()), null);
    rpc.stopProxy(client, conf);
    rm.close();
}
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) GetLabelsToNodesResponse(org.apache.hadoop.yarn.api.protocolrecords.GetLabelsToNodesResponse) 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) RMNodeLabelsManager(org.apache.hadoop.yarn.server.resourcemanager.nodelabels.RMNodeLabelsManager) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with NodeLabel

use of org.apache.hadoop.yarn.api.records.NodeLabel in project hadoop by apache.

the class RMWebServices method getClusterNodeLabels.

@GET
@Path("/get-node-labels")
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
public NodeLabelsInfo getClusterNodeLabels(@Context HttpServletRequest hsr) throws IOException {
    init();
    List<NodeLabel> nodeLabels = rm.getRMContext().getNodeLabelManager().getClusterNodeLabels();
    NodeLabelsInfo ret = new NodeLabelsInfo(nodeLabels);
    return ret;
}
Also used : NodeLabel(org.apache.hadoop.yarn.api.records.NodeLabel) NodeLabelsInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeLabelsInfo) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 13 with NodeLabel

use of org.apache.hadoop.yarn.api.records.NodeLabel in project hadoop by apache.

the class RMWebServices method getLabelsOnNode.

@GET
@Path("/nodes/{nodeId}/get-labels")
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
public NodeLabelsInfo getLabelsOnNode(@Context HttpServletRequest hsr, @PathParam("nodeId") String nodeId) throws IOException {
    init();
    NodeId nid = ConverterUtils.toNodeIdWithDefaultPort(nodeId);
    List<NodeLabel> labels = new ArrayList<NodeLabel>(rm.getRMContext().getNodeLabelManager().getLabelsInfoByNode(nid));
    return new NodeLabelsInfo(labels);
}
Also used : NodeLabel(org.apache.hadoop.yarn.api.records.NodeLabel) NodeLabelsInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeLabelsInfo) NodeId(org.apache.hadoop.yarn.api.records.NodeId) ArrayList(java.util.ArrayList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 14 with NodeLabel

use of org.apache.hadoop.yarn.api.records.NodeLabel in project hadoop by apache.

the class TestClusterCLI method testGetEmptyClusterNodeLabels.

@Test
public void testGetEmptyClusterNodeLabels() throws Exception {
    YarnClient client = mock(YarnClient.class);
    when(client.getClusterNodeLabels()).thenReturn(new ArrayList<NodeLabel>());
    ClusterCLI cli = new ClusterCLI();
    cli.setClient(client);
    cli.setSysOutPrintStream(sysOut);
    cli.setSysErrPrintStream(sysErr);
    int rc = cli.run(new String[] { ClusterCLI.CMD, "-" + ClusterCLI.LIST_LABELS_CMD });
    assertEquals(0, rc);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintWriter pw = new PrintWriter(baos);
    pw.print("Node Labels: ");
    pw.close();
    verify(sysOut).println(baos.toString("UTF-8"));
}
Also used : NodeLabel(org.apache.hadoop.yarn.api.records.NodeLabel) ByteArrayOutputStream(java.io.ByteArrayOutputStream) YarnClient(org.apache.hadoop.yarn.client.api.YarnClient) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 15 with NodeLabel

use of org.apache.hadoop.yarn.api.records.NodeLabel in project hadoop by apache.

the class GetClusterNodeLabelsResponsePBImpl method initLocalNodeLabels.

private void initLocalNodeLabels() {
    GetClusterNodeLabelsResponseProtoOrBuilder p = viaProto ? proto : builder;
    List<NodeLabelProto> attributesProtoList = p.getNodeLabelsList();
    this.updatedNodeLabels = new ArrayList<NodeLabel>();
    for (NodeLabelProto r : attributesProtoList) {
        this.updatedNodeLabels.add(convertFromProtoFormat(r));
    }
}
Also used : GetClusterNodeLabelsResponseProtoOrBuilder(org.apache.hadoop.yarn.proto.YarnServiceProtos.GetClusterNodeLabelsResponseProtoOrBuilder) NodeLabel(org.apache.hadoop.yarn.api.records.NodeLabel) NodeLabelProto(org.apache.hadoop.yarn.proto.YarnProtos.NodeLabelProto)

Aggregations

NodeLabel (org.apache.hadoop.yarn.api.records.NodeLabel)25 NodeId (org.apache.hadoop.yarn.api.records.NodeId)9 HashSet (java.util.HashSet)7 Set (java.util.Set)7 ArrayList (java.util.ArrayList)6 NodeLabelProto (org.apache.hadoop.yarn.proto.YarnProtos.NodeLabelProto)6 EnumSet (java.util.EnumSet)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)4 GET (javax.ws.rs.GET)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 NodeLabelsInfo (org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeLabelsInfo)3 InetSocketAddress (java.net.InetSocketAddress)2 Configuration (org.apache.hadoop.conf.Configuration)2 ApplicationClientProtocol (org.apache.hadoop.yarn.api.ApplicationClientProtocol)2 GetClusterNodeLabelsResponse (org.apache.hadoop.yarn.api.protocolrecords.GetClusterNodeLabelsResponse)2 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)2