com.google.protobuf.BlockingService Java Examples

The following examples show how to use com.google.protobuf.BlockingService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BlockingRpcServer.java    From tajo with Apache License 2.0 6 votes vote down vote up
public BlockingRpcServer(final Class<?> protocol,
                         final Object instance,
                         final InetSocketAddress bindAddress,
                         final int threads)
    throws Exception {

  super(protocol.getSimpleName(), bindAddress);

  String serviceClassName = protocol.getName() + "$" +
      protocol.getSimpleName() + "Service";
  Class<?> serviceClass = Class.forName(serviceClassName);
  Class<?> interfaceClass = Class.forName(serviceClassName +
      "$BlockingInterface");
  Method method = serviceClass.getMethod(
      "newReflectiveBlockingService", interfaceClass);

  this.service = (BlockingService) method.invoke(null, instance);
  this.initializer = new ProtoServerChannelInitializer(new ServerHandler(), RpcRequest.getDefaultInstance());

  super.init(this.initializer, threads);
}
 
Example #2
Source File: ZKFCRpcServer.java    From hadoop with Apache License 2.0 6 votes vote down vote up
ZKFCRpcServer(Configuration conf,
    InetSocketAddress bindAddr,
    ZKFailoverController zkfc,
    PolicyProvider policy) throws IOException {
  this.zkfc = zkfc;
  
  RPC.setProtocolEngine(conf, ZKFCProtocolPB.class,
      ProtobufRpcEngine.class);
  ZKFCProtocolServerSideTranslatorPB translator =
      new ZKFCProtocolServerSideTranslatorPB(this);
  BlockingService service = ZKFCProtocolService
      .newReflectiveBlockingService(translator);
  this.server = new RPC.Builder(conf).setProtocol(ZKFCProtocolPB.class)
      .setInstance(service).setBindAddress(bindAddr.getHostName())
      .setPort(bindAddr.getPort()).setNumHandlers(HANDLER_COUNT)
      .setVerbose(false).build();
  
  // set service-level authorization security policy
  if (conf.getBoolean(
      CommonConfigurationKeys.HADOOP_SECURITY_AUTHORIZATION, false)) {
    server.refreshServiceAcl(conf, policy);
  }

}
 
Example #3
Source File: TestBlockToken.java    From hadoop with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #4
Source File: ZKFCRpcServer.java    From big-c with Apache License 2.0 6 votes vote down vote up
ZKFCRpcServer(Configuration conf,
    InetSocketAddress bindAddr,
    ZKFailoverController zkfc,
    PolicyProvider policy) throws IOException {
  this.zkfc = zkfc;
  
  RPC.setProtocolEngine(conf, ZKFCProtocolPB.class,
      ProtobufRpcEngine.class);
  ZKFCProtocolServerSideTranslatorPB translator =
      new ZKFCProtocolServerSideTranslatorPB(this);
  BlockingService service = ZKFCProtocolService
      .newReflectiveBlockingService(translator);
  this.server = new RPC.Builder(conf).setProtocol(ZKFCProtocolPB.class)
      .setInstance(service).setBindAddress(bindAddr.getHostName())
      .setPort(bindAddr.getPort()).setNumHandlers(HANDLER_COUNT)
      .setVerbose(false).build();
  
  // set service-level authorization security policy
  if (conf.getBoolean(
      CommonConfigurationKeys.HADOOP_SECURITY_AUTHORIZATION, false)) {
    server.refreshServiceAcl(conf, policy);
  }

}
 
Example #5
Source File: TestBlockToken.java    From big-c with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #6
Source File: DummyHAService.java    From big-c with Apache License 2.0 6 votes vote down vote up
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;
  }
}
 
