org.apache.ratis.protocol.ClientId Java Examples

The following examples show how to use org.apache.ratis.protocol.ClientId. 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: ReconControllerModule.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
@Provides
OzoneManagerProtocol getOzoneManagerProtocol(
    final OzoneConfiguration ozoneConfiguration) {
  OzoneManagerProtocol ozoneManagerClient = null;
  try {
    ClientId clientId = ClientId.randomId();
    UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
    OmTransport transport =
        OmTransportFactory.create(ozoneConfiguration, ugi,
            ozoneConfiguration.get(OZONE_OM_INTERNAL_SERVICE_ID));
    ozoneManagerClient = new
        OzoneManagerProtocolClientSideTranslatorPB(
        transport, clientId.toString());
  } catch (IOException ioEx) {
    LOG.error("Error in provisioning OzoneManagerProtocol ", ioEx);
  }
  return ozoneManagerClient;
}
 
Example #2
Source File: TestRatisPipelineLeader.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
private boolean verifyLeaderInfo(Pipeline ratisPipeline) throws Exception {
  Optional<HddsDatanodeService> hddsDatanodeService =
      cluster.getHddsDatanodes().stream().filter(s ->
          s.getDatanodeStateMachine().getDatanodeDetails().getUuid()
              .equals(ratisPipeline.getLeaderId())).findFirst();
  Assert.assertTrue(hddsDatanodeService.isPresent());

  XceiverServerRatis serverRatis =
      (XceiverServerRatis) hddsDatanodeService.get()
          .getDatanodeStateMachine().getContainer().getWriteChannel();

  GroupInfoRequest groupInfoRequest = new GroupInfoRequest(
      ClientId.randomId(), serverRatis.getServer().getId(),
      RaftGroupId.valueOf(ratisPipeline.getId().getId()), 100);
  GroupInfoReply reply =
      serverRatis.getServer().getGroupInfo(groupInfoRequest);
  return reply.getRoleInfoProto().hasLeaderInfo() &&
      ratisPipeline.getLeaderId().toString().equals(
          reply.getRoleInfoProto().getSelf().getId().toStringUtf8());
}
 
Example #3
Source File: TestRetryCacheMetrics.java    From incubator-ratis with Apache License 2.0 6 votes vote down vote up
@Test
public void testRetryCacheHitMissCount() {
  checkHit(0, 1.0);
  checkMiss(0, 0.0);

  ClientId clientId = ClientId.randomId();
  retryCache.getOrCreateEntry(clientId, 2);

  checkHit(0, 0.0);
  checkMiss(1, 1.0);

  retryCache.getOrCreateEntry(clientId, 2);

  checkHit(1, 0.5);
  checkMiss(1, 0.5);
}
 
Example #4
Source File: Client.java    From ratis with Apache License 2.0 6 votes vote down vote up
@Override
public void run() throws Exception {
  RaftProperties raftProperties = new RaftProperties();

  final RaftGroup raftGroup = RaftGroup.valueOf(RaftGroupId.valueOf(ByteString.copyFromUtf8(raftGroupId)),
      parsePeers(peers));

  RaftClient.Builder builder =
      RaftClient.newBuilder().setProperties(raftProperties);
  builder.setRaftGroup(raftGroup);
  builder.setClientRpc(new GrpcFactory(new Parameters()).newRaftClientRpc(ClientId.randomId(), raftProperties));
  RaftClient client = builder.build();

  operation(client);


}
 
Example #5
Source File: Client.java    From incubator-ratis with Apache License 2.0 6 votes vote down vote up
@Override
public void run() throws Exception {
  RaftProperties raftProperties = new RaftProperties();

  final RaftGroup raftGroup = RaftGroup.valueOf(RaftGroupId.valueOf(ByteString.copyFromUtf8(getRaftGroupId())),
          getPeers());

  RaftClient.Builder builder =
      RaftClient.newBuilder().setProperties(raftProperties);
  builder.setRaftGroup(raftGroup);
  builder.setClientRpc(new GrpcFactory(new Parameters()).newRaftClientRpc(ClientId.randomId(), raftProperties));
  RaftClient client = builder.build();

  operation(client);


}
 
