From common-commits-return-79162-archive-asf-public=cust-asf.ponee.io@hadoop.apache.org Tue Feb 27 16:39:12 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 1BB59180651 for ; Tue, 27 Feb 2018 16:39:11 +0100 (CET) Received: (qmail 2757 invoked by uid 500); 27 Feb 2018 15:39:11 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 2748 invoked by uid 99); 27 Feb 2018 15:39:11 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Feb 2018 15:39:11 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 47D3DF3297; Tue, 27 Feb 2018 15:39:09 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: arp@apache.org To: common-commits@hadoop.apache.org Date: Tue, 27 Feb 2018 15:39:09 -0000 Message-Id: <8940e5a035a948fea85ee0df543b3e21@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] hadoop git commit: HADOOP-15178. Generalize NetUtils#wrapException to handle other subclasses with String Constructor. Contributed by Ajay Kumar. Repository: hadoop Updated Branches: refs/heads/branch-3.1 e54c76625 -> 4d1d1d7ae refs/heads/trunk 1e85a995d -> 28f644bf2 HADOOP-15178. Generalize NetUtils#wrapException to handle other subclasses with String Constructor. Contributed by Ajay Kumar. Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/28f644bf Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/28f644bf Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/28f644bf Branch: refs/heads/trunk Commit: 28f644bf25b80a6642ce1f32f1688a8d8f4c7cca Parents: 1e85a99 Author: Arpit Agarwal Authored: Tue Feb 27 07:38:29 2018 -0800 Committer: Arpit Agarwal Committed: Tue Feb 27 07:38:29 2018 -0800 ---------------------------------------------------------------------- .../java/org/apache/hadoop/net/NetUtils.java | 159 ++++++++++--------- .../org/apache/hadoop/net/TestNetUtils.java | 40 +++++ 2 files changed, 123 insertions(+), 76 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/28f644bf/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java index 4697320..e16c2a3 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java @@ -715,9 +715,9 @@ public class NetUtils { * return an IOException with the input exception as the cause and also * include the host details. The new exception provides the stack trace of the * place where the exception is thrown and some extra diagnostics information. - * If the exception is BindException or ConnectException or - * UnknownHostException or SocketTimeoutException, return a new one of the - * same type; Otherwise return an IOException. + * If the exception is of type BindException, ConnectException, + * UnknownHostException, SocketTimeoutException or has a String constructor, + * return a new one of the same type; Otherwise return an IOException. * * @param destHost target host (nullable) * @param destPort target port @@ -731,83 +731,90 @@ public class NetUtils { final String localHost, final int localPort, final IOException exception) { - if (exception instanceof BindException) { - return wrapWithMessage(exception, - "Problem binding to [" - + localHost - + ":" - + localPort - + "] " - + exception - + ";" - + see("BindException")); - } else if (exception instanceof ConnectException) { - // Check if client was trying to connect to an unspecified IPv4 address - // (0.0.0.0) or IPv6 address(0:0:0:0:0:0:0:0 or ::) - if ((destHost != null && (destHost.equals("0.0.0.0") || - destHost.equals("0:0:0:0:0:0:0:0") || destHost.equals("::"))) - || destPort == 0) { - return wrapWithMessage(exception, "Your endpoint configuration" + - " is wrong;" + see("UnsetHostnameOrPort")); - } else { - // connection refused; include the host:port in the error + try { + if (exception instanceof BindException) { return wrapWithMessage(exception, - "Call From " + "Problem binding to [" + localHost - + " to " - + destHost + ":" - + destPort - + " failed on connection exception: " + + localPort + + "] " + exception + ";" - + see("ConnectionRefused")); + + see("BindException")); + } else if (exception instanceof ConnectException) { + // Check if client was trying to connect to an unspecified IPv4 address + // (0.0.0.0) or IPv6 address(0:0:0:0:0:0:0:0 or ::) + if ((destHost != null && (destHost.equals("0.0.0.0") || + destHost.equals("0:0:0:0:0:0:0:0") || destHost.equals("::"))) + || destPort == 0) { + return wrapWithMessage(exception, "Your endpoint configuration" + + " is wrong;" + see("UnsetHostnameOrPort")); + } else { + // connection refused; include the host:port in the error + return wrapWithMessage(exception, + "Call From " + + localHost + + " to " + + destHost + + ":" + + destPort + + " failed on connection exception: " + + exception + + ";" + + see("ConnectionRefused")); + } + } else if (exception instanceof UnknownHostException) { + return wrapWithMessage(exception, + "Invalid host name: " + + getHostDetailsAsString(destHost, destPort, localHost) + + exception + + ";" + + see("UnknownHost")); + } else if (exception instanceof SocketTimeoutException) { + return wrapWithMessage(exception, + "Call From " + + localHost + " to " + destHost + ":" + destPort + + " failed on socket timeout exception: " + exception + + ";" + + see("SocketTimeout")); + } else if (exception instanceof NoRouteToHostException) { + return wrapWithMessage(exception, + "No Route to Host from " + + localHost + " to " + destHost + ":" + destPort + + " failed on socket timeout exception: " + exception + + ";" + + see("NoRouteToHost")); + } else if (exception instanceof EOFException) { + return wrapWithMessage(exception, + "End of File Exception between " + + getHostDetailsAsString(destHost, destPort, localHost) + + ": " + exception + + ";" + + see("EOFException")); + } else if (exception instanceof SocketException) { + // Many of the predecessor exceptions are subclasses of SocketException, + // so must be handled before this + return wrapWithMessage(exception, + "Call From " + + localHost + " to " + destHost + ":" + destPort + + " failed on socket exception: " + exception + + ";" + + see("SocketException")); + } else { + // Return instance of same type if Exception has a String constructor + return wrapWithMessage(exception, + "DestHost:destPort " + destHost + ":" + destPort + + " , LocalHost:localPort " + localHost + + ":" + localPort + ". Failed on local exception: " + + exception); + } - } else if (exception instanceof UnknownHostException) { - return wrapWithMessage(exception, - "Invalid host name: " - + getHostDetailsAsString(destHost, destPort, localHost) - + exception - + ";" - + see("UnknownHost")); - } else if (exception instanceof SocketTimeoutException) { - return wrapWithMessage(exception, - "Call From " - + localHost + " to " + destHost + ":" + destPort - + " failed on socket timeout exception: " + exception - + ";" - + see("SocketTimeout")); - } else if (exception instanceof NoRouteToHostException) { - return wrapWithMessage(exception, - "No Route to Host from " - + localHost + " to " + destHost + ":" + destPort - + " failed on socket timeout exception: " + exception - + ";" - + see("NoRouteToHost")); - } else if (exception instanceof EOFException) { - return wrapWithMessage(exception, - "End of File Exception between " - + getHostDetailsAsString(destHost, destPort, localHost) - + ": " + exception - + ";" - + see("EOFException")); - } else if (exception instanceof SocketException) { - // Many of the predecessor exceptions are subclasses of SocketException, - // so must be handled before this - return wrapWithMessage(exception, - "Call From " - + localHost + " to " + destHost + ":" + destPort - + " failed on socket exception: " + exception - + ";" - + see("SocketException")); - } - else { + } catch (IOException ex) { return (IOException) new IOException("Failed on local exception: " - + exception - + "; Host Details : " - + getHostDetailsAsString(destHost, destPort, localHost)) + + exception + "; Host Details : " + + getHostDetailsAsString(destHost, destPort, localHost)) .initCause(exception); - } } @@ -817,16 +824,16 @@ public class NetUtils { @SuppressWarnings("unchecked") private static T wrapWithMessage( - T exception, String msg) { + T exception, String msg) throws T { Class clazz = exception.getClass(); try { Constructor ctor = clazz.getConstructor(String.class); Throwable t = ctor.newInstance(msg); return (T)(t.initCause(exception)); } catch (Throwable e) { - LOG.warn("Unable to wrap exception of type " + - clazz + ": it has no (String) constructor", e); - return exception; + LOG.warn("Unable to wrap exception of type {}: it has no (String) " + + "constructor", clazz, e); + throw exception; } } http://git-wip-us.apache.org/repos/asf/hadoop/blob/28f644bf/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestNetUtils.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestNetUtils.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestNetUtils.java index fc1c102..b463c95 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestNetUtils.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/TestNetUtils.java @@ -32,6 +32,7 @@ import java.net.SocketException; import java.net.SocketTimeoutException; import java.net.URI; import java.net.UnknownHostException; +import java.nio.charset.CharacterCodingException; import java.util.Arrays; import java.util.Enumeration; import java.util.List; @@ -40,6 +41,7 @@ import java.util.concurrent.TimeUnit; import org.apache.commons.lang.StringUtils; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.io.IOUtils; +import org.apache.hadoop.security.KerberosAuthException; import org.apache.hadoop.security.NetUtilsTestResolver; import org.junit.Assume; import org.junit.Before; @@ -263,6 +265,44 @@ public class TestNetUtils { } @Test + public void testWrapKerbAuthException() throws Throwable { + IOException e = new KerberosAuthException("socket timeout on connection"); + IOException wrapped = verifyExceptionClass(e, KerberosAuthException.class); + assertInException(wrapped, "socket timeout on connection"); + assertInException(wrapped, "localhost"); + assertInException(wrapped, "DestHost:destPort "); + assertInException(wrapped, "LocalHost:localPort"); + assertRemoteDetailsIncluded(wrapped); + assertInException(wrapped, "KerberosAuthException"); + } + + @Test + public void testWrapIOEWithNoStringConstructor() throws Throwable { + IOException e = new CharacterCodingException(); + IOException wrapped = verifyExceptionClass(e, IOException.class); + assertInException(wrapped, "Failed on local exception"); + assertNotInException(wrapped, NetUtils.HADOOP_WIKI); + assertInException(wrapped, "Host Details "); + assertRemoteDetailsIncluded(wrapped); + } + + @Test + public void testWrapIOEWithPrivateStringConstructor() throws Throwable { + class TestIOException extends CharacterCodingException{ + private TestIOException(String cause){ + } + TestIOException(){ + } + } + IOException e = new TestIOException(); + IOException wrapped = verifyExceptionClass(e, IOException.class); + assertInException(wrapped, "Failed on local exception"); + assertNotInException(wrapped, NetUtils.HADOOP_WIKI); + assertInException(wrapped, "Host Details "); + assertRemoteDetailsIncluded(wrapped); + } + + @Test public void testWrapSocketException() throws Throwable { IOException wrapped = verifyExceptionClass(new SocketException("failed"), SocketException.class); --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org For additional commands, e-mail: common-commits-help@hadoop.apache.org