YARN-625. Move the utility method unwrapAndThrowException from YarnRemoteExceptionPBImpl to RPCUtil. Contributed by Siddharth Seth.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1478594 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Vinod Kumar Vavilapalli 2013-05-02 22:44:12 +00:00
parent afa786098a
commit fc275fed66
10 changed files with 86 additions and 74 deletions

View File

@ -98,7 +98,7 @@
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 GetJobReportResponse getJobReport(GetJobReportRequest request)
try {
return new GetJobReportResponsePBImpl(proxy.getJobReport(null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -144,7 +144,7 @@ public GetTaskReportResponse getTaskReport(GetTaskReportRequest request)
try {
return new GetTaskReportResponsePBImpl(proxy.getTaskReport(null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -155,7 +155,7 @@ public GetTaskAttemptReportResponse getTaskAttemptReport(
try {
return new GetTaskAttemptReportResponsePBImpl(proxy.getTaskAttemptReport(null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -166,7 +166,7 @@ public GetCountersResponse getCounters(GetCountersRequest request)
try {
return new GetCountersResponsePBImpl(proxy.getCounters(null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -177,7 +177,7 @@ public GetTaskAttemptCompletionEventsResponse getTaskAttemptCompletionEvents(
try {
return new GetTaskAttemptCompletionEventsResponsePBImpl(proxy.getTaskAttemptCompletionEvents(null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -188,7 +188,7 @@ public GetTaskReportsResponse getTaskReports(GetTaskReportsRequest request)
try {
return new GetTaskReportsResponsePBImpl(proxy.getTaskReports(null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -199,7 +199,7 @@ public GetDiagnosticsResponse getDiagnostics(GetDiagnosticsRequest request)
try {
return new GetDiagnosticsResponsePBImpl(proxy.getDiagnostics(null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -212,7 +212,7 @@ public GetDelegationTokenResponse getDelegationToken(
return new GetDelegationTokenResponsePBImpl(proxy.getDelegationToken(
null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -223,7 +223,7 @@ public KillJobResponse killJob(KillJobRequest request)
try {
return new KillJobResponsePBImpl(proxy.killJob(null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -234,7 +234,7 @@ public KillTaskResponse killTask(KillTaskRequest request)
try {
return new KillTaskResponsePBImpl(proxy.killTask(null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -245,7 +245,7 @@ public KillTaskAttemptResponse killTaskAttempt(KillTaskAttemptRequest request)
try {
return new KillTaskAttemptResponsePBImpl(proxy.killTaskAttempt(null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -256,7 +256,7 @@ public FailTaskAttemptResponse failTaskAttempt(FailTaskAttemptRequest request)
try {
return new FailTaskAttemptResponsePBImpl(proxy.failTaskAttempt(null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -269,7 +269,7 @@ public RenewDelegationTokenResponse renewDelegationToken(
return new RenewDelegationTokenResponsePBImpl(proxy.renewDelegationToken(
null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -283,7 +283,7 @@ public CancelDelegationTokenResponse cancelDelegationToken(
proxy.cancelDelegationToken(null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
}

View File

@ -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

View File

@ -110,29 +110,4 @@ private void maybeInitBuilder() {
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);
}
}
}

View File

@ -40,7 +40,7 @@
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 AllocateResponse allocate(AllocateRequest request)
try {
return new AllocateResponsePBImpl(proxy.allocate(null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -87,7 +87,7 @@ public FinishApplicationMasterResponse finishApplicationMaster(
return new FinishApplicationMasterResponsePBImpl(
proxy.finishApplicationMaster(null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -100,7 +100,7 @@ public RegisterApplicationMasterResponse registerApplicationMaster(
return new RegisterApplicationMasterResponsePBImpl(
proxy.registerApplicationMaster(null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
}

View File

@ -79,7 +79,7 @@
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 KillApplicationResponse forceKillApplication(
return new KillApplicationResponsePBImpl(proxy.forceKillApplication(null,
requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -133,7 +133,7 @@ public GetApplicationReportResponse getApplicationReport(
return new GetApplicationReportResponsePBImpl(proxy.getApplicationReport(
null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -146,7 +146,7 @@ public GetClusterMetricsResponse getClusterMetrics(
return new GetClusterMetricsResponsePBImpl(proxy.getClusterMetrics(null,
requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -159,7 +159,7 @@ public GetNewApplicationResponse getNewApplication(
return new GetNewApplicationResponsePBImpl(proxy.getNewApplication(null,
requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -172,7 +172,7 @@ public SubmitApplicationResponse submitApplication(
return new SubmitApplicationResponsePBImpl(proxy.submitApplication(null,
requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -185,7 +185,7 @@ public GetAllApplicationsResponse getAllApplications(
return new GetAllApplicationsResponsePBImpl(proxy.getAllApplications(
null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -199,7 +199,7 @@ public GetAllApplicationsResponse getAllApplications(
return new GetClusterNodesResponsePBImpl(proxy.getClusterNodes(null,
requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -212,7 +212,7 @@ public GetQueueInfoResponse getQueueInfo(GetQueueInfoRequest request)
return new GetQueueInfoResponsePBImpl(proxy.getQueueInfo(null,
requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -225,7 +225,7 @@ public GetQueueUserAclsInfoResponse getQueueUserAcls(
return new GetQueueUserAclsInfoResponsePBImpl(proxy.getQueueUserAcls(
null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -238,7 +238,7 @@ public GetDelegationTokenResponse getDelegationToken(
return new GetDelegationTokenResponsePBImpl(proxy.getDelegationToken(
null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -251,7 +251,7 @@ public RenewDelegationTokenResponse renewDelegationToken(
return new RenewDelegationTokenResponsePBImpl(proxy.renewDelegationToken(
null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -265,7 +265,7 @@ public CancelDelegationTokenResponse cancelDelegationToken(
proxy.cancelDelegationToken(null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
}

View File

@ -43,7 +43,7 @@
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 GetContainerStatusResponse getContainerStatus(
return new GetContainerStatusResponsePBImpl(proxy.getContainerStatus(
null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -106,7 +106,7 @@ public StartContainerResponse startContainer(StartContainerRequest request)
return new StartContainerResponsePBImpl(proxy.startContainer(null,
requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -119,7 +119,7 @@ public StopContainerResponse stopContainer(StopContainerRequest request)
return new StopContainerResponsePBImpl(proxy.stopContainer(null,
requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
}

View File

@ -53,7 +53,7 @@
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 RefreshQueuesResponse refreshQueues(RefreshQueuesRequest request)
return new RefreshQueuesResponsePBImpl(
proxy.refreshQueues(null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -107,7 +107,7 @@ public RefreshNodesResponse refreshNodes(RefreshNodesRequest request)
return new RefreshNodesResponsePBImpl(
proxy.refreshNodes(null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -121,7 +121,7 @@ public RefreshSuperUserGroupsConfigurationResponse refreshSuperUserGroupsConfigu
return new RefreshSuperUserGroupsConfigurationResponsePBImpl(
proxy.refreshSuperUserGroupsConfiguration(null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -134,7 +134,7 @@ public RefreshUserToGroupsMappingsResponse refreshUserToGroupsMappings(
return new RefreshUserToGroupsMappingsResponsePBImpl(
proxy.refreshUserToGroupsMappings(null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -147,7 +147,7 @@ public RefreshAdminAclsResponse refreshAdminAcls(
return new RefreshAdminAclsResponsePBImpl(
proxy.refreshAdminAcls(null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -160,7 +160,7 @@ public RefreshServiceAclsResponse refreshServiceAcls(
return new RefreshServiceAclsResponsePBImpl(proxy.refreshServiceAcls(
null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}

View File

@ -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 static String toString(YarnRemoteException e) {
(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);
}
}
}

View File

@ -25,7 +25,7 @@
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 @@ public RegisterNodeManagerResponse registerNodeManager(
try {
return new RegisterNodeManagerResponsePBImpl(proxy.registerNodeManager(null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}
@ -69,7 +69,7 @@ public NodeHeartbeatResponse nodeHeartbeat(NodeHeartbeatRequest request)
try {
return new NodeHeartbeatResponsePBImpl(proxy.nodeHeartbeat(null, requestProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}

View File

@ -25,7 +25,7 @@
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 LocalizerHeartbeatResponse heartbeat(LocalizerStatus status)
return new LocalizerHeartbeatResponsePBImpl(
proxy.heartbeat(null, statusProto));
} catch (ServiceException e) {
throw YarnRemoteExceptionPBImpl.unwrapAndThrowException(e);
throw RPCUtil.unwrapAndThrowException(e);
}
}