Java Code Examples for org.apache.hadoop.ipc.ProtobufRpcEngine

The following examples show how to use org.apache.hadoop.ipc.ProtobufRpcEngine. 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: big-c   Source File: IPCLoggerChannel.java    License: 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 Project: hadoop-ozone   Source File: SCMTestUtils.java    License: 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 3
Source Project: hadoop-ozone   Source File: ContainerTestUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates an Endpoint class for testing purpose.
 *
 * @param conf - Conf
 * @param address - InetAddres
 * @param rpcTimeout - rpcTimeOut
 * @return EndPoint
 * @throws Exception
 */
public static EndpointStateMachine createEndpoint(Configuration conf,
    InetSocketAddress address, int rpcTimeout) throws Exception {
  RPC.setProtocolEngine(conf, StorageContainerDatanodeProtocolPB.class,
      ProtobufRpcEngine.class);
  long version =
      RPC.getProtocolVersion(StorageContainerDatanodeProtocolPB.class);

  StorageContainerDatanodeProtocolPB rpcProxy = RPC.getProtocolProxy(
      StorageContainerDatanodeProtocolPB.class, version,
      address, UserGroupInformation.getCurrentUser(), conf,
      NetUtils.getDefaultSocketFactory(conf), rpcTimeout,
      RetryPolicies.TRY_ONCE_THEN_FAIL).getProxy();

  StorageContainerDatanodeProtocolClientSideTranslatorPB rpcClient =
      new StorageContainerDatanodeProtocolClientSideTranslatorPB(rpcProxy);
  return new EndpointStateMachine(address, rpcClient,
      new LegacyHadoopConfigurationSource(conf));
}
 
Example 4
Source Project: hadoop-ozone   Source File: ContainerOperationClient.java    License: Apache License 2.0 6 votes vote down vote up
public static StorageContainerLocationProtocol newContainerRpcClient(
    ConfigurationSource configSource) throws IOException {

  Class<StorageContainerLocationProtocolPB> protocol =
      StorageContainerLocationProtocolPB.class;
  Configuration conf =
      LegacyHadoopConfigurationSource.asHadoopConfiguration(configSource);
  RPC.setProtocolEngine(conf, protocol, ProtobufRpcEngine.class);
  long version = RPC.getProtocolVersion(protocol);
  InetSocketAddress scmAddress = getScmAddressForClients(configSource);
  UserGroupInformation user = UserGroupInformation.getCurrentUser();
  SocketFactory socketFactory = NetUtils.getDefaultSocketFactory(conf);
  int rpcTimeOut = Client.getRpcTimeout(conf);

  StorageContainerLocationProtocolPB rpcProxy =
      RPC.getProxy(protocol, version, scmAddress, user, conf,
          socketFactory, rpcTimeOut);

  StorageContainerLocationProtocolClientSideTranslatorPB client =
      new StorageContainerLocationProtocolClientSideTranslatorPB(rpcProxy);
  return TracingUtil.createProxy(
      client, StorageContainerLocationProtocol.class, configSource);
}
 
Example 5
Source Project: hadoop-ozone   Source File: HddsServerUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Create a scm security client.
 * @param conf    - Ozone configuration.
 *
 * @return {@link SCMSecurityProtocol}
 * @throws IOException
 */
public static SCMSecurityProtocolClientSideTranslatorPB getScmSecurityClient(
    OzoneConfiguration conf) throws IOException {
  RPC.setProtocolEngine(conf, SCMSecurityProtocolPB.class,
      ProtobufRpcEngine.class);
  long scmVersion =
      RPC.getProtocolVersion(ScmBlockLocationProtocolPB.class);
  InetSocketAddress address =
      getScmAddressForSecurityProtocol(conf);
  RetryPolicy retryPolicy =
      RetryPolicies.retryForeverWithFixedSleep(
          1000, TimeUnit.MILLISECONDS);
  return new SCMSecurityProtocolClientSideTranslatorPB(
      RPC.getProtocolProxy(SCMSecurityProtocolPB.class, scmVersion,
          address, UserGroupInformation.getCurrentUser(),
          conf, NetUtils.getDefaultSocketFactory(conf),
          Client.getRpcTimeout(conf), retryPolicy).getProxy());
}
 
