syntax = "proto3";

package yandex.cloud.dataproc.v1;

import "google/api/annotations.proto";
import "google/protobuf/field_mask.proto";
import "yandex/cloud/dataproc/v1/common.proto";
import "yandex/cloud/dataproc/v1/cluster.proto";
import "yandex/cloud/dataproc/v1/subcluster.proto";
import "yandex/cloud/operation/operation.proto";
import "yandex/cloud/validation.proto";
import "yandex/cloud/api/operation.proto";

option go_package = "github.com/yandex-cloud/go-genproto/yandex/cloud/dataproc/v1;dataproc";
option java_package = "yandex.cloud.api.dataproc.v1";

// A set of methods for managing Data Proc clusters.
service ClusterService {
  // Returns the specified cluster.
  //
  // To get the list of all available clusters, make a [ClusterService.List] request.
  rpc Get (GetClusterRequest) returns (Cluster) {
    option (google.api.http) = { get: "/dataproc/v1/clusters/{cluster_id}" };
  }

  // Retrieves the list of clusters in the specified folder.
  rpc List (ListClustersRequest) returns (ListClustersResponse) {
    option (google.api.http) = { get: "/dataproc/v1/clusters" };
  }

  // Creates a cluster in the specified folder.
  rpc Create (CreateClusterRequest) returns (operation.Operation) {
    option (google.api.http) = { post: "/dataproc/v1/clusters" body: "*" };
    option (yandex.cloud.api.operation) = {
      metadata: "CreateClusterMetadata"
      response: "Cluster"
    };
  }

  // Updates the configuration of the specified cluster.
  rpc Update (UpdateClusterRequest) returns (operation.Operation) {
    option (google.api.http) = { patch: "/dataproc/v1/clusters/{cluster_id}" body: "*" };
    option (yandex.cloud.api.operation) = {
      metadata: "UpdateClusterMetadata"
      response: "Cluster"
    };
  }

  // Deletes the specified cluster.
  rpc Delete (DeleteClusterRequest) returns (operation.Operation) {
    option (google.api.http) = { delete: "/dataproc/v1/clusters/{cluster_id}" };
    option (yandex.cloud.api.operation) = {
      metadata: "DeleteClusterMetadata"
      response: "google.protobuf.Empty"
    };
  }

  // Starts the specified cluster.
  rpc Start (StartClusterRequest) returns (operation.Operation) {
    option (google.api.http) = { post: "/dataproc/v1/clusters/{cluster_id}:start" };
    option (yandex.cloud.api.operation) = {
      metadata: "StartClusterMetadata"
      response: "Cluster"
    };
  }

  // Stops the specified cluster.
  rpc Stop (StopClusterRequest) returns (operation.Operation) {
    option (google.api.http) = { post: "/dataproc/v1/clusters/{cluster_id}:stop" body: "*" };
    option (yandex.cloud.api.operation) = {
      metadata: "StopClusterMetadata"
      response: "Cluster"
    };
  }

  // Lists operations for the specified cluster.
  rpc ListOperations (ListClusterOperationsRequest) returns (ListClusterOperationsResponse) {
    option (google.api.http) = { get: "/dataproc/v1/clusters/{cluster_id}/operations" };
  }

  // Retrieves the list of hosts in the specified cluster.
  rpc ListHosts (ListClusterHostsRequest) returns (ListClusterHostsResponse) {
    option (google.api.http) = { get: "/dataproc/v1/clusters/{cluster_id}/hosts" };
  }

  // Retrieves a list of links to web interfaces being proxied by Data Proc UI Proxy.
  rpc ListUILinks (ListUILinksRequest) returns (ListUILinksResponse) {
    option (google.api.http) = { get: "/dataproc/v1/clusters/{cluster_id}/ui_links" };
  }
}

message GetClusterRequest {
  // ID of the Data Proc cluster.
  //
  // To get a cluster ID make a [ClusterService.List] request.
  string cluster_id = 1 [(required) = true, (length) = "<=50"];
}

