hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cnaur...@apache.org
Subject [28/50] [abbrv] hadoop git commit: HDFS-10813. DiskBalancer: Add the getNodeList method in Command. Contributed by Yiqun Lin.
Date Tue, 06 Sep 2016 16:44:01 GMT
HDFS-10813. DiskBalancer: Add the getNodeList method in Command. Contributed by Yiqun Lin.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/20ae1fa2
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/20ae1fa2
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/20ae1fa2

Branch: refs/heads/HADOOP-13345
Commit: 20ae1fa259b36a7bc11b0f8de1ebf753c858f93c
Parents: d6d9cff
Author: Anu Engineer <aengineer@apache.org>
Authored: Tue Aug 30 18:42:55 2016 -0700
Committer: Anu Engineer <aengineer@apache.org>
Committed: Tue Aug 30 18:42:55 2016 -0700

----------------------------------------------------------------------
 .../server/diskbalancer/command/Command.java    | 44 +++++++++++++++++++-
 .../command/TestDiskBalancerCommand.java        | 22 ++++++++++
 2 files changed, 65 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/20ae1fa2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/diskbalancer/command/Command.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/diskbalancer/command/Command.java
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/diskbalancer/command/Command.java
index a1c15ae..5acd0ac 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/diskbalancer/command/Command.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/diskbalancer/command/Command.java
@@ -18,7 +18,10 @@
 
 package org.apache.hadoop.hdfs.server.diskbalancer.command;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.Option;
 import org.apache.commons.lang.StringUtils;
@@ -221,7 +224,7 @@ public abstract class Command extends Configured {
    * @return Set of node names
    * @throws IOException
    */
-  private Set<String> getNodeList(String listArg) throws IOException {
+  protected Set<String> getNodeList(String listArg) throws IOException {
     URL listURL;
     String nodeData;
     Set<String> resultSet = new TreeSet<>();
@@ -243,6 +246,37 @@ public abstract class Command extends Configured {
   }
 
   /**
+   * Returns a DiskBalancer Node list from the Cluster or null if not found.
+   *
+   * @param listArg String File URL or a comma separated list of node names.
+   * @return List of DiskBalancer Node
+   * @throws IOException
+   */
+  protected List<DiskBalancerDataNode> getNodes(String listArg)
+      throws IOException {
+    Set<String> nodeNames = null;
+    List<DiskBalancerDataNode> nodeList = Lists.newArrayList();
+
+    if ((listArg == null) || listArg.isEmpty()) {
+      return nodeList;
+    }
+    nodeNames = getNodeList(listArg);
+
+    DiskBalancerDataNode node = null;
+    if (!nodeNames.isEmpty()) {
+      for (String name : nodeNames) {
+        node = getNode(name);
+
+        if (node != null) {
+          nodeList.add(node);
+        }
+      }
+    }
+
+    return nodeList;
+  }
+
+  /**
    * Verifies if the command line options are sane.
    *
    * @param commandName - Name of the command
@@ -471,4 +505,12 @@ public abstract class Command extends Configured {
   public int getTopNodes() {
     return topNodes;
   }
+
+  /**
+   * Set DiskBalancer cluster
+   */
+  @VisibleForTesting
+  public void setCluster(DiskBalancerCluster newCluster) {
+    this.cluster = newCluster;
+  }
 }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/20ae1fa2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/command/TestDiskBalancerCommand.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/command/TestDiskBalancerCommand.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/command/TestDiskBalancerCommand.java
index 0d24f28..7d659af 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/command/TestDiskBalancerCommand.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/command/TestDiskBalancerCommand.java
@@ -40,6 +40,7 @@ import org.apache.hadoop.hdfs.server.datanode.DataNode;
 import org.apache.hadoop.hdfs.server.diskbalancer.connectors.ClusterConnector;
 import org.apache.hadoop.hdfs.server.diskbalancer.connectors.ConnectorFactory;
 import org.apache.hadoop.hdfs.server.diskbalancer.datamodel.DiskBalancerCluster;
+import org.apache.hadoop.hdfs.server.diskbalancer.datamodel.DiskBalancerDataNode;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -435,4 +436,25 @@ public class TestDiskBalancerCommand {
       miniDFSCluster.shutdown();
     }
   }
+
+  @Test(timeout = 60000)
+  public void testGetNodeList() throws Exception {
+    ClusterConnector jsonConnector =
+        ConnectorFactory.getCluster(clusterJson, conf);
+    DiskBalancerCluster diskBalancerCluster =
+        new DiskBalancerCluster(jsonConnector);
+    diskBalancerCluster.readClusterInfo();
+
+    int nodeNum = 5;
+    StringBuilder listArg = new StringBuilder();
+    for (int i = 0; i < nodeNum; i++) {
+      listArg.append(diskBalancerCluster.getNodes().get(i).getDataNodeUUID())
+          .append(",");
+    }
+
+    ReportCommand command = new ReportCommand(conf, null);
+    command.setCluster(diskBalancerCluster);
+    List<DiskBalancerDataNode> nodeList = command.getNodes(listArg.toString());
+    assertEquals(nodeNum, nodeList.size());
+  }
 }


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


Mime
View raw message