Search in sources :

Example 6 with BlockingService

use of com.google.protobuf.BlockingService in project hadoop by apache.

the class DummyHAService method startAndGetRPCServerAddress.

private InetSocketAddress startAndGetRPCServerAddress(InetSocketAddress serverAddress) {
    Configuration conf = new Configuration();
    try {
        RPC.setProtocolEngine(conf, HAServiceProtocolPB.class, ProtobufRpcEngine.class);
        HAServiceProtocolServerSideTranslatorPB haServiceProtocolXlator = new HAServiceProtocolServerSideTranslatorPB(new MockHAProtocolImpl());
        BlockingService haPbService = HAServiceProtocolService.newReflectiveBlockingService(haServiceProtocolXlator);
        Server server = new RPC.Builder(conf).setProtocol(HAServiceProtocolPB.class).setInstance(haPbService).setBindAddress(serverAddress.getHostName()).setPort(serverAddress.getPort()).build();
        server.start();
        return NetUtils.getConnectAddress(server);
    } catch (IOException e) {
        return null;
    }
}
Also used : HAServiceProtocolServerSideTranslatorPB(org.apache.hadoop.ha.protocolPB.HAServiceProtocolServerSideTranslatorPB) Configuration(org.apache.hadoop.conf.Configuration) Server(org.apache.hadoop.ipc.Server) RPC(org.apache.hadoop.ipc.RPC) BlockingService(com.google.protobuf.BlockingService) IOException(java.io.IOException)

Example 7 with BlockingService

use of com.google.protobuf.BlockingService in project hadoop by apache.

the class TestProtoBufRPCCompatibility method testProtocolVersionMismatch.

@Test
public void testProtocolVersionMismatch() throws IOException, ServiceException {
    conf = new Configuration();
    conf.setInt(CommonConfigurationKeys.IPC_MAXIMUM_DATA_LENGTH, 1024);
    // Set RPC engine to protobuf RPC engine
    RPC.setProtocolEngine(conf, NewRpcService.class, ProtobufRpcEngine.class);
    // Create server side implementation
    NewServerImpl serverImpl = new NewServerImpl();
    BlockingService service = NewProtobufRpcProto.newReflectiveBlockingService(serverImpl);
    // Get RPC server for server side implementation
    server = new RPC.Builder(conf).setProtocol(NewRpcService.class).setInstance(service).setBindAddress(ADDRESS).setPort(PORT).build();
    addr = NetUtils.getConnectAddress(server);
    server.start();
    RPC.setProtocolEngine(conf, OldRpcService.class, ProtobufRpcEngine.class);
    OldRpcService proxy = RPC.getProxy(OldRpcService.class, 0, addr, conf);
    // Verify that exception is thrown if protocolVersion is mismatch between
    // client and server.
    EmptyRequestProto emptyRequest = EmptyRequestProto.newBuilder().build();
    try {
        proxy.ping(null, emptyRequest);
        fail("Expected an exception to occur as version mismatch.");
    } catch (Exception e) {
        if (!(e.getMessage().contains("version mismatch"))) {
            // Exception type is not what we expected, re-throw it.
            throw new IOException(e);
        }
    }
    // Verify that missing of optional field is still compatible in RPC call.
    RPC.setProtocolEngine(conf, NewerRpcService.class, ProtobufRpcEngine.class);
    NewerRpcService newProxy = RPC.getProxy(NewerRpcService.class, 0, addr, conf);
    newProxy.echo(null, emptyRequest);
}
Also used : EmptyRequestProto(org.apache.hadoop.ipc.protobuf.TestProtos.EmptyRequestProto) Configuration(org.apache.hadoop.conf.Configuration) BlockingService(com.google.protobuf.BlockingService) IOException(java.io.IOException) ServiceException(com.google.protobuf.ServiceException) IOException(java.io.IOException) Test(org.junit.Test)

Example 8 with BlockingService

use of com.google.protobuf.BlockingService in project hadoop by apache.

the class TestProtoBufRpc method setUp.

@Before
public void setUp() throws IOException {
    // Setup server for both protocols
    conf = new Configuration();
    conf.setInt(CommonConfigurationKeys.IPC_MAXIMUM_DATA_LENGTH, 1024);
    conf.setBoolean(CommonConfigurationKeys.IPC_SERVER_LOG_SLOW_RPC, true);
    // Set RPC engine to protobuf RPC engine
    RPC.setProtocolEngine(conf, TestRpcService.class, ProtobufRpcEngine.class);
    RPC.setProtocolEngine(conf, TestRpcService2.class, ProtobufRpcEngine.class);
    // Create server side implementation
    PBServerImpl serverImpl = new PBServerImpl();
    BlockingService service = TestProtobufRpcProto.newReflectiveBlockingService(serverImpl);
    // Get RPC server for server side implementation
    server = new RPC.Builder(conf).setProtocol(TestRpcService.class).setInstance(service).setBindAddress(ADDRESS).setPort(PORT).build();
    addr = NetUtils.getConnectAddress(server);
    // now the second protocol
    PBServer2Impl server2Impl = new PBServer2Impl();
    BlockingService service2 = TestProtobufRpc2Proto.newReflectiveBlockingService(server2Impl);
    server.addProtocol(RPC.RpcKind.RPC_PROTOCOL_BUFFER, TestRpcService2.class, service2);
    server.start();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder) BlockingService(com.google.protobuf.BlockingService) Before(org.junit.Before)

