use of org.apache.ratis.proto.RaftProtos.GroupListRequestProto in project incubator-ratis by apache.
the class GrpcClientRpc method sendRequest.
@Override
public RaftClientReply sendRequest(RaftClientRequest request) throws IOException {
final RaftPeerId serverId = request.getServerId();
final GrpcClientProtocolClient proxy = getProxies().getProxy(serverId);
if (request instanceof GroupManagementRequest) {
final GroupManagementRequestProto proto = ClientProtoUtils.toGroupManagementRequestProto((GroupManagementRequest) request);
return ClientProtoUtils.toRaftClientReply(proxy.groupAdd(proto));
} else if (request instanceof SetConfigurationRequest) {
final SetConfigurationRequestProto setConf = ClientProtoUtils.toSetConfigurationRequestProto((SetConfigurationRequest) request);
return ClientProtoUtils.toRaftClientReply(proxy.setConfiguration(setConf));
} else if (request instanceof GroupListRequest) {
final GroupListRequestProto proto = ClientProtoUtils.toGroupListRequestProto((GroupListRequest) request);
return ClientProtoUtils.toGroupListReply(proxy.groupList(proto));
} else if (request instanceof GroupInfoRequest) {
final GroupInfoRequestProto proto = ClientProtoUtils.toGroupInfoRequestProto((GroupInfoRequest) request);
return ClientProtoUtils.toGroupInfoReply(proxy.groupInfo(proto));
} else if (request instanceof TransferLeadershipRequest) {
final TransferLeadershipRequestProto proto = ClientProtoUtils.toTransferLeadershipRequestProto((TransferLeadershipRequest) request);
return ClientProtoUtils.toRaftClientReply(proxy.transferLeadership(proto));
} else if (request instanceof SnapshotManagementRequest) {
final SnapshotManagementRequestProto proto = ClientProtoUtils.toSnapshotManagementRequestProto((SnapshotManagementRequest) request);
return ClientProtoUtils.toRaftClientReply(proxy.snapshotManagement(proto));
} else if (request instanceof LeaderElectionManagementRequest) {
final LeaderElectionManagementRequestProto proto = ClientProtoUtils.toLeaderElectionManagementRequestProto((LeaderElectionManagementRequest) request);
return ClientProtoUtils.toRaftClientReply(proxy.leaderElectionManagement(proto));
} else {
final CompletableFuture<RaftClientReply> f = sendRequest(request, proxy);
// TODO: timeout support
try {
return f.get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new InterruptedIOException("Interrupted while waiting for response of request " + request);
} catch (ExecutionException e) {
if (LOG.isTraceEnabled()) {
LOG.trace(clientId + ": failed " + request, e);
}
throw IOUtils.toIOException(e);
}
}
}
Aggregations