use of org.apache.ignite.raft.jraft.rpc.CliRequests.AddLearnersRequest in project ignite-3 by apache.
the class RaftGroupServiceImpl method addLearners.
/**
* {@inheritDoc}
*/
@Override
public CompletableFuture<Void> addLearners(List<Peer> learners) {
Peer leader = this.leader;
if (leader == null)
return refreshLeader().thenCompose(res -> addLearners(learners));
List<String> lrns = learners.stream().map(p -> PeerId.fromPeer(p).toString()).collect(Collectors.toList());
AddLearnersRequest req = factory.addLearnersRequest().groupId(groupId).learnersList(lrns).build();
CompletableFuture<LearnersOpResponse> fut = new CompletableFuture<>();
sendWithRetry(leader, req, currentTimeMillis() + timeout, fut);
return fut.thenApply(resp -> {
this.learners = parsePeerList(resp.newLearnersList());
return null;
});
}
use of org.apache.ignite.raft.jraft.rpc.CliRequests.AddLearnersRequest in project ignite-3 by apache.
the class CliServiceImpl method addLearners.
@Override
public Status addLearners(final String groupId, final Configuration conf, final List<PeerId> learners) {
checkLearnersOpParams(groupId, conf, learners);
final PeerId leaderId = new PeerId();
final Status st = getLeader(groupId, conf, leaderId);
if (!st.isOk()) {
return st;
}
if (!this.cliClientService.connect(leaderId.getEndpoint())) {
return new Status(-1, "Fail to init channel to leader %s", leaderId);
}
AddLearnersRequest rb = cliOptions.getRaftMessagesFactory().addLearnersRequest().groupId(groupId).leaderId(leaderId.toString()).learnersList(learners.stream().map(Object::toString).collect(toList())).build();
try {
final Message result = this.cliClientService.addLearners(leaderId.getEndpoint(), rb, null).get();
return processLearnersOpResponse(groupId, result, "adding learners: %s", learners);
} catch (final Exception e) {
return new Status(-1, e.getMessage());
}
}
Aggregations