use of org.apache.ratis.protocol.GroupInfoReply in project incubator-ratis by apache.
the class GroupManagementImpl method info.
@Override
public GroupInfoReply info(RaftGroupId groupId) throws IOException {
final RaftGroupId gid = groupId != null ? groupId : client.getGroupId();
final long callId = CallId.getAndIncrement();
final RaftClientReply reply = client.io().sendRequestWithRetry(() -> new GroupInfoRequest(client.getId(), server, gid, callId));
Preconditions.assertTrue(reply instanceof GroupInfoReply, () -> "Unexpected reply: " + reply);
return (GroupInfoReply) reply;
}
use of org.apache.ratis.protocol.GroupInfoReply in project incubator-ratis by apache.
the class GroupInfoCommand method run.
@Override
public int run(CommandLine cl) throws IOException {
super.run(cl);
println("group id: " + getRaftGroup().getGroupId().getUuid());
final GroupInfoReply reply = getGroupInfoReply();
RaftProtos.RaftPeerProto leader = getLeader(reply.getRoleInfoProto());
if (leader == null) {
println("leader not found");
} else {
printf("leader info: %s(%s)%n%n", leader.getId().toStringUtf8(), leader.getAddress());
}
println(reply.getCommitInfos());
return 0;
}
use of org.apache.ratis.protocol.GroupInfoReply in project incubator-ratis by apache.
the class NettyRpcService method handle.
RaftNettyServerReplyProto handle(RaftNettyServerRequestProto proto) {
RaftRpcRequestProto rpcRequest = null;
try {
switch(proto.getRaftNettyServerRequestCase()) {
case REQUESTVOTEREQUEST:
final RequestVoteRequestProto request = proto.getRequestVoteRequest();
rpcRequest = request.getServerRequest();
final RequestVoteReplyProto reply = server.requestVote(request);
return RaftNettyServerReplyProto.newBuilder().setRequestVoteReply(reply).build();
case TRANSFERLEADERSHIPREQUEST:
final TransferLeadershipRequestProto transferLeadershipRequest = proto.getTransferLeadershipRequest();
rpcRequest = transferLeadershipRequest.getRpcRequest();
final RaftClientReply transferLeadershipReply = server.transferLeadership(ClientProtoUtils.toTransferLeadershipRequest(transferLeadershipRequest));
return RaftNettyServerReplyProto.newBuilder().setRaftClientReply(ClientProtoUtils.toRaftClientReplyProto(transferLeadershipReply)).build();
case STARTLEADERELECTIONREQUEST:
final StartLeaderElectionRequestProto startLeaderElectionRequest = proto.getStartLeaderElectionRequest();
rpcRequest = startLeaderElectionRequest.getServerRequest();
final StartLeaderElectionReplyProto startLeaderElectionReply = server.startLeaderElection(startLeaderElectionRequest);
return RaftNettyServerReplyProto.newBuilder().setStartLeaderElectionReply(startLeaderElectionReply).build();
case SNAPSHOTMANAGEMENTREQUEST:
final SnapshotManagementRequestProto snapshotManagementRequest = proto.getSnapshotManagementRequest();
rpcRequest = snapshotManagementRequest.getRpcRequest();
final RaftClientReply snapshotManagementReply = server.snapshotManagement(ClientProtoUtils.toSnapshotManagementRequest(snapshotManagementRequest));
return RaftNettyServerReplyProto.newBuilder().setRaftClientReply(ClientProtoUtils.toRaftClientReplyProto(snapshotManagementReply)).build();
case LEADERELECTIONMANAGEMENTREQUEST:
final LeaderElectionManagementRequestProto leaderElectionManagementRequest = proto.getLeaderElectionManagementRequest();
rpcRequest = leaderElectionManagementRequest.getRpcRequest();
final RaftClientReply leaderElectionManagementReply = server.leaderElectionManagement(ClientProtoUtils.toLeaderElectionManagementRequest(leaderElectionManagementRequest));
return RaftNettyServerReplyProto.newBuilder().setRaftClientReply(ClientProtoUtils.toRaftClientReplyProto(leaderElectionManagementReply)).build();
case APPENDENTRIESREQUEST:
final AppendEntriesRequestProto appendEntriesRequest = proto.getAppendEntriesRequest();
rpcRequest = appendEntriesRequest.getServerRequest();
final AppendEntriesReplyProto appendEntriesReply = server.appendEntries(appendEntriesRequest);
return RaftNettyServerReplyProto.newBuilder().setAppendEntriesReply(appendEntriesReply).build();
case INSTALLSNAPSHOTREQUEST:
final InstallSnapshotRequestProto installSnapshotRequest = proto.getInstallSnapshotRequest();
rpcRequest = installSnapshotRequest.getServerRequest();
final InstallSnapshotReplyProto installSnapshotReply = server.installSnapshot(installSnapshotRequest);
return RaftNettyServerReplyProto.newBuilder().setInstallSnapshotReply(installSnapshotReply).build();
case RAFTCLIENTREQUEST:
final RaftClientRequestProto raftClientRequest = proto.getRaftClientRequest();
rpcRequest = raftClientRequest.getRpcRequest();
final RaftClientReply raftClientReply = server.submitClientRequest(ClientProtoUtils.toRaftClientRequest(raftClientRequest));
return RaftNettyServerReplyProto.newBuilder().setRaftClientReply(ClientProtoUtils.toRaftClientReplyProto(raftClientReply)).build();
case SETCONFIGURATIONREQUEST:
final SetConfigurationRequestProto configurationRequest = proto.getSetConfigurationRequest();
rpcRequest = configurationRequest.getRpcRequest();
final RaftClientReply configurationReply = server.setConfiguration(ClientProtoUtils.toSetConfigurationRequest(configurationRequest));
return RaftNettyServerReplyProto.newBuilder().setRaftClientReply(ClientProtoUtils.toRaftClientReplyProto(configurationReply)).build();
case GROUPMANAGEMENTREQUEST:
final GroupManagementRequestProto groupManagementRequest = proto.getGroupManagementRequest();
rpcRequest = groupManagementRequest.getRpcRequest();
final RaftClientReply groupManagementReply = server.groupManagement(ClientProtoUtils.toGroupManagementRequest(groupManagementRequest));
return RaftNettyServerReplyProto.newBuilder().setRaftClientReply(ClientProtoUtils.toRaftClientReplyProto(groupManagementReply)).build();
case GROUPLISTREQUEST:
final GroupListRequestProto groupListRequest = proto.getGroupListRequest();
rpcRequest = groupListRequest.getRpcRequest();
final GroupListReply groupListReply = server.getGroupList(ClientProtoUtils.toGroupListRequest(groupListRequest));
return RaftNettyServerReplyProto.newBuilder().setGroupListReply(ClientProtoUtils.toGroupListReplyProto(groupListReply)).build();
case GROUPINFOREQUEST:
final GroupInfoRequestProto groupInfoRequest = proto.getGroupInfoRequest();
rpcRequest = groupInfoRequest.getRpcRequest();
final GroupInfoReply groupInfoReply = server.getGroupInfo(ClientProtoUtils.toGroupInfoRequest(groupInfoRequest));
return RaftNettyServerReplyProto.newBuilder().setGroupInfoReply(ClientProtoUtils.toGroupInfoReplyProto(groupInfoReply)).build();
case RAFTNETTYSERVERREQUEST_NOT_SET:
throw new IllegalArgumentException("Request case not set in proto: " + proto.getRaftNettyServerRequestCase());
default:
throw new UnsupportedOperationException("Request case not supported: " + proto.getRaftNettyServerRequestCase());
}
} catch (IOException ioe) {
return toRaftNettyServerReplyProto(Objects.requireNonNull(rpcRequest, "rpcRequest = null"), ioe);
}
}
use of org.apache.ratis.protocol.GroupInfoReply in project alluxio by Alluxio.
the class RaftJournalSystem method getQuorumServerInfoList.
/**
* Used to get information of internal RAFT quorum.
*
* @return list of information for participating servers in RAFT quorum
*/
public synchronized List<QuorumServerInfo> getQuorumServerInfoList() throws IOException {
List<QuorumServerInfo> quorumMemberStateList = new LinkedList<>();
GroupInfoReply groupInfo = getGroupInfo();
if (groupInfo == null) {
throw new UnavailableException("Cannot get raft group info");
}
if (groupInfo.getException() != null) {
throw groupInfo.getException();
}
RaftProtos.RoleInfoProto roleInfo = groupInfo.getRoleInfoProto();
if (roleInfo == null) {
throw new UnavailableException("Cannot get server role info");
}
RaftProtos.LeaderInfoProto leaderInfo = roleInfo.getLeaderInfo();
if (leaderInfo == null) {
throw new UnavailableException("Cannot get server leader info");
}
for (RaftProtos.ServerRpcProto member : leaderInfo.getFollowerInfoList()) {
HostAndPort hp = HostAndPort.fromString(member.getId().getAddress());
NetAddress memberAddress = NetAddress.newBuilder().setHost(hp.getHost()).setRpcPort(hp.getPort()).build();
quorumMemberStateList.add(QuorumServerInfo.newBuilder().setIsLeader(false).setPriority(member.getId().getPriority()).setServerAddress(memberAddress).setServerState(member.getLastRpcElapsedTimeMs() > mConf.getMaxElectionTimeoutMs() ? QuorumServerState.UNAVAILABLE : QuorumServerState.AVAILABLE).build());
}
InetSocketAddress localAddress = mConf.getLocalAddress();
NetAddress self = NetAddress.newBuilder().setHost(localAddress.getHostString()).setRpcPort(localAddress.getPort()).build();
quorumMemberStateList.add(QuorumServerInfo.newBuilder().setIsLeader(true).setPriority(roleInfo.getSelf().getPriority()).setServerAddress(self).setServerState(QuorumServerState.AVAILABLE).build());
quorumMemberStateList.sort(Comparator.comparing(info -> info.getServerAddress().toString()));
return quorumMemberStateList;
}
Aggregations