Search in sources :

Example 1 with RaftRpcRequestProto

use of org.apache.ratis.proto.RaftProtos.RaftRpcRequestProto 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 RaftRpcRequestProto

use of org.apache.ratis.proto.RaftProtos.RaftRpcRequestProto in project ozone by apache.

the class FollowerAppendLogEntryGenerator method createInitialLogEntry.

/**
 * Create initial log entry to initialize the log.
 */
private AppendEntriesRequestProto createInitialLogEntry(long callId) {
    RaftRpcRequestProto serverRequest = createServerRequest(callId);
    long index = 0L;
    LogEntryProto logEntry = LogEntryProto.newBuilder().setTerm(term).setIndex(index).setConfigurationEntry(RaftConfigurationProto.newBuilder().addPeers(RaftPeerProto.newBuilder().setId(RaftPeerId.valueOf(serverAddress).toByteString()).setAddress(serverAddress).build()).addPeers(requestor).build()).build();
    return AppendEntriesRequestProto.newBuilder().setLeaderTerm(term).addEntries(logEntry).setServerRequest(serverRequest).build();
}
Also used : RaftRpcRequestProto(org.apache.ratis.proto.RaftProtos.RaftRpcRequestProto) LogEntryProto(org.apache.ratis.proto.RaftProtos.LogEntryProto) StateMachineLogEntryProto(org.apache.ratis.proto.RaftProtos.StateMachineLogEntryProto)

Aggregations

RaftRpcRequestProto (org.apache.ratis.proto.RaftProtos.RaftRpcRequestProto)2 NettyRpcProxy (org.apache.ratis.netty.NettyRpcProxy)1 RaftProtos (org.apache.ratis.proto.RaftProtos)1 GroupManagementRequestProto (org.apache.ratis.proto.RaftProtos.GroupManagementRequestProto)1 LogEntryProto (org.apache.ratis.proto.RaftProtos.LogEntryProto)1 RaftClientRequestProto (org.apache.ratis.proto.RaftProtos.RaftClientRequestProto)1 SetConfigurationRequestProto (org.apache.ratis.proto.RaftProtos.SetConfigurationRequestProto)1 StateMachineLogEntryProto (org.apache.ratis.proto.RaftProtos.StateMachineLogEntryProto)1 RaftNettyServerRequestProto (org.apache.ratis.proto.netty.NettyProtos.RaftNettyServerRequestProto)1