diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAAdmin.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAAdmin.java index f72df7739e3..9c28eb9ed42 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAAdmin.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAAdmin.java @@ -125,12 +125,12 @@ public abstract class HAAdmin extends Configured implements Tool { ToolRunner.printGenericCommandUsage(errOut); } - private static void printUsage(PrintStream errOut, String cmd) { + private void printUsage(PrintStream errOut, String cmd) { UsageInfo usage = USAGE.get(cmd); if (usage == null) { throw new RuntimeException("No usage for cmd " + cmd); } - errOut.println("Usage: HAAdmin [" + cmd + " " + usage.args + "]"); + errOut.println(getUsageString() + " [" + cmd + " " + usage.args + "]"); } private int transitionToActive(final CommandLine cmd) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index 2a49f548abf..8be8934c531 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -554,6 +554,9 @@ Release 2.7.0 - UNRELEASED YARN-3191. Log object should be initialized with its own class. (Rohith via aajisaka) + YARN-3164. RMAdmin command usage prints incorrect command name. + (Bibin A Chundatt via xgong) + Release 2.6.0 - 2014-11-18 INCOMPATIBLE CHANGES diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RMAdminCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RMAdminCLI.java index d29f6741317..4642add12e3 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RMAdminCLI.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/RMAdminCLI.java @@ -19,6 +19,7 @@ package org.apache.hadoop.yarn.client.cli; import java.io.IOException; +import java.io.PrintStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -127,6 +128,10 @@ public class RMAdminCLI extends HAAdmin { super(conf); } + protected void setErrOut(PrintStream errOut) { + this.errOut = errOut; + } + private static void appendHAUsage(final StringBuilder usageBuilder) { for (Map.Entry cmdEntry : USAGE.entrySet()) { if (cmdEntry.getKey().equals("-help")) { @@ -639,6 +644,11 @@ public class RMAdminCLI extends HAAdmin { "Could not connect to RM HA Admin for node " + rmId); } } + + @Override + protected String getUsageString() { + return "Usage: rmadmin"; + } public static void main(String[] args) throws Exception { int result = ToolRunner.run(new RMAdminCLI(), args); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestRMAdminCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestRMAdminCLI.java index d4480906d27..c22494c9eb6 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestRMAdminCLI.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestRMAdminCLI.java @@ -58,6 +58,7 @@ import org.mockito.ArgumentMatcher; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; +import com.google.common.base.Charsets; import com.google.common.collect.ImmutableSet; public class TestRMAdminCLI { @@ -561,5 +562,20 @@ public class TestRMAdminCLI { data.toString().contains(template)); data.reset(); } - + + @Test + public void testRMHAErrorUsage() throws Exception { + ByteArrayOutputStream errOutBytes = new ByteArrayOutputStream(); + rmAdminCLIWithHAEnabled.setErrOut(new PrintStream(errOutBytes)); + try { + String[] args = { "-failover" }; + assertEquals(-1, rmAdminCLIWithHAEnabled.run(args)); + String errOut = new String(errOutBytes.toByteArray(), Charsets.UTF_8); + errOutBytes.reset(); + assertTrue(errOut.contains("Usage: rmadmin")); + } finally { + rmAdminCLIWithHAEnabled.setErrOut(System.err); + } + } + }