use of org.apache.ignite.raft.jraft.rpc.CliRequests.RemovePeerResponse 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.RemovePeerResponse 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;
});
}
use of org.apache.ignite.raft.jraft.rpc.CliRequests.RemovePeerResponse in project ignite-3 by apache.
the class RemovePeerRequestProcessor method processRequest0.
@Override
protected Message processRequest0(final CliRequestContext ctx, final RemovePeerRequest request, final IgniteCliRpcRequestClosure done) {
final List<PeerId> oldPeers = ctx.node.listPeers();
final String removingPeerIdStr = request.peerId();
final PeerId removingPeer = new PeerId();
if (removingPeer.parse(removingPeerIdStr)) {
LOG.info("Receive RemovePeerRequest to {} from {}, removing {}", ctx.node.getNodeId(), done.getRpcCtx().getRemoteAddress(), removingPeerIdStr);
ctx.node.removePeer(removingPeer, status -> {
if (!status.isOk()) {
done.run(status);
} else {
List<String> oldPeersList = new ArrayList<>();
List<String> newPeersList = new ArrayList<>();
for (final PeerId oldPeer : oldPeers) {
oldPeersList.add(oldPeer.toString());
if (!oldPeer.equals(removingPeer)) {
newPeersList.add(oldPeer.toString());
}
}
RemovePeerResponse rb = msgFactory().removePeerResponse().newPeersList(newPeersList).oldPeersList(oldPeersList).build();
done.sendResponse(rb);
}
});
} else {
return //
RaftRpcFactory.DEFAULT.newResponse(msgFactory(), RaftError.EINVAL, "Fail to parse peer id %s", removingPeerIdStr);
}
return null;
}
Aggregations