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

The following examples show how to use org.apache.hadoop.ipc.RPC.Server. These examples are extracted from open source projects. 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 Project: xxhadoop   Source File: HelloServer.java    License: 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 Project: hadoop   Source File: AdminService.java    License: 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 Project: hadoop   Source File: AdminService.java    License: 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 Project: hadoop   Source File: RPCCallBenchmark.java    License: 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 Project: big-c   Source File: AdminService.java    License: 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 Project: big-c   Source File: AdminService.java    License: 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 Project: big-c   Source File: RPCCallBenchmark.java    License: 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 Project: incubator-tez   Source File: DAGClientServer.java    License: 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 Project: tez   Source File: DAGClientServer.java    License: 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 Project: hadoop   Source File: AdminService.java    License: Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
public Server getServer() {
  return this.server;
}
 
Example 11
Source Project: big-c   Source File: AdminService.java    License: Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
public Server getServer() {
  return this.server;
}