HDFS-11516. Admin command line should print message to stderr in failure case. Contributed by Kai Sasaki.
(cherry picked from commit 92ea6d74ec
)
Conflicts:
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cli/util/ErasureCodingCliCmdExecutor.java
hadoop-hdfs-project/hadoop-hdfs/src/test/resources/testErasureCodingConf.xml
This commit is contained in:
parent
dbdd97d057
commit
7cc88eca43
|
@ -297,6 +297,11 @@ public class CLITestHelper {
|
||||||
|
|
||||||
return compareOutput;
|
return compareOutput;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean compareTextExitCode(ComparatorData compdata,
|
||||||
|
Result cmdResult) {
|
||||||
|
return compdata.getExitCode() == cmdResult.getExitCode();
|
||||||
|
}
|
||||||
|
|
||||||
/***********************************
|
/***********************************
|
||||||
************* TESTS RUNNER
|
************* TESTS RUNNER
|
||||||
|
@ -329,10 +334,17 @@ public class CLITestHelper {
|
||||||
final String comptype = cd.getComparatorType();
|
final String comptype = cd.getComparatorType();
|
||||||
|
|
||||||
boolean compareOutput = false;
|
boolean compareOutput = false;
|
||||||
|
boolean compareExitCode = false;
|
||||||
|
|
||||||
if (! comptype.equalsIgnoreCase("none")) {
|
if (! comptype.equalsIgnoreCase("none")) {
|
||||||
compareOutput = compareTestOutput(cd, cmdResult);
|
compareOutput = compareTestOutput(cd, cmdResult);
|
||||||
overallTCResult &= compareOutput;
|
if (cd.getExitCode() == -1) {
|
||||||
|
// No need to check exit code if not specified
|
||||||
|
compareExitCode = true;
|
||||||
|
} else {
|
||||||
|
compareExitCode = compareTextExitCode(cd, cmdResult);
|
||||||
|
}
|
||||||
|
overallTCResult &= (compareOutput & compareExitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
cd.setExitCode(cmdResult.getExitCode());
|
cd.setExitCode(cmdResult.getExitCode());
|
||||||
|
@ -390,6 +402,7 @@ public class CLITestHelper {
|
||||||
testComparators = new ArrayList<ComparatorData>();
|
testComparators = new ArrayList<ComparatorData>();
|
||||||
} else if (qName.equals("comparator")) {
|
} else if (qName.equals("comparator")) {
|
||||||
comparatorData = new ComparatorData();
|
comparatorData = new ComparatorData();
|
||||||
|
comparatorData.setExitCode(-1);
|
||||||
}
|
}
|
||||||
charString = "";
|
charString = "";
|
||||||
}
|
}
|
||||||
|
@ -421,6 +434,8 @@ public class CLITestHelper {
|
||||||
comparatorData.setComparatorType(charString);
|
comparatorData.setComparatorType(charString);
|
||||||
} else if (qName.equals("expected-output")) {
|
} else if (qName.equals("expected-output")) {
|
||||||
comparatorData.setExpectedOutput(charString);
|
comparatorData.setExpectedOutput(charString);
|
||||||
|
} else if (qName.equals("expected-exit-code")) {
|
||||||
|
comparatorData.setExitCode(Integer.valueOf(charString));
|
||||||
} else if (qName.equals("test")) {
|
} else if (qName.equals("test")) {
|
||||||
if (!Shell.WINDOWS || runOnWindows) {
|
if (!Shell.WINDOWS || runOnWindows) {
|
||||||
testsFromConfigFile.add(td);
|
testsFromConfigFile.add(td);
|
||||||
|
|
|
@ -75,7 +75,7 @@ public abstract class CommandExecutor {
|
||||||
System.setErr(new PrintStream(bao));
|
System.setErr(new PrintStream(bao));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
execute(cmd);
|
exitCode = execute(cmd);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
lastException = e;
|
lastException = e;
|
||||||
|
@ -87,7 +87,7 @@ public abstract class CommandExecutor {
|
||||||
return new Result(bao.toString(), exitCode, lastException, cmd);
|
return new Result(bao.toString(), exitCode, lastException, cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void execute(final String cmd) throws Exception;
|
protected abstract int execute(String cmd) throws Exception;
|
||||||
|
|
||||||
public static class Result {
|
public static class Result {
|
||||||
final String commandOutput;
|
final String commandOutput;
|
||||||
|
|
|
@ -30,8 +30,8 @@ public class FSCmdExecutor extends CommandExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void execute(final String cmd) throws Exception{
|
protected int execute(final String cmd) throws Exception{
|
||||||
String[] args = getCommandAsArgs(cmd, "NAMENODE", this.namenode);
|
String[] args = getCommandAsArgs(cmd, "NAMENODE", this.namenode);
|
||||||
ToolRunner.run(shell, args);
|
return ToolRunner.run(shell, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,11 +176,11 @@ public class AdminHelper {
|
||||||
for (AdminHelper.Command command : commands) {
|
for (AdminHelper.Command command : commands) {
|
||||||
System.err.println(command.getLongUsage());
|
System.err.println(command.getLongUsage());
|
||||||
}
|
}
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
if (args.size() != 1) {
|
if (args.size() != 1) {
|
||||||
System.out.println("You must give exactly one argument to -help.");
|
System.err.println("You must give exactly one argument to -help.");
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
final String commandName = args.get(0);
|
final String commandName = args.get(0);
|
||||||
// prepend a dash to match against the command names
|
// prepend a dash to match against the command names
|
||||||
|
|
|
@ -233,7 +233,7 @@ public class CryptoAdmin extends Configured implements Tool {
|
||||||
final FileEncryptionInfo fei =
|
final FileEncryptionInfo fei =
|
||||||
admin.getFileEncryptionInfo(p);
|
admin.getFileEncryptionInfo(p);
|
||||||
if (fei == null) {
|
if (fei == null) {
|
||||||
System.out.println("No FileEncryptionInfo found for path " + path);
|
System.err.println("No FileEncryptionInfo found for path " + path);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
System.out.println(fei.toStringStable());
|
System.out.println(fei.toStringStable());
|
||||||
|
|
|
@ -30,8 +30,8 @@ public class CacheAdminCmdExecutor extends CommandExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void execute(final String cmd) throws Exception {
|
protected int execute(final String cmd) throws Exception {
|
||||||
String[] args = getCommandAsArgs(cmd, "NAMENODE", this.namenode);
|
String[] args = getCommandAsArgs(cmd, "NAMENODE", this.namenode);
|
||||||
ToolRunner.run(admin, args);
|
return ToolRunner.run(admin, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,8 @@ public class CryptoAdminCmdExecutor extends CommandExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void execute(final String cmd) throws Exception {
|
protected int execute(final String cmd) throws Exception {
|
||||||
String[] args = getCommandAsArgs(cmd, "NAMENODE", this.namenode);
|
String[] args = getCommandAsArgs(cmd, "NAMENODE", this.namenode);
|
||||||
ToolRunner.run(admin, args);
|
return ToolRunner.run(admin, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,37 @@
|
||||||
</comparators>
|
</comparators>
|
||||||
</test>
|
</test>
|
||||||
|
|
||||||
|
<test>
|
||||||
|
<description>Test help usage</description>
|
||||||
|
<test-commands>
|
||||||
|
<crypto-admin-command>-help</crypto-admin-command>
|
||||||
|
</test-commands>
|
||||||
|
<cleanup-commands>
|
||||||
|
</cleanup-commands>
|
||||||
|
<comparators>
|
||||||
|
<comparator>
|
||||||
|
<type>SubstringComparator</type>
|
||||||
|
<expected-output>[-createZone -keyName</expected-output>
|
||||||
|
</comparator>
|
||||||
|
</comparators>
|
||||||
|
</test>
|
||||||
|
|
||||||
|
<test>
|
||||||
|
<description>Test extra help argument</description>
|
||||||
|
<test-commands>
|
||||||
|
<crypto-admin-command>-help arg1 arg2</crypto-admin-command>
|
||||||
|
</test-commands>
|
||||||
|
<cleanup-commands>
|
||||||
|
</cleanup-commands>
|
||||||
|
<comparators>
|
||||||
|
<comparator>
|
||||||
|
<type>SubstringComparator</type>
|
||||||
|
<expected-output>You must give exactly one argument to -help.</expected-output>
|
||||||
|
<expected-exit-code>1</expected-exit-code>
|
||||||
|
</comparator>
|
||||||
|
</comparators>
|
||||||
|
</test>
|
||||||
|
|
||||||
<test>
|
<test>
|
||||||
<description>Test create ez, dir doesn't exist</description>
|
<description>Test create ez, dir doesn't exist</description>
|
||||||
<test-commands>
|
<test-commands>
|
||||||
|
|
Loading…
Reference in New Issue