Example 6
Source Project: hadoop-ozone   Source File: BaseFreonGenerator.java    License: Apache License 2.0 6 votes vote down vote up
public StorageContainerLocationProtocol createStorageContainerLocationClient(
    OzoneConfiguration ozoneConf)
    throws IOException {

  long version = RPC.getProtocolVersion(
      StorageContainerLocationProtocolPB.class);
  InetSocketAddress scmAddress =
      getScmAddressForClients(ozoneConf);

  RPC.setProtocolEngine(ozoneConf, StorageContainerLocationProtocolPB.class,
      ProtobufRpcEngine.class);
  StorageContainerLocationProtocol client =
      TracingUtil.createProxy(
          new StorageContainerLocationProtocolClientSideTranslatorPB(
              RPC.getProxy(StorageContainerLocationProtocolPB.class, version,
                  scmAddress, UserGroupInformation.getCurrentUser(),
                  ozoneConf,
                  NetUtils.getDefaultSocketFactory(ozoneConf),
                  Client.getRpcTimeout(ozoneConf))),
          StorageContainerLocationProtocol.class, ozoneConf);
  return client;
}
 
Example 7
Source Project: hadoop-ozone   Source File: Hadoop3OmTransport.java    License: Apache License 2.0 6 votes vote down vote up
public Hadoop3OmTransport(ConfigurationSource conf,
    UserGroupInformation ugi, String omServiceId) throws IOException {

  RPC.setProtocolEngine(OzoneConfiguration.of(conf),
      OzoneManagerProtocolPB.class,
      ProtobufRpcEngine.class);

  this.omFailoverProxyProvider = new OMFailoverProxyProvider(conf, ugi,
      omServiceId);

  int maxFailovers = conf.getInt(
      OzoneConfigKeys.OZONE_CLIENT_FAILOVER_MAX_ATTEMPTS_KEY,
      OzoneConfigKeys.OZONE_CLIENT_FAILOVER_MAX_ATTEMPTS_DEFAULT);

  this.rpcProxy = createRetryProxy(omFailoverProxyProvider, maxFailovers);
}
 
Example 8
Source Project: hadoop-ozone   Source File: OMClientRequest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Get User information which needs to be set in the OMRequest object.
 * @return User Info.
 */
public OzoneManagerProtocolProtos.UserInfo getUserInfo() {
  UserGroupInformation user = ProtobufRpcEngine.Server.getRemoteUser();
  InetAddress remoteAddress = ProtobufRpcEngine.Server.getRemoteIp();
  OzoneManagerProtocolProtos.UserInfo.Builder userInfo =
      OzoneManagerProtocolProtos.UserInfo.newBuilder();

  // Added not null checks, as in UT's these values might be null.
  if (user != null) {
    userInfo.setUserName(user.getUserName());
  }

  if (remoteAddress != null) {
    userInfo.setHostName(remoteAddress.getHostName());
    userInfo.setRemoteAddress(remoteAddress.getHostAddress()).build();
  }

  return userInfo.build();
}
 
Example 9
Source Project: hadoop-ozone   Source File: OzoneManager.java    License: 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 10
Source Project: hadoop-ozone   Source File: OzoneManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns a scm container client.
 *
 * @return {@link StorageContainerLocationProtocol}
 * @throws IOException
 */
