Java Code Examples for org.apache.hadoop.ipc.RPC#setProtocolEngine()

The following examples show how to use org.apache.hadoop.ipc.RPC#setProtocolEngine() . 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: IPCLoggerChannel.java    From hadoop with Apache License 2.0 6 votes vote down vote up
protected QJournalProtocol createProxy() throws IOException {
  final Configuration confCopy = new Configuration(conf);
  
  // Need to set NODELAY or else batches larger than MTU can trigger 
  // 40ms nagling delays.
  confCopy.setBoolean(
      CommonConfigurationKeysPublic.IPC_CLIENT_TCPNODELAY_KEY,
      true);
  
  RPC.setProtocolEngine(confCopy,
      QJournalProtocolPB.class, ProtobufRpcEngine.class);
  return SecurityUtil.doAsLoginUser(
      new PrivilegedExceptionAction<QJournalProtocol>() {
        @Override
        public QJournalProtocol run() throws IOException {
          RPC.setProtocolEngine(confCopy,
              QJournalProtocolPB.class, ProtobufRpcEngine.class);
          QJournalProtocolPB pbproxy = RPC.getProxy(
              QJournalProtocolPB.class,
              RPC.getProtocolVersion(QJournalProtocolPB.class),
              addr, confCopy);
          return new QJournalProtocolTranslatorPB(pbproxy);
        }
      });
}
 
Example 2
Source File: OzoneManager.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
/**
 * Create a scm block client, used by putKey() and getKey().
 *
 * @return {@link ScmBlockLocationProtocol}
 * @throws IOException
 */
private static ScmBlockLocationProtocol getScmBlockClient(
    OzoneConfiguration conf) throws IOException {
  RPC.setProtocolEngine(conf, ScmBlockLocationProtocolPB.class,
      ProtobufRpcEngine.class);
  long scmVersion =
      RPC.getProtocolVersion(ScmBlockLocationProtocolPB.class);
  InetSocketAddress scmBlockAddress =
      getScmAddressForBlockClients(conf);
  ScmBlockLocationProtocolClientSideTranslatorPB scmBlockLocationClient =
      new ScmBlockLocationProtocolClientSideTranslatorPB(
          RPC.getProxy(ScmBlockLocationProtocolPB.class, scmVersion,
              scmBlockAddress, UserGroupInformation.getCurrentUser(), conf,
              NetUtils.getDefaultSocketFactory(conf),
              Client.getRpcTimeout(conf)));
  return TracingUtil
      .createProxy(scmBlockLocationClient, ScmBlockLocationProtocol.class,
          conf);
}
 
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: 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 5
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 6
Source File: ClientDatanodeProtocolTranslatorPB.java    From hadoop with Apache License 2.0 5 votes vote down vote up
static ClientDatanodeProtocolPB createClientDatanodeProtocolProxy(
    InetSocketAddress addr, UserGroupInformation ticket, Configuration conf,
    SocketFactory factory, int socketTimeout) throws IOException {
  RPC.setProtocolEngine(conf, ClientDatanodeProtocolPB.class,
      ProtobufRpcEngine.class);
  return RPC.getProxy(ClientDatanodeProtocolPB.class,
      RPC.getProtocolVersion(ClientDatanodeProtocolPB.class), addr, ticket,
      conf, factory, socketTimeout);
}
 
Example 7
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 8
Source File: HSProxies.java    From big-c with Apache License 2.0 5 votes vote down vote up
private static Object createHSProxy(InetSocketAddress address,
    Configuration conf, UserGroupInformation ugi, Class<?> xface,
    int rpcTimeout) throws IOException {
  RPC.setProtocolEngine(conf, xface, ProtobufRpcEngine.class);
  Object proxy = RPC.getProxy(xface, RPC.getProtocolVersion(xface), address,
      ugi, conf, NetUtils.getDefaultSocketFactory(conf), rpcTimeout);
  return proxy;
}
 
Example 9
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 10
Source File: Proxy.java    From ratis with Apache License 2.0 5 votes vote down vote up
public static <PROTOCOL> PROTOCOL getProxy(
    Class<PROTOCOL> clazz, String addressStr, Configuration conf)
    throws IOException {
  RPC.setProtocolEngine(conf, clazz, ProtobufRpcEngineShaded.class);
  return RPC.getProxy(clazz, RPC.getProtocolVersion(clazz),
      org.apache.ratis.util.NetUtils.createSocketAddr(addressStr),
      UserGroupInformation.getCurrentUser(),
      conf, NetUtils.getSocketFactory(conf, clazz));
}
 
Example 11
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 12
Source File: Proxy.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
public static <PROTOCOL> PROTOCOL getProxy(
    Class<PROTOCOL> clazz, String addressStr, Configuration conf)
    throws IOException {
  RPC.setProtocolEngine(conf, clazz, ProtobufRpcEngine.class);
  return RPC.getProxy(clazz, RPC.getProtocolVersion(clazz),
      org.apache.ratis.util.NetUtils.createSocketAddr(addressStr),
      UserGroupInformation.getCurrentUser(),
      conf, NetUtils.getSocketFactory(conf, clazz));
}
 
