Java Code Examples for org.apache.hadoop.yarn.util.ConverterUtils#toNodeIdWithDefaultPort()

The following examples show how to use org.apache.hadoop.yarn.util.ConverterUtils#toNodeIdWithDefaultPort() . 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: RMWebServices.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/nodes/{nodeId}/get-labels")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public NodeLabelsInfo getLabelsOnNode(@Context HttpServletRequest hsr,
                                @PathParam("nodeId") String nodeId) 
  throws IOException {
  init();

  NodeId nid = ConverterUtils.toNodeIdWithDefaultPort(nodeId);
  return new NodeLabelsInfo(
    rm.getRMContext().getNodeLabelManager().getLabelsOnNode(nid));

}
 
Example 2
Source File: RMWebServices.java    From big-c with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/nodes/{nodeId}/get-labels")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public NodeLabelsInfo getLabelsOnNode(@Context HttpServletRequest hsr,
                                @PathParam("nodeId") String nodeId) 
  throws IOException {
  init();

  NodeId nid = ConverterUtils.toNodeIdWithDefaultPort(nodeId);
  return new NodeLabelsInfo(
    rm.getRMContext().getNodeLabelManager().getLabelsOnNode(nid));

}
 
Example 3
Source File: RMAdminCLI.java    From hadoop with Apache License 2.0 4 votes vote down vote up
private Map<NodeId, Set<String>> buildNodeLabelsMapFromStr(String args) {
  Map<NodeId, Set<String>> map = new HashMap<NodeId, Set<String>>();

  for (String nodeToLabels : args.split("[ \n]")) {
    nodeToLabels = nodeToLabels.trim();
    if (nodeToLabels.isEmpty() || nodeToLabels.startsWith("#")) {
      continue;
    }

    // "," also supported for compatibility
    String[] splits = nodeToLabels.split("=");
    int index = 0;
    if (splits.length != 2) {
      splits = nodeToLabels.split(",");
      index = 1;
    }

    String nodeIdStr = splits[0];
    if (index == 0) {
      splits = splits[1].split(",");
    }
    
    Preconditions.checkArgument(!nodeIdStr.trim().isEmpty(),
        "node name cannot be empty");

    NodeId nodeId = ConverterUtils.toNodeIdWithDefaultPort(nodeIdStr);
    map.put(nodeId, new HashSet<String>());

    for (int i = index; i < splits.length; i++) {
      if (!splits[i].trim().isEmpty()) {
        map.get(nodeId).add(splits[i].trim());
      }
    }
    
    int nLabels = map.get(nodeId).size();
    Preconditions.checkArgument(nLabels <= 1, "%d labels specified on host=%s"
        + ", please note that we do not support specifying multiple"
        + " labels on a single host for now.", nLabels, nodeIdStr);
  }

  if (map.isEmpty()) {
    throw new IllegalArgumentException(NO_MAPPING_ERR_MSG);
  }
  return map;
}
 
Example 4
Source File: RMAdminCLI.java    From big-c with Apache License 2.0 4 votes vote down vote up
private Map<NodeId, Set<String>> buildNodeLabelsMapFromStr(String args) {
  Map<NodeId, Set<String>> map = new HashMap<NodeId, Set<String>>();

  for (String nodeToLabels : args.split("[ \n]")) {
    nodeToLabels = nodeToLabels.trim();
    if (nodeToLabels.isEmpty() || nodeToLabels.startsWith("#")) {
      continue;
    }

    // "," also supported for compatibility
    String[] splits = nodeToLabels.split("=");
    int index = 0;
    if (splits.length != 2) {
      splits = nodeToLabels.split(",");
      index = 1;
    }

    String nodeIdStr = splits[0];
    if (index == 0) {
      splits = splits[1].split(",");
    }
    
    Preconditions.checkArgument(!nodeIdStr.trim().isEmpty(),
        "node name cannot be empty");

    NodeId nodeId = ConverterUtils.toNodeIdWithDefaultPort(nodeIdStr);
    map.put(nodeId, new HashSet<String>());

    for (int i = index; i < splits.length; i++) {
      if (!splits[i].trim().isEmpty()) {
        map.get(nodeId).add(splits[i].trim());
      }
    }
    
    int nLabels = map.get(nodeId).size();
    Preconditions.checkArgument(nLabels <= 1, "%d labels specified on host=%s"
        + ", please note that we do not support specifying multiple"
        + " labels on a single host for now.", nLabels, nodeIdStr);
  }

  if (map.isEmpty()) {
    throw new IllegalArgumentException(NO_MAPPING_ERR_MSG);
  }
  return map;
}