syntax = "proto3";

package deeprec;

enum Code {
  OK                  = 0;
  CANCELLED           = 1;
  UNKNOWN             = 2;
  INVALID_ARGUMENT    = 3;
  DEADLINE_EXCEEDED   = 4;
  NOT_FOUND           = 5;
  ALREADY_EXISTS      = 6;
  PERMISSION_DENIED   = 7;
  RESOURCE_EXHAUSTED  = 8;
  FAILED_PRECONDITION = 9;
  ABORTED             = 10;
  OUT_OF_RANGE        = 11;
  UNIMPLEMENTED       = 12;
  INTERNAL            = 13;
  UNAVAILABLE         = 14;
  DATA_LOSS           = 15;
  UNAUTHENTICATED     = 16;
  REQUEST_STOP        = 17;
}

enum ElasticTrainingState {
  READY = 0;
  SCALING = 1;
  All_SESSION_CLOSED = 2;
}

enum ScalingAction {
  NONE = 0;
  SCALING_UP = 1;
  SCALING_DOWN = 2;
}

message IsReadyScalingRequest {
  int32 task_index = 1;
}

message IsReadyScalingResponse {
  Code code = 1;
  string msg = 2;
  ScalingAction scaling_action = 3;
  int32 ps_num = 4; // updated ps_num;
}

message ReadyToUpdateRequest {};
message ReadyToUpdateResponse {};

message UpdateServerDefRequest {
  string cluster_def = 1;//serialized cluster_def
}

message UpdateServerDefResponse {
  Code code = 1;
  string msg = 2;
}

message FetchParamsRequest {
  repeated string names = 1; // vec of partitioned variables or ev
}

message FetchParamsResponse {
  Code code = 1;
  string msg = 2;
  map<string, int32> param_partition_map = 3; // per partition num of variable
}

service ElasticTrainingService {
  rpc IsReadyScaling(IsReadyScalingRequest) returns (IsReadyScalingResponse);
  rpc ReadyToUpdate(ReadyToUpdateRequest) returns (ReadyToUpdateResponse);
  rpc UpdateServerDef(UpdateServerDefRequest) returns (UpdateServerDefResponse);
  rpc FetchParamsMeta(FetchParamsRequest) returns (FetchParamsResponse);
}