syntax = "proto2";

option java_multiple_files = true;
option java_package = "alluxio.grpc";
option java_outer_classname = "JournalMasterProto";

package alluxio.grpc.journal;

import "grpc/common.proto";

enum QuorumServerState {
    AVAILABLE = 1;
    UNAVAILABLE = 2;
}

enum JournalDomain {
    MASTER = 1;
    JOB_MASTER = 2;
}

message QuorumServerInfo {
    optional NetAddress serverAddress = 1;
    optional QuorumServerState serverState = 2;
    optional bool isLeader = 3;
    optional int32 priority = 4;
}

// GetQuorumInfo API
message GetQuorumInfoPOptions {}
message GetQuorumInfoPRequest {
    optional GetQuorumInfoPOptions options = 1;
}
message GetQuorumInfoPResponse {
    optional JournalDomain domain = 1;
    repeated QuorumServerInfo serverInfo = 2;
}

// RemoveQuorumServer API
message RemoveQuorumServerPOptions {}
message RemoveQuorumServerPRequest {
    optional RemoveQuorumServerPOptions options = 1;
    optional NetAddress serverAddress = 2;
}
message RemoveQuorumServerPResponse {}

// TransferLeadership API
message TransferLeadershipPOptions {}
message TransferLeadershipPRequest {
    optional TransferLeadershipPOptions options = 1;
    optional NetAddress serverAddress = 2;
}
message TransferLeadershipPResponse {
    required string transferId = 1;
}

// ResetPriorities API
message ResetPrioritiesPOptions {}
message ResetPrioritiesPRequest {
    optional ResetPrioritiesPOptions options = 1;
}
message ResetPrioritiesPResponse {}

message TransferLeaderMessage {
    optional string msg = 1;
}
// GetTransferLeaderMessage API
message GetTransferLeaderMessageOptions {}
message GetTransferLeaderMessagePRequest {
    required string transferId = 1;
}
message GetTransferLeaderMessagePResponse{
    required TransferLeaderMessage transMsg = 1;
}

message GetNodeStatePRequest {}

message GetNodeStatePResponse {
    optional NodeState node_state = 1;
}

enum NodeState {
    STANDBY = 0;
    PRIMARY = 1;
}

/**
  * This interface contains journal master service endpoints for Alluxio clients.
  */
service JournalMasterClientService {

    /**
     * Gets list of server states in an embedded journal quorum.
     */
    rpc GetQuorumInfo(GetQuorumInfoPRequest) returns (GetQuorumInfoPResponse);

    /**
     * Removes a server from embedded journal quorum.
     */
    rpc RemoveQuorumServer(RemoveQuorumServerPRequest) returns (RemoveQuorumServerPResponse);

    /**
     * Transfers the leadership from the current leader to another designated leader.
     */
    rpc TransferLeadership(TransferLeadershipPRequest) returns (TransferLeadershipPResponse);

    /**
     * Reset all the RaftPeer priorities.
     */
    rpc ResetPriorities(ResetPrioritiesPRequest) returns (ResetPrioritiesPResponse);

    /**
     * Gets exception message throwing when transfer leader.
     */
    rpc GetTransferLeaderMessage(GetTransferLeaderMessagePRequest) returns (GetTransferLeaderMessagePResponse);

    /**
     * Gets the state of the current node and returns whether it is primary or standby.
     */
     rpc GetNodeState (GetNodeStatePRequest) returns (GetNodeStatePResponse);
}
