syntax = "proto2";

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

package alluxio.grpc.meta;

import "grpc/common.proto";

message ConfigProperties {
  repeated ConfigProperty properties = 1;
}

message GetConfigurationPOptions{
 optional bool rawValue = 1;
 optional bool ignoreClusterConf = 2;
 optional bool ignorePathConf = 3;
}
message GetConfigurationPResponse{
  repeated ConfigProperty clusterConfigs = 1;
  map<string, ConfigProperties> pathConfigs = 2;
  optional string clusterConfigHash = 3;
  optional string pathConfigHash = 4;
}

enum ConfigStatus {
  PASSED = 1;
  WARN = 2;
  FAILED = 3;
}

enum Scope {
  MASTER = 1;
  WORKER = 2;
  CLIENT = 4;
  SERVER = 3;
  ALL = 7;
  NONE = 0;
}

message InconsistentPropertyValues {
  repeated string values = 1;
}

message InconsistentProperty {
  optional string name = 1;
  map<string, InconsistentPropertyValues> values = 2;
}

message InconsistentProperties {
  repeated InconsistentProperty properties = 1;
}

message ConfigCheckReport {
  map<string, InconsistentProperties> errors = 1; // Scope name as key
  map<string, InconsistentProperties> warns = 2; // Scope name as key
  optional ConfigStatus status = 3;
}

message GetConfigReportPOptions {}
message GetConfigReportPResponse {
  optional ConfigCheckReport report = 1;
}

message MasterInfo {
 optional string leaderMasterAddress = 1;
 repeated grpc.NetAddress masterAddresses = 2;
 optional int32 rpcPort = 3;
 optional bool safeMode = 4;
 optional int64 startTimeMs = 5;
 optional int64 upTimeMs = 6;
 optional string version = 7;
 optional int32 webPort = 8;
 repeated grpc.NetAddress workerAddresses = 9;
 repeated string zookeeperAddresses = 10;// Empty means zookeeper is not enabled
}

enum MasterInfoField {
  LEADER_MASTER_ADDRESS = 0;
  MASTER_ADDRESSES = 1;
  RPC_PORT = 2;
  SAFE_MODE = 3;
  START_TIME_MS = 4;
  UP_TIME_MS = 5;
  VERSION = 6;
  WEB_PORT = 7;
  WORKER_ADDRESSES = 8;
  ZOOKEEPER_ADDRESSES = 9;
}

message GetMasterInfoPOptions {
  repeated MasterInfoField filter = 1;
}
message GetMasterInfoPResponse {
  optional MasterInfo masterInfo = 1;
}

message CheckpointPOptions {}
message CheckpointPResponse {
 // The hostname of the master that did the checkpoint
 optional string masterHostname = 1;
}

enum BackupState {
    None = 1;
    Initiating = 2;
    Transitioning = 3;
    Running = 4;
    Completed = 5;
    Failed = 6;
}

message BackupPRequest {
    optional BackupPOptions options = 1;
    optional string targetDirectory = 2;
}
message BackupPOptions {
    optional bool localFileSystem = 1;
    optional bool runAsync = 2;
    optional bool allowLeader = 3;
}
message BackupPStatus {
    optional string backupId = 1;
    optional BackupState backupState = 2;
    optional string backupHost = 3;
    optional string backupUri = 4;
    optional int64 entryCount = 5;
    optional bytes backupError = 6;
}

message BackupStatusPRequest {
    optional string backupId = 1;
}

 /**
  * This interface contains meta master service endpoints for Alluxio clients.
  */
service MetaMasterClientService {
  /**
   * Backs up the Alluxio master to the specified URI
   */
  rpc Backup (BackupPRequest) returns (BackupPStatus);

  /**
   * Returns status of the latest backup.
   */
  rpc GetBackupStatus (BackupStatusPRequest) returns (BackupPStatus);

  /**
   * Returns server-side configuration report.
   */
  rpc GetConfigReport(GetConfigReportPOptions) returns (GetConfigReportPResponse);

  /**
   * Returns information about the master.
   */
  rpc GetMasterInfo(GetMasterInfoPOptions) returns (GetMasterInfoPResponse);

  /**
   * Creates a checkpoint in the primary master journal system.
   */
  rpc Checkpoint(CheckpointPOptions) returns (CheckpointPResponse);
}

message SetPathConfigurationPOptions {}
message SetPathConfigurationPRequest {
  optional string path = 1;
  map<string, string> properties = 2;
  optional SetPathConfigurationPOptions options = 3;
}
message SetPathConfigurationPResponse {}

message RemovePathConfigurationPOptions {}
message RemovePathConfigurationPRequest {
  optional string path = 1;
  repeated string keys = 2;
  optional RemovePathConfigurationPOptions options = 3;
}
message RemovePathConfigurationPResponse {}

message GetConfigHashPOptions {}
message GetConfigHashPResponse {
  optional string clusterConfigHash = 1;
  optional string pathConfigHash = 2;
}

/**
  * This interface contains meta master service endpoints for Alluxio clients
  * to query cluster configuration.
  */
service MetaMasterConfigurationService {
  /**
   * Returns a list of Alluxio runtime configuration information.
   */
  rpc GetConfiguration (GetConfigurationPOptions) returns (GetConfigurationPResponse);

  /**
   * Sets a property for a path.
   */
  rpc SetPathConfiguration (SetPathConfigurationPRequest) returns (SetPathConfigurationPResponse);

  /**
   * Removes properties for a path, if the keys are empty, it means remove all properties.
   */
  rpc RemovePathConfiguration (RemovePathConfigurationPRequest) returns (RemovePathConfigurationPResponse);

  /**
   * Returns the hashes of cluster and path level configurations.
   */
  rpc GetConfigHash (GetConfigHashPOptions) returns (GetConfigHashPResponse);

  rpc UpdateConfiguration(UpdateConfigurationPRequest) returns (UpdateConfigurationPResponse);
}

message GetMasterIdPOptions {}
message GetMasterIdPRequest {
  optional grpc.NetAddress masterAddress = 1;
  optional GetMasterIdPOptions options = 2;
}
message GetMasterIdPResponse {
  optional int64 masterId = 1;
}

enum MetaCommand {
  MetaCommand_Unknown = 0;
  MetaCommand_Nothing = 1;
  MetaCommand_Register = 2; // Ask the standby master to re-register.
}

message RegisterMasterPOptions {
  repeated grpc.ConfigProperty configs = 1;
}
message RegisterMasterPRequest {
  optional int64 masterId = 1;
  optional RegisterMasterPOptions options = 2;
}
message RegisterMasterPResponse {}

message MasterHeartbeatPOptions {}
message MasterHeartbeatPRequest {
  optional int64 masterId = 1;
  optional MasterHeartbeatPOptions options = 2;
}
message MasterHeartbeatPResponse {
  optional MetaCommand command = 1;
}

message UpdateConfigurationPRequest {
  map<string, string> properties = 1;
}

message UpdateConfigurationPResponse {
  map<string, bool> status = 1;
}

/**
  * This interface contains meta master service endpoints for Alluxio standby masters.
  */
service MetaMasterMasterService {

  /**
   * Returns a master id for the given master address.
   */
  rpc GetMasterId(GetMasterIdPRequest) returns (GetMasterIdPResponse);

  /**
   * Registers a master.
   */
  rpc RegisterMaster(RegisterMasterPRequest) returns (RegisterMasterPResponse);

  /**
   * Heartbeats to indicate the master is lost or not.
   */
  rpc MasterHeartbeat(MasterHeartbeatPRequest) returns (MasterHeartbeatPResponse);
}
