use of org.apache.ignite.raft.jraft.rpc.CliRequests.RemovePeerRequest in project ignite-3 by apache.
the class CliServiceImpl method removePeer.
@Override
public Status removePeer(final String groupId, final Configuration conf, final PeerId peer) {
Requires.requireTrue(!StringUtils.isBlank(groupId), "Blank group id");
Requires.requireNonNull(conf, "Null configuration");
Requires.requireNonNull(peer, "Null peer");
Requires.requireTrue(!peer.isEmpty(), "Removing peer is blank");
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);
}
RemovePeerRequest req = cliOptions.getRaftMessagesFactory().removePeerRequest().groupId(groupId).leaderId(leaderId.toString()).peerId(peer.toString()).build();
try {
final Message result = this.cliClientService.removePeer(leaderId.getEndpoint(), req, null).get();
if (result instanceof RemovePeerResponse) {
final RemovePeerResponse resp = (RemovePeerResponse) result;
final Configuration oldConf = new Configuration();
for (final String peerIdStr : resp.oldPeersList()) {
final PeerId oldPeer = new PeerId();
oldPeer.parse(peerIdStr);
oldConf.addPeer(oldPeer);
}
final Configuration newConf = new Configuration();
for (final String peerIdStr : resp.newPeersList()) {
final PeerId newPeer = new PeerId();
newPeer.parse(peerIdStr);
newConf.addPeer(newPeer);
}
LOG.info("Configuration of replication group {} changed from {} to {}", groupId, oldConf, newConf);
return Status.OK();
} else {
return statusFromResponse(result);
}
} catch (final Exception e) {
return new Status(-1, e.getMessage());
}
}
use of org.apache.ignite.raft.jraft.rpc.CliRequests.RemovePeerRequest in project ignite-3 by apache.
the class RaftGroupServiceImpl method removePeer.
/**
* {@inheritDoc}
*/
@Override
public CompletableFuture<Void> removePeer(Peer peer) {
Peer leader = this.leader;
if (leader == null)
return refreshLeader().thenCompose(res -> removePeer(peer));
RemovePeerRequest req = factory.removePeerRequest().groupId(groupId).peerId(PeerId.fromPeer(peer).toString()).build();
CompletableFuture<RemovePeerResponse> fut = new CompletableFuture<>();
sendWithRetry(leader, req, currentTimeMillis() + timeout, fut);
return fut.thenApply(resp -> {
this.peers = parsePeerList(resp.newPeersList());
return null;
});
}
Aggregations