message ListClustersRequest {
  // ID of the folder to list clusters in.
  //
  // To get the folder ID make a [yandex.cloud.resourcemanager.v1.FolderService.List] request.
  string folder_id = 1 [(required) = true, (length) = "<=50"];

  // The maximum number of results per page to return. If the number of available
  // results is larger than [page_size], the service returns a [ListClustersResponse.next_page_token]
  // that can be used to get the next page of results in subsequent list requests.
  // Default value: 100.
  int64 page_size = 2 [(value) = "<=1000"];

  // Page token. To get the next page of results, set `page_token` to the
  // [ListClustersResponse.next_page_token] returned by a previous list request.
  string page_token = 3 [(length) = "<=100"];

  // A filter expression that filters clusters listed in the response.
  //
  // The expression must specify:
  // 1. The field name. Currently you can use filtering only on [Cluster.name] field.
  // 2. An operator. Can be either `=` or `!=` for single values, `IN` or `NOT IN` for lists of values.
  // 3. The value. Must be 3-63 characters long and match the regular expression `^[a-z][-a-z0-9]{1,61}[a-z0-9].
  // Example of a filter: `name=my-cluster`.
  string filter = 4 [(length) = "<=1000"];
}

message ListClustersResponse {
  // List of clusters in the specified folder.
  repeated Cluster clusters = 1;

  // Token for getting the next page of the list. If the number of results is greater than
  // the specified [ListClustersRequest.page_size], use `next_page_token` as the value
  // for the [ListClustersRequest.page_token] parameter in the next list request.
  //
  // Each subsequent page will have its own `next_page_token` to continue paging through the results.
  string next_page_token = 2;
}

message CreateSubclusterConfigSpec {
  // Name of the subcluster.
  string name = 1 [(pattern) = "|[a-z][-a-z0-9]{1,61}[a-z0-9]"];

  // Role of the subcluster in the Data Proc cluster.
  Role role = 2 [(required) = true];

  // Resource configuration for hosts in the subcluster.
  Resources resources = 3 [(required) = true];

  // ID of the VPC subnet used for hosts in the subcluster.
  string subnet_id = 4 [(required) = true, (length) = "<=50"];

  // Number of hosts in the subcluster.
  int64 hosts_count = 5 [(required) = true, (value) = ">=1"];

  reserved 6;

  // Configuration for instance group based subclusters
  AutoscalingConfig autoscaling_config = 7;
}

message UpdateSubclusterConfigSpec {
  // ID of the subcluster to update.
  //
  // To get the subcluster ID make a [SubclusterService.List] request.
  string id = 1;

  // Name of the subcluster.
  string name = 2 [(pattern) = "|[a-z][-a-z0-9]{1,61}[a-z0-9]"];

  // Resource configuration for each host in the subcluster.
  Resources resources = 3;

  // Number of hosts in the subcluster.
  int64 hosts_count = 4 [(value) = ">=1"];

  // Configuration for instance group based subclusters
  AutoscalingConfig autoscaling_config = 5;
}

message CreateClusterConfigSpec {
  // Version of the image for cluster provisioning.
  //
  // All available versions are listed in the [documentation](/docs/data-proc/concepts/image-versions).
  string version_id = 1;

  // Data Proc specific options.
  HadoopConfig hadoop = 2;

  // Specification for creating subclusters.
  repeated CreateSubclusterConfigSpec subclusters_spec = 3;
}

message UpdateClusterConfigSpec {
  // New configuration for subclusters in a cluster.
  repeated UpdateSubclusterConfigSpec subclusters_spec = 1;

  // Hadoop specific options
  HadoopConfig hadoop = 2;
}