Example 13
Source File: DatanodeProtocolClientSideTranslatorPB.java    From big-c with Apache License 2.0 5 votes vote down vote up
public DatanodeProtocolClientSideTranslatorPB(InetSocketAddress nameNodeAddr,
    Configuration conf) throws IOException {
  RPC.setProtocolEngine(conf, DatanodeProtocolPB.class,
      ProtobufRpcEngine.class);
  UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
  rpcProxy = createNamenode(nameNodeAddr, conf, ugi);
}
 
Example 14
Source File: HSProxies.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private static Object createHSProxy(InetSocketAddress address,
    Configuration conf, UserGroupInformation ugi, Class<?> xface,
    int rpcTimeout) throws IOException {
  RPC.setProtocolEngine(conf, xface, ProtobufRpcEngine.class);
  Object proxy = RPC.getProxy(xface, RPC.getProtocolVersion(xface), address,
      ugi, conf, NetUtils.getDefaultSocketFactory(conf), rpcTimeout);
  return proxy;
}
 
Example 15
Source File: ZKFCProtocolClientSideTranslatorPB.java    From big-c with Apache License 2.0 5 votes vote down vote up
public ZKFCProtocolClientSideTranslatorPB(
    InetSocketAddress addr, Configuration conf,
    SocketFactory socketFactory, int timeout) throws IOException {
  RPC.setProtocolEngine(conf, ZKFCProtocolPB.class,
      ProtobufRpcEngine.class);
  rpcProxy = RPC.getProxy(ZKFCProtocolPB.class,
      RPC.getProtocolVersion(ZKFCProtocolPB.class), addr,
      UserGroupInformation.getCurrentUser(), conf, socketFactory, timeout);
}
 
Example 16
Source File: TezTestServiceProtocolClientImpl.java    From tez with Apache License 2.0 5 votes vote down vote up
public TezTestServiceProtocolBlockingPB createProxy() throws IOException {
  TezTestServiceProtocolBlockingPB p;
  // TODO Fix security
  RPC.setProtocolEngine(conf, TezTestServiceProtocolBlockingPB.class, ProtobufRpcEngine.class);
  p = (TezTestServiceProtocolBlockingPB) RPC
      .getProxy(TezTestServiceProtocolBlockingPB.class, 0, serverAddr, conf);
  return p;
}
 
Example 17
Source File: HSClientProtocolPBClientImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public HSClientProtocolPBClientImpl(long clientVersion,
    InetSocketAddress addr, Configuration conf) throws IOException {
  super();
  RPC.setProtocolEngine(conf, HSClientProtocolPB.class,
      ProtobufRpcEngine.class);
  proxy = (HSClientProtocolPB)RPC.getProxy(
      HSClientProtocolPB.class, clientVersion, addr, conf);
}
 
Example 18
Source File: MRClientProtocolPBClientImpl.java    From big-c with Apache License 2.0 4 votes vote down vote up
public MRClientProtocolPBClientImpl(long clientVersion, InetSocketAddress addr, Configuration conf) throws IOException {
  RPC.setProtocolEngine(conf, MRClientProtocolPB.class, ProtobufRpcEngine.class);
  proxy = RPC.getProxy(MRClientProtocolPB.class, clientVersion, addr, conf);
}
 
Example 19
Source File: ApplicationClientProtocolPBClientImpl.java    From hadoop with Apache License 2.0 4 votes vote down vote up
public ApplicationClientProtocolPBClientImpl(long clientVersion,
    InetSocketAddress addr, Configuration conf) throws IOException {
  RPC.setProtocolEngine(conf, ApplicationClientProtocolPB.class,
    ProtobufRpcEngine.class);
  proxy = RPC.getProxy(ApplicationClientProtocolPB.class, clientVersion, addr, conf);
}
 
Example 20
Source File: TraceAdmin.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override
public int run(String argv[]) throws Exception {
  LinkedList<String> args = new LinkedList<String>();
  for (String arg : argv) {
    args.add(arg);
  }
  if (StringUtils.popOption("-h", args) ||
      StringUtils.popOption("-help", args)) {
    usage();
    return 0;
  } else if (args.size() == 0) {
    usage();
    return 0;
  }
  String hostPort = StringUtils.popOptionWithArgument("-host", args);
  if (hostPort == null) {
    System.err.println("You must specify a host with -host.");
    return 1;
  }
  if (args.size() < 0) {
    System.err.println("You must specify an operation.");
    return 1;
  }
  RPC.setProtocolEngine(getConf(), TraceAdminProtocolPB.class,
      ProtobufRpcEngine.class);
  InetSocketAddress address = NetUtils.createSocketAddr(hostPort);
  UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
  Class<?> xface = TraceAdminProtocolPB.class;
  proxy = (TraceAdminProtocolPB)RPC.getProxy(xface,
      RPC.getProtocolVersion(xface), address,
      ugi, getConf(), NetUtils.getDefaultSocketFactory(getConf()), 0);
  remote = new TraceAdminProtocolTranslatorPB(proxy);
  try {
    if (args.get(0).equals("-list")) {
      return listSpanReceivers(args.subList(1, args.size()));
    } else if (args.get(0).equals("-add")) {
      return addSpanReceiver(args.subList(1, args.size()));
    } else if (args.get(0).equals("-remove")) {
      return removeSpanReceiver(args.subList(1, args.size()));
    } else {
      System.err.println("Unrecognized tracing command: " + args.get(0));
      System.err.println("Use -help for help.");
      return 1;
    }
  } finally {
    remote.close();
  }
}