// 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.clouddms.v1;

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

option csharp_namespace = "Google.Cloud.CloudDms.V1";
option go_package = "cloud.google.com/go/clouddms/apiv1/clouddmspb;clouddmspb";
option java_multiple_files = true;
option java_outer_classname = "ClouddmsProto";
option java_package = "com.google.cloud.clouddms.v1";
option php_namespace = "Google\\Cloud\\CloudDms\\V1";
option ruby_package = "Google::Cloud::CloudDMS::V1";

// Database Migration service
service DataMigrationService {
  option (google.api.default_host) = "datamigration.googleapis.com";
  option (google.api.oauth_scopes) = "https://www.googleapis.com/auth/cloud-platform";

  // Lists migration jobs in a given project and location.
  rpc ListMigrationJobs(ListMigrationJobsRequest) returns (ListMigrationJobsResponse) {
    option (google.api.http) = {
      get: "/v1/{parent=projects/*/locations/*}/migrationJobs"
    };
    option (google.api.method_signature) = "parent";
  }

  // Gets details of a single migration job.
  rpc GetMigrationJob(GetMigrationJobRequest) returns (MigrationJob) {
    option (google.api.http) = {
      get: "/v1/{name=projects/*/locations/*/migrationJobs/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // Creates a new migration job in a given project and location.
  rpc CreateMigrationJob(CreateMigrationJobRequest) returns (google.longrunning.Operation) {
    option (google.api.http) = {
      post: "/v1/{parent=projects/*/locations/*}/migrationJobs"
      body: "migration_job"
    };
    option (google.api.method_signature) = "parent,migration_job,migration_job_id";
    option (google.longrunning.operation_info) = {
      response_type: "MigrationJob"
      metadata_type: "OperationMetadata"
    };
  }

  // Updates the parameters of a single migration job.
  rpc UpdateMigrationJob(UpdateMigrationJobRequest) returns (google.longrunning.Operation) {
    option (google.api.http) = {
      patch: "/v1/{migration_job.name=projects/*/locations/*/migrationJobs/*}"
      body: "migration_job"
    };
    option (google.api.method_signature) = "migration_job,update_mask";
    option (google.longrunning.operation_info) = {
      response_type: "MigrationJob"
      metadata_type: "OperationMetadata"
    };
  }

  // Deletes a single migration job.
  rpc DeleteMigrationJob(DeleteMigrationJobRequest) returns (google.longrunning.Operation) {
    option (google.api.http) = {
      delete: "/v1/{name=projects/*/locations/*/migrationJobs/*}"
    };
    option (google.api.method_signature) = "name";
    option (google.longrunning.operation_info) = {
      response_type: "google.protobuf.Empty"
      metadata_type: "OperationMetadata"
    };
  }

  // Start an already created migration job.
  rpc StartMigrationJob(StartMigrationJobRequest) returns (google.longrunning.Operation) {
    option (google.api.http) = {
      post: "/v1/{name=projects/*/locations/*/migrationJobs/*}:start"
      body: "*"
    };
    option (google.longrunning.operation_info) = {
      response_type: "MigrationJob"
      metadata_type: "OperationMetadata"
    };
  }

  // Stops a running migration job.
  rpc StopMigrationJob(StopMigrationJobRequest) returns (google.longrunning.Operation) {
    option (google.api.http) = {
      post: "/v1/{name=projects/*/locations/*/migrationJobs/*}:stop"
      body: "*"
    };
    option (google.longrunning.operation_info) = {
      response_type: "MigrationJob"
      metadata_type: "OperationMetadata"
    };
  }

  // Resume a migration job that is currently stopped and is resumable (was
  // stopped during CDC phase).
  rpc ResumeMigrationJob(ResumeMigrationJobRequest) returns (google.longrunning.Operation) {
    option (google.api.http) = {
      post: "/v1/{name=projects/*/locations/*/migrationJobs/*}:resume"
      body: "*"
    };
    option (google.longrunning.operation_info) = {
      response_type: "MigrationJob"
      metadata_type: "OperationMetadata"
    };
  }

  // Promote a migration job, stopping replication to the destination and
  // promoting the destination to be a standalone database.
  rpc PromoteMigrationJob(PromoteMigrationJobRequest) returns (google.longrunning.Operation) {
    option (google.api.http) = {
      post: "/v1/{name=projects/*/locations/*/migrationJobs/*}:promote"
      body: "*"
    };
    option (google.longrunning.operation_info) = {
      response_type: "MigrationJob"
      metadata_type: "OperationMetadata"
    };
  }

  // Verify a migration job, making sure the destination can reach the source
  // and that all configuration and prerequisites are met.
  rpc VerifyMigrationJob(VerifyMigrationJobRequest) returns (google.longrunning.Operation) {
    option (google.api.http) = {
      post: "/v1/{name=projects/*/locations/*/migrationJobs/*}:verify"
      body: "*"
    };
    option (google.longrunning.operation_info) = {
      response_type: "MigrationJob"
      metadata_type: "OperationMetadata"
    };
  }

  // Restart a stopped or failed migration job, resetting the destination
  // instance to its original state and starting the migration process from
  // scratch.
  rpc RestartMigrationJob(RestartMigrationJobRequest) returns (google.longrunning.Operation) {
    option (google.api.http) = {
      post: "/v1/{name=projects/*/locations/*/migrationJobs/*}:restart"
      body: "*"
    };
    option (google.longrunning.operation_info) = {
      response_type: "MigrationJob"
      metadata_type: "OperationMetadata"
    };
  }

  // Generate a SSH configuration script to configure the reverse SSH
  // connectivity.
  rpc GenerateSshScript(GenerateSshScriptRequest) returns (SshScript) {
    option (google.api.http) = {
      post: "/v1/{migration_job=projects/*/locations/*/migrationJobs/*}:generateSshScript"
      body: "*"
    };
  }

  // Retrieve a list of all connection profiles in a given project and location.
  rpc ListConnectionProfiles(ListConnectionProfilesRequest) returns (ListConnectionProfilesResponse) {
    option (google.api.http) = {
      get: "/v1/{parent=projects/*/locations/*}/connectionProfiles"
    };
    option (google.api.method_signature) = "parent";
  }

  // Gets details of a single connection profile.
  rpc GetConnectionProfile(GetConnectionProfileRequest) returns (ConnectionProfile) {
    option (google.api.http) = {
      get: "/v1/{name=projects/*/locations/*/connectionProfiles/*}"
    };
    option (google.api.method_signature) = "name";
  }

  // Creates a new connection profile in a given project and location.
  rpc CreateConnectionProfile(CreateConnectionProfileRequest) returns (google.longrunning.Operation) {
    option (google.api.http) = {
      post: "/v1/{parent=projects/*/locations/*}/connectionProfiles"
      body: "connection_profile"
    };
    option (google.api.method_signature) = "parent,connection_profile,connection_profile_id";
    option (google.longrunning.operation_info) = {
      response_type: "ConnectionProfile"
      metadata_type: "OperationMetadata"
    };
  }

  // Update the configuration of a single connection profile.
  rpc UpdateConnectionProfile(UpdateConnectionProfileRequest) returns (google.longrunning.Operation) {
    option (google.api.http) = {
      patch: "/v1/{connection_profile.name=projects/*/locations/*/connectionProfiles/*}"
      body: "connection_profile"
    };
    option (google.api.method_signature) = "connection_profile,update_mask";
    option (google.longrunning.operation_info) = {
      response_type: "ConnectionProfile"
      metadata_type: "OperationMetadata"
    };
  }

  // Deletes a single Database Migration Service connection profile.
  // A connection profile can only be deleted if it is not in use by any
  // active migration jobs.
  rpc DeleteConnectionProfile(DeleteConnectionProfileRequest) returns (google.longrunning.Operation) {
    option (google.api.http) = {
      delete: "/v1/{name=projects/*/locations/*/connectionProfiles/*}"
    };
    option (google.api.method_signature) = "name";
    option (google.longrunning.operation_info) = {
      response_type: "google.protobuf.Empty"
      metadata_type: "OperationMetadata"
    };
  }
}

// Retrieve a list of all migration jobs in a given project and location.
message ListMigrationJobsRequest {
  // Required. The parent, which owns this collection of migrationJobs.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "datamigration.googleapis.com/MigrationJob"
    }
  ];

  // The maximum number of migration jobs to return. The service may return
  // fewer than this value. If unspecified, at most 50 migration jobs will be
  // returned. The maximum value is 1000; values above 1000 will be coerced to
  // 1000.
  int32 page_size = 2;

  // The nextPageToken value received in the previous call to
  // migrationJobs.list, used in the subsequent request to retrieve the next
  // page of results. On first call this should be left blank. When paginating,
  // all other parameters provided to migrationJobs.list must match the call
  // that provided the page token.
  string page_token = 3;

  // A filter expression that filters migration jobs listed in the response.
  // The expression must specify the field name, a comparison operator, and the
  // value that you want to use for filtering. The value must be a string,
  // a number, or a boolean. The comparison operator must be
  // either =, !=, >, or <. For example, list migration jobs created this year
  // by specifying **createTime %gt; 2020-01-01T00:00:00.000000000Z.**
  // You can also filter nested fields. For example, you could specify
  // **reverseSshConnectivity.vmIp = "1.2.3.4"** to select all migration
  // jobs connecting through the specific SSH tunnel bastion.
  string filter = 4;

  // Sort the results based on the migration job name.
  // Valid values are: "name", "name asc", and "name desc".
  string order_by = 5;
}

