Search in sources :

Example 1 with ServiceDescriptor

use of org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.ServiceDescriptor in project hbase by apache.

the class MasterRpcServices method execMasterService.

@Override
public ClientProtos.CoprocessorServiceResponse execMasterService(final RpcController controller, final ClientProtos.CoprocessorServiceRequest request) throws ServiceException {
    rpcPreCheck("execMasterService");
    try {
        ServerRpcController execController = new ServerRpcController();
        ClientProtos.CoprocessorServiceCall call = request.getCall();
        String serviceName = call.getServiceName();
        String methodName = call.getMethodName();
        if (!server.coprocessorServiceHandlers.containsKey(serviceName)) {
            throw new UnknownProtocolException(null, "No registered Master Coprocessor Endpoint found for " + serviceName + ". Has it been enabled?");
        }
        Service service = server.coprocessorServiceHandlers.get(serviceName);
        ServiceDescriptor serviceDesc = service.getDescriptorForType();
        MethodDescriptor methodDesc = CoprocessorRpcUtils.getMethodDescriptor(methodName, serviceDesc);
        Message execRequest = CoprocessorRpcUtils.getRequest(service, methodDesc, call.getRequest());
        final Message.Builder responseBuilder = service.getResponsePrototype(methodDesc).newBuilderForType();
        service.callMethod(methodDesc, execController, execRequest, (message) -> {
            if (message != null) {
                responseBuilder.mergeFrom(message);
            }
        });
        Message execResult = responseBuilder.build();
        if (execController.getFailedOn() != null) {
            throw execController.getFailedOn();
        }
        String remoteAddress = RpcServer.getRemoteAddress().map(InetAddress::toString).orElse("");
        User caller = RpcServer.getRequestUser().orElse(null);
        AUDITLOG.info("User {} (remote address: {}) master service request for {}.{}", caller, remoteAddress, serviceName, methodName);
        return CoprocessorRpcUtils.getResponse(execResult, HConstants.EMPTY_BYTE_ARRAY);
    } catch (IOException ie) {
        throw new ServiceException(ie);
    }
}
Also used : InputUser(org.apache.hadoop.hbase.security.access.AccessChecker.InputUser) User(org.apache.hadoop.hbase.security.User) Message(org.apache.hbase.thirdparty.com.google.protobuf.Message) LockService(org.apache.hadoop.hbase.shaded.protobuf.generated.LockServiceProtos.LockService) AdminService(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService) Service(org.apache.hbase.thirdparty.com.google.protobuf.Service) ClientMetaService(org.apache.hadoop.hbase.shaded.protobuf.generated.RegistryProtos.ClientMetaService) MasterService(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MasterService) VisibilityLabelsService(org.apache.hadoop.hbase.shaded.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsService) AccessControlService(org.apache.hadoop.hbase.shaded.protobuf.generated.AccessControlProtos.AccessControlService) RegionServerStatusService(org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionServerStatusService) HbckService(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.HbckService) ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) ServerRpcController(org.apache.hadoop.hbase.ipc.ServerRpcController) MethodDescriptor(org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.MethodDescriptor) ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) ServiceDescriptor(org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.ServiceDescriptor) UnknownProtocolException(org.apache.hadoop.hbase.exceptions.UnknownProtocolException) ClientProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos)

Example 2 with ServiceDescriptor

use of org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.ServiceDescriptor in project hbase by apache.

the class HRegion method registerService.

/**
 * Registers a new protocol buffer {@link Service} subclass as a coprocessor endpoint to be
 * available for handling {@link #execService(RpcController, CoprocessorServiceCall)} calls.
 * <p/>
 * Only a single instance may be registered per region for a given {@link Service} subclass (the
 * instances are keyed on {@link ServiceDescriptor#getFullName()}.. After the first registration,
 * subsequent calls with the same service name will fail with a return value of {@code false}.
 * @param instance the {@code Service} subclass instance to expose as a coprocessor endpoint
 * @return {@code true} if the registration was successful, {@code false} otherwise
 */
