From d2874e04173613b1a3d44eabf8d449c8a3920fa4 Mon Sep 17 00:00:00 2001 From: Xiao Chen Date: Mon, 16 Jul 2018 13:19:24 -0700 Subject: [PATCH] HDFS-13690. Improve error message when creating encryption zone while KMS is unreachable. Contributed by Kitti Nanasi. --- .../hadoop/crypto/key/kms/KMSClientProvider.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/kms/KMSClientProvider.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/kms/KMSClientProvider.java index 11815da9d2..8125510a72 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/kms/KMSClientProvider.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/kms/KMSClientProvider.java @@ -56,6 +56,7 @@ import java.io.OutputStreamWriter; import java.io.Writer; import java.lang.reflect.UndeclaredThrowableException; +import java.net.ConnectException; import java.net.HttpURLConnection; import java.net.InetSocketAddress; import java.net.MalformedURLException; @@ -478,10 +479,14 @@ public HttpURLConnection run() throws Exception { return authUrl.openConnection(url, authToken, doAsUser); } }); + } catch (ConnectException ex) { + String msg = "Failed to connect to: " + url.toString(); + LOG.warn(msg); + throw new IOException(msg, ex); + } catch (SocketTimeoutException ex) { + LOG.warn("Failed to connect to {}:{}", url.getHost(), url.getPort()); + throw ex; } catch (IOException ex) { - if (ex instanceof SocketTimeoutException) { - LOG.warn("Failed to connect to {}:{}", url.getHost(), url.getPort()); - } throw ex; } catch (UndeclaredThrowableException ex) { throw new IOException(ex.getUndeclaredThrowable());