1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.ipc;
20
21 import com.google.protobuf.ByteString;
22 import com.google.protobuf.Descriptors;
23 import com.google.protobuf.Message;
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.hadoop.classification.InterfaceAudience;
27 import org.apache.hadoop.hbase.HConstants;
28 import org.apache.hadoop.hbase.client.HConnection;
29 import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
30 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos;
31 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.CoprocessorServiceResponse;
32
33 import java.io.IOException;
34
35
36
37
38
39
40
41
42
43 @InterfaceAudience.Private
44 public class MasterCoprocessorRpcChannel extends CoprocessorRpcChannel{
45 private static Log LOG = LogFactory.getLog(MasterCoprocessorRpcChannel.class);
46
47 private final HConnection connection;
48
49 public MasterCoprocessorRpcChannel(HConnection conn) {
50 this.connection = conn;
51 }
52
53 @Override
54 protected Message callExecService(Descriptors.MethodDescriptor method,
55 Message request, Message responsePrototype)
56 throws IOException {
57 if (LOG.isDebugEnabled()) {
58 LOG.debug("Call: "+method.getName()+", "+request.toString());
59 }
60
61 final ClientProtos.CoprocessorServiceCall call =
62 ClientProtos.CoprocessorServiceCall.newBuilder()
63 .setRow(ByteString.copyFrom(HConstants.EMPTY_BYTE_ARRAY))
64 .setServiceName(method.getService().getFullName())
65 .setMethodName(method.getName())
66 .setRequest(request.toByteString()).build();
67 CoprocessorServiceResponse result = ProtobufUtil.execService(connection.getMasterAdmin(), call);
68 Message response = null;
69 if (result.getValue().hasValue()) {
70 response = responsePrototype.newBuilderForType()
71 .mergeFrom(result.getValue().getValue()).build();
72 } else {
73 response = responsePrototype.getDefaultInstanceForType();
74 }
75 if (LOG.isTraceEnabled()) {
76 LOG.trace("Master Result is value=" + response);
77 }
78 return response;
79 }
80
81 }