Example #7
Source File: TestProtoBufRpc.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Before
public  void setUp() throws IOException { // Setup server for both protocols
  conf = new Configuration();
  conf.setInt(CommonConfigurationKeys.IPC_MAXIMUM_DATA_LENGTH, 1024);
  // Set RPC engine to protobuf RPC engine
  RPC.setProtocolEngine(conf, TestRpcService.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();
}
 
Example #8
Source File: TestMultipleProtocolServer.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  // create a server with two handlers
  server = new RPC.Builder(conf).setProtocol(Foo0.class)
      .setInstance(new Foo0Impl()).setBindAddress(ADDRESS).setPort(0)
      .setNumHandlers(2).setVerbose(false).build();
  server.addProtocol(RPC.RpcKind.RPC_WRITABLE, Foo1.class, new Foo1Impl());
  server.addProtocol(RPC.RpcKind.RPC_WRITABLE, Bar.class, new BarImpl());
  server.addProtocol(RPC.RpcKind.RPC_WRITABLE, Mixin.class, new BarImpl());
  
  
  // Add Protobuf server
  // Create server side implementation
  PBServerImpl pbServerImpl = 
      new PBServerImpl();
  BlockingService service = TestProtobufRpcProto
      .newReflectiveBlockingService(pbServerImpl);
  server.addProtocol(RPC.RpcKind.RPC_PROTOCOL_BUFFER, TestRpcService.class,
      service);
  server.start();
  addr = NetUtils.getConnectAddress(server);
}
 
Example #9
Source File: DummyHAService.java    From hadoop with Apache License 2.0 6 votes vote down vote up
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;
  }
}
 
Example #10
Source File: RpcForwarder.java    From protobuf-socket-rpc with MIT License 6 votes vote down vote up
/**
 * Handle the blocking RPC request by forwarding it to the correct
 * service/method.
 *
 * @throws RpcException If there was some error executing the RPC.
 */
public SocketRpcProtos.Response doBlockingRpc(
    SocketRpcProtos.Request rpcRequest) throws RpcException {
  // Get the service, first try BlockingService
  BlockingService blockingService = blockingServiceMap.get(
      rpcRequest.getServiceName());
  if (blockingService != null) {
    return forwardToBlockingService(rpcRequest, blockingService);
  }

  // Now try Service
  Service service = serviceMap.get(rpcRequest.getServiceName());
  if (service == null) {
    throw new RpcException(ErrorReason.SERVICE_NOT_FOUND,
        "Could not find service: " + rpcRequest.getServiceName(), null);
  }

  // Call service using an instant callback
  Callback<Message> callback = new Callback<Message>();
  SocketRpcController socketController = new SocketRpcController();
  forwardToService(rpcRequest, callback, service, socketController);

  // Build and return response (callback invocation is optional)
  return createRpcResponse(callback.response, callback.invoked,
      socketController);
}
 
