// Copyright 2021 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/pipeline_job.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 csharp_namespace = "Google.Cloud.AIPlatform.V1Beta1";
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";
option php_namespace = "Google\\Cloud\\AIPlatform\\V1beta1";
option ruby_package = "Google::Cloud::AIPlatform::V1beta1";

// A service for creating and managing Vertex AI's pipelines. This includes both
// `TrainingPipeline` resources (used for AutoML and custom training) and
// `PipelineJob` resources (used for Vertex 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";
  }

  // Creates a PipelineJob. A PipelineJob will run immediately when created.
  rpc CreatePipelineJob(CreatePipelineJobRequest) returns (PipelineJob) {
    option (google.api.http) = {
      post: "/v1beta1/{parent=projects/*/locations/*}/pipelineJobs"
      body: "pipeline_job"
    };
    option (google.api.method_signature) = "parent,pipeline_job,pipeline_job_id";
  }

  // Gets a PipelineJob.
  rpc GetPipelineJob(GetPipelineJobRequest) returns (PipelineJob) {
    option (google.api.http) = {
      get: "/v1beta1/{name=projects/*/locations/*/pipelineJobs/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // Lists PipelineJobs in a Location.
  rpc ListPipelineJobs(ListPipelineJobsRequest) returns (ListPipelineJobsResponse) {
    option (google.api.http) = {
      get: "/v1beta1/{parent=projects/*/locations/*}/pipelineJobs"
    };
    option (google.api.method_signature) = "parent";
  }

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

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

  // Lists the PipelineJobs that match the filter expression. The following
  // fields are supported:
  //
  // * `pipeline_name`: Supports `=` and `!=` comparisons.
  // * `create_time`: Supports `=`, `!=`, `<`, `>`, `<=`, and `>=` comparisons.
  //   Values must be in RFC 3339 format.
  // * `update_time`: Supports `=`, `!=`, `<`, `>`, `<=`, and `>=` comparisons.
  //   Values must be in RFC 3339 format.
  // * `end_time`: Supports `=`, `!=`, `<`, `>`, `<=`, and `>=` comparisons.
  //   Values must be in RFC 3339 format.
  // * `labels`: Supports key-value equality and key presence.
  //
  // Filter expressions can be combined together using logical operators
  // (`AND` & `OR`).
  // For example: `pipeline_name="test" AND create_time>"2020-05-18T13:30:00Z"`.
  //
  // The syntax to define filter expression is based on
  // https://google.aip.dev/160.
  //
  // Examples:
  //
  // * `create_time>"2021-05-18T00:00:00Z" OR
  //   update_time>"2020-05-18T00:00:00Z"` PipelineJobs created or updated
  //   after 2020-05-18 00:00:00 UTC.
  // * `labels.env = "prod"`
  //   PipelineJobs with label "env" set to "prod".
  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 the 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"
    }
  ];
}

// Request message for [PipelineService.CreatePipelineJob][google.cloud.aiplatform.v1beta1.PipelineService.CreatePipelineJob].
message CreatePipelineJobRequest {
  // Required. The resource name of the Location to create the PipelineJob 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 PipelineJob to create.
  PipelineJob pipeline_job = 2 [(google.api.field_behavior) = REQUIRED];

  // The ID to use for the PipelineJob, which will become the final component of
  // the PipelineJob name. If not provided, an ID will be automatically
  // generated.
  //
  // This value should be less than 128 characters, and valid characters
  // are /[a-z][0-9]-/.
  string pipeline_job_id = 3;
}

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

// Request message for [PipelineService.ListPipelineJobs][google.cloud.aiplatform.v1beta1.PipelineService.ListPipelineJobs].
message ListPipelineJobsRequest {
  // Required. The resource name of the Location to list the PipelineJobs 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 `!=`.
  //
  // The following examples demonstrate how to filter the list of PipelineJobs:
  //
  // * `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
  // [ListPipelineJobsResponse.next_page_token][google.cloud.aiplatform.v1beta1.ListPipelineJobsResponse.next_page_token] of the previous
  // [PipelineService.ListPipelineJobs][google.cloud.aiplatform.v1beta1.PipelineService.ListPipelineJobs] call.
  string page_token = 4;
}

// Response message for [PipelineService.ListPipelineJobs][google.cloud.aiplatform.v1beta1.PipelineService.ListPipelineJobs]
message ListPipelineJobsResponse {
  // List of PipelineJobs in the requested page.
  repeated PipelineJob pipeline_jobs = 1;

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

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

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