// 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.aiplatform.v1beta1;

import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/cloud/aiplatform/v1beta1/training_pipeline.proto";
import "google/longrunning/operations.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/field_mask.proto";

option go_package = "google.golang.org/genproto/googleapis/cloud/aiplatform/v1beta1;aiplatform";
option java_multiple_files = true;
option java_outer_classname = "PipelineServiceProto";
option java_package = "com.google.cloud.aiplatform.v1beta1";

// A service for creating and managing AI Platform's pipelines.
service PipelineService {
  option (google.api.default_host) = "aiplatform.googleapis.com";
  option (google.api.oauth_scopes) = "https://www.googleapis.com/auth/cloud-platform";

  // Creates a TrainingPipeline. A created TrainingPipeline right away will be
  // attempted to be run.
  rpc CreateTrainingPipeline(CreateTrainingPipelineRequest) returns (TrainingPipeline) {
    option (google.api.http) = {
      post: "/v1beta1/{parent=projects/*/locations/*}/trainingPipelines"
      body: "training_pipeline"
    };
    option (google.api.method_signature) = "parent,training_pipeline";
  }

  // Gets a TrainingPipeline.
  rpc GetTrainingPipeline(GetTrainingPipelineRequest) returns (TrainingPipeline) {
    option (google.api.http) = {
      get: "/v1beta1/{name=projects/*/locations/*/trainingPipelines/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // Lists TrainingPipelines in a Location.
  rpc ListTrainingPipelines(ListTrainingPipelinesRequest) returns (ListTrainingPipelinesResponse) {
    option (google.api.http) = {
      get: "/v1beta1/{parent=projects/*/locations/*}/trainingPipelines"
    };
    option (google.api.method_signature) = "parent";
  }

  // Deletes a TrainingPipeline.
  rpc DeleteTrainingPipeline(DeleteTrainingPipelineRequest) returns (google.longrunning.Operation) {
    option (google.api.http) = {
      delete: "/v1beta1/{name=projects/*/locations/*/trainingPipelines/*}"
    };
    option (google.api.method_signature) = "name";
    option (google.longrunning.operation_info) = {
      response_type: "google.protobuf.Empty"
      metadata_type: "DeleteOperationMetadata"
    };
  }

  // Cancels a TrainingPipeline.
  // Starts asynchronous cancellation on the TrainingPipeline. The server
  // makes a best effort to cancel the pipeline, but success is not
  // guaranteed. Clients can use [PipelineService.GetTrainingPipeline][google.cloud.aiplatform.v1beta1.PipelineService.GetTrainingPipeline] or
  // other methods to check whether the cancellation succeeded or whether the
  // pipeline completed despite cancellation. On successful cancellation,
  // the TrainingPipeline is not deleted; instead it becomes a pipeline with
  // a [TrainingPipeline.error][google.cloud.aiplatform.v1beta1.TrainingPipeline.error] value with a [google.rpc.Status.code][google.rpc.Status.code] of 1,
  // corresponding to `Code.CANCELLED`, and [TrainingPipeline.state][google.cloud.aiplatform.v1beta1.TrainingPipeline.state] is set to
  // `CANCELLED`.
  rpc CancelTrainingPipeline(CancelTrainingPipelineRequest) returns (google.protobuf.Empty) {
    option (google.api.http) = {
      post: "/v1beta1/{name=projects/*/locations/*/trainingPipelines/*}:cancel"
      body: "*"
    };
    option (google.api.method_signature) = "name";
  }
}

// Request message for [PipelineService.CreateTrainingPipeline][google.cloud.aiplatform.v1beta1.PipelineService.CreateTrainingPipeline].
message CreateTrainingPipelineRequest {
  // Required. The resource name of the Location to create the TrainingPipeline in.
  // Format: `projects/{project}/locations/{location}`
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "locations.googleapis.com/Location"
    }
  ];

  // Required. The TrainingPipeline to create.
  TrainingPipeline training_pipeline = 2 [(google.api.field_behavior) = REQUIRED];
}

// Request message for [PipelineService.GetTrainingPipeline][google.cloud.aiplatform.v1beta1.PipelineService.GetTrainingPipeline].
message GetTrainingPipelineRequest {
  // Required. The name of the TrainingPipeline resource.
  // Format:
  //
  // `projects/{project}/locations/{location}/trainingPipelines/{training_pipeline}`
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "aiplatform.googleapis.com/TrainingPipeline"
    }
  ];
}

// Request message for [PipelineService.ListTrainingPipelines][google.cloud.aiplatform.v1beta1.PipelineService.ListTrainingPipelines].
message ListTrainingPipelinesRequest {
  // Required. The resource name of the Location to list the TrainingPipelines from.
  // Format: `projects/{project}/locations/{location}`
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "locations.googleapis.com/Location"
    }
  ];

  // The standard list filter.
  // Supported fields:
  //
  //   * `display_name` supports = and !=.
  //
  //   * `state` supports = and !=.
  //
  // Some examples of using the filter are:
  //
  //  * `state="PIPELINE_STATE_SUCCEEDED" AND display_name="my_pipeline"`
  //
  //  * `state="PIPELINE_STATE_RUNNING" OR display_name="my_pipeline"`
  //
  //  * `NOT display_name="my_pipeline"`
  //
  //  * `state="PIPELINE_STATE_FAILED"`
  string filter = 2;

  // The standard list page size.
  int32 page_size = 3;

  // The standard list page token.
  // Typically obtained via
  // [ListTrainingPipelinesResponse.next_page_token][google.cloud.aiplatform.v1beta1.ListTrainingPipelinesResponse.next_page_token] of the previous
  // [PipelineService.ListTrainingPipelines][google.cloud.aiplatform.v1beta1.PipelineService.ListTrainingPipelines] call.
  string page_token = 4;

  // Mask specifying which fields to read.
  google.protobuf.FieldMask read_mask = 5;
}

// Response message for [PipelineService.ListTrainingPipelines][google.cloud.aiplatform.v1beta1.PipelineService.ListTrainingPipelines]
message ListTrainingPipelinesResponse {
  // List of TrainingPipelines in the requested page.
  repeated TrainingPipeline training_pipelines = 1;

  // A token to retrieve next page of results.
  // Pass to [ListTrainingPipelinesRequest.page_token][google.cloud.aiplatform.v1beta1.ListTrainingPipelinesRequest.page_token] to obtain that page.
  string next_page_token = 2;
}

// Request message for [PipelineService.DeleteTrainingPipeline][google.cloud.aiplatform.v1beta1.PipelineService.DeleteTrainingPipeline].
message DeleteTrainingPipelineRequest {
  // Required. The name of the TrainingPipeline resource to be deleted.
  // Format:
  //
  // `projects/{project}/locations/{location}/trainingPipelines/{training_pipeline}`
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "aiplatform.googleapis.com/TrainingPipeline"
    }
  ];
}

// Request message for [PipelineService.CancelTrainingPipeline][google.cloud.aiplatform.v1beta1.PipelineService.CancelTrainingPipeline].
message CancelTrainingPipelineRequest {
  // Required. The name of the TrainingPipeline to cancel.
  // Format:
  //
  // `projects/{project}/locations/{location}/trainingPipelines/{training_pipeline}`
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "aiplatform.googleapis.com/TrainingPipeline"
    }
  ];
}