Example #11
Source File: TestProtoBufRpc.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Before
public  void setUp() throws IOException { // Setup server for both protocols
  conf = new Configuration();
  conf.setInt(CommonConfigurationKeys.IPC_MAXIMUM_DATA_LENGTH, 1024);
  // Set RPC engine to protobuf RPC engine
  RPC.setProtocolEngine(conf, TestRpcService.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();
}
 
Example #12
Source File: BlockingRpcServer.java    From incubator-tajo with Apache License 2.0 6 votes vote down vote up
public BlockingRpcServer(final Class<?> protocol,
                         final Object instance,
                         final InetSocketAddress bindAddress,
                         final int workerNum)
    throws Exception {

  super(protocol.getSimpleName(), bindAddress);

  String serviceClassName = protocol.getName() + "$" +
      protocol.getSimpleName() + "Service";
  Class<?> serviceClass = Class.forName(serviceClassName);
  Class<?> interfaceClass = Class.forName(serviceClassName +
      "$BlockingInterface");
  Method method = serviceClass.getMethod(
      "newReflectiveBlockingService", interfaceClass);

  this.service = (BlockingService) method.invoke(null, instance);
  this.pipeline = new ProtoPipelineFactory(new ServerHandler(),
      RpcRequest.getDefaultInstance());

  super.init(this.pipeline, workerNum);
}
 
Example #13
Source File: OzoneManager.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new instance of rpc server. If an earlier instance is already
 * running then returns the same.
 */
private RPC.Server getRpcServer(OzoneConfiguration conf) throws IOException {
  if (isOmRpcServerRunning) {
    return omRpcServer;
  }

  InetSocketAddress omNodeRpcAddr = OmUtils.getOmAddress(conf);

  final int handlerCount = conf.getInt(OZONE_OM_HANDLER_COUNT_KEY,
      OZONE_OM_HANDLER_COUNT_DEFAULT);
  RPC.setProtocolEngine(configuration, OzoneManagerProtocolPB.class,
      ProtobufRpcEngine.class);
  this.omServerProtocol = new OzoneManagerProtocolServerSideTranslatorPB(
      this, omRatisServer, omClientProtocolMetrics, isRatisEnabled);

  BlockingService omService = newReflectiveBlockingService(omServerProtocol);

  return startRpcServer(configuration, omNodeRpcAddr,
      OzoneManagerProtocolPB.class, omService,
      handlerCount);
}
 
Example #14
Source File: OzoneManager.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
/**
 * Starts an RPC server, if configured.
 *
 * @param conf         configuration
 * @param addr         configured address of RPC server
 * @param protocol     RPC protocol provided by RPC server
 * @param instance     RPC protocol implementation instance
 * @param handlerCount RPC server handler count
 * @return RPC server
 * @throws IOException if there is an I/O error while creating RPC server
 */
private RPC.Server startRpcServer(OzoneConfiguration conf,
    InetSocketAddress addr, Class<?> protocol, BlockingService instance,
    int handlerCount) throws IOException {
  RPC.Server rpcServer = new RPC.Builder(conf)
      .setProtocol(protocol)
      .setInstance(instance)
      .setBindAddress(addr.getHostString())
      .setPort(addr.getPort())
      .setNumHandlers(handlerCount)
      .setVerbose(false)
      .setSecretManager(delegationTokenMgr)
      .build();

  HddsServerUtil.addPBProtocol(conf, protocol, instance, rpcServer);

  if (conf.getBoolean(CommonConfigurationKeys.HADOOP_SECURITY_AUTHORIZATION,
      false)) {
    rpcServer.refreshServiceAcl(conf, OMPolicyProvider.getInstance());
  }
  return rpcServer;
}
 
Example #15
Source File: TestMultipleProtocolServer.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  // create a server with two handlers
  server = new RPC.Builder(conf).setProtocol(Foo0.class)
      .setInstance(new Foo0Impl()).setBindAddress(ADDRESS).setPort(0)
      .setNumHandlers(2).setVerbose(false).build();
  server.addProtocol(RPC.RpcKind.RPC_WRITABLE, Foo1.class, new Foo1Impl());
  server.addProtocol(RPC.RpcKind.RPC_WRITABLE, Bar.class, new BarImpl());
  server.addProtocol(RPC.RpcKind.RPC_WRITABLE, Mixin.class, new BarImpl());
  
  
  // Add Protobuf server
  // Create server side implementation
  PBServerImpl pbServerImpl = 
      new PBServerImpl();
  BlockingService service = TestProtobufRpcProto
      .newReflectiveBlockingService(pbServerImpl);
  server.addProtocol(RPC.RpcKind.RPC_PROTOCOL_BUFFER, TestRpcService.class,
      service);
  server.start();
  addr = NetUtils.getConnectAddress(server);
}
 
Example #16
Source File: StorageContainerManager.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
/**
 * Starts an RPC server, if configured.
 *
 * @param conf configuration
 * @param addr configured address of RPC server
 * @param protocol RPC protocol provided by RPC server
 * @param instance RPC protocol implementation instance
 * @param handlerCount RPC server handler count
 * @return RPC server
 * @throws IOException if there is an I/O error while creating RPC server
 */
