diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/main/java/org/apache/hadoop/mapreduce/v2/api/impl/pb/client/MRClientProtocolPBClientImpl.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/main/java/org/apache/hadoop/mapreduce/v2/api/impl/pb/client/MRClientProtocolPBClientImpl.java index d8aa812f29..07db42e50b 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/main/java/org/apache/hadoop/mapreduce/v2/api/impl/pb/client/MRClientProtocolPBClientImpl.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/main/java/org/apache/hadoop/mapreduce/v2/api/impl/pb/client/MRClientProtocolPBClientImpl.java @@ -98,7 +98,7 @@ import org.apache.hadoop.security.proto.SecurityProtos.CancelDelegationTokenRequ import org.apache.hadoop.security.proto.SecurityProtos.GetDelegationTokenRequestProto; import org.apache.hadoop.security.proto.SecurityProtos.RenewDelegationTokenRequestProto; import org.apache.hadoop.yarn.exceptions.YarnRemoteException; -import org.apache.hadoop.yarn.exceptions.impl.pb.YarnRemoteExceptionPBImpl; +import org.apache.hadoop.yarn.ipc.RPCUtil; import com.google.protobuf.ServiceException; @@ -133,7 +133,7 @@ public class MRClientProtocolPBClientImpl implements MRClientProtocol, try { return new GetJobReportResponsePBImpl(proxy.getJobReport(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -144,7 +144,7 @@ public class MRClientProtocolPBClientImpl implements MRClientProtocol, try { return new GetTaskReportResponsePBImpl(proxy.getTaskReport(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -155,7 +155,7 @@ public class MRClientProtocolPBClientImpl implements MRClientProtocol, try { return new GetTaskAttemptReportResponsePBImpl(proxy.getTaskAttemptReport(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -166,7 +166,7 @@ public class MRClientProtocolPBClientImpl implements MRClientProtocol, try { return new GetCountersResponsePBImpl(proxy.getCounters(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -177,7 +177,7 @@ public class MRClientProtocolPBClientImpl implements MRClientProtocol, try { return new GetTaskAttemptCompletionEventsResponsePBImpl(proxy.getTaskAttemptCompletionEvents(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -188,7 +188,7 @@ public class MRClientProtocolPBClientImpl implements MRClientProtocol, try { return new GetTaskReportsResponsePBImpl(proxy.getTaskReports(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -199,7 +199,7 @@ public class MRClientProtocolPBClientImpl implements MRClientProtocol, try { return new GetDiagnosticsResponsePBImpl(proxy.getDiagnostics(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -212,7 +212,7 @@ public class MRClientProtocolPBClientImpl implements MRClientProtocol, return new GetDelegationTokenResponsePBImpl(proxy.getDelegationToken( null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -223,7 +223,7 @@ public class MRClientProtocolPBClientImpl implements MRClientProtocol, try { return new KillJobResponsePBImpl(proxy.killJob(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -234,7 +234,7 @@ public class MRClientProtocolPBClientImpl implements MRClientProtocol, try { return new KillTaskResponsePBImpl(proxy.killTask(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -245,7 +245,7 @@ public class MRClientProtocolPBClientImpl implements MRClientProtocol, try { return new KillTaskAttemptResponsePBImpl(proxy.killTaskAttempt(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -256,7 +256,7 @@ public class MRClientProtocolPBClientImpl implements MRClientProtocol, try { return new FailTaskAttemptResponsePBImpl(proxy.failTaskAttempt(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -269,7 +269,7 @@ public class MRClientProtocolPBClientImpl implements MRClientProtocol, return new RenewDelegationTokenResponsePBImpl(proxy.renewDelegationToken( null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -283,7 +283,7 @@ public class MRClientProtocolPBClientImpl implements MRClientProtocol, proxy.cancelDelegationToken(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } } diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index 22524f982b..9a24a27adb 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -204,6 +204,9 @@ Release 2.0.5-beta - UNRELEASED YARN-618. Modified RM_INVALID_IDENTIFIER to be -1 instead of zero. (Jian He via vinodkv) + YARN-625. Move the utility method unwrapAndThrowException from + YarnRemoteExceptionPBImpl to RPCUtil. (Siddharth Seth via vinodkv) + OPTIMIZATIONS BUG FIXES diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/exceptions/impl/pb/YarnRemoteExceptionPBImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/exceptions/impl/pb/YarnRemoteExceptionPBImpl.java index ae17ed0f8e..7a00010dcd 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/exceptions/impl/pb/YarnRemoteExceptionPBImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/exceptions/impl/pb/YarnRemoteExceptionPBImpl.java @@ -109,30 +109,5 @@ public class YarnRemoteExceptionPBImpl extends YarnRemoteException { } viaProto = false; } - - /** - * Utility method that unwraps and throws appropriate exception. - * @param se ServiceException - * @throws YarnRemoteException - * @throws UndeclaredThrowableException - */ - public static YarnRemoteException unwrapAndThrowException(ServiceException se) - throws UndeclaredThrowableException { - if (se.getCause() instanceof RemoteException) { - try { - throw ((RemoteException) se.getCause()) - .unwrapRemoteException(YarnRemoteExceptionPBImpl.class); - } catch (YarnRemoteException ex) { - return ex; - } catch (IOException e1) { - throw new UndeclaredThrowableException(e1); - } - } else if (se.getCause() instanceof YarnRemoteException) { - return (YarnRemoteException)se.getCause(); - } else if (se.getCause() instanceof UndeclaredThrowableException) { - throw (UndeclaredThrowableException)se.getCause(); - } else { - throw new UndeclaredThrowableException(se); - } - } + } \ No newline at end of file diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/impl/pb/client/AMRMProtocolPBClientImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/impl/pb/client/AMRMProtocolPBClientImpl.java index 382d913eef..497577d2c4 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/impl/pb/client/AMRMProtocolPBClientImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/impl/pb/client/AMRMProtocolPBClientImpl.java @@ -40,7 +40,7 @@ import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.FinishApplicationMaste import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.RegisterApplicationMasterRequestPBImpl; import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.RegisterApplicationMasterResponsePBImpl; import org.apache.hadoop.yarn.exceptions.YarnRemoteException; -import org.apache.hadoop.yarn.exceptions.impl.pb.YarnRemoteExceptionPBImpl; +import org.apache.hadoop.yarn.ipc.RPCUtil; import org.apache.hadoop.yarn.proto.YarnServiceProtos.AllocateRequestProto; import org.apache.hadoop.yarn.proto.YarnServiceProtos.FinishApplicationMasterRequestProto; import org.apache.hadoop.yarn.proto.YarnServiceProtos.RegisterApplicationMasterRequestProto; @@ -74,7 +74,7 @@ public class AMRMProtocolPBClientImpl implements AMRMProtocol, Closeable { try { return new AllocateResponsePBImpl(proxy.allocate(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -87,7 +87,7 @@ public class AMRMProtocolPBClientImpl implements AMRMProtocol, Closeable { return new FinishApplicationMasterResponsePBImpl( proxy.finishApplicationMaster(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -100,7 +100,7 @@ public class AMRMProtocolPBClientImpl implements AMRMProtocol, Closeable { return new RegisterApplicationMasterResponsePBImpl( proxy.registerApplicationMaster(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/impl/pb/client/ClientRMProtocolPBClientImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/impl/pb/client/ClientRMProtocolPBClientImpl.java index 25212b8300..94e692f25c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/impl/pb/client/ClientRMProtocolPBClientImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/impl/pb/client/ClientRMProtocolPBClientImpl.java @@ -79,7 +79,7 @@ import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.RenewDelegationTokenRe import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.SubmitApplicationRequestPBImpl; import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.SubmitApplicationResponsePBImpl; import org.apache.hadoop.yarn.exceptions.YarnRemoteException; -import org.apache.hadoop.yarn.exceptions.impl.pb.YarnRemoteExceptionPBImpl; +import org.apache.hadoop.yarn.ipc.RPCUtil; import org.apache.hadoop.yarn.proto.YarnServiceProtos.GetAllApplicationsRequestProto; import org.apache.hadoop.yarn.proto.YarnServiceProtos.GetApplicationReportRequestProto; import org.apache.hadoop.yarn.proto.YarnServiceProtos.GetClusterMetricsRequestProto; @@ -120,7 +120,7 @@ public class ClientRMProtocolPBClientImpl implements ClientRMProtocol, return new KillApplicationResponsePBImpl(proxy.forceKillApplication(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -133,7 +133,7 @@ public class ClientRMProtocolPBClientImpl implements ClientRMProtocol, return new GetApplicationReportResponsePBImpl(proxy.getApplicationReport( null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -146,7 +146,7 @@ public class ClientRMProtocolPBClientImpl implements ClientRMProtocol, return new GetClusterMetricsResponsePBImpl(proxy.getClusterMetrics(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -159,7 +159,7 @@ public class ClientRMProtocolPBClientImpl implements ClientRMProtocol, return new GetNewApplicationResponsePBImpl(proxy.getNewApplication(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -172,7 +172,7 @@ public class ClientRMProtocolPBClientImpl implements ClientRMProtocol, return new SubmitApplicationResponsePBImpl(proxy.submitApplication(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -185,7 +185,7 @@ public class ClientRMProtocolPBClientImpl implements ClientRMProtocol, return new GetAllApplicationsResponsePBImpl(proxy.getAllApplications( null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -199,7 +199,7 @@ public class ClientRMProtocolPBClientImpl implements ClientRMProtocol, return new GetClusterNodesResponsePBImpl(proxy.getClusterNodes(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -212,7 +212,7 @@ public class ClientRMProtocolPBClientImpl implements ClientRMProtocol, return new GetQueueInfoResponsePBImpl(proxy.getQueueInfo(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -225,7 +225,7 @@ public class ClientRMProtocolPBClientImpl implements ClientRMProtocol, return new GetQueueUserAclsInfoResponsePBImpl(proxy.getQueueUserAcls( null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -238,7 +238,7 @@ public class ClientRMProtocolPBClientImpl implements ClientRMProtocol, return new GetDelegationTokenResponsePBImpl(proxy.getDelegationToken( null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -251,7 +251,7 @@ public class ClientRMProtocolPBClientImpl implements ClientRMProtocol, return new RenewDelegationTokenResponsePBImpl(proxy.renewDelegationToken( null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -265,7 +265,7 @@ public class ClientRMProtocolPBClientImpl implements ClientRMProtocol, proxy.cancelDelegationToken(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/impl/pb/client/ContainerManagerPBClientImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/impl/pb/client/ContainerManagerPBClientImpl.java index cff287a90a..15ce6dea86 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/impl/pb/client/ContainerManagerPBClientImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/impl/pb/client/ContainerManagerPBClientImpl.java @@ -43,7 +43,7 @@ import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.StopContainerRequestPB import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.StopContainerResponsePBImpl; import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.exceptions.YarnRemoteException; -import org.apache.hadoop.yarn.exceptions.impl.pb.YarnRemoteExceptionPBImpl; +import org.apache.hadoop.yarn.ipc.RPCUtil; import org.apache.hadoop.yarn.proto.YarnServiceProtos.GetContainerStatusRequestProto; import org.apache.hadoop.yarn.proto.YarnServiceProtos.StartContainerRequestProto; import org.apache.hadoop.yarn.proto.YarnServiceProtos.StopContainerRequestProto; @@ -93,7 +93,7 @@ public class ContainerManagerPBClientImpl implements ContainerManager, return new GetContainerStatusResponsePBImpl(proxy.getContainerStatus( null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -106,7 +106,7 @@ public class ContainerManagerPBClientImpl implements ContainerManager, return new StartContainerResponsePBImpl(proxy.startContainer(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -119,7 +119,7 @@ public class ContainerManagerPBClientImpl implements ContainerManager, return new StopContainerResponsePBImpl(proxy.stopContainer(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/impl/pb/client/RMAdminProtocolPBClientImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/impl/pb/client/RMAdminProtocolPBClientImpl.java index f7b39f218b..3a85270dc9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/impl/pb/client/RMAdminProtocolPBClientImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/impl/pb/client/RMAdminProtocolPBClientImpl.java @@ -53,7 +53,7 @@ import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.RefreshSuperUserGroups import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.RefreshUserToGroupsMappingsRequestPBImpl; import org.apache.hadoop.yarn.api.protocolrecords.impl.pb.RefreshUserToGroupsMappingsResponsePBImpl; import org.apache.hadoop.yarn.exceptions.YarnRemoteException; -import org.apache.hadoop.yarn.exceptions.impl.pb.YarnRemoteExceptionPBImpl; +import org.apache.hadoop.yarn.ipc.RPCUtil; import org.apache.hadoop.yarn.proto.YarnServerResourceManagerServiceProtos.GetGroupsForUserRequestProto; import org.apache.hadoop.yarn.proto.YarnServerResourceManagerServiceProtos.GetGroupsForUserResponseProto; import org.apache.hadoop.yarn.proto.YarnServerResourceManagerServiceProtos.RefreshAdminAclsRequestProto; @@ -94,7 +94,7 @@ public class RMAdminProtocolPBClientImpl implements RMAdminProtocol, Closeable { return new RefreshQueuesResponsePBImpl( proxy.refreshQueues(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -107,7 +107,7 @@ public class RMAdminProtocolPBClientImpl implements RMAdminProtocol, Closeable { return new RefreshNodesResponsePBImpl( proxy.refreshNodes(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -121,7 +121,7 @@ public class RMAdminProtocolPBClientImpl implements RMAdminProtocol, Closeable { return new RefreshSuperUserGroupsConfigurationResponsePBImpl( proxy.refreshSuperUserGroupsConfiguration(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -134,7 +134,7 @@ public class RMAdminProtocolPBClientImpl implements RMAdminProtocol, Closeable { return new RefreshUserToGroupsMappingsResponsePBImpl( proxy.refreshUserToGroupsMappings(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -147,7 +147,7 @@ public class RMAdminProtocolPBClientImpl implements RMAdminProtocol, Closeable { return new RefreshAdminAclsResponsePBImpl( proxy.refreshAdminAcls(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -160,7 +160,7 @@ public class RMAdminProtocolPBClientImpl implements RMAdminProtocol, Closeable { return new RefreshServiceAclsResponsePBImpl(proxy.refreshServiceAcls( null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/ipc/RPCUtil.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/ipc/RPCUtil.java index 798af127f4..856c10b54c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/ipc/RPCUtil.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/ipc/RPCUtil.java @@ -18,11 +18,18 @@ package org.apache.hadoop.yarn.ipc; +import java.io.IOException; +import java.lang.reflect.UndeclaredThrowableException; + import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.ipc.RemoteException; import org.apache.hadoop.yarn.exceptions.YarnRemoteException; +import org.apache.hadoop.yarn.exceptions.impl.pb.YarnRemoteExceptionPBImpl; import org.apache.hadoop.yarn.factories.YarnRemoteExceptionFactory; import org.apache.hadoop.yarn.factory.providers.YarnRemoteExceptionFactoryProvider; +import com.google.protobuf.ServiceException; + public class RPCUtil { @@ -52,4 +59,31 @@ public class RPCUtil { (e.getRemoteTrace() == null ? "" : "\n StackTrace: " + e.getRemoteTrace()) + (e.getCause() == null ? "" : "\n Caused by: " + toString(e.getCause())); } + + /** + * Utility method that unwraps and throws appropriate exception. + * + * @param se ServiceException + * @throws YarnRemoteException + * @throws UndeclaredThrowableException + */ + public static YarnRemoteException unwrapAndThrowException(ServiceException se) + throws UndeclaredThrowableException { + if (se.getCause() instanceof RemoteException) { + try { + throw ((RemoteException) se.getCause()) + .unwrapRemoteException(YarnRemoteExceptionPBImpl.class); + } catch (YarnRemoteException ex) { + return ex; + } catch (IOException e1) { + throw new UndeclaredThrowableException(e1); + } + } else if (se.getCause() instanceof YarnRemoteException) { + return (YarnRemoteException) se.getCause(); + } else if (se.getCause() instanceof UndeclaredThrowableException) { + throw (UndeclaredThrowableException) se.getCause(); + } else { + throw new UndeclaredThrowableException(se); + } + } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/impl/pb/client/ResourceTrackerPBClientImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/impl/pb/client/ResourceTrackerPBClientImpl.java index 88c3b0d524..7ecfb203b1 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/impl/pb/client/ResourceTrackerPBClientImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-common/src/main/java/org/apache/hadoop/yarn/server/api/impl/pb/client/ResourceTrackerPBClientImpl.java @@ -25,7 +25,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.ipc.ProtobufRpcEngine; import org.apache.hadoop.ipc.RPC; import org.apache.hadoop.yarn.exceptions.YarnRemoteException; -import org.apache.hadoop.yarn.exceptions.impl.pb.YarnRemoteExceptionPBImpl; +import org.apache.hadoop.yarn.ipc.RPCUtil; import org.apache.hadoop.yarn.proto.YarnServerCommonServiceProtos.NodeHeartbeatRequestProto; import org.apache.hadoop.yarn.proto.YarnServerCommonServiceProtos.RegisterNodeManagerRequestProto; import org.apache.hadoop.yarn.server.api.ResourceTracker; @@ -58,7 +58,7 @@ private ResourceTrackerPB proxy; try { return new RegisterNodeManagerResponsePBImpl(proxy.registerNodeManager(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } @@ -69,7 +69,7 @@ private ResourceTrackerPB proxy; try { return new NodeHeartbeatResponsePBImpl(proxy.nodeHeartbeat(null, requestProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/api/impl/pb/client/LocalizationProtocolPBClientImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/api/impl/pb/client/LocalizationProtocolPBClientImpl.java index 257417d0db..aedf9c13e4 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/api/impl/pb/client/LocalizationProtocolPBClientImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/api/impl/pb/client/LocalizationProtocolPBClientImpl.java @@ -25,7 +25,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.ipc.ProtobufRpcEngine; import org.apache.hadoop.ipc.RPC; import org.apache.hadoop.yarn.exceptions.YarnRemoteException; -import org.apache.hadoop.yarn.exceptions.impl.pb.YarnRemoteExceptionPBImpl; +import org.apache.hadoop.yarn.ipc.RPCUtil; import org.apache.hadoop.yarn.proto.YarnServerNodemanagerServiceProtos.LocalizerStatusProto; import org.apache.hadoop.yarn.server.nodemanager.api.LocalizationProtocol; import org.apache.hadoop.yarn.server.nodemanager.api.LocalizationProtocolPB; @@ -62,7 +62,7 @@ public class LocalizationProtocolPBClientImpl implements LocalizationProtocol, return new LocalizerHeartbeatResponsePBImpl( proxy.heartbeat(null, statusProto)); } catch (ServiceException e) { - throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e); + throw RPCUtil.unwrapAndThrowException(e); } }