Search in sources :

Example 16 with NodeLabel

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

the class GetClusterNodeLabelsResponsePBImpl method addNodeLabelsToProto.

private void addNodeLabelsToProto() {
    maybeInitBuilder();
    builder.clearNodeLabels();
    builder.clearDeprecatedNodeLabels();
    List<NodeLabelProto> protoList = new ArrayList<NodeLabelProto>();
    List<String> protoListString = new ArrayList<String>();
    for (NodeLabel r : this.updatedNodeLabels) {
        protoList.add(convertToProtoFormat(r));
        protoListString.add(r.getName());
    }
    builder.addAllNodeLabels(protoList);
    builder.addAllDeprecatedNodeLabels(protoListString);
}
Also used : NodeLabel(org.apache.hadoop.yarn.api.records.NodeLabel) ArrayList(java.util.ArrayList) NodeLabelProto(org.apache.hadoop.yarn.proto.YarnProtos.NodeLabelProto)

Example 17 with NodeLabel

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

the class CommonNodeLabelsManager method addToCluserNodeLabels.

@SuppressWarnings("unchecked")
public void addToCluserNodeLabels(Collection<NodeLabel> labels) throws IOException {
    if (!nodeLabelsEnabled) {
        LOG.error(NODE_LABELS_NOT_ENABLED_ERR);
        throw new IOException(NODE_LABELS_NOT_ENABLED_ERR);
    }
    if (null == labels || labels.isEmpty()) {
        return;
    }
    List<NodeLabel> newLabels = new ArrayList<NodeLabel>();
    normalizeNodeLabels(labels);
    // check any mismatch in exclusivity no mismatch with skip
    checkExclusivityMatch(labels);
    // doesn't meet label name requirement
    for (NodeLabel label : labels) {
        checkAndThrowLabelName(label.getName());
    }
    for (NodeLabel label : labels) {
        // shouldn't overwrite it to avoid changing the Label.resource
        if (this.labelCollections.get(label.getName()) == null) {
            this.labelCollections.put(label.getName(), new RMNodeLabel(label));
            newLabels.add(label);
        }
    }
    if (null != dispatcher && !newLabels.isEmpty()) {
        dispatcher.getEventHandler().handle(new StoreNewClusterNodeLabels(newLabels));
    }
    LOG.info("Add labels: [" + StringUtils.join(labels.iterator(), ",") + "]");
}
Also used : StoreNewClusterNodeLabels(org.apache.hadoop.yarn.nodelabels.event.StoreNewClusterNodeLabels) NodeLabel(org.apache.hadoop.yarn.api.records.NodeLabel) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 18 with NodeLabel

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

the class CommonNodeLabelsManager method generateNodeLabelsInfoPerNode.

@SuppressWarnings("unchecked")
private <T> Map<NodeId, Set<T>> generateNodeLabelsInfoPerNode(Class<T> type) {
    try {
        readLock.lock();
        Map<NodeId, Set<T>> nodeToLabels = new HashMap<>();
        for (Entry<String, Host> entry : nodeCollections.entrySet()) {
            String hostName = entry.getKey();
            Host host = entry.getValue();
            for (NodeId nodeId : host.nms.keySet()) {
                if (type.isAssignableFrom(String.class)) {
                    Set<String> nodeLabels = getLabelsByNode(nodeId);
                    if (nodeLabels == null || nodeLabels.isEmpty()) {
                        continue;
                    }
                    nodeToLabels.put(nodeId, (Set<T>) nodeLabels);
                } else {
                    Set<NodeLabel> nodeLabels = getLabelsInfoByNode(nodeId);
                    if (nodeLabels == null || nodeLabels.isEmpty()) {
                        continue;
                    }
                    nodeToLabels.put(nodeId, (Set<T>) nodeLabels);
                }
            }
            if (!host.labels.isEmpty()) {
                if (type.isAssignableFrom(String.class)) {
                    nodeToLabels.put(NodeId.newInstance(hostName, WILDCARD_PORT), (Set<T>) host.labels);
                } else {
                    nodeToLabels.put(NodeId.newInstance(hostName, WILDCARD_PORT), (Set<T>) createNodeLabelFromLabelNames(host.labels));
                }
            }
        }
        return Collections.unmodifiableMap(nodeToLabels);
    } finally {
        readLock.unlock();
    }
}
Also used : HashSet(java.util.HashSet) EnumSet(java.util.EnumSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) NodeLabel(org.apache.hadoop.yarn.api.records.NodeLabel) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) NodeId(org.apache.hadoop.yarn.api.records.NodeId)

Example 19 with NodeLabel

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

the class AddToClusterNodeLabelsRequestPBImpl method addNodeLabelsToProto.

private void addNodeLabelsToProto() {
    maybeInitBuilder();
    builder.clearNodeLabels();
    builder.clearDeprecatedNodeLabels();
    List<NodeLabelProto> protoList = new ArrayList<NodeLabelProto>();
    List<String> protoListString = new ArrayList<String>();
    for (NodeLabel r : this.updatedNodeLabels) {
        protoList.add(convertToProtoFormat(r));
        protoListString.add(r.getName());
    }
    builder.addAllNodeLabels(protoList);
    builder.addAllDeprecatedNodeLabels(protoListString);
}
Also used : NodeLabel(org.apache.hadoop.yarn.api.records.NodeLabel) ArrayList(java.util.ArrayList) NodeLabelProto(org.apache.hadoop.yarn.proto.YarnProtos.NodeLabelProto)

Example 20 with NodeLabel

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

the class AddToClusterNodeLabelsRequestPBImpl method initLocalNodeLabels.

private void initLocalNodeLabels() {
    AddToClusterNodeLabelsRequestProtoOrBuilder 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 : NodeLabel(org.apache.hadoop.yarn.api.records.NodeLabel) AddToClusterNodeLabelsRequestProtoOrBuilder(org.apache.hadoop.yarn.proto.YarnServerResourceManagerServiceProtos.AddToClusterNodeLabelsRequestProtoOrBuilder) 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