public boolean registerService(Service instance) {
    // No stacking of instances is allowed for a single service name
    ServiceDescriptor serviceDesc = instance.getDescriptorForType();
    String serviceName = CoprocessorRpcUtils.getServiceName(serviceDesc);
    if (coprocessorServiceHandlers.containsKey(serviceName)) {
        LOG.error("Coprocessor service {} already registered, rejecting request from {} in region {}", serviceName, instance, this);
        return false;
    }
    coprocessorServiceHandlers.put(serviceName, instance);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Registered coprocessor service: region=" + Bytes.toStringBinary(getRegionInfo().getRegionName()) + " service=" + serviceName);
    }
    return true;
}
Also used : ServiceDescriptor(org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.ServiceDescriptor)

Example 3 with ServiceDescriptor

use of org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.ServiceDescriptor in project hbase by apache.

the class HRegion method execService.

/**
 * Executes a single protocol buffer coprocessor endpoint {@link Service} method using
 * the registered protocol handlers.  {@link Service} implementations must be registered via the
 * {@link #registerService(Service)}
 * method before they are available.
 *
 * @param controller an {@code RpcContoller} implementation to pass to the invoked service
 * @param call a {@code CoprocessorServiceCall} instance identifying the service, method,
 *     and parameters for the method invocation
 * @return a protocol buffer {@code Message} instance containing the method's result
 * @throws IOException if no registered service handler is found or an error
 *     occurs during the invocation
 * @see #registerService(Service)
 */
public Message execService(RpcController controller, CoprocessorServiceCall call) throws IOException {
    String serviceName = call.getServiceName();
    Service service = coprocessorServiceHandlers.get(serviceName);
    if (service == null) {
        throw new UnknownProtocolException(null, "No registered coprocessor service found for " + serviceName + " in region " + Bytes.toStringBinary(getRegionInfo().getRegionName()));
    }
    ServiceDescriptor serviceDesc = service.getDescriptorForType();
    cpRequestsCount.increment();
    String methodName = call.getMethodName();
    MethodDescriptor methodDesc = CoprocessorRpcUtils.getMethodDescriptor(methodName, serviceDesc);
    Message.Builder builder = service.getRequestPrototype(methodDesc).newBuilderForType();
    ProtobufUtil.mergeFrom(builder, call.getRequest().toByteArray());
    Message request = CoprocessorRpcUtils.getRequest(service, methodDesc, call.getRequest());
    if (coprocessorHost != null) {
        request = coprocessorHost.preEndpointInvocation(service, methodName, request);
    }
    final Message.Builder responseBuilder = service.getResponsePrototype(methodDesc).newBuilderForType();
    service.callMethod(methodDesc, controller, request, new RpcCallback<Message>() {

        @Override
        public void run(Message message) {
            if (message != null) {
                responseBuilder.mergeFrom(message);
            }
        }
    });
    if (coprocessorHost != null) {
        coprocessorHost.postEndpointInvocation(service, methodName, request, responseBuilder);
    }
    IOException exception = org.apache.hadoop.hbase.ipc.CoprocessorRpcUtils.getControllerException(controller);
    if (exception != null) {
        throw exception;
    }
    return responseBuilder.build();
}
Also used : Message(org.apache.hbase.thirdparty.com.google.protobuf.Message) ServiceDescriptor(org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.ServiceDescriptor) Service(org.apache.hbase.thirdparty.com.google.protobuf.Service) CompletionService(java.util.concurrent.CompletionService) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) UnknownProtocolException(org.apache.hadoop.hbase.exceptions.UnknownProtocolException) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) TimeoutIOException(org.apache.hadoop.hbase.exceptions.TimeoutIOException) InterruptedIOException(java.io.InterruptedIOException) MethodDescriptor(org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.MethodDescriptor)

Example 4 with ServiceDescriptor

