// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package google.cloud.memcache.v1;

import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/longrunning/operations.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/timestamp.proto";

option go_package = "google.golang.org/genproto/googleapis/cloud/memcache/v1;memcache";
option java_multiple_files = true;
option java_outer_classname = "CloudMemcacheProto";
option java_package = "com.google.cloud.memcache.v1";

// Configures and manages Cloud Memorystore for Memcached instances.
//
//
// The `memcache.googleapis.com` service implements the Google Cloud Memorystore
// for Memcached API and defines the following resource model for managing
// Memorystore Memcached (also called Memcached below) instances:
// * The service works with a collection of cloud projects, named: `/projects/*`
// * Each project has a collection of available locations, named: `/locations/*`
// * Each location has a collection of Memcached instances, named:
// `/instances/*`
// * As such, Memcached instances are resources of the form:
//   `/projects/{project_id}/locations/{location_id}/instances/{instance_id}`
//
// Note that location_id must be a GCP `region`; for example:
// * `projects/my-memcached-project/locations/us-central1/instances/my-memcached`
service CloudMemcache {
  option (google.api.default_host) = "memcache.googleapis.com";
  option (google.api.oauth_scopes) = "https://www.googleapis.com/auth/cloud-platform";

  // Lists Instances in a given location.
  rpc ListInstances(ListInstancesRequest) returns (ListInstancesResponse) {
    option (google.api.http) = {
      get: "/v1/{parent=projects/*/locations/*}/instances"
    };
    option (google.api.method_signature) = "parent";
  }

  // Gets details of a single Instance.
  rpc GetInstance(GetInstanceRequest) returns (Instance) {
    option (google.api.http) = {
      get: "/v1/{name=projects/*/locations/*/instances/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // Creates a new Instance in a given location.
  rpc CreateInstance(CreateInstanceRequest) returns (google.longrunning.Operation) {
    option (google.api.http) = {
      post: "/v1/{parent=projects/*/locations/*}/instances"
      body: "instance"
    };
    option (google.api.method_signature) = "parent,instance,instance_id";
    option (google.longrunning.operation_info) = {
      response_type: "google.cloud.memcache.v1.Instance"
      metadata_type: "google.cloud.memcache.v1.OperationMetadata"
    };
  }

  // Updates an existing Instance in a given project and location.
  rpc UpdateInstance(UpdateInstanceRequest) returns (google.longrunning.Operation) {
    option (google.api.http) = {
      patch: "/v1/{instance.name=projects/*/locations/*/instances/*}"
      body: "instance"
    };
    option (google.api.method_signature) = "instance,update_mask";
    option (google.longrunning.operation_info) = {
      response_type: "google.cloud.memcache.v1.Instance"
      metadata_type: "google.cloud.memcache.v1.OperationMetadata"
    };
  }

  // Updates the defined Memcached Parameters for an existing Instance.
  // This method only stages the parameters, it must be followed by
  // ApplyParameters to apply the parameters to nodes of the Memcached Instance.
  rpc UpdateParameters(UpdateParametersRequest) returns (google.longrunning.Operation) {
    option (google.api.http) = {
      patch: "/v1/{name=projects/*/locations/*/instances/*}:updateParameters"
      body: "*"
    };
    option (google.api.method_signature) = "name,update_mask,parameters";
    option (google.longrunning.operation_info) = {
      response_type: "google.cloud.memcache.v1.Instance"
      metadata_type: "google.cloud.memcache.v1.OperationMetadata"
    };
  }

  // Deletes a single Instance.
  rpc DeleteInstance(DeleteInstanceRequest) returns (google.longrunning.Operation) {
    option (google.api.http) = {
      delete: "/v1/{name=projects/*/locations/*/instances/*}"
    };
    option (google.api.method_signature) = "name";
    option (google.longrunning.operation_info) = {
      response_type: "google.protobuf.Empty"
      metadata_type: "google.cloud.memcache.v1.OperationMetadata"
    };
  }

  // ApplyParameters will restart the set of specified nodes in order to update
  // them to the current set of parameters for the Memcached Instance.
  rpc ApplyParameters(ApplyParametersRequest) returns (google.longrunning.Operation) {
    option (google.api.http) = {
      post: "/v1/{name=projects/*/locations/*/instances/*}:applyParameters"
      body: "*"
    };
    option (google.api.method_signature) = "name,node_ids,apply_all";
    option (google.longrunning.operation_info) = {
      response_type: "google.cloud.memcache.v1.Instance"
      metadata_type: "google.cloud.memcache.v1.OperationMetadata"
    };
  }
}

message Instance {
  option (google.api.resource) = {
    type: "memcache.googleapis.com/Instance"
    pattern: "projects/{project}/locations/{location}/instances/{instance}"
  };

  // Configuration for a Memcached Node.
  message NodeConfig {
    // Required. Number of cpus per Memcached node.
    int32 cpu_count = 1 [(google.api.field_behavior) = REQUIRED];

    // Required. Memory size in MiB for each Memcached node.
    int32 memory_size_mb = 2 [(google.api.field_behavior) = REQUIRED];
  }

  message Node {
    // Different states of a Memcached node.
    enum State {
      // Node state is not set.
      STATE_UNSPECIFIED = 0;

      // Node is being created.
      CREATING = 1;

      // Node has been created and ready to be used.
      READY = 2;

      // Node is being deleted.
      DELETING = 3;

      // Node is being updated.
      UPDATING = 4;
    }

    // Output only. Identifier of the Memcached node. The node id does not
    // include project or location like the Memcached instance name.
    string node_id = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. Location (GCP Zone) for the Memcached node.
    string zone = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. Current state of the Memcached node.
    State state = 3 [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. Hostname or IP address of the Memcached node used by the
    // clients to connect to the Memcached server on this node.
    string host = 4 [(google.api.field_behavior) = OUTPUT_ONLY];

    // Output only. The port number of the Memcached server on this node.
    int32 port = 5 [(google.api.field_behavior) = OUTPUT_ONLY];

    // User defined parameters currently applied to the node.
    MemcacheParameters parameters = 6;
  }

  message InstanceMessage {
    enum Code {
      // Message Code not set.
      CODE_UNSPECIFIED = 0;

      // Memcached nodes are distributed unevenly.
      ZONE_DISTRIBUTION_UNBALANCED = 1;
    }

    // A code that correspond to one type of user-facing message.
    Code code = 1;

    // Message on memcached instance which will be exposed to users.
    string message = 2;
  }

  // Different states of a Memcached instance.
  enum State {
    // State not set.
    STATE_UNSPECIFIED = 0;

    // Memcached instance is being created.
    CREATING = 1;

    // Memcached instance has been created and ready to be used.
    READY = 2;

    // Memcached instance is being deleted.
    DELETING = 4;

    // Memcached instance is going through maintenance, e.g. data plane rollout.
    PERFORMING_MAINTENANCE = 5;
  }

  // Required. Unique name of the resource in this scope including project and
  // location using the form:
  //     `projects/{project_id}/locations/{location_id}/instances/{instance_id}`
  //
  // Note: Memcached instances are managed and addressed at regional level so
  // location_id here refers to a GCP region; however, users may choose which
  // zones Memcached nodes within an instances should be provisioned in.
  // Refer to [zones] field for more details.
  string name = 1 [(google.api.field_behavior) = REQUIRED];

  // User provided name for the instance only used for display
  // purposes. Cannot be more than 80 characters.
  string display_name = 2;

  // Resource labels to represent user-provided metadata.
  // Refer to cloud documentation on labels for more details.
  // https://cloud.google.com/compute/docs/labeling-resources
  map<string, string> labels = 3;

  // The full name of the Google Compute Engine
  // [network](/compute/docs/networks-and-firewalls#networks) to which the
  // instance is connected. If left unspecified, the `default` network
  // will be used.
  string authorized_network = 4;

  // Zones where Memcached nodes should be provisioned in.
  // Memcached nodes will be equally distributed across these zones. If not
  // provided, the service will by default create nodes in all zones in the
  // region for the instance.
  repeated string zones = 5;

  // Required. Number of nodes in the Memcached instance.
  int32 node_count = 6 [(google.api.field_behavior) = REQUIRED];

  // Required. Configuration for Memcached nodes.
  NodeConfig node_config = 7 [(google.api.field_behavior) = REQUIRED];

  // The major version of Memcached software.
  // If not provided, latest supported version will be used. Currently the
  // latest supported major version is MEMCACHE_1_5.
  // The minor version will be automatically determined by our system based on
  // the latest supported minor version.
  MemcacheVersion memcache_version = 9;

  // Optional: User defined parameters to apply to the memcached process
  // on each node.
  MemcacheParameters parameters = 11;

  // Output only. List of Memcached nodes.
  // Refer to [Node] message for more details.
  repeated Node memcache_nodes = 12 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The time the instance was created.
  google.protobuf.Timestamp create_time = 13 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The time the instance was updated.
  google.protobuf.Timestamp update_time = 14 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The state of this Memcached instance.
  State state = 15 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. The full version of memcached server running on this instance.
  // System automatically determines the full memcached version for an instance
  // based on the input MemcacheVersion.
  // The full version format will be "memcached-1.5.16".
  string memcache_full_version = 18 [(google.api.field_behavior) = OUTPUT_ONLY];

  // List of messages that describe current statuses of memcached instance.
  repeated InstanceMessage instance_messages = 19;

  // Output only. Endpoint for Discovery API
  string discovery_endpoint = 20 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Request for [ListInstances][google.cloud.memcache.v1.CloudMemcache.ListInstances].
message ListInstancesRequest {
  // Required. The resource name of the instance location using the form:
  //     `projects/{project_id}/locations/{location_id}`
  // where `location_id` refers to a GCP region
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "locations.googleapis.com/Location"
    }
  ];

  // The maximum number of items to return.
  //
  // If not specified, a default value of 1000 will be used by the service.
  // Regardless of the page_size value, the response may include a partial list
  // and a caller should only rely on response's
  // [next_page_token][CloudMemcache.ListInstancesResponse.next_page_token]
  // to determine if there are more instances left to be queried.
  int32 page_size = 2;

  // The next_page_token value returned from a previous List request,
  // if any.
  string page_token = 3;

  // List filter. For example, exclude all Memcached instances with name as
  // my-instance by specifying "name != my-instance".
  string filter = 4;

  // Sort results. Supported values are "name", "name desc" or "" (unsorted).
  string order_by = 5;
}

// Response for [ListInstances][google.cloud.memcache.v1.CloudMemcache.ListInstances].
message ListInstancesResponse {
  // A list of Memcached instances in the project in the specified location,
  // or across all locations.
  //
  // If the `location_id` in the parent field of the request is "-", all regions
  // available to the project are queried, and the results aggregated.
  repeated Instance instances = 1;

  // Token to retrieve the next page of results, or empty if there are no more
  // results in the list.
  string next_page_token = 2;

  // Locations that could not be reached.
  repeated string unreachable = 3;
}

// Request for [GetInstance][google.cloud.memcache.v1.CloudMemcache.GetInstance].
message GetInstanceRequest {
  // Required. Memcached instance resource name in the format:
  //     `projects/{project_id}/locations/{location_id}/instances/{instance_id}`
  // where `location_id` refers to a GCP region
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "memcache.googleapis.com/Instance"
    }
  ];
}

