diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 2a8dfcd674e..3f9b47b3316 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -363,6 +363,8 @@ Release 2.0.4-beta - UNRELEASED HADOOP-9334. Upgrade netty version. (Nicolas Liochon via suresh) + HADOOP-9343. Allow additional exceptions through the RPC layer. (sseth) + OPTIMIZATIONS BUG FIXES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Server.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Server.java index c43b8a9029a..a859138fd9d 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Server.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Server.java @@ -24,6 +24,7 @@ import java.io.DataInputStream; import java.io.DataOutput; import java.io.DataOutputStream; import java.io.IOException; +import java.lang.reflect.UndeclaredThrowableException; import java.net.BindException; import java.net.InetAddress; import java.net.InetSocketAddress; @@ -1788,6 +1789,9 @@ public abstract class Server { ); } } catch (Throwable e) { + if (e instanceof UndeclaredThrowableException) { + e = e.getCause(); + } String logMsg = getName() + ", call " + call + ": error: " + e; if (e instanceof RuntimeException || e instanceof Error) { // These exception types indicate something is probably wrong diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/UserGroupInformation.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/UserGroupInformation.java index afca92f3cc7..f2c74d8f654 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/UserGroupInformation.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/UserGroupInformation.java @@ -1501,7 +1501,7 @@ public class UserGroupInformation { } else if (cause instanceof InterruptedException) { throw (InterruptedException) cause; } else { - throw new UndeclaredThrowableException(pae,"Unknown exception in doAs"); + throw new UndeclaredThrowableException(cause); } } } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestProtoBufRpc.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestProtoBufRpc.java index 54e227a26bb..2dcf2fb16ef 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestProtoBufRpc.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestProtoBufRpc.java @@ -22,6 +22,7 @@ import static org.apache.hadoop.test.MetricsAsserts.assertCounterGt; import java.io.IOException; import java.net.InetSocketAddress; +import java.net.URISyntaxException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.ipc.protobuf.TestProtos.EchoRequestProto; @@ -83,6 +84,13 @@ public class TestProtoBufRpc { EmptyRequestProto request) throws ServiceException { throw new ServiceException("error", new RpcServerException("error")); } + + @Override + public EmptyResponseProto error2(RpcController unused, + EmptyRequestProto request) throws ServiceException { + throw new ServiceException("error", new URISyntaxException("", + "testException")); + } } public static class PBServer2Impl implements TestRpcService2 { @@ -149,7 +157,7 @@ public class TestProtoBufRpc { conf); } - @Test + @Test (timeout=5000) public void testProtoBufRpc() throws Exception { TestRpcService client = getClient(); testProtoBufRpc(client); @@ -178,7 +186,7 @@ public class TestProtoBufRpc { } } - @Test + @Test (timeout=5000) public void testProtoBufRpc2() throws Exception { TestRpcService2 client = getClient2(); @@ -201,4 +209,20 @@ public class TestProtoBufRpc { getMetrics(server.getRpcDetailedMetrics().name()); assertCounterGt("Echo2NumOps", 0L, rpcDetailedMetrics); } + + @Test (timeout=5000) + public void testProtoBufRandomException() throws Exception { + TestRpcService client = getClient(); + EmptyRequestProto emptyRequest = EmptyRequestProto.newBuilder().build(); + + try { + client.error2(null, emptyRequest); + } catch (ServiceException se) { + Assert.assertTrue(se.getCause() instanceof RemoteException); + RemoteException re = (RemoteException) se.getCause(); + Assert.assertTrue(re.getClassName().equals( + URISyntaxException.class.getName())); + Assert.assertTrue(re.getMessage().contains("testException")); + } + } } \ No newline at end of file diff --git a/hadoop-common-project/hadoop-common/src/test/proto/test_rpc_service.proto b/hadoop-common-project/hadoop-common/src/test/proto/test_rpc_service.proto index 7f70c3a99de..1d54e45d5a7 100644 --- a/hadoop-common-project/hadoop-common/src/test/proto/test_rpc_service.proto +++ b/hadoop-common-project/hadoop-common/src/test/proto/test_rpc_service.proto @@ -31,6 +31,7 @@ service TestProtobufRpcProto { rpc ping(EmptyRequestProto) returns (EmptyResponseProto); rpc echo(EchoRequestProto) returns (EchoResponseProto); rpc error(EmptyRequestProto) returns (EmptyResponseProto); + rpc error2(EmptyRequestProto) returns (EmptyResponseProto); } service TestProtobufRpc2Proto {