public static RPC.Server startRpcServer(
    OzoneConfiguration conf,
    InetSocketAddress addr,
    Class<?> protocol,
    BlockingService instance,
    int handlerCount)
    throws IOException {
  RPC.Server rpcServer =
      new RPC.Builder(conf)
          .setProtocol(protocol)
          .setInstance(instance)
          .setBindAddress(addr.getHostString())
          .setPort(addr.getPort())
          .setNumHandlers(handlerCount)
          .setVerbose(false)
          .setSecretManager(null)
          .build();

  HddsServerUtil.addPBProtocol(conf, protocol, instance, rpcServer);
  return rpcServer;
}
 
Example #17
Source File: SCMTestUtils.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
/**
 * Starts an RPC server, if configured.
 *
 * @param conf configuration
 * @param addr configured address of RPC server
 * @param protocol RPC protocol provided by RPC server
 * @param instance RPC protocol implementation instance
 * @param handlerCount RPC server handler count
 * @return RPC server
 * @throws IOException if there is an I/O error while creating RPC server
 */
private static RPC.Server startRpcServer(Configuration conf,
    InetSocketAddress addr, Class<?>
    protocol, BlockingService instance, int handlerCount)
    throws IOException {
  RPC.Server rpcServer = new RPC.Builder(conf)
      .setProtocol(protocol)
      .setInstance(instance)
      .setBindAddress(addr.getHostString())
      .setPort(addr.getPort())
      .setNumHandlers(handlerCount)
      .setVerbose(false)
      .setSecretManager(null)
      .build();

  HddsServerUtil.addPBProtocol(conf, protocol, instance, rpcServer);
  return rpcServer;
}
 
Example #18
Source File: SCMTestUtils.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
/**
 * Start Datanode RPC server.
 */
public static RPC.Server startScmRpcServer(ConfigurationSource configuration,
    StorageContainerDatanodeProtocol server,
    InetSocketAddress rpcServerAddresss, int handlerCount) throws
    IOException {

  Configuration hadoopConfig =
      LegacyHadoopConfigurationSource.asHadoopConfiguration(configuration);
  RPC.setProtocolEngine(hadoopConfig,
      StorageContainerDatanodeProtocolPB.class,
      ProtobufRpcEngine.class);

  BlockingService scmDatanodeService =
      StorageContainerDatanodeProtocolService.
          newReflectiveBlockingService(
              new StorageContainerDatanodeProtocolServerSideTranslatorPB(
                  server, Mockito.mock(ProtocolMessageMetrics.class)));

  RPC.Server scmServer = startRpcServer(hadoopConfig, rpcServerAddresss,
      StorageContainerDatanodeProtocolPB.class, scmDatanodeService,
      handlerCount);

  scmServer.start();
  return scmServer;
}
 
Example #19
Source File: AdminService.java    From big-c with Apache License 2.0 5 votes vote down vote up
protected void startServer() throws Exception {
  Configuration conf = getConfig();
  YarnRPC rpc = YarnRPC.create(conf);
  this.server = (Server) rpc.getServer(
      ResourceManagerAdministrationProtocol.class, this, masterServiceBindAddress,
      conf, null,
      conf.getInt(YarnConfiguration.RM_ADMIN_CLIENT_THREAD_COUNT,
          YarnConfiguration.DEFAULT_RM_ADMIN_CLIENT_THREAD_COUNT));

  // Enable service authorization?
  if (conf.getBoolean(
      CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION,
      false)) {
    refreshServiceAcls(
        getConfiguration(conf,
            YarnConfiguration.HADOOP_POLICY_CONFIGURATION_FILE),
        RMPolicyProvider.getInstance());
  }

  if (rmContext.isHAEnabled()) {
    RPC.setProtocolEngine(conf, HAServiceProtocolPB.class,
        ProtobufRpcEngine.class);

    HAServiceProtocolServerSideTranslatorPB haServiceProtocolXlator =
        new HAServiceProtocolServerSideTranslatorPB(this);
    BlockingService haPbService =
        HAServiceProtocolProtos.HAServiceProtocolService
            .newReflectiveBlockingService(haServiceProtocolXlator);
    server.addProtocol(RPC.RpcKind.RPC_PROTOCOL_BUFFER,
        HAServiceProtocol.class, haPbService);
  }

  this.server.start();
  conf.updateConnectAddr(YarnConfiguration.RM_BIND_HOST,
                         YarnConfiguration.RM_ADMIN_ADDRESS,
                         YarnConfiguration.DEFAULT_RM_ADMIN_ADDRESS,
                         server.getListenerAddress());
}
 