Example #6
Source File: ServerProtoUtils.java    From ratis with Apache License 2.0 6 votes vote down vote up
static String toLogEntryString(LogEntryProto entry) {
  if (entry == null) {
    return null;
  }
  final String s;
  if (entry.hasStateMachineLogEntry()) {
    final StateMachineLogEntryProto smLog = entry.getStateMachineLogEntry();
    final ByteString clientId = smLog.getClientId();
    s = ", " + (clientId.isEmpty()? "<empty clientId>": ClientId.valueOf(clientId)) + ", cid=" + smLog.getCallId();
  } else if (entry.hasMetadataEntry()) {
    final MetadataProto metadata = entry.getMetadataEntry();
    s = "(c" + metadata.getCommitIndex() + ")";
  } else {
    s = "";
  }
  return toTermIndexString(entry) + ", " + entry.getLogEntryBodyCase() + s;
}
 
Example #7
Source File: RetryCacheTestUtil.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
public static void createEntry(RetryCache cache, LogEntryProto logEntry){
  if(logEntry.hasStateMachineLogEntry()) {
    final StateMachineLogEntryProto smLogEntry = logEntry.getStateMachineLogEntry();
    final ClientId clientId = ClientId.valueOf(smLogEntry.getClientId());
    final long callId = smLogEntry.getCallId();
    cache.getOrCreateEntry(clientId, callId);
  }
}
 
Example #8
Source File: ServerProtoUtils.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
static String toStateMachineLogEntryString(StateMachineLogEntryProto smLog,
                                           Function<StateMachineLogEntryProto, String> function) {
  final ByteString clientId = smLog.getClientId();
  String callIdString = (clientId.isEmpty() ? "<empty clientId>" : ClientId.valueOf(clientId))
      + ", cid=" + smLog.getCallId();

  String smString = "";
  if (function != null) {
    smString = "\n\t State Machine: " + function.apply(smLog);
  }
  return callIdString + smString;
}
 
Example #9
Source File: TestRetryCacheMetrics.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
@Test
public void testRetryCacheEntryCount() {
  checkEntryCount(0);

  ClientId clientId = ClientId.randomId();
  RetryCache.CacheKey key = new RetryCache.CacheKey(clientId, 1);
  RetryCache.CacheEntry entry = new RetryCache.CacheEntry(key);

  retryCache.refreshEntry(entry);
  checkEntryCount(1);

  retryCache.close();
  checkEntryCount(0);
}
 
Example #10
Source File: RetryCache.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
CacheQueryResult queryCache(ClientId clientId, long callId) {
  CacheKey key = new CacheKey(clientId, callId);
  final CacheEntry newEntry = new CacheEntry(key);
  CacheEntry cacheEntry;
  try {
    cacheEntry = cache.get(key, () -> newEntry);
  } catch (ExecutionException e) {
    throw new IllegalStateException(e);
  }

  if (cacheEntry == newEntry) {
    // this is the entry we just newly created
    return new CacheQueryResult(cacheEntry, false);
  } else if (!cacheEntry.isDone() || !cacheEntry.isFailed()){
    // the previous attempt is either pending or successful
    return new CacheQueryResult(cacheEntry, true);
  }

  // the previous attempt failed, replace it with a new one.
  synchronized (this) {
    // need to recheck, since there may be other retry attempts being
    // processed at the same time. The recheck+replacement should be protected
    // by lock.
    CacheEntry currentEntry = cache.getIfPresent(key);
    if (currentEntry == cacheEntry || currentEntry == null) {
      // if the failed entry has not got replaced by another retry, or the
      // failed entry got invalidated, we add a new cache entry
      return new CacheQueryResult(refreshEntry(newEntry), false);
    } else {
      return new CacheQueryResult(currentEntry, true);
    }
  }
}
 
Example #11
Source File: RetryCache.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
CacheEntry getOrCreateEntry(ClientId clientId, long callId) {
  final CacheKey key = new CacheKey(clientId, callId);
  final CacheEntry entry;
  try {
    entry = cache.get(key, () -> new CacheEntry(key));
  } catch (ExecutionException e) {
    throw new IllegalStateException(e);
  }
  return entry;
}
 
Example #12
Source File: ServerProtoUtils.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
static StateMachineLogEntryProto toStateMachineLogEntryProto(
    ClientId clientId, long callId, ByteString logData, ByteString stateMachineData) {
  final StateMachineLogEntryProto.Builder b = StateMachineLogEntryProto.newBuilder()
      .setClientId(clientId.toByteString())
      .setCallId(callId)
      .setLogData(logData);
  if (stateMachineData != null) {
    b.setStateMachineEntry(toStateMachineEntryProtoBuilder(stateMachineData));
  }
  return b.build();
}
 
