HADOOP-15596. Stack trace should not be printed out when running hadoop key commands. Contributed by Kitti Nanasi.

This commit is contained in:
Xiao Chen 2018-07-19 14:25:38 -07:00
parent 1622a4b810
commit 993ec026d1
3 changed files with 27 additions and 13 deletions

View File

@ -265,8 +265,7 @@ public void execute() throws IOException {
} }
} }
} catch (IOException e) { } catch (IOException e) {
getOut().println("Cannot list keys for KeyProvider: " + provider getOut().println("Cannot list keys for KeyProvider: " + provider);
+ ": " + e.toString());
throw e; throw e;
} }
} }
@ -318,12 +317,12 @@ public void execute() throws NoSuchAlgorithmException, IOException {
printProviderWritten(); printProviderWritten();
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
getOut().println("Cannot roll key: " + keyName + getOut().println("Cannot roll key: " + keyName +
" within KeyProvider: " + provider + ". " + e.toString()); " within KeyProvider: " + provider + ".");
throw e; throw e;
} }
} catch (IOException e1) { } catch (IOException e1) {
getOut().println("Cannot roll key: " + keyName + " within KeyProvider: " getOut().println("Cannot roll key: " + keyName + " within KeyProvider: "
+ provider + ". " + e1.toString()); + provider + ".");
throw e1; throw e1;
} }
} }
@ -374,8 +373,8 @@ public boolean validate() {
} }
return cont; return cont;
} catch (IOException e) { } catch (IOException e) {
getOut().println(keyName + " will not be deleted."); getOut().println(keyName + " will not be deleted. "
e.printStackTrace(getErr()); + prettifyException(e));
} }
} }
return true; return true;
@ -392,7 +391,7 @@ public void execute() throws IOException {
getOut().println(keyName + " has been successfully deleted."); getOut().println(keyName + " has been successfully deleted.");
printProviderWritten(); printProviderWritten();
} catch (IOException e) { } catch (IOException e) {
getOut().println(keyName + " has not been deleted. " + e.toString()); getOut().println(keyName + " has not been deleted.");
throw e; throw e;
} }
} }
@ -463,13 +462,13 @@ public void execute() throws IOException, NoSuchAlgorithmException {
"with options " + options.toString() + "."); "with options " + options.toString() + ".");
printProviderWritten(); printProviderWritten();
} catch (InvalidParameterException e) { } catch (InvalidParameterException e) {
getOut().println(keyName + " has not been created. " + e.toString()); getOut().println(keyName + " has not been created.");
throw e; throw e;
} catch (IOException e) { } catch (IOException e) {
getOut().println(keyName + " has not been created. " + e.toString()); getOut().println(keyName + " has not been created.");
throw e; throw e;
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
getOut().println(keyName + " has not been created. " + e.toString()); getOut().println(keyName + " has not been created.");
throw e; throw e;
} }
} }
@ -520,7 +519,7 @@ public void execute() throws NoSuchAlgorithmException, IOException {
printProviderWritten(); printProviderWritten();
} catch (IOException e) { } catch (IOException e) {
getOut().println("Cannot invalidate cache for key: " + keyName + getOut().println("Cannot invalidate cache for key: " + keyName +
" within KeyProvider: " + provider + ". " + e.toString()); " within KeyProvider: " + provider + ".");
throw e; throw e;
} }
} }
@ -531,6 +530,17 @@ public String getUsage() {
} }
} }
@Override
protected void printException(Exception e){
getErr().println("Executing command failed with " +
"the following exception: " + prettifyException(e));
}
private String prettifyException(Exception e) {
return e.getClass().getSimpleName() + ": " +
e.getLocalizedMessage().split("\n")[0];
}
/** /**
* main() entry point for the KeyShell. While strictly speaking the * main() entry point for the KeyShell. While strictly speaking the
* return is void, it will System.exit() with a return code: 0 is for * return is void, it will System.exit() with a return code: 0 is for

View File

@ -145,7 +145,7 @@ private <T> T doOp(ProviderCallable<T> op, int currPos)
// compatible with earlier versions of LBKMSCP // compatible with earlier versions of LBKMSCP
if (action.action == RetryAction.RetryDecision.FAIL if (action.action == RetryAction.RetryDecision.FAIL
&& numFailovers >= providers.length - 1) { && numFailovers >= providers.length - 1) {
LOG.warn("Aborting since the Request has failed with all KMS" LOG.error("Aborting since the Request has failed with all KMS"
+ " providers(depending on {}={} setting and numProviders={})" + " providers(depending on {}={} setting and numProviders={})"
+ " in the group OR the exception is not recoverable", + " in the group OR the exception is not recoverable",
CommonConfigurationKeysPublic.KMS_CLIENT_FAILOVER_MAX_RETRIES_KEY, CommonConfigurationKeysPublic.KMS_CLIENT_FAILOVER_MAX_RETRIES_KEY,

View File

@ -76,7 +76,7 @@ public int run(String[] args) throws Exception {
} }
} catch (Exception e) { } catch (Exception e) {
printShellUsage(); printShellUsage();
e.printStackTrace(err); printException(e);
return 1; return 1;
} }
return exitCode; return exitCode;
@ -98,6 +98,10 @@ protected final void printShellUsage() {
out.flush(); out.flush();
} }
protected void printException(Exception ex){
ex.printStackTrace(err);
}
/** /**
* Base class for any subcommands of this shell command. * Base class for any subcommands of this shell command.
*/ */