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 ar...@apache.org on 2016/06/24 01:36:30 UTC

[34/49] hadoop git commit: HDFS-10402. DiskBalancer: Add QueryStatus command. (Contributed by Anu Engineer)

HDFS-10402. DiskBalancer: Add QueryStatus command. (Contributed by Anu Engineer)


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

Branch: refs/heads/HDFS-1312
Commit: 9e5fcb5e40bb370e4579e6040c02e923c1a90427
Parents: 5df2d2b
Author: Arpit Agarwal <ar...@apache.org>
Authored: Fri May 20 14:09:58 2016 -0700
Committer: Arpit Agarwal <ar...@apache.org>
Committed: Thu Jun 23 18:21:08 2016 -0700

----------------------------------------------------------------------
 .../diskbalancer/command/QueryCommand.java      | 82 ++++++++++++++++++++
 .../apache/hadoop/hdfs/tools/DiskBalancer.java  | 22 ++++++
 2 files changed, 104 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/9e5fcb5e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/diskbalancer/command/QueryCommand.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/diskbalancer/command/QueryCommand.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/diskbalancer/command/QueryCommand.java
new file mode 100644
index 0000000..36448b8
--- /dev/null
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/diskbalancer/command/QueryCommand.java
@@ -0,0 +1,82 @@
+/*
+ * 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.hdfs.server.diskbalancer.command;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.cli.CommandLine;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hdfs.protocol.ClientDatanodeProtocol;
+import org.apache.hadoop.hdfs.server.datanode.DiskBalancerWorkStatus;
+import org.apache.hadoop.hdfs.server.diskbalancer.DiskBalancerException;
+import org.apache.hadoop.hdfs.tools.DiskBalancer;
+
+/**
+ * Gets the current status of disk balancer command.
+ */
+public class QueryCommand extends Command {
+
+  /**
+   * Constructs QueryCommand.
+   *
+   * @param conf - Configuration.
+   */
+  public QueryCommand(Configuration conf) {
+    super(conf);
+    addValidCommandParameters(DiskBalancer.QUERY, "Queries the status of disk" +
+        " plan running on a given datanode.");
+    addValidCommandParameters(DiskBalancer.VERBOSE, "Prints verbose results.");
+  }
+  /**
+   * Executes the Client Calls.
+   *
+   * @param cmd - CommandLine
+   */
+  @Override
+  public void execute(CommandLine cmd) throws Exception {
+    LOG.info("Executing \"query plan\" command.");
+    Preconditions.checkState(cmd.hasOption(DiskBalancer.QUERY));
+    verifyCommandOptions(DiskBalancer.QUERY, cmd);
+    String nodeName = cmd.getOptionValue(DiskBalancer.QUERY);
+    Preconditions.checkNotNull(nodeName);
+    ClientDatanodeProtocol dataNode = getDataNodeProxy(nodeName);
+    try {
+      DiskBalancerWorkStatus workStatus = dataNode.queryDiskBalancerPlan();
+      System.out.printf("Plan ID: %s Result: %s%n", workStatus.getPlanID(),
+          workStatus.getResult().toString());
+
+      if(cmd.hasOption(DiskBalancer.VERBOSE)) {
+        System.out.printf("%s", workStatus.currentStateString());
+      }
+    } catch (DiskBalancerException ex) {
+      LOG.error("Query plan failed. ex: {}", ex);
+      throw ex;
+    }
+  }
+
+  /**
+   * Gets extended help for this command.
+   *
+   * @return Help Message
+   */
+  @Override
+  protected String getHelp() {
+    return "Gets the status of disk balancing on a given node";
+  }
+}

http://git-wip-us.apache.org/repos/asf/hadoop/blob/9e5fcb5e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DiskBalancer.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DiskBalancer.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DiskBalancer.java
index 87fbf4a..f5dbe4e 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DiskBalancer.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DiskBalancer.java
@@ -27,6 +27,7 @@ import org.apache.hadoop.hdfs.HdfsConfiguration;
 import org.apache.hadoop.hdfs.server.diskbalancer.command.Command;
 import org.apache.hadoop.hdfs.server.diskbalancer.command.ExecuteCommand;
 import org.apache.hadoop.hdfs.server.diskbalancer.command.PlanCommand;
+import org.apache.hadoop.hdfs.server.diskbalancer.command.QueryCommand;
 import org.apache.hadoop.util.Tool;
 import org.apache.hadoop.util.ToolRunner;
 import org.slf4j.Logger;
@@ -101,6 +102,11 @@ public class DiskBalancer extends Configured implements Tool {
   public static final String VERBOSE = "v";
   public static final int PLAN_VERSION = 1;
   /**
+   * Reports the status of disk balancer operation.
+   */
+  public static final String QUERY = "query";
+
+  /**
    * Template for the Before File. It is node.before.json.
    */
   public static final String BEFORE_TEMPLATE = "%s.before.json";
@@ -160,6 +166,8 @@ public class DiskBalancer extends Configured implements Tool {
   private Options getOpts() {
     Options opts = new Options();
     addPlanCommands(opts);
+    addExecuteCommands(opts);
+    addQueryCommands(opts);
     return opts;
   }
 
@@ -216,6 +224,16 @@ public class DiskBalancer extends Configured implements Tool {
   }
 
   /**
+   * Adds query command options.
+   * @param opt Options
+   */
+  private void addQueryCommands(Options opt) {
+    Option query = new Option(QUERY, true, "Queries the disk balancer " +
+        "status of a given datanode. e.g. -query <nodename>");
+    opt.addOption(query);
+  }
+
+  /**
    * This function parses all command line arguments and returns the appropriate
    * values.
    *
@@ -249,6 +267,10 @@ public class DiskBalancer extends Configured implements Tool {
         currentCommand = new ExecuteCommand(getConf());
       }
 
+      if(cmd.hasOption(DiskBalancer.QUERY)) {
+        currentCommand = new QueryCommand(getConf());
+      }
+
       if(currentCommand == null) {
         HelpFormatter helpFormatter = new HelpFormatter();
         helpFormatter.printHelp(80, "hdfs diskbalancer -uri [args]",


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