Search in sources :

Example 6 with LearnersOpResponse

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;
}
Also used : LearnersOpResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.LearnersOpResponse) ArrayList(java.util.ArrayList) PeerId(org.apache.ignite.raft.jraft.entity.PeerId)

Example 7 with LearnersOpResponse

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;
}
Also used : LearnersOpResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.LearnersOpResponse) ArrayList(java.util.ArrayList) PeerId(org.apache.ignite.raft.jraft.entity.PeerId)

Aggregations

PeerId (org.apache.ignite.raft.jraft.entity.PeerId)7 LearnersOpResponse (org.apache.ignite.raft.jraft.rpc.CliRequests.LearnersOpResponse)7 ArrayList (java.util.ArrayList)6 IOException (java.io.IOException)3 System.currentTimeMillis (java.lang.System.currentTimeMillis)3 Collection (java.util.Collection)3 Collections (java.util.Collections)3 List (java.util.List)3 Objects.requireNonNull (java.util.Objects.requireNonNull)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3 ThreadLocalRandom.current (java.util.concurrent.ThreadLocalRandom.current)3 TimeUnit (java.util.concurrent.TimeUnit)3 TimeoutException (java.util.concurrent.TimeoutException)3 BiConsumer (java.util.function.BiConsumer)3 Collectors (java.util.stream.Collectors)3 S (org.apache.ignite.internal.tostring.S)3 IgniteException (org.apache.ignite.lang.IgniteException)3 IgniteLogger (org.apache.ignite.lang.IgniteLogger)3 ClusterService (org.apache.ignite.network.ClusterService)3