// Response message for 'ListMigrationJobs' request.
message ListMigrationJobsResponse {
  // The list of migration jobs objects.
  repeated MigrationJob migration_jobs = 1;

  // A token, which can be sent as `page_token` to retrieve the next page.
  // If this field is omitted, there are no subsequent pages.
  string next_page_token = 2;

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

// Request message for 'GetMigrationJob' request.
message GetMigrationJobRequest {
  // Required. Name of the migration job resource to get.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "datamigration.googleapis.com/MigrationJob"
    }
  ];
}

// Request message to create a new Database Migration Service migration job
// in the specified project and region.
message CreateMigrationJobRequest {
  // Required. The parent, which owns this collection of migration jobs.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "datamigration.googleapis.com/MigrationJob"
    }
  ];

  // Required. The ID of the instance to create.
  string migration_job_id = 2 [(google.api.field_behavior) = REQUIRED];

  // Required. Represents a [migration
  // job](https://cloud.google.com/database-migration/docs/reference/rest/v1/projects.locations.migrationJobs)
  // object.
  MigrationJob migration_job = 3 [(google.api.field_behavior) = REQUIRED];

  // A unique id used to identify the request. If the server receives two
  // requests with the same id, then the second request will be ignored.
  //
  // It is recommended to always set this value to a UUID.
  //
  // The id must contain only letters (a-z, A-Z), numbers (0-9), underscores
  // (_), and hyphens (-). The maximum length is 40 characters.
  string request_id = 4;
}

