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);
}
}
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;
}
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();
}
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));
}
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 });
}
Aggregations