/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-common/src/main/java/org/apache/hadoop/mapreduce/v2/api/impl/pb/client/MRClientProtocolPBClientImpl.java

https://github.com/patrickangeles/hadoop-common · Java · 286 lines · 250 code · 19 blank · 17 comment · 44 complexity · b2f8b9533276e17032725262ba9db55c MD5 · raw file

  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. package org.apache.hadoop.mapreduce.v2.api.impl.pb.client;
  19. import java.io.IOException;
  20. import java.lang.reflect.UndeclaredThrowableException;
  21. import java.net.InetSocketAddress;
  22. import org.apache.hadoop.conf.Configuration;
  23. import org.apache.hadoop.ipc.RPC;
  24. import org.apache.hadoop.mapreduce.v2.api.MRClientProtocol;
  25. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.FailTaskAttemptRequest;
  26. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.FailTaskAttemptResponse;
  27. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetCountersRequest;
  28. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetCountersResponse;
  29. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetDiagnosticsRequest;
  30. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetDiagnosticsResponse;
  31. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetJobReportRequest;
  32. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetJobReportResponse;
  33. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetTaskAttemptCompletionEventsRequest;
  34. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetTaskAttemptCompletionEventsResponse;
  35. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetTaskAttemptReportRequest;
  36. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetTaskAttemptReportResponse;
  37. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetTaskReportRequest;
  38. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetTaskReportResponse;
  39. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetTaskReportsRequest;
  40. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetTaskReportsResponse;
  41. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.KillJobRequest;
  42. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.KillJobResponse;
  43. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.KillTaskAttemptRequest;
  44. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.KillTaskAttemptResponse;
  45. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.KillTaskRequest;
  46. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.KillTaskResponse;
  47. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.impl.pb.FailTaskAttemptRequestPBImpl;
  48. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.impl.pb.FailTaskAttemptResponsePBImpl;
  49. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.impl.pb.GetCountersRequestPBImpl;
  50. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.impl.pb.GetCountersResponsePBImpl;
  51. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.impl.pb.GetDiagnosticsRequestPBImpl;
  52. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.impl.pb.GetDiagnosticsResponsePBImpl;
  53. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.impl.pb.GetJobReportRequestPBImpl;
  54. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.impl.pb.GetJobReportResponsePBImpl;
  55. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.impl.pb.GetTaskAttemptCompletionEventsRequestPBImpl;
  56. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.impl.pb.GetTaskAttemptCompletionEventsResponsePBImpl;
  57. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.impl.pb.GetTaskAttemptReportRequestPBImpl;
  58. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.impl.pb.GetTaskAttemptReportResponsePBImpl;
  59. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.impl.pb.GetTaskReportRequestPBImpl;
  60. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.impl.pb.GetTaskReportResponsePBImpl;
  61. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.impl.pb.GetTaskReportsRequestPBImpl;
  62. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.impl.pb.GetTaskReportsResponsePBImpl;
  63. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.impl.pb.KillJobRequestPBImpl;
  64. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.impl.pb.KillJobResponsePBImpl;
  65. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.impl.pb.KillTaskAttemptRequestPBImpl;
  66. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.impl.pb.KillTaskAttemptResponsePBImpl;
  67. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.impl.pb.KillTaskRequestPBImpl;
  68. import org.apache.hadoop.mapreduce.v2.api.protocolrecords.impl.pb.KillTaskResponsePBImpl;
  69. import org.apache.hadoop.mapreduce.v2.proto.MRServiceProtos.FailTaskAttemptRequestProto;
  70. import org.apache.hadoop.mapreduce.v2.proto.MRServiceProtos.GetCountersRequestProto;
  71. import org.apache.hadoop.mapreduce.v2.proto.MRServiceProtos.GetDiagnosticsRequestProto;
  72. import org.apache.hadoop.mapreduce.v2.proto.MRServiceProtos.GetJobReportRequestProto;
  73. import org.apache.hadoop.mapreduce.v2.proto.MRServiceProtos.GetTaskAttemptCompletionEventsRequestProto;
  74. import org.apache.hadoop.mapreduce.v2.proto.MRServiceProtos.GetTaskAttemptReportRequestProto;
  75. import org.apache.hadoop.mapreduce.v2.proto.MRServiceProtos.GetTaskReportRequestProto;
  76. import org.apache.hadoop.mapreduce.v2.proto.MRServiceProtos.GetTaskReportsRequestProto;
  77. import org.apache.hadoop.mapreduce.v2.proto.MRServiceProtos.KillJobRequestProto;
  78. import org.apache.hadoop.mapreduce.v2.proto.MRServiceProtos.KillTaskAttemptRequestProto;
  79. import org.apache.hadoop.mapreduce.v2.proto.MRServiceProtos.KillTaskRequestProto;
  80. import org.apache.hadoop.yarn.exceptions.YarnRemoteException;
  81. import org.apache.hadoop.yarn.ipc.ProtoOverHadoopRpcEngine;
  82. import org.apache.hadoop.yarn.proto.MRClientProtocol.MRClientProtocolService;
  83. import com.google.protobuf.ServiceException;
  84. public class MRClientProtocolPBClientImpl implements MRClientProtocol {
  85. private MRClientProtocolService.BlockingInterface proxy;
  86. public MRClientProtocolPBClientImpl(long clientVersion, InetSocketAddress addr, Configuration conf) throws IOException {
  87. RPC.setProtocolEngine(conf, MRClientProtocolService.BlockingInterface.class, ProtoOverHadoopRpcEngine.class);
  88. proxy = (MRClientProtocolService.BlockingInterface)RPC.getProxy(
  89. MRClientProtocolService.BlockingInterface.class, clientVersion, addr, conf);
  90. }
  91. @Override
  92. public GetJobReportResponse getJobReport(GetJobReportRequest request)
  93. throws YarnRemoteException {
  94. GetJobReportRequestProto requestProto = ((GetJobReportRequestPBImpl)request).getProto();
  95. try {
  96. return new GetJobReportResponsePBImpl(proxy.getJobReport(null, requestProto));
  97. } catch (ServiceException e) {
  98. if (e.getCause() instanceof YarnRemoteException) {
  99. throw (YarnRemoteException)e.getCause();
  100. } else if (e.getCause() instanceof UndeclaredThrowableException) {
  101. throw (UndeclaredThrowableException)e.getCause();
  102. } else {
  103. throw new UndeclaredThrowableException(e);
  104. }
  105. }
  106. }
  107. @Override
  108. public GetTaskReportResponse getTaskReport(GetTaskReportRequest request)
  109. throws YarnRemoteException {
  110. GetTaskReportRequestProto requestProto = ((GetTaskReportRequestPBImpl)request).getProto();
  111. try {
  112. return new GetTaskReportResponsePBImpl(proxy.getTaskReport(null, requestProto));
  113. } catch (ServiceException e) {
  114. if (e.getCause() instanceof YarnRemoteException) {
  115. throw (YarnRemoteException)e.getCause();
  116. } else if (e.getCause() instanceof UndeclaredThrowableException) {
  117. throw (UndeclaredThrowableException)e.getCause();
  118. } else {
  119. throw new UndeclaredThrowableException(e);
  120. }
  121. }
  122. }
  123. @Override
  124. public GetTaskAttemptReportResponse getTaskAttemptReport(
  125. GetTaskAttemptReportRequest request) throws YarnRemoteException {
  126. GetTaskAttemptReportRequestProto requestProto = ((GetTaskAttemptReportRequestPBImpl)request).getProto();
  127. try {
  128. return new GetTaskAttemptReportResponsePBImpl(proxy.getTaskAttemptReport(null, requestProto));
  129. } catch (ServiceException e) {
  130. if (e.getCause() instanceof YarnRemoteException) {
  131. throw (YarnRemoteException)e.getCause();
  132. } else if (e.getCause() instanceof UndeclaredThrowableException) {
  133. throw (UndeclaredThrowableException)e.getCause();
  134. } else {
  135. throw new UndeclaredThrowableException(e);
  136. }
  137. }
  138. }
  139. @Override
  140. public GetCountersResponse getCounters(GetCountersRequest request)
  141. throws YarnRemoteException {
  142. GetCountersRequestProto requestProto = ((GetCountersRequestPBImpl)request).getProto();
  143. try {
  144. return new GetCountersResponsePBImpl(proxy.getCounters(null, requestProto));
  145. } catch (ServiceException e) {
  146. if (e.getCause() instanceof YarnRemoteException) {
  147. throw (YarnRemoteException)e.getCause();
  148. } else if (e.getCause() instanceof UndeclaredThrowableException) {
  149. throw (UndeclaredThrowableException)e.getCause();
  150. } else {
  151. throw new UndeclaredThrowableException(e);
  152. }
  153. }
  154. }
  155. @Override
  156. public GetTaskAttemptCompletionEventsResponse getTaskAttemptCompletionEvents(
  157. GetTaskAttemptCompletionEventsRequest request) throws YarnRemoteException {
  158. GetTaskAttemptCompletionEventsRequestProto requestProto = ((GetTaskAttemptCompletionEventsRequestPBImpl)request).getProto();
  159. try {
  160. return new GetTaskAttemptCompletionEventsResponsePBImpl(proxy.getTaskAttemptCompletionEvents(null, requestProto));
  161. } catch (ServiceException e) {
  162. if (e.getCause() instanceof YarnRemoteException) {
  163. throw (YarnRemoteException)e.getCause();
  164. } else if (e.getCause() instanceof UndeclaredThrowableException) {
  165. throw (UndeclaredThrowableException)e.getCause();
  166. } else {
  167. throw new UndeclaredThrowableException(e);
  168. }
  169. }
  170. }
  171. @Override
  172. public GetTaskReportsResponse getTaskReports(GetTaskReportsRequest request)
  173. throws YarnRemoteException {
  174. GetTaskReportsRequestProto requestProto = ((GetTaskReportsRequestPBImpl)request).getProto();
  175. try {
  176. return new GetTaskReportsResponsePBImpl(proxy.getTaskReports(null, requestProto));
  177. } catch (ServiceException e) {
  178. if (e.getCause() instanceof YarnRemoteException) {
  179. throw (YarnRemoteException)e.getCause();
  180. } else if (e.getCause() instanceof UndeclaredThrowableException) {
  181. throw (UndeclaredThrowableException)e.getCause();
  182. } else {
  183. throw new UndeclaredThrowableException(e);
  184. }
  185. }
  186. }
  187. @Override
  188. public GetDiagnosticsResponse getDiagnostics(GetDiagnosticsRequest request)
  189. throws YarnRemoteException {
  190. GetDiagnosticsRequestProto requestProto = ((GetDiagnosticsRequestPBImpl)request).getProto();
  191. try {
  192. return new GetDiagnosticsResponsePBImpl(proxy.getDiagnostics(null, requestProto));
  193. } catch (ServiceException e) {
  194. if (e.getCause() instanceof YarnRemoteException) {
  195. throw (YarnRemoteException)e.getCause();
  196. } else if (e.getCause() instanceof UndeclaredThrowableException) {
  197. throw (UndeclaredThrowableException)e.getCause();
  198. } else {
  199. throw new UndeclaredThrowableException(e);
  200. }
  201. }
  202. }
  203. @Override
  204. public KillJobResponse killJob(KillJobRequest request)
  205. throws YarnRemoteException {
  206. KillJobRequestProto requestProto = ((KillJobRequestPBImpl)request).getProto();
  207. try {
  208. return new KillJobResponsePBImpl(proxy.killJob(null, requestProto));
  209. } catch (ServiceException e) {
  210. if (e.getCause() instanceof YarnRemoteException) {
  211. throw (YarnRemoteException)e.getCause();
  212. } else if (e.getCause() instanceof UndeclaredThrowableException) {
  213. throw (UndeclaredThrowableException)e.getCause();
  214. } else {
  215. throw new UndeclaredThrowableException(e);
  216. }
  217. }
  218. }
  219. @Override
  220. public KillTaskResponse killTask(KillTaskRequest request)
  221. throws YarnRemoteException {
  222. KillTaskRequestProto requestProto = ((KillTaskRequestPBImpl)request).getProto();
  223. try {
  224. return new KillTaskResponsePBImpl(proxy.killTask(null, requestProto));
  225. } catch (ServiceException e) {
  226. if (e.getCause() instanceof YarnRemoteException) {
  227. throw (YarnRemoteException)e.getCause();
  228. } else if (e.getCause() instanceof UndeclaredThrowableException) {
  229. throw (UndeclaredThrowableException)e.getCause();
  230. } else {
  231. throw new UndeclaredThrowableException(e);
  232. }
  233. }
  234. }
  235. @Override
  236. public KillTaskAttemptResponse killTaskAttempt(KillTaskAttemptRequest request)
  237. throws YarnRemoteException {
  238. KillTaskAttemptRequestProto requestProto = ((KillTaskAttemptRequestPBImpl)request).getProto();
  239. try {
  240. return new KillTaskAttemptResponsePBImpl(proxy.killTaskAttempt(null, requestProto));
  241. } catch (ServiceException e) {
  242. if (e.getCause() instanceof YarnRemoteException) {
  243. throw (YarnRemoteException)e.getCause();
  244. } else if (e.getCause() instanceof UndeclaredThrowableException) {
  245. throw (UndeclaredThrowableException)e.getCause();
  246. } else {
  247. throw new UndeclaredThrowableException(e);
  248. }
  249. }
  250. }
  251. @Override
  252. public FailTaskAttemptResponse failTaskAttempt(FailTaskAttemptRequest request)
  253. throws YarnRemoteException {
  254. FailTaskAttemptRequestProto requestProto = ((FailTaskAttemptRequestPBImpl)request).getProto();
  255. try {
  256. return new FailTaskAttemptResponsePBImpl(proxy.failTaskAttempt(null, requestProto));
  257. } catch (ServiceException e) {
  258. if (e.getCause() instanceof YarnRemoteException) {
  259. throw (YarnRemoteException)e.getCause();
  260. } else if (e.getCause() instanceof UndeclaredThrowableException) {
  261. throw (UndeclaredThrowableException)e.getCause();
  262. } else {
  263. throw new UndeclaredThrowableException(e);
  264. }
  265. }
  266. }
  267. }