org.apache.ratis.rpc.RpcType Java Examples

The following examples show how to use org.apache.ratis.rpc.RpcType. 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: RaftClient.java    From ratis with Apache License 2.0 6 votes vote down vote up
/** @return a {@link RaftClient} object. */
public RaftClient build() {
  if (clientId == null) {
    clientId = ClientId.randomId();
  }
  if (properties != null) {
    if (clientRpc == null) {
      final RpcType rpcType = RaftConfigKeys.Rpc.type(properties, LOG::debug);
      final ClientFactory factory = ClientFactory.cast(rpcType.newFactory(parameters));
      clientRpc = factory.newRaftClientRpc(clientId, properties);
    }
  }
  return ClientImplUtils.newRaftClient(clientId,
      Objects.requireNonNull(group, "The 'group' field is not initialized."),
      leaderId,
      Objects.requireNonNull(clientRpc, "The 'clientRpc' field is not initialized."),
      properties, retryPolicy);
}
 
Example #2
Source File: RaftClient.java    From incubator-ratis with Apache License 2.0 6 votes vote down vote up
/** @return a {@link RaftClient} object. */
public RaftClient build() {
  if (clientId == null) {
    clientId = ClientId.randomId();
  }
  if (properties != null) {
    if (clientRpc == null) {
      final RpcType rpcType = RaftConfigKeys.Rpc.type(properties, LOG::debug);
      final ClientFactory factory = ClientFactory.cast(rpcType.newFactory(parameters));
      clientRpc = factory.newRaftClientRpc(clientId, properties);
    }
  }
  return ClientImplUtils.newRaftClient(clientId,
      Objects.requireNonNull(group, "The 'group' field is not initialized."),
      leaderId,
      Objects.requireNonNull(clientRpc, "The 'clientRpc' field is not initialized."),
      properties, retryPolicy);
}
 
Example #3
Source File: XceiverClientRatis.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a client.
 */
private XceiverClientRatis(Pipeline pipeline, RpcType rpcType,
    RetryPolicy retryPolicy, GrpcTlsConfig tlsConfig,
    ConfigurationSource configuration) {
  super();
  this.pipeline = pipeline;
  this.rpcType = rpcType;
  this.retryPolicy = retryPolicy;
  commitInfoMap = new ConcurrentHashMap<>();
  this.tlsConfig = tlsConfig;
  metrics = XceiverClientManager.getXceiverClientMetrics();
  this.ozoneConfiguration = configuration;
}
 
Example #4
Source File: RaftServerProxy.java    From ratis with Apache License 2.0 5 votes vote down vote up
RaftServerProxy(RaftPeerId id, StateMachine.Registry stateMachineRegistry,
    RaftProperties properties, Parameters parameters) {
  this.properties = properties;
  this.stateMachineRegistry = stateMachineRegistry;

  final RpcType rpcType = RaftConfigKeys.Rpc.type(properties, LOG::info);
  this.factory = ServerFactory.cast(rpcType.newFactory(parameters));

  this.serverRpc = factory.newRaftServerRpc(this);
  this.id = id != null? id: RaftPeerId.valueOf(getIdStringFrom(serverRpc));
  this.lifeCycle = new LifeCycle(this.id + "-" + getClass().getSimpleName());
}
 
Example #5
Source File: RaftServerProxy.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
RaftServerProxy(RaftPeerId id, StateMachine.Registry stateMachineRegistry,
    RaftProperties properties, Parameters parameters) {
  this.properties = properties;
  this.stateMachineRegistry = stateMachineRegistry;

  final RpcType rpcType = RaftConfigKeys.Rpc.type(properties, LOG::info);
  this.factory = ServerFactory.cast(rpcType.newFactory(parameters));

  this.serverRpc = factory.newRaftServerRpc(this);
  this.id = id != null? id: RaftPeerId.valueOf(getIdStringFrom(serverRpc));
  this.lifeCycle = new LifeCycle(this.id + "-" + getClass().getSimpleName());

  this.implExecutor = Executors.newSingleThreadExecutor();
}
 
Example #6
Source File: RatisTestHelper.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
static void initXceiverServerRatis(
    RpcType rpc, DatanodeDetails dd, Pipeline pipeline) throws IOException {
  final RaftPeer p = RatisHelper.toRaftPeer(dd);
  final OzoneConfiguration conf = new OzoneConfiguration();
  final RaftClient client =
      newRaftClient(rpc, p, RatisHelper.createRetryPolicy(conf), conf);
  client.groupAdd(RatisHelper.newRaftGroup(pipeline), p.getId());
}
 