// Request message for 'UpdateMigrationJob' request.
message UpdateMigrationJobRequest {
  // Required. Field mask is used to specify the fields to be overwritten in the
  // migration job resource by the update.
  google.protobuf.FieldMask update_mask = 1 [(google.api.field_behavior) = REQUIRED];

  // Required. The migration job parameters to update.
  MigrationJob migration_job = 2 [(google.api.field_behavior) = REQUIRED];

  // A unique id used to identify the request. If the server receives two
  // requests with the same id, then the second request will be ignored.
  //
  // It is recommended to always set this value to a UUID.
  //
  // The id must contain only letters (a-z, A-Z), numbers (0-9), underscores
  // (_), and hyphens (-). The maximum length is 40 characters.
  string request_id = 3;
}

// Request message for 'DeleteMigrationJob' request.
message DeleteMigrationJobRequest {
  // Required. Name of the migration job resource to delete.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "datamigration.googleapis.com/MigrationJob"
    }
  ];

  // A unique id used to identify the request. If the server receives two
  // requests with the same id, then the second request will be ignored.
  //
  // It is recommended to always set this value to a UUID.
  //
  // The id must contain only letters (a-z, A-Z), numbers (0-9), underscores
  // (_), and hyphens (-). The maximum length is 40 characters.
  string request_id = 2;

  // The destination CloudSQL connection profile is always deleted with the
  // migration job. In case of force delete, the destination CloudSQL replica
  // database is also deleted.
  bool force = 3;
}