Example #13
Source File: LogStateMachine.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
private RaftClient getClient() throws IOException {
  if (client == null) {
    try {
      RaftServer raftServer = getServer().get();
      client = RaftClient.newBuilder().setRaftGroup(getGroupFromGroupId(raftServer, getGroupId()))
          .setClientId(ClientId.randomId())
          .setProperties(raftServer.getProperties()).build();
    } catch (Exception e) {
      throw new IOException(e);
    }
  }
  return client;
}
 
Example #14
Source File: LeaderAppendLogEntryGenerator.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
private void configureGroup() throws IOException {
  ClientId clientId = ClientId.randomId();

  RaftGroupId groupId = RaftGroupId
      .valueOf(UUID.fromString(pipelineId));
  RaftPeerId peerId =
      RaftPeerId.getRaftPeerId(serverId);

  RaftGroup group = RaftGroup.valueOf(groupId,
      new RaftPeer(RaftPeerId.valueOf(serverId), serverAddress),
      new RaftPeer(RaftPeerId.valueOf(FAKE_FOLLOWER_ID1),
          FAKE_LEADER_ADDDRESS1),
      new RaftPeer(RaftPeerId.valueOf(FAKE_FOLLOWER_ID1),
          FAKE_LEADER_ADDDRESS2));
  RaftClient client = RaftClient.newBuilder()
      .setClientId(clientId)
      .setProperties(new RaftProperties(true))
      .setRaftGroup(group)
      .build();

  RaftClientReply raftClientReply = client.groupAdd(group, peerId);

  LOG.info(
      "Group is configured in the RAFT server (with two fake leader leader)"
          + ": {}",
      raftClientReply);
}
 
Example #15
Source File: TestClientProtoUtils.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
void runTestToRaftClientRequestProto(int n, SizeInBytes messageSize)
    throws Exception {
  final ClientId clientId = ClientId.randomId();
  final RaftPeerId leaderId = RaftPeerId.valueOf("s0");
  final RaftGroupId groupId = RaftGroupId.randomId();


  TimeDuration toProto = TimeDuration.ZERO;
  TimeDuration toRequest = TimeDuration.ZERO;

  for(int i = 0; i < n; i++) {
    final ByteString bytes = newByteString(messageSize.getSizeInt(), i);
    final RaftClientRequest request = new RaftClientRequest(clientId, leaderId, groupId,
        1, () -> bytes, RaftClientRequest.writeRequestType(), null);

    final Timestamp startTime = Timestamp.currentTime();
    final RaftClientRequestProto proto = ClientProtoUtils.toRaftClientRequestProto(request);
    final TimeDuration p = startTime.elapsedTime();
    final RaftClientRequest computed = ClientProtoUtils.toRaftClientRequest(proto);
    final TimeDuration r = startTime.elapsedTime().subtract(p);

    Assert.assertEquals(request.getMessage().getContent(), computed.getMessage().getContent());
    toProto = toProto.add(p);
    toRequest = toRequest.add(r);

  }

  System.out.printf("%nmessageSize=%s, n=%d%n", messageSize, n);
  print("toProto  ", toProto, n);
  print("toRequest", toRequest, n);
}
 
Example #16
Source File: Client.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
@Override
public void run() throws Exception {
  int raftSegmentPreallocatedSize = 1024 * 1024 * 1024;
  RaftProperties raftProperties = new RaftProperties();
  RaftConfigKeys.Rpc.setType(raftProperties, SupportedRpcType.GRPC);
  GrpcConfigKeys.setMessageSizeMax(raftProperties,
      SizeInBytes.valueOf(raftSegmentPreallocatedSize));
  RaftServerConfigKeys.Log.Appender.setBufferByteLimit(raftProperties,
      SizeInBytes.valueOf(raftSegmentPreallocatedSize));
  RaftServerConfigKeys.Log.setWriteBufferSize(raftProperties,
      SizeInBytes.valueOf(raftSegmentPreallocatedSize));
  RaftServerConfigKeys.Log.setPreallocatedSize(raftProperties,
      SizeInBytes.valueOf(raftSegmentPreallocatedSize));
  RaftServerConfigKeys.Log.setSegmentSizeMax(raftProperties,
      SizeInBytes.valueOf(1 * 1024 * 1024 * 1024));

  RaftServerConfigKeys.Log.setSegmentCacheNumMax(raftProperties, 2);

  RaftClientConfigKeys.Rpc.setRequestTimeout(raftProperties,
      TimeDuration.valueOf(50000, TimeUnit.MILLISECONDS));
  RaftClientConfigKeys.Async.setOutstandingRequestsMax(raftProperties, 1000);


  final RaftGroup raftGroup = RaftGroup.valueOf(RaftGroupId.valueOf(ByteString.copyFromUtf8(getRaftGroupId())),
          getPeers());

  RaftClient.Builder builder =
      RaftClient.newBuilder().setProperties(raftProperties);
  builder.setRaftGroup(raftGroup);
  builder.setClientRpc(new GrpcFactory(new Parameters()).newRaftClientRpc(ClientId.randomId(), raftProperties));
  RaftClient client = builder.build();

  operation(client);
}
 