Example #7
Source File: RatisTestHelper.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
static void initRatisConf(RpcType rpc, OzoneConfiguration conf) {
  conf.setBoolean(OzoneConfigKeys.DFS_CONTAINER_RATIS_ENABLED_KEY, true);
  conf.set(OzoneConfigKeys.DFS_CONTAINER_RATIS_RPC_TYPE_KEY, rpc.name());
  conf.setTimeDuration(HDDS_CONTAINER_REPORT_INTERVAL, 1, TimeUnit.SECONDS);
  conf.setTimeDuration(OZONE_SCM_STALENODE_INTERVAL, 30, TimeUnit.SECONDS);
  LOG.info("{} = {}", OzoneConfigKeys.DFS_CONTAINER_RATIS_RPC_TYPE_KEY,
          rpc.name());
}
 
Example #8
Source File: TestSecureContainerServer.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
static void runTestClientServerRatis(RpcType rpc, int numNodes)
    throws Exception {
  runTestClientServer(numNodes,
      (pipeline, conf) -> RatisTestHelper.initRatisConf(rpc, conf),
      XceiverClientRatis::newXceiverClientRatis,
      TestSecureContainerServer::newXceiverServerRatis,
      (dn, p) -> RatisTestHelper.initXceiverServerRatis(rpc, dn, p),
      (p) -> {});
}
 
Example #9
Source File: TestContainerServer.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
static void runTestClientServerRatis(RpcType rpc, int numNodes)
    throws Exception {
  runTestClientServer(numNodes,
      (pipeline, conf) -> RatisTestHelper.initRatisConf(rpc, conf),
      XceiverClientRatis::newXceiverClientRatis,
      TestContainerServer::newXceiverServerRatis,
      (dn, p) -> RatisTestHelper.initXceiverServerRatis(rpc, dn, p));
}
 
Example #10
Source File: XceiverServerRatis.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
private RpcType setRpcType(RaftProperties properties) {
  final String rpcType = conf.get(
      OzoneConfigKeys.DFS_CONTAINER_RATIS_RPC_TYPE_KEY,
      OzoneConfigKeys.DFS_CONTAINER_RATIS_RPC_TYPE_DEFAULT);
  final RpcType rpc = SupportedRpcType.valueOfIgnoreCase(rpcType);
  RaftConfigKeys.Rpc.setType(properties, rpc);
  return rpc;
}
 
Example #11
Source File: RatisHelper.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("checkstyle:ParameterNumber")
private static RaftClient newRaftClient(RpcType rpcType, RaftPeerId leader,
    RaftGroup group, RetryPolicy retryPolicy,
    GrpcTlsConfig tlsConfig, ConfigurationSource ozoneConfiguration) {
  if (LOG.isTraceEnabled()) {
    LOG.trace("newRaftClient: {}, leader={}, group={}",
        rpcType, leader, group);
  }
  final RaftProperties properties = new RaftProperties();

  RaftConfigKeys.Rpc.setType(properties, rpcType);

  // Set the ratis client headers which are matching with regex.
  createRaftClientProperties(ozoneConfiguration, properties);

  RaftClient.Builder builder =  RaftClient.newBuilder()
      .setRaftGroup(group)
      .setLeaderId(leader)
      .setProperties(properties)
      .setRetryPolicy(retryPolicy);

  // TODO: GRPC TLS only for now, netty/hadoop RPC TLS support later.
  if (tlsConfig != null && rpcType == SupportedRpcType.GRPC) {
    builder.setParameters(GrpcFactory.newRaftParameters(tlsConfig));
  }
  return builder.build();
}
 
Example #12
Source File: RatisHelper.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
public static RaftClient newRaftClient(RpcType rpcType, RaftPeer leader,
    RetryPolicy retryPolicy,
    ConfigurationSource ozoneConfiguration) {
  return newRaftClient(rpcType, leader.getId(),
      newRaftGroup(Collections.singletonList(leader)), retryPolicy, null,
      ozoneConfiguration);
}
 
Example #13
Source File: RatisHelper.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
public static RaftClient newRaftClient(RpcType rpcType, Pipeline pipeline,
    RetryPolicy retryPolicy, GrpcTlsConfig tlsConfig,
    ConfigurationSource ozoneConfiguration) throws IOException {
  return newRaftClient(rpcType,
      toRaftPeerId(pipeline.getLeaderNode()),
      newRaftGroup(RaftGroupId.valueOf(pipeline.getId().getId()),
          pipeline.getNodes()), retryPolicy, tlsConfig, ozoneConfiguration);
}
 
Example #14
Source File: RatisHelper.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
public static RaftClient newRaftClient(RpcType rpcType, RaftPeer leader,
    RetryPolicy retryPolicy, GrpcTlsConfig tlsConfig,
    ConfigurationSource configuration) {
  return newRaftClient(rpcType, leader.getId(),
      newRaftGroup(Collections.singletonList(leader)), retryPolicy,
      tlsConfig, configuration);
}
 
