class CommonNodeLabelsManager extends AbstractService {

  @SuppressWarnings("unchecked")
  public void addToCluserNodeLabels(Set<String> 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;
    }
    Set<String> newLabels = new HashSet<String>();
    labels = normalizeLabels(labels);

    // do a check before actual adding them, will throw exception if any of them
    // doesn't meet label name requirement
    for (String label : labels) {
      checkAndThrowLabelName(label);
    }

    for (String label : labels) {
      // shouldn't overwrite it to avoid changing the Label.resource
      if (this.labelCollections.get(label) == null) {
        this.labelCollections.put(label, new NodeLabel(label));
        newLabels.add(label);
      }
    }
    if (null != dispatcher && !newLabels.isEmpty()) {
      dispatcher.getEventHandler().handle(
          new StoreNewClusterNodeLabels(newLabels));
    }

    LOG.info("Add labels: [" + StringUtils.join(labels.iterator(), ",") + "]");
  }

  public  CommonNodeLabelsManager();

}