Example #17
Source File: GrpcOutputStream.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
public GrpcOutputStream(RaftProperties prop, ClientId clientId,
    RaftGroup group, RaftPeerId leaderId, GrpcTlsConfig tlsConfig) {
  final int bufferSize = GrpcConfigKeys.OutputStream.bufferSize(prop).getSizeInt();
  buf = new byte[bufferSize];
  count = 0;
  this.clientId = clientId;
  streamer = new GrpcClientStreamer(prop, group, leaderId, clientId, tlsConfig);
}
 
Example #18
Source File: RetryCacheTests.java    From ratis with Apache License 2.0 5 votes vote down vote up
public void assertServer(MiniRaftCluster cluster, ClientId clientId, long callId, long oldLastApplied) throws Exception {
  long leaderApplied = cluster.getLeader().getState().getLastAppliedIndex();
  // make sure retry cache has the entry
  for (RaftServerImpl server : cluster.iterateServerImpls()) {
    LOG.info("check server " + server.getId());
    if (server.getState().getLastAppliedIndex() < leaderApplied) {
      Thread.sleep(1000);
    }
    Assert.assertEquals(2, RaftServerTestUtil.getRetryCacheSize(server));
    Assert.assertNotNull(RaftServerTestUtil.getRetryEntry(server, clientId, callId));
    // make sure there is only one log entry committed
    Assert.assertEquals(1, count(server.getState().getLog(), oldLastApplied + 1));
  }
}
 
Example #19
Source File: RetryCacheTestUtil.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
public static void assertFailure(RetryCache cache, LogEntryProto logEntry, boolean isFailed) {
  if(logEntry.hasStateMachineLogEntry()) {
    final StateMachineLogEntryProto smLogEntry = logEntry.getStateMachineLogEntry();
    final ClientId clientId = ClientId.valueOf(smLogEntry.getClientId());
    final long callId = smLogEntry.getCallId();
    Assert.assertEquals(isFailed, cache.get(clientId, callId).isFailed());
  }
}
 
Example #20
Source File: RetryCacheTests.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
public void assertServer(MiniRaftCluster cluster, ClientId clientId, long callId, long oldLastApplied) throws Exception {
  long leaderApplied = cluster.getLeader().getState().getLastAppliedIndex();
  // make sure retry cache has the entry
  for (RaftServerImpl server : cluster.iterateServerImpls()) {
    LOG.info("check server " + server.getId());
    if (server.getState().getLastAppliedIndex() < leaderApplied) {
      Thread.sleep(1000);
    }
    Assert.assertEquals(2, RaftServerTestUtil.getRetryCacheSize(server));
    Assert.assertNotNull(RaftServerTestUtil.getRetryEntry(server, clientId, callId));
    // make sure there is only one log entry committed
    Assert.assertEquals(1, count(server.getState().getLog(), oldLastApplied + 1));
  }
}
 
