Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id B451F200B92 for ; Wed, 14 Sep 2016 04:43:47 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id B2EF1160AD3; Wed, 14 Sep 2016 02:43:47 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D2C70160AD8 for ; Wed, 14 Sep 2016 04:43:46 +0200 (CEST) Received: (qmail 99558 invoked by uid 500); 14 Sep 2016 02:43:41 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 98447 invoked by uid 99); 14 Sep 2016 02:43:40 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Sep 2016 02:43:40 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 67A03E09AC; Wed, 14 Sep 2016 02:43:40 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: subru@apache.org To: common-commits@hadoop.apache.org Date: Wed, 14 Sep 2016 02:44:01 -0000 Message-Id: <2293c66bc78d4bc6a33632bd669daa7c@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [23/50] [abbrv] hadoop git commit: HDFS-10599. DiskBalancer: Execute CLI via Shell. Contributed by Manoj Govindassamy. archived-at: Wed, 14 Sep 2016 02:43:47 -0000 HDFS-10599. DiskBalancer: Execute CLI via Shell. Contributed by Manoj Govindassamy. Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/e3f7f58a Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/e3f7f58a Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/e3f7f58a Branch: refs/heads/YARN-2915 Commit: e3f7f58a5fb3e18fe6e603ce5018eb805f170d09 Parents: e793309 Author: Anu Engineer Authored: Tue Sep 13 09:38:12 2016 -0700 Committer: Anu Engineer Committed: Tue Sep 13 09:38:12 2016 -0700 ---------------------------------------------------------------------- .../hadoop/hdfs/tools/DiskBalancerCLI.java | 25 +++++++---------- .../command/TestDiskBalancerCommand.java | 29 ++++++++++++++++++-- 2 files changed, 36 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/e3f7f58a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DiskBalancerCLI.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DiskBalancerCLI.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DiskBalancerCLI.java index e961c14..c216a30 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DiskBalancerCLI.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/DiskBalancerCLI.java @@ -135,13 +135,20 @@ public class DiskBalancerCLI extends Configured implements Tool { private static final Options CANCEL_OPTIONS = new Options(); private static final Options REPORT_OPTIONS = new Options(); + private final PrintStream printStream; + /** * Construct a DiskBalancer. * * @param conf */ public DiskBalancerCLI(Configuration conf) { + this(conf, System.out); + } + + public DiskBalancerCLI(Configuration conf, final PrintStream printStream) { super(conf); + this.printStream = printStream; } /** @@ -171,21 +178,9 @@ public class DiskBalancerCLI extends Configured implements Tool { */ @Override public int run(String[] args) throws Exception { - return run(args, System.out); - } - - /** - * Execute the command with the given arguments. - * - * @param args command specific arguments. - * @param out the output stream used for printing - * @return exit code. - * @throws Exception - */ - public int run(String[] args, final PrintStream out) throws Exception { Options opts = getOpts(); CommandLine cmd = parseArgs(args, opts); - return dispatch(cmd, opts, out); + return dispatch(cmd, opts); } /** @@ -443,7 +438,7 @@ public class DiskBalancerCLI extends Configured implements Tool { * @param opts options of command line * @param out the output stream used for printing */ - private int dispatch(CommandLine cmd, Options opts, final PrintStream out) + private int dispatch(CommandLine cmd, Options opts) throws Exception { Command currentCommand = null; if (cmd.hasOption(DiskBalancerCLI.PLAN)) { @@ -463,7 +458,7 @@ public class DiskBalancerCLI extends Configured implements Tool { } if (cmd.hasOption(DiskBalancerCLI.REPORT)) { - currentCommand = new ReportCommand(getConf(), out); + currentCommand = new ReportCommand(getConf(), this.printStream); } if (cmd.hasOption(DiskBalancerCLI.HELP)) { http://git-wip-us.apache.org/repos/asf/hadoop/blob/e3f7f58a/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 1950c85..6697785 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 @@ -43,6 +43,8 @@ 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.apache.hadoop.hdfs.tools.DiskBalancerCLI; +import org.apache.hadoop.util.Tool; +import org.apache.hadoop.util.ToolRunner; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -140,6 +142,27 @@ public class TestDiskBalancerCommand { containsString("9 volumes with node data density 1.97")))); } + /** + * This test simulates DiskBalancerCLI Report command run from a shell + * with a generic option 'fs'. + * @throws Exception + */ + @Test(timeout = 60000) + public void testReportWithGenericOptionFS() throws Exception { + final String topReportArg = "5"; + final String reportArgs = String.format("-%s file:%s -%s -%s %s", + "fs", clusterJson.getPath(), + REPORT, "top", topReportArg); + final String cmdLine = String.format("%s", reportArgs); + final List outputs = runCommand(cmdLine); + + assertThat(outputs.get(0), containsString("Processing report command")); + assertThat(outputs.get(1), + is(allOf(containsString("Reporting top"), containsString(topReportArg), + containsString( + "DataNode(s) benefiting from running DiskBalancer")))); + } + /* test more than 64 DataNode(s) as total, e.g., -report -top 128 */ @Test(timeout = 60000) public void testReportMoreThanTotal() throws Exception { @@ -389,11 +412,11 @@ public class TestDiskBalancerCommand { private List runCommandInternal(final String cmdLine) throws Exception { String[] cmds = StringUtils.split(cmdLine, ' '); - DiskBalancerCLI db = new DiskBalancerCLI(conf); - ByteArrayOutputStream bufOut = new ByteArrayOutputStream(); PrintStream out = new PrintStream(bufOut); - db.run(cmds, out); + + Tool diskBalancerTool = new DiskBalancerCLI(conf, out); + ToolRunner.run(conf, diskBalancerTool, cmds); Scanner scanner = new Scanner(bufOut.toString()); List outputs = Lists.newArrayList(); --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org For additional commands, e-mail: common-commits-help@hadoop.apache.org