use of com.jd.blockchain.consensus.raft.manager.RaftConsensusView 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;
}
use of com.jd.blockchain.consensus.raft.manager.RaftConsensusView 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;
}
Aggregations