HDFS-13690. Improve error message when creating encryption zone while KMS is unreachable. Contributed by Kitti Nanasi.

This commit is contained in:
Xiao Chen 2018-07-16 13:19:24 -07:00
parent 0c7a578927
commit d2874e0417
1 changed files with 8 additions and 3 deletions

View File

@ -56,6 +56,7 @@ import java.io.OutputStream;
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 class KMSClientProvider extends KeyProvider implements CryptoExtension,
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());