message CreateClusterRequest {
  // ID of the folder to create a cluster in.
  //
  // To get a folder ID make a [yandex.cloud.resourcemanager.v1.FolderService.List] request.
  string folder_id = 1 [(required) = true, (length) = "<=50"];

  // Name of the cluster. The name must be unique within the folder.
  // The name can't be changed after the Data Proc cluster is created.
  string name = 2 [(pattern) = "|[a-z][-a-z0-9]{1,61}[a-z0-9]"];

  // Description of the cluster.
  string description = 3 [(length) = "<=256"];

  // Cluster labels as `key:value` pairs.
  map<string, string> labels = 4 [(yandex.cloud.size) = "<=64", (length) = "<=63", (pattern) = "[-_0-9a-z]*", (map_key).length = "1-63", (map_key).pattern = "[a-z][-_0-9a-z]*"];

  // Configuration and resources for hosts that should be created with the cluster.
  CreateClusterConfigSpec config_spec = 6 [(required) = true];

  // ID of the availability zone where the cluster should be placed.
  //
  // To get the list of available zones make a [yandex.cloud.compute.v1.ZoneService.List] request.
  string zone_id = 7 [(required) = true, (length) = "<=50"];

  // ID of the service account to be used by the Data Proc manager agent.
  string service_account_id = 8 [(required) = true];

  // Name of the Object Storage bucket to use for Data Proc jobs.
  string bucket = 9;

  // Enable UI Proxy feature.
  bool ui_proxy = 10;

  // User security groups.
  repeated string security_group_ids = 11;

  // Host groups to place VMs of cluster on.
  repeated string host_group_ids = 12;

  // Deletion Protection inhibits deletion of the cluster
  bool deletion_protection = 13;

  // ID of the cloud logging log group to write logs. If not set, logs will not be sent to logging service
  string log_group_id = 14;
}

message CreateClusterMetadata {
  // ID of the cluster that is being created.
  string cluster_id = 1;
}

message UpdateClusterRequest {
  // ID of the cluster to update.
  //
  // To get the cluster ID, make a [ClusterService.List] request.
  string cluster_id = 1 [(length) = "<=50"];

  // Field mask that specifies which attributes of the cluster should be updated.
  google.protobuf.FieldMask update_mask = 2;

  // New description for the cluster.
  string description = 3 [(length) = "<=256"];

  // A new set of cluster labels as `key:value` pairs.
  map<string, string> labels = 4 [(yandex.cloud.size) = "<=64", (length) = "<=63", (pattern) = "[-_0-9a-z]*", (map_key).length = "1-63", (map_key).pattern = "[a-z][-_0-9a-z]*"];

  // Configuration and resources for hosts that should be created with the Data Proc cluster.
  UpdateClusterConfigSpec config_spec = 5;

  // New name for the Data Proc cluster. The name must be unique within the folder.
  string name = 6 [(pattern) = "|[a-z][-a-z0-9]{1,61}[a-z0-9]"];

  // ID of the new service account to be used by the Data Proc manager agent.
  string service_account_id = 7;

  // Name of the new Object Storage bucket to use for Data Proc jobs.
  string bucket = 8;

  // Timeout to gracefully decommission nodes. In seconds. Default value: 0
  int64 decommission_timeout = 9 [(value) = "0-86400"];

  // Enable UI Proxy feature.
  bool ui_proxy = 10;

  // User security groups.
  repeated string security_group_ids = 11;

  // Deletion Protection inhibits deletion of the cluster
  bool deletion_protection = 12;

  // ID of the cloud logging log group to write logs. If not set, logs will not be sent to logging service
  string log_group_id = 13;
}

message UpdateClusterMetadata {
  // ID of the cluster that is being updated.
  string cluster_id = 1;
}

message DeleteClusterRequest {
  // ID of the cluster to delete.
  //
  // To get a cluster ID, make a [ClusterService.List] request.
  string cluster_id = 1 [(required) = true, (length) = "<=50"];

  // Timeout to gracefully decommission nodes. In seconds. Default value: 0
  int64 decommission_timeout = 2 [(value) = "0-86400"];
}

