Java Code Examples for org.apache.hadoop.ipc.RPC#Server

The following examples show how to use org.apache.hadoop.ipc.RPC#Server . 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: 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 2
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 3
Source File: HadoopRpcService.java    From incubator-ratis with Apache License 2.0 6 votes vote down vote up
private static RPC.Server newRpcServer(
    RaftServerProtocol serverProtocol, final Configuration conf)
    throws IOException {
  final int handlerCount = HadoopConfigKeys.Ipc.handlers(conf);
  final InetSocketAddress address = HadoopConfigKeys.Ipc.address(conf);

  final BlockingService service
      = RaftServerProtocolService.newReflectiveBlockingService(
          new RaftServerProtocolServerSideTranslatorPB(serverProtocol));
  RPC.setProtocolEngine(conf, RaftServerProtocolPB.class, ProtobufRpcEngine.class);
  return new RPC.Builder(conf)
      .setProtocol(RaftServerProtocolPB.class)
      .setInstance(service)
      .setBindAddress(address.getHostName())
      .setPort(address.getPort())
      .setNumHandlers(handlerCount)
      .setVerbose(false)
      .build();
}
 
Example 4
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 5
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 6
Source File: RPCServer.java    From 163-bigdate-note with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
        Configuration configuration = new Configuration();
        RPC.Builder builder = new RPC.Builder(configuration);
        RPC.Server server = builder.setProtocol(UserService.class)
                .setInstance(new UserServiceImpl())
                .setBindAddress("localhost")
                .setPort(9999)
                .build();
//        System.setProperty("hadoop.home.dir", "C:\\winutils");
        server.start();
    }
 
Example 7
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 8
Source File: RpcServerFactoryPBImpl.java    From big-c with Apache License 2.0 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();
  LOG.info("Adding protocol "+pbProtocol.getCanonicalName()+" to the server");
  server.addProtocol(RPC.RpcKind.RPC_PROTOCOL_BUFFER, pbProtocol, blockingService);
  return server;
}
 
Example 9
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 10
Source File: RpcServerFactoryPBImpl.java    From hadoop with Apache License 2.0 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();
  LOG.info("Adding protocol "+pbProtocol.getCanonicalName()+" to the server");
  server.addProtocol(RPC.RpcKind.RPC_PROTOCOL_BUFFER, pbProtocol, blockingService);
  return server;
}
 
Example 11
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 12
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 13
Source File: NameNodeRpcServer.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/** Allow access to the lifeline RPC server for testing */
@VisibleForTesting
RPC.Server getLifelineRpcServer() {
  return lifelineRpcServer;
}
 
Example 14
Source File: NameNodeRpcServer.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/** Allow access to the client RPC server for testing */
@VisibleForTesting
RPC.Server getClientRpcServer() {
  return clientRpcServer;
}
 
Example 15
Source File: SCMSecurityProtocolServer.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
public RPC.Server getRpcServer() {
  return rpcServer;
}
 
Example 16
Source File: SCMBlockProtocolServer.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
public RPC.Server getBlockRpcServer() {
  return blockRpcServer;
}
 
Example 17
Source File: NameNodeRpcServer.java    From big-c with Apache License 2.0 4 votes vote down vote up
/** Allow access to the client RPC server for testing */
@VisibleForTesting
RPC.Server getClientRpcServer() {
  return clientRpcServer;
}
 
Example 18
Source File: ServerUtils.java    From hadoop-ozone with Apache License 2.0 3 votes vote down vote up
/**
 * After starting an RPC server, updates configuration with the actual
 * listening address of that server. The listening address may be different
 * from the configured address if, for example, the configured address uses
 * port 0 to request use of an ephemeral port.
 *
 * @param conf configuration to update
 * @param rpcAddressKey configuration key for RPC server address
 * @param addr configured address
 * @param rpcServer started RPC server.
 */
public static InetSocketAddress updateRPCListenAddress(
    OzoneConfiguration conf, String rpcAddressKey,
    InetSocketAddress addr, RPC.Server rpcServer) {
  return updateListenAddress(conf, rpcAddressKey, addr,
      rpcServer.getListenerAddress());
}
 
Example 19
Source File: HddsServerUtil.java    From hadoop-ozone with Apache License 2.0 2 votes vote down vote up
/**
 * Add protobuf-based protocol to the {@link RPC.Server}.
 * @param conf configuration
 * @param protocol Protocol interface
 * @param service service that implements the protocol
 * @param server RPC server to which the protocol & implementation is added to
 */
public static void addPBProtocol(Configuration conf, Class<?> protocol,
    BlockingService service, RPC.Server server) throws IOException {
  RPC.setProtocolEngine(conf, protocol, ProtobufRpcEngine.class);
  server.addProtocol(RPC.RpcKind.RPC_PROTOCOL_BUFFER, protocol, service);
}
 
Example 20
Source File: DFSUtil.java    From hadoop with Apache License 2.0 2 votes vote down vote up
/**
 * Add protobuf based protocol to the {@link org.apache.hadoop.ipc.RPC.Server}
 * @param conf configuration
 * @param protocol Protocol interface
 * @param service service that implements the protocol
 * @param server RPC server to which the protocol & implementation is added to
 * @throws IOException
 */
public static void addPBProtocol(Configuration conf, Class<?> protocol,
    BlockingService service, RPC.Server server) throws IOException {
  RPC.setProtocolEngine(conf, protocol, ProtobufRpcEngine.class);
  server.addProtocol(RPC.RpcKind.RPC_PROTOCOL_BUFFER, protocol, service);
}