From 307db61aac9f4b51301ab9d4e74be7632c42d62f Mon Sep 17 00:00:00 2001 From: Zhe Zhang Date: Tue, 10 May 2016 15:20:17 -0700 Subject: [PATCH] HDFS-10172. hdfs erasurecode command should remove the redundant -usage option. Contributed by Yuanbo Liu. --- .../main/java/org/apache/hadoop/fs/FsShell.java | 15 +++++++++++---- .../hadoop/hdfs/tools/erasurecode/ECCli.java | 14 +++++++++++++- .../src/test/resources/testErasureCodingConf.xml | 16 ++++++++++++++++ 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FsShell.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FsShell.java index c0a3bea6ac2..1de9374b805 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FsShell.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FsShell.java @@ -50,12 +50,12 @@ public class FsShell extends Configured implements Tool { private FileSystem fs; private Trash trash; + private Help help; protected CommandFactory commandFactory; private final String usagePrefix = "Usage: hadoop fs [generic options]"; - private Tracer tracer; static final String SHELL_HTRACE_PREFIX = "fs.shell.htrace."; /** @@ -89,6 +89,13 @@ protected Trash getTrash() throws IOException { } return this.trash; } + + protected Help getHelp() throws IOException { + if (this.help == null){ + this.help = new Help(); + } + return this.help; + } protected void init() throws IOException { getConf().setQuietMode(true); @@ -98,9 +105,6 @@ protected void init() throws IOException { commandFactory.addObject(new Usage(), "-usage"); registerCommands(commandFactory); } - this.tracer = new Tracer.Builder("FsShell"). - conf(TraceUtils.wrapHadoopConf(SHELL_HTRACE_PREFIX, getConf())). - build(); } protected void registerCommands(CommandFactory factory) { @@ -296,6 +300,9 @@ private TableListing createOptionTableListing() { public int run(String argv[]) throws Exception { // initialize FsShell init(); + Tracer tracer = new Tracer.Builder("FsShell"). + conf(TraceUtils.wrapHadoopConf(SHELL_HTRACE_PREFIX, getConf())). + build(); int exitCode = -1; if (argv.length < 1) { printUsage(System.err); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/erasurecode/ECCli.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/erasurecode/ECCli.java index c7ce7144218..48574d3a5e1 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/erasurecode/ECCli.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/erasurecode/ECCli.java @@ -23,6 +23,8 @@ import org.apache.hadoop.hdfs.HdfsConfiguration; import org.apache.hadoop.util.ToolRunner; +import java.io.IOException; + /** * CLI for the erasure code encoding operations. */ @@ -37,6 +39,16 @@ protected String getUsagePrefix() { return usagePrefix; } + @Override + protected void init() throws IOException { + getConf().setQuietMode(true); + if (commandFactory == null) { + commandFactory = new CommandFactory(getConf()); + commandFactory.addObject(getHelp(), "-help"); + registerCommands(commandFactory); + } + } + @Override protected void registerCommands(CommandFactory factory) { factory.registerCommands(ECCommand.class); @@ -47,4 +59,4 @@ public static void main(String[] args) throws Exception { int res = ToolRunner.run(conf, new ECCli(), args); System.exit(res); } -} \ No newline at end of file +} diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testErasureCodingConf.xml b/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testErasureCodingConf.xml index 1c782c3c276..f8ee9738aa3 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testErasureCodingConf.xml +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testErasureCodingConf.xml @@ -31,6 +31,22 @@ --> + + + usage: help for erasure coding command + + -usage + + + + + + SubstringComparator + -usage: Unknown command + + + + help: help for erasure coding command