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);
}
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(), ",") + "]");
}
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();
}
}
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);
}
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));
}
}
Aggregations