use of org.apache.ignite.raft.jraft.rpc.CliRequests.LearnersOpResponse in project ignite-3 by apache.
the class RemoveLearnersRequestProcessor method processRequest0.
@Override
protected Message processRequest0(final CliRequestContext ctx, final RemoveLearnersRequest request, final IgniteCliRpcRequestClosure done) {
final List<PeerId> oldLearners = ctx.node.listLearners();
final List<PeerId> removeingLearners = new ArrayList<>(request.learnersList().size());
for (final String peerStr : request.learnersList()) {
final PeerId peer = new PeerId();
if (!peer.parse(peerStr)) {
return //
RaftRpcFactory.DEFAULT.newResponse(msgFactory(), RaftError.EINVAL, "Fail to parse peer id %s", peerStr);
}
removeingLearners.add(peer);
}
LOG.info("Receive RemoveLearnersRequest to {} from {}, removing {}.", ctx.node.getNodeId(), done.getRpcCtx().getRemoteAddress(), removeingLearners);
ctx.node.removeLearners(removeingLearners, status -> {
if (!status.isOk()) {
done.run(status);
} else {
List<String> oldLearnersList = new ArrayList<>();
List<String> newLearnersList = new ArrayList<>();
for (final PeerId peer : oldLearners) {
oldLearnersList.add(peer.toString());
if (!removeingLearners.contains(peer)) {
newLearnersList.add(peer.toString());
}
}
LearnersOpResponse response = msgFactory().learnersOpResponse().oldLearnersList(oldLearnersList).newLearnersList(newLearnersList).build();
done.sendResponse(response);
}
});
return null;
}
use of org.apache.ignite.raft.jraft.rpc.CliRequests.LearnersOpResponse in project ignite-3 by apache.
the class ResetLearnersRequestProcessor method processRequest0.
@Override
protected Message processRequest0(final CliRequestContext ctx, final ResetLearnersRequest request, final IgniteCliRpcRequestClosure done) {
final List<PeerId> oldLearners = ctx.node.listLearners();
final List<PeerId> newLearners = new ArrayList<>(request.learnersList().size());
for (final String peerStr : request.learnersList()) {
final PeerId peer = new PeerId();
if (!peer.parse(peerStr)) {
return RaftRpcFactory.DEFAULT.newResponse(msgFactory(), RaftError.EINVAL, "Fail to parse peer id %s", peerStr);
}
newLearners.add(peer);
}
LOG.info("Receive ResetLearnersRequest to {} from {}, resetting into {}.", ctx.node.getNodeId(), done.getRpcCtx().getRemoteAddress(), newLearners);
ctx.node.resetLearners(newLearners, status -> {
if (!status.isOk()) {
done.run(status);
} else {
LearnersOpResponse response = msgFactory().learnersOpResponse().oldLearnersList(oldLearners.stream().map(Object::toString).collect(toList())).newLearnersList(newLearners.stream().map(Object::toString).collect(toList())).build();
done.sendResponse(response);
}
});
return null;
}
Aggregations