Example #21
Source File: Client.java    From ratis with Apache License 2.0 5 votes vote down vote up
@Override
public void run() throws Exception {
  int raftSegmentPreallocatedSize = 1024 * 1024 * 1024;
  RaftProperties raftProperties = new RaftProperties();
  RaftConfigKeys.Rpc.setType(raftProperties, SupportedRpcType.GRPC);
  GrpcConfigKeys.setMessageSizeMax(raftProperties,
      SizeInBytes.valueOf(raftSegmentPreallocatedSize));
  RaftServerConfigKeys.Log.Appender.setBufferByteLimit(raftProperties,
      SizeInBytes.valueOf(raftSegmentPreallocatedSize));
  RaftServerConfigKeys.Log.setWriteBufferSize(raftProperties,
      SizeInBytes.valueOf(raftSegmentPreallocatedSize));
  RaftServerConfigKeys.Log.setPreallocatedSize(raftProperties,
      SizeInBytes.valueOf(raftSegmentPreallocatedSize));
  RaftServerConfigKeys.Log.setSegmentSizeMax(raftProperties,
      SizeInBytes.valueOf(1 * 1024 * 1024 * 1024));

  RaftServerConfigKeys.Log.setMaxCachedSegmentNum(raftProperties, 2);

  RaftClientConfigKeys.Rpc.setRequestTimeout(raftProperties,
      TimeDuration.valueOf(50000, TimeUnit.MILLISECONDS));
  RaftClientConfigKeys.Async.setSchedulerThreads(raftProperties, 10);
  RaftClientConfigKeys.Async.setMaxOutstandingRequests(raftProperties, 1000);


  final RaftGroup raftGroup = RaftGroup.valueOf(RaftGroupId.valueOf(ByteString.copyFromUtf8(raftGroupId)),
      parsePeers(peers));

  RaftClient.Builder builder =
      RaftClient.newBuilder().setProperties(raftProperties);
  builder.setRaftGroup(raftGroup);
  builder.setClientRpc(new GrpcFactory(new Parameters()).newRaftClientRpc(ClientId.randomId(), raftProperties));
  RaftClient client = builder.build();

  operation(client);
}
 
Example #22
Source File: GrpcClientProtocolClient.java    From ratis with Apache License 2.0 5 votes vote down vote up
public GrpcClientProtocolClient(ClientId id, RaftPeer target,
                                RaftProperties properties,
                                GrpcTlsConfig tlsConf) {
  this.name = JavaUtils.memoize(() -> id + "->" + target.getId());
  this.target = target;
  final SizeInBytes flowControlWindow = GrpcConfigKeys.flowControlWindow(properties, LOG::debug);
  final SizeInBytes maxMessageSize = GrpcConfigKeys.messageSizeMax(properties, LOG::debug);
  NettyChannelBuilder channelBuilder =
      NettyChannelBuilder.forTarget(target.getAddress());

  if (tlsConf!= null) {
    SslContextBuilder sslContextBuilder = GrpcSslContexts.forClient();
    if (tlsConf.getTrustStore() != null) {
      sslContextBuilder.trustManager(tlsConf.getTrustStore());
    }
    if (tlsConf.getMtlsEnabled()) {
      sslContextBuilder.keyManager(tlsConf.getCertChain(),
          tlsConf.getPrivateKey());
    }
    try {
      channelBuilder.useTransportSecurity().sslContext(sslContextBuilder.build());
    } catch (Exception ex) {
      throw new RuntimeException(ex);
    }
  } else {
    channelBuilder.negotiationType(NegotiationType.PLAINTEXT);
  }
  channel = channelBuilder.flowControlWindow(flowControlWindow.getSizeInt())
      .maxInboundMessageSize(maxMessageSize.getSizeInt())
      .build();
  blockingStub = RaftClientProtocolServiceGrpc.newBlockingStub(channel);
  asyncStub = RaftClientProtocolServiceGrpc.newStub(channel);
  adminBlockingStub = AdminProtocolServiceGrpc.newBlockingStub(channel);
  this.requestTimeoutDuration = RaftClientConfigKeys.Rpc.requestTimeout(properties);
}
 
Example #23
Source File: GrpcOutputStream.java    From ratis with Apache License 2.0 5 votes vote down vote up
public GrpcOutputStream(RaftProperties prop, ClientId clientId,
    RaftGroup group, RaftPeerId leaderId, GrpcTlsConfig tlsConfig) {
  final int bufferSize = GrpcConfigKeys.OutputStream.bufferSize(prop).getSizeInt();
  buf = new byte[bufferSize];
  count = 0;
  this.clientId = clientId;
  streamer = new GrpcClientStreamer(prop, group, leaderId, clientId, tlsConfig);
}
 
Example #24
Source File: ServerProtoUtils.java    From ratis with Apache License 2.0 5 votes vote down vote up
static StateMachineLogEntryProto toStateMachineLogEntryProto(
    ClientId clientId, long callId, ByteString logData, ByteString stateMachineData) {
  final StateMachineLogEntryProto.Builder b = StateMachineLogEntryProto.newBuilder()
      .setClientId(clientId.toByteString())
      .setCallId(callId)
      .setLogData(logData);
  if (stateMachineData != null) {
    b.setStateMachineEntry(toStateMachineEntryProtoBuilder(stateMachineData));
  }
  return b.build();
}
 
