Search in sources :

Example 1 with SetConfigurationRequestProto

use of org.apache.ratis.proto.RaftProtos.SetConfigurationRequestProto in project incubator-ratis by apache.

the class NettyClientRpc method sendRequest.

@Override
public RaftClientReply sendRequest(RaftClientRequest request) throws IOException {
    final RaftPeerId serverId = request.getServerId();
    final NettyRpcProxy proxy = getProxies().getProxy(serverId);
    final RaftNettyServerRequestProto.Builder b = RaftNettyServerRequestProto.newBuilder();
    final RaftRpcRequestProto rpcRequest;
    if (request instanceof GroupManagementRequest) {
        final GroupManagementRequestProto proto = ClientProtoUtils.toGroupManagementRequestProto((GroupManagementRequest) request);
        b.setGroupManagementRequest(proto);
        rpcRequest = proto.getRpcRequest();
    } else if (request instanceof SetConfigurationRequest) {
        final SetConfigurationRequestProto proto = ClientProtoUtils.toSetConfigurationRequestProto((SetConfigurationRequest) request);
        b.setSetConfigurationRequest(proto);
        rpcRequest = proto.getRpcRequest();
    } else if (request instanceof GroupListRequest) {
        final RaftProtos.GroupListRequestProto proto = ClientProtoUtils.toGroupListRequestProto((GroupListRequest) request);
        b.setGroupListRequest(proto);
        rpcRequest = proto.getRpcRequest();
    } else if (request instanceof GroupInfoRequest) {
        final RaftProtos.GroupInfoRequestProto proto = ClientProtoUtils.toGroupInfoRequestProto((GroupInfoRequest) request);
        b.setGroupInfoRequest(proto);
        rpcRequest = proto.getRpcRequest();
    } else if (request instanceof TransferLeadershipRequest) {
        final RaftProtos.TransferLeadershipRequestProto proto = ClientProtoUtils.toTransferLeadershipRequestProto((TransferLeadershipRequest) request);
        b.setTransferLeadershipRequest(proto);
        rpcRequest = proto.getRpcRequest();
    } else if (request instanceof SnapshotManagementRequest) {
        final RaftProtos.SnapshotManagementRequestProto proto = ClientProtoUtils.toSnapshotManagementRequestProto((SnapshotManagementRequest) request);
        b.setSnapshotManagementRequest(proto);
        rpcRequest = proto.getRpcRequest();
    } else if (request instanceof LeaderElectionManagementRequest) {
        final RaftProtos.LeaderElectionManagementRequestProto proto = ClientProtoUtils.toLeaderElectionManagementRequestProto((LeaderElectionManagementRequest) request);
        b.setLeaderElectionManagementRequest(proto);
        rpcRequest = proto.getRpcRequest();
    } else {
        final RaftClientRequestProto proto = ClientProtoUtils.toRaftClientRequestProto(request);
        b.setRaftClientRequest(proto);
        rpcRequest = proto.getRpcRequest();
    }
    if (request instanceof GroupListRequest) {
        return ClientProtoUtils.toGroupListReply(proxy.send(rpcRequest, b.build()).getGroupListReply());
    } else if (request instanceof GroupInfoRequest) {
        return ClientProtoUtils.toGroupInfoReply(proxy.send(rpcRequest, b.build()).getGroupInfoReply());
    } else {
        return ClientProtoUtils.toRaftClientReply(proxy.send(rpcRequest, b.build()).getRaftClientReply());
    }
}
Also used : NettyRpcProxy(org.apache.ratis.netty.NettyRpcProxy) RaftRpcRequestProto(org.apache.ratis.proto.RaftProtos.RaftRpcRequestProto) GroupManagementRequestProto(org.apache.ratis.proto.RaftProtos.GroupManagementRequestProto) SetConfigurationRequestProto(org.apache.ratis.proto.RaftProtos.SetConfigurationRequestProto) RaftClientRequestProto(org.apache.ratis.proto.RaftProtos.RaftClientRequestProto) RaftProtos(org.apache.ratis.proto.RaftProtos) RaftNettyServerRequestProto(org.apache.ratis.proto.netty.NettyProtos.RaftNettyServerRequestProto)

Example 2 with SetConfigurationRequestProto

use of org.apache.ratis.proto.RaftProtos.SetConfigurationRequestProto 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);
        }
    }
}
Also used : InterruptedIOException(java.io.InterruptedIOException) GroupManagementRequestProto(org.apache.ratis.proto.RaftProtos.GroupManagementRequestProto) LeaderElectionManagementRequestProto(org.apache.ratis.proto.RaftProtos.LeaderElectionManagementRequestProto) GroupInfoRequestProto(org.apache.ratis.proto.RaftProtos.GroupInfoRequestProto) SetConfigurationRequestProto(org.apache.ratis.proto.RaftProtos.SetConfigurationRequestProto) TransferLeadershipRequestProto(org.apache.ratis.proto.RaftProtos.TransferLeadershipRequestProto) GroupListRequestProto(org.apache.ratis.proto.RaftProtos.GroupListRequestProto) SnapshotManagementRequestProto(org.apache.ratis.proto.RaftProtos.SnapshotManagementRequestProto) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

GroupManagementRequestProto (org.apache.ratis.proto.RaftProtos.GroupManagementRequestProto)2 SetConfigurationRequestProto (org.apache.ratis.proto.RaftProtos.SetConfigurationRequestProto)2 InterruptedIOException (java.io.InterruptedIOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 NettyRpcProxy (org.apache.ratis.netty.NettyRpcProxy)1 RaftProtos (org.apache.ratis.proto.RaftProtos)1 GroupInfoRequestProto (org.apache.ratis.proto.RaftProtos.GroupInfoRequestProto)1 GroupListRequestProto (org.apache.ratis.proto.RaftProtos.GroupListRequestProto)1 LeaderElectionManagementRequestProto (org.apache.ratis.proto.RaftProtos.LeaderElectionManagementRequestProto)1 RaftClientRequestProto (org.apache.ratis.proto.RaftProtos.RaftClientRequestProto)1 RaftRpcRequestProto (org.apache.ratis.proto.RaftProtos.RaftRpcRequestProto)1 SnapshotManagementRequestProto (org.apache.ratis.proto.RaftProtos.SnapshotManagementRequestProto)1 TransferLeadershipRequestProto (org.apache.ratis.proto.RaftProtos.TransferLeadershipRequestProto)1 RaftNettyServerRequestProto (org.apache.ratis.proto.netty.NettyProtos.RaftNettyServerRequestProto)1