Search in sources :

Example 1 with ListPeersRequest

use of com.baidu.hugegraph.backend.store.raft.rpc.RaftRequests.ListPeersRequest in project incubator-hugegraph by apache.

the class RaftGroupManagerImpl method listPeers.

@Override
public List<String> listPeers() {
    if (this.raftNode.selfIsLeader()) {
        List<PeerId> peerIds = this.raftNode.node().listPeers();
        return peerIds.stream().map(PeerId::toString).collect(Collectors.toList());
    }
    // If current node is not leader, forward request to leader
    ListPeersRequest request = ListPeersRequest.getDefaultInstance();
    try {
        RaftClosure<ListPeersResponse> future;
        future = this.forwardToLeader(request);
        ListPeersResponse response = future.waitFinished();
        return response.getEndpointsList();
    } catch (Throwable e) {
        throw new BackendException("Failed to list peers", e);
    }
}
Also used : ListPeersRequest(com.baidu.hugegraph.backend.store.raft.rpc.RaftRequests.ListPeersRequest) ListPeersResponse(com.baidu.hugegraph.backend.store.raft.rpc.RaftRequests.ListPeersResponse) PeerId(com.alipay.sofa.jraft.entity.PeerId) BackendException(com.baidu.hugegraph.backend.BackendException)

Aggregations

PeerId (com.alipay.sofa.jraft.entity.PeerId)1 BackendException (com.baidu.hugegraph.backend.BackendException)1 ListPeersRequest (com.baidu.hugegraph.backend.store.raft.rpc.RaftRequests.ListPeersRequest)1 ListPeersResponse (com.baidu.hugegraph.backend.store.raft.rpc.RaftRequests.ListPeersResponse)1