Example #25
Source File: RetryCache.java    From ratis with Apache License 2.0 5 votes vote down vote up
CacheEntry getOrCreateEntry(ClientId clientId, long callId) {
  final CacheKey key = new CacheKey(clientId, callId);
  final CacheEntry entry;
  try {
    entry = cache.get(key, () -> new CacheEntry(key));
  } catch (ExecutionException e) {
    throw new IllegalStateException(e);
  }
  Preconditions.assertTrue(entry != null && !entry.isCompletedNormally(),
      "retry cache entry should be pending: %s", entry);
  return entry;
}
 
Example #26
Source File: RetryCache.java    From ratis with Apache License 2.0 5 votes vote down vote up
CacheQueryResult queryCache(ClientId clientId, long callId) {
  CacheKey key = new CacheKey(clientId, callId);
  final CacheEntry newEntry = new CacheEntry(key);
  CacheEntry cacheEntry;
  try {
    cacheEntry = cache.get(key, () -> newEntry);
  } catch (ExecutionException e) {
    throw new IllegalStateException(e);
  }

  if (cacheEntry == newEntry) {
    // this is the entry we just newly created
    return new CacheQueryResult(cacheEntry, false);
  } else if (!cacheEntry.isDone() || !cacheEntry.isFailed()){
    // the previous attempt is either pending or successful
    return new CacheQueryResult(cacheEntry, true);
  }

  // the previous attempt failed, replace it with a new one.
  synchronized (this) {
    // need to recheck, since there may be other retry attempts being
    // processed at the same time. The recheck+replacement should be protected
    // by lock.
    CacheEntry currentEntry = cache.getIfPresent(key);
    if (currentEntry == cacheEntry || currentEntry == null) {
      // if the failed entry has not got replaced by another retry, or the
      // failed entry got invalidated, we add a new cache entry
      return new CacheQueryResult(refreshEntry(newEntry), false);
    } else {
      return new CacheQueryResult(currentEntry, true);
    }
  }
}
 
Example #27
Source File: MiniRaftCluster.java    From ratis with Apache License 2.0 5 votes vote down vote up
public RaftClient createClient(RaftPeerId leaderId, RaftGroup group,
    ClientId clientId, RetryPolicy retryPolicy) {
  RaftClient.Builder builder = RaftClient.newBuilder()
      .setClientId(clientId)
      .setRaftGroup(group)
      .setLeaderId(leaderId)
      .setProperties(properties)
      .setParameters(parameters)
      .setRetryPolicy(retryPolicy);
  return builder.build();
}
 
Example #28
Source File: RetryCacheTestUtil.java    From ratis with Apache License 2.0 5 votes vote down vote up
public static void createEntry(RetryCache cache, LogEntryProto logEntry){
  if(logEntry.hasStateMachineLogEntry()) {
    final StateMachineLogEntryProto smLogEntry = logEntry.getStateMachineLogEntry();
    final ClientId clientId = ClientId.valueOf(smLogEntry.getClientId());
    final long callId = smLogEntry.getCallId();
    cache.getOrCreateEntry(clientId, callId);
  }
}
 
Example #29
Source File: RetryCacheTestUtil.java    From ratis with Apache License 2.0 5 votes vote down vote up
public static void assertFailure(RetryCache cache, LogEntryProto logEntry, boolean isFailed) {
  if(logEntry.hasStateMachineLogEntry()) {
    final StateMachineLogEntryProto smLogEntry = logEntry.getStateMachineLogEntry();
    final ClientId clientId = ClientId.valueOf(smLogEntry.getClientId());
    final long callId = smLogEntry.getCallId();
    Assert.assertEquals(isFailed, cache.get(clientId, callId).isFailed());
  }
}
 
Example #30
Source File: TestCreatePipelineCommandHandler.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
private RaftClient.Builder mockRaftClientBuilder() {
  final RaftClient.Builder builder = Mockito.mock(RaftClient.Builder.class);
  Mockito.when(builder.setClientId(Mockito.any(ClientId.class)))
      .thenReturn(builder);
  Mockito.when(builder.setRaftGroup(Mockito.any(RaftGroup.class)))
      .thenReturn(builder);
  Mockito.when(builder.setLeaderId(Mockito.any(RaftPeerId.class)))
      .thenReturn(builder);
  Mockito.when(builder.setProperties(Mockito.any(RaftProperties.class)))
      .thenReturn(builder);
  Mockito.when(builder.setRetryPolicy(Mockito.any(RetryPolicy.class)))
      .thenReturn(builder);
  return builder;
}