// Request for [CreateInstance][google.cloud.memcache.v1.CloudMemcache.CreateInstance].
message CreateInstanceRequest {
  // Required. The resource name of the instance location using the form:
  //     `projects/{project_id}/locations/{location_id}`
  // where `location_id` refers to a GCP region
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "locations.googleapis.com/Location"
    }
  ];

  // Required. The logical name of the Memcached instance in the user
  // project with the following restrictions:
  //
  // * Must contain only lowercase letters, numbers, and hyphens.
  // * Must start with a letter.
  // * Must be between 1-40 characters.
  // * Must end with a number or a letter.
  // * Must be unique within the user project / location
  //
  // If any of the above are not met, will raise an invalid argument error.
  string instance_id = 2 [(google.api.field_behavior) = REQUIRED];

  // Required. A Memcached Instance
  Instance instance = 3 [(google.api.field_behavior) = REQUIRED];
}

// Request for [UpdateInstance][google.cloud.memcache.v1.CloudMemcache.UpdateInstance].
message UpdateInstanceRequest {
  // Required. Mask of fields to update.
  //  *   `displayName`
  google.protobuf.FieldMask update_mask = 1 [(google.api.field_behavior) = REQUIRED];

  // Required. A Memcached Instance.
  // Only fields specified in update_mask are updated.
  Instance instance = 2 [(google.api.field_behavior) = REQUIRED];
}