Example 9 with BlockingService

use of com.google.protobuf.BlockingService in project hadoop by apache.

the class RPCCallBenchmark method startServer.

private Server startServer(MyOptions opts) throws IOException {
    if (opts.serverThreads <= 0) {
        return null;
    }
    conf.setInt(CommonConfigurationKeys.IPC_SERVER_RPC_READ_THREADS_KEY, opts.serverReaderThreads);
    RPC.Server server;
    // Get RPC server for server side implementation
    if (opts.rpcEngine == ProtobufRpcEngine.class) {
        // Create server side implementation
        PBServerImpl serverImpl = new PBServerImpl();
        BlockingService service = TestProtobufRpcProto.newReflectiveBlockingService(serverImpl);
        server = new RPC.Builder(conf).setProtocol(TestRpcService.class).setInstance(service).setBindAddress(opts.host).setPort(opts.getPort()).setNumHandlers(opts.serverThreads).setVerbose(false).build();
    } else {
        throw new RuntimeException("Bad engine: " + opts.rpcEngine);
    }
    server.start();
    return server;
}
Also used : Server(org.apache.hadoop.ipc.RPC.Server) OptionBuilder(org.apache.commons.cli.OptionBuilder) BlockingService(com.google.protobuf.BlockingService)

Example 10 with BlockingService

use of com.google.protobuf.BlockingService in project hadoop by apache.

the class TestBlockToken method createMockDatanode.

private static Server createMockDatanode(BlockTokenSecretManager sm, Token<BlockTokenIdentifier> token, Configuration conf) throws IOException, ServiceException {
    ClientDatanodeProtocolPB mockDN = mock(ClientDatanodeProtocolPB.class);
    BlockTokenIdentifier id = sm.createIdentifier();
    id.readFields(new DataInputStream(new ByteArrayInputStream(token.getIdentifier())));
    doAnswer(new GetLengthAnswer(sm, id)).when(mockDN).getReplicaVisibleLength(any(RpcController.class), any(GetReplicaVisibleLengthRequestProto.class));
    RPC.setProtocolEngine(conf, ClientDatanodeProtocolPB.class, ProtobufRpcEngine.class);
    BlockingService service = ClientDatanodeProtocolService.newReflectiveBlockingService(mockDN);
    return new RPC.Builder(conf).setProtocol(ClientDatanodeProtocolPB.class).setInstance(service).setBindAddress(ADDRESS).setPort(0).setNumHandlers(5).setVerbose(true).setSecretManager(sm).build();
}
Also used : RpcController(com.google.protobuf.RpcController) ByteArrayInputStream(java.io.ByteArrayInputStream) BlockingService(com.google.protobuf.BlockingService) ClientDatanodeProtocolPB(org.apache.hadoop.hdfs.protocolPB.ClientDatanodeProtocolPB) DataInputStream(java.io.DataInputStream) GetReplicaVisibleLengthRequestProto(org.apache.hadoop.hdfs.protocol.proto.ClientDatanodeProtocolProtos.GetReplicaVisibleLengthRequestProto)

Aggregations

BlockingService (com.google.protobuf.BlockingService)14 Configuration (org.apache.hadoop.conf.Configuration)9 RPC (org.apache.hadoop.ipc.RPC)5 InetSocketAddress (java.net.InetSocketAddress)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 Server (org.apache.hadoop.ipc.Server)3 HAServiceProtocolServerSideTranslatorPB (org.apache.hadoop.ha.protocolPB.HAServiceProtocolServerSideTranslatorPB)2 TestRpcService (org.apache.hadoop.ipc.TestRpcBase.TestRpcService)2 TestProtos (org.apache.hadoop.ipc.protobuf.TestProtos)2 ByteString (com.google.protobuf.ByteString)1 RpcController (com.google.protobuf.RpcController)1 ServiceException (com.google.protobuf.ServiceException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 ExecutorCompletionService (java.util.concurrent.ExecutorCompletionService)1 ExecutorService (java.util.concurrent.ExecutorService)1 OptionBuilder (org.apache.commons.cli.OptionBuilder)1 HDFSPolicyProvider (org.apache.hadoop.hdfs.HDFSPolicyProvider)1 GetReplicaVisibleLengthRequestProto (org.apache.hadoop.hdfs.protocol.proto.ClientDatanodeProtocolProtos.GetReplicaVisibleLengthRequestProto)1