message DeleteClusterMetadata {
  // ID of the Data Proc cluster that is being deleted.
  string cluster_id = 1;
}

message StartClusterRequest {
  // ID of the cluster to start.
  //
  // To get a cluster ID, make a [ClusterService.List] request.
  string cluster_id = 1 [(required) = true, (length) = "<=50"];
}

message StartClusterMetadata {
  // ID of the Data Proc cluster that is being started.
  string cluster_id = 1;
}

message StopClusterRequest {
  // ID of the cluster to stop.
  //
  // To get a cluster ID, make a [ClusterService.List] request.
  string cluster_id = 1 [(required) = true, (length) = "<=50"];

  // Timeout to gracefully decommission nodes. In seconds. Default value: 0
  int64 decommission_timeout = 2 [(value) = "0-86400"];
}

message StopClusterMetadata {
  // ID of the Data Proc cluster that is being stopped.
  string cluster_id = 1;
}

message ListClusterOperationsRequest {
  // ID of the cluster to list operations for.
  string cluster_id = 1 [(required) = true, (length) = "<=50"];

  // The maximum number of results per page to return. If the number of available
  // results is larger than [page_size], the service returns a [ListClusterOperationsResponse.next_page_token]
  // that can be used to get the next page of results in subsequent list requests.
  // Default value: 100.
  int64 page_size = 2 [(value) = "<=1000"];

  // Page token. To get the next page of results, set [page_token] to the
  // [ListClusterOperationsResponse.next_page_token] returned by a previous list request.
  string page_token = 3 [(length) = "<=100"];
}

message ListClusterOperationsResponse {
  // List of operations for the specified cluster.
  repeated operation.Operation operations = 1;

  // Token for getting the next page of the list. If the number of results is greater than
  // the specified [ListClusterOperationsRequest.page_size], use `next_page_token` as the value
  // for the [ListClusterOperationsRequest.page_token] parameter in the next list request.
  //
  // Each subsequent page will have its own `next_page_token` to continue paging through the results.
  string next_page_token = 2;
}

message ListClusterHostsRequest {
  // ID of the cluster to list hosts for.
  //
  // To get a cluster ID, make a [ClusterService.List] request.
  string cluster_id = 1 [(length) = "<=50"];

  // The maximum number of results per page to return. If the number of available
  // results is larger than [page_size], the service returns a [ListClusterHostsResponse.next_page_token]
  // that can be used to get the next page of results in subsequent list requests.
  // Default value: 100.
  int64 page_size = 2 [(value) = "<=1000"];

  // Page token. To get the next page of results, set [page_token] to the
  // [ListClusterHostsResponse.next_page_token] returned by a previous list request.
  string page_token = 3 [(length) = "<=100"];

  // A filter expression that filters hosts listed in the response.
  //
  // The expression must specify:
  // 1. The field name. Currently you can use filtering only on [Cluster.name] field.
  // 2. An operator. Can be either `=` or `!=` for single values, `IN` or `NOT IN` for lists of values.
  // 3. The value. Must be 3-63 characters long and match the regular expression `^[a-z][-a-z0-9]{1,61}[a-z0-9].
  // Example of a filter: `name=my-host`
  string filter = 4 [(length) = "<=1000"];
}

message ListClusterHostsResponse {
  // Requested list of hosts.
  repeated Host hosts = 1;

  // Token for getting the next page of the list. If the number of results is greater than
  // the specified [ListClusterHostsRequest.page_size], use `next_page_token` as the value
  // for the [ListClusterHostsRequest.page_token] parameter in the next list request.
  //
  // Each subsequent page will have its own `next_page_token` to continue paging through the results.
  string next_page_token = 2;
}

message ListUILinksRequest {
  // Required. ID of the Hadoop cluster.
  string cluster_id = 1 [(length) = "<=50"];
}

message UILink {
  string name = 1;
  string url = 2;
}

message ListUILinksResponse {
  // Requested list of ui links.
  repeated UILink links = 1;
}