// Request message for 'StartMigrationJob' request.
message StartMigrationJobRequest {
  // Name of the migration job resource to start.
  string name = 1 [(google.api.resource_reference) = {
                     type: "datamigration.googleapis.com/MigrationJob"
                   }];
}

// Request message for 'StopMigrationJob' request.
message StopMigrationJobRequest {
  // Name of the migration job resource to stop.
  string name = 1 [(google.api.resource_reference) = {
                     type: "datamigration.googleapis.com/MigrationJob"
                   }];
}

// Request message for 'ResumeMigrationJob' request.
message ResumeMigrationJobRequest {
  // Name of the migration job resource to resume.
  string name = 1 [(google.api.resource_reference) = {
                     type: "datamigration.googleapis.com/MigrationJob"
                   }];
}

// Request message for 'PromoteMigrationJob' request.
message PromoteMigrationJobRequest {
  // Name of the migration job resource to promote.
  string name = 1 [(google.api.resource_reference) = {
                     type: "datamigration.googleapis.com/MigrationJob"
                   }];
}

// Request message for 'VerifyMigrationJob' request.
message VerifyMigrationJobRequest {
  // Name of the migration job resource to verify.
  string name = 1 [(google.api.resource_reference) = {
                     type: "datamigration.googleapis.com/MigrationJob"
                   }];
}

// Request message for 'RestartMigrationJob' request.
message RestartMigrationJobRequest {
  // Name of the migration job resource to restart.
  string name = 1 [(google.api.resource_reference) = {
                     type: "datamigration.googleapis.com/MigrationJob"
                   }];
}

// Request message for 'GenerateSshScript' request.
message GenerateSshScriptRequest {
  // Name of the migration job resource to generate the SSH script.
  string migration_job = 1 [(google.api.resource_reference) = {
                              type: "datamigration.googleapis.com/MigrationJob"
                            }];

  // Required. Bastion VM Instance name to use or to create.
  string vm = 2 [(google.api.field_behavior) = REQUIRED];

  // The VM configuration
  oneof vm_config {
    // The VM creation configuration
    VmCreationConfig vm_creation_config = 100;

    // The VM selection configuration
    VmSelectionConfig vm_selection_config = 101;
  }

  // The port that will be open on the bastion host
  int32 vm_port = 3;
}

// VM creation configuration message
message VmCreationConfig {
  // Required. VM instance machine type to create.
  string vm_machine_type = 1 [(google.api.field_behavior) = REQUIRED];

  // The Google Cloud Platform zone to create the VM in.
  string vm_zone = 2;

  // The subnet name the vm needs to be created in.
  string subnet = 3;
}

// VM selection configuration message
message VmSelectionConfig {
  // Required. The Google Cloud Platform zone the VM is located.
  string vm_zone = 1 [(google.api.field_behavior) = REQUIRED];
}

// Response message for 'GenerateSshScript' request.
message SshScript {
  // The ssh configuration script.
  string script = 1;
}