Example #15
Source File: RatisHelper.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
private static RpcType getRpcType(ConfigurationSource conf) {
  return SupportedRpcType.valueOfIgnoreCase(conf.get(
      ScmConfigKeys.DFS_CONTAINER_RATIS_RPC_TYPE_KEY,
      ScmConfigKeys.DFS_CONTAINER_RATIS_RPC_TYPE_DEFAULT));
}
 
Example #16
Source File: SimulatedRpc.java    From ratis with Apache License 2.0 4 votes vote down vote up
@Override
public RpcType getRpcType() {
  return INSTANCE;
}
 
Example #17
Source File: RaftServerProxy.java    From ratis with Apache License 2.0 4 votes vote down vote up
@Override
public RpcType getRpcType() {
  return getFactory().getRpcType();
}
 
Example #18
Source File: RaftConfigKeys.java    From ratis with Apache License 2.0 4 votes vote down vote up
static void setType(RaftProperties properties, RpcType type) {
  set(properties::set, TYPE_KEY, type.name());
}
 
Example #19
Source File: RaftConfigKeys.java    From ratis with Apache License 2.0 4 votes vote down vote up
static RpcType type(RaftProperties properties, Consumer<String> logger) {
  final String t = get(properties::get, TYPE_KEY, TYPE_DEFAULT, logger);
  return RpcType.valueOf(t);
}
 
Example #20
Source File: SimulatedRpc.java    From incubator-ratis with Apache License 2.0 4 votes vote down vote up
@Override
public RpcType getRpcType() {
  return INSTANCE;
}
 
Example #21
Source File: RaftServerProxy.java    From incubator-ratis with Apache License 2.0 4 votes vote down vote up
@Override
public RpcType getRpcType() {
  return getFactory().getRpcType();
}
 
Example #22
Source File: TestOzoneContainerRatis.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
private static void runTestBothGetandPutSmallFileRatis(
    RpcType rpc, int numNodes) throws Exception {
  runTest("runTestBothGetandPutSmallFileRatis", rpc, numNodes,
      TestOzoneContainer::runTestBothGetandPutSmallFile);
}
 
Example #23
Source File: RaftConfigKeys.java    From incubator-ratis with Apache License 2.0 4 votes vote down vote up
static void setType(RaftProperties properties, RpcType type) {
  set(properties::set, TYPE_KEY, type.name());
}
 
Example #24
Source File: RaftConfigKeys.java    From incubator-ratis with Apache License 2.0 4 votes vote down vote up
static RpcType type(RaftProperties properties, Consumer<String> logger) {
  final String t = get(properties::get, TYPE_KEY, TYPE_DEFAULT, logger);
  return RpcType.valueOf(t);
}
 
Example #25
Source File: RatisTestHelper.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
static OzoneConfiguration newOzoneConfiguration(RpcType rpc) {
  final OzoneConfiguration conf = new OzoneConfiguration();
  initRatisConf(rpc, conf);
  return conf;
}
 
Example #26
Source File: TestOzoneContainerRatis.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
private static void runTestOzoneContainerViaDataNodeRatis(
    RpcType rpc, int numNodes) throws Exception {
  runTest("runTestOzoneContainerViaDataNodeRatis", rpc, numNodes,
      TestOzoneContainer::runTestOzoneContainerViaDataNode);
}
 
Example #27
Source File: TestOzoneContainerRatis.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
private static void runTest(
      String testName, RpcType rpc, int numNodes,
      CheckedBiConsumer<Long, XceiverClientSpi, Exception> test)
      throws Exception {
    LOG.info("{}(rpc={}, numNodes={}", testName, rpc, numNodes);

    // create Ozone clusters
    final OzoneConfiguration conf = newOzoneConfiguration();
    RatisTestHelper.initRatisConf(rpc, conf);
    final MiniOzoneCluster cluster =
        MiniOzoneCluster.newBuilder(conf)
        .setNumDatanodes(numNodes)
        .build();
    try {
      cluster.waitForClusterToBeReady();

      final String containerName = OzoneUtils.getRequestID();
      final List<HddsDatanodeService> datanodes = cluster.getHddsDatanodes();
      final Pipeline pipeline = MockPipeline.createPipeline(
          CollectionUtils.as(datanodes,
              HddsDatanodeService::getDatanodeDetails));
      LOG.info("pipeline={}", pipeline);

      // Create Ratis cluster
//      final String ratisId = "ratis1";
//      final PipelineManager manager = RatisManagerImpl.newRatisManager(conf);
//      manager.createPipeline(ratisId, pipeline.getNodes());
//      LOG.info("Created RatisCluster " + ratisId);
//
//      // check Ratis cluster members
//      final List<DatanodeDetails> dns = manager.getMembers(ratisId);
//      Assert.assertEquals(pipeline.getNodes(), dns);
//
//      // run test
//      final XceiverClientSpi client = XceiverClientRatis
// .newXceiverClientRatis(
//          pipeline, conf);
//      test.accept(containerName, client);
    } finally {
      cluster.shutdown();
    }
  }