From 52703c2d0d9e2ad89d0ffca079e37eee339b89b7 Mon Sep 17 00:00:00 2001 From: Siddharth Seth Date: Tue, 5 Mar 2013 17:56:17 +0000 Subject: [PATCH] HADOOP-9343. Allow additional exceptions through the RPC layer. (sseth) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1452918 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-common/CHANGES.txt | 2 ++ .../java/org/apache/hadoop/ipc/Server.java | 4 +++ .../hadoop/security/UserGroupInformation.java | 2 +- .../apache/hadoop/ipc/TestProtoBufRpc.java | 28 +++++++++++++++++-- .../src/test/proto/test_rpc_service.proto | 1 + 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 2a8dfcd674..3f9b47b331 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 c43b8a9029..a859138fd9 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.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 Writable run() throws Exception { ); } } 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 afca92f3cc..f2c74d8f65 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 T doAs(PrivilegedExceptionAction action } 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 54e227a26b..2dcf2fb16e 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 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 EmptyResponseProto error(RpcController unused, 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 @@ private static TestRpcService2 getClient2() throws IOException { conf); } - @Test + @Test (timeout=5000) public void testProtoBufRpc() throws Exception { TestRpcService client = getClient(); testProtoBufRpc(client); @@ -178,7 +186,7 @@ public static void testProtoBufRpc(TestRpcService client) throws Exception { } } - @Test + @Test (timeout=5000) public void testProtoBufRpc2() throws Exception { TestRpcService2 client = getClient2(); @@ -201,4 +209,20 @@ public void testProtoBufRpc2() throws Exception { 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 7f70c3a99d..1d54e45d5a 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 {