// Request message for 'ListConnectionProfiles' request.
message ListConnectionProfilesRequest {
  // Required. The parent, which owns this collection of connection profiles.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      child_type: "datamigration.googleapis.com/ConnectionProfile"
    }
  ];

  // The maximum number of connection profiles to return. The service may return
  // fewer than this value. If unspecified, at most 50 connection profiles will
  // be returned. The maximum value is 1000; values above 1000 will be coerced
  // to 1000.
  int32 page_size = 2;

  // A page token, received from a previous `ListConnectionProfiles` call.
  // Provide this to retrieve the subsequent page.
  //
  // When paginating, all other parameters provided to `ListConnectionProfiles`
  // must match the call that provided the page token.
  string page_token = 3;

  // A filter expression that filters connection profiles listed in the
  // response. The expression must specify the field name, a comparison
  // operator, and the value that you want to use for filtering. The value must
  // be a string, a number, or a boolean. The comparison operator must be either
  // =, !=, >, or <. For example, list connection profiles created this year by
  // specifying **createTime %gt; 2020-01-01T00:00:00.000000000Z**. You can
  // also filter nested fields. For example, you could specify **mySql.username
  // = %lt;my_username%gt;** to list all connection profiles configured to
  // connect with a specific username.
  string filter = 4;

  // the order by fields for the result.
  string order_by = 5;
}

// Response message for 'ListConnectionProfiles' request.
message ListConnectionProfilesResponse {
  // The response list of connection profiles.
  repeated ConnectionProfile connection_profiles = 1;

  // A token, which can be sent as `page_token` to retrieve the next page.
  // If this field is omitted, there are no subsequent pages.
  string next_page_token = 2;

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

// Request message for 'GetConnectionProfile' request.
message GetConnectionProfileRequest {
  // Required. Name of the connection profile resource to get.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "datamigration.googleapis.com/ConnectionProfile"
    }
  ];
}

// Request message for 'CreateConnectionProfile' request.
message CreateConnectionProfileRequest {
  // Required. The parent, which owns this collection of connection profiles.
  string parent = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "datamigration.googleapis.com/ConnectionProfile"
    }
  ];

  // Required. The connection profile identifier.
  string connection_profile_id = 2 [(google.api.field_behavior) = REQUIRED];

  // Required. The create request body including the connection profile data
  ConnectionProfile connection_profile = 3 [(google.api.field_behavior) = REQUIRED];

  // A unique id used to identify the request. If the server receives two
  // requests with the same id, then the second request will be ignored.
  //
  // It is recommended to always set this value to a UUID.
  //
  // The id must contain only letters (a-z, A-Z), numbers (0-9), underscores
  // (_), and hyphens (-). The maximum length is 40 characters.
  string request_id = 4;
}

// Request message for 'UpdateConnectionProfile' request.
message UpdateConnectionProfileRequest {
  // Required. Field mask is used to specify the fields to be overwritten in the
  // connection profile resource by the update.
  google.protobuf.FieldMask update_mask = 1 [(google.api.field_behavior) = REQUIRED];

  // Required. The connection profile parameters to update.
  ConnectionProfile connection_profile = 2 [(google.api.field_behavior) = REQUIRED];

  // A unique id used to identify the request. If the server receives two
  // requests with the same id, then the second request will be ignored.
  //
  // It is recommended to always set this value to a UUID.
  //
  // The id must contain only letters (a-z, A-Z), numbers (0-9), underscores
  // (_), and hyphens (-). The maximum length is 40 characters.
  string request_id = 3;
}

// Request message for 'DeleteConnectionProfile' request.
message DeleteConnectionProfileRequest {
  // Required. Name of the connection profile resource to delete.
  string name = 1 [
    (google.api.field_behavior) = REQUIRED,
    (google.api.resource_reference) = {
      type: "datamigration.googleapis.com/ConnectionProfile"
    }
  ];

  // A unique id used to identify the request. If the server receives two
  // requests with the same id, then the second request will be ignored.
  //
  // It is recommended to always set this value to a UUID.
  //
  // The id must contain only letters (a-z, A-Z), numbers (0-9), underscores
  // (_), and hyphens (-). The maximum length is 40 characters.
  string request_id = 2;

  // In case of force delete, the CloudSQL replica database is also deleted
  // (only for CloudSQL connection profile).
  bool force = 3;
}

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

  // Output only. The time 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_message = 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 requested_cancellation = 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];
}