// Request for [DeleteInstance][google.cloud.memcache.v1.CloudMemcache.DeleteInstance].
message DeleteInstanceRequest {
  // Required. Memcached instance resource name in the format:
  //     `projects/{project_id}/locations/{location_id}/instances/{instance_id}`
  // where `location_id` refers to a GCP region
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "memcache.googleapis.com/Instance"
    }
  ];
}

// Request for [ApplyParameters][google.cloud.memcache.v1.CloudMemcache.ApplyParameters].
message ApplyParametersRequest {
  // Required. Resource name of the Memcached instance for which parameter group updates
  // should be applied.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "memcache.googleapis.com/Instance"
    }
  ];

  // Nodes to which we should apply the instance-level parameter group.
  repeated string node_ids = 2;

  // Whether to apply instance-level parameter group to all nodes. If set to
  // true, will explicitly restrict users from specifying any nodes, and apply
  // parameter group updates to all nodes within the instance.
  bool apply_all = 3;
}

// Request for [UpdateParameters][google.cloud.memcache.v1.CloudMemcache.UpdateParameters].
message UpdateParametersRequest {
  // Required. Resource name of the Memcached instance for which the parameters should be
  // updated.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "memcache.googleapis.com/Instance"
    }
  ];

  // Required. Mask of fields to update.
  google.protobuf.FieldMask update_mask = 2 [(google.api.field_behavior) = REQUIRED];

  // The parameters to apply to the instance.
  MemcacheParameters parameters = 3;
}

