Search in sources :

Example 1 with RaftReplica

use of com.jd.blockchain.consensus.raft.config.RaftReplica in project jdchain-core by blockchain-jd-com.

the class RaftMessageService method addNode.

@Override
public AsyncFuture<ConsensusView> addNode(Replica replica) {
    ensureConnected();
    CompletableAsyncFuture<ConsensusView> asyncFuture = new CompletableAsyncFuture<>();
    RaftReplica raftReplica = (RaftReplica) replica;
    CliRequests.AddPeerRequest addPeerRequest = CliRequests.AddPeerRequest.newBuilder().setGroupId(this.groupId).setPeerId(raftReplica.getPeerStr()).build();
    clientService.addPeer(leader.getEndpoint(), addPeerRequest, new RpcResponseClosureAdapter<CliRequests.AddPeerResponse>() {

        @Override
        public void run(Status status) {
            CliRequests.AddPeerResponse response = getResponse();
            LoggerUtils.debugIfEnabled(LOGGER, "raft client add node {} result is: {}, response is: {}", replica, status, response);
            if (!status.isOk()) {
                asyncFuture.error(new RuntimeException(status.getErrorMsg()));
                return;
            }
            RaftConsensusView consensusView = new RaftConsensusView();
            consensusView.setOldPeers(covertToRaftNodeInfoArray(response.getOldPeersList()));
            consensusView.setNewPeers(covertToRaftNodeInfoArray(response.getNewPeersList()));
            asyncFuture.complete(consensusView);
        }
    });
    return asyncFuture;
}
Also used : Status(com.alipay.sofa.jraft.Status) RaftConsensusView(com.jd.blockchain.consensus.raft.manager.RaftConsensusView) CliRequests(com.alipay.sofa.jraft.rpc.CliRequests) CompletableAsyncFuture(utils.concurrent.CompletableAsyncFuture) RaftConsensusView(com.jd.blockchain.consensus.raft.manager.RaftConsensusView) ConsensusView(com.jd.blockchain.consensus.manage.ConsensusView) RaftReplica(com.jd.blockchain.consensus.raft.config.RaftReplica)

Example 2 with RaftReplica

use of com.jd.blockchain.consensus.raft.config.RaftReplica in project jdchain-core by blockchain-jd-com.

the class RaftMessageService method removeNode.

@Override
public AsyncFuture<ConsensusView> removeNode(Replica replica) {
    ensureConnected();
    CompletableAsyncFuture<ConsensusView> asyncFuture = new CompletableAsyncFuture<>();
    RaftReplica raftReplica = (RaftReplica) replica;
    CliRequests.RemovePeerRequest removePeerRequest = CliRequests.RemovePeerRequest.newBuilder().setGroupId(this.groupId).setPeerId(raftReplica.getPeerStr()).build();
    clientService.removePeer(leader.getEndpoint(), removePeerRequest, new RpcResponseClosureAdapter<CliRequests.RemovePeerResponse>() {

        @Override
        public void run(Status status) {
            CliRequests.RemovePeerResponse response = getResponse();
            LoggerUtils.debugIfEnabled(LOGGER, "raft client remove node {} result is: {}, response is: {}", replica, status, response);
            if (!status.isOk()) {
                asyncFuture.error(new RuntimeException(status.getErrorMsg()));
                return;
            }
            RaftConsensusView consensusView = new RaftConsensusView();
            consensusView.setOldPeers(covertToRaftNodeInfoArray(response.getOldPeersList()));
            consensusView.setNewPeers(covertToRaftNodeInfoArray(response.getNewPeersList()));
            asyncFuture.complete(consensusView);
        }
    });
    return asyncFuture;
}
Also used : Status(com.alipay.sofa.jraft.Status) RaftConsensusView(com.jd.blockchain.consensus.raft.manager.RaftConsensusView) CliRequests(com.alipay.sofa.jraft.rpc.CliRequests) CompletableAsyncFuture(utils.concurrent.CompletableAsyncFuture) RaftConsensusView(com.jd.blockchain.consensus.raft.manager.RaftConsensusView) ConsensusView(com.jd.blockchain.consensus.manage.ConsensusView) RaftReplica(com.jd.blockchain.consensus.raft.config.RaftReplica)

Aggregations

Status (com.alipay.sofa.jraft.Status)2 CliRequests (com.alipay.sofa.jraft.rpc.CliRequests)2 ConsensusView (com.jd.blockchain.consensus.manage.ConsensusView)2 RaftReplica (com.jd.blockchain.consensus.raft.config.RaftReplica)2 RaftConsensusView (com.jd.blockchain.consensus.raft.manager.RaftConsensusView)2 CompletableAsyncFuture (utils.concurrent.CompletableAsyncFuture)2