

package org.apache.hadoop.yarn.server.resourcemanager.nodelabels;

import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.yarn.api.records.NodeId;
import org.apache.hadoop.yarn.api.records.NodeLabel;
import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.apache.hadoop.yarn.nodelabels.NodeLabelsStore;

public class NullRMNodeLabelsManager extends RMNodeLabelsManager {
  Map<NodeId, Set<String>> lastNodeToLabels = null;
  Collection<String> lastAddedlabels = null;
  Collection<String> lastRemovedlabels = null;

  @Override
  public void initNodeLabelStore(Configuration conf) {
    this.store = new NodeLabelsStore(this) {

      @Override
      public void recover() throws IOException {
        // do nothing
      }

      @Override
      public void removeClusterNodeLabels(Collection<String> labels)
          throws IOException {
        // do nothing
      }

      @Override
      public void updateNodeToLabelsMappings(
          Map<NodeId, Set<String>> nodeToLabels) throws IOException {
        // do nothing
      }

      @Override
      public void storeNewClusterNodeLabels(Set<String> label) throws IOException {
        // do nothing
      }

      @Override
      public void close() throws IOException {
        // do nothing
      }

      @Override
      public void updateNodeLabels(List<NodeLabel> updatedNodeLabels)
          throws IOException {
        // do nothing
      }
    };
  }

  @Override
  protected void initDispatcher(Configuration conf) {
    super.dispatcher = null;
  }

  @Override
  protected void startDispatcher() {
    // do nothing
  }
  
  @Override
  protected void stopDispatcher() {
    // do nothing
  }
  
  @Override
  protected void serviceInit(Configuration conf) throws Exception {
    // always enable node labels while using MemoryRMNodeLabelsManager
    conf.setBoolean(YarnConfiguration.NODE_LABELS_ENABLED, true);
    super.serviceInit(conf);
  }
}