message MemcacheParameters {
  // Output only. The unique ID associated with this set of parameters. Users
  // can use this id to determine if the parameters associated with the instance
  // differ from the parameters associated with the nodes and any action needs
  // to be taken to apply parameters on nodes.
  string id = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // User defined set of parameters to use in the memcached process.
  map<string, string> params = 3;
}

// Represents the metadata of a long-running operation.
message OperationMetadata {
  // Output only. Time when the operation was created.
  google.protobuf.Timestamp create_time = 1 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Time when the operation finished running.
  google.protobuf.Timestamp end_time = 2 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Server-defined resource path for the target of the operation.
  string target = 3 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Name of the verb executed by the operation.
  string verb = 4 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Human-readable status of the operation, if any.
  string status_detail = 5 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. Identifies whether the user has requested cancellation
  // of the operation. Operations that have successfully been cancelled
  // have [Operation.error][] value with a [google.rpc.Status.code][google.rpc.Status.code] of 1,
  // corresponding to `Code.CANCELLED`.
  bool cancel_requested = 6 [(google.api.field_behavior) = OUTPUT_ONLY];

  // Output only. API version used to start the operation.
  string api_version = 7 [(google.api.field_behavior) = OUTPUT_ONLY];
}

// Memcached versions supported by our service.
enum MemcacheVersion {
  MEMCACHE_VERSION_UNSPECIFIED = 0;

  // Memcached 1.5 version.
  MEMCACHE_1_5 = 1;
}
