Search in sources :

Example 1 with StoreNewClusterNodeLabels

use of org.apache.hadoop.yarn.nodelabels.event.StoreNewClusterNodeLabels 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 2 with StoreNewClusterNodeLabels

use of org.apache.hadoop.yarn.nodelabels.event.StoreNewClusterNodeLabels in project hadoop by apache.

the class CommonNodeLabelsManager method handleStoreEvent.

// Dispatcher related code
protected void handleStoreEvent(NodeLabelsStoreEvent event) {
    try {
        switch(event.getType()) {
            case ADD_LABELS:
                StoreNewClusterNodeLabels storeNewClusterNodeLabelsEvent = (StoreNewClusterNodeLabels) event;
                store.storeNewClusterNodeLabels(storeNewClusterNodeLabelsEvent.getLabels());
                break;
            case REMOVE_LABELS:
                RemoveClusterNodeLabels removeClusterNodeLabelsEvent = (RemoveClusterNodeLabels) event;
                store.removeClusterNodeLabels(removeClusterNodeLabelsEvent.getLabels());
                break;
            case STORE_NODE_TO_LABELS:
                UpdateNodeToLabelsMappingsEvent updateNodeToLabelsMappingsEvent = (UpdateNodeToLabelsMappingsEvent) event;
                store.updateNodeToLabelsMappings(updateNodeToLabelsMappingsEvent.getNodeToLabels());
                break;
        }
    } catch (IOException e) {
        LOG.error("Failed to store label modification to storage");
        throw new YarnRuntimeException(e);
    }
}
Also used : YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) StoreNewClusterNodeLabels(org.apache.hadoop.yarn.nodelabels.event.StoreNewClusterNodeLabels) UpdateNodeToLabelsMappingsEvent(org.apache.hadoop.yarn.nodelabels.event.UpdateNodeToLabelsMappingsEvent) IOException(java.io.IOException) RemoveClusterNodeLabels(org.apache.hadoop.yarn.nodelabels.event.RemoveClusterNodeLabels)

Aggregations

IOException (java.io.IOException)2 StoreNewClusterNodeLabels (org.apache.hadoop.yarn.nodelabels.event.StoreNewClusterNodeLabels)2 ArrayList (java.util.ArrayList)1 NodeLabel (org.apache.hadoop.yarn.api.records.NodeLabel)1 YarnRuntimeException (org.apache.hadoop.yarn.exceptions.YarnRuntimeException)1 RemoveClusterNodeLabels (org.apache.hadoop.yarn.nodelabels.event.RemoveClusterNodeLabels)1 UpdateNodeToLabelsMappingsEvent (org.apache.hadoop.yarn.nodelabels.event.UpdateNodeToLabelsMappingsEvent)1