org.apache.hadoop.ipc.RPC.Server Java Examples

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: HelloServer.java    From xxhadoop with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws HadoopIllegalArgumentException, IOException {
	Configuration conf = new Configuration();
	Builder builder = new RPC.Builder(conf);
	String bindAddress = "node-01";
	int port = 8888;
	builder.setBindAddress(bindAddress)
		.setPort(8888)
		.setProtocol(HelloProtocol.class)
		.setInstance(new HelloServer());
	Server server = builder.build();
	LOGGER.info("Server start to listen on " + port);
	server.start();
}
 
Example #2
Source File: AdminService.java    From hadoop 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 #3
Source File: AdminService.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Check that a request to change this node's HA state is valid.
 * In particular, verifies that, if auto failover is enabled, non-forced
 * requests from the HAAdmin CLI are rejected, and vice versa.
 *
 * @param req the request to check
 * @throws AccessControlException if the request is disallowed
 */
private void checkHaStateChange(StateChangeRequestInfo req)
    throws AccessControlException {
  switch (req.getSource()) {
    case REQUEST_BY_USER:
      if (autoFailoverEnabled) {
        throw new AccessControlException(
            "Manual failover for this ResourceManager is disallowed, " +
                "because automatic failover is enabled.");
      }
      break;
    case REQUEST_BY_USER_FORCED:
      if (autoFailoverEnabled) {
        LOG.warn("Allowing manual failover from " +
            org.apache.hadoop.ipc.Server.getRemoteAddress() +
            " even though automatic failover is enabled, because the user " +
            "specified the force flag");
      }
      break;
    case REQUEST_BY_ZKFC:
      if (!autoFailoverEnabled) {
        throw new AccessControlException(
            "Request from ZK failover controller at " +
                org.apache.hadoop.ipc.Server.getRemoteAddress() + " denied " +
                "since automatic failover is not enabled");
      }
      break;
  }
}
 
Example #4
Source File: RPCCallBenchmark.java    From hadoop 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 #5
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 #6
Source File: AdminService.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Check that a request to change this node's HA state is valid.
 * In particular, verifies that, if auto failover is enabled, non-forced
 * requests from the HAAdmin CLI are rejected, and vice versa.
 *
 * @param req the request to check
 * @throws AccessControlException if the request is disallowed
 */
private void checkHaStateChange(StateChangeRequestInfo req)
    throws AccessControlException {
  switch (req.getSource()) {
    case REQUEST_BY_USER:
      if (autoFailoverEnabled) {
        throw new AccessControlException(
            "Manual failover for this ResourceManager is disallowed, " +
                "because automatic failover is enabled.");
      }
      break;
    case REQUEST_BY_USER_FORCED:
      if (autoFailoverEnabled) {
        LOG.warn("Allowing manual failover from " +
            org.apache.hadoop.ipc.Server.getRemoteAddress() +
            " even though automatic failover is enabled, because the user " +
            "specified the force flag");
      }
      break;
    case REQUEST_BY_ZKFC:
      if (!autoFailoverEnabled) {
        throw new AccessControlException(
            "Request from ZK failover controller at " +
                org.apache.hadoop.ipc.Server.getRemoteAddress() + " denied " +
                "since automatic failover is not enabled");
      }
      break;
  }
}
 
Example #7
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 #8
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 #9
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 #10
Source File: AdminService.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
public Server getServer() {
  return this.server;
}
 
Example #11
Source File: AdminService.java    From big-c with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
public Server getServer() {
  return this.server;
}