YARN-3164. RMAdmin command usage prints incorrect command name.

Contributed by Bibin A Chundatt

(cherry picked from commit 253035491c)
This commit is contained in:
Xuan 2015-02-12 21:39:16 -08:00
parent 613065d75a
commit 3c4b5606dc
4 changed files with 32 additions and 3 deletions

View File

@ -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)

View File

@ -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

View File

@ -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<String,UsageInfo> cmdEntry : USAGE.entrySet()) {
if (cmdEntry.getKey().equals("-help")) {
@ -640,6 +645,11 @@ public class RMAdminCLI extends HAAdmin {
}
}
@Override
protected String getUsageString() {
return "Usage: rmadmin";
}
public static void main(String[] args) throws Exception {
int result = ToolRunner.run(new RMAdminCLI(), args);
System.exit(result);

View File

@ -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 {
@ -562,4 +563,19 @@ public class TestRMAdminCLI {
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);
}
}
}