Search in sources :

Example 1 with ConsensusView

use of com.jd.blockchain.consensus.manage.ConsensusView 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 ConsensusView

use of com.jd.blockchain.consensus.manage.ConsensusView 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)

Example 3 with ConsensusView

use of com.jd.blockchain.consensus.manage.ConsensusView in project jdchain-core by blockchain-jd-com.

the class BftsmartConsensusManageService method addNode.

@Override
public AsyncFuture<ConsensusView> addNode(Replica replica) {
    BftsmartServiceProxyPool serviceProxyPool = getServiceProxyPool();
    BftsmartReplica bftsmartReplica = (BftsmartReplica) replica;
    CompletableAsyncFuture<ConsensusView> asyncFuture = new CompletableAsyncFuture<>();
    AsynchServiceProxy serviceProxy = null;
    try {
        serviceProxy = serviceProxyPool.borrowObject();
        Reconfiguration reconfiguration = new Reconfiguration(serviceProxy.getProcessId(), serviceProxy);
        reconfiguration.addServer(bftsmartReplica.getId(), bftsmartReplica.getNetworkAddress());
        ReconfigureReply reply = reconfiguration.execute();
        asyncFuture.complete(new BftsmartView(reply.getView()));
    } catch (Exception e) {
        asyncFuture.error(e);
    } finally {
        if (serviceProxy != null) {
            serviceProxyPool.returnObject(serviceProxy);
        }
    }
    return asyncFuture;
}
Also used : ReconfigureReply(bftsmart.reconfiguration.ReconfigureReply) BftsmartServiceProxyPool(com.jd.blockchain.consensus.bftsmart.client.BftsmartServiceProxyPool) BftsmartReplica(com.jd.blockchain.consensus.bftsmart.BftsmartReplica) CompletableAsyncFuture(utils.concurrent.CompletableAsyncFuture) ConsensusView(com.jd.blockchain.consensus.manage.ConsensusView) AsynchServiceProxy(bftsmart.tom.AsynchServiceProxy) Reconfiguration(bftsmart.reconfiguration.Reconfiguration)

Example 4 with ConsensusView

use of com.jd.blockchain.consensus.manage.ConsensusView in project jdchain-core by blockchain-jd-com.

the class BftsmartConsensusManageService method removeNode.

@Override
public AsyncFuture<ConsensusView> removeNode(Replica replica) {
    BftsmartServiceProxyPool serviceProxyPool = getServiceProxyPool();
    CompletableAsyncFuture<ConsensusView> asyncFuture = new CompletableAsyncFuture<>();
    AsynchServiceProxy serviceProxy = null;
    try {
        serviceProxy = serviceProxyPool.borrowObject();
        Reconfiguration reconfiguration = new Reconfiguration(serviceProxy.getProcessId(), serviceProxy);
        reconfiguration.removeServer(replica.getId());
        ReconfigureReply reply = reconfiguration.execute();
        asyncFuture.complete(new BftsmartView(reply.getView()));
    } catch (Exception e) {
        asyncFuture.error(e);
    } finally {
        if (serviceProxy != null) {
            serviceProxyPool.returnObject(serviceProxy);
        }
    }
    return asyncFuture;
}
Also used : ReconfigureReply(bftsmart.reconfiguration.ReconfigureReply) BftsmartServiceProxyPool(com.jd.blockchain.consensus.bftsmart.client.BftsmartServiceProxyPool) CompletableAsyncFuture(utils.concurrent.CompletableAsyncFuture) ConsensusView(com.jd.blockchain.consensus.manage.ConsensusView) AsynchServiceProxy(bftsmart.tom.AsynchServiceProxy) Reconfiguration(bftsmart.reconfiguration.Reconfiguration)

Aggregations

ConsensusView (com.jd.blockchain.consensus.manage.ConsensusView)4 CompletableAsyncFuture (utils.concurrent.CompletableAsyncFuture)4 Reconfiguration (bftsmart.reconfiguration.Reconfiguration)2 ReconfigureReply (bftsmart.reconfiguration.ReconfigureReply)2 AsynchServiceProxy (bftsmart.tom.AsynchServiceProxy)2 Status (com.alipay.sofa.jraft.Status)2 CliRequests (com.alipay.sofa.jraft.rpc.CliRequests)2 BftsmartServiceProxyPool (com.jd.blockchain.consensus.bftsmart.client.BftsmartServiceProxyPool)2 RaftReplica (com.jd.blockchain.consensus.raft.config.RaftReplica)2 RaftConsensusView (com.jd.blockchain.consensus.raft.manager.RaftConsensusView)2 BftsmartReplica (com.jd.blockchain.consensus.bftsmart.BftsmartReplica)1