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;
}
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;
}
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;
}
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));
}
}
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());
}
Aggregations