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 java.io.IOException;
22
23 import org.apache.hadoop.hbase.util.ByteStringer;
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 com.google.protobuf.Descriptors;
34 import com.google.protobuf.Message;
35
36
37
38
39
40
41
42
43
44 @InterfaceAudience.Private
45 public class MasterCoprocessorRpcChannel extends CoprocessorRpcChannel{
46 private static Log LOG = LogFactory.getLog(MasterCoprocessorRpcChannel.class);
47
48 private final HConnection connection;
49
50 public MasterCoprocessorRpcChannel(HConnection conn) {
51 this.connection = conn;
52 }
53
54 @Override
55 protected Message callExecService(Descriptors.MethodDescriptor method,
56 Message request, Message responsePrototype)
57 throws IOException {
58 if (LOG.isDebugEnabled()) {
59 LOG.debug("Call: "+method.getName()+", "+request.toString());
60 }
61
62 final ClientProtos.CoprocessorServiceCall call =
63 ClientProtos.CoprocessorServiceCall.newBuilder()
64 .setRow(ByteStringer.wrap(HConstants.EMPTY_BYTE_ARRAY))
65 .setServiceName(method.getService().getFullName())
66 .setMethodName(method.getName())
67 .setRequest(request.toByteString()).build();
68 CoprocessorServiceResponse result = ProtobufUtil.execService(connection.getMaster(), call);
69 Message response = null;
70 if (result.getValue().hasValue()) {
71 response = responsePrototype.newBuilderForType()
72 .mergeFrom(result.getValue().getValue()).build();
73 } else {
74 response = responsePrototype.getDefaultInstanceForType();
75 }
76 if (LOG.isTraceEnabled()) {
77 LOG.trace("Master Result is value=" + response);
78 }
79 return response;
80 }
81
82 }