You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by ae...@apache.org on 2018/03/15 16:32:34 UTC

[19/51] [partial] hadoop git commit: HDFS-13258. Ozone: restructure Hdsl/Ozone code to separated maven subprojects. Contributed by Elek Marton, Mukul Kumar Singh, Xiaoyu Yao, Ajay Kumar, Anu Engineer, Lokesh Jain, Nanda Kumar.

http://git-wip-us.apache.org/repos/asf/hadoop/blob/ce23d9ad/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/container/replication/InProgressPool.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/container/replication/InProgressPool.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/container/replication/InProgressPool.java
deleted file mode 100644
index 833d1a8..0000000
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/container/replication/InProgressPool.java
+++ /dev/null
@@ -1,313 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership.  The ASF
- * licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.apache.hadoop.ozone.scm.container.replication;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
-import org.apache.hadoop.hdfs.protocol.DatanodeID;
-import org.apache.hadoop.ozone.protocol.commands.SendContainerCommand;
-import org.apache.hadoop.ozone.protocol.proto.OzoneProtos.NodeState;
-import org.apache.hadoop.ozone.protocol.proto
-    .StorageContainerDatanodeProtocolProtos.ContainerInfo;
-import org.apache.hadoop.ozone.protocol.proto
-    .StorageContainerDatanodeProtocolProtos.ContainerReportsRequestProto;
-import org.apache.hadoop.ozone.scm.node.NodeManager;
-import org.apache.hadoop.ozone.scm.node.NodePoolManager;
-import org.apache.hadoop.util.Time;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.function.Predicate;
-import java.util.stream.Collectors;
-
-import static com.google.common.util.concurrent.Uninterruptibles
-    .sleepUninterruptibly;
-import static org.apache.hadoop.ozone.protocol.proto.OzoneProtos
-    .NodeState.HEALTHY;
-import static org.apache.hadoop.ozone.protocol.proto.OzoneProtos
-    .NodeState.STALE;
-import static org.apache.hadoop.ozone.protocol.proto.OzoneProtos
-    .NodeState.UNKNOWN;
-
-/**
- * These are pools that are actively checking for replication status of the
- * containers.
- */
-public final class InProgressPool {
-  public static final Logger LOG =
-      LoggerFactory.getLogger(InProgressPool.class);
-
-  private final PeriodicPool pool;
-  private final NodeManager nodeManager;
-  private final NodePoolManager poolManager;
-  private final ExecutorService executorService;
-  private final Map<String, Integer> containerCountMap;
-  private final Map<String, Boolean> processedNodeSet;
-  private final long startTime;
-  private ProgressStatus status;
-  private AtomicInteger nodeCount;
-  private AtomicInteger nodeProcessed;
-  private AtomicInteger containerProcessedCount;
-  private long maxWaitTime;
-  /**
-   * Constructs an pool that is being processed.
-   *  @param maxWaitTime - Maximum wait time in milliseconds.
-   * @param pool - Pool that we are working against
-   * @param nodeManager - Nodemanager
-   * @param poolManager - pool manager
-   * @param executorService - Shared Executor service.
-   */
-  InProgressPool(long maxWaitTime, PeriodicPool pool,
-      NodeManager nodeManager, NodePoolManager poolManager,
-                 ExecutorService executorService) {
-    Preconditions.checkNotNull(pool);
-    Preconditions.checkNotNull(nodeManager);
-    Preconditions.checkNotNull(poolManager);
-    Preconditions.checkNotNull(executorService);
-    Preconditions.checkArgument(maxWaitTime > 0);
-    this.pool = pool;
-    this.nodeManager = nodeManager;
-    this.poolManager = poolManager;
-    this.executorService = executorService;
-    this.containerCountMap = new ConcurrentHashMap<>();
-    this.processedNodeSet = new ConcurrentHashMap<>();
-    this.maxWaitTime = maxWaitTime;
-    startTime = Time.monotonicNow();
-  }
-
-  /**
-   * Returns periodic pool.
-   *
-   * @return PeriodicPool
-   */
-  public PeriodicPool getPool() {
-    return pool;
-  }
-
-  /**
-   * We are done if we have got reports from all nodes or we have
-   * done waiting for the specified time.
-   *
-   * @return true if we are done, false otherwise.
-   */
-  public boolean isDone() {
-    return (nodeCount.get() == nodeProcessed.get()) ||
-        (this.startTime + this.maxWaitTime) > Time.monotonicNow();
-  }
-
-  /**
-   * Gets the number of containers processed.
-   *
-   * @return int
-   */
-  public int getContainerProcessedCount() {
-    return containerProcessedCount.get();
-  }
-
-  /**
-   * Returns the start time in milliseconds.
-   *
-   * @return - Start Time.
-   */
-  public long getStartTime() {
-    return startTime;
-  }
-
-  /**
-   * Get the number of nodes in this pool.
-   *
-   * @return - node count
-   */
-  public int getNodeCount() {
-    return nodeCount.get();
-  }
-
-  /**
-   * Get the number of nodes that we have already processed container reports
-   * from.
-   *
-   * @return - Processed count.
-   */
-  public int getNodeProcessed() {
-    return nodeProcessed.get();
-  }
-
-  /**
-   * Returns the current status.
-   *
-   * @return Status
-   */
-  public ProgressStatus getStatus() {
-    return status;
-  }
-
-  /**
-   * Starts the reconciliation process for all the nodes in the pool.
-   */
-  public void startReconciliation() {
-    List<DatanodeID> datanodeIDList =
-        this.poolManager.getNodes(pool.getPoolName());
-    if (datanodeIDList.size() == 0) {
-      LOG.error("Datanode list for {} is Empty. Pool with no nodes ? ",
-          pool.getPoolName());
-      this.status = ProgressStatus.Error;
-      return;
-    }
-
-    nodeProcessed = new AtomicInteger(0);
-    containerProcessedCount = new AtomicInteger(0);
-    nodeCount = new AtomicInteger(0);
-    /*
-       Ask each datanode to send us commands.
-     */
-    SendContainerCommand cmd = SendContainerCommand.newBuilder().build();
-    for (DatanodeID id : datanodeIDList) {
-      NodeState currentState = getNodestate(id);
-      if (currentState == HEALTHY || currentState == STALE) {
-        nodeCount.incrementAndGet();
-        // Queue commands to all datanodes in this pool to send us container
-        // report. Since we ignore dead nodes, it is possible that we would have
-        // over replicated the container if the node comes back.
-        nodeManager.addDatanodeCommand(id, cmd);
-      }
-    }
-    this.status = ProgressStatus.InProgress;
-    this.getPool().setLastProcessedTime(Time.monotonicNow());
-  }
-
-  /**
-   * Gets the node state.
-   *
-   * @param id - datanode ID.
-   * @return NodeState.
-   */
-  private NodeState getNodestate(DatanodeID id) {
-    NodeState  currentState = UNKNOWN;
-    int maxTry = 100;
-    // We need to loop to make sure that we will retry if we get
-    // node state unknown. This can lead to infinite loop if we send
-    // in unknown node ID. So max try count is used to prevent it.
-
-    int currentTry = 0;
-    while (currentState == UNKNOWN && currentTry < maxTry) {
-      // Retry to make sure that we deal with the case of node state not
-      // known.
-      currentState = nodeManager.getNodeState(id);
-      currentTry++;
-      if (currentState == UNKNOWN) {
-        // Sleep to make sure that this is not a tight loop.
-        sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
-      }
-    }
-    if (currentState == UNKNOWN) {
-      LOG.error("Not able to determine the state of Node: {}, Exceeded max " +
-          "try and node manager returns UNKNOWN state. This indicates we " +
-          "are dealing with a node that we don't know about.", id);
-    }
-    return currentState;
-  }
-
-  /**
-   * Queues a container Report for handling. This is done in a worker thread
-   * since decoding a container report might be compute intensive . We don't
-   * want to block since we have asked for bunch of container reports
-   * from a set of datanodes.
-   *
-   * @param containerReport - ContainerReport
-   */
-  public void handleContainerReport(
-      ContainerReportsRequestProto containerReport) {
-    if (status == ProgressStatus.InProgress) {
-      executorService.submit(processContainerReport(containerReport));
-    } else {
-      LOG.debug("Cannot handle container report when the pool is in {} status.",
-          status);
-    }
-  }
-
-  private Runnable processContainerReport(
-      ContainerReportsRequestProto reports) {
-    return () -> {
-      DatanodeID datanodeID =
-          DatanodeID.getFromProtoBuf(reports.getDatanodeID());
-      if (processedNodeSet.computeIfAbsent(datanodeID.getDatanodeUuid(),
-          (k) -> true)) {
-        nodeProcessed.incrementAndGet();
-        LOG.debug("Total Nodes processed : {} Node Name: {} ", nodeProcessed,
-            datanodeID.getDatanodeUuid());
-        for (ContainerInfo info : reports.getReportsList()) {
-          containerProcessedCount.incrementAndGet();
-          LOG.debug("Total Containers processed: {} Container Name: {}",
-              containerProcessedCount.get(), info.getContainerName());
-
-          // Update the container map with count + 1 if the key exists or
-          // update the map with 1. Since this is a concurrentMap the
-          // computation and update is atomic.
-          containerCountMap.merge(info.getContainerName(), 1, Integer::sum);
-        }
-      }
-    };
-  }
-
-  /**
-   * Filter the containers based on specific rules.
-   *
-   * @param predicate -- Predicate to filter by
-   * @return A list of map entries.
-   */
-  public List<Map.Entry<String, Integer>> filterContainer(
-      Predicate<Map.Entry<String, Integer>> predicate) {
-    return containerCountMap.entrySet().stream()
-        .filter(predicate).collect(Collectors.toList());
-  }
-
-  /**
-   * Used only for testing, calling this will abort container report
-   * processing. This is very dangerous call and should not be made by any users
-   */
-  @VisibleForTesting
-  public void setDoneProcessing() {
-    nodeProcessed.set(nodeCount.get());
-  }
-
-  /**
-   * Returns the pool name.
-   *
-   * @return Name of the pool.
-   */
-  String getPoolName() {
-    return pool.getPoolName();
-  }
-
-  public void finalizeReconciliation() {
-    status = ProgressStatus.Done;
-    //TODO: Add finalizing logic. This is where actual reconciliation happens.
-  }
-
-  /**
-   * Current status of the computing replication status.
-   */
-  public enum ProgressStatus {
-    InProgress, Done, Error
-  }
-}

