diff --git a/ci/etc/expected_install_directories b/ci/etc/expected_install_directories index 0b0c89ae1b880..806b9c9be7af9 100644 --- a/ci/etc/expected_install_directories +++ b/ci/etc/expected_install_directories @@ -82,6 +82,8 @@ ./include/google/cloud/bigquery/datatransfer ./include/google/cloud/bigquery/datatransfer/v1 ./include/google/cloud/bigquery/internal +./include/google/cloud/bigquery/migration +./include/google/cloud/bigquery/migration/v2 ./include/google/cloud/bigquery/mocks ./include/google/cloud/bigquery/reservation ./include/google/cloud/bigquery/reservation/v1 diff --git a/external/googleapis/protodeps/bigquery.deps b/external/googleapis/protodeps/bigquery.deps index 69dbd0b02f272..ac643641dccba 100644 --- a/external/googleapis/protodeps/bigquery.deps +++ b/external/googleapis/protodeps/bigquery.deps @@ -1,10 +1,15 @@ @com_google_googleapis//google/api:annotations_proto @com_google_googleapis//google/api:client_proto +@com_google_googleapis//google/api:distribution_proto @com_google_googleapis//google/api:field_behavior_proto @com_google_googleapis//google/api:http_proto +@com_google_googleapis//google/api:label_proto +@com_google_googleapis//google/api:launch_stage_proto +@com_google_googleapis//google/api:metric_proto @com_google_googleapis//google/api:resource_proto @com_google_googleapis//google/iam/v1:iam_policy_proto @com_google_googleapis//google/iam/v1:options_proto @com_google_googleapis//google/iam/v1:policy_proto +@com_google_googleapis//google/rpc:error_details_proto @com_google_googleapis//google/rpc:status_proto @com_google_googleapis//google/type:expr_proto diff --git a/external/googleapis/protolists/bigquery.list b/external/googleapis/protolists/bigquery.list index b185e09cadaf0..3f6f774e36b40 100644 --- a/external/googleapis/protolists/bigquery.list +++ b/external/googleapis/protolists/bigquery.list @@ -3,6 +3,11 @@ @com_google_googleapis//google/cloud/bigquery/datatransfer/v1:datatransfer.proto @com_google_googleapis//google/cloud/bigquery/datatransfer/v1:transfer.proto @com_google_googleapis//google/cloud/bigquery/logging/v1:audit_data.proto +@com_google_googleapis//google/cloud/bigquery/migration/v2:migration_entities.proto +@com_google_googleapis//google/cloud/bigquery/migration/v2:migration_error_details.proto +@com_google_googleapis//google/cloud/bigquery/migration/v2:migration_metrics.proto +@com_google_googleapis//google/cloud/bigquery/migration/v2:migration_service.proto +@com_google_googleapis//google/cloud/bigquery/migration/v2:translation_config.proto @com_google_googleapis//google/cloud/bigquery/reservation/v1:reservation.proto @com_google_googleapis//google/cloud/bigquery/storage/v1:annotations.proto @com_google_googleapis//google/cloud/bigquery/storage/v1:arrow.proto diff --git a/external/googleapis/update_libraries.sh b/external/googleapis/update_libraries.sh index bebb3826ebfe7..05ef0e8d273a9 100755 --- a/external/googleapis/update_libraries.sh +++ b/external/googleapis/update_libraries.sh @@ -46,14 +46,16 @@ declare -A -r LIBRARIES=( "@com_google_googleapis//google/cloud/beyondcorp/clientgateways/v1:clientgateways_cc_grpc" )" ["bigquery"]="$( + # This is long enough that it needs to be kept in alphabetical order printf ",%s" \ - "@com_google_googleapis//google/cloud/bigquery/v2:bigquery_cc_grpc" \ - "@com_google_googleapis//google/cloud/bigquery/storage/v1:storage_cc_grpc" \ - "@com_google_googleapis//google/cloud/bigquery/reservation/v1:reservation_cc_grpc" \ - "@com_google_googleapis//google/cloud/bigquery/logging/v1:logging_cc_grpc" \ - "@com_google_googleapis//google/cloud/bigquery/datatransfer/v1:datatransfer_cc_grpc" \ + "@com_google_googleapis//google/cloud/bigquery/analyticshub/v1:analyticshub_cc_grpc" \ "@com_google_googleapis//google/cloud/bigquery/connection/v1:connection_cc_grpc" \ - "@com_google_googleapis//google/cloud/bigquery/analyticshub/v1:analyticshub_cc_grpc" + "@com_google_googleapis//google/cloud/bigquery/datatransfer/v1:datatransfer_cc_grpc" \ + "@com_google_googleapis//google/cloud/bigquery/logging/v1:logging_cc_grpc" \ + "@com_google_googleapis//google/cloud/bigquery/migration/v2:migration_cc_grpc" \ + "@com_google_googleapis//google/cloud/bigquery/reservation/v1:reservation_cc_grpc" \ + "@com_google_googleapis//google/cloud/bigquery/storage/v1:storage_cc_grpc" \ + "@com_google_googleapis//google/cloud/bigquery/v2:bigquery_cc_grpc" )" ["bigtable"]="$( printf ",%s" \ diff --git a/generator/generator_config.textproto b/generator/generator_config.textproto index 6aa549937b1cd..1ad9ab11ee64e 100644 --- a/generator/generator_config.textproto +++ b/generator/generator_config.textproto @@ -159,53 +159,60 @@ service { # BigQuery service { - service_proto_path: "google/cloud/bigquery/storage/v1/storage.proto" + service_proto_path: "google/cloud/bigquery/analyticshub/v1/analyticshub.proto" product_path: "google/cloud/bigquery" - initial_copyright_year: "2021" - omitted_services: ["BigQueryWrite"] - backwards_compatibility_namespace_alias: true + initial_copyright_year: "2022" retryable_status_codes: ["kUnavailable"] } service { - service_proto_path: "google/cloud/bigquery/storage/v1/storage.proto" + service_proto_path: "google/cloud/bigquery/connection/v1/connection.proto" product_path: "google/cloud/bigquery" initial_copyright_year: "2022" - omitted_services: ["BigQueryRead"] + service_endpoint_env_var: "GOOGLE_CLOUD_CPP_BIGQUERY_CONNECTION_SERVICE_ENDPOINT" retryable_status_codes: ["kUnavailable"] } service { - service_proto_path: "google/cloud/bigquery/connection/v1/connection.proto" + service_proto_path: "google/cloud/bigquery/datatransfer/v1/datatransfer.proto" product_path: "google/cloud/bigquery" initial_copyright_year: "2022" - service_endpoint_env_var: "GOOGLE_CLOUD_CPP_BIGQUERY_CONNECTION_SERVICE_ENDPOINT" retryable_status_codes: ["kUnavailable"] } service { - service_proto_path: "google/cloud/bigquery/reservation/v1/reservation.proto" + service_proto_path: "google/cloud/bigquery/migration/v2/migration_service.proto" product_path: "google/cloud/bigquery" initial_copyright_year: "2022" retryable_status_codes: ["kUnavailable"] } service { - service_proto_path: "google/cloud/bigquery/datatransfer/v1/datatransfer.proto" + service_proto_path: "google/cloud/bigquery/reservation/v1/reservation.proto" product_path: "google/cloud/bigquery" initial_copyright_year: "2022" retryable_status_codes: ["kUnavailable"] } service { - service_proto_path: "google/cloud/bigquery/v2/model.proto" + service_proto_path: "google/cloud/bigquery/storage/v1/storage.proto" + product_path: "google/cloud/bigquery" + initial_copyright_year: "2021" + omitted_services: ["BigQueryWrite"] + backwards_compatibility_namespace_alias: true + retryable_status_codes: ["kUnavailable"] +} + +service { + service_proto_path: "google/cloud/bigquery/storage/v1/storage.proto" product_path: "google/cloud/bigquery" initial_copyright_year: "2022" + omitted_services: ["BigQueryRead"] retryable_status_codes: ["kUnavailable"] } service { - service_proto_path: "google/cloud/bigquery/analyticshub/v1/analyticshub.proto" + service_proto_path: "google/cloud/bigquery/v2/model.proto" product_path: "google/cloud/bigquery" initial_copyright_year: "2022" retryable_status_codes: ["kUnavailable"] diff --git a/google/cloud/bigquery/BUILD.bazel b/google/cloud/bigquery/BUILD.bazel index 2807f6e540794..f4fe1506aa80d 100644 --- a/google/cloud/bigquery/BUILD.bazel +++ b/google/cloud/bigquery/BUILD.bazel @@ -30,6 +30,7 @@ cc_library( "@com_google_googleapis//google/cloud/bigquery/connection/v1:connection_cc_grpc", "@com_google_googleapis//google/cloud/bigquery/datatransfer/v1:datatransfer_cc_grpc", "@com_google_googleapis//google/cloud/bigquery/logging/v1:logging_cc_grpc", + "@com_google_googleapis//google/cloud/bigquery/migration/v2:migration_cc_grpc", "@com_google_googleapis//google/cloud/bigquery/reservation/v1:reservation_cc_grpc", "@com_google_googleapis//google/cloud/bigquery/storage/v1:storage_cc_grpc", "@com_google_googleapis//google/cloud/bigquery/v2:bigquery_cc_grpc", diff --git a/google/cloud/bigquery/CMakeLists.txt b/google/cloud/bigquery/CMakeLists.txt index 8c797a06926c2..1a9db79dab10c 100644 --- a/google/cloud/bigquery/CMakeLists.txt +++ b/google/cloud/bigquery/CMakeLists.txt @@ -28,165 +28,12 @@ set(GOOGLE_CLOUD_CPP_DOXYGEN_DEPS google-cloud-cpp::cloud_bigquery_protos) include(GoogleCloudCppCommon) -# configure_file(version_info.h.in ${CMAKE_CURRENT_SOURCE_DIR}/version_info.h) -add_library( - google_cloud_cpp_bigquery # cmake-format: sort - analytics_hub_client.cc - analytics_hub_client.h - analytics_hub_connection.cc - analytics_hub_connection.h - analytics_hub_connection_idempotency_policy.cc - analytics_hub_connection_idempotency_policy.h - analytics_hub_options.h - bigquery_read_client.cc - bigquery_read_client.h - bigquery_read_connection.cc - bigquery_read_connection.h - bigquery_read_connection_idempotency_policy.cc - bigquery_read_connection_idempotency_policy.h - bigquery_read_options.h - bigquery_write_client.cc - bigquery_write_client.h - bigquery_write_connection.cc - bigquery_write_connection.h - bigquery_write_connection_idempotency_policy.cc - bigquery_write_connection_idempotency_policy.h - bigquery_write_options.h - connection_client.cc - connection_client.h - connection_connection.cc - connection_connection.h - connection_connection_idempotency_policy.cc - connection_connection_idempotency_policy.h - connection_options.h - data_transfer_client.cc - data_transfer_client.h - data_transfer_connection.cc - data_transfer_connection.h - data_transfer_connection_idempotency_policy.cc - data_transfer_connection_idempotency_policy.h - data_transfer_options.h - internal/analytics_hub_auth_decorator.cc - internal/analytics_hub_auth_decorator.h - internal/analytics_hub_connection_impl.cc - internal/analytics_hub_connection_impl.h - internal/analytics_hub_logging_decorator.cc - internal/analytics_hub_logging_decorator.h - internal/analytics_hub_metadata_decorator.cc - internal/analytics_hub_metadata_decorator.h - internal/analytics_hub_option_defaults.cc - internal/analytics_hub_option_defaults.h - internal/analytics_hub_retry_traits.h - internal/analytics_hub_stub.cc - internal/analytics_hub_stub.h - internal/analytics_hub_stub_factory.cc - internal/analytics_hub_stub_factory.h - internal/bigquery_read_auth_decorator.cc - internal/bigquery_read_auth_decorator.h - internal/bigquery_read_connection_impl.cc - internal/bigquery_read_connection_impl.h - internal/bigquery_read_logging_decorator.cc - internal/bigquery_read_logging_decorator.h - internal/bigquery_read_metadata_decorator.cc - internal/bigquery_read_metadata_decorator.h - internal/bigquery_read_option_defaults.cc - internal/bigquery_read_option_defaults.h - internal/bigquery_read_retry_traits.h - internal/bigquery_read_stub.cc - internal/bigquery_read_stub.h - internal/bigquery_read_stub_factory.cc - internal/bigquery_read_stub_factory.h - internal/bigquery_write_auth_decorator.cc - internal/bigquery_write_auth_decorator.h - internal/bigquery_write_connection_impl.cc - internal/bigquery_write_connection_impl.h - internal/bigquery_write_logging_decorator.cc - internal/bigquery_write_logging_decorator.h - internal/bigquery_write_metadata_decorator.cc - internal/bigquery_write_metadata_decorator.h - internal/bigquery_write_option_defaults.cc - internal/bigquery_write_option_defaults.h - internal/bigquery_write_retry_traits.h - internal/bigquery_write_stub.cc - internal/bigquery_write_stub.h - internal/bigquery_write_stub_factory.cc - internal/bigquery_write_stub_factory.h - internal/connection_auth_decorator.cc - internal/connection_auth_decorator.h - internal/connection_connection_impl.cc - internal/connection_connection_impl.h - internal/connection_logging_decorator.cc - internal/connection_logging_decorator.h - internal/connection_metadata_decorator.cc - internal/connection_metadata_decorator.h - internal/connection_option_defaults.cc - internal/connection_option_defaults.h - internal/connection_retry_traits.h - internal/connection_stub.cc - internal/connection_stub.h - internal/connection_stub_factory.cc - internal/connection_stub_factory.h - internal/data_transfer_auth_decorator.cc - internal/data_transfer_auth_decorator.h - internal/data_transfer_connection_impl.cc - internal/data_transfer_connection_impl.h - internal/data_transfer_logging_decorator.cc - internal/data_transfer_logging_decorator.h - internal/data_transfer_metadata_decorator.cc - internal/data_transfer_metadata_decorator.h - internal/data_transfer_option_defaults.cc - internal/data_transfer_option_defaults.h - internal/data_transfer_retry_traits.h - internal/data_transfer_stub.cc - internal/data_transfer_stub.h - internal/data_transfer_stub_factory.cc - internal/data_transfer_stub_factory.h - internal/model_auth_decorator.cc - internal/model_auth_decorator.h - internal/model_connection_impl.cc - internal/model_connection_impl.h - internal/model_logging_decorator.cc - internal/model_logging_decorator.h - internal/model_metadata_decorator.cc - internal/model_metadata_decorator.h - internal/model_option_defaults.cc - internal/model_option_defaults.h - internal/model_retry_traits.h - internal/model_stub.cc - internal/model_stub.h - internal/model_stub_factory.cc - internal/model_stub_factory.h - internal/reservation_auth_decorator.cc - internal/reservation_auth_decorator.h - internal/reservation_connection_impl.cc - internal/reservation_connection_impl.h - internal/reservation_logging_decorator.cc - internal/reservation_logging_decorator.h - internal/reservation_metadata_decorator.cc - internal/reservation_metadata_decorator.h - internal/reservation_option_defaults.cc - internal/reservation_option_defaults.h - internal/reservation_retry_traits.h - internal/reservation_stub.cc - internal/reservation_stub.h - internal/reservation_stub_factory.cc - internal/reservation_stub_factory.h - internal/streaming.cc - model_client.cc - model_client.h - model_connection.cc - model_connection.h - model_connection_idempotency_policy.cc - model_connection_idempotency_policy.h - model_options.h - reservation_client.cc - reservation_client.h - reservation_connection.cc - reservation_connection.h - reservation_connection_idempotency_policy.cc - reservation_connection_idempotency_policy.h - reservation_options.h - retry_traits.h) +file( + GLOB source_files + RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" + "*.h" "*.cc" "internal/*.h" "internal/*.cc") +list(SORT source_files) +add_library(google_cloud_cpp_bigquery ${source_files}) target_include_directories( google_cloud_cpp_bigquery PUBLIC $ diff --git a/google/cloud/bigquery/google_cloud_cpp_bigquery.bzl b/google/cloud/bigquery/google_cloud_cpp_bigquery.bzl index a1cc5e075d658..2ee6a726430e7 100644 --- a/google/cloud/bigquery/google_cloud_cpp_bigquery.bzl +++ b/google/cloud/bigquery/google_cloud_cpp_bigquery.bzl @@ -77,6 +77,14 @@ google_cloud_cpp_bigquery_hdrs = [ "internal/data_transfer_retry_traits.h", "internal/data_transfer_stub.h", "internal/data_transfer_stub_factory.h", + "internal/migration_auth_decorator.h", + "internal/migration_connection_impl.h", + "internal/migration_logging_decorator.h", + "internal/migration_metadata_decorator.h", + "internal/migration_option_defaults.h", + "internal/migration_retry_traits.h", + "internal/migration_stub.h", + "internal/migration_stub_factory.h", "internal/model_auth_decorator.h", "internal/model_connection_impl.h", "internal/model_logging_decorator.h", @@ -93,6 +101,10 @@ google_cloud_cpp_bigquery_hdrs = [ "internal/reservation_retry_traits.h", "internal/reservation_stub.h", "internal/reservation_stub_factory.h", + "migration_client.h", + "migration_connection.h", + "migration_connection_idempotency_policy.h", + "migration_options.h", "model_client.h", "model_connection.h", "model_connection_idempotency_policy.h", @@ -155,6 +167,13 @@ google_cloud_cpp_bigquery_srcs = [ "internal/data_transfer_option_defaults.cc", "internal/data_transfer_stub.cc", "internal/data_transfer_stub_factory.cc", + "internal/migration_auth_decorator.cc", + "internal/migration_connection_impl.cc", + "internal/migration_logging_decorator.cc", + "internal/migration_metadata_decorator.cc", + "internal/migration_option_defaults.cc", + "internal/migration_stub.cc", + "internal/migration_stub_factory.cc", "internal/model_auth_decorator.cc", "internal/model_connection_impl.cc", "internal/model_logging_decorator.cc", @@ -170,6 +189,9 @@ google_cloud_cpp_bigquery_srcs = [ "internal/reservation_stub.cc", "internal/reservation_stub_factory.cc", "internal/streaming.cc", + "migration_client.cc", + "migration_connection.cc", + "migration_connection_idempotency_policy.cc", "model_client.cc", "model_connection.cc", "model_connection_idempotency_policy.cc", diff --git a/google/cloud/bigquery/internal/migration_auth_decorator.cc b/google/cloud/bigquery/internal/migration_auth_decorator.cc new file mode 100644 index 0000000000000..a62537e1af27c --- /dev/null +++ b/google/cloud/bigquery/internal/migration_auth_decorator.cc @@ -0,0 +1,104 @@ +// Copyright 2022 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 +// +// https://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. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/bigquery/migration/v2/migration_service.proto + +#include "google/cloud/bigquery/internal/migration_auth_decorator.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquery_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +MigrationServiceAuth::MigrationServiceAuth( + std::shared_ptr auth, + std::shared_ptr child) + : auth_(std::move(auth)), child_(std::move(child)) {} + +StatusOr +MigrationServiceAuth::CreateMigrationWorkflow( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + CreateMigrationWorkflowRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->CreateMigrationWorkflow(context, request); +} + +StatusOr +MigrationServiceAuth::GetMigrationWorkflow( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2::GetMigrationWorkflowRequest const& + request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->GetMigrationWorkflow(context, request); +} + +StatusOr +MigrationServiceAuth::ListMigrationWorkflows( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2::ListMigrationWorkflowsRequest const& + request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->ListMigrationWorkflows(context, request); +} + +Status MigrationServiceAuth::DeleteMigrationWorkflow( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + DeleteMigrationWorkflowRequest const& request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->DeleteMigrationWorkflow(context, request); +} + +Status MigrationServiceAuth::StartMigrationWorkflow( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2::StartMigrationWorkflowRequest const& + request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->StartMigrationWorkflow(context, request); +} + +StatusOr +MigrationServiceAuth::GetMigrationSubtask( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2::GetMigrationSubtaskRequest const& + request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->GetMigrationSubtask(context, request); +} + +StatusOr +MigrationServiceAuth::ListMigrationSubtasks( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2::ListMigrationSubtasksRequest const& + request) { + auto status = auth_->ConfigureContext(context); + if (!status.ok()) return status; + return child_->ListMigrationSubtasks(context, request); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquery_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquery/internal/migration_auth_decorator.h b/google/cloud/bigquery/internal/migration_auth_decorator.h new file mode 100644 index 0000000000000..7fa9f358311c6 --- /dev/null +++ b/google/cloud/bigquery/internal/migration_auth_decorator.h @@ -0,0 +1,93 @@ +// Copyright 2022 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 +// +// https://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. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/bigquery/migration/v2/migration_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_INTERNAL_MIGRATION_AUTH_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_INTERNAL_MIGRATION_AUTH_DECORATOR_H + +#include "google/cloud/bigquery/internal/migration_stub.h" +#include "google/cloud/internal/unified_grpc_credentials.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace bigquery_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class MigrationServiceAuth : public MigrationServiceStub { + public: + ~MigrationServiceAuth() override = default; + MigrationServiceAuth( + std::shared_ptr auth, + std::shared_ptr child); + + StatusOr + CreateMigrationWorkflow( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + CreateMigrationWorkflowRequest const& request) override; + + StatusOr + GetMigrationWorkflow( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2::GetMigrationWorkflowRequest const& + request) override; + + StatusOr< + google::cloud::bigquery::migration::v2::ListMigrationWorkflowsResponse> + ListMigrationWorkflows( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + ListMigrationWorkflowsRequest const& request) override; + + Status DeleteMigrationWorkflow( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + DeleteMigrationWorkflowRequest const& request) override; + + Status StartMigrationWorkflow( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + StartMigrationWorkflowRequest const& request) override; + + StatusOr + GetMigrationSubtask( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2::GetMigrationSubtaskRequest const& + request) override; + + StatusOr< + google::cloud::bigquery::migration::v2::ListMigrationSubtasksResponse> + ListMigrationSubtasks( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + ListMigrationSubtasksRequest const& request) override; + + private: + std::shared_ptr auth_; + std::shared_ptr child_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquery_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_INTERNAL_MIGRATION_AUTH_DECORATOR_H diff --git a/google/cloud/bigquery/internal/migration_connection_impl.cc b/google/cloud/bigquery/internal/migration_connection_impl.cc new file mode 100644 index 0000000000000..b3b912525646e --- /dev/null +++ b/google/cloud/bigquery/internal/migration_connection_impl.cc @@ -0,0 +1,190 @@ +// Copyright 2022 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 +// +// https://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. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/bigquery/migration/v2/migration_service.proto + +#include "google/cloud/bigquery/internal/migration_connection_impl.h" +#include "google/cloud/bigquery/internal/migration_option_defaults.h" +#include "google/cloud/background_threads.h" +#include "google/cloud/common_options.h" +#include "google/cloud/grpc_options.h" +#include "google/cloud/internal/pagination_range.h" +#include "google/cloud/internal/retry_loop.h" +#include + +namespace google { +namespace cloud { +namespace bigquery_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +MigrationServiceConnectionImpl::MigrationServiceConnectionImpl( + std::unique_ptr background, + std::shared_ptr stub, + Options options) + : background_(std::move(background)), + stub_(std::move(stub)), + options_(internal::MergeOptions(std::move(options), + MigrationServiceConnection::options())) {} + +StatusOr +MigrationServiceConnectionImpl::CreateMigrationWorkflow( + google::cloud::bigquery::migration::v2:: + CreateMigrationWorkflowRequest const& request) { + return google::cloud::internal::RetryLoop( + retry_policy(), backoff_policy(), + idempotency_policy()->CreateMigrationWorkflow(request), + [this](grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + CreateMigrationWorkflowRequest const& request) { + return stub_->CreateMigrationWorkflow(context, request); + }, + request, __func__); +} + +StatusOr +MigrationServiceConnectionImpl::GetMigrationWorkflow( + google::cloud::bigquery::migration::v2::GetMigrationWorkflowRequest const& + request) { + return google::cloud::internal::RetryLoop( + retry_policy(), backoff_policy(), + idempotency_policy()->GetMigrationWorkflow(request), + [this](grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + GetMigrationWorkflowRequest const& request) { + return stub_->GetMigrationWorkflow(context, request); + }, + request, __func__); +} + +StreamRange +MigrationServiceConnectionImpl::ListMigrationWorkflows( + google::cloud::bigquery::migration::v2::ListMigrationWorkflowsRequest + request) { + request.clear_page_token(); + auto& stub = stub_; + auto retry = std::shared_ptr( + retry_policy()); + auto backoff = std::shared_ptr(backoff_policy()); + auto idempotency = idempotency_policy()->ListMigrationWorkflows(request); + char const* function_name = __func__; + return google::cloud::internal::MakePaginationRange< + StreamRange>( + std::move(request), + [stub, retry, backoff, idempotency, + function_name](google::cloud::bigquery::migration::v2:: + ListMigrationWorkflowsRequest const& r) { + return google::cloud::internal::RetryLoop( + retry->clone(), backoff->clone(), idempotency, + [stub](grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + ListMigrationWorkflowsRequest const& request) { + return stub->ListMigrationWorkflows(context, request); + }, + r, function_name); + }, + [](google::cloud::bigquery::migration::v2::ListMigrationWorkflowsResponse + r) { + std::vector + result(r.migration_workflows().size()); + auto& messages = *r.mutable_migration_workflows(); + std::move(messages.begin(), messages.end(), result.begin()); + return result; + }); +} + +Status MigrationServiceConnectionImpl::DeleteMigrationWorkflow( + google::cloud::bigquery::migration::v2:: + DeleteMigrationWorkflowRequest const& request) { + return google::cloud::internal::RetryLoop( + retry_policy(), backoff_policy(), + idempotency_policy()->DeleteMigrationWorkflow(request), + [this](grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + DeleteMigrationWorkflowRequest const& request) { + return stub_->DeleteMigrationWorkflow(context, request); + }, + request, __func__); +} + +Status MigrationServiceConnectionImpl::StartMigrationWorkflow( + google::cloud::bigquery::migration::v2::StartMigrationWorkflowRequest const& + request) { + return google::cloud::internal::RetryLoop( + retry_policy(), backoff_policy(), + idempotency_policy()->StartMigrationWorkflow(request), + [this](grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + StartMigrationWorkflowRequest const& request) { + return stub_->StartMigrationWorkflow(context, request); + }, + request, __func__); +} + +StatusOr +MigrationServiceConnectionImpl::GetMigrationSubtask( + google::cloud::bigquery::migration::v2::GetMigrationSubtaskRequest const& + request) { + return google::cloud::internal::RetryLoop( + retry_policy(), backoff_policy(), + idempotency_policy()->GetMigrationSubtask(request), + [this](grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + GetMigrationSubtaskRequest const& request) { + return stub_->GetMigrationSubtask(context, request); + }, + request, __func__); +} + +StreamRange +MigrationServiceConnectionImpl::ListMigrationSubtasks( + google::cloud::bigquery::migration::v2::ListMigrationSubtasksRequest + request) { + request.clear_page_token(); + auto& stub = stub_; + auto retry = std::shared_ptr( + retry_policy()); + auto backoff = std::shared_ptr(backoff_policy()); + auto idempotency = idempotency_policy()->ListMigrationSubtasks(request); + char const* function_name = __func__; + return google::cloud::internal::MakePaginationRange< + StreamRange>( + std::move(request), + [stub, retry, backoff, idempotency, + function_name](google::cloud::bigquery::migration::v2:: + ListMigrationSubtasksRequest const& r) { + return google::cloud::internal::RetryLoop( + retry->clone(), backoff->clone(), idempotency, + [stub](grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + ListMigrationSubtasksRequest const& request) { + return stub->ListMigrationSubtasks(context, request); + }, + r, function_name); + }, + [](google::cloud::bigquery::migration::v2::ListMigrationSubtasksResponse + r) { + std::vector + result(r.migration_subtasks().size()); + auto& messages = *r.mutable_migration_subtasks(); + std::move(messages.begin(), messages.end(), result.begin()); + return result; + }); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquery_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquery/internal/migration_connection_impl.h b/google/cloud/bigquery/internal/migration_connection_impl.h new file mode 100644 index 0000000000000..12e04a68d743a --- /dev/null +++ b/google/cloud/bigquery/internal/migration_connection_impl.h @@ -0,0 +1,129 @@ +// Copyright 2022 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 +// +// https://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. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/bigquery/migration/v2/migration_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_INTERNAL_MIGRATION_CONNECTION_IMPL_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_INTERNAL_MIGRATION_CONNECTION_IMPL_H + +#include "google/cloud/bigquery/internal/migration_retry_traits.h" +#include "google/cloud/bigquery/internal/migration_stub.h" +#include "google/cloud/bigquery/migration_connection.h" +#include "google/cloud/bigquery/migration_connection_idempotency_policy.h" +#include "google/cloud/bigquery/migration_options.h" +#include "google/cloud/background_threads.h" +#include "google/cloud/backoff_policy.h" +#include "google/cloud/options.h" +#include "google/cloud/status_or.h" +#include "google/cloud/stream_range.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace bigquery_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class MigrationServiceConnectionImpl + : public bigquery::MigrationServiceConnection { + public: + ~MigrationServiceConnectionImpl() override = default; + + MigrationServiceConnectionImpl( + std::unique_ptr background, + std::shared_ptr stub, + Options options); + + Options options() override { return options_; } + + StatusOr + CreateMigrationWorkflow( + google::cloud::bigquery::migration::v2:: + CreateMigrationWorkflowRequest const& request) override; + + StatusOr + GetMigrationWorkflow( + google::cloud::bigquery::migration::v2::GetMigrationWorkflowRequest const& + request) override; + + StreamRange + ListMigrationWorkflows( + google::cloud::bigquery::migration::v2::ListMigrationWorkflowsRequest + request) override; + + Status DeleteMigrationWorkflow( + google::cloud::bigquery::migration::v2:: + DeleteMigrationWorkflowRequest const& request) override; + + Status StartMigrationWorkflow( + google::cloud::bigquery::migration::v2:: + StartMigrationWorkflowRequest const& request) override; + + StatusOr + GetMigrationSubtask( + google::cloud::bigquery::migration::v2::GetMigrationSubtaskRequest const& + request) override; + + StreamRange + ListMigrationSubtasks( + google::cloud::bigquery::migration::v2::ListMigrationSubtasksRequest + request) override; + + private: + std::unique_ptr retry_policy() { + auto const& options = internal::CurrentOptions(); + if (options.has()) { + return options.get() + ->clone(); + } + return options_.get()->clone(); + } + + std::unique_ptr backoff_policy() { + auto const& options = internal::CurrentOptions(); + if (options.has()) { + return options.get() + ->clone(); + } + return options_.get() + ->clone(); + } + + std::unique_ptr + idempotency_policy() { + auto const& options = internal::CurrentOptions(); + if (options.has< + bigquery::MigrationServiceConnectionIdempotencyPolicyOption>()) { + return options + .get() + ->clone(); + } + return options_ + .get() + ->clone(); + } + + std::unique_ptr background_; + std::shared_ptr stub_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquery_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_INTERNAL_MIGRATION_CONNECTION_IMPL_H diff --git a/google/cloud/bigquery/internal/migration_logging_decorator.cc b/google/cloud/bigquery/internal/migration_logging_decorator.cc new file mode 100644 index 0000000000000..eaec21bbe523d --- /dev/null +++ b/google/cloud/bigquery/internal/migration_logging_decorator.cc @@ -0,0 +1,136 @@ +// Copyright 2022 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 +// +// https://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. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/bigquery/migration/v2/migration_service.proto + +#include "google/cloud/bigquery/internal/migration_logging_decorator.h" +#include "google/cloud/internal/log_wrapper.h" +#include "google/cloud/status_or.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquery_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +MigrationServiceLogging::MigrationServiceLogging( + std::shared_ptr child, TracingOptions tracing_options, + std::set components) + : child_(std::move(child)), + tracing_options_(std::move(tracing_options)), + components_(std::move(components)) {} + +StatusOr +MigrationServiceLogging::CreateMigrationWorkflow( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + CreateMigrationWorkflowRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + CreateMigrationWorkflowRequest const& request) { + return child_->CreateMigrationWorkflow(context, request); + }, + context, request, __func__, tracing_options_); +} + +StatusOr +MigrationServiceLogging::GetMigrationWorkflow( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2::GetMigrationWorkflowRequest const& + request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + GetMigrationWorkflowRequest const& request) { + return child_->GetMigrationWorkflow(context, request); + }, + context, request, __func__, tracing_options_); +} + +StatusOr +MigrationServiceLogging::ListMigrationWorkflows( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2::ListMigrationWorkflowsRequest const& + request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + ListMigrationWorkflowsRequest const& request) { + return child_->ListMigrationWorkflows(context, request); + }, + context, request, __func__, tracing_options_); +} + +Status MigrationServiceLogging::DeleteMigrationWorkflow( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + DeleteMigrationWorkflowRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + DeleteMigrationWorkflowRequest const& request) { + return child_->DeleteMigrationWorkflow(context, request); + }, + context, request, __func__, tracing_options_); +} + +Status MigrationServiceLogging::StartMigrationWorkflow( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2::StartMigrationWorkflowRequest const& + request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + StartMigrationWorkflowRequest const& request) { + return child_->StartMigrationWorkflow(context, request); + }, + context, request, __func__, tracing_options_); +} + +StatusOr +MigrationServiceLogging::GetMigrationSubtask( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2::GetMigrationSubtaskRequest const& + request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + GetMigrationSubtaskRequest const& request) { + return child_->GetMigrationSubtask(context, request); + }, + context, request, __func__, tracing_options_); +} + +StatusOr +MigrationServiceLogging::ListMigrationSubtasks( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2::ListMigrationSubtasksRequest const& + request) { + return google::cloud::internal::LogWrapper( + [this](grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + ListMigrationSubtasksRequest const& request) { + return child_->ListMigrationSubtasks(context, request); + }, + context, request, __func__, tracing_options_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquery_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquery/internal/migration_logging_decorator.h b/google/cloud/bigquery/internal/migration_logging_decorator.h new file mode 100644 index 0000000000000..afc3a162ce448 --- /dev/null +++ b/google/cloud/bigquery/internal/migration_logging_decorator.h @@ -0,0 +1,94 @@ +// Copyright 2022 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 +// +// https://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. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/bigquery/migration/v2/migration_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_INTERNAL_MIGRATION_LOGGING_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_INTERNAL_MIGRATION_LOGGING_DECORATOR_H + +#include "google/cloud/bigquery/internal/migration_stub.h" +#include "google/cloud/tracing_options.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace bigquery_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class MigrationServiceLogging : public MigrationServiceStub { + public: + ~MigrationServiceLogging() override = default; + MigrationServiceLogging(std::shared_ptr child, + TracingOptions tracing_options, + std::set components); + + StatusOr + CreateMigrationWorkflow( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + CreateMigrationWorkflowRequest const& request) override; + + StatusOr + GetMigrationWorkflow( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2::GetMigrationWorkflowRequest const& + request) override; + + StatusOr< + google::cloud::bigquery::migration::v2::ListMigrationWorkflowsResponse> + ListMigrationWorkflows( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + ListMigrationWorkflowsRequest const& request) override; + + Status DeleteMigrationWorkflow( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + DeleteMigrationWorkflowRequest const& request) override; + + Status StartMigrationWorkflow( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + StartMigrationWorkflowRequest const& request) override; + + StatusOr + GetMigrationSubtask( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2::GetMigrationSubtaskRequest const& + request) override; + + StatusOr< + google::cloud::bigquery::migration::v2::ListMigrationSubtasksResponse> + ListMigrationSubtasks( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + ListMigrationSubtasksRequest const& request) override; + + private: + std::shared_ptr child_; + TracingOptions tracing_options_; + std::set components_; +}; // MigrationServiceLogging + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquery_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_INTERNAL_MIGRATION_LOGGING_DECORATOR_H diff --git a/google/cloud/bigquery/internal/migration_metadata_decorator.cc b/google/cloud/bigquery/internal/migration_metadata_decorator.cc new file mode 100644 index 0000000000000..69e4a056b2a8b --- /dev/null +++ b/google/cloud/bigquery/internal/migration_metadata_decorator.cc @@ -0,0 +1,118 @@ +// Copyright 2022 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 +// +// https://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. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/bigquery/migration/v2/migration_service.proto + +#include "google/cloud/bigquery/internal/migration_metadata_decorator.h" +#include "google/cloud/common_options.h" +#include "google/cloud/internal/api_client_header.h" +#include "google/cloud/status_or.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquery_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +MigrationServiceMetadata::MigrationServiceMetadata( + std::shared_ptr child) + : child_(std::move(child)), + api_client_header_( + google::cloud::internal::ApiClientHeader("generator")) {} + +StatusOr +MigrationServiceMetadata::CreateMigrationWorkflow( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + CreateMigrationWorkflowRequest const& request) { + SetMetadata(context, "parent=" + request.parent()); + return child_->CreateMigrationWorkflow(context, request); +} + +StatusOr +MigrationServiceMetadata::GetMigrationWorkflow( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2::GetMigrationWorkflowRequest const& + request) { + SetMetadata(context, "name=" + request.name()); + return child_->GetMigrationWorkflow(context, request); +} + +StatusOr +MigrationServiceMetadata::ListMigrationWorkflows( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2::ListMigrationWorkflowsRequest const& + request) { + SetMetadata(context, "parent=" + request.parent()); + return child_->ListMigrationWorkflows(context, request); +} + +Status MigrationServiceMetadata::DeleteMigrationWorkflow( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + DeleteMigrationWorkflowRequest const& request) { + SetMetadata(context, "name=" + request.name()); + return child_->DeleteMigrationWorkflow(context, request); +} + +Status MigrationServiceMetadata::StartMigrationWorkflow( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2::StartMigrationWorkflowRequest const& + request) { + SetMetadata(context, "name=" + request.name()); + return child_->StartMigrationWorkflow(context, request); +} + +StatusOr +MigrationServiceMetadata::GetMigrationSubtask( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2::GetMigrationSubtaskRequest const& + request) { + SetMetadata(context, "name=" + request.name()); + return child_->GetMigrationSubtask(context, request); +} + +StatusOr +MigrationServiceMetadata::ListMigrationSubtasks( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2::ListMigrationSubtasksRequest const& + request) { + SetMetadata(context, "parent=" + request.parent()); + return child_->ListMigrationSubtasks(context, request); +} + +void MigrationServiceMetadata::SetMetadata(grpc::ClientContext& context, + std::string const& request_params) { + context.AddMetadata("x-goog-request-params", request_params); + SetMetadata(context); +} + +void MigrationServiceMetadata::SetMetadata(grpc::ClientContext& context) { + context.AddMetadata("x-goog-api-client", api_client_header_); + auto const& options = internal::CurrentOptions(); + if (options.has()) { + context.AddMetadata("x-goog-user-project", + options.get()); + } + auto const& authority = options.get(); + if (!authority.empty()) context.set_authority(authority); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquery_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquery/internal/migration_metadata_decorator.h b/google/cloud/bigquery/internal/migration_metadata_decorator.h new file mode 100644 index 0000000000000..84149ccb97411 --- /dev/null +++ b/google/cloud/bigquery/internal/migration_metadata_decorator.h @@ -0,0 +1,94 @@ +// Copyright 2022 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 +// +// https://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. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/bigquery/migration/v2/migration_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_INTERNAL_MIGRATION_METADATA_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_INTERNAL_MIGRATION_METADATA_DECORATOR_H + +#include "google/cloud/bigquery/internal/migration_stub.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquery_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class MigrationServiceMetadata : public MigrationServiceStub { + public: + ~MigrationServiceMetadata() override = default; + explicit MigrationServiceMetadata( + std::shared_ptr child); + + StatusOr + CreateMigrationWorkflow( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + CreateMigrationWorkflowRequest const& request) override; + + StatusOr + GetMigrationWorkflow( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2::GetMigrationWorkflowRequest const& + request) override; + + StatusOr< + google::cloud::bigquery::migration::v2::ListMigrationWorkflowsResponse> + ListMigrationWorkflows( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + ListMigrationWorkflowsRequest const& request) override; + + Status DeleteMigrationWorkflow( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + DeleteMigrationWorkflowRequest const& request) override; + + Status StartMigrationWorkflow( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + StartMigrationWorkflowRequest const& request) override; + + StatusOr + GetMigrationSubtask( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2::GetMigrationSubtaskRequest const& + request) override; + + StatusOr< + google::cloud::bigquery::migration::v2::ListMigrationSubtasksResponse> + ListMigrationSubtasks( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + ListMigrationSubtasksRequest const& request) override; + + private: + void SetMetadata(grpc::ClientContext& context, + std::string const& request_params); + void SetMetadata(grpc::ClientContext& context); + + std::shared_ptr child_; + std::string api_client_header_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquery_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_INTERNAL_MIGRATION_METADATA_DECORATOR_H diff --git a/google/cloud/bigquery/internal/migration_option_defaults.cc b/google/cloud/bigquery/internal/migration_option_defaults.cc new file mode 100644 index 0000000000000..d58572e47eefd --- /dev/null +++ b/google/cloud/bigquery/internal/migration_option_defaults.cc @@ -0,0 +1,66 @@ +// Copyright 2022 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 +// +// https://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. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/bigquery/migration/v2/migration_service.proto + +#include "google/cloud/bigquery/internal/migration_option_defaults.h" +#include "google/cloud/bigquery/migration_connection.h" +#include "google/cloud/bigquery/migration_options.h" +#include "google/cloud/internal/populate_common_options.h" +#include "google/cloud/internal/populate_grpc_options.h" +#include + +namespace google { +namespace cloud { +namespace bigquery_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +namespace { +auto constexpr kBackoffScaling = 2.0; +} // namespace + +Options MigrationServiceDefaultOptions(Options options) { + options = google::cloud::internal::PopulateCommonOptions( + std::move(options), "GOOGLE_CLOUD_CPP_MIGRATION_SERVICE_ENDPOINT", "", + "GOOGLE_CLOUD_CPP_MIGRATION_SERVICE_AUTHORITY", + "bigquerymigration.googleapis.com"); + options = + google::cloud::internal::PopulateGrpcOptions(std::move(options), ""); + if (!options.has()) { + options.set( + bigquery::MigrationServiceLimitedTimeRetryPolicy( + std::chrono::minutes(30)) + .clone()); + } + if (!options.has()) { + options.set( + ExponentialBackoffPolicy(std::chrono::seconds(1), + std::chrono::minutes(5), kBackoffScaling) + .clone()); + } + if (!options.has< + bigquery::MigrationServiceConnectionIdempotencyPolicyOption>()) { + options.set( + bigquery::MakeDefaultMigrationServiceConnectionIdempotencyPolicy()); + } + + return options; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquery_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquery/internal/migration_option_defaults.h b/google/cloud/bigquery/internal/migration_option_defaults.h new file mode 100644 index 0000000000000..47947a72a990b --- /dev/null +++ b/google/cloud/bigquery/internal/migration_option_defaults.h @@ -0,0 +1,37 @@ +// Copyright 2022 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 +// +// https://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. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/bigquery/migration/v2/migration_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_INTERNAL_MIGRATION_OPTION_DEFAULTS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_INTERNAL_MIGRATION_OPTION_DEFAULTS_H + +#include "google/cloud/options.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace bigquery_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +Options MigrationServiceDefaultOptions(Options options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquery_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_INTERNAL_MIGRATION_OPTION_DEFAULTS_H diff --git a/google/cloud/bigquery/internal/migration_retry_traits.h b/google/cloud/bigquery/internal/migration_retry_traits.h new file mode 100644 index 0000000000000..a12981301cca5 --- /dev/null +++ b/google/cloud/bigquery/internal/migration_retry_traits.h @@ -0,0 +1,43 @@ +// Copyright 2022 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 +// +// https://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. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/bigquery/migration/v2/migration_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_INTERNAL_MIGRATION_RETRY_TRAITS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_INTERNAL_MIGRATION_RETRY_TRAITS_H + +#include "google/cloud/status.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace bigquery_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// Define the gRPC status code semantics for retrying requests. +struct MigrationServiceRetryTraits { + static inline bool IsPermanentFailure(google::cloud::Status const& status) { + return status.code() != StatusCode::kOk && + status.code() != StatusCode::kUnavailable; + } +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquery_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_INTERNAL_MIGRATION_RETRY_TRAITS_H diff --git a/google/cloud/bigquery/internal/migration_stub.cc b/google/cloud/bigquery/internal/migration_stub.cc new file mode 100644 index 0000000000000..3ebbb200f8bb4 --- /dev/null +++ b/google/cloud/bigquery/internal/migration_stub.cc @@ -0,0 +1,133 @@ +// Copyright 2022 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 +// +// https://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. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/bigquery/migration/v2/migration_service.proto + +#include "google/cloud/bigquery/internal/migration_stub.h" +#include "google/cloud/grpc_error_delegate.h" +#include "google/cloud/status_or.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquery_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +MigrationServiceStub::~MigrationServiceStub() = default; + +StatusOr +DefaultMigrationServiceStub::CreateMigrationWorkflow( + grpc::ClientContext& client_context, + google::cloud::bigquery::migration::v2:: + CreateMigrationWorkflowRequest const& request) { + google::cloud::bigquery::migration::v2::MigrationWorkflow response; + auto status = + grpc_stub_->CreateMigrationWorkflow(&client_context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultMigrationServiceStub::GetMigrationWorkflow( + grpc::ClientContext& client_context, + google::cloud::bigquery::migration::v2::GetMigrationWorkflowRequest const& + request) { + google::cloud::bigquery::migration::v2::MigrationWorkflow response; + auto status = + grpc_stub_->GetMigrationWorkflow(&client_context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultMigrationServiceStub::ListMigrationWorkflows( + grpc::ClientContext& client_context, + google::cloud::bigquery::migration::v2::ListMigrationWorkflowsRequest const& + request) { + google::cloud::bigquery::migration::v2::ListMigrationWorkflowsResponse + response; + auto status = + grpc_stub_->ListMigrationWorkflows(&client_context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +Status DefaultMigrationServiceStub::DeleteMigrationWorkflow( + grpc::ClientContext& client_context, + google::cloud::bigquery::migration::v2:: + DeleteMigrationWorkflowRequest const& request) { + google::protobuf::Empty response; + auto status = + grpc_stub_->DeleteMigrationWorkflow(&client_context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return google::cloud::Status(); +} + +Status DefaultMigrationServiceStub::StartMigrationWorkflow( + grpc::ClientContext& client_context, + google::cloud::bigquery::migration::v2::StartMigrationWorkflowRequest const& + request) { + google::protobuf::Empty response; + auto status = + grpc_stub_->StartMigrationWorkflow(&client_context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return google::cloud::Status(); +} + +StatusOr +DefaultMigrationServiceStub::GetMigrationSubtask( + grpc::ClientContext& client_context, + google::cloud::bigquery::migration::v2::GetMigrationSubtaskRequest const& + request) { + google::cloud::bigquery::migration::v2::MigrationSubtask response; + auto status = + grpc_stub_->GetMigrationSubtask(&client_context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +StatusOr +DefaultMigrationServiceStub::ListMigrationSubtasks( + grpc::ClientContext& client_context, + google::cloud::bigquery::migration::v2::ListMigrationSubtasksRequest const& + request) { + google::cloud::bigquery::migration::v2::ListMigrationSubtasksResponse + response; + auto status = + grpc_stub_->ListMigrationSubtasks(&client_context, request, &response); + if (!status.ok()) { + return google::cloud::MakeStatusFromRpcError(status); + } + return response; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquery_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquery/internal/migration_stub.h b/google/cloud/bigquery/internal/migration_stub.h new file mode 100644 index 0000000000000..1f8b97a44fe92 --- /dev/null +++ b/google/cloud/bigquery/internal/migration_stub.h @@ -0,0 +1,138 @@ +// Copyright 2022 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 +// +// https://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. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/bigquery/migration/v2/migration_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_INTERNAL_MIGRATION_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_INTERNAL_MIGRATION_STUB_H + +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquery_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class MigrationServiceStub { + public: + virtual ~MigrationServiceStub() = 0; + + virtual StatusOr + CreateMigrationWorkflow( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + CreateMigrationWorkflowRequest const& request) = 0; + + virtual StatusOr + GetMigrationWorkflow( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2::GetMigrationWorkflowRequest const& + request) = 0; + + virtual StatusOr< + google::cloud::bigquery::migration::v2::ListMigrationWorkflowsResponse> + ListMigrationWorkflows(grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + ListMigrationWorkflowsRequest const& request) = 0; + + virtual Status DeleteMigrationWorkflow( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + DeleteMigrationWorkflowRequest const& request) = 0; + + virtual Status StartMigrationWorkflow( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + StartMigrationWorkflowRequest const& request) = 0; + + virtual StatusOr + GetMigrationSubtask( + grpc::ClientContext& context, + google::cloud::bigquery::migration::v2::GetMigrationSubtaskRequest const& + request) = 0; + + virtual StatusOr< + google::cloud::bigquery::migration::v2::ListMigrationSubtasksResponse> + ListMigrationSubtasks(grpc::ClientContext& context, + google::cloud::bigquery::migration::v2:: + ListMigrationSubtasksRequest const& request) = 0; +}; + +class DefaultMigrationServiceStub : public MigrationServiceStub { + public: + explicit DefaultMigrationServiceStub( + std::unique_ptr + grpc_stub) + : grpc_stub_(std::move(grpc_stub)) {} + + StatusOr + CreateMigrationWorkflow( + grpc::ClientContext& client_context, + google::cloud::bigquery::migration::v2:: + CreateMigrationWorkflowRequest const& request) override; + + StatusOr + GetMigrationWorkflow( + grpc::ClientContext& client_context, + google::cloud::bigquery::migration::v2::GetMigrationWorkflowRequest const& + request) override; + + StatusOr< + google::cloud::bigquery::migration::v2::ListMigrationWorkflowsResponse> + ListMigrationWorkflows( + grpc::ClientContext& client_context, + google::cloud::bigquery::migration::v2:: + ListMigrationWorkflowsRequest const& request) override; + + Status DeleteMigrationWorkflow( + grpc::ClientContext& client_context, + google::cloud::bigquery::migration::v2:: + DeleteMigrationWorkflowRequest const& request) override; + + Status StartMigrationWorkflow( + grpc::ClientContext& client_context, + google::cloud::bigquery::migration::v2:: + StartMigrationWorkflowRequest const& request) override; + + StatusOr + GetMigrationSubtask( + grpc::ClientContext& client_context, + google::cloud::bigquery::migration::v2::GetMigrationSubtaskRequest const& + request) override; + + StatusOr< + google::cloud::bigquery::migration::v2::ListMigrationSubtasksResponse> + ListMigrationSubtasks( + grpc::ClientContext& client_context, + google::cloud::bigquery::migration::v2:: + ListMigrationSubtasksRequest const& request) override; + + private: + std::unique_ptr< + google::cloud::bigquery::migration::v2::MigrationService::StubInterface> + grpc_stub_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquery_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_INTERNAL_MIGRATION_STUB_H diff --git a/google/cloud/bigquery/internal/migration_stub_factory.cc b/google/cloud/bigquery/internal/migration_stub_factory.cc new file mode 100644 index 0000000000000..747f456a64101 --- /dev/null +++ b/google/cloud/bigquery/internal/migration_stub_factory.cc @@ -0,0 +1,67 @@ +// Copyright 2022 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 +// +// https://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. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/bigquery/migration/v2/migration_service.proto + +#include "google/cloud/bigquery/internal/migration_stub_factory.h" +#include "google/cloud/bigquery/internal/migration_auth_decorator.h" +#include "google/cloud/bigquery/internal/migration_logging_decorator.h" +#include "google/cloud/bigquery/internal/migration_metadata_decorator.h" +#include "google/cloud/bigquery/internal/migration_stub.h" +#include "google/cloud/common_options.h" +#include "google/cloud/grpc_options.h" +#include "google/cloud/internal/algorithm.h" +#include "google/cloud/log.h" +#include "google/cloud/options.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquery_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultMigrationServiceStub( + google::cloud::CompletionQueue cq, Options const& options) { + auto auth = google::cloud::internal::CreateAuthenticationStrategy( + std::move(cq), options); + auto channel = auth->CreateChannel(options.get(), + internal::MakeChannelArguments(options)); + auto service_grpc_stub = + google::cloud::bigquery::migration::v2::MigrationService::NewStub( + channel); + std::shared_ptr stub = + std::make_shared( + std::move(service_grpc_stub)); + + if (auth->RequiresConfigureContext()) { + stub = std::make_shared(std::move(auth), + std::move(stub)); + } + stub = std::make_shared(std::move(stub)); + if (internal::Contains(options.get(), "rpc")) { + GCP_LOG(INFO) << "Enabled logging for gRPC calls"; + stub = std::make_shared( + std::move(stub), options.get(), + options.get()); + } + return stub; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquery_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquery/internal/migration_stub_factory.h b/google/cloud/bigquery/internal/migration_stub_factory.h new file mode 100644 index 0000000000000..493843bb306f2 --- /dev/null +++ b/google/cloud/bigquery/internal/migration_stub_factory.h @@ -0,0 +1,42 @@ +// Copyright 2022 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 +// +// https://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. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/bigquery/migration/v2/migration_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_INTERNAL_MIGRATION_STUB_FACTORY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_INTERNAL_MIGRATION_STUB_FACTORY_H + +#include "google/cloud/bigquery/internal/migration_stub.h" +#include "google/cloud/completion_queue.h" +#include "google/cloud/credentials.h" +#include "google/cloud/internal/unified_grpc_credentials.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace bigquery_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultMigrationServiceStub( + google::cloud::CompletionQueue cq, Options const& options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquery_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_INTERNAL_MIGRATION_STUB_FACTORY_H diff --git a/google/cloud/bigquery/migration_client.cc b/google/cloud/bigquery/migration_client.cc new file mode 100644 index 0000000000000..23632ecfb5c7c --- /dev/null +++ b/google/cloud/bigquery/migration_client.cc @@ -0,0 +1,165 @@ +// Copyright 2022 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 +// +// https://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. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/bigquery/migration/v2/migration_service.proto + +#include "google/cloud/bigquery/migration_client.h" +#include + +namespace google { +namespace cloud { +namespace bigquery { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +MigrationServiceClient::MigrationServiceClient( + std::shared_ptr connection, Options opts) + : connection_(std::move(connection)), + options_( + internal::MergeOptions(std::move(opts), connection_->options())) {} +MigrationServiceClient::~MigrationServiceClient() = default; + +StatusOr +MigrationServiceClient::CreateMigrationWorkflow( + std::string const& parent, + google::cloud::bigquery::migration::v2::MigrationWorkflow const& + migration_workflow, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::bigquery::migration::v2::CreateMigrationWorkflowRequest + request; + request.set_parent(parent); + *request.mutable_migration_workflow() = migration_workflow; + return connection_->CreateMigrationWorkflow(request); +} + +StatusOr +MigrationServiceClient::CreateMigrationWorkflow( + google::cloud::bigquery::migration::v2:: + CreateMigrationWorkflowRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->CreateMigrationWorkflow(request); +} + +StatusOr +MigrationServiceClient::GetMigrationWorkflow(std::string const& name, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::bigquery::migration::v2::GetMigrationWorkflowRequest request; + request.set_name(name); + return connection_->GetMigrationWorkflow(request); +} + +StatusOr +MigrationServiceClient::GetMigrationWorkflow( + google::cloud::bigquery::migration::v2::GetMigrationWorkflowRequest const& + request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->GetMigrationWorkflow(request); +} + +StreamRange +MigrationServiceClient::ListMigrationWorkflows(std::string const& parent, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::bigquery::migration::v2::ListMigrationWorkflowsRequest request; + request.set_parent(parent); + return connection_->ListMigrationWorkflows(request); +} + +StreamRange +MigrationServiceClient::ListMigrationWorkflows( + google::cloud::bigquery::migration::v2::ListMigrationWorkflowsRequest + request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->ListMigrationWorkflows(std::move(request)); +} + +Status MigrationServiceClient::DeleteMigrationWorkflow(std::string const& name, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::bigquery::migration::v2::DeleteMigrationWorkflowRequest + request; + request.set_name(name); + return connection_->DeleteMigrationWorkflow(request); +} + +Status MigrationServiceClient::DeleteMigrationWorkflow( + google::cloud::bigquery::migration::v2:: + DeleteMigrationWorkflowRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->DeleteMigrationWorkflow(request); +} + +Status MigrationServiceClient::StartMigrationWorkflow(std::string const& name, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::bigquery::migration::v2::StartMigrationWorkflowRequest request; + request.set_name(name); + return connection_->StartMigrationWorkflow(request); +} + +Status MigrationServiceClient::StartMigrationWorkflow( + google::cloud::bigquery::migration::v2::StartMigrationWorkflowRequest const& + request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->StartMigrationWorkflow(request); +} + +StatusOr +MigrationServiceClient::GetMigrationSubtask(std::string const& name, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::bigquery::migration::v2::GetMigrationSubtaskRequest request; + request.set_name(name); + return connection_->GetMigrationSubtask(request); +} + +StatusOr +MigrationServiceClient::GetMigrationSubtask( + google::cloud::bigquery::migration::v2::GetMigrationSubtaskRequest const& + request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->GetMigrationSubtask(request); +} + +StreamRange +MigrationServiceClient::ListMigrationSubtasks(std::string const& parent, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::bigquery::migration::v2::ListMigrationSubtasksRequest request; + request.set_parent(parent); + return connection_->ListMigrationSubtasks(request); +} + +StreamRange +MigrationServiceClient::ListMigrationSubtasks( + google::cloud::bigquery::migration::v2::ListMigrationSubtasksRequest + request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->ListMigrationSubtasks(std::move(request)); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquery +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquery/migration_client.h b/google/cloud/bigquery/migration_client.h new file mode 100644 index 0000000000000..81547434f8b03 --- /dev/null +++ b/google/cloud/bigquery/migration_client.h @@ -0,0 +1,364 @@ +// Copyright 2022 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 +// +// https://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. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/bigquery/migration/v2/migration_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_MIGRATION_CLIENT_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_MIGRATION_CLIENT_H + +#include "google/cloud/bigquery/migration_connection.h" +#include "google/cloud/future.h" +#include "google/cloud/options.h" +#include "google/cloud/polling_policy.h" +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquery { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// +/// Service to handle EDW migrations. +/// +/// @par Equality +/// +/// Instances of this class created via copy-construction or copy-assignment +/// always compare equal. Instances created with equal +/// `std::shared_ptr<*Connection>` objects compare equal. Objects that compare +/// equal share the same underlying resources. +/// +/// @par Performance +/// +/// Creating a new instance of this class is a relatively expensive operation, +/// new objects establish new connections to the service. In contrast, +/// copy-construction, move-construction, and the corresponding assignment +/// operations are relatively efficient as the copies share all underlying +/// resources. +/// +/// @par Thread Safety +/// +/// Concurrent access to different instances of this class, even if they compare +/// equal, is guaranteed to work. Two or more threads operating on the same +/// instance of this class is not guaranteed to work. Since copy-construction +/// and move-construction is a relatively efficient operation, consider using +/// such a copy when using this class from multiple threads. +/// +class MigrationServiceClient { + public: + explicit MigrationServiceClient( + std::shared_ptr connection, + Options opts = {}); + ~MigrationServiceClient(); + + //@{ + // @name Copy and move support + MigrationServiceClient(MigrationServiceClient const&) = default; + MigrationServiceClient& operator=(MigrationServiceClient const&) = default; + MigrationServiceClient(MigrationServiceClient&&) = default; + MigrationServiceClient& operator=(MigrationServiceClient&&) = default; + //@} + + //@{ + // @name Equality + friend bool operator==(MigrationServiceClient const& a, + MigrationServiceClient const& b) { + return a.connection_ == b.connection_; + } + friend bool operator!=(MigrationServiceClient const& a, + MigrationServiceClient const& b) { + return !(a == b); + } + //@} + + /// + /// Creates a migration workflow. + /// + /// @param parent Required. The name of the project to which this migration + /// workflow belongs. + /// Example: `projects/foo/locations/bar` + /// @param migration_workflow Required. The migration workflow to create. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return + /// @googleapis_link{google::cloud::bigquery::migration::v2::MigrationWorkflow,google/cloud/bigquery/migration/v2/migration_entities.proto#L36} + /// + /// [google.cloud.bigquery.migration.v2.CreateMigrationWorkflowRequest]: + /// @googleapis_reference_link{google/cloud/bigquery/migration/v2/migration_service.proto#L102} + /// [google.cloud.bigquery.migration.v2.MigrationWorkflow]: + /// @googleapis_reference_link{google/cloud/bigquery/migration/v2/migration_entities.proto#L36} + /// + StatusOr + CreateMigrationWorkflow( + std::string const& parent, + google::cloud::bigquery::migration::v2::MigrationWorkflow const& + migration_workflow, + Options opts = {}); + + /// + /// Creates a migration workflow. + /// + /// @param request + /// @googleapis_link{google::cloud::bigquery::migration::v2::CreateMigrationWorkflowRequest,google/cloud/bigquery/migration/v2/migration_service.proto#L102} + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return + /// @googleapis_link{google::cloud::bigquery::migration::v2::MigrationWorkflow,google/cloud/bigquery/migration/v2/migration_entities.proto#L36} + /// + /// [google.cloud.bigquery.migration.v2.CreateMigrationWorkflowRequest]: + /// @googleapis_reference_link{google/cloud/bigquery/migration/v2/migration_service.proto#L102} + /// [google.cloud.bigquery.migration.v2.MigrationWorkflow]: + /// @googleapis_reference_link{google/cloud/bigquery/migration/v2/migration_entities.proto#L36} + /// + StatusOr + CreateMigrationWorkflow(google::cloud::bigquery::migration::v2:: + CreateMigrationWorkflowRequest const& request, + Options opts = {}); + + /// + /// Gets a previously created migration workflow. + /// + /// @param name Required. The unique identifier for the migration workflow. + /// Example: `projects/123/locations/us/workflows/1234` + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return + /// @googleapis_link{google::cloud::bigquery::migration::v2::MigrationWorkflow,google/cloud/bigquery/migration/v2/migration_entities.proto#L36} + /// + /// [google.cloud.bigquery.migration.v2.GetMigrationWorkflowRequest]: + /// @googleapis_reference_link{google/cloud/bigquery/migration/v2/migration_service.proto#L117} + /// [google.cloud.bigquery.migration.v2.MigrationWorkflow]: + /// @googleapis_reference_link{google/cloud/bigquery/migration/v2/migration_entities.proto#L36} + /// + StatusOr + GetMigrationWorkflow(std::string const& name, Options opts = {}); + + /// + /// Gets a previously created migration workflow. + /// + /// @param request + /// @googleapis_link{google::cloud::bigquery::migration::v2::GetMigrationWorkflowRequest,google/cloud/bigquery/migration/v2/migration_service.proto#L117} + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return + /// @googleapis_link{google::cloud::bigquery::migration::v2::MigrationWorkflow,google/cloud/bigquery/migration/v2/migration_entities.proto#L36} + /// + /// [google.cloud.bigquery.migration.v2.GetMigrationWorkflowRequest]: + /// @googleapis_reference_link{google/cloud/bigquery/migration/v2/migration_service.proto#L117} + /// [google.cloud.bigquery.migration.v2.MigrationWorkflow]: + /// @googleapis_reference_link{google/cloud/bigquery/migration/v2/migration_entities.proto#L36} + /// + StatusOr + GetMigrationWorkflow( + google::cloud::bigquery::migration::v2::GetMigrationWorkflowRequest const& + request, + Options opts = {}); + + /// + /// Lists previously created migration workflow. + /// + /// @param parent Required. The project and location of the migration + /// workflows to list. + /// Example: `projects/123/locations/us` + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return + /// @googleapis_link{google::cloud::bigquery::migration::v2::MigrationWorkflow,google/cloud/bigquery/migration/v2/migration_entities.proto#L36} + /// + /// [google.cloud.bigquery.migration.v2.ListMigrationWorkflowsRequest]: + /// @googleapis_reference_link{google/cloud/bigquery/migration/v2/migration_service.proto#L132} + /// [google.cloud.bigquery.migration.v2.MigrationWorkflow]: + /// @googleapis_reference_link{google/cloud/bigquery/migration/v2/migration_entities.proto#L36} + /// + StreamRange + ListMigrationWorkflows(std::string const& parent, Options opts = {}); + + /// + /// Lists previously created migration workflow. + /// + /// @param request + /// @googleapis_link{google::cloud::bigquery::migration::v2::ListMigrationWorkflowsRequest,google/cloud/bigquery/migration/v2/migration_service.proto#L132} + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return + /// @googleapis_link{google::cloud::bigquery::migration::v2::MigrationWorkflow,google/cloud/bigquery/migration/v2/migration_entities.proto#L36} + /// + /// [google.cloud.bigquery.migration.v2.ListMigrationWorkflowsRequest]: + /// @googleapis_reference_link{google/cloud/bigquery/migration/v2/migration_service.proto#L132} + /// [google.cloud.bigquery.migration.v2.MigrationWorkflow]: + /// @googleapis_reference_link{google/cloud/bigquery/migration/v2/migration_entities.proto#L36} + /// + StreamRange + ListMigrationWorkflows( + google::cloud::bigquery::migration::v2::ListMigrationWorkflowsRequest + request, + Options opts = {}); + + /// + /// Deletes a migration workflow by name. + /// + /// @param name Required. The unique identifier for the migration workflow. + /// Example: `projects/123/locations/us/workflows/1234` + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// + /// [google.cloud.bigquery.migration.v2.DeleteMigrationWorkflowRequest]: + /// @googleapis_reference_link{google/cloud/bigquery/migration/v2/migration_service.proto#L168} + /// + Status DeleteMigrationWorkflow(std::string const& name, Options opts = {}); + + /// + /// Deletes a migration workflow by name. + /// + /// @param request + /// @googleapis_link{google::cloud::bigquery::migration::v2::DeleteMigrationWorkflowRequest,google/cloud/bigquery/migration/v2/migration_service.proto#L168} + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// + /// [google.cloud.bigquery.migration.v2.DeleteMigrationWorkflowRequest]: + /// @googleapis_reference_link{google/cloud/bigquery/migration/v2/migration_service.proto#L168} + /// + Status DeleteMigrationWorkflow( + google::cloud::bigquery::migration::v2:: + DeleteMigrationWorkflowRequest const& request, + Options opts = {}); + + /// + /// Starts a previously created migration workflow. I.e., the state + /// transitions from DRAFT to RUNNING. This is a no-op if the state is already + /// RUNNING. An error will be signaled if the state is anything other than + /// DRAFT or RUNNING. + /// + /// @param name Required. The unique identifier for the migration workflow. + /// Example: `projects/123/locations/us/workflows/1234` + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// + /// [google.cloud.bigquery.migration.v2.StartMigrationWorkflowRequest]: + /// @googleapis_reference_link{google/cloud/bigquery/migration/v2/migration_service.proto#L180} + /// + Status StartMigrationWorkflow(std::string const& name, Options opts = {}); + + /// + /// Starts a previously created migration workflow. I.e., the state + /// transitions from DRAFT to RUNNING. This is a no-op if the state is already + /// RUNNING. An error will be signaled if the state is anything other than + /// DRAFT or RUNNING. + /// + /// @param request + /// @googleapis_link{google::cloud::bigquery::migration::v2::StartMigrationWorkflowRequest,google/cloud/bigquery/migration/v2/migration_service.proto#L180} + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// + /// [google.cloud.bigquery.migration.v2.StartMigrationWorkflowRequest]: + /// @googleapis_reference_link{google/cloud/bigquery/migration/v2/migration_service.proto#L180} + /// + Status StartMigrationWorkflow( + google::cloud::bigquery::migration::v2:: + StartMigrationWorkflowRequest const& request, + Options opts = {}); + + /// + /// Gets a previously created migration subtask. + /// + /// @param name Required. The unique identifier for the migration subtask. + /// Example: `projects/123/locations/us/workflows/1234/subtasks/543` + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return + /// @googleapis_link{google::cloud::bigquery::migration::v2::MigrationSubtask,google/cloud/bigquery/migration/v2/migration_entities.proto#L159} + /// + /// [google.cloud.bigquery.migration.v2.GetMigrationSubtaskRequest]: + /// @googleapis_reference_link{google/cloud/bigquery/migration/v2/migration_service.proto#L192} + /// [google.cloud.bigquery.migration.v2.MigrationSubtask]: + /// @googleapis_reference_link{google/cloud/bigquery/migration/v2/migration_entities.proto#L159} + /// + StatusOr + GetMigrationSubtask(std::string const& name, Options opts = {}); + + /// + /// Gets a previously created migration subtask. + /// + /// @param request + /// @googleapis_link{google::cloud::bigquery::migration::v2::GetMigrationSubtaskRequest,google/cloud/bigquery/migration/v2/migration_service.proto#L192} + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return + /// @googleapis_link{google::cloud::bigquery::migration::v2::MigrationSubtask,google/cloud/bigquery/migration/v2/migration_entities.proto#L159} + /// + /// [google.cloud.bigquery.migration.v2.GetMigrationSubtaskRequest]: + /// @googleapis_reference_link{google/cloud/bigquery/migration/v2/migration_service.proto#L192} + /// [google.cloud.bigquery.migration.v2.MigrationSubtask]: + /// @googleapis_reference_link{google/cloud/bigquery/migration/v2/migration_entities.proto#L159} + /// + StatusOr + GetMigrationSubtask( + google::cloud::bigquery::migration::v2::GetMigrationSubtaskRequest const& + request, + Options opts = {}); + + /// + /// Lists previously created migration subtasks. + /// + /// @param parent Required. The migration task of the subtasks to list. + /// Example: `projects/123/locations/us/workflows/1234` + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return + /// @googleapis_link{google::cloud::bigquery::migration::v2::MigrationSubtask,google/cloud/bigquery/migration/v2/migration_entities.proto#L159} + /// + /// [google.cloud.bigquery.migration.v2.ListMigrationSubtasksRequest]: + /// @googleapis_reference_link{google/cloud/bigquery/migration/v2/migration_service.proto#L207} + /// [google.cloud.bigquery.migration.v2.MigrationSubtask]: + /// @googleapis_reference_link{google/cloud/bigquery/migration/v2/migration_entities.proto#L159} + /// + StreamRange + ListMigrationSubtasks(std::string const& parent, Options opts = {}); + + /// + /// Lists previously created migration subtasks. + /// + /// @param request + /// @googleapis_link{google::cloud::bigquery::migration::v2::ListMigrationSubtasksRequest,google/cloud/bigquery/migration/v2/migration_service.proto#L207} + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return + /// @googleapis_link{google::cloud::bigquery::migration::v2::MigrationSubtask,google/cloud/bigquery/migration/v2/migration_entities.proto#L159} + /// + /// [google.cloud.bigquery.migration.v2.ListMigrationSubtasksRequest]: + /// @googleapis_reference_link{google/cloud/bigquery/migration/v2/migration_service.proto#L207} + /// [google.cloud.bigquery.migration.v2.MigrationSubtask]: + /// @googleapis_reference_link{google/cloud/bigquery/migration/v2/migration_entities.proto#L159} + /// + StreamRange + ListMigrationSubtasks( + google::cloud::bigquery::migration::v2::ListMigrationSubtasksRequest + request, + Options opts = {}); + + private: + std::shared_ptr connection_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquery +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_MIGRATION_CLIENT_H diff --git a/google/cloud/bigquery/migration_connection.cc b/google/cloud/bigquery/migration_connection.cc new file mode 100644 index 0000000000000..8d817927b5f3e --- /dev/null +++ b/google/cloud/bigquery/migration_connection.cc @@ -0,0 +1,104 @@ +// Copyright 2022 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 +// +// https://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. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/bigquery/migration/v2/migration_service.proto + +#include "google/cloud/bigquery/migration_connection.h" +#include "google/cloud/bigquery/internal/migration_connection_impl.h" +#include "google/cloud/bigquery/internal/migration_option_defaults.h" +#include "google/cloud/bigquery/internal/migration_stub_factory.h" +#include "google/cloud/bigquery/migration_options.h" +#include "google/cloud/background_threads.h" +#include "google/cloud/common_options.h" +#include "google/cloud/credentials.h" +#include "google/cloud/grpc_options.h" +#include "google/cloud/internal/pagination_range.h" +#include + +namespace google { +namespace cloud { +namespace bigquery { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +MigrationServiceConnection::~MigrationServiceConnection() = default; + +StatusOr +MigrationServiceConnection::CreateMigrationWorkflow( + google::cloud::bigquery::migration::v2:: + CreateMigrationWorkflowRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +MigrationServiceConnection::GetMigrationWorkflow( + google::cloud::bigquery::migration::v2:: + GetMigrationWorkflowRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StreamRange +MigrationServiceConnection::ListMigrationWorkflows( + google::cloud::bigquery::migration::v2:: + ListMigrationWorkflowsRequest) { // NOLINT(performance-unnecessary-value-param) + return google::cloud::internal::MakeUnimplementedPaginationRange< + StreamRange>(); +} + +Status MigrationServiceConnection::DeleteMigrationWorkflow( + google::cloud::bigquery::migration::v2:: + DeleteMigrationWorkflowRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +Status MigrationServiceConnection::StartMigrationWorkflow( + google::cloud::bigquery::migration::v2:: + StartMigrationWorkflowRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +MigrationServiceConnection::GetMigrationSubtask( + google::cloud::bigquery::migration::v2::GetMigrationSubtaskRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StreamRange +MigrationServiceConnection::ListMigrationSubtasks( + google::cloud::bigquery::migration::v2:: + ListMigrationSubtasksRequest) { // NOLINT(performance-unnecessary-value-param) + return google::cloud::internal::MakeUnimplementedPaginationRange< + StreamRange>(); +} + +std::shared_ptr MakeMigrationServiceConnection( + Options options) { + internal::CheckExpectedOptions(options, + __func__); + options = + bigquery_internal::MigrationServiceDefaultOptions(std::move(options)); + auto background = internal::MakeBackgroundThreadsFactory(options)(); + auto stub = bigquery_internal::CreateDefaultMigrationServiceStub( + background->cq(), options); + return std::make_shared( + std::move(background), std::move(stub), std::move(options)); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquery +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquery/migration_connection.h b/google/cloud/bigquery/migration_connection.h new file mode 100644 index 0000000000000..7b9abad6e3879 --- /dev/null +++ b/google/cloud/bigquery/migration_connection.h @@ -0,0 +1,130 @@ +// Copyright 2022 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 +// +// https://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. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/bigquery/migration/v2/migration_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_MIGRATION_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_MIGRATION_CONNECTION_H + +#include "google/cloud/bigquery/internal/migration_retry_traits.h" +#include "google/cloud/bigquery/internal/migration_stub.h" +#include "google/cloud/bigquery/migration_connection_idempotency_policy.h" +#include "google/cloud/backoff_policy.h" +#include "google/cloud/options.h" +#include "google/cloud/status_or.h" +#include "google/cloud/stream_range.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace bigquery { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +using MigrationServiceRetryPolicy = + ::google::cloud::internal::TraitBasedRetryPolicy< + bigquery_internal::MigrationServiceRetryTraits>; + +using MigrationServiceLimitedTimeRetryPolicy = + ::google::cloud::internal::LimitedTimeRetryPolicy< + bigquery_internal::MigrationServiceRetryTraits>; + +using MigrationServiceLimitedErrorCountRetryPolicy = + ::google::cloud::internal::LimitedErrorCountRetryPolicy< + bigquery_internal::MigrationServiceRetryTraits>; + +/** + * The `MigrationServiceConnection` object for `MigrationServiceClient`. + * + * This interface defines virtual methods for each of the user-facing overload + * sets in `MigrationServiceClient`. This allows users to inject custom behavior + * (e.g., with a Google Mock object) when writing tests that use objects of type + * `MigrationServiceClient`. + * + * To create a concrete instance, see `MakeMigrationServiceConnection()`. + * + * For mocking, see `bigquery_mocks::MockMigrationServiceConnection`. + */ +class MigrationServiceConnection { + public: + virtual ~MigrationServiceConnection() = 0; + + virtual Options options() { return Options{}; } + + virtual StatusOr + CreateMigrationWorkflow(google::cloud::bigquery::migration::v2:: + CreateMigrationWorkflowRequest const& request); + + virtual StatusOr + GetMigrationWorkflow( + google::cloud::bigquery::migration::v2::GetMigrationWorkflowRequest const& + request); + + virtual StreamRange + ListMigrationWorkflows( + google::cloud::bigquery::migration::v2::ListMigrationWorkflowsRequest + request); + + virtual Status DeleteMigrationWorkflow( + google::cloud::bigquery::migration::v2:: + DeleteMigrationWorkflowRequest const& request); + + virtual Status StartMigrationWorkflow( + google::cloud::bigquery::migration::v2:: + StartMigrationWorkflowRequest const& request); + + virtual StatusOr + GetMigrationSubtask( + google::cloud::bigquery::migration::v2::GetMigrationSubtaskRequest const& + request); + + virtual StreamRange + ListMigrationSubtasks( + google::cloud::bigquery::migration::v2::ListMigrationSubtasksRequest + request); +}; + +/** + * A factory function to construct an object of type + * `MigrationServiceConnection`. + * + * The returned connection object should not be used directly; instead it + * should be passed as an argument to the constructor of MigrationServiceClient. + * + * The optional @p options argument may be used to configure aspects of the + * returned `MigrationServiceConnection`. Expected options are any of the types + * in the following option lists: + * + * - `google::cloud::CommonOptionList` + * - `google::cloud::GrpcOptionList` + * - `google::cloud::UnifiedCredentialsOptionList` + * - `google::cloud::bigquery::MigrationServicePolicyOptionList` + * + * @note Unexpected options will be ignored. To log unexpected options instead, + * set `GOOGLE_CLOUD_CPP_ENABLE_CLOG=yes` in the environment. + * + * @param options (optional) Configure the `MigrationServiceConnection` created + * by this function. + */ +std::shared_ptr MakeMigrationServiceConnection( + Options options = {}); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquery +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_MIGRATION_CONNECTION_H diff --git a/google/cloud/bigquery/migration_connection_idempotency_policy.cc b/google/cloud/bigquery/migration_connection_idempotency_policy.cc new file mode 100644 index 0000000000000..5e74418444e41 --- /dev/null +++ b/google/cloud/bigquery/migration_connection_idempotency_policy.cc @@ -0,0 +1,89 @@ +// Copyright 2022 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 +// +// https://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. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/bigquery/migration/v2/migration_service.proto + +#include "google/cloud/bigquery/migration_connection_idempotency_policy.h" +#include "absl/memory/memory.h" +#include + +namespace google { +namespace cloud { +namespace bigquery { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +using ::google::cloud::Idempotency; + +MigrationServiceConnectionIdempotencyPolicy:: + ~MigrationServiceConnectionIdempotencyPolicy() = default; + +std::unique_ptr +MigrationServiceConnectionIdempotencyPolicy::clone() const { + return absl::make_unique(*this); +} + +Idempotency +MigrationServiceConnectionIdempotencyPolicy::CreateMigrationWorkflow( + google::cloud::bigquery::migration::v2:: + CreateMigrationWorkflowRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency MigrationServiceConnectionIdempotencyPolicy::GetMigrationWorkflow( + google::cloud::bigquery::migration::v2:: + GetMigrationWorkflowRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency MigrationServiceConnectionIdempotencyPolicy::ListMigrationWorkflows( + google::cloud::bigquery::migration::v2:: + ListMigrationWorkflowsRequest) { // NOLINT + return Idempotency::kIdempotent; +} + +Idempotency +MigrationServiceConnectionIdempotencyPolicy::DeleteMigrationWorkflow( + google::cloud::bigquery::migration::v2:: + DeleteMigrationWorkflowRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency MigrationServiceConnectionIdempotencyPolicy::StartMigrationWorkflow( + google::cloud::bigquery::migration::v2:: + StartMigrationWorkflowRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency MigrationServiceConnectionIdempotencyPolicy::GetMigrationSubtask( + google::cloud::bigquery::migration::v2::GetMigrationSubtaskRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency MigrationServiceConnectionIdempotencyPolicy::ListMigrationSubtasks( + google::cloud::bigquery::migration::v2:: + ListMigrationSubtasksRequest) { // NOLINT + return Idempotency::kIdempotent; +} + +std::unique_ptr +MakeDefaultMigrationServiceConnectionIdempotencyPolicy() { + return absl::make_unique(); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquery +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquery/migration_connection_idempotency_policy.h b/google/cloud/bigquery/migration_connection_idempotency_policy.h new file mode 100644 index 0000000000000..ed8a6f1e28d1c --- /dev/null +++ b/google/cloud/bigquery/migration_connection_idempotency_policy.h @@ -0,0 +1,78 @@ +// Copyright 2022 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 +// +// https://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. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/bigquery/migration/v2/migration_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_MIGRATION_CONNECTION_IDEMPOTENCY_POLICY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_MIGRATION_CONNECTION_IDEMPOTENCY_POLICY_H + +#include "google/cloud/idempotency.h" +#include "google/cloud/internal/retry_policy.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquery { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class MigrationServiceConnectionIdempotencyPolicy { + public: + virtual ~MigrationServiceConnectionIdempotencyPolicy(); + + /// Create a new copy of this object. + virtual std::unique_ptr clone() + const; + + virtual google::cloud::Idempotency CreateMigrationWorkflow( + google::cloud::bigquery::migration::v2:: + CreateMigrationWorkflowRequest const& request); + + virtual google::cloud::Idempotency GetMigrationWorkflow( + google::cloud::bigquery::migration::v2::GetMigrationWorkflowRequest const& + request); + + virtual google::cloud::Idempotency ListMigrationWorkflows( + google::cloud::bigquery::migration::v2::ListMigrationWorkflowsRequest + request); + + virtual google::cloud::Idempotency DeleteMigrationWorkflow( + google::cloud::bigquery::migration::v2:: + DeleteMigrationWorkflowRequest const& request); + + virtual google::cloud::Idempotency StartMigrationWorkflow( + google::cloud::bigquery::migration::v2:: + StartMigrationWorkflowRequest const& request); + + virtual google::cloud::Idempotency GetMigrationSubtask( + google::cloud::bigquery::migration::v2::GetMigrationSubtaskRequest const& + request); + + virtual google::cloud::Idempotency ListMigrationSubtasks( + google::cloud::bigquery::migration::v2::ListMigrationSubtasksRequest + request); +}; + +std::unique_ptr +MakeDefaultMigrationServiceConnectionIdempotencyPolicy(); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquery +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_MIGRATION_CONNECTION_IDEMPOTENCY_POLICY_H diff --git a/google/cloud/bigquery/migration_options.h b/google/cloud/bigquery/migration_options.h new file mode 100644 index 0000000000000..466620c82d950 --- /dev/null +++ b/google/cloud/bigquery/migration_options.h @@ -0,0 +1,59 @@ +// Copyright 2022 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 +// +// https://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. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/bigquery/migration/v2/migration_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_MIGRATION_OPTIONS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_MIGRATION_OPTIONS_H + +#include "google/cloud/bigquery/migration_connection.h" +#include "google/cloud/bigquery/migration_connection_idempotency_policy.h" +#include "google/cloud/backoff_policy.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace bigquery { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// Option to use with `google::cloud::Options`. +struct MigrationServiceRetryPolicyOption { + using Type = std::shared_ptr; +}; + +/// Option to use with `google::cloud::Options`. +struct MigrationServiceBackoffPolicyOption { + using Type = std::shared_ptr; +}; + +/// Option to use with `google::cloud::Options`. +struct MigrationServiceConnectionIdempotencyPolicyOption { + using Type = std::shared_ptr; +}; + +using MigrationServicePolicyOptionList = + OptionList; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquery +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_MIGRATION_OPTIONS_H diff --git a/google/cloud/bigquery/mocks/mock_migration_connection.h b/google/cloud/bigquery/mocks/mock_migration_connection.h new file mode 100644 index 0000000000000..5b68d847b14ce --- /dev/null +++ b/google/cloud/bigquery/mocks/mock_migration_connection.h @@ -0,0 +1,101 @@ +// Copyright 2022 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 +// +// https://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. + +// Generated by the Codegen C++ plugin. +// If you make any local changes, they will be lost. +// source: google/cloud/bigquery/migration/v2/migration_service.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_MOCKS_MOCK_MIGRATION_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_MOCKS_MOCK_MIGRATION_CONNECTION_H + +#include "google/cloud/bigquery/migration_connection.h" +#include + +namespace google { +namespace cloud { +namespace bigquery_mocks { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * A class to mock `MigrationServiceConnection`. + * + * Application developers may want to test their code with simulated responses, + * including errors, from an object of type `MigrationServiceClient`. To do so, + * construct an object of type `MigrationServiceClient` with an instance of this + * class. Then use the Google Test framework functions to program the behavior + * of this mock. + * + * @see [This example][bq-mock] for how to test your application with + * GoogleTest. While the example showcases types from the BigQuery library, the + * underlying principles apply for any pair of `*Client` and `*Connection`. + * + * [bq-mock]: @googleapis_dev_link{bigquery,bigquery-read-mock.html} + */ +class MockMigrationServiceConnection + : public bigquery::MigrationServiceConnection { + public: + MOCK_METHOD(Options, options, (), (override)); + + MOCK_METHOD( + StatusOr, + CreateMigrationWorkflow, + (google::cloud::bigquery::migration::v2:: + CreateMigrationWorkflowRequest const& request), + (override)); + + MOCK_METHOD( + StatusOr, + GetMigrationWorkflow, + (google::cloud::bigquery::migration::v2:: + GetMigrationWorkflowRequest const& request), + (override)); + + MOCK_METHOD( + StreamRange, + ListMigrationWorkflows, + (google::cloud::bigquery::migration::v2::ListMigrationWorkflowsRequest + request), + (override)); + + MOCK_METHOD(Status, DeleteMigrationWorkflow, + (google::cloud::bigquery::migration::v2:: + DeleteMigrationWorkflowRequest const& request), + (override)); + + MOCK_METHOD(Status, StartMigrationWorkflow, + (google::cloud::bigquery::migration::v2:: + StartMigrationWorkflowRequest const& request), + (override)); + + MOCK_METHOD( + StatusOr, + GetMigrationSubtask, + (google::cloud::bigquery::migration::v2::GetMigrationSubtaskRequest const& + request), + (override)); + + MOCK_METHOD( + StreamRange, + ListMigrationSubtasks, + (google::cloud::bigquery::migration::v2::ListMigrationSubtasksRequest + request), + (override)); +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquery_mocks +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERY_MOCKS_MOCK_MIGRATION_CONNECTION_H