private static StorageContainerLocationProtocol getScmContainerClient(
    OzoneConfiguration conf) throws IOException {
  RPC.setProtocolEngine(conf, StorageContainerLocationProtocolPB.class,
      ProtobufRpcEngine.class);
  long scmVersion =
      RPC.getProtocolVersion(StorageContainerLocationProtocolPB.class);
  InetSocketAddress scmAddr = getScmAddressForClients(
      conf);
  StorageContainerLocationProtocol scmContainerClient =
      TracingUtil.createProxy(
          new StorageContainerLocationProtocolClientSideTranslatorPB(
              RPC.getProxy(StorageContainerLocationProtocolPB.class,
                  scmVersion,
                  scmAddr, UserGroupInformation.getCurrentUser(), conf,
                  NetUtils.getDefaultSocketFactory(conf),
                  Client.getRpcTimeout(conf))),
          StorageContainerLocationProtocol.class, conf);
  return scmContainerClient;
}
 
Example 11
Source Project: hadoop-ozone   Source File: OzoneManager.java    License: 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 12
Source Project: incubator-ratis   Source File: HadoopRpcService.java    License: 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 13
Source Project: big-c   Source File: DummyHAService.java    License: 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 14
Source Project: hadoop   Source File: TestBlockToken.java    License: 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 15
Source Project: big-c   Source File: TestBlockToken.java    License: 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 16
Source Project: hadoop   Source File: DummyHAService.java    License: 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 17
Source Project: big-c   Source File: ZKFCRpcServer.java    License: 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 18
Source Project: hadoop-ozone   Source File: SCMConnectionManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Adds a new Recon server to the set of endpoints.
 * @param address Recon address.
 * @throws IOException
 */
public void addReconServer(InetSocketAddress address) throws IOException {
  LOG.info("Adding Recon Server : {}", address.toString());
  writeLock();
  try {
    if (scmMachines.containsKey(address)) {
      LOG.warn("Trying to add an existing SCM Machine to Machines group. " +
          "Ignoring the request.");
      return;
    }
    Configuration hadoopConfig =
        LegacyHadoopConfigurationSource.asHadoopConfiguration(this.conf);
    RPC.setProtocolEngine(hadoopConfig, ReconDatanodeProtocolPB.class,
        ProtobufRpcEngine.class);
    long version =
        RPC.getProtocolVersion(ReconDatanodeProtocolPB.class);

    RetryPolicy retryPolicy =
        RetryPolicies.retryUpToMaximumCountWithFixedSleep(10,
            60000, TimeUnit.MILLISECONDS);
    ReconDatanodeProtocolPB rpcProxy = RPC.getProtocolProxy(
        ReconDatanodeProtocolPB.class, version,
        address, UserGroupInformation.getCurrentUser(), hadoopConfig,
        NetUtils.getDefaultSocketFactory(hadoopConfig), getRpcTimeout(),
        retryPolicy).getProxy();

    StorageContainerDatanodeProtocolClientSideTranslatorPB rpcClient =
        new StorageContainerDatanodeProtocolClientSideTranslatorPB(rpcProxy);

    EndpointStateMachine endPoint =
        new EndpointStateMachine(address, rpcClient, conf);
    endPoint.setPassive(true);
    scmMachines.put(address, endPoint);
  } finally {
    writeUnlock();
  }
}
 
Example 19
public HAServiceProtocolClientSideTranslatorPB(InetSocketAddress addr,
    Configuration conf) throws IOException {
  RPC.setProtocolEngine(conf, HAServiceProtocolPB.class,
      ProtobufRpcEngine.class);
  rpcProxy = RPC.getProxy(HAServiceProtocolPB.class,
      RPC.getProtocolVersion(HAServiceProtocolPB.class), addr, conf);
}
 
Example 20
Source Project: hadoop-ozone   Source File: SCMSecurityProtocolServer.java    License: 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());
  }
}
 