Example #20
Source File: JournalNodeRpcServer.java    From big-c with Apache License 2.0 5 votes vote down vote up
JournalNodeRpcServer(Configuration conf, JournalNode jn) throws IOException {
  this.jn = jn;
  
  Configuration confCopy = new Configuration(conf);
  
  // Ensure that nagling doesn't kick in, which could cause latency issues.
  confCopy.setBoolean(
      CommonConfigurationKeysPublic.IPC_SERVER_TCPNODELAY_KEY,
      true);
  
  InetSocketAddress addr = getAddress(confCopy);
  RPC.setProtocolEngine(confCopy, QJournalProtocolPB.class,
      ProtobufRpcEngine.class);
  QJournalProtocolServerSideTranslatorPB translator =
      new QJournalProtocolServerSideTranslatorPB(this);
  BlockingService service = QJournalProtocolService
      .newReflectiveBlockingService(translator);
  
  this.server = new RPC.Builder(confCopy)
    .setProtocol(QJournalProtocolPB.class)
    .setInstance(service)
    .setBindAddress(addr.getHostName())
    .setPort(addr.getPort())
    .setNumHandlers(HANDLER_COUNT)
    .setVerbose(false)
    .build();

  // set service-level authorization security policy
  if (confCopy.getBoolean(
    CommonConfigurationKeys.HADOOP_SECURITY_AUTHORIZATION, false)) {
        server.refreshServiceAcl(confCopy, new HDFSPolicyProvider());
  }
}
 
Example #21
Source File: BackupNode.java    From big-c with Apache License 2.0 5 votes vote down vote up
private BackupNodeRpcServer(Configuration conf, BackupNode nn)
    throws IOException {
  super(conf, nn);
  JournalProtocolServerSideTranslatorPB journalProtocolTranslator = 
      new JournalProtocolServerSideTranslatorPB(this);
  BlockingService service = JournalProtocolService
      .newReflectiveBlockingService(journalProtocolTranslator);
  DFSUtil.addPBProtocol(conf, JournalProtocolPB.class, service,
      this.clientRpcServer);
}
 
Example #22
Source File: DAGClientServer.java    From tez with Apache License 2.0 5 votes vote down vote up
private Server createServer(Class<?> pbProtocol, InetSocketAddress addr, Configuration conf,
    int numHandlers,
    BlockingService blockingService, String portRangeConfig) throws IOException {
  RPC.setProtocolEngine(conf, pbProtocol, ProtobufRpcEngine.class);
  RPC.Server server = new RPC.Builder(conf).setProtocol(pbProtocol)
      .setInstance(blockingService).setBindAddress(addr.getHostString())
      .setPort(addr.getPort()).setNumHandlers(numHandlers).setVerbose(false)
      .setPortRangeConfig(portRangeConfig).setSecretManager(secretManager)
      .build();
  server.addProtocol(RPC.RpcKind.RPC_PROTOCOL_BUFFER, pbProtocol, blockingService);
  return server;
}
 
Example #23
Source File: RPC.java    From big-c with Apache License 2.0 5 votes vote down vote up
private void initProtocolMetaInfo(Configuration conf) {
  RPC.setProtocolEngine(conf, ProtocolMetaInfoPB.class,
      ProtobufRpcEngine.class);
  ProtocolMetaInfoServerSideTranslatorPB xlator = 
      new ProtocolMetaInfoServerSideTranslatorPB(this);
  BlockingService protocolInfoBlockingService = ProtocolInfoService
      .newReflectiveBlockingService(xlator);
  addProtocol(RpcKind.RPC_PROTOCOL_BUFFER, ProtocolMetaInfoPB.class,
      protocolInfoBlockingService);
}
 
