Search in sources :

Example 1 with CoprocessorServiceCall

use of org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.CoprocessorServiceCall in project hbase by apache.

the class HRegionServer method execRegionServerService.

public CoprocessorServiceResponse execRegionServerService(@SuppressWarnings("UnusedParameters") final RpcController controller, final CoprocessorServiceRequest serviceRequest) throws ServiceException {
    try {
        ServerRpcController serviceController = new ServerRpcController();
        CoprocessorServiceCall call = serviceRequest.getCall();
        String serviceName = call.getServiceName();
        com.google.protobuf.Service service = coprocessorServiceHandlers.get(serviceName);
        if (service == null) {
            throw new UnknownProtocolException(null, "No registered coprocessor service found for " + serviceName);
        }
        com.google.protobuf.Descriptors.ServiceDescriptor serviceDesc = service.getDescriptorForType();
        String methodName = call.getMethodName();
        com.google.protobuf.Descriptors.MethodDescriptor methodDesc = serviceDesc.findMethodByName(methodName);
        if (methodDesc == null) {
            throw new UnknownProtocolException(service.getClass(), "Unknown method " + methodName + " called on service " + serviceName);
        }
        com.google.protobuf.Message request = CoprocessorRpcUtils.getRequest(service, methodDesc, call.getRequest());
        final com.google.protobuf.Message.Builder responseBuilder = service.getResponsePrototype(methodDesc).newBuilderForType();
        service.callMethod(methodDesc, serviceController, request, new com.google.protobuf.RpcCallback<com.google.protobuf.Message>() {

            @Override
            public void run(com.google.protobuf.Message message) {
                if (message != null) {
                    responseBuilder.mergeFrom(message);
                }
            }
        });
        IOException exception = CoprocessorRpcUtils.getControllerException(serviceController);
        if (exception != null) {
            throw exception;
        }
        return CoprocessorRpcUtils.getResponse(responseBuilder.build(), HConstants.EMPTY_BYTE_ARRAY);
    } catch (IOException ie) {
        throw new ServiceException(ie);
    }
}
Also used : CoprocessorServiceCall(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.CoprocessorServiceCall) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) ServerRpcController(org.apache.hadoop.hbase.ipc.ServerRpcController) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) UnknownProtocolException(org.apache.hadoop.hbase.exceptions.UnknownProtocolException) TableDescriptors(org.apache.hadoop.hbase.TableDescriptors) FSTableDescriptors(org.apache.hadoop.hbase.util.FSTableDescriptors)

Aggregations

IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 TableDescriptors (org.apache.hadoop.hbase.TableDescriptors)1 UnknownProtocolException (org.apache.hadoop.hbase.exceptions.UnknownProtocolException)1 ServerRpcController (org.apache.hadoop.hbase.ipc.ServerRpcController)1 ServiceException (org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException)1 CoprocessorServiceCall (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.CoprocessorServiceCall)1 FSTableDescriptors (org.apache.hadoop.hbase.util.FSTableDescriptors)1