Search in sources :

Example 1 with NodeLabel

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

the class RMWebServices method getLabelsToNodes.

@GET
@Path("/label-mappings")
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
public LabelsToNodesInfo getLabelsToNodes(@QueryParam("labels") Set<String> labels) throws IOException {
    init();
    LabelsToNodesInfo lts = new LabelsToNodesInfo();
    Map<NodeLabelInfo, NodeIDsInfo> ltsMap = lts.getLabelsToNodes();
    Map<NodeLabel, Set<NodeId>> labelsToNodeId = null;
    if (labels == null || labels.size() == 0) {
        labelsToNodeId = rm.getRMContext().getNodeLabelManager().getLabelsInfoToNodes();
    } else {
        labelsToNodeId = rm.getRMContext().getNodeLabelManager().getLabelsInfoToNodes(labels);
    }
    for (Entry<NodeLabel, Set<NodeId>> entry : labelsToNodeId.entrySet()) {
        List<String> nodeIdStrList = new ArrayList<String>();
        for (NodeId nodeId : entry.getValue()) {
            nodeIdStrList.add(nodeId.toString());
        }
        ltsMap.put(new NodeLabelInfo(entry.getKey()), new NodeIDsInfo(nodeIdStrList));
    }
    return lts;
}
Also used : LabelsToNodesInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.LabelsToNodesInfo) NodeLabel(org.apache.hadoop.yarn.api.records.NodeLabel) EnumSet(java.util.EnumSet) Set(java.util.Set) HashSet(java.util.HashSet) NodeLabelInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeLabelInfo) ArrayList(java.util.ArrayList) NodeId(org.apache.hadoop.yarn.api.records.NodeId) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with NodeLabel

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

the class RMWebServices method getNodeToLabels.

@GET
@Path("/get-node-to-labels")
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
public NodeToLabelsInfo getNodeToLabels(@Context HttpServletRequest hsr) throws IOException {
    init();
    NodeToLabelsInfo ntl = new NodeToLabelsInfo();
    HashMap<String, NodeLabelsInfo> ntlMap = ntl.getNodeToLabels();
    Map<NodeId, Set<NodeLabel>> nodeIdToLabels = rm.getRMContext().getNodeLabelManager().getNodeLabelsInfo();
    for (Map.Entry<NodeId, Set<NodeLabel>> nitle : nodeIdToLabels.entrySet()) {
        List<NodeLabel> labels = new ArrayList<NodeLabel>(nitle.getValue());
        ntlMap.put(nitle.getKey().toString(), new NodeLabelsInfo(labels));
    }
    return ntl;
}
Also used : EnumSet(java.util.EnumSet) Set(java.util.Set) HashSet(java.util.HashSet) 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) NodeToLabelsInfo(org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeToLabelsInfo) Map(java.util.Map) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with NodeLabel

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

the class RMAdminCLI method handleAddToClusterNodeLabels.

private int handleAddToClusterNodeLabels(String[] args, String cmd, boolean isHAEnabled) throws IOException, YarnException, ParseException {
    Options opts = new Options();
    opts.addOption("addToClusterNodeLabels", true, "Add to cluster node labels.");
    opts.addOption("directlyAccessNodeLabelStore", false, "Directly access node label store.");
    int exitCode = -1;
    CommandLine cliParser = null;
    try {
        cliParser = new GnuParser().parse(opts, args);
    } catch (MissingArgumentException ex) {
        System.err.println(NO_LABEL_ERR_MSG);
        printUsage(args[0], isHAEnabled);
        return exitCode;
    }
    List<NodeLabel> labels = buildNodeLabelsFromStr(cliParser.getOptionValue("addToClusterNodeLabels"));
    if (cliParser.hasOption("directlyAccessNodeLabelStore")) {
        getNodeLabelManagerInstance(getConf()).addToCluserNodeLabels(labels);
    } else {
        ResourceManagerAdministrationProtocol adminProtocol = createAdminProtocol();
        AddToClusterNodeLabelsRequest request = AddToClusterNodeLabelsRequest.newInstance(labels);
        adminProtocol.addToClusterNodeLabels(request);
    }
    return 0;
}
Also used : Options(org.apache.commons.cli.Options) ResourceManagerAdministrationProtocol(org.apache.hadoop.yarn.server.api.ResourceManagerAdministrationProtocol) CommandLine(org.apache.commons.cli.CommandLine) NodeLabel(org.apache.hadoop.yarn.api.records.NodeLabel) MissingArgumentException(org.apache.commons.cli.MissingArgumentException) GnuParser(org.apache.commons.cli.GnuParser) AddToClusterNodeLabelsRequest(org.apache.hadoop.yarn.server.api.protocolrecords.AddToClusterNodeLabelsRequest)

Example 4 with NodeLabel

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

the class NodeLabelTestBase method assertLabelsInfoToNodesEquals.

public static void assertLabelsInfoToNodesEquals(Map<NodeLabel, Set<NodeId>> expected, ImmutableMap<NodeLabel, Set<NodeId>> actual) {
    Assert.assertEquals(expected.size(), actual.size());
    for (NodeLabel k : expected.keySet()) {
        Assert.assertTrue(actual.containsKey(k));
        Set<NodeId> expectedS1 = new HashSet<>(expected.get(k));
        Set<NodeId> actualS2 = new HashSet<>(actual.get(k));
        Assert.assertEquals(expectedS1, actualS2);
        Assert.assertTrue(expectedS1.containsAll(actualS2));
    }
}
Also used : NodeLabel(org.apache.hadoop.yarn.api.records.NodeLabel) NodeId(org.apache.hadoop.yarn.api.records.NodeId) HashSet(java.util.HashSet)

Example 5 with NodeLabel

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

the class TestYarnServerApiClasses method testRegisterNodeManagerRequestWithValidLabels.

@Test
public void testRegisterNodeManagerRequestWithValidLabels() {
    HashSet<NodeLabel> nodeLabels = getValidNodeLabels();
    RegisterNodeManagerRequest request = RegisterNodeManagerRequest.newInstance(NodeId.newInstance("host", 1234), 1234, Resource.newInstance(0, 0), "version", null, null, nodeLabels);
    // serialze to proto, and get request from proto
    RegisterNodeManagerRequest copy = new RegisterNodeManagerRequestPBImpl(((RegisterNodeManagerRequestPBImpl) request).getProto());
    // check labels are coming with valid values
    Assert.assertEquals(true, nodeLabels.containsAll(copy.getNodeLabels()));
    // check for empty labels
    request.setNodeLabels(new HashSet<NodeLabel>());
    copy = new RegisterNodeManagerRequestPBImpl(((RegisterNodeManagerRequestPBImpl) request).getProto());
    Assert.assertNotNull(copy.getNodeLabels());
    Assert.assertEquals(0, copy.getNodeLabels().size());
}
Also used : RegisterNodeManagerRequest(org.apache.hadoop.yarn.server.api.protocolrecords.RegisterNodeManagerRequest) NodeLabel(org.apache.hadoop.yarn.api.records.NodeLabel) RegisterNodeManagerRequestPBImpl(org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb.RegisterNodeManagerRequestPBImpl) UnRegisterNodeManagerRequestPBImpl(org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb.UnRegisterNodeManagerRequestPBImpl) Test(org.junit.Test)

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