syntax = "proto3";

package yandex.cloud.mdb.clickhouse.v1;

import "google/protobuf/timestamp.proto";
import "google/protobuf/wrappers.proto";
import "google/type/timeofday.proto";
import "yandex/cloud/mdb/clickhouse/v1/config/clickhouse.proto";
import "yandex/cloud/mdb/clickhouse/v1/maintenance.proto";

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

// A ClickHouse Cluster resource. For more information, see the
// [Cluster](/docs/managed-clickhouse/concepts) section in the Developer's Guide.
message Cluster {
  // Deployment environment.
  enum Environment {
    ENVIRONMENT_UNSPECIFIED = 0;

    // Stable environment with a conservative update policy:
    // only hotfixes are applied during regular maintenance.
    PRODUCTION = 1;

    // Environment with more aggressive update policy: new versions
    // are rolled out irrespective of backward compatibility.
    PRESTABLE = 2;
  }

  enum Health {

    // State of the cluster is unknown ([Host.health] for every host in the cluster is UNKNOWN).
    HEALTH_UNKNOWN = 0;

    // Cluster is alive and well ([Host.health] for every host in the cluster is ALIVE).
    ALIVE = 1;

    // Cluster is inoperable ([Host.health] for every host in the cluster is DEAD).
    DEAD = 2;

    // Cluster is working below capacity ([Host.health] for at least one host in the cluster is not ALIVE).
    DEGRADED = 3;
  }

  enum Status {

    // Cluster state is unknown.
    STATUS_UNKNOWN = 0;

    // Cluster is being created.
    CREATING = 1;

    // Cluster is running normally.
    RUNNING = 2;

    // Cluster encountered a problem and cannot operate.
    ERROR = 3;

    // Cluster is being updated.
    UPDATING = 4;

    // Cluster is stopping.
    STOPPING = 5;

    // Cluster stopped.
    STOPPED = 6;

    // Cluster is starting.
    STARTING = 7;
  }

  // ID of the ClickHouse cluster.
  // This ID is assigned by MDB at creation time.
  string id = 1;

  // ID of the folder that the ClickHouse cluster belongs to.
  string folder_id = 2;

  // Creation timestamp in [RFC3339](https://www.ietf.org/rfc/rfc3339.txt) text format.
  google.protobuf.Timestamp created_at = 3;

  // Name of the ClickHouse cluster.
  // The name is unique within the folder. 1-63 characters long.
  string name = 4;

  // Description of the ClickHouse cluster. 0-256 characters long.
  string description = 5;

  // Custom labels for the ClickHouse cluster as `key:value` pairs. Maximum 64 per resource.
  map<string, string> labels = 6;

  // Deployment environment of the ClickHouse cluster.
  Environment environment = 7;

  // Description of monitoring systems relevant to the ClickHouse cluster.
  repeated Monitoring monitoring = 8;

  // Configuration of the ClickHouse cluster.
  ClusterConfig config = 9;

  // ID of the network that the cluster belongs to.
  string network_id = 10;

  // Aggregated cluster health.
  Health health = 11;

  // Current state of the cluster.
  Status status = 12;

  // ID of the service account used for access to Yandex Object Storage.
  string service_account_id = 13;

  // Maintenance window for the cluster.
  MaintenanceWindow maintenance_window = 14;

  // Planned maintenance operation to be started for the cluster within the nearest [maintenance_window].
  MaintenanceOperation planned_operation = 15;

  // User security groups
  repeated string security_group_ids = 16;

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

// Monitoring system metadata.
message Monitoring {
  // Name of the monitoring system.
  string name = 1;

  // Description of the monitoring system.
  string description = 2;

  // Link to the monitoring system charts for the ClickHouse cluster.
  string link = 3;
}

message ClusterConfig {
  message Clickhouse {
    // Configuration settings of a ClickHouse server.
    config.ClickhouseConfigSet config = 1;

    // Resources allocated to ClickHouse hosts.
    Resources resources = 2;
  }

  message Zookeeper {
    // Resources allocated to ZooKeeper hosts.
    Resources resources = 1;
  }

  // Version of the ClickHouse server software.
  string version = 1;

  // Configuration and resource allocation for ClickHouse hosts.
  Clickhouse clickhouse = 2;

  // Configuration and resource allocation for ZooKeeper hosts.
  Zookeeper zookeeper = 3;

  // Time to start the daily backup, in the UTC timezone.
  google.type.TimeOfDay backup_window_start = 4;

  // Access policy for external services.
  Access access = 5;

  CloudStorage cloud_storage = 6;

  // Whether database management through SQL commands is enabled.
  google.protobuf.BoolValue sql_database_management = 7;

  // Whether user management through SQL commands is enabled.
  google.protobuf.BoolValue sql_user_management = 8;
}

message Shard {
  // Name of the shard.
  string name = 1;

  // ID of the cluster that the shard belongs to.
  string cluster_id = 2;

  // Configuration of the shard.
  ShardConfig config = 3;
}

message ShardGroup {
  // Name of the shard group.
  string name = 1;

  // ID of the ClickHouse cluster that the shard group belongs to.
  string cluster_id = 2;

  // Description of the shard group. 0-256 characters long.
  string description = 3;

  // List of shard names contained in the shard group.
  repeated string shard_names = 4;
}

message ShardConfig {
  message Clickhouse {
    // ClickHouse settings for a shard.
    config.ClickhouseConfigSet config = 1;

    // Computational resources for a shard.
    Resources resources = 2;

    // Relative weight of a shard considered when writing data to the cluster.
    // For details, see [ClickHouse documentation](https://clickhouse.yandex/docs/en/operations/table_engines/distributed/).
    google.protobuf.Int64Value weight = 3;
  }

  // ClickHouse configuration for a shard.
  Clickhouse clickhouse = 1;
}

message Host {
  enum Type {
    TYPE_UNSPECIFIED = 0;

    // ClickHouse host.
    CLICKHOUSE = 1;

    // ZooKeeper host.
    ZOOKEEPER = 2;
  }

  enum Health {

    // Health of the host is unknown.
    UNKNOWN = 0;

    // The host is performing all its functions normally.
    ALIVE = 1;

    // The host is inoperable, and cannot perform any of its essential functions.
    DEAD = 2;

    // The host is degraded, and can perform only some of its essential functions.
    DEGRADED = 3;
  }

  // Name of the ClickHouse host. The host name is assigned by MDB at creation time, and cannot be changed.
  // 1-63 characters long.
  //
  // The name is unique across all existing MDB hosts in Yandex.Cloud, as it defines the FQDN of the host.
  string name = 1;

  // ID of the ClickHouse host. The ID is assigned by MDB at creation time.
  string cluster_id = 2;

  // ID of the availability zone where the ClickHouse host resides.
  string zone_id = 3;

  // Type of the host.
  Type type = 4;

  // Resources allocated to the ClickHouse host.
  Resources resources = 5;

  // Status code of the aggregated health of the host.
  Health health = 6;

  // Services provided by the host.
  repeated Service services = 7;

  // ID of the subnet that the host belongs to.
  string subnet_id = 8;

  // Flag showing public IP assignment status to this host.
  bool assign_public_ip = 9;

  string shard_name = 10;
}

message Service {
  enum Type {
    TYPE_UNSPECIFIED = 0;

    // The host is a ClickHouse server.
    CLICKHOUSE = 1;

    // The host is a ZooKeeper server.
    ZOOKEEPER = 2;
  }

  enum Health {

    // Health of the server is unknown.
    UNKNOWN = 0;

    // The server is working normally.
    ALIVE = 1;

    // The server is dead or unresponsive.
    DEAD = 2;
  }

  // Type of the service provided by the host.
  Type type = 1;

  // Status code of server availability.
  Health health = 2;
}

message Resources {
  // ID of the preset for computational resources available to a host (CPU, memory etc.).
  // All available presets are listed in the [documentation](/docs/managed-clickhouse/concepts/instance-types)
  string resource_preset_id = 1;

  // Volume of the storage available to a host, in bytes.
  int64 disk_size = 2;

  // Type of the storage environment for the host.
  // Possible values:
  // * network-hdd - network HDD drive,
  // * network-ssd - network SSD drive,
  // * local-ssd - local SSD storage.
  string disk_type_id = 3;
}

message Access {
  // Allow to export data from the cluster to Yandex DataLens.
  bool data_lens = 1;

  // Allow SQL queries to the cluster databases from the Yandex.Cloud management console.
  //
  // See [SQL queries in the management console](/docs/managed-clickhouse/operations/web-sql-query) for more details.
  bool web_sql = 2;

  // Allow to import data from Yandex.Metrica and AppMetrica to the cluster.
  //
  // See [Export data to Yandex.Cloud](https://appmetrica.yandex.com/docs/cloud/index.html) for more details.
  bool metrika = 3;

  // Allow access to cluster for Serverless.
  bool serverless = 4;
}

message CloudStorage {
  // Whether to use Yandex Object Storage for storing ClickHouse data.
  bool enabled = 1;
}