use of org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.ServiceDescriptor in project hbase by apache.

the class TestCoprocessorRpcUtils method testServiceName.

@Test
public void testServiceName() throws Exception {
    // verify that we de-namespace build in HBase rpc services
    ServiceDescriptor authService = AuthenticationProtos.AuthenticationService.getDescriptor();
    assertEquals(authService.getName(), CoprocessorRpcUtils.getServiceName(authService));
    // non-hbase rpc services should remain fully qualified
    ServiceDescriptor dummyService = DummyRegionServerEndpointProtos.DummyService.getDescriptor();
    assertEquals(dummyService.getFullName(), CoprocessorRpcUtils.getServiceName(dummyService));
}
Also used : ServiceDescriptor(org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.ServiceDescriptor) Test(org.junit.Test)

Example 5 with ServiceDescriptor

use of org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.ServiceDescriptor in project hbase by apache.

the class RpcServerFactory method createRpcServer.

public static RpcServer createRpcServer(final Server server, final String name, final List<BlockingServiceAndInterface> services, final InetSocketAddress bindAddress, Configuration conf, RpcScheduler scheduler, boolean reservoirEnabled) throws IOException {
    String rpcServerClass = conf.get(CUSTOM_RPC_SERVER_IMPL_CONF_KEY, NettyRpcServer.class.getName());
    StringBuilder servicesList = new StringBuilder();
    for (BlockingServiceAndInterface s : services) {
        ServiceDescriptor sd = s.getBlockingService().getDescriptorForType();
        // Can be null for certain tests like TestTokenAuthentication
        if (sd == null)
            continue;
        if (servicesList.length() > 0)
            servicesList.append(", ");
        servicesList.append(sd.getFullName());
    }
    LOG.info("Creating " + rpcServerClass + " hosting " + servicesList);
    return ReflectionUtils.instantiateWithCustomCtor(rpcServerClass, new Class[] { Server.class, String.class, List.class, InetSocketAddress.class, Configuration.class, RpcScheduler.class, boolean.class }, new Object[] { server, name, services, bindAddress, conf, scheduler, reservoirEnabled });
}
Also used : BlockingServiceAndInterface(org.apache.hadoop.hbase.ipc.RpcServer.BlockingServiceAndInterface) ServiceDescriptor(org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.ServiceDescriptor)

Aggregations

ServiceDescriptor (org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.ServiceDescriptor)7 IOException (java.io.IOException)3 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)3 UnknownProtocolException (org.apache.hadoop.hbase.exceptions.UnknownProtocolException)3 MethodDescriptor (org.apache.hbase.thirdparty.com.google.protobuf.Descriptors.MethodDescriptor)3 Message (org.apache.hbase.thirdparty.com.google.protobuf.Message)3 Service (org.apache.hbase.thirdparty.com.google.protobuf.Service)3 ServerRpcController (org.apache.hadoop.hbase.ipc.ServerRpcController)2 LockService (org.apache.hadoop.hbase.shaded.protobuf.generated.LockServiceProtos.LockService)2 RegionServerStatusService (org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionServerStatusService)2 ServiceException (org.apache.hbase.thirdparty.com.google.protobuf.ServiceException)2 InterruptedIOException (java.io.InterruptedIOException)1 CompletionService (java.util.concurrent.CompletionService)1 ExecutorCompletionService (java.util.concurrent.ExecutorCompletionService)1 TimeoutIOException (org.apache.hadoop.hbase.exceptions.TimeoutIOException)1 BlockingServiceAndInterface (org.apache.hadoop.hbase.ipc.RpcServer.BlockingServiceAndInterface)1 User (org.apache.hadoop.hbase.security.User)1 InputUser (org.apache.hadoop.hbase.security.access.AccessChecker.InputUser)1 AccessControlService (org.apache.hadoop.hbase.shaded.protobuf.generated.AccessControlProtos.AccessControlService)1 AdminService (org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService)1