Search in sources :

Example 6 with ClientProtoUtils

use of org.apache.ratis.client.impl.ClientProtoUtils in project incubator-ratis by apache.

the class GrpcClientRpc method sendRequest.

private CompletableFuture<RaftClientReply> sendRequest(RaftClientRequest request, RaftClientProtocolClient proxy) throws IOException {
    final RaftClientRequestProto requestProto = toRaftClientRequestProto(request);
    final CompletableFuture<RaftClientReplyProto> replyFuture = new CompletableFuture<>();
    // create a new grpc stream for each non-async call.
    final StreamObserver<RaftClientRequestProto> requestObserver = proxy.appendWithTimeout(new StreamObserver<RaftClientReplyProto>() {

        @Override
        public void onNext(RaftClientReplyProto value) {
            replyFuture.complete(value);
        }

        @Override
        public void onError(Throwable t) {
            replyFuture.completeExceptionally(RaftGrpcUtil.unwrapIOException(t));
        }

        @Override
        public void onCompleted() {
            if (!replyFuture.isDone()) {
                replyFuture.completeExceptionally(new IOException(clientId + ": Stream completed but no reply for request " + request));
            }
        }
    });
    requestObserver.onNext(requestProto);
    requestObserver.onCompleted();
    return replyFuture.thenApply(ClientProtoUtils::toRaftClientReply);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RaftClientRequestProto(org.apache.ratis.shaded.proto.RaftProtos.RaftClientRequestProto) ClientProtoUtils(org.apache.ratis.client.impl.ClientProtoUtils) RaftClientReplyProto(org.apache.ratis.shaded.proto.RaftProtos.RaftClientReplyProto) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException)

Example 7 with ClientProtoUtils

use of org.apache.ratis.client.impl.ClientProtoUtils in project incubator-ratis by apache.

the class AdminProtocolService method reinitialize.

@Override
public void reinitialize(ReinitializeRequestProto proto, StreamObserver<RaftClientReplyProto> responseObserver) {
    final ReinitializeRequest request = ClientProtoUtils.toReinitializeRequest(proto);
    RaftGrpcUtil.asyncCall(responseObserver, () -> protocol.reinitializeAsync(request), ClientProtoUtils::toRaftClientReplyProto);
}
Also used : ReinitializeRequest(org.apache.ratis.protocol.ReinitializeRequest) ClientProtoUtils(org.apache.ratis.client.impl.ClientProtoUtils)

Example 8 with ClientProtoUtils

use of org.apache.ratis.client.impl.ClientProtoUtils in project incubator-ratis by apache.

the class AdminProtocolService method serverInformation.

@Override
public void serverInformation(ServerInformationRequestProto proto, StreamObserver<ServerInformationReplyProto> responseObserver) {
    final ServerInformationRequest request = ClientProtoUtils.toServerInformationRequest(proto);
    RaftGrpcUtil.asyncCall(responseObserver, () -> protocol.getInfoAsync(request), ClientProtoUtils::toServerInformationReplyProto);
}
Also used : ServerInformationRequest(org.apache.ratis.protocol.ServerInformationRequest) ClientProtoUtils(org.apache.ratis.client.impl.ClientProtoUtils)

Example 9 with ClientProtoUtils

use of org.apache.ratis.client.impl.ClientProtoUtils in project incubator-ratis by apache.

the class GrpcAdminProtocolService method snapshotManagement.

@Override
public void snapshotManagement(SnapshotManagementRequestProto proto, StreamObserver<RaftClientReplyProto> responseObserver) {
    final SnapshotManagementRequest request = ClientProtoUtils.toSnapshotManagementRequest(proto);
    GrpcUtil.asyncCall(responseObserver, () -> protocol.snapshotManagementAsync(request), ClientProtoUtils::toRaftClientReplyProto);
}
Also used : SnapshotManagementRequest(org.apache.ratis.protocol.SnapshotManagementRequest) ClientProtoUtils(org.apache.ratis.client.impl.ClientProtoUtils)

Example 10 with ClientProtoUtils

use of org.apache.ratis.client.impl.ClientProtoUtils in project incubator-ratis by apache.

the class GrpcAdminProtocolService method groupList.

@Override
public void groupList(GroupListRequestProto proto, StreamObserver<GroupListReplyProto> responseObserver) {
    final GroupListRequest request = ClientProtoUtils.toGroupListRequest(proto);
    GrpcUtil.asyncCall(responseObserver, () -> protocol.getGroupListAsync(request), ClientProtoUtils::toGroupListReplyProto);
}
Also used : GroupListRequest(org.apache.ratis.protocol.GroupListRequest) ClientProtoUtils(org.apache.ratis.client.impl.ClientProtoUtils)

Aggregations

ClientProtoUtils (org.apache.ratis.client.impl.ClientProtoUtils)11 CompletableFuture (java.util.concurrent.CompletableFuture)2 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 RaftClientReplyProto (org.apache.ratis.proto.RaftProtos.RaftClientReplyProto)1 RaftClientRequestProto (org.apache.ratis.proto.RaftProtos.RaftClientRequestProto)1 GroupInfoRequest (org.apache.ratis.protocol.GroupInfoRequest)1 GroupListRequest (org.apache.ratis.protocol.GroupListRequest)1 GroupManagementRequest (org.apache.ratis.protocol.GroupManagementRequest)1 LeaderElectionManagementRequest (org.apache.ratis.protocol.LeaderElectionManagementRequest)1 ReinitializeRequest (org.apache.ratis.protocol.ReinitializeRequest)1 ServerInformationRequest (org.apache.ratis.protocol.ServerInformationRequest)1 SetConfigurationRequest (org.apache.ratis.protocol.SetConfigurationRequest)1 SnapshotManagementRequest (org.apache.ratis.protocol.SnapshotManagementRequest)1 TransferLeadershipRequest (org.apache.ratis.protocol.TransferLeadershipRequest)1 AlreadyClosedException (org.apache.ratis.protocol.exceptions.AlreadyClosedException)1 RaftClientReplyProto (org.apache.ratis.shaded.proto.RaftProtos.RaftClientReplyProto)1 RaftClientRequestProto (org.apache.ratis.shaded.proto.RaftProtos.RaftClientRequestProto)1