http://git-wip-us.apache.org/repos/asf/hadoop/blob/ce23d9ad/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/container/replication/PeriodicPool.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/container/replication/PeriodicPool.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/container/replication/PeriodicPool.java
deleted file mode 100644
index 35b1e76..0000000
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/container/replication/PeriodicPool.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership.  The ASF
- * licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.apache.hadoop.ozone.scm.container.replication;
-
-import java.util.concurrent.atomic.AtomicLong;
-
-/**
- * Periodic pool is a pool with a time stamp, this allows us to process pools
- * based on a cyclic clock.
- */
-public class PeriodicPool implements Comparable<PeriodicPool> {
-  private final String poolName;
-  private long lastProcessedTime;
-  private AtomicLong totalProcessedCount;
-
-  /**
-   * Constructs a periodic pool.
-   *
-   * @param poolName - Name of the pool
-   */
-  public PeriodicPool(String poolName) {
-    this.poolName = poolName;
-    lastProcessedTime = 0;
-    totalProcessedCount = new AtomicLong(0);
-  }
-
-  /**
-   * Get pool Name.
-   * @return PoolName
-   */
-  public String getPoolName() {
-    return poolName;
-  }
-
-  /**
-   * Compares this object with the specified object for order.  Returns a
-   * negative integer, zero, or a positive integer as this object is less
-   * than, equal to, or greater than the specified object.
-   *
-   * @param o the object to be compared.
-   * @return a negative integer, zero, or a positive integer as this object is
-   * less than, equal to, or greater than the specified object.
-   * @throws NullPointerException if the specified object is null
-   * @throws ClassCastException   if the specified object's type prevents it
-   *                              from being compared to this object.
-   */
-  @Override
-  public int compareTo(PeriodicPool o) {
-    return Long.compare(this.lastProcessedTime, o.lastProcessedTime);
-  }
-
-  @Override
-  public boolean equals(Object o) {
-    if (this == o) {
-      return true;
-    }
-    if (o == null || getClass() != o.getClass()) {
-      return false;
-    }
-
-    PeriodicPool that = (PeriodicPool) o;
-
-    return poolName.equals(that.poolName);
-  }
-
-  @Override
-  public int hashCode() {
-    return poolName.hashCode();
-  }
-
-  /**
-   * Returns the Total Times we have processed this pool.
-   *
-   * @return processed count.
-   */
-  public long getTotalProcessedCount() {
-    return totalProcessedCount.get();
-  }
-
-  /**
-   * Gets the last time we processed this pool.
-   * @return time in milliseconds
-   */
-  public long getLastProcessedTime() {
-    return this.lastProcessedTime;
-  }
-
-
-  /**
-   * Sets the last processed time.
-   *
-   * @param lastProcessedTime - Long in milliseconds.
-   */
-
-  public void setLastProcessedTime(long lastProcessedTime) {
-    this.lastProcessedTime = lastProcessedTime;
-  }
-
-  /*
-   * Increments the total processed count.
-   */
-  public void incTotalProcessedCount() {
-    this.totalProcessedCount.incrementAndGet();
-  }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/hadoop/blob/ce23d9ad/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/container/replication/package-info.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/container/replication/package-info.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/container/replication/package-info.java
deleted file mode 100644
index 82e4202..0000000
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/container/replication/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership.  The ASF
- * licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.apache.hadoop.ozone.scm.container.replication;
-/*
- This package contains routines that manage replication of a container. This
- relies on container reports to understand the replication level of a
- container - UnderReplicated, Replicated, OverReplicated -- and manages the
- replication level based on that.
- */
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/hadoop/blob/ce23d9ad/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/exceptions/SCMException.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/exceptions/SCMException.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/exceptions/SCMException.java
deleted file mode 100644
index 4fb50e7..0000000
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/exceptions/SCMException.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.hadoop.ozone.scm.exceptions;
-
-import java.io.IOException;
-
-/**
- * Exception thrown by SCM.
- */
-public class SCMException extends IOException {
-  private final ResultCodes result;
-
-  /**
-   * Constructs an {@code IOException} with {@code null}
-   * as its error detail message.
-   */
-  public SCMException(ResultCodes result) {
-    this.result = result;
-  }
-
-  /**
-   * Constructs an {@code IOException} with the specified detail message.
-   *
-   * @param message The detail message (which is saved for later retrieval by
-   * the
-   * {@link #getMessage()} method)
-   */
-  public SCMException(String message, ResultCodes result) {
-    super(message);
-    this.result = result;
-  }
-
-  /**
-   * Constructs an {@code IOException} with the specified detail message
-   * and cause.
-   * <p>
-   * <p> Note that the detail message associated with {@code cause} is
-   * <i>not</i> automatically incorporated into this exception's detail
-   * message.
-   *
-   * @param message The detail message (which is saved for later retrieval by
-   * the
-   * {@link #getMessage()} method)
-   * @param cause The cause (which is saved for later retrieval by the {@link
-   * #getCause()} method).  (A null value is permitted, and indicates that the
-   * cause is nonexistent or unknown.)
-   * @since 1.6
-   */
-  public SCMException(String message, Throwable cause, ResultCodes result) {
-    super(message, cause);
-    this.result = result;
-  }
-
-  /**
-   * Constructs an {@code IOException} with the specified cause and a
-   * detail message of {@code (cause==null ? null : cause.toString())}
-   * (which typically contains the class and detail message of {@code cause}).
-   * This constructor is useful for IO exceptions that are little more
-   * than wrappers for other throwables.
-   *
-   * @param cause The cause (which is saved for later retrieval by the {@link
-   * #getCause()} method).  (A null value is permitted, and indicates that the
-   * cause is nonexistent or unknown.)
-   * @since 1.6
-   */
-  public SCMException(Throwable cause, ResultCodes result) {
-    super(cause);
-    this.result = result;
-  }
-
-  /**
-   * Returns resultCode.
-   * @return ResultCode
-   */
-  public ResultCodes getResult() {
-    return result;
-  }
-
-  /**
-   * Error codes to make it easy to decode these exceptions.
-   */
-  public enum ResultCodes {
-    SUCCEESS,
-    FAILED_TO_LOAD_NODEPOOL,
-    FAILED_TO_FIND_NODE_IN_POOL,
-    FAILED_TO_FIND_HEALTHY_NODES,
-    FAILED_TO_FIND_NODES_WITH_SPACE,
-    FAILED_TO_FIND_SUITABLE_NODE,
-    INVALID_CAPACITY,
-    INVALID_BLOCK_SIZE,
-    CHILL_MODE_EXCEPTION,
-    FAILED_TO_LOAD_OPEN_CONTAINER,
-    FAILED_TO_ALLOCATE_CONTAINER,
-    FAILED_TO_CHANGE_CONTAINER_STATE,
-    CONTAINER_EXISTS,
-    FAILED_TO_FIND_CONTAINER,
-    FAILED_TO_FIND_CONTAINER_WITH_SPACE,
-    BLOCK_EXISTS,
-    FAILED_TO_FIND_BLOCK,
-    IO_EXCEPTION,
-    UNEXPECTED_CONTAINER_STATE,
-    SCM_NOT_INITIALIZED
-  }
-}

http://git-wip-us.apache.org/repos/asf/hadoop/blob/ce23d9ad/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/exceptions/package-info.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/exceptions/package-info.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/exceptions/package-info.java
deleted file mode 100644
index 0922382..0000000
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/exceptions/package-info.java
+++ /dev/null
@@ -1,18 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership.  The ASF
- * licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.apache.hadoop.ozone.scm.exceptions;
-// Exceptions thrown by SCM.
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/hadoop/blob/ce23d9ad/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/CommandQueue.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/CommandQueue.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/CommandQueue.java
deleted file mode 100644
index bbf319b..0000000
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/CommandQueue.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.hadoop.ozone.scm.node;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
-import org.apache.hadoop.hdfs.protocol.DatanodeID;
-import org.apache.hadoop.ozone.protocol.commands.SCMCommand;
-import org.apache.hadoop.util.Time;
-
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-
-/**
- * Command Queue is queue of commands for the datanode.
- * <p>
- * Node manager, container Manager and key space managers can queue commands for
- * datanodes into this queue. These commands will be send in the order in which
- * there where queued.
- */
-public class CommandQueue {
-  // This list is used as default return value.
-  private static final List<SCMCommand> DEFAULT_LIST = new LinkedList<>();
-  private final Map<DatanodeID, Commands> commandMap;
-  private final Lock lock;
-  private long commandsInQueue;
-
-  /**
-   * Returns number of commands in queue.
-   * @return Command Count.
-   */
-  public long getCommandsInQueue() {
-    return commandsInQueue;
-  }
-
-  /**
-   * Constructs a Command Queue.
-   * TODO : Add a flusher thread that throws away commands older than a certain
-   * time period.
-   */
-  public CommandQueue() {
-    commandMap = new HashMap<>();
-    lock = new ReentrantLock();
-    commandsInQueue = 0;
-  }
-
-  /**
-   * This function is used only for test purposes.
-   */
-  @VisibleForTesting
-  public void clear() {
-    lock.lock();
-    try {
-      commandMap.clear();
-      commandsInQueue = 0;
-    } finally {
-      lock.unlock();
-    }
-  }
-
-  /**
-   * Returns  a list of Commands for the datanode to execute, if we have no
-   * commands returns a empty list otherwise the current set of
-   * commands are returned and command map set to empty list again.
-   *
-   * @param datanodeID DatanodeID
-   * @return List of SCM Commands.
-   */
-  @SuppressWarnings("unchecked")
-  List<SCMCommand> getCommand(final DatanodeID datanodeID) {
-    lock.lock();
-    try {
-      Commands cmds = commandMap.remove(datanodeID);
-      List<SCMCommand> cmdList = null;
-      if(cmds != null) {
-        cmdList = cmds.getCommands();
-        commandsInQueue -= cmdList.size() > 0 ? cmdList.size() : 0;
-        // A post condition really.
-        Preconditions.checkState(commandsInQueue >= 0);
-      }
-      return cmds == null ? DEFAULT_LIST : cmdList;
-    } finally {
-      lock.unlock();
-    }
-  }
-
-  /**
-   * Adds a Command to the SCM Queue to send the command to container.
-   *
-   * @param datanodeID DatanodeID
-   * @param command    - Command
-   */
-  public void addCommand(final DatanodeID datanodeID, final SCMCommand
-      command) {
-    lock.lock();
-    try {
-      if (commandMap.containsKey(datanodeID)) {
-        commandMap.get(datanodeID).add(command);
-      } else {
-        commandMap.put(datanodeID, new Commands(command));
-      }
-      commandsInQueue++;
-    } finally {
-      lock.unlock();
-    }
-  }
-
-  /**
-   * Class that stores commands for a datanode.
-   */
-  private static class Commands {
-    private long updateTime;
-    private long readTime;
-    private List<SCMCommand> commands;
-
-    /**
-     * Constructs a Commands class.
-     */
-    Commands() {
-      commands = new LinkedList<>();
-      updateTime = 0;
-      readTime = 0;
-    }
-
-    /**
-     * Creates the object and populates with the command.
-     * @param command command to add to queue.
-     */
-    Commands(SCMCommand command) {
-      this();
-      this.add(command);
-    }
-
-    /**
-     * Gets the last time the commands for this node was updated.
-     * @return Time stamp
-     */
-    public long getUpdateTime() {
-      return updateTime;
-    }
-
-    /**
-     * Gets the last read time.
-     * @return last time when these commands were read from this queue.
-     */
-    public long getReadTime() {
-      return readTime;
-    }
-
-    /**
-     * Adds a command to the list.
-     *
-     * @param command SCMCommand
-     */
-    public void add(SCMCommand command) {
-      this.commands.add(command);
-      updateTime = Time.monotonicNow();
-    }
-
-    /**
-     * Returns the commands for this datanode.
-     * @return command list.
-     */
-    public List<SCMCommand> getCommands() {
-      List<SCMCommand> temp = this.commands;
-      this.commands = new LinkedList<>();
-      readTime = Time.monotonicNow();
-      return temp;
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/hadoop/blob/ce23d9ad/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/HeartbeatQueueItem.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/HeartbeatQueueItem.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/HeartbeatQueueItem.java
deleted file mode 100644
index 1e755b2..0000000
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/HeartbeatQueueItem.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hadoop.ozone.scm.node;
-
-import com.google.common.annotations.VisibleForTesting;
-import org.apache.hadoop.hdfs.protocol.DatanodeID;
-import org.apache.hadoop.ozone.protocol.proto.StorageContainerDatanodeProtocolProtos.ReportState;
-import org.apache.hadoop.ozone.protocol.proto
-    .StorageContainerDatanodeProtocolProtos.SCMNodeReport;
-
-import static org.apache.hadoop.util.Time.monotonicNow;
-
-/**
- * This class represents the item in SCM heartbeat queue.
- */
-public class HeartbeatQueueItem {
-  private DatanodeID datanodeID;
-  private long recvTimestamp;
-  private SCMNodeReport nodeReport;
-  private ReportState containerReportState;
-
-  /**
-   *
-   * @param datanodeID - datanode ID of the heartbeat.
-   * @param recvTimestamp - heartbeat receive timestamp.
-   * @param nodeReport - node report associated with the heartbeat if any.
-   * @param containerReportState - container report state.
-   */
-  HeartbeatQueueItem(DatanodeID datanodeID, long recvTimestamp,
-      SCMNodeReport nodeReport, ReportState containerReportState) {
-    this.datanodeID = datanodeID;
-    this.recvTimestamp = recvTimestamp;
-    this.nodeReport = nodeReport;
-    this.containerReportState = containerReportState;
-  }
-
-  /**
-   * @return datanode ID.
-   */
-  public DatanodeID getDatanodeID() {
-    return datanodeID;
-  }
-
-  /**
-   * @return node report.
-   */
-  public SCMNodeReport getNodeReport() {
-    return nodeReport;
-  }
-
-  /**
-   * @return container report state.
-   */
-  public ReportState getContainerReportState() {
-    return containerReportState;
-  }
-
-  /**
-   * @return heartbeat receive timestamp.
-   */
-  public long getRecvTimestamp() {
-    return recvTimestamp;
-  }
-
-  /**
-   * Builder for HeartbeatQueueItem.
-   */
-  public static class Builder {
-    private DatanodeID datanodeID;
-    private SCMNodeReport nodeReport;
-    private ReportState containerReportState;
-    private long recvTimestamp = monotonicNow();
-
-    public Builder setDatanodeID(DatanodeID datanodeId) {
-      this.datanodeID = datanodeId;
-      return this;
-    }
-
-    public Builder setNodeReport(SCMNodeReport scmNodeReport) {
-      this.nodeReport = scmNodeReport;
-      return this;
-    }
-
-    public Builder setContainerReportState(ReportState crs) {
-      this.containerReportState = crs;
-      return this;
-    }
-
-    @VisibleForTesting
-    public Builder setRecvTimestamp(long recvTime) {
-      this.recvTimestamp = recvTime;
-      return this;
-    }
-
-    public HeartbeatQueueItem build() {
-      return new HeartbeatQueueItem(datanodeID, recvTimestamp, nodeReport,
-          containerReportState);
-    }
-  }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/hadoop/blob/ce23d9ad/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/NodeManager.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/NodeManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/NodeManager.java
deleted file mode 100644
index 77b3bff..0000000
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/NodeManager.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.hadoop.ozone.scm.node;
-
-import com.google.common.annotations.VisibleForTesting;
-import org.apache.hadoop.hdfs.protocol.DatanodeID;
-import org.apache.hadoop.hdfs.protocol.UnregisteredNodeException;
-import org.apache.hadoop.ozone.protocol.StorageContainerNodeProtocol;
-import org.apache.hadoop.ozone.protocol.commands.SCMCommand;
-import org.apache.hadoop.ozone.protocol.proto.OzoneProtos.NodeState;
-import org.apache.hadoop.ozone.scm.container.placement.metrics.SCMNodeMetric;
-import org.apache.hadoop.ozone.scm.container.placement.metrics.SCMNodeStat;
-
-import java.io.Closeable;
-import java.util.List;
-import java.util.Map;
-
-/**
- * A node manager supports a simple interface for managing a datanode.
- * <p/>
- * 1. A datanode registers with the NodeManager.
- * <p/>
- * 2. If the node is allowed to register, we add that to the nodes that we need
- * to keep track of.
- * <p/>
- * 3. A heartbeat is made by the node at a fixed frequency.
- * <p/>
- * 4. A node can be in any of these 4 states: {HEALTHY, STALE, DEAD,
- * DECOMMISSIONED}
- * <p/>
- * HEALTHY - It is a datanode that is regularly heartbeating us.
- *
- * STALE - A datanode for which we have missed few heart beats.
- *
- * DEAD - A datanode that we have not heard from for a while.
- *
- * DECOMMISSIONED - Someone told us to remove this node from the tracking
- * list, by calling removeNode. We will throw away this nodes info soon.
- */
-public interface NodeManager extends StorageContainerNodeProtocol,
-    NodeManagerMXBean, Closeable, Runnable {
-  /**
-   * Removes a data node from the management of this Node Manager.
-   *
-   * @param node - DataNode.
-   * @throws UnregisteredNodeException
-   */
-  void removeNode(DatanodeID node) throws UnregisteredNodeException;
-
-  /**
-   * Gets all Live Datanodes that is currently communicating with SCM.
-   * @param nodeState - State of the node
-   * @return List of Datanodes that are Heartbeating SCM.
-   */
-  List<DatanodeID> getNodes(NodeState nodeState);
-
-  /**
-   * Returns the Number of Datanodes that are communicating with SCM.
-   * @param nodeState - State of the node
-   * @return int -- count
-   */
-  int getNodeCount(NodeState nodeState);
-
-  /**
-   * Get all datanodes known to SCM.
-   *
-   * @return List of DatanodeIDs known to SCM.
-   */
-  List<DatanodeID> getAllNodes();
-
-  /**
-   * Chill mode is the period when node manager waits for a minimum
-   * configured number of datanodes to report in. This is called chill mode
-   * to indicate the period before node manager gets into action.
-   *
-   * Forcefully exits the chill mode, even if we have not met the minimum
-   * criteria of the nodes reporting in.
-   */
-  void forceExitChillMode();
-
-  /**
-   * Puts the node manager into manual chill mode.
-   */
-  void enterChillMode();
-
-  /**
-   * Brings node manager out of manual chill mode.
-   */
-  void exitChillMode();
-
-  /**
-   * Returns the aggregated node stats.
-   * @return the aggregated node stats.
-   */
-  SCMNodeStat getStats();
-
-  /**
-   * Return a map of node stats.
-   * @return a map of individual node stats (live/stale but not dead).
-   */
-  Map<String, SCMNodeStat> getNodeStats();
-
-  /**
-   * Return the node stat of the specified datanode.
-   * @param datanodeID - datanode ID.
-   * @return node stat if it is live/stale, null if it is dead or does't exist.
-   */
-  SCMNodeMetric getNodeStat(DatanodeID datanodeID);
-
-  /**
-   * Returns the NodePoolManager associated with the NodeManager.
-   * @return NodePoolManager
-   */
-  NodePoolManager getNodePoolManager();
-
-  /**
-   * Wait for the heartbeat is processed by NodeManager.
-   * @return true if heartbeat has been processed.
-   */
-  @VisibleForTesting
-  boolean waitForHeartbeatProcessed();
-
-  /**
-   * Returns the node state of a specific node.
-   * @param id - DatanodeID
-   * @return Healthy/Stale/Dead.
-   */
-  NodeState getNodeState(DatanodeID id);
-
-  /**
-   * Add a {@link SCMCommand} to the command queue, which are
-   * handled by HB thread asynchronously.
-   * @param id
-   * @param command
-   */
-  void addDatanodeCommand(DatanodeID id, SCMCommand command);
-}

http://git-wip-us.apache.org/repos/asf/hadoop/blob/ce23d9ad/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/NodeManagerMXBean.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/NodeManagerMXBean.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/NodeManagerMXBean.java
deleted file mode 100644
index 46881c9..0000000
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/NodeManagerMXBean.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hadoop.ozone.scm.node;
-
-import org.apache.hadoop.classification.InterfaceAudience;
-
-import java.util.Map;
-
-/**
- *
- * This is the JMX management interface for node manager information.
- */
-@InterfaceAudience.Private
-public interface NodeManagerMXBean {
-  /**
-   * Get the minimum number of nodes to get out of chill mode.
-   *
-   * @return int
-   */
-  int getMinimumChillModeNodes();
-
-  /**
-   * Returns a chill mode status string.
-   * @return String
-   */
-  String getChillModeStatus();
-
-
-  /**
-   * Returns true if node manager is out of chill mode, else false.
-   * @return true if out of chill mode, else false
-   */
-  boolean isOutOfChillMode();
-
-  /**
-   * Get the number of data nodes that in all states.
-   *
-   * @return A state to number of nodes that in this state mapping
-   */
-  Map<String, Integer> getNodeCount();
-}

http://git-wip-us.apache.org/repos/asf/hadoop/blob/ce23d9ad/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/NodePoolManager.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/NodePoolManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/NodePoolManager.java
deleted file mode 100644
index d3218b7..0000000
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/NodePoolManager.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hadoop.ozone.scm.node;
-
-
-import org.apache.hadoop.hdfs.protocol.DatanodeID;
-import org.apache.hadoop.ozone.scm.exceptions.SCMException;
-
-import java.io.Closeable;
-import java.io.IOException;
-import java.util.List;
-
-/**
- * Interface that defines SCM NodePoolManager.
- */
-public interface NodePoolManager extends Closeable {
-
-  /**
-   * Add a node to a node pool.
-   * @param pool - name of the node pool.
-   * @param node - data node.
-   */
-  void addNode(String pool, DatanodeID node) throws IOException;
-
-  /**
-   * Remove a node from a node pool.
-   * @param pool - name of the node pool.
-   * @param node - data node.
-   * @throws SCMException
-   */
-  void removeNode(String pool, DatanodeID node)
-      throws SCMException;
-
-  /**
-   * Get a list of known node pools.
-   * @return a list of known node pool names or an empty list if not node pool
-   * is defined.
-   */
-  List<String> getNodePools();
-
-  /**
-   * Get all nodes of a node pool given the name of the node pool.
-   * @param pool - name of the node pool.
-   * @return a list of datanode ids or an empty list if the node pool was not
-   *  found.
-   */
-  List<DatanodeID> getNodes(String pool);
-
-  /**
-   * Get the node pool name if the node has been added to a node pool.
-   * @param datanodeID - datanode ID.
-   * @return node pool name if it has been assigned.
-   * null if the node has not been assigned to any node pool yet.
-   */
-  String getNodePool(DatanodeID datanodeID) throws SCMException;
-}

http://git-wip-us.apache.org/repos/asf/hadoop/blob/ce23d9ad/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/SCMNodeManager.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/SCMNodeManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/SCMNodeManager.java
deleted file mode 100644
index 129e65d..0000000
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/SCMNodeManager.java
+++ /dev/null
@@ -1,883 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.hadoop.ozone.scm.node;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.ThreadFactoryBuilder;
-import org.apache.hadoop.hdfs.protocol.DatanodeID;
-import org.apache.hadoop.hdfs.protocol.UnregisteredNodeException;
-import org.apache.hadoop.metrics2.util.MBeans;
-import org.apache.hadoop.ozone.client.OzoneClientUtils;
-import org.apache.hadoop.conf.OzoneConfiguration;
-import org.apache.hadoop.ozone.protocol.StorageContainerNodeProtocol;
-import org.apache.hadoop.ozone.protocol.VersionResponse;
-import org.apache.hadoop.ozone.protocol.commands.ReregisterCommand;
-import org.apache.hadoop.ozone.protocol.commands.RegisteredCommand;
-import org.apache.hadoop.ozone.protocol.commands.SCMCommand;
-import org.apache.hadoop.ozone.protocol.commands.SendContainerCommand;
-import org.apache.hadoop.ozone.protocol.proto.OzoneProtos.NodeState;
-import org.apache.hadoop.ozone.protocol.proto
-    .StorageContainerDatanodeProtocolProtos.ReportState;
-import org.apache.hadoop.ozone.protocol.proto
-    .StorageContainerDatanodeProtocolProtos.SCMRegisteredCmdResponseProto
-    .ErrorCode;
-import org.apache.hadoop.ozone.protocol.proto
-    .StorageContainerDatanodeProtocolProtos.SCMVersionRequestProto;
-import org.apache.hadoop.ozone.protocol
-    .proto.StorageContainerDatanodeProtocolProtos.SCMNodeReport;
-import org.apache.hadoop.ozone.protocol
-    .proto.StorageContainerDatanodeProtocolProtos.SCMStorageReport;
-import org.apache.hadoop.ozone.scm.StorageContainerManager;
-import org.apache.hadoop.ozone.scm.VersionInfo;
-import org.apache.hadoop.ozone.scm.container.placement.metrics.SCMNodeMetric;
-import org.apache.hadoop.ozone.scm.container.placement.metrics.SCMNodeStat;
-import org.apache.hadoop.util.Time;
-import org.apache.hadoop.util.concurrent.HadoopExecutors;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.management.ObjectName;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Queue;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.stream.Collectors;
-
-import static org.apache.hadoop.ozone.protocol.proto.OzoneProtos.NodeState.DEAD;
-import static org.apache.hadoop.ozone.protocol.proto.OzoneProtos.NodeState.HEALTHY;
-import static org.apache.hadoop.ozone.protocol.proto.OzoneProtos.NodeState.STALE;
-import static org.apache.hadoop.ozone.protocol.proto.OzoneProtos.NodeState.UNKNOWN;
-import static org.apache.hadoop.util.Time.monotonicNow;
-
-/**
- * Maintains information about the Datanodes on SCM side.
- * <p>
- * Heartbeats under SCM is very simple compared to HDFS heartbeatManager.
- * <p>
- * Here we maintain 3 maps, and we propagate a node from healthyNodesMap to
- * staleNodesMap to deadNodesMap. This moving of a node from one map to another
- * is controlled by 4 configuration variables. These variables define how many
- * heartbeats must go missing for the node to move from one map to another.
- * <p>
- * Each heartbeat that SCMNodeManager receives is  put into heartbeatQueue. The
- * worker thread wakes up and grabs that heartbeat from the queue. The worker
- * thread will lookup the healthynodes map and set the timestamp if the entry
- * is there. if not it will look up stale and deadnodes map.
- * <p>
- * The getNode(byState) functions make copy of node maps and then creates a list
- * based on that. It should be assumed that these get functions always report
- * *stale* information. For example, getting the deadNodeCount followed by
- * getNodes(DEAD) could very well produce totally different count. Also
- * getNodeCount(HEALTHY) + getNodeCount(DEAD) + getNodeCode(STALE), is not
- * guaranteed to add up to the total nodes that we know off. Please treat all
- * get functions in this file as a snap-shot of information that is inconsistent
- * as soon as you read it.
- */
-public class SCMNodeManager
-    implements NodeManager, StorageContainerNodeProtocol {
-
-  @VisibleForTesting
-  static final Logger LOG =
-      LoggerFactory.getLogger(SCMNodeManager.class);
-
-  /**
-   * Key = NodeID, value = timestamp.
-   */
-  private final ConcurrentHashMap<String, Long> healthyNodes;
-  private final ConcurrentHashMap<String, Long> staleNodes;
-  private final ConcurrentHashMap<String, Long> deadNodes;
-  private final Queue<HeartbeatQueueItem> heartbeatQueue;
-  private final ConcurrentHashMap<String, DatanodeID> nodes;
-  // Individual live node stats
-  private final ConcurrentHashMap<String, SCMNodeStat> nodeStats;
-  // Aggregated node stats
-  private SCMNodeStat scmStat;
-  // TODO: expose nodeStats and scmStat as metrics
-  private final AtomicInteger healthyNodeCount;
-  private final AtomicInteger staleNodeCount;
-  private final AtomicInteger deadNodeCount;
-  private final AtomicInteger totalNodes;
-  private long staleNodeIntervalMs;
-  private final long deadNodeIntervalMs;
-  private final long heartbeatCheckerIntervalMs;
-  private final long datanodeHBIntervalSeconds;
-  private final ScheduledExecutorService executorService;
-  private long lastHBcheckStart;
-  private long lastHBcheckFinished = 0;
-  private long lastHBProcessedCount;
-  private int chillModeNodeCount;
-  private final int maxHBToProcessPerLoop;
-  private final String clusterID;
-  private final VersionInfo version;
-  /**
-   * During start up of SCM, it will enter into chill mode and will be there
-   * until number of Datanodes registered reaches {@code chillModeNodeCount}.
-   * This flag is for tracking startup chill mode.
-   */
-  private AtomicBoolean inStartupChillMode;
-  /**
-   * Administrator can put SCM into chill mode manually.
-   * This flag is for tracking manual chill mode.
-   */
-  private AtomicBoolean inManualChillMode;
-  private final CommandQueue commandQueue;
-  // Node manager MXBean
-  private ObjectName nmInfoBean;
-
-  // Node pool manager.
-  private final SCMNodePoolManager nodePoolManager;
-  private final StorageContainerManager scmManager;
-
-  /**
-   * Constructs SCM machine Manager.
-   */
-  public SCMNodeManager(OzoneConfiguration conf, String clusterID,
-      StorageContainerManager scmManager) throws IOException {
-    heartbeatQueue = new ConcurrentLinkedQueue<>();
-    healthyNodes = new ConcurrentHashMap<>();
-    deadNodes = new ConcurrentHashMap<>();
-    staleNodes = new ConcurrentHashMap<>();
-    nodes = new ConcurrentHashMap<>();
-    nodeStats = new ConcurrentHashMap();
-    scmStat = new SCMNodeStat();
-
-    healthyNodeCount = new AtomicInteger(0);
-    staleNodeCount = new AtomicInteger(0);
-    deadNodeCount = new AtomicInteger(0);
-    totalNodes = new AtomicInteger(0);
-    this.clusterID = clusterID;
-    this.version = VersionInfo.getLatestVersion();
-    commandQueue = new CommandQueue();
-
-    // TODO: Support this value as a Percentage of known machines.
-    chillModeNodeCount = 1;
-
-    staleNodeIntervalMs = OzoneClientUtils.getStaleNodeInterval(conf);
-    deadNodeIntervalMs = OzoneClientUtils.getDeadNodeInterval(conf);
-    heartbeatCheckerIntervalMs =
-        OzoneClientUtils.getScmheartbeatCheckerInterval(conf);
-    datanodeHBIntervalSeconds = OzoneClientUtils.getScmHeartbeatInterval(conf);
-    maxHBToProcessPerLoop = OzoneClientUtils.getMaxHBToProcessPerLoop(conf);
-
-    executorService = HadoopExecutors.newScheduledThreadPool(1,
-        new ThreadFactoryBuilder().setDaemon(true)
-            .setNameFormat("SCM Heartbeat Processing Thread - %d").build());
-
-    LOG.info("Entering startup chill mode.");
-    this.inStartupChillMode = new AtomicBoolean(true);
-    this.inManualChillMode = new AtomicBoolean(false);
-
-    Preconditions.checkState(heartbeatCheckerIntervalMs > 0);
-    executorService.schedule(this, heartbeatCheckerIntervalMs,
-        TimeUnit.MILLISECONDS);
-
-    registerMXBean();
-
-    this.nodePoolManager = new SCMNodePoolManager(conf);
-    this.scmManager = scmManager;
-  }
-
-  private void registerMXBean() {
-    this.nmInfoBean = MBeans.register("SCMNodeManager",
-        "SCMNodeManagerInfo", this);
-  }
-
-  private void unregisterMXBean() {
-    if(this.nmInfoBean != null) {
-      MBeans.unregister(this.nmInfoBean);
-      this.nmInfoBean = null;
-    }
-  }
-
-  /**
-   * Removes a data node from the management of this Node Manager.
-   *
-   * @param node - DataNode.
-   * @throws UnregisteredNodeException
-   */
-  @Override
-  public void removeNode(DatanodeID node) throws UnregisteredNodeException {
-    // TODO : Fix me when adding the SCM CLI.
-
-  }
-
-  /**
-   * Gets all datanodes that are in a certain state. This function works by
-   * taking a snapshot of the current collection and then returning the list
-   * from that collection. This means that real map might have changed by the
-   * time we return this list.
-   *
-   * @return List of Datanodes that are known to SCM in the requested state.
-   */
-  @Override
-  public List<DatanodeID> getNodes(NodeState nodestate)
-      throws IllegalArgumentException {
-    Map<String, Long> set;
-    switch (nodestate) {
-    case HEALTHY:
-      synchronized (this) {
-        set = Collections.unmodifiableMap(new HashMap<>(healthyNodes));
-      }
-      break;
-    case STALE:
-      synchronized (this) {
-        set = Collections.unmodifiableMap(new HashMap<>(staleNodes));
-      }
-      break;
-    case DEAD:
-      synchronized (this) {
-        set = Collections.unmodifiableMap(new HashMap<>(deadNodes));
-      }
-      break;
-    default:
-      throw new IllegalArgumentException("Unknown node state requested.");
-    }
-
-    return set.entrySet().stream().map(entry -> nodes.get(entry.getKey()))
-        .collect(Collectors.toList());
-  }
-
-  /**
-   * Returns all datanodes that are known to SCM.
-   *
-   * @return List of DatanodeIDs
-   */
-  @Override
-  public List<DatanodeID> getAllNodes() {
-    Map<String, DatanodeID> set;
-    synchronized (this) {
-      set = Collections.unmodifiableMap(new HashMap<>(nodes));
-    }
-    return set.entrySet().stream().map(entry -> nodes.get(entry.getKey()))
-        .collect(Collectors.toList());
-  }
-
-  /**
-   * Get the minimum number of nodes to get out of Chill mode.
-   *
-   * @return int
-   */
-  @Override
-  public int getMinimumChillModeNodes() {
-    return chillModeNodeCount;
-  }
-
-  /**
-   * Sets the Minimum chill mode nodes count, used only in testing.
-   *
-   * @param count - Number of nodes.
-   */
-  @VisibleForTesting
-  public void setMinimumChillModeNodes(int count) {
-    chillModeNodeCount = count;
-  }
-
-  /**
-   * Returns chill mode Status string.
-   * @return String
-   */
-  @Override
-  public String getChillModeStatus() {
-    if (inStartupChillMode.get()) {
-      return "Still in chill mode, waiting on nodes to report in." +
-          String.format(" %d nodes reported, minimal %d nodes required.",
-              totalNodes.get(), getMinimumChillModeNodes());
-    }
-    if (inManualChillMode.get()) {
-      return "Out of startup chill mode, but in manual chill mode." +
-          String.format(" %d nodes have reported in.", totalNodes.get());
-    }
-    return "Out of chill mode." +
-        String.format(" %d nodes have reported in.", totalNodes.get());
-  }
-
-  /**
-   * Forcefully exits the chill mode even if we have not met the minimum
-   * criteria of exiting the chill mode. This will exit from both startup
-   * and manual chill mode.
-   */
-  @Override
-  public void forceExitChillMode() {
-    if(inStartupChillMode.get()) {
-      LOG.info("Leaving startup chill mode.");
-      inStartupChillMode.set(false);
-    }
-    if(inManualChillMode.get()) {
-      LOG.info("Leaving manual chill mode.");
-      inManualChillMode.set(false);
-    }
-  }
-
-  /**
-   * Puts the node manager into manual chill mode.
-   */
-  @Override
-  public void enterChillMode() {
-    LOG.info("Entering manual chill mode.");
-    inManualChillMode.set(true);
-  }
-
-  /**
-   * Brings node manager out of manual chill mode.
-   */
-  @Override
-  public void exitChillMode() {
-    LOG.info("Leaving manual chill mode.");
-    inManualChillMode.set(false);
-  }
-
-  /**
-   * Returns true if node manager is out of chill mode, else false.
-   * @return true if out of chill mode, else false
-   */
-  @Override
-  public boolean isOutOfChillMode() {
-    return !(inStartupChillMode.get() || inManualChillMode.get());
-  }
-
-  /**
-   * Returns the Number of Datanodes by State they are in.
-   *
-   * @return int -- count
-   */
-  @Override
-  public int getNodeCount(NodeState nodestate) {
-    switch (nodestate) {
-    case HEALTHY:
-      return healthyNodeCount.get();
-    case STALE:
-      return staleNodeCount.get();
-    case DEAD:
-      return deadNodeCount.get();
-    case UNKNOWN:
-      // This is unknown due to the fact that some nodes can be in
-      // transit between the other states. Returning a count for that is not
-      // possible. The fact that we have such state is to deal with the fact
-      // that this information might not be consistent always.
-      return 0;
-    default:
-      return 0;
-    }
-  }
-
-  /**
-   * Used for testing.
-   *
-   * @return true if the HB check is done.
-   */
-  @VisibleForTesting
-  @Override
-  public boolean waitForHeartbeatProcessed() {
-    return lastHBcheckFinished != 0;
-  }
-
-  /**
-   * Returns the node state of a specific node.
-   *
-   * @param id - DatanodeID
-   * @return Healthy/Stale/Dead/Unknown.
-   */
-  @Override
-  public NodeState getNodeState(DatanodeID id) {
-    // There is a subtle race condition here, hence we also support
-    // the NODEState.UNKNOWN. It is possible that just before we check the
-    // healthyNodes, we have removed the node from the healthy list but stil
-    // not added it to Stale Nodes list.
-    // We can fix that by adding the node to stale list before we remove, but
-    // then the node is in 2 states to avoid this race condition. Instead we
-    // just deal with the possibilty of getting a state called unknown.
-
-    if(healthyNodes.containsKey(id.getDatanodeUuid())) {
-      return HEALTHY;
-    }
-
-    if(staleNodes.containsKey(id.getDatanodeUuid())) {
-      return STALE;
-    }
-
-    if(deadNodes.containsKey(id.getDatanodeUuid())) {
-      return DEAD;
-    }
-
-    return UNKNOWN;
-  }
-
-  /**
-   * This is the real worker thread that processes the HB queue. We do the
-   * following things in this thread.
-   * <p>
-   * Process the Heartbeats that are in the HB Queue. Move Stale or Dead node to
-   * healthy if we got a heartbeat from them. Move Stales Node to dead node
-   * table if it is needed. Move healthy nodes to stale nodes if it is needed.
-   * <p>
-   * if it is a new node, we call register node and add it to the list of nodes.
-   * This will be replaced when we support registration of a node in SCM.
-   *
-   * @see Thread#run()
-   */
-  @Override
-  public void run() {
-    lastHBcheckStart = monotonicNow();
-    lastHBProcessedCount = 0;
-
-    // Process the whole queue.
-    while (!heartbeatQueue.isEmpty() &&
-        (lastHBProcessedCount < maxHBToProcessPerLoop)) {
-      HeartbeatQueueItem hbItem = heartbeatQueue.poll();
-      synchronized (this) {
-        handleHeartbeat(hbItem);
-      }
-      // we are shutting down or something give up processing the rest of
-      // HBs. This will terminate the HB processing thread.
-      if (Thread.currentThread().isInterrupted()) {
-        LOG.info("Current Thread is isInterrupted, shutting down HB " +
-            "processing thread for Node Manager.");
-        return;
-      }
-    }
-
-    if (lastHBProcessedCount >= maxHBToProcessPerLoop) {
-      LOG.error("SCM is being flooded by heartbeats. Not able to keep up with" +
-          " the heartbeat counts. Processed {} heartbeats. Breaking out of" +
-          " loop. Leaving rest to be processed later. ", lastHBProcessedCount);
-    }
-
-    // Iterate over the Stale nodes and decide if we need to move any node to
-    // dead State.
-    long currentTime = monotonicNow();
-    for (Map.Entry<String, Long> entry : staleNodes.entrySet()) {
-      if (currentTime - entry.getValue() > deadNodeIntervalMs) {
-        synchronized (this) {
-          moveStaleNodeToDead(entry);
-        }
-      }
-    }
-
-    // Iterate over the healthy nodes and decide if we need to move any node to
-    // Stale State.
-    currentTime = monotonicNow();
-    for (Map.Entry<String, Long> entry : healthyNodes.entrySet()) {
-      if (currentTime - entry.getValue() > staleNodeIntervalMs) {
-        synchronized (this) {
-          moveHealthyNodeToStale(entry);
-        }
-      }
-    }
-    lastHBcheckFinished = monotonicNow();
-
-    monitorHBProcessingTime();
-
-    // we purposefully make this non-deterministic. Instead of using a
-    // scheduleAtFixedFrequency  we will just go to sleep
-    // and wake up at the next rendezvous point, which is currentTime +
-    // heartbeatCheckerIntervalMs. This leads to the issue that we are now
-    // heart beating not at a fixed cadence, but clock tick + time taken to
-    // work.
-    //
-    // This time taken to work can skew the heartbeat processor thread.
-    // The reason why we don't care is because of the following reasons.
-    //
-    // 1. checkerInterval is general many magnitudes faster than datanode HB
-    // frequency.
-    //
-    // 2. if we have too much nodes, the SCM would be doing only HB
-    // processing, this could lead to SCM's CPU starvation. With this
-    // approach we always guarantee that  HB thread sleeps for a little while.
-    //
-    // 3. It is possible that we will never finish processing the HB's in the
-    // thread. But that means we have a mis-configured system. We will warn
-    // the users by logging that information.
-    //
-    // 4. And the most important reason, heartbeats are not blocked even if
-    // this thread does not run, they will go into the processing queue.
-
-    if (!Thread.currentThread().isInterrupted() &&
-        !executorService.isShutdown()) {
-      executorService.schedule(this, heartbeatCheckerIntervalMs, TimeUnit
-          .MILLISECONDS);
-    } else {
-      LOG.info("Current Thread is interrupted, shutting down HB processing " +
-          "thread for Node Manager.");
-    }
-  }
-
-  /**
-   * If we have taken too much time for HB processing, log that information.
-   */
-  private void monitorHBProcessingTime() {
-    if (TimeUnit.MILLISECONDS.toSeconds(lastHBcheckFinished -
-        lastHBcheckStart) > datanodeHBIntervalSeconds) {
-      LOG.error("Total time spend processing datanode HB's is greater than " +
-              "configured values for datanode heartbeats. Please adjust the" +
-              " heartbeat configs. Time Spend on HB processing: {} seconds " +
-              "Datanode heartbeat Interval: {} seconds , heartbeats " +
-              "processed: {}",
-          TimeUnit.MILLISECONDS
-              .toSeconds(lastHBcheckFinished - lastHBcheckStart),
-          datanodeHBIntervalSeconds, lastHBProcessedCount);
-    }
-  }
-
-  /**
-   * Moves a Healthy node to a Stale node state.
-   *
-   * @param entry - Map Entry
-   */
-  private void moveHealthyNodeToStale(Map.Entry<String, Long> entry) {
-    LOG.trace("Moving healthy node to stale: {}", entry.getKey());
-    healthyNodes.remove(entry.getKey());
-    healthyNodeCount.decrementAndGet();
-    staleNodes.put(entry.getKey(), entry.getValue());
-    staleNodeCount.incrementAndGet();
-
-    if (scmManager != null) {
-      // remove stale node's container report
-      scmManager.removeContainerReport(entry.getKey());
-    }
-  }
-
-  /**
-   * Moves a Stale node to a dead node state.
-   *
-   * @param entry - Map Entry
-   */
-  private void moveStaleNodeToDead(Map.Entry<String, Long> entry) {
-    LOG.trace("Moving stale node to dead: {}", entry.getKey());
-    staleNodes.remove(entry.getKey());
-    staleNodeCount.decrementAndGet();
-    deadNodes.put(entry.getKey(), entry.getValue());
-    deadNodeCount.incrementAndGet();
-
-    // Update SCM node stats
-    SCMNodeStat deadNodeStat = nodeStats.get(entry.getKey());
-    scmStat.subtract(deadNodeStat);
-    nodeStats.remove(entry.getKey());
-  }
-
-  /**
-   * Handles a single heartbeat from a datanode.
-   *
-   * @param hbItem - heartbeat item from a datanode.
-   */
-  private void handleHeartbeat(HeartbeatQueueItem hbItem) {
-    lastHBProcessedCount++;
-
-    DatanodeID datanodeID = hbItem.getDatanodeID();
-    String datanodeUuid = datanodeID.getDatanodeUuid();
-    SCMNodeReport nodeReport = hbItem.getNodeReport();
-    long recvTimestamp = hbItem.getRecvTimestamp();
-    long processTimestamp = Time.monotonicNow();
-    if (LOG.isTraceEnabled()) {
-      //TODO: add average queue time of heartbeat request as metrics
-      LOG.trace("Processing Heartbeat from datanode {}: queueing time {}",
-          datanodeUuid, processTimestamp - recvTimestamp);
-    }
-
-    // If this node is already in the list of known and healthy nodes
-    // just set the last timestamp and return.
-    if (healthyNodes.containsKey(datanodeUuid)) {
-      healthyNodes.put(datanodeUuid, processTimestamp);
-      updateNodeStat(datanodeUuid, nodeReport);
-      updateCommandQueue(datanodeID,
-          hbItem.getContainerReportState().getState());
-      return;
-    }
-
-    // A stale node has heartbeat us we need to remove the node from stale
-    // list and move to healthy list.
-    if (staleNodes.containsKey(datanodeUuid)) {
-      staleNodes.remove(datanodeUuid);
-      healthyNodes.put(datanodeUuid, processTimestamp);
-      healthyNodeCount.incrementAndGet();
-      staleNodeCount.decrementAndGet();
-      updateNodeStat(datanodeUuid, nodeReport);
-      updateCommandQueue(datanodeID,
-          hbItem.getContainerReportState().getState());
-      return;
-    }
-
-    // A dead node has heartbeat us, we need to remove that node from dead
-    // node list and move it to the healthy list.
-    if (deadNodes.containsKey(datanodeUuid)) {
-      deadNodes.remove(datanodeUuid);
-      healthyNodes.put(datanodeUuid, processTimestamp);
-      deadNodeCount.decrementAndGet();
-      healthyNodeCount.incrementAndGet();
-      updateNodeStat(datanodeUuid, nodeReport);
-      updateCommandQueue(datanodeID,
-          hbItem.getContainerReportState().getState());
-      return;
-    }
-
-    LOG.warn("SCM receive heartbeat from unregistered datanode {}",
-        datanodeUuid);
-    this.commandQueue.addCommand(hbItem.getDatanodeID(),
-        new ReregisterCommand());
-  }
-
-  private void updateNodeStat(String datanodeUuid, SCMNodeReport nodeReport) {
-    SCMNodeStat stat = nodeStats.get(datanodeUuid);
-    if (stat == null) {
-      LOG.debug("SCM updateNodeStat based on heartbeat from previous" +
-          "dead datanode {}", datanodeUuid);
-      stat = new SCMNodeStat();
-    }
-
-    if (nodeReport != null && nodeReport.getStorageReportCount() > 0) {
-      long totalCapacity = 0;
-      long totalRemaining = 0;
-      long totalScmUsed = 0;
-      List<SCMStorageReport> storageReports = nodeReport.getStorageReportList();
-      for (SCMStorageReport report : storageReports) {
-        totalCapacity += report.getCapacity();
-        totalRemaining +=  report.getRemaining();
-        totalScmUsed+= report.getScmUsed();
-      }
-      scmStat.subtract(stat);
-      stat.set(totalCapacity, totalScmUsed, totalRemaining);
-      nodeStats.put(datanodeUuid, stat);
-      scmStat.add(stat);
-    }
-  }
-
-  private void updateCommandQueue(DatanodeID datanodeID,
-                                  ReportState.states containerReportState) {
-    if (containerReportState != null) {
-      switch (containerReportState) {
-      case completeContinerReport:
-        commandQueue.addCommand(datanodeID,
-            SendContainerCommand.newBuilder().build());
-        return;
-      case deltaContainerReport:
-      case noContainerReports:
-      default:
-        // do nothing
-      }
-    }
-  }
-
-  /**
-   * Closes this stream and releases any system resources associated with it. If
-   * the stream is already closed then invoking this method has no effect.
-   *
-   * @throws IOException if an I/O error occurs
-   */
-  @Override
-  public void close() throws IOException {
-    unregisterMXBean();
-    nodePoolManager.close();
-    executorService.shutdown();
-    try {
-      if (!executorService.awaitTermination(5, TimeUnit.SECONDS)) {
-        executorService.shutdownNow();
-      }
-
-      if (!executorService.awaitTermination(5, TimeUnit.SECONDS)) {
-        LOG.error("Unable to shutdown NodeManager properly.");
-      }
-    } catch (InterruptedException e) {
-      executorService.shutdownNow();
-      Thread.currentThread().interrupt();
-    }
-  }
-
-  @VisibleForTesting
-  long getLastHBProcessedCount() {
-    return lastHBProcessedCount;
-  }
-
-  /**
-   * Gets the version info from SCM.
-   *
-   * @param versionRequest - version Request.
-   * @return - returns SCM version info and other required information needed by
-   * datanode.
-   */
-  @Override
-  public VersionResponse getVersion(SCMVersionRequestProto versionRequest) {
-    return VersionResponse.newBuilder()
-        .setVersion(this.version.getVersion())
-        .build();
-  }
-
-  /**
-   * Register the node if the node finds that it is not registered with any
-   * SCM.
-   *
-   * @param datanodeID - Send datanodeID with Node info. This function
-   *                   generates and assigns new datanode ID for the datanode.
-   *                   This allows SCM to be run independent of Namenode if
-   *                   required.
-   *
-   * @return SCMHeartbeatResponseProto
-   */
-  @Override
-  public SCMCommand register(DatanodeID datanodeID) {
-
-    SCMCommand responseCommand = verifyDatanodeUUID(datanodeID);
-    if (responseCommand != null) {
-      return responseCommand;
-    }
-
-    nodes.put(datanodeID.getDatanodeUuid(), datanodeID);
-    totalNodes.incrementAndGet();
-    healthyNodes.put(datanodeID.getDatanodeUuid(), monotonicNow());
-    healthyNodeCount.incrementAndGet();
-    nodeStats.put(datanodeID.getDatanodeUuid(), new SCMNodeStat());
-
-    if(inStartupChillMode.get() &&
-        totalNodes.get() >= getMinimumChillModeNodes()) {
-      inStartupChillMode.getAndSet(false);
-      LOG.info("Leaving startup chill mode.");
-    }
-
-    // TODO: define node pool policy for non-default node pool.
-    // For now, all nodes are added to the "DefaultNodePool" upon registration
-    // if it has not been added to any node pool yet.
-    try {
-      if (nodePoolManager.getNodePool(datanodeID) == null) {
-        nodePoolManager.addNode(SCMNodePoolManager.DEFAULT_NODEPOOL,
-            datanodeID);
-      }
-    } catch (IOException e) {
-      // TODO: make sure registration failure is handled correctly.
-      return RegisteredCommand.newBuilder()
-          .setErrorCode(ErrorCode.errorNodeNotPermitted)
-          .build();
-    }
-    LOG.info("Data node with ID: {} Registered.",
-        datanodeID.getDatanodeUuid());
-    return RegisteredCommand.newBuilder()
-        .setErrorCode(ErrorCode.success)
-        .setDatanodeUUID(datanodeID.getDatanodeUuid())
-        .setClusterID(this.clusterID)
-        .build();
-  }
-
-  /**
-   * Verifies the datanode does not have a valid UUID already.
-   *
-   * @param datanodeID - Datanode UUID.
-   * @return SCMCommand
-   */
-  private SCMCommand verifyDatanodeUUID(DatanodeID datanodeID) {
-    if (datanodeID.getDatanodeUuid() != null &&
-        nodes.containsKey(datanodeID.getDatanodeUuid())) {
-      LOG.trace("Datanode is already registered. Datanode: {}",
-          datanodeID.toString());
-      return RegisteredCommand.newBuilder()
-          .setErrorCode(ErrorCode.success)
-          .setClusterID(this.clusterID)
-          .setDatanodeUUID(datanodeID.getDatanodeUuid())
-          .build();
-    }
-    return null;
-  }
-
-  /**
-   * Send heartbeat to indicate the datanode is alive and doing well.
-   *
-   * @param datanodeID - Datanode ID.
-   * @param nodeReport - node report.
-   * @param containerReportState - container report state.
-   * @return SCMheartbeat response.
-   * @throws IOException
-   */
-  @Override
-  public List<SCMCommand> sendHeartbeat(DatanodeID datanodeID,
-      SCMNodeReport nodeReport, ReportState containerReportState) {
-
-    // Checking for NULL to make sure that we don't get
-    // an exception from ConcurrentList.
-    // This could be a problem in tests, if this function is invoked via
-    // protobuf, transport layer will guarantee that this is not null.
-    if (datanodeID != null) {
-      heartbeatQueue.add(
-          new HeartbeatQueueItem.Builder()
-              .setDatanodeID(datanodeID)
-              .setNodeReport(nodeReport)
-              .setContainerReportState(containerReportState)
-              .build());
-    } else {
-      LOG.error("Datanode ID in heartbeat is null");
-    }
-
-    return commandQueue.getCommand(datanodeID);
-  }
-
-  /**
-   * Returns the aggregated node stats.
-   * @return the aggregated node stats.
-   */
-  @Override
-  public SCMNodeStat getStats() {
-    return new SCMNodeStat(this.scmStat);
-  }
-
-  /**
-   * Return a map of node stats.
-   * @return a map of individual node stats (live/stale but not dead).
-   */
-  @Override
-  public Map<String, SCMNodeStat> getNodeStats() {
-    return Collections.unmodifiableMap(nodeStats);
-  }
-
-  /**
-   * Return the node stat of the specified datanode.
-   * @param datanodeID - datanode ID.
-   * @return node stat if it is live/stale, null if it is dead or does't exist.
-   */
-  @Override
-  public SCMNodeMetric getNodeStat(DatanodeID datanodeID) {
-    return new SCMNodeMetric(nodeStats.get(datanodeID.getDatanodeUuid()));
-  }
-
-  @Override
-  public NodePoolManager getNodePoolManager() {
-    return nodePoolManager;
-  }
-
-  @Override
-  public Map<String, Integer> getNodeCount() {
-    Map<String, Integer> nodeCountMap = new HashMap<String, Integer>();
-    for(NodeState state : NodeState.values()) {
-      nodeCountMap.put(state.toString(), getNodeCount(state));
-    }
-    return nodeCountMap;
-  }
-
-  @Override
-  public void addDatanodeCommand(DatanodeID id, SCMCommand command) {
-    this.commandQueue.addCommand(id, command);
-  }
-
-  @VisibleForTesting
-  public void setStaleNodeIntervalMs(long interval) {
-    this.staleNodeIntervalMs = interval;
-  }
-}

http://git-wip-us.apache.org/repos/asf/hadoop/blob/ce23d9ad/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/SCMNodePoolManager.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/SCMNodePoolManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/SCMNodePoolManager.java
deleted file mode 100644
index 55bf1c4..0000000
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/SCMNodePoolManager.java
+++ /dev/null
@@ -1,266 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hadoop.ozone.scm.node;
-
-import com.google.common.base.Preconditions;
-import org.apache.hadoop.hdfs.DFSUtil;
-import org.apache.hadoop.hdfs.protocol.DatanodeID;
-import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos;
-import org.apache.hadoop.conf.OzoneConfiguration;
-import org.apache.hadoop.ozone.OzoneConsts;
-import org.apache.hadoop.ozone.scm.exceptions.SCMException;
-import org.apache.hadoop.ozone.web.utils.OzoneUtils;
-import org.apache.hadoop.utils.MetadataStore;
-import org.apache.hadoop.utils.MetadataStoreBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-import java.util.stream.Collectors;
-
-import static org.apache.hadoop.ozone.OzoneConsts.NODEPOOL_DB;
-import static org.apache.hadoop.ozone.scm
-    .exceptions.SCMException.ResultCodes.FAILED_TO_LOAD_NODEPOOL;
-import static org.apache.hadoop.ozone.scm
-    .exceptions.SCMException.ResultCodes.FAILED_TO_FIND_NODE_IN_POOL;
-import static org.apache.hadoop.scm
-    .ScmConfigKeys.OZONE_SCM_DB_CACHE_SIZE_DEFAULT;
-import static org.apache.hadoop.scm
-    .ScmConfigKeys.OZONE_SCM_DB_CACHE_SIZE_MB;
-
-/**
- * SCM node pool manager that manges node pools.
- */
-public final class SCMNodePoolManager implements NodePoolManager {
-
-  private static final Logger LOG =
-      LoggerFactory.getLogger(SCMNodePoolManager.class);
-  private static final List<DatanodeID> EMPTY_NODE_LIST = new ArrayList<>();
-  private static final List<String> EMPTY_NODEPOOL_LIST = new ArrayList<>();
-  public static final String DEFAULT_NODEPOOL = "DefaultNodePool";
-
-  // DB that saves the node to node pool mapping.
-  private MetadataStore nodePoolStore;
-
-  // In-memory node pool to nodes mapping
-  private HashMap<String, Set<DatanodeID>> nodePools;
-
-  // Read-write lock for nodepool operations
-  private ReadWriteLock lock;
-
-  /**
-   * Construct SCMNodePoolManager class that manages node to node pool mapping.
-   * @param conf - configuration.
-   * @throws IOException
-   */
-  public SCMNodePoolManager(final OzoneConfiguration conf)
-      throws IOException {
-    final int cacheSize = conf.getInt(OZONE_SCM_DB_CACHE_SIZE_MB,
-        OZONE_SCM_DB_CACHE_SIZE_DEFAULT);
-    File metaDir = OzoneUtils.getOzoneMetaDirPath(conf);
-    String scmMetaDataDir = metaDir.getPath();
-    File nodePoolDBPath = new File(scmMetaDataDir, NODEPOOL_DB);
-    nodePoolStore = MetadataStoreBuilder.newBuilder()
-        .setConf(conf)
-        .setDbFile(nodePoolDBPath)
-        .setCacheSize(cacheSize * OzoneConsts.MB)
-        .build();
-    nodePools = new HashMap<>();
-    lock = new ReentrantReadWriteLock();
-    init();
-  }
-
-  /**
-   * Initialize the in-memory store based on persist store from level db.
-   * No lock is needed as init() is only invoked by constructor.
-   * @throws SCMException
-   */
-  private void init() throws SCMException {
-    try {
-      nodePoolStore.iterate(null, (key, value) -> {
-        try {
-          DatanodeID nodeId = DatanodeID.getFromProtoBuf(
-              HdfsProtos.DatanodeIDProto.PARSER.parseFrom(key));
-          String poolName = DFSUtil.bytes2String(value);
-
-          Set<DatanodeID> nodePool = null;
-          if (nodePools.containsKey(poolName)) {
-            nodePool = nodePools.get(poolName);
-          } else {
-            nodePool = new HashSet<>();
-            nodePools.put(poolName, nodePool);
-          }
-          nodePool.add(nodeId);
-          if (LOG.isDebugEnabled()) {
-            LOG.debug("Adding node: {} to node pool: {}",
-                nodeId, poolName);
-          }
-        } catch (IOException e) {
-          LOG.warn("Can't add a datanode to node pool, continue next...");
-        }
-        return true;
-      });
-    } catch (IOException e) {
-      LOG.error("Loading node pool error " + e);
-      throw new SCMException("Failed to load node pool",
-          FAILED_TO_LOAD_NODEPOOL);
-    }
-  }
-
-  /**
-   * Add a datanode to a node pool.
-   * @param pool - name of the node pool.
-   * @param node - name of the datanode.
-   */
-  @Override
-  public void addNode(final String pool, final DatanodeID node)
-      throws IOException {
-    Preconditions.checkNotNull(pool, "pool name is null");
-    Preconditions.checkNotNull(node, "node is null");
-    lock.writeLock().lock();
-    try {
-      // add to the persistent store
-      nodePoolStore.put(node.getProtoBufMessage().toByteArray(),
-          DFSUtil.string2Bytes(pool));
-
-      // add to the in-memory store
-      Set<DatanodeID> nodePool = null;
-      if (nodePools.containsKey(pool)) {
-        nodePool = nodePools.get(pool);
-      } else {
-        nodePool = new HashSet<DatanodeID>();
-        nodePools.put(pool, nodePool);
-      }
-      nodePool.add(node);
-    } finally {
-      lock.writeLock().unlock();
-    }
-  }
-
-  /**
-   * Remove a datanode from a node pool.
-   * @param pool - name of the node pool.
-   * @param node - datanode id.
-   * @throws SCMException
-   */
-  @Override
-  public void removeNode(final String pool, final DatanodeID node)
-      throws SCMException {
-    Preconditions.checkNotNull(pool, "pool name is null");
-    Preconditions.checkNotNull(node, "node is null");
-    lock.writeLock().lock();
-    try {
-      // Remove from the persistent store
-      byte[] kName = node.getProtoBufMessage().toByteArray();
-      byte[] kData = nodePoolStore.get(kName);
-      if (kData == null) {
-        throw new SCMException(String.format("Unable to find node %s from" +
-            " pool %s in DB.", DFSUtil.bytes2String(kName), pool),
-            FAILED_TO_FIND_NODE_IN_POOL);
-      }
-      nodePoolStore.delete(kName);
-
-      // Remove from the in-memory store
-      if (nodePools.containsKey(pool)) {
-        Set<DatanodeID> nodePool = nodePools.get(pool);
-        nodePool.remove(node);
-      } else {
-        throw new SCMException(String.format("Unable to find node %s from" +
-            " pool %s in MAP.", DFSUtil.bytes2String(kName), pool),
-            FAILED_TO_FIND_NODE_IN_POOL);      }
-    } catch (IOException e) {
-      throw new SCMException("Failed to remove node " + node.toString()
-          + " from node pool " + pool, e,
-          SCMException.ResultCodes.IO_EXCEPTION);
-    } finally {
-      lock.writeLock().unlock();
-    }
-  }
-
-  /**
-   * Get all the node pools.
-   * @return all the node pools.
-   */
-  @Override
-  public List<String> getNodePools() {
-    lock.readLock().lock();
-    try {
-      if (!nodePools.isEmpty()) {
-        return nodePools.keySet().stream().collect(Collectors.toList());
-      } else {
-        return EMPTY_NODEPOOL_LIST;
-      }
-    } finally {
-      lock.readLock().unlock();
-    }
-  }
-
-  /**
-   * Get all datanodes of a specific node pool.
-   * @param pool - name of the node pool.
-   * @return all datanodes of the specified node pool.
-   */
-  @Override
-  public List<DatanodeID> getNodes(final String pool) {
-    Preconditions.checkNotNull(pool, "pool name is null");
-    if (nodePools.containsKey(pool)) {
-      return nodePools.get(pool).stream().collect(Collectors.toList());
-    } else {
-      return EMPTY_NODE_LIST;
-    }
-  }
-
-  /**
-   * Get the node pool name if the node has been added to a node pool.
-   * @param datanodeID - datanode ID.
-   * @return node pool name if it has been assigned.
-   * null if the node has not been assigned to any node pool yet.
-   * TODO: Put this in a in-memory map if performance is an issue.
-   */
-  @Override
-  public String getNodePool(final DatanodeID datanodeID) throws SCMException {
-    Preconditions.checkNotNull(datanodeID, "node is null");
-    try {
-      byte[]  result = nodePoolStore.get(
-          datanodeID.getProtoBufMessage().toByteArray());
-      return result == null ? null : DFSUtil.bytes2String(result);
-    } catch (IOException e) {
-      throw new SCMException("Failed to get node pool for node "
-          + datanodeID.toString(), e,
-          SCMException.ResultCodes.IO_EXCEPTION);
-    }
-  }
-
-  /**
-   * Close node pool level db store.
-   * @throws IOException
-   */
-  @Override
-  public void close() throws IOException {
-    nodePoolStore.close();
-  }
-}

http://git-wip-us.apache.org/repos/asf/hadoop/blob/ce23d9ad/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/package-info.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/package-info.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/package-info.java
deleted file mode 100644
index f1efe79..0000000
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/scm/node/package-info.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership.  The ASF
- * licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.apache.hadoop.ozone.scm.node;
-
-/**
- * The node package deals with node management.
- * <p/>
- * The node manager takes care of node registrations, removal of node and
- * handling of heartbeats.
- * <p/>
- * The node manager maintains statistics that gets send as part of
- * heartbeats.
- * <p/>
- * The container manager polls the node manager to learn the state of
- * datanodes  that it is interested in.
- * <p/>
- */
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org