Example #24
Source File: RPCCallBenchmark.java    From big-c with Apache License 2.0 5 votes vote down vote up
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 if (opts.rpcEngine == WritableRpcEngine.class) {
    server = new RPC.Builder(conf).setProtocol(TestProtocol.class)
        .setInstance(new TestRPC.TestImpl()).setBindAddress(opts.host)
        .setPort(opts.getPort()).setNumHandlers(opts.serverThreads)
        .setVerbose(false).build();
  } else {
    throw new RuntimeException("Bad engine: " + opts.rpcEngine);
  }
  server.start();
  return server;
}
 
Example #25
Source File: RPCService.java    From varOne with MIT License 5 votes vote down vote up
private Server createServer(Class<?> pbProtocol, InetSocketAddress addr, Configuration conf, 
    SecretManager<? extends TokenIdentifier> secretManager, int numHandlers, 
    BlockingService blockingService, String portRangeConfig) throws IOException {
  RPC.setProtocolEngine(conf, pbProtocol, ProtobufRpcEngine.class);
  RPC.Server server = new RPC.Builder(conf).setProtocol(pbProtocol)
      .setInstance(blockingService).setBindAddress(addr.getHostName())
      .setPort(addr.getPort()).setNumHandlers(numHandlers).setVerbose(false)
      .setSecretManager(secretManager).setPortRangeConfig(portRangeConfig)
      .build();
  System.out.println("Adding protocol "+pbProtocol.getCanonicalName()+" to the server");
  server.addProtocol(RPC.RpcKind.RPC_PROTOCOL_BUFFER, pbProtocol, blockingService);
  return server;
}
 
Example #26
Source File: DAGClientServer.java    From incubator-tez with Apache License 2.0 5 votes vote down vote up
@Override
public void serviceStart() {
  try {
    Configuration conf = getConfig();
    InetSocketAddress addr = new InetSocketAddress(0);

    DAGClientAMProtocolBlockingPBServerImpl service =
        new DAGClientAMProtocolBlockingPBServerImpl(realInstance);

    BlockingService blockingService =
              DAGClientAMProtocol.newReflectiveBlockingService(service);

    int numHandlers = conf.getInt(TezConfiguration.TEZ_AM_CLIENT_THREAD_COUNT,
                        TezConfiguration.TEZ_AM_CLIENT_THREAD_COUNT_DEFAULT);

    String portRange = conf.get(TezConfiguration.TEZ_AM_CLIENT_AM_PORT_RANGE);

    server = createServer(DAGClientAMProtocolBlockingPB.class, addr, conf,
                          numHandlers, blockingService, portRange);
    
    // Enable service authorization?
    if (conf.getBoolean(
        CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION,
        false)) {
      refreshServiceAcls(conf, new TezAMPolicyProvider());
    }

    server.start();
    bindAddress = NetUtils.getConnectAddress(server);
    LOG.info("Instantiated DAGClientRPCServer at " + bindAddress);
  } catch (Exception e) {
    LOG.error("Failed to start DAGClientServer: ", e);
    throw new TezUncheckedException(e);
  }
}
 
Example #27
Source File: DAGClientServer.java    From incubator-tez with Apache License 2.0 5 votes vote down vote up
private Server createServer(Class<?> pbProtocol, InetSocketAddress addr, Configuration conf,
    int numHandlers,
    BlockingService blockingService, String portRangeConfig) throws IOException {
  RPC.setProtocolEngine(conf, pbProtocol, ProtobufRpcEngine.class);
  RPC.Server server = new RPC.Builder(conf).setProtocol(pbProtocol)
      .setInstance(blockingService).setBindAddress(addr.getHostName())
      .setPort(addr.getPort()).setNumHandlers(numHandlers).setVerbose(false)
      .setPortRangeConfig(portRangeConfig).setSecretManager(secretManager)
      .build();
  server.addProtocol(RPC.RpcKind.RPC_PROTOCOL_BUFFER, pbProtocol, blockingService);
  return server;
}
 
