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) {
getOut().println("Cannot list keys for KeyProvider: " + provider
+ ": " + e.toString());
getOut().println("Cannot list keys for KeyProvider: " + provider);
throw e;
}
}
@ -318,12 +317,12 @@ public void execute() throws NoSuchAlgorithmException, IOException {
printProviderWritten();
} catch (NoSuchAlgorithmException e) {
getOut().println("Cannot roll key: " + keyName +
" within KeyProvider: " + provider + ". " + e.toString());
" within KeyProvider: " + provider + ".");
throw e;
}
} catch (IOException e1) {
getOut().println("Cannot roll key: " + keyName + " within KeyProvider: "
+ provider + ". " + e1.toString());
+ provider + ".");
throw e1;
}
}
@ -374,8 +373,8 @@ public boolean validate() {
}
return cont;
} catch (IOException e) {
getOut().println(keyName + " will not be deleted.");
e.printStackTrace(getErr());
getOut().println(keyName + " will not be deleted. "
+ prettifyException(e));
}
}
return true;
@ -392,7 +391,7 @@ public void execute() throws IOException {
getOut().println(keyName + " has been successfully deleted.");
printProviderWritten();
} catch (IOException e) {
getOut().println(keyName + " has not been deleted. " + e.toString());
getOut().println(keyName + " has not been deleted.");
throw e;
}
}
@ -463,13 +462,13 @@ public void execute() throws IOException, NoSuchAlgorithmException {
"with options " + options.toString() + ".");
printProviderWritten();
} catch (InvalidParameterException e) {
getOut().println(keyName + " has not been created. " + e.toString());
getOut().println(keyName + " has not been created.");
throw e;
} catch (IOException e) {
getOut().println(keyName + " has not been created. " + e.toString());
getOut().println(keyName + " has not been created.");
throw e;
} catch (NoSuchAlgorithmException e) {
getOut().println(keyName + " has not been created. " + e.toString());
getOut().println(keyName + " has not been created.");
throw e;
}
}
@ -520,7 +519,7 @@ public void execute() throws NoSuchAlgorithmException, IOException {
printProviderWritten();
} catch (IOException e) {
getOut().println("Cannot invalidate cache for key: " + keyName +
" within KeyProvider: " + provider + ". " + e.toString());
" within KeyProvider: " + provider + ".");
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
* 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
if (action.action == RetryAction.RetryDecision.FAIL
&& 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={})"
+ " in the group OR the exception is not recoverable",
CommonConfigurationKeysPublic.KMS_CLIENT_FAILOVER_MAX_RETRIES_KEY,

View File

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