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;
}
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;
}
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;
}
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;
}
Aggregations