use of org.apache.ignite.raft.jraft.rpc.CliRequests.ResetLearnersRequest in project ignite-3 by apache.
the class CliServiceImpl method resetLearners.
@Override
public Status resetLearners(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);
}
ResetLearnersRequest req = cliOptions.getRaftMessagesFactory().resetLearnersRequest().groupId(groupId).leaderId(leaderId.toString()).learnersList(learners.stream().map(Object::toString).collect(toList())).build();
try {
final Message result = this.cliClientService.resetLearners(leaderId.getEndpoint(), req, null).get();
return processLearnersOpResponse(groupId, result, "resetting learners: %s", learners);
} catch (final Exception e) {
return new Status(-1, e.getMessage());
}
}
use of org.apache.ignite.raft.jraft.rpc.CliRequests.ResetLearnersRequest in project ignite-3 by apache.
the class RaftGroupServiceImpl method resetLearners.
/**
* {@inheritDoc}
*/
@Override
public CompletableFuture<Void> resetLearners(List<Peer> learners) {
Peer leader = this.leader;
if (leader == null)
return refreshLeader().thenCompose(res -> resetLearners(learners));
List<String> lrns = learners.stream().map(p -> PeerId.fromPeer(p).toString()).collect(Collectors.toList());
ResetLearnersRequest req = factory.resetLearnersRequest().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;
});
}
Aggregations