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

Contributed by Bibin A Chundatt
This commit is contained in:
Xuan 2015-02-12 21:39:16 -08:00
parent 110cf6b9a3
commit 253035491c
4 changed files with 32 additions and 3 deletions

View File

@ -125,12 +125,12 @@ protected void printUsage(PrintStream errOut) {
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

@ -590,6 +590,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 RMAdminCLI(Configuration conf) {
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")) {
@ -639,6 +644,11 @@ protected HAServiceTarget resolveTarget(String rmId) {
"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);

View File

@ -58,6 +58,7 @@
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 @@ private void testError(String[] args, String template,
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);
}
}
}