HADOOP-10816. KeyShell returns -1 on error to the shell, should be 1. (Mike Yoder via wang)
Conflicts: hadoop-common-project/hadoop-common/CHANGES.txt git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1619532 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0ef751797e
commit
9467bef8ea
|
@ -247,6 +247,9 @@ Release 2.6.0 - UNRELEASED
|
||||||
HADOOP-10611. KMS, keyVersion name should not be assumed to be
|
HADOOP-10611. KMS, keyVersion name should not be assumed to be
|
||||||
keyName@versionNumber. (tucu)
|
keyName@versionNumber. (tucu)
|
||||||
|
|
||||||
|
HADOOP-10816. KeyShell returns -1 on error to the shell, should be 1.
|
||||||
|
(Mike Yoder via wang)
|
||||||
|
|
||||||
Release 2.5.0 - 2014-08-11
|
Release 2.5.0 - 2014-08-11
|
||||||
|
|
||||||
INCOMPATIBLE CHANGES
|
INCOMPATIBLE CHANGES
|
||||||
|
|
|
@ -57,6 +57,16 @@ public class KeyShell extends Configured implements Tool {
|
||||||
|
|
||||||
private boolean userSuppliedProvider = false;
|
private boolean userSuppliedProvider = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Primary entry point for the KeyShell; called via main().
|
||||||
|
*
|
||||||
|
* @param args Command line arguments.
|
||||||
|
* @return 0 on success and 1 on failure. This value is passed back to
|
||||||
|
* the unix shell, so we must follow shell return code conventions:
|
||||||
|
* the return code is an unsigned character, and 0 means success, and
|
||||||
|
* small positive integers mean failure.
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int run(String[] args) throws Exception {
|
public int run(String[] args) throws Exception {
|
||||||
int exitCode = 0;
|
int exitCode = 0;
|
||||||
|
@ -68,11 +78,11 @@ public class KeyShell extends Configured implements Tool {
|
||||||
if (command.validate()) {
|
if (command.validate()) {
|
||||||
command.execute();
|
command.execute();
|
||||||
} else {
|
} else {
|
||||||
exitCode = -1;
|
exitCode = 1;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace(err);
|
e.printStackTrace(err);
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
return exitCode;
|
return exitCode;
|
||||||
}
|
}
|
||||||
|
@ -86,8 +96,8 @@ public class KeyShell extends Configured implements Tool {
|
||||||
* % hadoop key list [-provider providerPath]
|
* % hadoop key list [-provider providerPath]
|
||||||
* % hadoop key delete keyName [--provider providerPath] [-i]
|
* % hadoop key delete keyName [--provider providerPath] [-i]
|
||||||
* </pre>
|
* </pre>
|
||||||
* @param args
|
* @param args Command line arguments.
|
||||||
* @return
|
* @return 0 on success, 1 on failure.
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private int init(String[] args) throws IOException {
|
private int init(String[] args) throws IOException {
|
||||||
|
@ -105,7 +115,7 @@ public class KeyShell extends Configured implements Tool {
|
||||||
command = new CreateCommand(keyName, options);
|
command = new CreateCommand(keyName, options);
|
||||||
if ("--help".equals(keyName)) {
|
if ("--help".equals(keyName)) {
|
||||||
printKeyShellUsage();
|
printKeyShellUsage();
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
} else if (args[i].equals("delete")) {
|
} else if (args[i].equals("delete")) {
|
||||||
String keyName = "--help";
|
String keyName = "--help";
|
||||||
|
@ -116,7 +126,7 @@ public class KeyShell extends Configured implements Tool {
|
||||||
command = new DeleteCommand(keyName);
|
command = new DeleteCommand(keyName);
|
||||||
if ("--help".equals(keyName)) {
|
if ("--help".equals(keyName)) {
|
||||||
printKeyShellUsage();
|
printKeyShellUsage();
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
} else if (args[i].equals("roll")) {
|
} else if (args[i].equals("roll")) {
|
||||||
String keyName = "--help";
|
String keyName = "--help";
|
||||||
|
@ -127,7 +137,7 @@ public class KeyShell extends Configured implements Tool {
|
||||||
command = new RollCommand(keyName);
|
command = new RollCommand(keyName);
|
||||||
if ("--help".equals(keyName)) {
|
if ("--help".equals(keyName)) {
|
||||||
printKeyShellUsage();
|
printKeyShellUsage();
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
} else if ("list".equals(args[i])) {
|
} else if ("list".equals(args[i])) {
|
||||||
command = new ListCommand();
|
command = new ListCommand();
|
||||||
|
@ -145,13 +155,13 @@ public class KeyShell extends Configured implements Tool {
|
||||||
out.println("\nAttributes must be in attribute=value form, " +
|
out.println("\nAttributes must be in attribute=value form, " +
|
||||||
"or quoted\nlike \"attribute = value\"\n");
|
"or quoted\nlike \"attribute = value\"\n");
|
||||||
printKeyShellUsage();
|
printKeyShellUsage();
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (attributes.containsKey(attr)) {
|
if (attributes.containsKey(attr)) {
|
||||||
out.println("\nEach attribute must correspond to only one value:\n" +
|
out.println("\nEach attribute must correspond to only one value:\n" +
|
||||||
"atttribute \"" + attr + "\" was repeated\n" );
|
"atttribute \"" + attr + "\" was repeated\n" );
|
||||||
printKeyShellUsage();
|
printKeyShellUsage();
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
attributes.put(attr, val);
|
attributes.put(attr, val);
|
||||||
} else if ("--provider".equals(args[i]) && moreTokens) {
|
} else if ("--provider".equals(args[i]) && moreTokens) {
|
||||||
|
@ -163,17 +173,17 @@ public class KeyShell extends Configured implements Tool {
|
||||||
interactive = true;
|
interactive = true;
|
||||||
} else if ("--help".equals(args[i])) {
|
} else if ("--help".equals(args[i])) {
|
||||||
printKeyShellUsage();
|
printKeyShellUsage();
|
||||||
return -1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
printKeyShellUsage();
|
printKeyShellUsage();
|
||||||
ToolRunner.printGenericCommandUsage(System.err);
|
ToolRunner.printGenericCommandUsage(System.err);
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command == null) {
|
if (command == null) {
|
||||||
printKeyShellUsage();
|
printKeyShellUsage();
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!attributes.isEmpty()) {
|
if (!attributes.isEmpty()) {
|
||||||
|
@ -491,10 +501,11 @@ public class KeyShell extends Configured implements Tool {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main program.
|
* main() entry point for the KeyShell. While strictly speaking the
|
||||||
|
* return is void, it will System.exit() with a return code: 0 is for
|
||||||
|
* success and 1 for failure.
|
||||||
*
|
*
|
||||||
* @param args
|
* @param args Command line arguments.
|
||||||
* Command line arguments
|
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|
|
@ -161,7 +161,7 @@ public class TestKeyShell {
|
||||||
KeyShell ks = new KeyShell();
|
KeyShell ks = new KeyShell();
|
||||||
ks.setConf(new Configuration());
|
ks.setConf(new Configuration());
|
||||||
rc = ks.run(args1);
|
rc = ks.run(args1);
|
||||||
assertEquals(-1, rc);
|
assertEquals(1, rc);
|
||||||
assertTrue(outContent.toString().contains("key1 has not been created."));
|
assertTrue(outContent.toString().contains("key1 has not been created."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ public class TestKeyShell {
|
||||||
KeyShell ks = new KeyShell();
|
KeyShell ks = new KeyShell();
|
||||||
ks.setConf(new Configuration());
|
ks.setConf(new Configuration());
|
||||||
rc = ks.run(args1);
|
rc = ks.run(args1);
|
||||||
assertEquals(-1, rc);
|
assertEquals(1, rc);
|
||||||
assertTrue(outContent.toString().contains("key1 has not been created."));
|
assertTrue(outContent.toString().contains("key1 has not been created."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,7 +187,7 @@ public class TestKeyShell {
|
||||||
KeyShell ks = new KeyShell();
|
KeyShell ks = new KeyShell();
|
||||||
ks.setConf(new Configuration());
|
ks.setConf(new Configuration());
|
||||||
rc = ks.run(args1);
|
rc = ks.run(args1);
|
||||||
assertEquals(-1, rc);
|
assertEquals(1, rc);
|
||||||
assertTrue(outContent.toString().contains("There are no valid " +
|
assertTrue(outContent.toString().contains("There are no valid " +
|
||||||
"KeyProviders configured."));
|
"KeyProviders configured."));
|
||||||
}
|
}
|
||||||
|
@ -216,7 +216,7 @@ public class TestKeyShell {
|
||||||
config.set(KeyProviderFactory.KEY_PROVIDER_PATH, "user:///");
|
config.set(KeyProviderFactory.KEY_PROVIDER_PATH, "user:///");
|
||||||
ks.setConf(config);
|
ks.setConf(config);
|
||||||
rc = ks.run(args1);
|
rc = ks.run(args1);
|
||||||
assertEquals(-1, rc);
|
assertEquals(1, rc);
|
||||||
assertTrue(outContent.toString().contains("There are no valid " +
|
assertTrue(outContent.toString().contains("There are no valid " +
|
||||||
"KeyProviders configured."));
|
"KeyProviders configured."));
|
||||||
}
|
}
|
||||||
|
@ -262,19 +262,19 @@ public class TestKeyShell {
|
||||||
final String[] args2 = {"create", "keyattr2", "--provider", jceksProvider,
|
final String[] args2 = {"create", "keyattr2", "--provider", jceksProvider,
|
||||||
"--attr", "=bar"};
|
"--attr", "=bar"};
|
||||||
rc = ks.run(args2);
|
rc = ks.run(args2);
|
||||||
assertEquals(-1, rc);
|
assertEquals(1, rc);
|
||||||
|
|
||||||
/* Not in attribute = value form */
|
/* Not in attribute = value form */
|
||||||
outContent.reset();
|
outContent.reset();
|
||||||
args2[5] = "foo";
|
args2[5] = "foo";
|
||||||
rc = ks.run(args2);
|
rc = ks.run(args2);
|
||||||
assertEquals(-1, rc);
|
assertEquals(1, rc);
|
||||||
|
|
||||||
/* No attribute or value */
|
/* No attribute or value */
|
||||||
outContent.reset();
|
outContent.reset();
|
||||||
args2[5] = "=";
|
args2[5] = "=";
|
||||||
rc = ks.run(args2);
|
rc = ks.run(args2);
|
||||||
assertEquals(-1, rc);
|
assertEquals(1, rc);
|
||||||
|
|
||||||
/* Legal: attribute is a, value is b=c */
|
/* Legal: attribute is a, value is b=c */
|
||||||
outContent.reset();
|
outContent.reset();
|
||||||
|
@ -308,7 +308,7 @@ public class TestKeyShell {
|
||||||
"--attr", "foo=bar",
|
"--attr", "foo=bar",
|
||||||
"--attr", "foo=glarch"};
|
"--attr", "foo=glarch"};
|
||||||
rc = ks.run(args4);
|
rc = ks.run(args4);
|
||||||
assertEquals(-1, rc);
|
assertEquals(1, rc);
|
||||||
|
|
||||||
/* Clean up to be a good citizen */
|
/* Clean up to be a good citizen */
|
||||||
deleteKey(ks, "keyattr1");
|
deleteKey(ks, "keyattr1");
|
||||||
|
|
Loading…
Reference in New Issue