Example 21
Source Project: hadoop-ozone   Source File: SCMClientProtocolServer.java    License: Apache License 2.0 5 votes vote down vote up
public SCMClientProtocolServer(OzoneConfiguration conf,
    StorageContainerManager scm) throws IOException {
  this.scm = scm;
  this.conf = conf;
  safeModePrecheck = new SafeModePrecheck(conf);
  final int handlerCount =
      conf.getInt(OZONE_SCM_HANDLER_COUNT_KEY,
          OZONE_SCM_HANDLER_COUNT_DEFAULT);
  RPC.setProtocolEngine(conf, StorageContainerLocationProtocolPB.class,
      ProtobufRpcEngine.class);

  protocolMetrics = ProtocolMessageMetrics
      .create("ScmContainerLocationProtocol",
          "SCM ContainerLocation protocol metrics",
          StorageContainerLocationProtocolProtos.Type.values());

  // SCM Container Service RPC
  BlockingService storageProtoPbService =
      newReflectiveBlockingService(
          new StorageContainerLocationProtocolServerSideTranslatorPB(this,
              protocolMetrics));

  final InetSocketAddress scmAddress = HddsServerUtil
      .getScmClientBindAddress(conf);
  clientRpcServer =
      startRpcServer(
          conf,
          scmAddress,
          StorageContainerLocationProtocolPB.class,
          storageProtoPbService,
          handlerCount);
  clientRpcAddress =
      updateRPCListenAddress(conf, OZONE_SCM_CLIENT_ADDRESS_KEY,
          scmAddress, clientRpcServer);
  if (conf.getBoolean(CommonConfigurationKeys.HADOOP_SECURITY_AUTHORIZATION,
      false)) {
    clientRpcServer.refreshServiceAcl(conf, SCMPolicyProvider.getInstance());
  }
}
 
Example 22
Source Project: hadoop-ozone   Source File: HddsServerUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a scm block client, used by putKey() and getKey().
 *
 * @return {@link ScmBlockLocationProtocol}
 * @throws IOException
 */
public static SCMSecurityProtocol getScmSecurityClient(
    OzoneConfiguration conf, UserGroupInformation ugi) throws IOException {
  RPC.setProtocolEngine(conf, SCMSecurityProtocolPB.class,
      ProtobufRpcEngine.class);
  long scmVersion =
      RPC.getProtocolVersion(ScmBlockLocationProtocolPB.class);
  InetSocketAddress scmSecurityProtoAdd =
      getScmAddressForSecurityProtocol(conf);
  return new SCMSecurityProtocolClientSideTranslatorPB(
      RPC.getProxy(SCMSecurityProtocolPB.class, scmVersion,
          scmSecurityProtoAdd, ugi, conf,
          NetUtils.getDefaultSocketFactory(conf),
          Client.getRpcTimeout(conf)));
}
 
Example 23
Source Project: hadoop-ozone   Source File: BaseFreonGenerator.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create the OM RPC client to use it for testing.
 */
public OzoneManagerProtocolClientSideTranslatorPB createOmClient(
    OzoneConfiguration conf, String omServiceID) throws IOException {
  UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
  RPC.setProtocolEngine(conf, OzoneManagerProtocolPB.class,
      ProtobufRpcEngine.class);
  String clientId = ClientId.randomId().toString();
  OmTransport transport = OmTransportFactory.create(conf, ugi, omServiceID);
  return new OzoneManagerProtocolClientSideTranslatorPB(transport, clientId);
}
 
Example 24
Source Project: hadoop-ozone   Source File: OMFailoverProxyProvider.java    License: Apache License 2.0 5 votes vote down vote up
private OzoneManagerProtocolPB createOMProxy(InetSocketAddress omAddress)
    throws IOException {
  Configuration hadoopConf =
      LegacyHadoopConfigurationSource.asHadoopConfiguration(conf);
  RPC.setProtocolEngine(hadoopConf, OzoneManagerProtocolPB.class,
      ProtobufRpcEngine.class);
  return RPC.getProxy(OzoneManagerProtocolPB.class, omVersion, omAddress, ugi,
      hadoopConf, NetUtils.getDefaultSocketFactory(hadoopConf),
          (int) OmUtils.getOMClientRpcTimeOut(hadoopConf));

}
 
Example 25
Source Project: hadoop-ozone   Source File: OzoneManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * A variant of checkAcls that doesn't throw exception if permission denied.
 *
 * @return true if permission granted, false if permission denied.
 */