Example #28
Source File: TezTestServiceProtocolServerImpl.java    From tez with Apache License 2.0 5 votes vote down vote up
private RPC.Server createServer(Class<?> pbProtocol, InetSocketAddress addr, Configuration conf,
                                int numHandlers, BlockingService blockingService) throws
    IOException {
  RPC.setProtocolEngine(conf, pbProtocol, ProtobufRpcEngine.class);
  RPC.Server server = new RPC.Builder(conf)
      .setProtocol(pbProtocol)
      .setInstance(blockingService)
      .setBindAddress(addr.getHostName())
      .setPort(0)
      .setNumHandlers(numHandlers)
      .build();
  // TODO Add security.
  return server;
}
 
Example #29
Source File: DAGClientServer.java    From tez with Apache License 2.0 5 votes vote down vote up
@Override
public void serviceStart() {
  try {
    Configuration conf = getConfig();
    InetSocketAddress addr = new InetSocketAddress(0);

    DAGClientAMProtocolBlockingPBServerImpl service =
        new DAGClientAMProtocolBlockingPBServerImpl(realInstance, stagingFs);

    BlockingService blockingService =
              DAGClientAMProtocol.newReflectiveBlockingService(service);

    int numHandlers = conf.getInt(TezConfiguration.TEZ_AM_CLIENT_THREAD_COUNT,
                        TezConfiguration.TEZ_AM_CLIENT_THREAD_COUNT_DEFAULT);
    if (numHandlers < 2) {
      numHandlers = 2;
    }

    server = createServer(DAGClientAMProtocolBlockingPB.class, addr, conf,
                          numHandlers, blockingService, TezConfiguration.TEZ_AM_CLIENT_AM_PORT_RANGE);
    
    // Enable service authorization?
    if (conf.getBoolean(
        CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION,
        false)) {
      refreshServiceAcls(conf, new TezAMPolicyProvider());
    }

    server.start();
    InetSocketAddress serverBindAddress = NetUtils.getConnectAddress(server);
    this.bindAddress = NetUtils.createSocketAddrForHost(
        serverBindAddress.getAddress().getCanonicalHostName(),
        serverBindAddress.getPort());
    LOG.info("Instantiated DAGClientRPCServer at " + bindAddress);
  } catch (Exception e) {
    LOG.error("Failed to start DAGClientServer: ", e);
    throw new TezUncheckedException(e);
  }
}
 
Example #30
Source File: SCMSecurityProtocolServer.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
SCMSecurityProtocolServer(OzoneConfiguration conf,
    CertificateServer certificateServer) throws IOException {
  this.certificateServer = certificateServer;

  final int handlerCount =
      conf.getInt(ScmConfigKeys.OZONE_SCM_SECURITY_HANDLER_COUNT_KEY,
          ScmConfigKeys.OZONE_SCM_SECURITY_HANDLER_COUNT_DEFAULT);
  rpcAddress = HddsServerUtil
      .getScmSecurityInetAddress(conf);
  // SCM security service RPC service.
  RPC.setProtocolEngine(conf, SCMSecurityProtocolPB.class,
      ProtobufRpcEngine.class);
  metrics = new ProtocolMessageMetrics("ScmSecurityProtocol",
      "SCM Security protocol metrics",
      SCMSecurityProtocolProtos.Type.values());
  BlockingService secureProtoPbService =
      SCMSecurityProtocolProtos.SCMSecurityProtocolService
          .newReflectiveBlockingService(
              new SCMSecurityProtocolServerSideTranslatorPB(this, metrics));
  this.rpcServer =
      StorageContainerManager.startRpcServer(
          conf,
          rpcAddress,
          SCMSecurityProtocolPB.class,
          secureProtoPbService,
          handlerCount);
  if (conf.getBoolean(
      CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION, false)) {
    rpcServer.refreshServiceAcl(conf, SCMPolicyProvider.getInstance());
  }
}