syntax = "proto3";
package pb;

service AppRuntimeSync {
  // Deprecated: -
  rpc GetAppStatusDeprecated (ServicesRequest) returns (StatusMessage) {}
  rpc GetAppStatus (AppStatusReq) returns (AppStatus) {}
  rpc GetAppPods (ServiceRequest) returns (ServiceAppPodList) {}
  rpc GetMultiAppPods (ServicesRequest) returns (MultiServiceAppPodList) {}
  rpc GetDeployInfo (ServiceRequest) returns (DeployInfo) {}
  rpc GetTenantResource (TenantRequest) returns (TenantResource) {}
  rpc GetTenantResources (Empty) returns (TenantResourceList) {}
  rpc ListThirdPartyEndpoints (ServiceRequest) returns (ThirdPartyEndpoints) {}
  rpc AddThirdPartyEndpoint (AddThirdPartyEndpointsReq) returns (Empty) {}
  rpc UpdThirdPartyEndpoint (UpdThirdPartyEndpointsReq) returns (Empty) {}
  rpc DelThirdPartyEndpoint (DelThirdPartyEndpointsReq) returns (Empty) {}
  rpc GetPodDetail(GetPodDetailReq) returns (PodDetail) {}
  rpc GetStorageClasses(Empty) returns (StorageClasses) {}
  rpc GetAppVolumeStatus(ServiceRequest) returns(ServiceVolumeStatusMessage){}
}

message Empty {}

message AppStatusReq {
  string app_id = 1;
}

message ServiceRequest {
  string service_id = 1;
}
message ServicesRequest {
  string service_ids = 1;
}
message TenantRequest {
  string tenant_id = 1;
}

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

message DiskMessage {
  map<string, double> disks = 1;
}

message ServiceAppPodList {
  repeated ServiceAppPod oldPods = 1;
  repeated ServiceAppPod newPods = 2;
}

message MultiServiceAppPodList {
  map<string, ServiceAppPodList> servicePods = 1;
}

message ServiceAppPod {
  string service_id = 1;
  string deploy_id = 2;
  string deploy_type = 3;
  string pod_name = 4;
  string pod_ip = 5;
  string pod_status = 6;
  map<string, Container> containers = 7;
  repeated string pod_volumes = 8;
}

message Container {
  string container_name = 1;
  int64 memory_limit = 2;
  int64 cpu_request = 3;
}

message DeployInfo {
  string namespace = 1;
  string statefuleset = 2;
  string deployment = 3;
  string start_time = 4;
  map<string, string> pods = 5;
  map<string, string> services = 6;
  map<string, string> endpoints = 7;
  map<string, string> secrets = 8;
  map<string, string> ingresses = 9;
  map<string, string> replicatset = 10;
  string status = 11;
}

message TenantResource {
  int64 cpu_request = 1;
  int64 cpu_limit = 2;
  int64 memory_request = 3;
  int64 memory_limit = 4;
  int64 running_app_num = 5;
  int64 running_app_third_num = 10;
  int64 running_app_internal_num = 11;
}

message TenantResourceList {
  map<string, TenantResource> resources = 1;
}

message AddThirdPartyEndpointsReq {
  string uuid = 1;
  string sid = 2;
  string ip = 3;
  int32 port = 4;
  bool is_online = 5;
}

message UpdThirdPartyEndpointsReq {
  string uuid = 1;
  string sid = 2;
  string ip = 3;
  int32 port = 4;
  bool is_online = 5;
}

message DelThirdPartyEndpointsReq {
  string uuid = 1;
  string sid = 2;
  string ip = 3;
  int32 port = 4;
}

message ThirdPartyEndpoint {
  string uuid = 1;
  string sid = 2;
  string ip = 3;
  int32 port = 4;
  string status = 5;
  bool is_online = 6;
}

message ThirdPartyEndpoints {
  repeated ThirdPartyEndpoint obj = 1;
}

message ListPodsBySIDReq {
  string sid = 1;
}

message GetPodDetailReq {
  string sid = 1;
  string pod_name = 2;
}

message PodEvent {
  string type = 1;
  string reason = 2;
  string age = 3;
  string message = 5;
}

message PodStatus {
  enum Type {
    // PENDING means the pod has been accepted by the system, but one or more of the containers
    // has not been started. This includes time before being bound to a node, as well as time spent
    // pulling images onto the host.
    PENDING = 0;
    // RUNNING means the pod has been bound to a node and all of the containers have been started.
    // At least one container is still running or is in the process of being restarted.
    RUNNING = 1;
    // SUCCEEDED means that all containers in the pod have voluntarily terminated
    // with a container exit code of 0, and the system is not going to restart any of these containers.
    SUCCEEDED = 2;
    // FAILED means that all containers in the pod have terminated, and at least one container has
    // terminated in a failure (exited with a non-zero exit code or was stopped by the system).
    FAILED = 3;
    // UNKNOWN means that for some reason the state of the pod could not be obtained, typically due
    // to an error in communicating with the host of the pod.
    UNKNOWN = 4;
    TEMINATING = 5;
    ABNORMAL = 6;
    INITIATING = 7;
    SCHEDULING = 8;
    NOTREADY = 9;
    UNHEALTHY = 10;
  }

  Type type = 1;
  string reason = 2;
  string message = 3;
  string advice = 4;
  string type_str = 5;
}

message PodContainer {
  string image = 1;
  string state = 2;
  string reason = 3;
  string started = 4;
  string limit_memory = 5;
  string limit_cpu = 6;
  string request_memory = 7;
  string request_cpu = 8;
}

message PodDetail {
  string name = 1;
  string node = 2;
  string start_time = 3;
  PodStatus status = 4;
  string ip = 5;
  string node_ip = 6;
  string version = 7;
  repeated PodContainer init_containers = 8;
  repeated PodContainer containers = 9;
  repeated PodEvent events = 10;
}

message StorageClasses {
  repeated StorageClassDetail list = 1;
}

message StorageClassDetail{
  string name = 1;
  string provisioner = 2;
  map<string, string> parameters = 3;
  string reclaim_policy = 4;
  bool allow_volume_expansion = 5;
  string volume_binding_mode = 6;
  repeated TopologySelectorTerm allowed_topologies = 7;
}

message TopologySelectorTerm {
repeated TopologySelectorLabelRequirement match_label_expressions = 1;
}

message TopologySelectorLabelRequirement {
  string key = 1;
  repeated string values = 2;
}

enum ServiceVolumeStatus {
    READY = 0;
    NOT_READY = 1;
}

message ServiceVolumeStatusMessage {
  map<string, ServiceVolumeStatus> status = 1;
}

message AppStatus {
  enum Status {
    NIL = 0;
    RUNNING = 1;
    CLOSED = 2;
    ABNORMAL = 3;
    STARTING = 4;
    STOPPING = 5;
  }

  Status status = 1;
  int64 cpu = 2;
  int64 memory = 3;
}