private boolean hasAcls(String userName, ResourceType resType,
    StoreType store, ACLType acl, String vol, String bucket, String key) {
  try {
    return checkAcls(resType, store, acl, vol, bucket, key,
        UserGroupInformation.createRemoteUser(userName),
        ProtobufRpcEngine.Server.getRemoteIp(),
        ProtobufRpcEngine.Server.getRemoteIp().getHostName(),
        false);
  } catch (OMException ex) {
    // Should not trigger exception here at all
    return false;
  }
}
 
Example 26
Source Project: hadoop-ozone   Source File: OzoneManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
/**
 * {@inheritDoc}
 */
public S3SecretValue getS3Secret(String kerberosID) throws IOException {
  UserGroupInformation user = ProtobufRpcEngine.Server.getRemoteUser();

  // Check whether user name passed is matching with the current user or not.
  if (!user.getUserName().equals(kerberosID)) {
    throw new OMException("User mismatch. Requested user name is " +
        "mismatched " + kerberosID + ", with current user " +
        user.getUserName(), OMException.ResultCodes.USER_MISMATCH);
  }
  return s3SecretManager.getS3Secret(kerberosID);
}
 
Example 27
@Before
public void setup() throws Exception {
  ozoneManager = Mockito.mock(OzoneManager.class);
  omMetrics = OMMetrics.create();
  OzoneConfiguration ozoneConfiguration = new OzoneConfiguration();
  ozoneConfiguration.set(OMConfigKeys.OZONE_OM_DB_DIRS,
      folder.newFolder().getAbsolutePath());
  omMetadataManager = new OmMetadataManagerImpl(ozoneConfiguration);
  when(ozoneManager.getMetrics()).thenReturn(omMetrics);
  when(ozoneManager.getMetadataManager()).thenReturn(omMetadataManager);
  inetAddress = InetAddress.getByName("127.0.0.1");

  new MockUp<ProtobufRpcEngine.Server>() {
    @Mock
    public UserGroupInformation getRemoteUser() {
      return userGroupInformation;
    }

    @Mock
    public InetAddress getRemoteIp() {
      return inetAddress;
    }

    public InetAddress getRemoteAddress() {
      return inetAddress;
    }
  };
}
 
Example 28
Source Project: big-c   Source File: NameNodeProxies.java    License: Apache License 2.0 5 votes vote down vote up
private static Object createNameNodeProxy(InetSocketAddress address,
    Configuration conf, UserGroupInformation ugi, Class<?> xface)
    throws IOException {
  RPC.setProtocolEngine(conf, xface, ProtobufRpcEngine.class);
  Object proxy = RPC.getProxy(xface, RPC.getProtocolVersion(xface), address,
      ugi, conf, NetUtils.getDefaultSocketFactory(conf));
  return proxy;
}
 
Example 29
Source Project: incubator-ratis   Source File: HadoopRpcService.java    License: Apache License 2.0 5 votes vote down vote up
private void addRaftClientProtocol(RaftServer server, Configuration conf) {
  final Class<?> protocol = CombinedClientProtocolPB.class;
  RPC.setProtocolEngine(conf, protocol, ProtobufRpcEngine.class);

  final BlockingService service = CombinedClientProtocolService.newReflectiveBlockingService(
      new CombinedClientProtocolServerSideTranslatorPB(server));
  ipcServer.addProtocol(RPC.RpcKind.RPC_PROTOCOL_BUFFER, protocol, service);
}
 
Example 30
public ApplicationMasterProtocolPBClientImpl(long clientVersion, InetSocketAddress addr,
    Configuration conf) throws IOException {
  RPC.setProtocolEngine(conf, ApplicationMasterProtocolPB.class, ProtobufRpcEngine.class);
  proxy =
      (ApplicationMasterProtocolPB) RPC.getProxy(ApplicationMasterProtocolPB.class, clientVersion,
        addr, conf);
}