use of org.apache.ignite.raft.jraft.rpc.CliRequests.ChangePeersRequest in project ignite-3 by apache.
the class CliServiceImpl method changePeers.
// TODO refactor addPeer/removePeer/changePeers/transferLeader, remove duplicated code IGNITE-14832
@Override
public Status changePeers(final String groupId, final Configuration conf, final Configuration newPeers) {
Requires.requireTrue(!StringUtils.isBlank(groupId), "Blank group id");
Requires.requireNonNull(conf, "Null configuration");
Requires.requireNonNull(newPeers, "Null new peers");
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);
}
ChangePeersRequest req = cliOptions.getRaftMessagesFactory().changePeersRequest().groupId(groupId).leaderId(leaderId.toString()).newPeersList(newPeers.getPeers().stream().map(Object::toString).collect(toList())).build();
try {
final Message result = this.cliClientService.changePeers(leaderId.getEndpoint(), req, null).get();
if (result instanceof ChangePeersResponse) {
final ChangePeersResponse resp = (ChangePeersResponse) 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.ChangePeersRequest in project ignite-3 by apache.
the class RaftGroupServiceImpl method changePeers.
/**
* {@inheritDoc}
*/
@Override
public CompletableFuture<Void> changePeers(List<Peer> peers) {
Peer leader = this.leader;
if (leader == null)
return refreshLeader().thenCompose(res -> changePeers(peers));
List<String> peersToChange = peers.stream().map(p -> PeerId.fromPeer(p).toString()).collect(Collectors.toList());
ChangePeersRequest req = factory.changePeersRequest().groupId(groupId).newPeersList(peersToChange).build();
CompletableFuture<ChangePeersResponse> fut = new CompletableFuture<>();
sendWithRetry(leader, req, currentTimeMillis() + timeout, fut);
return fut.thenApply(resp -> {
this.peers = parsePeerList(resp.newPeersList());
return null;
});
}
Aggregations