diff --git a/ci/etc/expected_install_directories b/ci/etc/expected_install_directories index 0c56c5a7c7d54..b7a66c86f9171 100644 --- a/ci/etc/expected_install_directories +++ b/ci/etc/expected_install_directories @@ -148,6 +148,36 @@ ./include/google/cloud/bigquery/storage/v1 ./include/google/cloud/bigquery/storage/v1/internal ./include/google/cloud/bigquery/storage/v1/mocks +./include/google/cloud/bigquery/v2 +./include/google/cloud/bigquerycontrol +./include/google/cloud/bigquerycontrol/dataset +./include/google/cloud/bigquerycontrol/dataset/v2 +./include/google/cloud/bigquerycontrol/dataset/v2/internal +./include/google/cloud/bigquerycontrol/dataset/v2/mocks +./include/google/cloud/bigquerycontrol/job +./include/google/cloud/bigquerycontrol/job/v2 +./include/google/cloud/bigquerycontrol/job/v2/internal +./include/google/cloud/bigquerycontrol/job/v2/mocks +./include/google/cloud/bigquerycontrol/model +./include/google/cloud/bigquerycontrol/model/v2 +./include/google/cloud/bigquerycontrol/model/v2/internal +./include/google/cloud/bigquerycontrol/model/v2/mocks +./include/google/cloud/bigquerycontrol/project +./include/google/cloud/bigquerycontrol/project/v2 +./include/google/cloud/bigquerycontrol/project/v2/internal +./include/google/cloud/bigquerycontrol/project/v2/mocks +./include/google/cloud/bigquerycontrol/routine +./include/google/cloud/bigquerycontrol/routine/v2 +./include/google/cloud/bigquerycontrol/routine/v2/internal +./include/google/cloud/bigquerycontrol/routine/v2/mocks +./include/google/cloud/bigquerycontrol/row_access_policy +./include/google/cloud/bigquerycontrol/row_access_policy/v2 +./include/google/cloud/bigquerycontrol/row_access_policy/v2/internal +./include/google/cloud/bigquerycontrol/row_access_policy/v2/mocks +./include/google/cloud/bigquerycontrol/table +./include/google/cloud/bigquerycontrol/table/v2 +./include/google/cloud/bigquerycontrol/table/v2/internal +./include/google/cloud/bigquerycontrol/table/v2/mocks ./include/google/cloud/bigtable ./include/google/cloud/bigtable/admin ./include/google/cloud/bigtable/admin/internal @@ -1272,6 +1302,8 @@ ./lib64/cmake/google_cloud_cpp_beyondcorp_mocks ./lib64/cmake/google_cloud_cpp_bigquery ./lib64/cmake/google_cloud_cpp_bigquery_mocks +./lib64/cmake/google_cloud_cpp_bigquerycontrol +./lib64/cmake/google_cloud_cpp_bigquerycontrol_mocks ./lib64/cmake/google_cloud_cpp_bigtable ./lib64/cmake/google_cloud_cpp_bigtable_mocks ./lib64/cmake/google_cloud_cpp_billing diff --git a/cmake/GoogleCloudCppFeatures.cmake b/cmake/GoogleCloudCppFeatures.cmake index 4c235ae98c30e..d2c598c650db0 100644 --- a/cmake/GoogleCloudCppFeatures.cmake +++ b/cmake/GoogleCloudCppFeatures.cmake @@ -33,6 +33,7 @@ set(GOOGLE_CLOUD_CPP_NO_GRPC_FEATURES set(GOOGLE_CLOUD_CPP_EXPERIMENTAL_LIBRARIES # cmake-format: sort + "bigquerycontrol" # Some proto RPC comments indicate experimental methods. "pubsublite" # This is WIP, it needs a number of hand-crafted APIs. ) diff --git a/external/googleapis/protodeps/bigquerycontrol.deps b/external/googleapis/protodeps/bigquerycontrol.deps new file mode 100644 index 0000000000000..2e749051efbb4 --- /dev/null +++ b/external/googleapis/protodeps/bigquerycontrol.deps @@ -0,0 +1,6 @@ +@com_google_googleapis//google/api:annotations_proto +@com_google_googleapis//google/api:client_proto +@com_google_googleapis//google/api:field_behavior_proto +@com_google_googleapis//google/api:http_proto +@com_google_googleapis//google/api:launch_stage_proto +@com_google_googleapis//google/api:resource_proto diff --git a/external/googleapis/protolists/bigquerycontrol.list b/external/googleapis/protolists/bigquerycontrol.list new file mode 100644 index 0000000000000..52a2b31bcb804 --- /dev/null +++ b/external/googleapis/protolists/bigquerycontrol.list @@ -0,0 +1,44 @@ +@com_google_googleapis//google/cloud/bigquery/v2:biglake_config.proto +@com_google_googleapis//google/cloud/bigquery/v2:clustering.proto +@com_google_googleapis//google/cloud/bigquery/v2:data_format_options.proto +@com_google_googleapis//google/cloud/bigquery/v2:dataset.proto +@com_google_googleapis//google/cloud/bigquery/v2:dataset_reference.proto +@com_google_googleapis//google/cloud/bigquery/v2:decimal_target_types.proto +@com_google_googleapis//google/cloud/bigquery/v2:encryption_config.proto +@com_google_googleapis//google/cloud/bigquery/v2:error.proto +@com_google_googleapis//google/cloud/bigquery/v2:external_catalog_dataset_options.proto +@com_google_googleapis//google/cloud/bigquery/v2:external_catalog_table_options.proto +@com_google_googleapis//google/cloud/bigquery/v2:external_data_config.proto +@com_google_googleapis//google/cloud/bigquery/v2:external_dataset_reference.proto +@com_google_googleapis//google/cloud/bigquery/v2:file_set_specification_type.proto +@com_google_googleapis//google/cloud/bigquery/v2:hive_partitioning.proto +@com_google_googleapis//google/cloud/bigquery/v2:job.proto +@com_google_googleapis//google/cloud/bigquery/v2:job_config.proto +@com_google_googleapis//google/cloud/bigquery/v2:job_creation_reason.proto +@com_google_googleapis//google/cloud/bigquery/v2:job_reference.proto +@com_google_googleapis//google/cloud/bigquery/v2:job_stats.proto +@com_google_googleapis//google/cloud/bigquery/v2:job_status.proto +@com_google_googleapis//google/cloud/bigquery/v2:json_extension.proto +@com_google_googleapis//google/cloud/bigquery/v2:location_metadata.proto +@com_google_googleapis//google/cloud/bigquery/v2:map_target_type.proto +@com_google_googleapis//google/cloud/bigquery/v2:model.proto +@com_google_googleapis//google/cloud/bigquery/v2:model_reference.proto +@com_google_googleapis//google/cloud/bigquery/v2:partitioning_definition.proto +@com_google_googleapis//google/cloud/bigquery/v2:privacy_policy.proto +@com_google_googleapis//google/cloud/bigquery/v2:project.proto +@com_google_googleapis//google/cloud/bigquery/v2:query_parameter.proto +@com_google_googleapis//google/cloud/bigquery/v2:range_partitioning.proto +@com_google_googleapis//google/cloud/bigquery/v2:restriction_config.proto +@com_google_googleapis//google/cloud/bigquery/v2:routine.proto +@com_google_googleapis//google/cloud/bigquery/v2:routine_reference.proto +@com_google_googleapis//google/cloud/bigquery/v2:row_access_policy.proto +@com_google_googleapis//google/cloud/bigquery/v2:row_access_policy_reference.proto +@com_google_googleapis//google/cloud/bigquery/v2:session_info.proto +@com_google_googleapis//google/cloud/bigquery/v2:standard_sql.proto +@com_google_googleapis//google/cloud/bigquery/v2:system_variable.proto +@com_google_googleapis//google/cloud/bigquery/v2:table.proto +@com_google_googleapis//google/cloud/bigquery/v2:table_constraints.proto +@com_google_googleapis//google/cloud/bigquery/v2:table_reference.proto +@com_google_googleapis//google/cloud/bigquery/v2:table_schema.proto +@com_google_googleapis//google/cloud/bigquery/v2:time_partitioning.proto +@com_google_googleapis//google/cloud/bigquery/v2:udf_resource.proto diff --git a/google/cloud/bigquerycontrol/BUILD.bazel b/google/cloud/bigquerycontrol/BUILD.bazel new file mode 100644 index 0000000000000..a9f590820a752 --- /dev/null +++ b/google/cloud/bigquerycontrol/BUILD.bazel @@ -0,0 +1,31 @@ +# Copyright 2024 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. + +load("//bazel:gapic.bzl", "cc_gapic_library") + +package(default_visibility = ["//visibility:private"]) + +licenses(["notice"]) # Apache 2.0 + +service_dirs = ["table/v2/"] + +googleapis_deps = [ + "@com_google_googleapis//google/cloud/bigquery/v2:bigquerycontrol_cc_grpc", +] + +cc_gapic_library( + name = "bigquerycontrol", + googleapis_deps = googleapis_deps, + service_dirs = service_dirs, +) diff --git a/google/cloud/bigquerycontrol/CMakeLists.txt b/google/cloud/bigquerycontrol/CMakeLists.txt new file mode 100644 index 0000000000000..8b219cdd449c1 --- /dev/null +++ b/google/cloud/bigquerycontrol/CMakeLists.txt @@ -0,0 +1,37 @@ +# ~~~ +# Copyright 2024 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. +# ~~~ + +include(GoogleCloudCppLibrary) + +google_cloud_cpp_add_gapic_library(bigquerycontrol "BigQuery API" EXPERIMENTAL + SERVICE_DIRS "table/v2/") + +if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS) + add_executable(bigquerycontrol_quickstart "quickstart/quickstart.cc") + target_link_libraries( + bigquerycontrol_quickstart + PRIVATE google-cloud-cpp::experimental-bigquerycontrol) + google_cloud_cpp_add_common_options(bigquerycontrol_quickstart) + add_test( + NAME bigquerycontrol_quickstart + COMMAND + cmake -P "${PROJECT_SOURCE_DIR}/cmake/quickstart-runner.cmake" + $ GOOGLE_CLOUD_PROJECT + GOOGLE_CLOUD_CPP_TEST_REGION # EDIT HERE + ) + set_tests_properties(bigquerycontrol_quickstart + PROPERTIES LABELS "integration-test;quickstart") +endif () diff --git a/google/cloud/bigquerycontrol/README.md b/google/cloud/bigquerycontrol/README.md new file mode 100644 index 0000000000000..d9ad1a510cb3d --- /dev/null +++ b/google/cloud/bigquerycontrol/README.md @@ -0,0 +1,67 @@ +# BigQuery API C++ Client Library + +:construction: + +This directory contains an idiomatic C++ client library for the \[BigQuery +API\]\[cloud-service-docs\]. + +A data platform for customers to create, manage, share and query data. + +This library is **experimental**. Its APIs are subject to change without notice. + +Please, note that the Google Cloud C++ client libraries do **not** follow +[Semantic Versioning](https://semver.org/). + +## Quickstart + +The [quickstart/](quickstart/README.md) directory contains a minimal environment +to get started using this client library in a larger project. The following +"Hello World" program is used in this quickstart, and should give you a taste of +this library. + + + +```cc +#include "google/cloud/bigquerycontrol/table/v2/ EDIT HERE _client.h" +#include "google/cloud/location.h" +#include + +int main(int argc, char* argv[]) try { + if (argc != 3) { + std::cerr << "Usage: " << argv[0] << " project-id location-id\n"; + return 1; + } + + auto const location = google::cloud::Location(argv[1], argv[2]); + + namespace bigquerycontrol = ::google::cloud::bigquerycontrol_table_v2; + auto client = bigquerycontrol::ServiceClient( + bigquerycontrol::MakeServiceConnection()); // EDIT HERE + + for (auto r : client.List /*EDIT HERE*/ (location.FullName())) { + if (!r) throw std::move(r).status(); + std::cout << r->DebugString() << "\n"; + } + + return 0; +} catch (google::cloud::Status const& status) { + std::cerr << "google::cloud::Status thrown: " << status << "\n"; + return 1; +} +``` + + + +## More Information + +- Official documentation about the \[BigQuery API\]\[cloud-service-docs\] + service +- \[Reference doxygen documentation\]\[doxygen-link\] for each release of this + client library +- Detailed header comments in our \[public `.h`\]\[source-link\] files + +\[cloud-service-docs\]: https://cloud.google.com/bigquerycontrol \[EDIT HERE\] +\[doxygen-link\]: +https://cloud.google.com/cpp/docs/reference/bigquerycontrol/latest/ +\[source-link\]: +https://github.com/googleapis/google-cloud-cpp/tree/main/google/cloud/bigquerycontrol diff --git a/google/cloud/bigquerycontrol/dataset/v2/dataset_client.cc b/google/cloud/bigquerycontrol/dataset/v2/dataset_client.cc new file mode 100644 index 0000000000000..94cc1c46a9ea3 --- /dev/null +++ b/google/cloud/bigquerycontrol/dataset/v2/dataset_client.cc @@ -0,0 +1,91 @@ +// Copyright 2024 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/v2/dataset.proto + +#include "google/cloud/bigquerycontrol/dataset/v2/dataset_client.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_dataset_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +DatasetServiceClient::DatasetServiceClient( + std::shared_ptr connection, Options opts) + : connection_(std::move(connection)), + options_( + internal::MergeOptions(std::move(opts), connection_->options())) {} +DatasetServiceClient::~DatasetServiceClient() = default; + +StatusOr DatasetServiceClient::GetDataset( + google::cloud::bigquery::v2::GetDatasetRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->GetDataset(request); +} + +StatusOr +DatasetServiceClient::InsertDataset( + google::cloud::bigquery::v2::InsertDatasetRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->InsertDataset(request); +} + +StatusOr +DatasetServiceClient::PatchDataset( + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->PatchDataset(request); +} + +StatusOr +DatasetServiceClient::UpdateDataset( + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->UpdateDataset(request); +} + +Status DatasetServiceClient::DeleteDataset( + google::cloud::bigquery::v2::DeleteDatasetRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->DeleteDataset(request); +} + +StreamRange +DatasetServiceClient::ListDatasets( + google::cloud::bigquery::v2::ListDatasetsRequest request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->ListDatasets(std::move(request)); +} + +StatusOr +DatasetServiceClient::UndeleteDataset( + google::cloud::bigquery::v2::UndeleteDatasetRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->UndeleteDataset(request); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_dataset_v2 +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/dataset/v2/dataset_client.h b/google/cloud/bigquerycontrol/dataset/v2/dataset_client.h new file mode 100644 index 0000000000000..bf3d03db3e8b5 --- /dev/null +++ b/google/cloud/bigquerycontrol/dataset/v2/dataset_client.h @@ -0,0 +1,336 @@ +// Copyright 2024 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/v2/dataset.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_DATASET_CLIENT_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_DATASET_CLIENT_H + +#include "google/cloud/bigquerycontrol/dataset/v2/dataset_rest_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 +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_dataset_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// +/// This is an experimental RPC service definition for the BigQuery +/// Dataset Service. +/// +/// It should not be relied on for production use cases at this time. +/// +/// @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 DatasetServiceClient { + public: + explicit DatasetServiceClient( + std::shared_ptr connection, Options opts = {}); + ~DatasetServiceClient(); + + ///@{ + /// @name Copy and move support + DatasetServiceClient(DatasetServiceClient const&) = default; + DatasetServiceClient& operator=(DatasetServiceClient const&) = default; + DatasetServiceClient(DatasetServiceClient&&) = default; + DatasetServiceClient& operator=(DatasetServiceClient&&) = default; + ///@} + + ///@{ + /// @name Equality + friend bool operator==(DatasetServiceClient const& a, + DatasetServiceClient const& b) { + return a.connection_ == b.connection_; + } + friend bool operator!=(DatasetServiceClient const& a, + DatasetServiceClient const& b) { + return !(a == b); + } + ///@} + + // clang-format off + /// + /// Returns the dataset specified by datasetID. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.GetDatasetRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return the result of the RPC. The response message type + /// ([google.cloud.bigquery.v2.Dataset]) + /// is mapped to a C++ class using the [Protobuf mapping rules]. + /// If the request fails, the [`StatusOr`] contains the error details. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.Dataset]: @googleapis_reference_link{google/cloud/bigquery/v2/dataset.proto#L206} + /// [google.cloud.bigquery.v2.GetDatasetRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/dataset.proto#L455} + /// + // clang-format on + StatusOr GetDataset( + google::cloud::bigquery::v2::GetDatasetRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Creates a new empty dataset. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.InsertDatasetRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return the result of the RPC. The response message type + /// ([google.cloud.bigquery.v2.Dataset]) + /// is mapped to a C++ class using the [Protobuf mapping rules]. + /// If the request fails, the [`StatusOr`] contains the error details. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.Dataset]: @googleapis_reference_link{google/cloud/bigquery/v2/dataset.proto#L206} + /// [google.cloud.bigquery.v2.InsertDatasetRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/dataset.proto#L486} + /// + // clang-format on + StatusOr InsertDataset( + google::cloud::bigquery::v2::InsertDatasetRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Updates information in an existing dataset. The update method replaces the + /// entire dataset resource, whereas the patch method only replaces fields that + /// are provided in the submitted dataset resource. + /// This method supports RFC5789 patch semantics. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return the result of the RPC. The response message type + /// ([google.cloud.bigquery.v2.Dataset]) + /// is mapped to a C++ class using the [Protobuf mapping rules]. + /// If the request fails, the [`StatusOr`] contains the error details. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.Dataset]: @googleapis_reference_link{google/cloud/bigquery/v2/dataset.proto#L206} + /// [google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/dataset.proto#L495} + /// + // clang-format on + StatusOr PatchDataset( + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Updates information in an existing dataset. The update method replaces the + /// entire dataset resource, whereas the patch method only replaces fields that + /// are provided in the submitted dataset resource. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return the result of the RPC. The response message type + /// ([google.cloud.bigquery.v2.Dataset]) + /// is mapped to a C++ class using the [Protobuf mapping rules]. + /// If the request fails, the [`StatusOr`] contains the error details. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.Dataset]: @googleapis_reference_link{google/cloud/bigquery/v2/dataset.proto#L206} + /// [google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/dataset.proto#L495} + /// + // clang-format on + StatusOr UpdateDataset( + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Deletes the dataset specified by the datasetId value. Before you can delete + /// a dataset, you must delete all its tables, either manually or by specifying + /// deleteContents. Immediately after deletion, you can create another dataset + /// with the same name. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.DeleteDatasetRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return a [`Status`] object. If the request failed, the + /// status contains the details of the failure. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.DeleteDatasetRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/dataset.proto#L508} + /// + // clang-format on + Status DeleteDataset( + google::cloud::bigquery::v2::DeleteDatasetRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Lists all datasets in the specified project to which the user has been + /// granted the READER dataset role. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.ListDatasetsRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return a [StreamRange](@ref google::cloud::StreamRange) + /// to iterate of the results. See the documentation of this type for + /// details. In brief, this class has `begin()` and `end()` member + /// functions returning a iterator class meeting the + /// [input iterator requirements]. The value type for this iterator is a + /// [`StatusOr`] as the iteration may fail even after some values are + /// retrieved successfully, for example, if there is a network disconnect. + /// An empty set of results does not indicate an error, it indicates + /// that there are no resources meeting the request criteria. + /// On a successful iteration the `StatusOr` contains elements of type + /// [google.cloud.bigquery.v2.ListFormatDataset], or rather, + /// the C++ class generated by Protobuf from that type. Please consult the + /// Protobuf documentation for details on the [Protobuf mapping rules]. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.ListDatasetsRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/dataset.proto#L521} + /// [google.cloud.bigquery.v2.ListFormatDataset]: @googleapis_reference_link{google/cloud/bigquery/v2/dataset.proto#L548} + /// + // clang-format on + StreamRange ListDatasets( + google::cloud::bigquery::v2::ListDatasetsRequest request, + Options opts = {}); + + // clang-format off + /// + /// Undeletes a dataset which is within time travel window based on datasetId. + /// If a time is specified, the dataset version deleted at that time is + /// undeleted, else the last live version is undeleted. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.UndeleteDatasetRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return the result of the RPC. The response message type + /// ([google.cloud.bigquery.v2.Dataset]) + /// is mapped to a C++ class using the [Protobuf mapping rules]. + /// If the request fails, the [`StatusOr`] contains the error details. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.Dataset]: @googleapis_reference_link{google/cloud/bigquery/v2/dataset.proto#L206} + /// [google.cloud.bigquery.v2.UndeleteDatasetRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/dataset.proto#L601} + /// + // clang-format on + StatusOr UndeleteDataset( + google::cloud::bigquery::v2::UndeleteDatasetRequest const& request, + Options opts = {}); + + private: + std::shared_ptr connection_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_dataset_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_DATASET_CLIENT_H diff --git a/google/cloud/bigquerycontrol/dataset/v2/dataset_connection.cc b/google/cloud/bigquerycontrol/dataset/v2/dataset_connection.cc new file mode 100644 index 0000000000000..451932b14f450 --- /dev/null +++ b/google/cloud/bigquerycontrol/dataset/v2/dataset_connection.cc @@ -0,0 +1,85 @@ +// Copyright 2024 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/v2/dataset.proto + +#include "google/cloud/bigquerycontrol/dataset/v2/dataset_connection.h" +#include "google/cloud/bigquerycontrol/dataset/v2/dataset_options.h" +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_option_defaults.h" +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_tracing_connection.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 "google/cloud/internal/unified_grpc_credentials.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_dataset_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +DatasetServiceConnection::~DatasetServiceConnection() = default; + +StatusOr +DatasetServiceConnection::GetDataset( + google::cloud::bigquery::v2::GetDatasetRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +DatasetServiceConnection::InsertDataset( + google::cloud::bigquery::v2::InsertDatasetRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +DatasetServiceConnection::PatchDataset( + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +DatasetServiceConnection::UpdateDataset( + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +Status DatasetServiceConnection::DeleteDataset( + google::cloud::bigquery::v2::DeleteDatasetRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StreamRange +DatasetServiceConnection::ListDatasets( + google::cloud::bigquery::v2:: + ListDatasetsRequest) { // NOLINT(performance-unnecessary-value-param) + return google::cloud::internal::MakeUnimplementedPaginationRange< + StreamRange>(); +} + +StatusOr +DatasetServiceConnection::UndeleteDataset( + google::cloud::bigquery::v2::UndeleteDatasetRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_dataset_v2 +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/dataset/v2/dataset_connection.h b/google/cloud/bigquerycontrol/dataset/v2/dataset_connection.h new file mode 100644 index 0000000000000..7188b8a915576 --- /dev/null +++ b/google/cloud/bigquerycontrol/dataset/v2/dataset_connection.h @@ -0,0 +1,214 @@ +// Copyright 2024 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/v2/dataset.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_DATASET_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_DATASET_CONNECTION_H + +#include "google/cloud/bigquerycontrol/dataset/v2/dataset_connection_idempotency_policy.h" +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_retry_traits.h" +#include "google/cloud/backoff_policy.h" +#include "google/cloud/experimental_tag.h" +#include "google/cloud/internal/retry_policy_impl.h" +#include "google/cloud/options.h" +#include "google/cloud/status_or.h" +#include "google/cloud/stream_range.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_dataset_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// The retry policy for `DatasetServiceConnection`. +class DatasetServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `DatasetServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DatasetServiceLimitedErrorCountRetryPolicy + : public DatasetServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit DatasetServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + DatasetServiceLimitedErrorCountRetryPolicy( + DatasetServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : DatasetServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + DatasetServiceLimitedErrorCountRetryPolicy( + DatasetServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : DatasetServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = DatasetServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + bigquerycontrol_dataset_v2_internal::DatasetServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `DatasetServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class DatasetServiceLimitedTimeRetryPolicy : public DatasetServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit DatasetServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + DatasetServiceLimitedTimeRetryPolicy( + DatasetServiceLimitedTimeRetryPolicy&& rhs) noexcept + : DatasetServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + DatasetServiceLimitedTimeRetryPolicy( + DatasetServiceLimitedTimeRetryPolicy const& rhs) noexcept + : DatasetServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = DatasetServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + bigquerycontrol_dataset_v2_internal::DatasetServiceRetryTraits> + impl_; +}; + +/** + * The `DatasetServiceConnection` object for `DatasetServiceClient`. + * + * This interface defines virtual methods for each of the user-facing overload + * sets in `DatasetServiceClient`. This allows users to inject custom behavior + * (e.g., with a Google Mock object) when writing tests that use objects of type + * `DatasetServiceClient`. + * + * To create a concrete instance, see `MakeDatasetServiceConnection()`. + * + * For mocking, see + * `bigquerycontrol_dataset_v2_mocks::MockDatasetServiceConnection`. + */ +class DatasetServiceConnection { + public: + virtual ~DatasetServiceConnection() = 0; + + virtual Options options() { return Options{}; } + + virtual StatusOr GetDataset( + google::cloud::bigquery::v2::GetDatasetRequest const& request); + + virtual StatusOr InsertDataset( + google::cloud::bigquery::v2::InsertDatasetRequest const& request); + + virtual StatusOr PatchDataset( + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request); + + virtual StatusOr UpdateDataset( + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request); + + virtual Status DeleteDataset( + google::cloud::bigquery::v2::DeleteDatasetRequest const& request); + + virtual StreamRange + ListDatasets(google::cloud::bigquery::v2::ListDatasetsRequest request); + + virtual StatusOr UndeleteDataset( + google::cloud::bigquery::v2::UndeleteDatasetRequest const& request); +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_dataset_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_DATASET_CONNECTION_H diff --git a/google/cloud/bigquerycontrol/dataset/v2/dataset_connection_idempotency_policy.cc b/google/cloud/bigquerycontrol/dataset/v2/dataset_connection_idempotency_policy.cc new file mode 100644 index 0000000000000..32e6c8cec0903 --- /dev/null +++ b/google/cloud/bigquerycontrol/dataset/v2/dataset_connection_idempotency_policy.cc @@ -0,0 +1,80 @@ +// Copyright 2024 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/v2/dataset.proto + +#include "google/cloud/bigquerycontrol/dataset/v2/dataset_connection_idempotency_policy.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_dataset_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +using ::google::cloud::Idempotency; + +DatasetServiceConnectionIdempotencyPolicy:: + ~DatasetServiceConnectionIdempotencyPolicy() = default; + +std::unique_ptr +DatasetServiceConnectionIdempotencyPolicy::clone() const { + return std::make_unique(*this); +} + +Idempotency DatasetServiceConnectionIdempotencyPolicy::GetDataset( + google::cloud::bigquery::v2::GetDatasetRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency DatasetServiceConnectionIdempotencyPolicy::InsertDataset( + google::cloud::bigquery::v2::InsertDatasetRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency DatasetServiceConnectionIdempotencyPolicy::PatchDataset( + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency DatasetServiceConnectionIdempotencyPolicy::UpdateDataset( + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency DatasetServiceConnectionIdempotencyPolicy::DeleteDataset( + google::cloud::bigquery::v2::DeleteDatasetRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency DatasetServiceConnectionIdempotencyPolicy::ListDatasets( + google::cloud::bigquery::v2::ListDatasetsRequest) { // NOLINT + return Idempotency::kIdempotent; +} + +Idempotency DatasetServiceConnectionIdempotencyPolicy::UndeleteDataset( + google::cloud::bigquery::v2::UndeleteDatasetRequest const&) { + return Idempotency::kNonIdempotent; +} + +std::unique_ptr +MakeDefaultDatasetServiceConnectionIdempotencyPolicy() { + return std::make_unique(); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_dataset_v2 +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/dataset/v2/dataset_connection_idempotency_policy.h b/google/cloud/bigquerycontrol/dataset/v2/dataset_connection_idempotency_policy.h new file mode 100644 index 0000000000000..64534f36bc809 --- /dev/null +++ b/google/cloud/bigquerycontrol/dataset/v2/dataset_connection_idempotency_policy.h @@ -0,0 +1,70 @@ +// Copyright 2024 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/v2/dataset.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_DATASET_CONNECTION_IDEMPOTENCY_POLICY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_DATASET_CONNECTION_IDEMPOTENCY_POLICY_H + +#include "google/cloud/idempotency.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_dataset_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class DatasetServiceConnectionIdempotencyPolicy { + public: + virtual ~DatasetServiceConnectionIdempotencyPolicy(); + + /// Create a new copy of this object. + virtual std::unique_ptr clone() + const; + + virtual google::cloud::Idempotency GetDataset( + google::cloud::bigquery::v2::GetDatasetRequest const& request); + + virtual google::cloud::Idempotency InsertDataset( + google::cloud::bigquery::v2::InsertDatasetRequest const& request); + + virtual google::cloud::Idempotency PatchDataset( + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request); + + virtual google::cloud::Idempotency UpdateDataset( + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request); + + virtual google::cloud::Idempotency DeleteDataset( + google::cloud::bigquery::v2::DeleteDatasetRequest const& request); + + virtual google::cloud::Idempotency ListDatasets( + google::cloud::bigquery::v2::ListDatasetsRequest request); + + virtual google::cloud::Idempotency UndeleteDataset( + google::cloud::bigquery::v2::UndeleteDatasetRequest const& request); +}; + +std::unique_ptr +MakeDefaultDatasetServiceConnectionIdempotencyPolicy(); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_dataset_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_DATASET_CONNECTION_IDEMPOTENCY_POLICY_H diff --git a/google/cloud/bigquerycontrol/dataset/v2/dataset_options.h b/google/cloud/bigquerycontrol/dataset/v2/dataset_options.h new file mode 100644 index 0000000000000..30a763bb94215 --- /dev/null +++ b/google/cloud/bigquerycontrol/dataset/v2/dataset_options.h @@ -0,0 +1,76 @@ +// Copyright 2024 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/v2/dataset.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_DATASET_OPTIONS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_DATASET_OPTIONS_H + +#include "google/cloud/bigquerycontrol/dataset/v2/dataset_connection.h" +#include "google/cloud/bigquerycontrol/dataset/v2/dataset_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 bigquerycontrol_dataset_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * Use with `google::cloud::Options` to configure the retry policy. + * + * @ingroup google-cloud-bigquerycontrol-options + */ +struct DatasetServiceRetryPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure the backoff policy. + * + * @ingroup google-cloud-bigquerycontrol-options + */ +struct DatasetServiceBackoffPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure which operations are retried. + * + * @ingroup google-cloud-bigquerycontrol-options + */ +struct DatasetServiceConnectionIdempotencyPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * The options applicable to DatasetService. + * + * @ingroup google-cloud-bigquerycontrol-options + */ +using DatasetServicePolicyOptionList = + OptionList; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_dataset_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_DATASET_OPTIONS_H diff --git a/google/cloud/bigquerycontrol/dataset/v2/dataset_rest_connection.cc b/google/cloud/bigquerycontrol/dataset/v2/dataset_rest_connection.cc new file mode 100644 index 0000000000000..dd5a7fb5021fa --- /dev/null +++ b/google/cloud/bigquerycontrol/dataset/v2/dataset_rest_connection.cc @@ -0,0 +1,60 @@ +// Copyright 2024 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/v2/dataset.proto + +#include "google/cloud/bigquerycontrol/dataset/v2/dataset_rest_connection.h" +#include "google/cloud/bigquerycontrol/dataset/v2/dataset_options.h" +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_option_defaults.h" +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_connection_impl.h" +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_stub_factory.h" +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_tracing_connection.h" +#include "google/cloud/common_options.h" +#include "google/cloud/credentials.h" +#include "google/cloud/internal/rest_background_threads_impl.h" +#include "google/cloud/internal/rest_options.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_dataset_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr MakeDatasetServiceConnectionRest( + Options options) { + internal::CheckExpectedOptions< + CommonOptionList, RestOptionList, UnifiedCredentialsOptionList, + rest_internal::TargetApiVersionOption, DatasetServicePolicyOptionList>( + options, __func__); + options = bigquerycontrol_dataset_v2_internal::DatasetServiceDefaultOptions( + std::move(options)); + auto background = std::make_unique< + rest_internal::AutomaticallyCreatedRestBackgroundThreads>(); + auto stub = + bigquerycontrol_dataset_v2_internal::CreateDefaultDatasetServiceRestStub( + options); + return bigquerycontrol_dataset_v2_internal:: + MakeDatasetServiceTracingConnection( + std::make_shared( + std::move(background), std::move(stub), std::move(options))); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_dataset_v2 +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/dataset/v2/dataset_rest_connection.h b/google/cloud/bigquerycontrol/dataset/v2/dataset_rest_connection.h new file mode 100644 index 0000000000000..5470702891664 --- /dev/null +++ b/google/cloud/bigquerycontrol/dataset/v2/dataset_rest_connection.h @@ -0,0 +1,64 @@ +// Copyright 2024 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/v2/dataset.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_DATASET_REST_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_DATASET_REST_CONNECTION_H + +#include "google/cloud/bigquerycontrol/dataset/v2/dataset_connection.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_dataset_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * A factory function to construct an object of type `DatasetServiceConnection` + * that uses REST over HTTP as transport in lieu of gRPC. REST transport should + * only be used for services that do not support gRPC or if the existing network + * configuration precludes using gRPC. + * + * The returned connection object should not be used directly; instead it + * should be passed as an argument to the constructor of DatasetServiceClient. + * + * The optional @p options argument may be used to configure aspects of the + * returned `DatasetServiceConnection`. Expected options are any of the types in + * the following option lists: + * + * - `google::cloud::CommonOptionList` + * - `google::cloud::RestOptionList` + * - `google::cloud::UnifiedCredentialsOptionList` + * - `google::cloud::bigquerycontrol_dataset_v2::DatasetServicePolicyOptionList` + * + * @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 `DatasetServiceConnection` created by + * this function. + */ +std::shared_ptr MakeDatasetServiceConnectionRest( + Options options = {}); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_dataset_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_DATASET_REST_CONNECTION_H diff --git a/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_option_defaults.cc b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_option_defaults.cc new file mode 100644 index 0000000000000..7ce107cc616e4 --- /dev/null +++ b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_option_defaults.cc @@ -0,0 +1,70 @@ +// Copyright 2024 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/v2/dataset.proto + +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_option_defaults.h" +#include "google/cloud/bigquerycontrol/dataset/v2/dataset_connection.h" +#include "google/cloud/bigquerycontrol/dataset/v2/dataset_options.h" +#include "google/cloud/internal/populate_common_options.h" +#include "google/cloud/internal/populate_grpc_options.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_dataset_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +namespace { +auto constexpr kBackoffScaling = 2.0; +} // namespace + +Options DatasetServiceDefaultOptions(Options options) { + options = internal::PopulateCommonOptions( + std::move(options), "GOOGLE_CLOUD_CPP_DATASET_SERVICE_ENDPOINT", "", + "GOOGLE_CLOUD_CPP_DATASET_SERVICE_AUTHORITY", "bigquery.googleapis.com"); + options = internal::PopulateGrpcOptions(std::move(options)); + if (!options.has< + bigquerycontrol_dataset_v2::DatasetServiceRetryPolicyOption>()) { + options.set( + bigquerycontrol_dataset_v2::DatasetServiceLimitedTimeRetryPolicy( + std::chrono::minutes(30)) + .clone()); + } + if (!options.has< + bigquerycontrol_dataset_v2::DatasetServiceBackoffPolicyOption>()) { + options.set( + ExponentialBackoffPolicy( + std::chrono::seconds(0), std::chrono::seconds(1), + std::chrono::minutes(5), kBackoffScaling, kBackoffScaling) + .clone()); + } + if (!options.has()) { + options.set( + bigquerycontrol_dataset_v2:: + MakeDefaultDatasetServiceConnectionIdempotencyPolicy()); + } + + return options; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_dataset_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_option_defaults.h b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_option_defaults.h new file mode 100644 index 0000000000000..92a6aedba7902 --- /dev/null +++ b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_option_defaults.h @@ -0,0 +1,37 @@ +// Copyright 2024 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/v2/dataset.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_INTERNAL_DATASET_OPTION_DEFAULTS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_INTERNAL_DATASET_OPTION_DEFAULTS_H + +#include "google/cloud/options.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace bigquerycontrol_dataset_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +Options DatasetServiceDefaultOptions(Options options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_dataset_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_INTERNAL_DATASET_OPTION_DEFAULTS_H diff --git a/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_connection_impl.cc b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_connection_impl.cc new file mode 100644 index 0000000000000..cef8f05a52f5c --- /dev/null +++ b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_connection_impl.cc @@ -0,0 +1,169 @@ +// Copyright 2024 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/v2/dataset.proto + +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_connection_impl.h" +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_stub_factory.h" +#include "google/cloud/common_options.h" +#include "google/cloud/credentials.h" +#include "google/cloud/internal/pagination_range.h" +#include "google/cloud/internal/rest_retry_loop.h" +#include "google/cloud/rest_options.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_dataset_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +DatasetServiceRestConnectionImpl::DatasetServiceRestConnectionImpl( + std::unique_ptr background, + std::shared_ptr + stub, + Options options) + : background_(std::move(background)), + stub_(std::move(stub)), + options_(internal::MergeOptions(std::move(options), + DatasetServiceConnection::options())) {} + +StatusOr +DatasetServiceRestConnectionImpl::GetDataset( + google::cloud::bigquery::v2::GetDatasetRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::rest_internal::RestRetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->GetDataset(request), + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::GetDatasetRequest const& request) { + return stub_->GetDataset(rest_context, options, request); + }, + *current, request, __func__); +} + +StatusOr +DatasetServiceRestConnectionImpl::InsertDataset( + google::cloud::bigquery::v2::InsertDatasetRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::rest_internal::RestRetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->InsertDataset(request), + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::InsertDatasetRequest const& request) { + return stub_->InsertDataset(rest_context, options, request); + }, + *current, request, __func__); +} + +StatusOr +DatasetServiceRestConnectionImpl::PatchDataset( + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::rest_internal::RestRetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->PatchDataset(request), + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& + request) { + return stub_->PatchDataset(rest_context, options, request); + }, + *current, request, __func__); +} + +StatusOr +DatasetServiceRestConnectionImpl::UpdateDataset( + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::rest_internal::RestRetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->UpdateDataset(request), + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& + request) { + return stub_->UpdateDataset(rest_context, options, request); + }, + *current, request, __func__); +} + +Status DatasetServiceRestConnectionImpl::DeleteDataset( + google::cloud::bigquery::v2::DeleteDatasetRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::rest_internal::RestRetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->DeleteDataset(request), + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::DeleteDatasetRequest const& request) { + return stub_->DeleteDataset(rest_context, options, request); + }, + *current, request, __func__); +} + +StreamRange +DatasetServiceRestConnectionImpl::ListDatasets( + google::cloud::bigquery::v2::ListDatasetsRequest request) { + request.clear_page_token(); + auto current = google::cloud::internal::SaveCurrentOptions(); + auto idempotency = idempotency_policy(*current)->ListDatasets(request); + char const* function_name = __func__; + return google::cloud::internal::MakePaginationRange< + StreamRange>( + current, std::move(request), + [idempotency, function_name, stub = stub_, + retry = std::shared_ptr< + bigquerycontrol_dataset_v2::DatasetServiceRetryPolicy>( + retry_policy(*current)), + backoff = std::shared_ptr(backoff_policy(*current))]( + Options const& options, + google::cloud::bigquery::v2::ListDatasetsRequest const& r) { + return google::cloud::rest_internal::RestRetryLoop( + retry->clone(), backoff->clone(), idempotency, + [stub](rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListDatasetsRequest const& + request) { + return stub->ListDatasets(rest_context, options, request); + }, + options, r, function_name); + }, + [](google::cloud::bigquery::v2::DatasetList r) { + std::vector result( + r.datasets().size()); + auto& messages = *r.mutable_datasets(); + std::move(messages.begin(), messages.end(), result.begin()); + return result; + }); +} + +StatusOr +DatasetServiceRestConnectionImpl::UndeleteDataset( + google::cloud::bigquery::v2::UndeleteDatasetRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::rest_internal::RestRetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->UndeleteDataset(request), + [this]( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::UndeleteDatasetRequest const& request) { + return stub_->UndeleteDataset(rest_context, options, request); + }, + *current, request, __func__); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_dataset_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_connection_impl.h b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_connection_impl.h new file mode 100644 index 0000000000000..2ea0db6daa81b --- /dev/null +++ b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_connection_impl.h @@ -0,0 +1,113 @@ +// Copyright 2024 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/v2/dataset.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_INTERNAL_DATASET_REST_CONNECTION_IMPL_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_INTERNAL_DATASET_REST_CONNECTION_IMPL_H + +#include "google/cloud/bigquerycontrol/dataset/v2/dataset_connection.h" +#include "google/cloud/bigquerycontrol/dataset/v2/dataset_connection_idempotency_policy.h" +#include "google/cloud/bigquerycontrol/dataset/v2/dataset_options.h" +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_stub.h" +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_retry_traits.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 bigquerycontrol_dataset_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class DatasetServiceRestConnectionImpl + : public bigquerycontrol_dataset_v2::DatasetServiceConnection { + public: + ~DatasetServiceRestConnectionImpl() override = default; + + DatasetServiceRestConnectionImpl( + std::unique_ptr background, + std::shared_ptr< + bigquerycontrol_dataset_v2_internal::DatasetServiceRestStub> + stub, + Options options); + + Options options() override { return options_; } + + StatusOr GetDataset( + google::cloud::bigquery::v2::GetDatasetRequest const& request) override; + + StatusOr InsertDataset( + google::cloud::bigquery::v2::InsertDatasetRequest const& request) + override; + + StatusOr PatchDataset( + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request) + override; + + StatusOr UpdateDataset( + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request) + override; + + Status DeleteDataset(google::cloud::bigquery::v2::DeleteDatasetRequest const& + request) override; + + StreamRange ListDatasets( + google::cloud::bigquery::v2::ListDatasetsRequest request) override; + + StatusOr UndeleteDataset( + google::cloud::bigquery::v2::UndeleteDatasetRequest const& request) + override; + + private: + static std::unique_ptr + retry_policy(Options const& options) { + return options + .get() + ->clone(); + } + + static std::unique_ptr backoff_policy(Options const& options) { + return options + .get() + ->clone(); + } + + static std::unique_ptr< + bigquerycontrol_dataset_v2::DatasetServiceConnectionIdempotencyPolicy> + idempotency_policy(Options const& options) { + return options + .get() + ->clone(); + } + + std::unique_ptr background_; + std::shared_ptr + stub_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_dataset_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_INTERNAL_DATASET_REST_CONNECTION_IMPL_H diff --git a/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_logging_decorator.cc b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_logging_decorator.cc new file mode 100644 index 0000000000000..0da693aea17ec --- /dev/null +++ b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_logging_decorator.cc @@ -0,0 +1,126 @@ +// Copyright 2024 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/v2/dataset.proto + +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_logging_decorator.h" +#include "google/cloud/internal/log_wrapper.h" +#include "google/cloud/status_or.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_dataset_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +DatasetServiceRestLogging::DatasetServiceRestLogging( + 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 +DatasetServiceRestLogging::GetDataset( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::GetDatasetRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::GetDatasetRequest const& request) { + return child_->GetDataset(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +StatusOr +DatasetServiceRestLogging::InsertDataset( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::InsertDatasetRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::InsertDatasetRequest const& request) { + return child_->InsertDataset(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +StatusOr +DatasetServiceRestLogging::PatchDataset( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& + request) { + return child_->PatchDataset(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +StatusOr +DatasetServiceRestLogging::UpdateDataset( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& + request) { + return child_->UpdateDataset(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +Status DatasetServiceRestLogging::DeleteDataset( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::DeleteDatasetRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::DeleteDatasetRequest const& request) { + return child_->DeleteDataset(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +StatusOr +DatasetServiceRestLogging::ListDatasets( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::ListDatasetsRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::ListDatasetsRequest const& request) { + return child_->ListDatasets(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +StatusOr +DatasetServiceRestLogging::UndeleteDataset( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::UndeleteDatasetRequest const& request) { + return google::cloud::internal::LogWrapper( + [this]( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::UndeleteDatasetRequest const& request) { + return child_->UndeleteDataset(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_dataset_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_logging_decorator.h b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_logging_decorator.h new file mode 100644 index 0000000000000..f48bf8862d3ca --- /dev/null +++ b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_logging_decorator.h @@ -0,0 +1,94 @@ +// Copyright 2024 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/v2/dataset.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_INTERNAL_DATASET_REST_LOGGING_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_INTERNAL_DATASET_REST_LOGGING_DECORATOR_H + +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_stub.h" +#include "google/cloud/future.h" +#include "google/cloud/internal/rest_context.h" +#include "google/cloud/tracing_options.h" +#include "google/cloud/version.h" +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_dataset_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class DatasetServiceRestLogging : public DatasetServiceRestStub { + public: + ~DatasetServiceRestLogging() override = default; + DatasetServiceRestLogging(std::shared_ptr child, + TracingOptions tracing_options, + std::set components); + + StatusOr GetDataset( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetDatasetRequest const& request) override; + + StatusOr InsertDataset( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::InsertDatasetRequest const& request) + override; + + StatusOr PatchDataset( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request) + override; + + StatusOr UpdateDataset( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request) + override; + + Status DeleteDataset(google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::DeleteDatasetRequest const& + request) override; + + StatusOr ListDatasets( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListDatasetsRequest const& request) override; + + StatusOr UndeleteDataset( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UndeleteDatasetRequest const& request) + override; + + private: + std::shared_ptr child_; + TracingOptions tracing_options_; + std::set components_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_dataset_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_INTERNAL_DATASET_REST_LOGGING_DECORATOR_H diff --git a/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_metadata_decorator.cc b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_metadata_decorator.cc new file mode 100644 index 0000000000000..28a7b2157714a --- /dev/null +++ b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_metadata_decorator.cc @@ -0,0 +1,107 @@ +// Copyright 2024 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/v2/dataset.proto + +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_metadata_decorator.h" +#include "google/cloud/internal/absl_str_cat_quiet.h" +#include "google/cloud/internal/api_client_header.h" +#include "google/cloud/internal/rest_set_metadata.h" +#include "google/cloud/status_or.h" +#include "absl/strings/str_format.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_dataset_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +DatasetServiceRestMetadata::DatasetServiceRestMetadata( + std::shared_ptr child, + std::string api_client_header) + : child_(std::move(child)), + api_client_header_( + api_client_header.empty() + ? google::cloud::internal::GeneratedLibClientHeader() + : std::move(api_client_header)) {} + +StatusOr +DatasetServiceRestMetadata::GetDataset( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::GetDatasetRequest const& request) { + SetMetadata(rest_context, options); + return child_->GetDataset(rest_context, options, request); +} + +StatusOr +DatasetServiceRestMetadata::InsertDataset( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::InsertDatasetRequest const& request) { + SetMetadata(rest_context, options); + return child_->InsertDataset(rest_context, options, request); +} + +StatusOr +DatasetServiceRestMetadata::PatchDataset( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request) { + SetMetadata(rest_context, options); + return child_->PatchDataset(rest_context, options, request); +} + +StatusOr +DatasetServiceRestMetadata::UpdateDataset( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request) { + SetMetadata(rest_context, options); + return child_->UpdateDataset(rest_context, options, request); +} + +Status DatasetServiceRestMetadata::DeleteDataset( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::DeleteDatasetRequest const& request) { + SetMetadata(rest_context, options); + return child_->DeleteDataset(rest_context, options, request); +} + +StatusOr +DatasetServiceRestMetadata::ListDatasets( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::ListDatasetsRequest const& request) { + SetMetadata(rest_context, options); + return child_->ListDatasets(rest_context, options, request); +} + +StatusOr +DatasetServiceRestMetadata::UndeleteDataset( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::UndeleteDatasetRequest const& request) { + SetMetadata(rest_context, options); + return child_->UndeleteDataset(rest_context, options, request); +} + +void DatasetServiceRestMetadata::SetMetadata( + rest_internal::RestContext& rest_context, Options const& options, + std::vector const& params) { + google::cloud::rest_internal::SetMetadata(rest_context, options, params, + api_client_header_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_dataset_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_metadata_decorator.h b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_metadata_decorator.h new file mode 100644 index 0000000000000..159b5cff3495e --- /dev/null +++ b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_metadata_decorator.h @@ -0,0 +1,95 @@ +// Copyright 2024 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/v2/dataset.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_INTERNAL_DATASET_REST_METADATA_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_INTERNAL_DATASET_REST_METADATA_DECORATOR_H + +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_stub.h" +#include "google/cloud/future.h" +#include "google/cloud/rest_options.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_dataset_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class DatasetServiceRestMetadata : public DatasetServiceRestStub { + public: + ~DatasetServiceRestMetadata() override = default; + explicit DatasetServiceRestMetadata( + std::shared_ptr child, + std::string api_client_header = ""); + + StatusOr GetDataset( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetDatasetRequest const& request) override; + + StatusOr InsertDataset( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::InsertDatasetRequest const& request) + override; + + StatusOr PatchDataset( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request) + override; + + StatusOr UpdateDataset( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request) + override; + + Status DeleteDataset(google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::DeleteDatasetRequest const& + request) override; + + StatusOr ListDatasets( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListDatasetsRequest const& request) override; + + StatusOr UndeleteDataset( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UndeleteDatasetRequest const& request) + override; + + private: + void SetMetadata(rest_internal::RestContext& rest_context, + Options const& options, + std::vector const& params = {}); + + std::shared_ptr child_; + std::string api_client_header_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_dataset_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_INTERNAL_DATASET_REST_METADATA_DECORATOR_H diff --git a/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_stub.cc b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_stub.cc new file mode 100644 index 0000000000000..105325c4d6f12 --- /dev/null +++ b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_stub.cc @@ -0,0 +1,141 @@ +// Copyright 2024 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/v2/dataset.proto + +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_stub.h" +#include "google/cloud/common_options.h" +#include "google/cloud/internal/absl_str_cat_quiet.h" +#include "google/cloud/internal/rest_stub_helpers.h" +#include "google/cloud/status_or.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_dataset_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +DefaultDatasetServiceRestStub::DefaultDatasetServiceRestStub(Options options) + : service_(rest_internal::MakePooledRestClient( + options.get(), options)), + options_(std::move(options)) {} + +DefaultDatasetServiceRestStub::DefaultDatasetServiceRestStub( + std::shared_ptr service, Options options) + : service_(std::move(service)), options_(std::move(options)) {} + +StatusOr +DefaultDatasetServiceRestStub::GetDataset( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetDatasetRequest const& request) { + return rest_internal::Get( + *service_, rest_context, request, false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "datasets", "/", + request.dataset_id()), + rest_internal::TrimEmptyQueryParameters({std::make_pair( + "dataset_view", std::to_string(request.dataset_view()))})); +} + +StatusOr +DefaultDatasetServiceRestStub::InsertDataset( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::InsertDatasetRequest const& request) { + return rest_internal::Post( + *service_, rest_context, request.dataset(), false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "datasets")); +} + +StatusOr +DefaultDatasetServiceRestStub::PatchDataset( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request) { + return rest_internal::Patch( + *service_, rest_context, request.dataset(), false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "datasets", "/", + request.dataset_id())); +} + +StatusOr +DefaultDatasetServiceRestStub::UpdateDataset( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request) { + return rest_internal::Put( + *service_, rest_context, request.dataset(), false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "datasets", "/", + request.dataset_id())); +} + +Status DefaultDatasetServiceRestStub::DeleteDataset( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::DeleteDatasetRequest const& request) { + return rest_internal::Delete( + *service_, rest_context, request, false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "datasets", "/", + request.dataset_id()), + rest_internal::TrimEmptyQueryParameters({std::make_pair( + "delete_contents", request.delete_contents() ? "1" : "0")})); +} + +StatusOr +DefaultDatasetServiceRestStub::ListDatasets( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListDatasetsRequest const& request) { + return rest_internal::Get( + *service_, rest_context, request, false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "datasets"), + rest_internal::TrimEmptyQueryParameters( + {std::make_pair("page_token", request.page_token()), + std::make_pair("all", request.all() ? "1" : "0"), + std::make_pair("filter", request.filter())})); +} + +StatusOr +DefaultDatasetServiceRestStub::UndeleteDataset( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UndeleteDatasetRequest const& request) { + return rest_internal::Post( + *service_, rest_context, request, false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "datasets", "/", + request.dataset_id(), ":undelete")); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_dataset_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_stub.h b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_stub.h new file mode 100644 index 0000000000000..05151f21f457e --- /dev/null +++ b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_stub.h @@ -0,0 +1,134 @@ +// Copyright 2024 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/v2/dataset.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_INTERNAL_DATASET_REST_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_INTERNAL_DATASET_REST_STUB_H + +#include "google/cloud/completion_queue.h" +#include "google/cloud/internal/rest_client.h" +#include "google/cloud/internal/rest_context.h" +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_dataset_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class DatasetServiceRestStub { + public: + virtual ~DatasetServiceRestStub() = default; + + virtual StatusOr GetDataset( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetDatasetRequest const& request) = 0; + + virtual StatusOr InsertDataset( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::InsertDatasetRequest const& request) = 0; + + virtual StatusOr PatchDataset( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& + request) = 0; + + virtual StatusOr UpdateDataset( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& + request) = 0; + + virtual Status DeleteDataset( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::DeleteDatasetRequest const& request) = 0; + + virtual StatusOr ListDatasets( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListDatasetsRequest const& request) = 0; + + virtual StatusOr UndeleteDataset( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UndeleteDatasetRequest const& request) = 0; +}; + +class DefaultDatasetServiceRestStub : public DatasetServiceRestStub { + public: + ~DefaultDatasetServiceRestStub() override = default; + + explicit DefaultDatasetServiceRestStub(Options options); + DefaultDatasetServiceRestStub( + std::shared_ptr service, Options options); + + StatusOr GetDataset( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetDatasetRequest const& request) override; + + StatusOr InsertDataset( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::InsertDatasetRequest const& request) + override; + + StatusOr PatchDataset( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request) + override; + + StatusOr UpdateDataset( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request) + override; + + Status DeleteDataset(google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::DeleteDatasetRequest const& + request) override; + + StatusOr ListDatasets( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListDatasetsRequest const& request) override; + + StatusOr UndeleteDataset( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UndeleteDatasetRequest const& request) + override; + + private: + std::shared_ptr service_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_dataset_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_INTERNAL_DATASET_REST_STUB_H diff --git a/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_stub_factory.cc b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_stub_factory.cc new file mode 100644 index 0000000000000..ae917626f21f0 --- /dev/null +++ b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_stub_factory.cc @@ -0,0 +1,56 @@ +// Copyright 2024 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/v2/dataset.proto + +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_stub_factory.h" +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_logging_decorator.h" +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_metadata_decorator.h" +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_stub.h" +#include "google/cloud/common_options.h" +#include "google/cloud/internal/algorithm.h" +#include "google/cloud/internal/populate_rest_options.h" +#include "google/cloud/log.h" +#include "google/cloud/options.h" +#include "google/cloud/rest_options.h" +#include "absl/strings/match.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_dataset_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultDatasetServiceRestStub( + Options const& options) { + auto opts = internal::PopulateRestOptions(options); + std::shared_ptr stub = + std::make_shared(std::move(opts)); + stub = std::make_shared(std::move(stub)); + if (internal::Contains(options.get(), "rpc")) { + GCP_LOG(INFO) << "Enabled logging for REST rpc calls"; + stub = std::make_shared( + std::move(stub), options.get(), + options.get()); + } + return stub; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_dataset_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_stub_factory.h b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_stub_factory.h new file mode 100644 index 0000000000000..f429c1f38db84 --- /dev/null +++ b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_stub_factory.h @@ -0,0 +1,40 @@ +// Copyright 2024 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/v2/dataset.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_INTERNAL_DATASET_REST_STUB_FACTORY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_INTERNAL_DATASET_REST_STUB_FACTORY_H + +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_stub.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_dataset_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultDatasetServiceRestStub( + Options const& options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_dataset_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_INTERNAL_DATASET_REST_STUB_FACTORY_H diff --git a/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_retry_traits.h b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_retry_traits.h new file mode 100644 index 0000000000000..1ebf56f97f26d --- /dev/null +++ b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_retry_traits.h @@ -0,0 +1,43 @@ +// Copyright 2024 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/v2/dataset.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_INTERNAL_DATASET_RETRY_TRAITS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_INTERNAL_DATASET_RETRY_TRAITS_H + +#include "google/cloud/status.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace bigquerycontrol_dataset_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// Define the gRPC status code semantics for retrying requests. +struct DatasetServiceRetryTraits { + static bool IsPermanentFailure(google::cloud::Status const& status) { + return status.code() != StatusCode::kOk && + status.code() != StatusCode::kUnavailable; + } +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_dataset_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_INTERNAL_DATASET_RETRY_TRAITS_H diff --git a/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_sources.cc b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_sources.cc new file mode 100644 index 0000000000000..262e4b946e2e9 --- /dev/null +++ b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_sources.cc @@ -0,0 +1,31 @@ +// Copyright 2024 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/v2/dataset.proto + +// NOLINTBEGIN(bugprone-suspicious-include) +#include "google/cloud/bigquerycontrol/dataset/v2/dataset_client.cc" +#include "google/cloud/bigquerycontrol/dataset/v2/dataset_connection.cc" +#include "google/cloud/bigquerycontrol/dataset/v2/dataset_connection_idempotency_policy.cc" +#include "google/cloud/bigquerycontrol/dataset/v2/dataset_rest_connection.cc" +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_option_defaults.cc" +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_connection_impl.cc" +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_logging_decorator.cc" +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_metadata_decorator.cc" +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_stub.cc" +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_rest_stub_factory.cc" +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_tracing_connection.cc" +// NOLINTEND(bugprone-suspicious-include) diff --git a/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_tracing_connection.cc b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_tracing_connection.cc new file mode 100644 index 0000000000000..bce02e1f7d704 --- /dev/null +++ b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_tracing_connection.cc @@ -0,0 +1,118 @@ +// Copyright 2024 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/v2/dataset.proto + +#include "google/cloud/bigquerycontrol/dataset/v2/internal/dataset_tracing_connection.h" +#include "google/cloud/internal/opentelemetry.h" +#include "google/cloud/internal/traced_stream_range.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_dataset_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +DatasetServiceTracingConnection::DatasetServiceTracingConnection( + std::shared_ptr child) + : child_(std::move(child)) {} + +StatusOr +DatasetServiceTracingConnection::GetDataset( + google::cloud::bigquery::v2::GetDatasetRequest const& request) { + auto span = internal::MakeSpan( + "bigquerycontrol_dataset_v2::DatasetServiceConnection::GetDataset"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->GetDataset(request)); +} + +StatusOr +DatasetServiceTracingConnection::InsertDataset( + google::cloud::bigquery::v2::InsertDatasetRequest const& request) { + auto span = internal::MakeSpan( + "bigquerycontrol_dataset_v2::DatasetServiceConnection::InsertDataset"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->InsertDataset(request)); +} + +StatusOr +DatasetServiceTracingConnection::PatchDataset( + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request) { + auto span = internal::MakeSpan( + "bigquerycontrol_dataset_v2::DatasetServiceConnection::PatchDataset"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->PatchDataset(request)); +} + +StatusOr +DatasetServiceTracingConnection::UpdateDataset( + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request) { + auto span = internal::MakeSpan( + "bigquerycontrol_dataset_v2::DatasetServiceConnection::UpdateDataset"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->UpdateDataset(request)); +} + +Status DatasetServiceTracingConnection::DeleteDataset( + google::cloud::bigquery::v2::DeleteDatasetRequest const& request) { + auto span = internal::MakeSpan( + "bigquerycontrol_dataset_v2::DatasetServiceConnection::DeleteDataset"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->DeleteDataset(request)); +} + +StreamRange +DatasetServiceTracingConnection::ListDatasets( + google::cloud::bigquery::v2::ListDatasetsRequest request) { + auto span = internal::MakeSpan( + "bigquerycontrol_dataset_v2::DatasetServiceConnection::ListDatasets"); + internal::OTelScope scope(span); + auto sr = child_->ListDatasets(std::move(request)); + return internal::MakeTracedStreamRange< + google::cloud::bigquery::v2::ListFormatDataset>(std::move(span), + std::move(sr)); +} + +StatusOr +DatasetServiceTracingConnection::UndeleteDataset( + google::cloud::bigquery::v2::UndeleteDatasetRequest const& request) { + auto span = internal::MakeSpan( + "bigquerycontrol_dataset_v2::DatasetServiceConnection::UndeleteDataset"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->UndeleteDataset(request)); +} + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +std::shared_ptr +MakeDatasetServiceTracingConnection( + std::shared_ptr + conn) { +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + if (internal::TracingEnabled(conn->options())) { + conn = std::make_shared(std::move(conn)); + } +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + return conn; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_dataset_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_tracing_connection.h b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_tracing_connection.h new file mode 100644 index 0000000000000..7caa6c3b575be --- /dev/null +++ b/google/cloud/bigquerycontrol/dataset/v2/internal/dataset_tracing_connection.h @@ -0,0 +1,90 @@ +// Copyright 2024 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/v2/dataset.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_INTERNAL_DATASET_TRACING_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_INTERNAL_DATASET_TRACING_CONNECTION_H + +#include "google/cloud/bigquerycontrol/dataset/v2/dataset_connection.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_dataset_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +class DatasetServiceTracingConnection + : public bigquerycontrol_dataset_v2::DatasetServiceConnection { + public: + ~DatasetServiceTracingConnection() override = default; + + explicit DatasetServiceTracingConnection( + std::shared_ptr + child); + + Options options() override { return child_->options(); } + + StatusOr GetDataset( + google::cloud::bigquery::v2::GetDatasetRequest const& request) override; + + StatusOr InsertDataset( + google::cloud::bigquery::v2::InsertDatasetRequest const& request) + override; + + StatusOr PatchDataset( + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request) + override; + + StatusOr UpdateDataset( + google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request) + override; + + Status DeleteDataset(google::cloud::bigquery::v2::DeleteDatasetRequest const& + request) override; + + StreamRange ListDatasets( + google::cloud::bigquery::v2::ListDatasetsRequest request) override; + + StatusOr UndeleteDataset( + google::cloud::bigquery::v2::UndeleteDatasetRequest const& request) + override; + + private: + std::shared_ptr child_; +}; + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +/** + * Conditionally applies the tracing decorator to the given connection. + * + * The connection is only decorated if tracing is enabled (as determined by the + * connection's options). + */ +std::shared_ptr +MakeDatasetServiceTracingConnection( + std::shared_ptr conn); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_dataset_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_INTERNAL_DATASET_TRACING_CONNECTION_H diff --git a/google/cloud/bigquerycontrol/dataset/v2/mocks/mock_dataset_connection.h b/google/cloud/bigquerycontrol/dataset/v2/mocks/mock_dataset_connection.h new file mode 100644 index 0000000000000..7d8fecaf6bd28 --- /dev/null +++ b/google/cloud/bigquerycontrol/dataset/v2/mocks/mock_dataset_connection.h @@ -0,0 +1,90 @@ +// Copyright 2024 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/v2/dataset.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_MOCKS_MOCK_DATASET_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_MOCKS_MOCK_DATASET_CONNECTION_H + +#include "google/cloud/bigquerycontrol/dataset/v2/dataset_connection.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_dataset_v2_mocks { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * A class to mock `DatasetServiceConnection`. + * + * Application developers may want to test their code with simulated responses, + * including errors, from an object of type `DatasetServiceClient`. To do so, + * construct an object of type `DatasetServiceClient` 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]: @cloud_cpp_docs_link{bigquery,bigquery-read-mock} + */ +class MockDatasetServiceConnection + : public bigquerycontrol_dataset_v2::DatasetServiceConnection { + public: + MOCK_METHOD(Options, options, (), (override)); + + MOCK_METHOD(StatusOr, GetDataset, + (google::cloud::bigquery::v2::GetDatasetRequest const& request), + (override)); + + MOCK_METHOD( + StatusOr, InsertDataset, + (google::cloud::bigquery::v2::InsertDatasetRequest const& request), + (override)); + + MOCK_METHOD( + StatusOr, PatchDataset, + (google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request), + (override)); + + MOCK_METHOD( + StatusOr, UpdateDataset, + (google::cloud::bigquery::v2::UpdateOrPatchDatasetRequest const& request), + (override)); + + MOCK_METHOD( + Status, DeleteDataset, + (google::cloud::bigquery::v2::DeleteDatasetRequest const& request), + (override)); + + MOCK_METHOD((StreamRange), + ListDatasets, + (google::cloud::bigquery::v2::ListDatasetsRequest request), + (override)); + + MOCK_METHOD( + StatusOr, UndeleteDataset, + (google::cloud::bigquery::v2::UndeleteDatasetRequest const& request), + (override)); +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_dataset_v2_mocks +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_DATASET_V2_MOCKS_MOCK_DATASET_CONNECTION_H diff --git a/google/cloud/bigquerycontrol/dataset/v2/samples/dataset_client_samples.cc b/google/cloud/bigquerycontrol/dataset/v2/samples/dataset_client_samples.cc new file mode 100644 index 0000000000000..25e63e952f5e1 --- /dev/null +++ b/google/cloud/bigquerycontrol/dataset/v2/samples/dataset_client_samples.cc @@ -0,0 +1,163 @@ +// Copyright 2024 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/v2/dataset.proto + +#include "google/cloud/bigquerycontrol/dataset/v2/dataset_client.h" +#include "google/cloud/bigquerycontrol/dataset/v2/dataset_connection_idempotency_policy.h" +#include "google/cloud/bigquerycontrol/dataset/v2/dataset_options.h" +#include "google/cloud/common_options.h" +#include "google/cloud/credentials.h" +#include "google/cloud/internal/getenv.h" +#include "google/cloud/testing_util/example_driver.h" +#include +#include +#include +#include + +// clang-format off +// main-dox-marker: bigquerycontrol_dataset_v2::DatasetServiceClient +// clang-format on +namespace { + +void SetClientEndpoint(std::vector const& argv) { + if (!argv.empty()) { + throw google::cloud::testing_util::Usage{"set-client-endpoint"}; + } + //! [set-client-endpoint] + // This configuration is common with Private Google Access: + // https://cloud.google.com/vpc/docs/private-google-access + auto options = google::cloud::Options{}.set( + "private.googleapis.com"); + auto client = google::cloud::bigquerycontrol_dataset_v2::DatasetServiceClient( + google::cloud::bigquerycontrol_dataset_v2:: + MakeDatasetServiceConnectionRest(options)); + //! [set-client-endpoint] +} + +//! [custom-idempotency-policy] +class CustomIdempotencyPolicy + : public google::cloud::bigquerycontrol_dataset_v2:: + DatasetServiceConnectionIdempotencyPolicy { + public: + ~CustomIdempotencyPolicy() override = default; + std::unique_ptr + clone() const override { + return std::make_unique(*this); + } + // Override inherited functions to define as needed. +}; +//! [custom-idempotency-policy] + +void SetRetryPolicy(std::vector const& argv) { + if (!argv.empty()) { + throw google::cloud::testing_util::Usage{"set-client-retry-policy"}; + } + //! [set-retry-policy] + auto options = google::cloud::Options{} + .set( + CustomIdempotencyPolicy().clone()) + .set( + google::cloud::bigquerycontrol_dataset_v2:: + DatasetServiceLimitedErrorCountRetryPolicy(3) + .clone()) + .set( + google::cloud::ExponentialBackoffPolicy( + /*initial_delay=*/std::chrono::milliseconds(200), + /*maximum_delay=*/std::chrono::seconds(45), + /*scaling=*/2.0) + .clone()); + auto connection = google::cloud::bigquerycontrol_dataset_v2:: + MakeDatasetServiceConnectionRest(options); + + // c1 and c2 share the same retry policies + auto c1 = google::cloud::bigquerycontrol_dataset_v2::DatasetServiceClient( + connection); + auto c2 = google::cloud::bigquerycontrol_dataset_v2::DatasetServiceClient( + connection); + + // You can override any of the policies in a new client. This new client + // will share the policies from c1 (or c2) *except* for the retry policy. + auto c3 = google::cloud::bigquerycontrol_dataset_v2::DatasetServiceClient( + connection, + google::cloud::Options{} + .set( + google::cloud::bigquerycontrol_dataset_v2:: + DatasetServiceLimitedTimeRetryPolicy(std::chrono::minutes(5)) + .clone())); + + // You can also override the policies in a single call: + // c3.SomeRpc(..., google::cloud::Options{} + // .set( + // google::cloud::bigquerycontrol_dataset_v2::DatasetServiceLimitedErrorCountRetryPolicy(10).clone())); + //! [set-retry-policy] +} + +void WithServiceAccount(std::vector const& argv) { + if (argv.size() != 1 || argv[0] == "--help") { + throw google::cloud::testing_util::Usage{"with-service-account "}; + } + //! [with-service-account] + [](std::string const& keyfile) { + auto is = std::ifstream(keyfile); + is.exceptions(std::ios::badbit); // Minimal error handling in examples + auto contents = std::string(std::istreambuf_iterator(is.rdbuf()), {}); + auto options = + google::cloud::Options{}.set( + google::cloud::MakeServiceAccountCredentials(contents)); + return google::cloud::bigquerycontrol_dataset_v2::DatasetServiceClient( + google::cloud::bigquerycontrol_dataset_v2:: + MakeDatasetServiceConnectionRest(options)); + } + //! [with-service-account] + (argv.at(0)); +} + +void AutoRun(std::vector const& argv) { + namespace examples = ::google::cloud::testing_util; + using ::google::cloud::internal::GetEnv; + if (!argv.empty()) throw examples::Usage{"auto"}; + examples::CheckEnvironmentVariablesAreSet( + {"GOOGLE_CLOUD_CPP_TEST_SERVICE_ACCOUNT_KEYFILE"}); + auto const keyfile = + GetEnv("GOOGLE_CLOUD_CPP_TEST_SERVICE_ACCOUNT_KEYFILE").value(); + + std::cout << "\nRunning SetClientEndpoint() example" << std::endl; + SetClientEndpoint({}); + + std::cout << "\nRunning SetRetryPolicy() example" << std::endl; + SetRetryPolicy({}); + + std::cout << "\nRunning WithServiceAccount() example" << std::endl; + WithServiceAccount({keyfile}); +} + +} // namespace + +int main(int argc, char* argv[]) { // NOLINT(bugprone-exception-escape) + google::cloud::testing_util::Example example({ + {"set-client-endpoint", SetClientEndpoint}, + {"set-retry-policy", SetRetryPolicy}, + {"with-service-account", WithServiceAccount}, + {"auto", AutoRun}, + }); + return example.Run(argc, argv); +} diff --git a/google/cloud/bigquerycontrol/doc/environment-variables.dox b/google/cloud/bigquerycontrol/doc/environment-variables.dox new file mode 100644 index 0000000000000..024f0f31e6cdb --- /dev/null +++ b/google/cloud/bigquerycontrol/doc/environment-variables.dox @@ -0,0 +1,74 @@ +/*! + +@page bigquerycontrol-env Environment Variables + +A number of environment variables can be used to configure the behavior of +the library. There are also functions to configure this behavior in code. The +environment variables are convenient when troubleshooting problems. + +@section bigquerycontrol-env-endpoint Endpoint Overrides + + + +- `GOOGLE_CLOUD_CPP_DATASET_SERVICE_ENDPOINT=...` overrides the + `EndpointOption` (which defaults to "bigquery.googleapis.com") + used by `MakeDatasetServiceConnection()`. + +- `GOOGLE_CLOUD_CPP_JOB_SERVICE_ENDPOINT=...` overrides the + `EndpointOption` (which defaults to "bigquery.googleapis.com") + used by `MakeJobServiceConnection()`. + +- `GOOGLE_CLOUD_CPP_MODEL_SERVICE_ENDPOINT=...` overrides the + `EndpointOption` (which defaults to "bigquery.googleapis.com") + used by `MakeModelServiceConnection()`. + +- `GOOGLE_CLOUD_CPP_PROJECT_SERVICE_ENDPOINT=...` overrides the + `EndpointOption` (which defaults to "bigquery.googleapis.com") + used by `MakeProjectServiceConnection()`. + +- `GOOGLE_CLOUD_CPP_ROUTINE_SERVICE_ENDPOINT=...` overrides the + `EndpointOption` (which defaults to "bigquery.googleapis.com") + used by `MakeRoutineServiceConnection()`. + +- `GOOGLE_CLOUD_CPP_ROW_ACCESS_POLICY_SERVICE_ENDPOINT=...` overrides the + `EndpointOption` (which defaults to "bigquery.googleapis.com") + used by `MakeRowAccessPolicyServiceConnection()`. + +- `GOOGLE_CLOUD_CPP_TABLE_SERVICE_ENDPOINT=...` overrides the + `EndpointOption` (which defaults to "bigquery.googleapis.com") + used by `MakeTableServiceConnection()`. + + + +@see google::cloud::EndpointOption + +@section bigquerycontrol-env-logging Logging + +`GOOGLE_CLOUD_CPP_ENABLE_TRACING=rpc`: turns on tracing for most gRPC +calls. The library injects an additional Stub decorator that prints each gRPC +request and response. Unless you have configured your own logging backend, +you should also set `GOOGLE_CLOUD_CPP_ENABLE_CLOG` to produce any output on +the program's console. + +@see google::cloud::LoggingComponentsOption + +`GOOGLE_CLOUD_CPP_TRACING_OPTIONS=...`: modifies the behavior of gRPC tracing, +including whether messages will be output on multiple lines, or whether +string/bytes fields will be truncated. + +@see google::cloud::GrpcTracingOptionsOption + +`GOOGLE_CLOUD_CPP_ENABLE_CLOG=yes`: turns on logging in the library, basically +the library always "logs" but the logging infrastructure has no backend to +actually print anything until the application sets a backend or they set this +environment variable. + +@see google::cloud::LogBackend +@see google::cloud::LogSink + +@section bigquerycontrol-env-project Setting the Default Project + +`GOOGLE_CLOUD_PROJECT=...`: is used in examples and integration tests to +configure the GCP project. This has no effect in the library. + +*/ diff --git a/google/cloud/bigquerycontrol/doc/main.dox b/google/cloud/bigquerycontrol/doc/main.dox new file mode 100644 index 0000000000000..98085e62f3c74 --- /dev/null +++ b/google/cloud/bigquerycontrol/doc/main.dox @@ -0,0 +1,60 @@ +/*! + +@mainpage BigQuery API C++ Client Library + +An idiomatic C++ client library for the [BigQuery API][cloud-service-docs]. + +A data platform for customers to create, manage, share and query data. + +This library is **experimental**. Its APIs are subject to change without notice. + +Please, note that the Google Cloud C++ client libraries do **not** follow +[Semantic Versioning](https://semver.org/). + +@tableofcontents{HTML:2} + +## Quickstart + +The following shows the code that you'll run in the +`google/cloud/bigquerycontrol/quickstart/` directory, +which should give you a taste of the BigQuery API C++ client library API. + +@snippet quickstart.cc all + +## Main classes + + +This library offers multiple `*Client` classes, which are listed below. Each one +of these classes exposes all the RPCs for a service as member functions of the +class. This library groups multiple services because they are part of the same +product or are often used together. A typical example may be the administrative +and data plane operations for a single product. + +The library also has other classes that provide helpers, configuration +parameters, and infrastructure to mock the `*Client` classes when testing your +application. + +- [\c bigquerycontrol_dataset_v2::DatasetServiceClient](@ref google::cloud::bigquerycontrol_dataset_v2::DatasetServiceClient) +- [\c bigquerycontrol_job_v2::JobServiceClient](@ref google::cloud::bigquerycontrol_job_v2::JobServiceClient) +- [\c bigquerycontrol_model_v2::ModelServiceClient](@ref google::cloud::bigquerycontrol_model_v2::ModelServiceClient) +- [\c bigquerycontrol_project_v2::ProjectServiceClient](@ref google::cloud::bigquerycontrol_project_v2::ProjectServiceClient) +- [\c bigquerycontrol_routine_v2::RoutineServiceClient](@ref google::cloud::bigquerycontrol_routine_v2::RoutineServiceClient) +- [\c bigquerycontrol_row_access_policy_v2::RowAccessPolicyServiceClient](@ref google::cloud::bigquerycontrol_row_access_policy_v2::RowAccessPolicyServiceClient) +- [\c bigquerycontrol_table_v2::TableServiceClient](@ref google::cloud::bigquerycontrol_table_v2::TableServiceClient) + + +## More Information + +- @ref common-error-handling - describes how the library reports errors. +- @ref bigquerycontrol-override-endpoint - describes how to override the default + endpoint. +- @ref bigquerycontrol-override-authentication - describes how to change the + authentication credentials used by the library. +- @ref bigquerycontrol-override-retry - describes how to change the default retry + policies. +- @ref bigquerycontrol-env - describes environment variables that can configure the + behavior of the library. + +[cloud-service-docs]: https://cloud.google.com/bigquerycontrol [EDIT HERE] + +*/ diff --git a/google/cloud/bigquerycontrol/doc/options.dox b/google/cloud/bigquerycontrol/doc/options.dox new file mode 100644 index 0000000000000..6b9c7d8515312 --- /dev/null +++ b/google/cloud/bigquerycontrol/doc/options.dox @@ -0,0 +1,10 @@ +/*! +@defgroup google-cloud-bigquerycontrol-options BigQuery API Configuration Options + +This library uses the same mechanism (`google::cloud::Options`) and the common +[options](@ref options) as all other C++ client libraries for its configuration. +Some `*Option` classes, which are only used in this library, are documented in +this page. + +@see @ref options - for an overview of client library configuration. +*/ diff --git a/google/cloud/bigquerycontrol/doc/override-authentication.dox b/google/cloud/bigquerycontrol/doc/override-authentication.dox new file mode 100644 index 0000000000000..037a09650aa73 --- /dev/null +++ b/google/cloud/bigquerycontrol/doc/override-authentication.dox @@ -0,0 +1,81 @@ +/*! +@page bigquerycontrol-override-authentication How to Override the Authentication Credentials + +Unless otherwise configured, the client libraries use +[Application Default Credentials] to authenticate with Google Cloud Services. +While this works for most applications, in some cases you may need to override +this default. You can do so by providing the +[UnifiedCredentialsOption](@ref google::cloud::UnifiedCredentialsOption) +The following example shows how to explicitly load a service account key file: + + +@snippet dataset_client_samples.cc with-service-account + +Follow these links to find examples for other \c *Client classes: + +- [\c bigquerycontrol_dataset_v2::DatasetServiceClient](@ref bigquerycontrol_dataset_v2::DatasetServiceClient-service-account-snippet) +- [\c bigquerycontrol_job_v2::JobServiceClient](@ref bigquerycontrol_job_v2::JobServiceClient-service-account-snippet) +- [\c bigquerycontrol_model_v2::ModelServiceClient](@ref bigquerycontrol_model_v2::ModelServiceClient-service-account-snippet) +- [\c bigquerycontrol_project_v2::ProjectServiceClient](@ref bigquerycontrol_project_v2::ProjectServiceClient-service-account-snippet) +- [\c bigquerycontrol_routine_v2::RoutineServiceClient](@ref bigquerycontrol_routine_v2::RoutineServiceClient-service-account-snippet) +- [\c bigquerycontrol_row_access_policy_v2::RowAccessPolicyServiceClient](@ref bigquerycontrol_row_access_policy_v2::RowAccessPolicyServiceClient-service-account-snippet) +- [\c bigquerycontrol_table_v2::TableServiceClient](@ref bigquerycontrol_table_v2::TableServiceClient-service-account-snippet) + + + +Keep in mind that we chose this as an example because it is relatively easy to +understand. Consult the [Best practices for managing service account keys] +guide for more details. + +@see @ref guac - for more information on the factory functions to create +`google::cloud::Credentials` objects. + +[Best practices for managing service account keys]: https://cloud.google.com/iam/docs/best-practices-for-managing-service-account-keys +[Application Default Credentials]: https://cloud.google.com/docs/authentication#adc + +*/ + +// + +/*! @page bigquerycontrol_dataset_v2::DatasetServiceClient-service-account-snippet Override bigquerycontrol_dataset_v2::DatasetServiceClient Authentication Defaults + +@snippet google/cloud/bigquerycontrol/dataset/v2/samples/dataset_client_samples.cc with-service-account + +*/ + +/*! @page bigquerycontrol_job_v2::JobServiceClient-service-account-snippet Override bigquerycontrol_job_v2::JobServiceClient Authentication Defaults + +@snippet google/cloud/bigquerycontrol/job/v2/samples/job_client_samples.cc with-service-account + +*/ + +/*! @page bigquerycontrol_model_v2::ModelServiceClient-service-account-snippet Override bigquerycontrol_model_v2::ModelServiceClient Authentication Defaults + +@snippet google/cloud/bigquerycontrol/model/v2/samples/model_client_samples.cc with-service-account + +*/ + +/*! @page bigquerycontrol_project_v2::ProjectServiceClient-service-account-snippet Override bigquerycontrol_project_v2::ProjectServiceClient Authentication Defaults + +@snippet google/cloud/bigquerycontrol/project/v2/samples/project_client_samples.cc with-service-account + +*/ + +/*! @page bigquerycontrol_routine_v2::RoutineServiceClient-service-account-snippet Override bigquerycontrol_routine_v2::RoutineServiceClient Authentication Defaults + +@snippet google/cloud/bigquerycontrol/routine/v2/samples/routine_client_samples.cc with-service-account + +*/ + +/*! @page bigquerycontrol_row_access_policy_v2::RowAccessPolicyServiceClient-service-account-snippet Override bigquerycontrol_row_access_policy_v2::RowAccessPolicyServiceClient Authentication Defaults + +@snippet google/cloud/bigquerycontrol/row_access_policy/v2/samples/row_access_policy_client_samples.cc with-service-account + +*/ + +/*! @page bigquerycontrol_table_v2::TableServiceClient-service-account-snippet Override bigquerycontrol_table_v2::TableServiceClient Authentication Defaults + +@snippet google/cloud/bigquerycontrol/table/v2/samples/table_client_samples.cc with-service-account + +*/ +// diff --git a/google/cloud/bigquerycontrol/doc/override-endpoint.dox b/google/cloud/bigquerycontrol/doc/override-endpoint.dox new file mode 100644 index 0000000000000..8c9e3a764906b --- /dev/null +++ b/google/cloud/bigquerycontrol/doc/override-endpoint.dox @@ -0,0 +1,71 @@ +/*! +@page bigquerycontrol-override-endpoint How to Override the Default Endpoint + +In some cases, you may need to override the default endpoint used by the client +library. Use the +[EndpointOption](@ref google::cloud::EndpointOption) when initializing the +client library to change this default. + + +For example, this will override the default endpoint for `bigquerycontrol_dataset_v2::DatasetServiceClient`: + +@snippet dataset_client_samples.cc set-client-endpoint + +Follow these links to find examples for other \c *Client classes: + +- [\c bigquerycontrol_dataset_v2::DatasetServiceClient](@ref bigquerycontrol_dataset_v2::DatasetServiceClient-endpoint-snippet) +- [\c bigquerycontrol_job_v2::JobServiceClient](@ref bigquerycontrol_job_v2::JobServiceClient-endpoint-snippet) +- [\c bigquerycontrol_model_v2::ModelServiceClient](@ref bigquerycontrol_model_v2::ModelServiceClient-endpoint-snippet) +- [\c bigquerycontrol_project_v2::ProjectServiceClient](@ref bigquerycontrol_project_v2::ProjectServiceClient-endpoint-snippet) +- [\c bigquerycontrol_routine_v2::RoutineServiceClient](@ref bigquerycontrol_routine_v2::RoutineServiceClient-endpoint-snippet) +- [\c bigquerycontrol_row_access_policy_v2::RowAccessPolicyServiceClient](@ref bigquerycontrol_row_access_policy_v2::RowAccessPolicyServiceClient-endpoint-snippet) +- [\c bigquerycontrol_table_v2::TableServiceClient](@ref bigquerycontrol_table_v2::TableServiceClient-endpoint-snippet) + + + +*/ + +// + +/*! @page bigquerycontrol_dataset_v2::DatasetServiceClient-endpoint-snippet Override bigquerycontrol_dataset_v2::DatasetServiceClient Endpoint Configuration + +@snippet google/cloud/bigquerycontrol/dataset/v2/samples/dataset_client_samples.cc set-client-endpoint + +*/ + +/*! @page bigquerycontrol_job_v2::JobServiceClient-endpoint-snippet Override bigquerycontrol_job_v2::JobServiceClient Endpoint Configuration + +@snippet google/cloud/bigquerycontrol/job/v2/samples/job_client_samples.cc set-client-endpoint + +*/ + +/*! @page bigquerycontrol_model_v2::ModelServiceClient-endpoint-snippet Override bigquerycontrol_model_v2::ModelServiceClient Endpoint Configuration + +@snippet google/cloud/bigquerycontrol/model/v2/samples/model_client_samples.cc set-client-endpoint + +*/ + +/*! @page bigquerycontrol_project_v2::ProjectServiceClient-endpoint-snippet Override bigquerycontrol_project_v2::ProjectServiceClient Endpoint Configuration + +@snippet google/cloud/bigquerycontrol/project/v2/samples/project_client_samples.cc set-client-endpoint + +*/ + +/*! @page bigquerycontrol_routine_v2::RoutineServiceClient-endpoint-snippet Override bigquerycontrol_routine_v2::RoutineServiceClient Endpoint Configuration + +@snippet google/cloud/bigquerycontrol/routine/v2/samples/routine_client_samples.cc set-client-endpoint + +*/ + +/*! @page bigquerycontrol_row_access_policy_v2::RowAccessPolicyServiceClient-endpoint-snippet Override bigquerycontrol_row_access_policy_v2::RowAccessPolicyServiceClient Endpoint Configuration + +@snippet google/cloud/bigquerycontrol/row_access_policy/v2/samples/row_access_policy_client_samples.cc set-client-endpoint + +*/ + +/*! @page bigquerycontrol_table_v2::TableServiceClient-endpoint-snippet Override bigquerycontrol_table_v2::TableServiceClient Endpoint Configuration + +@snippet google/cloud/bigquerycontrol/table/v2/samples/table_client_samples.cc set-client-endpoint + +*/ +// diff --git a/google/cloud/bigquerycontrol/doc/override-retry-policies.dox b/google/cloud/bigquerycontrol/doc/override-retry-policies.dox new file mode 100644 index 0000000000000..26bb112647d41 --- /dev/null +++ b/google/cloud/bigquerycontrol/doc/override-retry-policies.dox @@ -0,0 +1,186 @@ +/*! +@page bigquerycontrol-override-retry Override Retry, Backoff, and Idempotency Policies + +When it is safe to do so, the library automatically retries requests that fail +due to a transient error. The library then uses [exponential backoff] to backoff +before trying again. Which operations are considered safe to retry, which +errors are treated as transient failures, the details of the exponential backoff +algorithm, and for how long the library retries are all configurable via +policies. + +This document provides examples showing how to override the default policies. + +The policies can be set when the `*Connection` object is created. The library +provides default policies for any policy that is not set. The application can +also override some (or all) policies when the `*Client` object is created. This +can be useful if multiple `*Client` objects share the same `*Connection` object, +but you want different retry behavior in some of the clients. Finally, the +application can override some retry policies when calling a specific member +function. + +The library uses three different options to control the retry loop. The options +have per-client names. + +@section bigquerycontrol-override-retry-retry-policy Configuring the transient errors and retry duration + +The `*RetryPolicyOption` controls: + +- Which errors are to be treated as transient errors. +- How long the library will keep retrying transient errors. + +You can provide your own class for this option. The library also provides two +built-in policies: + +- `*LimitedErrorCountRetryPolicy`: stops retrying after a specified number + of transient errors. +- `*LimitedTimeRetryPolicy`: stops retrying after a specified time. + +Note that a library may have more than one version of these classes. Their name +match the `*Client` and `*Connection` object they are intended to be used +with. Some `*Client` objects treat different error codes as transient errors. +In most cases, only [kUnavailable](@ref google::cloud::StatusCode) is treated +as a transient error. + +@section bigquerycontrol-override-retry-backoff-policy Controlling the backoff algorithm + +The `*BackoffPolicyOption` controls how long the client library will wait +before retrying a request that failed with a transient error. You can provide +your own class for this option. + +The only built-in backoff policy is +[`ExponentialBackoffPolicy`](@ref google::cloud::ExponentialBackoffPolicy). +This class implements a truncated exponential backoff algorithm, with jitter. +In summary, it doubles the current backoff time after each failure. The actual +backoff time for an RPC is chosen at random, but never exceeds the current +backoff. The current backoff is doubled after each failure, but never exceeds +(or is "truncated") if it reaches a prescribed maximum. + +@section bigquerycontrol-override-retry-idempotency-policy Controlling which operations are retryable + +The `*IdempotencyPolicyOption` controls which requests are retryable, as some +requests are never safe to retry. + +Only one built-in idempotency policy is provided by the library. The name +matches the name of the client it is intended for. For example, `FooBarClient` +will use `FooBarIdempotencyPolicy`. This policy is very conservative. + +@section bigquerycontrol-override-retry-example Example + + +For example, this will override the retry policies for `bigquerycontrol_dataset_v2::DatasetServiceClient`: + +@snippet dataset_client_samples.cc set-retry-policy + +This assumes you have created a custom idempotency policy. Such as: + +@snippet dataset_client_samples.cc custom-idempotency-policy + + +Follow these links to find examples for other \c *Client classes: + +- [\c bigquerycontrol_dataset_v2::DatasetServiceClient](@ref bigquerycontrol_dataset_v2::DatasetServiceClient-retry-snippet) +- [\c bigquerycontrol_job_v2::JobServiceClient](@ref bigquerycontrol_job_v2::JobServiceClient-retry-snippet) +- [\c bigquerycontrol_model_v2::ModelServiceClient](@ref bigquerycontrol_model_v2::ModelServiceClient-retry-snippet) +- [\c bigquerycontrol_project_v2::ProjectServiceClient](@ref bigquerycontrol_project_v2::ProjectServiceClient-retry-snippet) +- [\c bigquerycontrol_routine_v2::RoutineServiceClient](@ref bigquerycontrol_routine_v2::RoutineServiceClient-retry-snippet) +- [\c bigquerycontrol_row_access_policy_v2::RowAccessPolicyServiceClient](@ref bigquerycontrol_row_access_policy_v2::RowAccessPolicyServiceClient-retry-snippet) +- [\c bigquerycontrol_table_v2::TableServiceClient](@ref bigquerycontrol_table_v2::TableServiceClient-retry-snippet) + + + +@section bigquerycontrol-override-retry-more-information More Information + +@see google::cloud::Options +@see google::cloud::BackoffPolicy +@see google::cloud::ExponentialBackoffPolicy + +[exponential backoff]: https://en.wikipedia.org/wiki/Exponential_backoff + +*/ + +// + +/*! @page bigquerycontrol_dataset_v2::DatasetServiceClient-retry-snippet Override bigquerycontrol_dataset_v2::DatasetServiceClient Retry Policies + +This shows how to override the retry policies for bigquerycontrol_dataset_v2::DatasetServiceClient: + +@snippet google/cloud/bigquerycontrol/dataset/v2/samples/dataset_client_samples.cc set-retry-policy + +Assuming you have created a custom idempotency policy. Such as: + +@snippet google/cloud/bigquerycontrol/dataset/v2/samples/dataset_client_samples.cc custom-idempotency-policy + +*/ + +/*! @page bigquerycontrol_job_v2::JobServiceClient-retry-snippet Override bigquerycontrol_job_v2::JobServiceClient Retry Policies + +This shows how to override the retry policies for bigquerycontrol_job_v2::JobServiceClient: + +@snippet google/cloud/bigquerycontrol/job/v2/samples/job_client_samples.cc set-retry-policy + +Assuming you have created a custom idempotency policy. Such as: + +@snippet google/cloud/bigquerycontrol/job/v2/samples/job_client_samples.cc custom-idempotency-policy + +*/ + +/*! @page bigquerycontrol_model_v2::ModelServiceClient-retry-snippet Override bigquerycontrol_model_v2::ModelServiceClient Retry Policies + +This shows how to override the retry policies for bigquerycontrol_model_v2::ModelServiceClient: + +@snippet google/cloud/bigquerycontrol/model/v2/samples/model_client_samples.cc set-retry-policy + +Assuming you have created a custom idempotency policy. Such as: + +@snippet google/cloud/bigquerycontrol/model/v2/samples/model_client_samples.cc custom-idempotency-policy + +*/ + +/*! @page bigquerycontrol_project_v2::ProjectServiceClient-retry-snippet Override bigquerycontrol_project_v2::ProjectServiceClient Retry Policies + +This shows how to override the retry policies for bigquerycontrol_project_v2::ProjectServiceClient: + +@snippet google/cloud/bigquerycontrol/project/v2/samples/project_client_samples.cc set-retry-policy + +Assuming you have created a custom idempotency policy. Such as: + +@snippet google/cloud/bigquerycontrol/project/v2/samples/project_client_samples.cc custom-idempotency-policy + +*/ + +/*! @page bigquerycontrol_routine_v2::RoutineServiceClient-retry-snippet Override bigquerycontrol_routine_v2::RoutineServiceClient Retry Policies + +This shows how to override the retry policies for bigquerycontrol_routine_v2::RoutineServiceClient: + +@snippet google/cloud/bigquerycontrol/routine/v2/samples/routine_client_samples.cc set-retry-policy + +Assuming you have created a custom idempotency policy. Such as: + +@snippet google/cloud/bigquerycontrol/routine/v2/samples/routine_client_samples.cc custom-idempotency-policy + +*/ + +/*! @page bigquerycontrol_row_access_policy_v2::RowAccessPolicyServiceClient-retry-snippet Override bigquerycontrol_row_access_policy_v2::RowAccessPolicyServiceClient Retry Policies + +This shows how to override the retry policies for bigquerycontrol_row_access_policy_v2::RowAccessPolicyServiceClient: + +@snippet google/cloud/bigquerycontrol/row_access_policy/v2/samples/row_access_policy_client_samples.cc set-retry-policy + +Assuming you have created a custom idempotency policy. Such as: + +@snippet google/cloud/bigquerycontrol/row_access_policy/v2/samples/row_access_policy_client_samples.cc custom-idempotency-policy + +*/ + +/*! @page bigquerycontrol_table_v2::TableServiceClient-retry-snippet Override bigquerycontrol_table_v2::TableServiceClient Retry Policies + +This shows how to override the retry policies for bigquerycontrol_table_v2::TableServiceClient: + +@snippet google/cloud/bigquerycontrol/table/v2/samples/table_client_samples.cc set-retry-policy + +Assuming you have created a custom idempotency policy. Such as: + +@snippet google/cloud/bigquerycontrol/table/v2/samples/table_client_samples.cc custom-idempotency-policy + +*/ +// diff --git a/google/cloud/bigquerycontrol/job/v2/internal/job_option_defaults.cc b/google/cloud/bigquerycontrol/job/v2/internal/job_option_defaults.cc new file mode 100644 index 0000000000000..e6802f3a2e108 --- /dev/null +++ b/google/cloud/bigquerycontrol/job/v2/internal/job_option_defaults.cc @@ -0,0 +1,68 @@ +// Copyright 2024 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/v2/job.proto + +#include "google/cloud/bigquerycontrol/job/v2/internal/job_option_defaults.h" +#include "google/cloud/bigquerycontrol/job/v2/job_connection.h" +#include "google/cloud/bigquerycontrol/job/v2/job_options.h" +#include "google/cloud/internal/populate_common_options.h" +#include "google/cloud/internal/populate_grpc_options.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_job_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +namespace { +auto constexpr kBackoffScaling = 2.0; +} // namespace + +Options JobServiceDefaultOptions(Options options) { + options = internal::PopulateCommonOptions( + std::move(options), "GOOGLE_CLOUD_CPP_JOB_SERVICE_ENDPOINT", "", + "GOOGLE_CLOUD_CPP_JOB_SERVICE_AUTHORITY", "bigquery.googleapis.com"); + options = internal::PopulateGrpcOptions(std::move(options)); + if (!options.has()) { + options.set( + bigquerycontrol_job_v2::JobServiceLimitedTimeRetryPolicy( + std::chrono::minutes(30)) + .clone()); + } + if (!options.has()) { + options.set( + ExponentialBackoffPolicy( + std::chrono::seconds(0), std::chrono::seconds(1), + std::chrono::minutes(5), kBackoffScaling, kBackoffScaling) + .clone()); + } + if (!options.has()) { + options.set< + bigquerycontrol_job_v2::JobServiceConnectionIdempotencyPolicyOption>( + bigquerycontrol_job_v2:: + MakeDefaultJobServiceConnectionIdempotencyPolicy()); + } + + return options; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_job_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/job/v2/internal/job_option_defaults.h b/google/cloud/bigquerycontrol/job/v2/internal/job_option_defaults.h new file mode 100644 index 0000000000000..b505adfae39cb --- /dev/null +++ b/google/cloud/bigquerycontrol/job/v2/internal/job_option_defaults.h @@ -0,0 +1,37 @@ +// Copyright 2024 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/v2/job.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_INTERNAL_JOB_OPTION_DEFAULTS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_INTERNAL_JOB_OPTION_DEFAULTS_H + +#include "google/cloud/options.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace bigquerycontrol_job_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +Options JobServiceDefaultOptions(Options options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_job_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_INTERNAL_JOB_OPTION_DEFAULTS_H diff --git a/google/cloud/bigquerycontrol/job/v2/internal/job_rest_connection_impl.cc b/google/cloud/bigquerycontrol/job/v2/internal/job_rest_connection_impl.cc new file mode 100644 index 0000000000000..1d2d67a91a319 --- /dev/null +++ b/google/cloud/bigquerycontrol/job/v2/internal/job_rest_connection_impl.cc @@ -0,0 +1,164 @@ +// Copyright 2024 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/v2/job.proto + +#include "google/cloud/bigquerycontrol/job/v2/internal/job_rest_connection_impl.h" +#include "google/cloud/bigquerycontrol/job/v2/internal/job_rest_stub_factory.h" +#include "google/cloud/common_options.h" +#include "google/cloud/credentials.h" +#include "google/cloud/internal/pagination_range.h" +#include "google/cloud/internal/rest_retry_loop.h" +#include "google/cloud/rest_options.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_job_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +JobServiceRestConnectionImpl::JobServiceRestConnectionImpl( + std::unique_ptr background, + std::shared_ptr stub, + Options options) + : background_(std::move(background)), + stub_(std::move(stub)), + options_(internal::MergeOptions(std::move(options), + JobServiceConnection::options())) {} + +StatusOr +JobServiceRestConnectionImpl::CancelJob( + google::cloud::bigquery::v2::CancelJobRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::rest_internal::RestRetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->CancelJob(request), + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::CancelJobRequest const& request) { + return stub_->CancelJob(rest_context, options, request); + }, + *current, request, __func__); +} + +StatusOr JobServiceRestConnectionImpl::GetJob( + google::cloud::bigquery::v2::GetJobRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::rest_internal::RestRetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->GetJob(request), + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::GetJobRequest const& request) { + return stub_->GetJob(rest_context, options, request); + }, + *current, request, __func__); +} + +StatusOr +JobServiceRestConnectionImpl::InsertJob( + google::cloud::bigquery::v2::InsertJobRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::rest_internal::RestRetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->InsertJob(request), + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::InsertJobRequest const& request) { + return stub_->InsertJob(rest_context, options, request); + }, + *current, request, __func__); +} + +Status JobServiceRestConnectionImpl::DeleteJob( + google::cloud::bigquery::v2::DeleteJobRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::rest_internal::RestRetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->DeleteJob(request), + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::DeleteJobRequest const& request) { + return stub_->DeleteJob(rest_context, options, request); + }, + *current, request, __func__); +} + +StreamRange +JobServiceRestConnectionImpl::ListJobs( + google::cloud::bigquery::v2::ListJobsRequest request) { + request.clear_page_token(); + auto current = google::cloud::internal::SaveCurrentOptions(); + auto idempotency = idempotency_policy(*current)->ListJobs(request); + char const* function_name = __func__; + return google::cloud::internal::MakePaginationRange< + StreamRange>( + current, std::move(request), + [idempotency, function_name, stub = stub_, + retry = std::shared_ptr( + retry_policy(*current)), + backoff = std::shared_ptr(backoff_policy(*current))]( + Options const& options, + google::cloud::bigquery::v2::ListJobsRequest const& r) { + return google::cloud::rest_internal::RestRetryLoop( + retry->clone(), backoff->clone(), idempotency, + [stub]( + rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListJobsRequest const& request) { + return stub->ListJobs(rest_context, options, request); + }, + options, r, function_name); + }, + [](google::cloud::bigquery::v2::JobList r) { + std::vector result( + r.jobs().size()); + auto& messages = *r.mutable_jobs(); + std::move(messages.begin(), messages.end(), result.begin()); + return result; + }); +} + +StatusOr +JobServiceRestConnectionImpl::GetQueryResults( + google::cloud::bigquery::v2::GetQueryResultsRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::rest_internal::RestRetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->GetQueryResults(request), + [this]( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::GetQueryResultsRequest const& request) { + return stub_->GetQueryResults(rest_context, options, request); + }, + *current, request, __func__); +} + +StatusOr +JobServiceRestConnectionImpl::Query( + google::cloud::bigquery::v2::PostQueryRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::rest_internal::RestRetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->Query(request), + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::PostQueryRequest const& request) { + return stub_->Query(rest_context, options, request); + }, + *current, request, __func__); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_job_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/job/v2/internal/job_rest_connection_impl.h b/google/cloud/bigquerycontrol/job/v2/internal/job_rest_connection_impl.h new file mode 100644 index 0000000000000..a927a8d1f4c3e --- /dev/null +++ b/google/cloud/bigquerycontrol/job/v2/internal/job_rest_connection_impl.h @@ -0,0 +1,105 @@ +// Copyright 2024 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/v2/job.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_INTERNAL_JOB_REST_CONNECTION_IMPL_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_INTERNAL_JOB_REST_CONNECTION_IMPL_H + +#include "google/cloud/bigquerycontrol/job/v2/internal/job_rest_stub.h" +#include "google/cloud/bigquerycontrol/job/v2/internal/job_retry_traits.h" +#include "google/cloud/bigquerycontrol/job/v2/job_connection.h" +#include "google/cloud/bigquerycontrol/job/v2/job_connection_idempotency_policy.h" +#include "google/cloud/bigquerycontrol/job/v2/job_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 bigquerycontrol_job_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class JobServiceRestConnectionImpl + : public bigquerycontrol_job_v2::JobServiceConnection { + public: + ~JobServiceRestConnectionImpl() override = default; + + JobServiceRestConnectionImpl( + std::unique_ptr background, + std::shared_ptr stub, + Options options); + + Options options() override { return options_; } + + StatusOr CancelJob( + google::cloud::bigquery::v2::CancelJobRequest const& request) override; + + StatusOr GetJob( + google::cloud::bigquery::v2::GetJobRequest const& request) override; + + StatusOr InsertJob( + google::cloud::bigquery::v2::InsertJobRequest const& request) override; + + Status DeleteJob( + google::cloud::bigquery::v2::DeleteJobRequest const& request) override; + + StreamRange ListJobs( + google::cloud::bigquery::v2::ListJobsRequest request) override; + + StatusOr + GetQueryResults(google::cloud::bigquery::v2::GetQueryResultsRequest const& + request) override; + + StatusOr Query( + google::cloud::bigquery::v2::PostQueryRequest const& request) override; + + private: + static std::unique_ptr + retry_policy(Options const& options) { + return options.get() + ->clone(); + } + + static std::unique_ptr backoff_policy(Options const& options) { + return options.get() + ->clone(); + } + + static std::unique_ptr< + bigquerycontrol_job_v2::JobServiceConnectionIdempotencyPolicy> + idempotency_policy(Options const& options) { + return options + .get() + ->clone(); + } + + std::unique_ptr background_; + std::shared_ptr stub_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_job_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_INTERNAL_JOB_REST_CONNECTION_IMPL_H diff --git a/google/cloud/bigquerycontrol/job/v2/internal/job_rest_logging_decorator.cc b/google/cloud/bigquerycontrol/job/v2/internal/job_rest_logging_decorator.cc new file mode 100644 index 0000000000000..5b5d7b67b9514 --- /dev/null +++ b/google/cloud/bigquerycontrol/job/v2/internal/job_rest_logging_decorator.cc @@ -0,0 +1,121 @@ +// Copyright 2024 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/v2/job.proto + +#include "google/cloud/bigquerycontrol/job/v2/internal/job_rest_logging_decorator.h" +#include "google/cloud/internal/log_wrapper.h" +#include "google/cloud/status_or.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_job_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +JobServiceRestLogging::JobServiceRestLogging( + 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 +JobServiceRestLogging::CancelJob( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::CancelJobRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::CancelJobRequest const& request) { + return child_->CancelJob(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +StatusOr JobServiceRestLogging::GetJob( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::GetJobRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::GetJobRequest const& request) { + return child_->GetJob(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +StatusOr JobServiceRestLogging::InsertJob( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::InsertJobRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::InsertJobRequest const& request) { + return child_->InsertJob(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +Status JobServiceRestLogging::DeleteJob( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::DeleteJobRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::DeleteJobRequest const& request) { + return child_->DeleteJob(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +StatusOr JobServiceRestLogging::ListJobs( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::ListJobsRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::ListJobsRequest const& request) { + return child_->ListJobs(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +StatusOr +JobServiceRestLogging::GetQueryResults( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::GetQueryResultsRequest const& request) { + return google::cloud::internal::LogWrapper( + [this]( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::GetQueryResultsRequest const& request) { + return child_->GetQueryResults(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +StatusOr +JobServiceRestLogging::Query( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::PostQueryRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::PostQueryRequest const& request) { + return child_->Query(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_job_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/job/v2/internal/job_rest_logging_decorator.h b/google/cloud/bigquerycontrol/job/v2/internal/job_rest_logging_decorator.h new file mode 100644 index 0000000000000..1ee2dc42d0d7c --- /dev/null +++ b/google/cloud/bigquerycontrol/job/v2/internal/job_rest_logging_decorator.h @@ -0,0 +1,91 @@ +// Copyright 2024 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/v2/job.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_INTERNAL_JOB_REST_LOGGING_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_INTERNAL_JOB_REST_LOGGING_DECORATOR_H + +#include "google/cloud/bigquerycontrol/job/v2/internal/job_rest_stub.h" +#include "google/cloud/future.h" +#include "google/cloud/internal/rest_context.h" +#include "google/cloud/tracing_options.h" +#include "google/cloud/version.h" +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_job_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class JobServiceRestLogging : public JobServiceRestStub { + public: + ~JobServiceRestLogging() override = default; + JobServiceRestLogging(std::shared_ptr child, + TracingOptions tracing_options, + std::set components); + + StatusOr CancelJob( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::CancelJobRequest const& request) override; + + StatusOr GetJob( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetJobRequest const& request) override; + + StatusOr InsertJob( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::InsertJobRequest const& request) override; + + Status DeleteJob( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::DeleteJobRequest const& request) override; + + StatusOr ListJobs( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListJobsRequest const& request) override; + + StatusOr + GetQueryResults(google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetQueryResultsRequest const& + request) override; + + StatusOr Query( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::PostQueryRequest const& request) override; + + private: + std::shared_ptr child_; + TracingOptions tracing_options_; + std::set components_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_job_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_INTERNAL_JOB_REST_LOGGING_DECORATOR_H diff --git a/google/cloud/bigquerycontrol/job/v2/internal/job_rest_metadata_decorator.cc b/google/cloud/bigquerycontrol/job/v2/internal/job_rest_metadata_decorator.cc new file mode 100644 index 0000000000000..d4037863e322d --- /dev/null +++ b/google/cloud/bigquerycontrol/job/v2/internal/job_rest_metadata_decorator.cc @@ -0,0 +1,103 @@ +// Copyright 2024 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/v2/job.proto + +#include "google/cloud/bigquerycontrol/job/v2/internal/job_rest_metadata_decorator.h" +#include "google/cloud/internal/absl_str_cat_quiet.h" +#include "google/cloud/internal/api_client_header.h" +#include "google/cloud/internal/rest_set_metadata.h" +#include "google/cloud/status_or.h" +#include "absl/strings/str_format.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_job_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +JobServiceRestMetadata::JobServiceRestMetadata( + std::shared_ptr child, std::string api_client_header) + : child_(std::move(child)), + api_client_header_( + api_client_header.empty() + ? google::cloud::internal::GeneratedLibClientHeader() + : std::move(api_client_header)) {} + +StatusOr +JobServiceRestMetadata::CancelJob( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::CancelJobRequest const& request) { + SetMetadata(rest_context, options); + return child_->CancelJob(rest_context, options, request); +} + +StatusOr JobServiceRestMetadata::GetJob( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::GetJobRequest const& request) { + SetMetadata(rest_context, options); + return child_->GetJob(rest_context, options, request); +} + +StatusOr JobServiceRestMetadata::InsertJob( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::InsertJobRequest const& request) { + SetMetadata(rest_context, options); + return child_->InsertJob(rest_context, options, request); +} + +Status JobServiceRestMetadata::DeleteJob( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::DeleteJobRequest const& request) { + SetMetadata(rest_context, options); + return child_->DeleteJob(rest_context, options, request); +} + +StatusOr JobServiceRestMetadata::ListJobs( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::ListJobsRequest const& request) { + SetMetadata(rest_context, options); + return child_->ListJobs(rest_context, options, request); +} + +StatusOr +JobServiceRestMetadata::GetQueryResults( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::GetQueryResultsRequest const& request) { + SetMetadata(rest_context, options); + return child_->GetQueryResults(rest_context, options, request); +} + +StatusOr +JobServiceRestMetadata::Query( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::PostQueryRequest const& request) { + SetMetadata(rest_context, options); + return child_->Query(rest_context, options, request); +} + +void JobServiceRestMetadata::SetMetadata( + rest_internal::RestContext& rest_context, Options const& options, + std::vector const& params) { + google::cloud::rest_internal::SetMetadata(rest_context, options, params, + api_client_header_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_job_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/job/v2/internal/job_rest_metadata_decorator.h b/google/cloud/bigquerycontrol/job/v2/internal/job_rest_metadata_decorator.h new file mode 100644 index 0000000000000..2e71ca329e6a8 --- /dev/null +++ b/google/cloud/bigquerycontrol/job/v2/internal/job_rest_metadata_decorator.h @@ -0,0 +1,91 @@ +// Copyright 2024 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/v2/job.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_INTERNAL_JOB_REST_METADATA_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_INTERNAL_JOB_REST_METADATA_DECORATOR_H + +#include "google/cloud/bigquerycontrol/job/v2/internal/job_rest_stub.h" +#include "google/cloud/future.h" +#include "google/cloud/rest_options.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_job_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class JobServiceRestMetadata : public JobServiceRestStub { + public: + ~JobServiceRestMetadata() override = default; + explicit JobServiceRestMetadata(std::shared_ptr child, + std::string api_client_header = ""); + + StatusOr CancelJob( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::CancelJobRequest const& request) override; + + StatusOr GetJob( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetJobRequest const& request) override; + + StatusOr InsertJob( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::InsertJobRequest const& request) override; + + Status DeleteJob( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::DeleteJobRequest const& request) override; + + StatusOr ListJobs( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListJobsRequest const& request) override; + + StatusOr + GetQueryResults(google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetQueryResultsRequest const& + request) override; + + StatusOr Query( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::PostQueryRequest const& request) override; + + private: + void SetMetadata(rest_internal::RestContext& rest_context, + Options const& options, + std::vector const& params = {}); + + std::shared_ptr child_; + std::string api_client_header_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_job_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_INTERNAL_JOB_REST_METADATA_DECORATOR_H diff --git a/google/cloud/bigquerycontrol/job/v2/internal/job_rest_stub.cc b/google/cloud/bigquerycontrol/job/v2/internal/job_rest_stub.cc new file mode 100644 index 0000000000000..956f814888bd8 --- /dev/null +++ b/google/cloud/bigquerycontrol/job/v2/internal/job_rest_stub.cc @@ -0,0 +1,147 @@ +// Copyright 2024 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/v2/job.proto + +#include "google/cloud/bigquerycontrol/job/v2/internal/job_rest_stub.h" +#include "google/cloud/common_options.h" +#include "google/cloud/internal/absl_str_cat_quiet.h" +#include "google/cloud/internal/rest_stub_helpers.h" +#include "google/cloud/status_or.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_job_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +DefaultJobServiceRestStub::DefaultJobServiceRestStub(Options options) + : service_(rest_internal::MakePooledRestClient( + options.get(), options)), + options_(std::move(options)) {} + +DefaultJobServiceRestStub::DefaultJobServiceRestStub( + std::shared_ptr service, Options options) + : service_(std::move(service)), options_(std::move(options)) {} + +StatusOr +DefaultJobServiceRestStub::CancelJob( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::CancelJobRequest const& request) { + return rest_internal::Post( + *service_, rest_context, request, false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "jobs", "/", + request.job_id(), "/", "cancel"), + rest_internal::TrimEmptyQueryParameters( + {std::make_pair("location", request.location())})); +} + +StatusOr DefaultJobServiceRestStub::GetJob( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetJobRequest const& request) { + return rest_internal::Get( + *service_, rest_context, request, false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "jobs", "/", + request.job_id()), + rest_internal::TrimEmptyQueryParameters( + {std::make_pair("location", request.location())})); +} + +StatusOr DefaultJobServiceRestStub::InsertJob( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::InsertJobRequest const& request) { + return rest_internal::Post( + *service_, rest_context, request.job(), false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "jobs")); +} + +Status DefaultJobServiceRestStub::DeleteJob( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::DeleteJobRequest const& request) { + return rest_internal::Delete( + *service_, rest_context, request, false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "jobs", "/", + request.job_id(), "/", "delete"), + rest_internal::TrimEmptyQueryParameters( + {std::make_pair("location", request.location())})); +} + +StatusOr +DefaultJobServiceRestStub::ListJobs( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListJobsRequest const& request) { + return rest_internal::Get( + *service_, rest_context, request, false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "jobs"), + rest_internal::TrimEmptyQueryParameters( + {std::make_pair("all_users", request.all_users() ? "1" : "0"), + std::make_pair("min_creation_time", + std::to_string(request.min_creation_time())), + std::make_pair("page_token", request.page_token()), + std::make_pair("projection", std::to_string(request.projection())), + std::make_pair("parent_job_id", request.parent_job_id())})); +} + +StatusOr +DefaultJobServiceRestStub::GetQueryResults( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetQueryResultsRequest const& request) { + return rest_internal::Get< + google::cloud::bigquery::v2::GetQueryResultsResponse>( + *service_, rest_context, request, false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "queries", "/", + request.job_id()), + rest_internal::TrimEmptyQueryParameters( + {std::make_pair("page_token", request.page_token()), + std::make_pair("location", request.location())})); +} + +StatusOr +DefaultJobServiceRestStub::Query( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::PostQueryRequest const& request) { + return rest_internal::Post( + *service_, rest_context, request.query_request(), false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "queries")); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_job_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/job/v2/internal/job_rest_stub.h b/google/cloud/bigquerycontrol/job/v2/internal/job_rest_stub.h new file mode 100644 index 0000000000000..526c6bf21e4ad --- /dev/null +++ b/google/cloud/bigquerycontrol/job/v2/internal/job_rest_stub.h @@ -0,0 +1,130 @@ +// Copyright 2024 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/v2/job.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_INTERNAL_JOB_REST_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_INTERNAL_JOB_REST_STUB_H + +#include "google/cloud/completion_queue.h" +#include "google/cloud/internal/rest_client.h" +#include "google/cloud/internal/rest_context.h" +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_job_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class JobServiceRestStub { + public: + virtual ~JobServiceRestStub() = default; + + virtual StatusOr CancelJob( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::CancelJobRequest const& request) = 0; + + virtual StatusOr GetJob( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetJobRequest const& request) = 0; + + virtual StatusOr InsertJob( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::InsertJobRequest const& request) = 0; + + virtual Status DeleteJob( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::DeleteJobRequest const& request) = 0; + + virtual StatusOr ListJobs( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListJobsRequest const& request) = 0; + + virtual StatusOr + GetQueryResults( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetQueryResultsRequest const& request) = 0; + + virtual StatusOr Query( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::PostQueryRequest const& request) = 0; +}; + +class DefaultJobServiceRestStub : public JobServiceRestStub { + public: + ~DefaultJobServiceRestStub() override = default; + + explicit DefaultJobServiceRestStub(Options options); + DefaultJobServiceRestStub(std::shared_ptr service, + Options options); + + StatusOr CancelJob( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::CancelJobRequest const& request) override; + + StatusOr GetJob( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetJobRequest const& request) override; + + StatusOr InsertJob( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::InsertJobRequest const& request) override; + + Status DeleteJob( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::DeleteJobRequest const& request) override; + + StatusOr ListJobs( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListJobsRequest const& request) override; + + StatusOr + GetQueryResults(google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetQueryResultsRequest const& + request) override; + + StatusOr Query( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::PostQueryRequest const& request) override; + + private: + std::shared_ptr service_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_job_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_INTERNAL_JOB_REST_STUB_H diff --git a/google/cloud/bigquerycontrol/job/v2/internal/job_rest_stub_factory.cc b/google/cloud/bigquerycontrol/job/v2/internal/job_rest_stub_factory.cc new file mode 100644 index 0000000000000..c583645372331 --- /dev/null +++ b/google/cloud/bigquerycontrol/job/v2/internal/job_rest_stub_factory.cc @@ -0,0 +1,56 @@ +// Copyright 2024 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/v2/job.proto + +#include "google/cloud/bigquerycontrol/job/v2/internal/job_rest_stub_factory.h" +#include "google/cloud/bigquerycontrol/job/v2/internal/job_rest_logging_decorator.h" +#include "google/cloud/bigquerycontrol/job/v2/internal/job_rest_metadata_decorator.h" +#include "google/cloud/bigquerycontrol/job/v2/internal/job_rest_stub.h" +#include "google/cloud/common_options.h" +#include "google/cloud/internal/algorithm.h" +#include "google/cloud/internal/populate_rest_options.h" +#include "google/cloud/log.h" +#include "google/cloud/options.h" +#include "google/cloud/rest_options.h" +#include "absl/strings/match.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_job_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultJobServiceRestStub( + Options const& options) { + auto opts = internal::PopulateRestOptions(options); + std::shared_ptr stub = + std::make_shared(std::move(opts)); + stub = std::make_shared(std::move(stub)); + if (internal::Contains(options.get(), "rpc")) { + GCP_LOG(INFO) << "Enabled logging for REST rpc calls"; + stub = std::make_shared( + std::move(stub), options.get(), + options.get()); + } + return stub; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_job_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/job/v2/internal/job_rest_stub_factory.h b/google/cloud/bigquerycontrol/job/v2/internal/job_rest_stub_factory.h new file mode 100644 index 0000000000000..b923b951cd72e --- /dev/null +++ b/google/cloud/bigquerycontrol/job/v2/internal/job_rest_stub_factory.h @@ -0,0 +1,40 @@ +// Copyright 2024 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/v2/job.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_INTERNAL_JOB_REST_STUB_FACTORY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_INTERNAL_JOB_REST_STUB_FACTORY_H + +#include "google/cloud/bigquerycontrol/job/v2/internal/job_rest_stub.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_job_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultJobServiceRestStub( + Options const& options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_job_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_INTERNAL_JOB_REST_STUB_FACTORY_H diff --git a/google/cloud/bigquerycontrol/job/v2/internal/job_retry_traits.h b/google/cloud/bigquerycontrol/job/v2/internal/job_retry_traits.h new file mode 100644 index 0000000000000..453cd7c55f9e5 --- /dev/null +++ b/google/cloud/bigquerycontrol/job/v2/internal/job_retry_traits.h @@ -0,0 +1,43 @@ +// Copyright 2024 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/v2/job.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_INTERNAL_JOB_RETRY_TRAITS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_INTERNAL_JOB_RETRY_TRAITS_H + +#include "google/cloud/status.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace bigquerycontrol_job_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// Define the gRPC status code semantics for retrying requests. +struct JobServiceRetryTraits { + static bool IsPermanentFailure(google::cloud::Status const& status) { + return status.code() != StatusCode::kOk && + status.code() != StatusCode::kUnavailable; + } +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_job_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_INTERNAL_JOB_RETRY_TRAITS_H diff --git a/google/cloud/bigquerycontrol/job/v2/internal/job_sources.cc b/google/cloud/bigquerycontrol/job/v2/internal/job_sources.cc new file mode 100644 index 0000000000000..87e29d2542863 --- /dev/null +++ b/google/cloud/bigquerycontrol/job/v2/internal/job_sources.cc @@ -0,0 +1,31 @@ +// Copyright 2024 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/v2/job.proto + +// NOLINTBEGIN(bugprone-suspicious-include) +#include "google/cloud/bigquerycontrol/job/v2/internal/job_option_defaults.cc" +#include "google/cloud/bigquerycontrol/job/v2/internal/job_rest_connection_impl.cc" +#include "google/cloud/bigquerycontrol/job/v2/internal/job_rest_logging_decorator.cc" +#include "google/cloud/bigquerycontrol/job/v2/internal/job_rest_metadata_decorator.cc" +#include "google/cloud/bigquerycontrol/job/v2/internal/job_rest_stub.cc" +#include "google/cloud/bigquerycontrol/job/v2/internal/job_rest_stub_factory.cc" +#include "google/cloud/bigquerycontrol/job/v2/internal/job_tracing_connection.cc" +#include "google/cloud/bigquerycontrol/job/v2/job_client.cc" +#include "google/cloud/bigquerycontrol/job/v2/job_connection.cc" +#include "google/cloud/bigquerycontrol/job/v2/job_connection_idempotency_policy.cc" +#include "google/cloud/bigquerycontrol/job/v2/job_rest_connection.cc" +// NOLINTEND(bugprone-suspicious-include) diff --git a/google/cloud/bigquerycontrol/job/v2/internal/job_tracing_connection.cc b/google/cloud/bigquerycontrol/job/v2/internal/job_tracing_connection.cc new file mode 100644 index 0000000000000..144424cdf9cd9 --- /dev/null +++ b/google/cloud/bigquerycontrol/job/v2/internal/job_tracing_connection.cc @@ -0,0 +1,116 @@ +// Copyright 2024 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/v2/job.proto + +#include "google/cloud/bigquerycontrol/job/v2/internal/job_tracing_connection.h" +#include "google/cloud/internal/opentelemetry.h" +#include "google/cloud/internal/traced_stream_range.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_job_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +JobServiceTracingConnection::JobServiceTracingConnection( + std::shared_ptr child) + : child_(std::move(child)) {} + +StatusOr +JobServiceTracingConnection::CancelJob( + google::cloud::bigquery::v2::CancelJobRequest const& request) { + auto span = internal::MakeSpan( + "bigquerycontrol_job_v2::JobServiceConnection::CancelJob"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->CancelJob(request)); +} + +StatusOr JobServiceTracingConnection::GetJob( + google::cloud::bigquery::v2::GetJobRequest const& request) { + auto span = internal::MakeSpan( + "bigquerycontrol_job_v2::JobServiceConnection::GetJob"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->GetJob(request)); +} + +StatusOr +JobServiceTracingConnection::InsertJob( + google::cloud::bigquery::v2::InsertJobRequest const& request) { + auto span = internal::MakeSpan( + "bigquerycontrol_job_v2::JobServiceConnection::InsertJob"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->InsertJob(request)); +} + +Status JobServiceTracingConnection::DeleteJob( + google::cloud::bigquery::v2::DeleteJobRequest const& request) { + auto span = internal::MakeSpan( + "bigquerycontrol_job_v2::JobServiceConnection::DeleteJob"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->DeleteJob(request)); +} + +StreamRange +JobServiceTracingConnection::ListJobs( + google::cloud::bigquery::v2::ListJobsRequest request) { + auto span = internal::MakeSpan( + "bigquerycontrol_job_v2::JobServiceConnection::ListJobs"); + internal::OTelScope scope(span); + auto sr = child_->ListJobs(std::move(request)); + return internal::MakeTracedStreamRange< + google::cloud::bigquery::v2::ListFormatJob>(std::move(span), + std::move(sr)); +} + +StatusOr +JobServiceTracingConnection::GetQueryResults( + google::cloud::bigquery::v2::GetQueryResultsRequest const& request) { + auto span = internal::MakeSpan( + "bigquerycontrol_job_v2::JobServiceConnection::GetQueryResults"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->GetQueryResults(request)); +} + +StatusOr +JobServiceTracingConnection::Query( + google::cloud::bigquery::v2::PostQueryRequest const& request) { + auto span = + internal::MakeSpan("bigquerycontrol_job_v2::JobServiceConnection::Query"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->Query(request)); +} + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +std::shared_ptr +MakeJobServiceTracingConnection( + std::shared_ptr conn) { +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + if (internal::TracingEnabled(conn->options())) { + conn = std::make_shared(std::move(conn)); + } +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + return conn; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_job_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/job/v2/internal/job_tracing_connection.h b/google/cloud/bigquerycontrol/job/v2/internal/job_tracing_connection.h new file mode 100644 index 0000000000000..0749555bc301b --- /dev/null +++ b/google/cloud/bigquerycontrol/job/v2/internal/job_tracing_connection.h @@ -0,0 +1,86 @@ +// Copyright 2024 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/v2/job.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_INTERNAL_JOB_TRACING_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_INTERNAL_JOB_TRACING_CONNECTION_H + +#include "google/cloud/bigquerycontrol/job/v2/job_connection.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_job_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +class JobServiceTracingConnection + : public bigquerycontrol_job_v2::JobServiceConnection { + public: + ~JobServiceTracingConnection() override = default; + + explicit JobServiceTracingConnection( + std::shared_ptr child); + + Options options() override { return child_->options(); } + + StatusOr CancelJob( + google::cloud::bigquery::v2::CancelJobRequest const& request) override; + + StatusOr GetJob( + google::cloud::bigquery::v2::GetJobRequest const& request) override; + + StatusOr InsertJob( + google::cloud::bigquery::v2::InsertJobRequest const& request) override; + + Status DeleteJob( + google::cloud::bigquery::v2::DeleteJobRequest const& request) override; + + StreamRange ListJobs( + google::cloud::bigquery::v2::ListJobsRequest request) override; + + StatusOr + GetQueryResults(google::cloud::bigquery::v2::GetQueryResultsRequest const& + request) override; + + StatusOr Query( + google::cloud::bigquery::v2::PostQueryRequest const& request) override; + + private: + std::shared_ptr child_; +}; + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +/** + * Conditionally applies the tracing decorator to the given connection. + * + * The connection is only decorated if tracing is enabled (as determined by the + * connection's options). + */ +std::shared_ptr +MakeJobServiceTracingConnection( + std::shared_ptr conn); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_job_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_INTERNAL_JOB_TRACING_CONNECTION_H diff --git a/google/cloud/bigquerycontrol/job/v2/job_client.cc b/google/cloud/bigquerycontrol/job/v2/job_client.cc new file mode 100644 index 0000000000000..45e09014033e3 --- /dev/null +++ b/google/cloud/bigquerycontrol/job/v2/job_client.cc @@ -0,0 +1,88 @@ +// Copyright 2024 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/v2/job.proto + +#include "google/cloud/bigquerycontrol/job/v2/job_client.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_job_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +JobServiceClient::JobServiceClient( + std::shared_ptr connection, Options opts) + : connection_(std::move(connection)), + options_( + internal::MergeOptions(std::move(opts), connection_->options())) {} +JobServiceClient::~JobServiceClient() = default; + +StatusOr +JobServiceClient::CancelJob( + google::cloud::bigquery::v2::CancelJobRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->CancelJob(request); +} + +StatusOr JobServiceClient::GetJob( + google::cloud::bigquery::v2::GetJobRequest const& request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->GetJob(request); +} + +StatusOr JobServiceClient::InsertJob( + google::cloud::bigquery::v2::InsertJobRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->InsertJob(request); +} + +Status JobServiceClient::DeleteJob( + google::cloud::bigquery::v2::DeleteJobRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->DeleteJob(request); +} + +StreamRange +JobServiceClient::ListJobs(google::cloud::bigquery::v2::ListJobsRequest request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->ListJobs(std::move(request)); +} + +StatusOr +JobServiceClient::GetQueryResults( + google::cloud::bigquery::v2::GetQueryResultsRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->GetQueryResults(request); +} + +StatusOr JobServiceClient::Query( + google::cloud::bigquery::v2::PostQueryRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->Query(request); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_job_v2 +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/job/v2/job_client.h b/google/cloud/bigquerycontrol/job/v2/job_client.h new file mode 100644 index 0000000000000..f5593f9338b02 --- /dev/null +++ b/google/cloud/bigquerycontrol/job/v2/job_client.h @@ -0,0 +1,341 @@ +// Copyright 2024 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/v2/job.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_JOB_CLIENT_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_JOB_CLIENT_H + +#include "google/cloud/bigquerycontrol/job/v2/job_rest_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 bigquerycontrol_job_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// +/// This is an experimental RPC service definition for the BigQuery +/// Job Service. +/// +/// It should not be relied on for production use cases at this time. +/// +/// @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 JobServiceClient { + public: + explicit JobServiceClient(std::shared_ptr connection, + Options opts = {}); + ~JobServiceClient(); + + ///@{ + /// @name Copy and move support + JobServiceClient(JobServiceClient const&) = default; + JobServiceClient& operator=(JobServiceClient const&) = default; + JobServiceClient(JobServiceClient&&) = default; + JobServiceClient& operator=(JobServiceClient&&) = default; + ///@} + + ///@{ + /// @name Equality + friend bool operator==(JobServiceClient const& a, JobServiceClient const& b) { + return a.connection_ == b.connection_; + } + friend bool operator!=(JobServiceClient const& a, JobServiceClient const& b) { + return !(a == b); + } + ///@} + + // clang-format off + /// + /// Requests that a job be cancelled. This call will return immediately, and + /// the client will need to poll for the job status to see if the cancel + /// completed successfully. Cancelled jobs may still incur costs. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.CancelJobRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return the result of the RPC. The response message type + /// ([google.cloud.bigquery.v2.JobCancelResponse]) + /// is mapped to a C++ class using the [Protobuf mapping rules]. + /// If the request fails, the [`StatusOr`] contains the error details. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.CancelJobRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/job.proto#L172} + /// [google.cloud.bigquery.v2.JobCancelResponse]: @googleapis_reference_link{google/cloud/bigquery/v2/job.proto#L191} + /// + // clang-format on + StatusOr CancelJob( + google::cloud::bigquery::v2::CancelJobRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Returns information about a specific job. Job information is available for + /// a six month period after creation. Requires that you're the person who ran + /// the job, or have the Is Owner project role. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.GetJobRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return the result of the RPC. The response message type + /// ([google.cloud.bigquery.v2.Job]) + /// is mapped to a C++ class using the [Protobuf mapping rules]. + /// If the request fails, the [`StatusOr`] contains the error details. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.GetJobRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/job.proto#L200} + /// [google.cloud.bigquery.v2.Job]: @googleapis_reference_link{google/cloud/bigquery/v2/job.proto#L128} + /// + // clang-format on + StatusOr GetJob( + google::cloud::bigquery::v2::GetJobRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Starts a new asynchronous job. + /// + /// This API has two different kinds of endpoint URIs, as this method supports + /// a variety of use cases. + /// + /// * The *Metadata* URI is used for most interactions, as it accepts the job + /// configuration directly. + /// * The *Upload* URI is ONLY for the case when you're sending both a load job + /// configuration and a data stream together. In this case, the Upload URI + /// accepts the job configuration and the data as two distinct multipart MIME + /// parts. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.InsertJobRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return the result of the RPC. The response message type + /// ([google.cloud.bigquery.v2.Job]) + /// is mapped to a C++ class using the [Protobuf mapping rules]. + /// If the request fails, the [`StatusOr`] contains the error details. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.InsertJobRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/job.proto#L219} + /// [google.cloud.bigquery.v2.Job]: @googleapis_reference_link{google/cloud/bigquery/v2/job.proto#L128} + /// + // clang-format on + StatusOr InsertJob( + google::cloud::bigquery::v2::InsertJobRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Requests the deletion of the metadata of a job. This call returns when the + /// job's metadata is deleted. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.DeleteJobRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return a [`Status`] object. If the request failed, the + /// status contains the details of the failure. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.DeleteJobRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/job.proto#L228} + /// + // clang-format on + Status DeleteJob(google::cloud::bigquery::v2::DeleteJobRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Lists all jobs that you started in the specified project. Job information + /// is available for a six month period after creation. The job list is sorted + /// in reverse chronological order, by job creation time. Requires the Can View + /// project role, or the Is Owner project role if you set the allUsers + /// property. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.ListJobsRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return a [StreamRange](@ref google::cloud::StreamRange) + /// to iterate of the results. See the documentation of this type for + /// details. In brief, this class has `begin()` and `end()` member + /// functions returning a iterator class meeting the + /// [input iterator requirements]. The value type for this iterator is a + /// [`StatusOr`] as the iteration may fail even after some values are + /// retrieved successfully, for example, if there is a network disconnect. + /// An empty set of results does not indicate an error, it indicates + /// that there are no resources meeting the request criteria. + /// On a successful iteration the `StatusOr` contains elements of type + /// [google.cloud.bigquery.v2.ListFormatJob], or rather, + /// the C++ class generated by Protobuf from that type. Please consult the + /// Protobuf documentation for details on the [Protobuf mapping rules]. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.ListFormatJob]: @googleapis_reference_link{google/cloud/bigquery/v2/job.proto#L321} + /// [google.cloud.bigquery.v2.ListJobsRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/job.proto#L245} + /// + // clang-format on + StreamRange ListJobs( + google::cloud::bigquery::v2::ListJobsRequest request, Options opts = {}); + + // clang-format off + /// + /// RPC to get the results of a query job. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.GetQueryResultsRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return the result of the RPC. The response message type + /// ([google.cloud.bigquery.v2.GetQueryResultsResponse]) + /// is mapped to a C++ class using the [Protobuf mapping rules]. + /// If the request fails, the [`StatusOr`] contains the error details. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.GetQueryResultsRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/job.proto#L378} + /// [google.cloud.bigquery.v2.GetQueryResultsResponse]: @googleapis_reference_link{google/cloud/bigquery/v2/job.proto#L426} + /// + // clang-format on + StatusOr + GetQueryResults( + google::cloud::bigquery::v2::GetQueryResultsRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Runs a BigQuery SQL query synchronously and returns query results if the + /// query completes within a specified timeout. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.PostQueryRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return the result of the RPC. The response message type + /// ([google.cloud.bigquery.v2.QueryResponse]) + /// is mapped to a C++ class using the [Protobuf mapping rules]. + /// If the request fails, the [`StatusOr`] contains the error details. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.PostQueryRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/job.proto#L488} + /// [google.cloud.bigquery.v2.QueryResponse]: @googleapis_reference_link{google/cloud/bigquery/v2/job.proto#L657} + /// + // clang-format on + StatusOr Query( + google::cloud::bigquery::v2::PostQueryRequest const& request, + Options opts = {}); + + private: + std::shared_ptr connection_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_job_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_JOB_CLIENT_H diff --git a/google/cloud/bigquerycontrol/job/v2/job_connection.cc b/google/cloud/bigquerycontrol/job/v2/job_connection.cc new file mode 100644 index 0000000000000..b0bc928319737 --- /dev/null +++ b/google/cloud/bigquerycontrol/job/v2/job_connection.cc @@ -0,0 +1,83 @@ +// Copyright 2024 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/v2/job.proto + +#include "google/cloud/bigquerycontrol/job/v2/job_connection.h" +#include "google/cloud/bigquerycontrol/job/v2/internal/job_option_defaults.h" +#include "google/cloud/bigquerycontrol/job/v2/internal/job_tracing_connection.h" +#include "google/cloud/bigquerycontrol/job/v2/job_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 "google/cloud/internal/unified_grpc_credentials.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_job_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +JobServiceConnection::~JobServiceConnection() = default; + +StatusOr +JobServiceConnection::CancelJob( + google::cloud::bigquery::v2::CancelJobRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr JobServiceConnection::GetJob( + google::cloud::bigquery::v2::GetJobRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr JobServiceConnection::InsertJob( + google::cloud::bigquery::v2::InsertJobRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +Status JobServiceConnection::DeleteJob( + google::cloud::bigquery::v2::DeleteJobRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StreamRange +JobServiceConnection::ListJobs( + google::cloud::bigquery::v2:: + ListJobsRequest) { // NOLINT(performance-unnecessary-value-param) + return google::cloud::internal::MakeUnimplementedPaginationRange< + StreamRange>(); +} + +StatusOr +JobServiceConnection::GetQueryResults( + google::cloud::bigquery::v2::GetQueryResultsRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +JobServiceConnection::Query( + google::cloud::bigquery::v2::PostQueryRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_job_v2 +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/job/v2/job_connection.h b/google/cloud/bigquerycontrol/job/v2/job_connection.h new file mode 100644 index 0000000000000..f9a8648792f97 --- /dev/null +++ b/google/cloud/bigquerycontrol/job/v2/job_connection.h @@ -0,0 +1,213 @@ +// Copyright 2024 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/v2/job.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_JOB_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_JOB_CONNECTION_H + +#include "google/cloud/bigquerycontrol/job/v2/internal/job_retry_traits.h" +#include "google/cloud/bigquerycontrol/job/v2/job_connection_idempotency_policy.h" +#include "google/cloud/backoff_policy.h" +#include "google/cloud/experimental_tag.h" +#include "google/cloud/internal/retry_policy_impl.h" +#include "google/cloud/options.h" +#include "google/cloud/status_or.h" +#include "google/cloud/stream_range.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_job_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// The retry policy for `JobServiceConnection`. +class JobServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `JobServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class JobServiceLimitedErrorCountRetryPolicy : public JobServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit JobServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + JobServiceLimitedErrorCountRetryPolicy( + JobServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : JobServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + JobServiceLimitedErrorCountRetryPolicy( + JobServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : JobServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = JobServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + bigquerycontrol_job_v2_internal::JobServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `JobServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class JobServiceLimitedTimeRetryPolicy : public JobServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit JobServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + JobServiceLimitedTimeRetryPolicy( + JobServiceLimitedTimeRetryPolicy&& rhs) noexcept + : JobServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + JobServiceLimitedTimeRetryPolicy( + JobServiceLimitedTimeRetryPolicy const& rhs) noexcept + : JobServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = JobServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + bigquerycontrol_job_v2_internal::JobServiceRetryTraits> + impl_; +}; + +/** + * The `JobServiceConnection` object for `JobServiceClient`. + * + * This interface defines virtual methods for each of the user-facing overload + * sets in `JobServiceClient`. This allows users to inject custom behavior + * (e.g., with a Google Mock object) when writing tests that use objects of type + * `JobServiceClient`. + * + * To create a concrete instance, see `MakeJobServiceConnection()`. + * + * For mocking, see `bigquerycontrol_job_v2_mocks::MockJobServiceConnection`. + */ +class JobServiceConnection { + public: + virtual ~JobServiceConnection() = 0; + + virtual Options options() { return Options{}; } + + virtual StatusOr CancelJob( + google::cloud::bigquery::v2::CancelJobRequest const& request); + + virtual StatusOr GetJob( + google::cloud::bigquery::v2::GetJobRequest const& request); + + virtual StatusOr InsertJob( + google::cloud::bigquery::v2::InsertJobRequest const& request); + + virtual Status DeleteJob( + google::cloud::bigquery::v2::DeleteJobRequest const& request); + + virtual StreamRange ListJobs( + google::cloud::bigquery::v2::ListJobsRequest request); + + virtual StatusOr + GetQueryResults( + google::cloud::bigquery::v2::GetQueryResultsRequest const& request); + + virtual StatusOr Query( + google::cloud::bigquery::v2::PostQueryRequest const& request); +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_job_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_JOB_CONNECTION_H diff --git a/google/cloud/bigquerycontrol/job/v2/job_connection_idempotency_policy.cc b/google/cloud/bigquerycontrol/job/v2/job_connection_idempotency_policy.cc new file mode 100644 index 0000000000000..e558e65341259 --- /dev/null +++ b/google/cloud/bigquerycontrol/job/v2/job_connection_idempotency_policy.cc @@ -0,0 +1,80 @@ +// Copyright 2024 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/v2/job.proto + +#include "google/cloud/bigquerycontrol/job/v2/job_connection_idempotency_policy.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_job_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +using ::google::cloud::Idempotency; + +JobServiceConnectionIdempotencyPolicy:: + ~JobServiceConnectionIdempotencyPolicy() = default; + +std::unique_ptr +JobServiceConnectionIdempotencyPolicy::clone() const { + return std::make_unique(*this); +} + +Idempotency JobServiceConnectionIdempotencyPolicy::CancelJob( + google::cloud::bigquery::v2::CancelJobRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency JobServiceConnectionIdempotencyPolicy::GetJob( + google::cloud::bigquery::v2::GetJobRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency JobServiceConnectionIdempotencyPolicy::InsertJob( + google::cloud::bigquery::v2::InsertJobRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency JobServiceConnectionIdempotencyPolicy::DeleteJob( + google::cloud::bigquery::v2::DeleteJobRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency JobServiceConnectionIdempotencyPolicy::ListJobs( + google::cloud::bigquery::v2::ListJobsRequest) { // NOLINT + return Idempotency::kIdempotent; +} + +Idempotency JobServiceConnectionIdempotencyPolicy::GetQueryResults( + google::cloud::bigquery::v2::GetQueryResultsRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency JobServiceConnectionIdempotencyPolicy::Query( + google::cloud::bigquery::v2::PostQueryRequest const&) { + return Idempotency::kNonIdempotent; +} + +std::unique_ptr +MakeDefaultJobServiceConnectionIdempotencyPolicy() { + return std::make_unique(); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_job_v2 +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/job/v2/job_connection_idempotency_policy.h b/google/cloud/bigquerycontrol/job/v2/job_connection_idempotency_policy.h new file mode 100644 index 0000000000000..9aedc1977b93c --- /dev/null +++ b/google/cloud/bigquerycontrol/job/v2/job_connection_idempotency_policy.h @@ -0,0 +1,69 @@ +// Copyright 2024 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/v2/job.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_JOB_CONNECTION_IDEMPOTENCY_POLICY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_JOB_CONNECTION_IDEMPOTENCY_POLICY_H + +#include "google/cloud/idempotency.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_job_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class JobServiceConnectionIdempotencyPolicy { + public: + virtual ~JobServiceConnectionIdempotencyPolicy(); + + /// Create a new copy of this object. + virtual std::unique_ptr clone() const; + + virtual google::cloud::Idempotency CancelJob( + google::cloud::bigquery::v2::CancelJobRequest const& request); + + virtual google::cloud::Idempotency GetJob( + google::cloud::bigquery::v2::GetJobRequest const& request); + + virtual google::cloud::Idempotency InsertJob( + google::cloud::bigquery::v2::InsertJobRequest const& request); + + virtual google::cloud::Idempotency DeleteJob( + google::cloud::bigquery::v2::DeleteJobRequest const& request); + + virtual google::cloud::Idempotency ListJobs( + google::cloud::bigquery::v2::ListJobsRequest request); + + virtual google::cloud::Idempotency GetQueryResults( + google::cloud::bigquery::v2::GetQueryResultsRequest const& request); + + virtual google::cloud::Idempotency Query( + google::cloud::bigquery::v2::PostQueryRequest const& request); +}; + +std::unique_ptr +MakeDefaultJobServiceConnectionIdempotencyPolicy(); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_job_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_JOB_CONNECTION_IDEMPOTENCY_POLICY_H diff --git a/google/cloud/bigquerycontrol/job/v2/job_options.h b/google/cloud/bigquerycontrol/job/v2/job_options.h new file mode 100644 index 0000000000000..4858c1634f3d9 --- /dev/null +++ b/google/cloud/bigquerycontrol/job/v2/job_options.h @@ -0,0 +1,75 @@ +// Copyright 2024 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/v2/job.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_JOB_OPTIONS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_JOB_OPTIONS_H + +#include "google/cloud/bigquerycontrol/job/v2/job_connection.h" +#include "google/cloud/bigquerycontrol/job/v2/job_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 bigquerycontrol_job_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * Use with `google::cloud::Options` to configure the retry policy. + * + * @ingroup google-cloud-bigquerycontrol-options + */ +struct JobServiceRetryPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure the backoff policy. + * + * @ingroup google-cloud-bigquerycontrol-options + */ +struct JobServiceBackoffPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure which operations are retried. + * + * @ingroup google-cloud-bigquerycontrol-options + */ +struct JobServiceConnectionIdempotencyPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * The options applicable to JobService. + * + * @ingroup google-cloud-bigquerycontrol-options + */ +using JobServicePolicyOptionList = + OptionList; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_job_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_JOB_OPTIONS_H diff --git a/google/cloud/bigquerycontrol/job/v2/job_rest_connection.cc b/google/cloud/bigquerycontrol/job/v2/job_rest_connection.cc new file mode 100644 index 0000000000000..c4943ce2945e1 --- /dev/null +++ b/google/cloud/bigquerycontrol/job/v2/job_rest_connection.cc @@ -0,0 +1,58 @@ +// Copyright 2024 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/v2/job.proto + +#include "google/cloud/bigquerycontrol/job/v2/job_rest_connection.h" +#include "google/cloud/bigquerycontrol/job/v2/internal/job_option_defaults.h" +#include "google/cloud/bigquerycontrol/job/v2/internal/job_rest_connection_impl.h" +#include "google/cloud/bigquerycontrol/job/v2/internal/job_rest_stub_factory.h" +#include "google/cloud/bigquerycontrol/job/v2/internal/job_tracing_connection.h" +#include "google/cloud/bigquerycontrol/job/v2/job_options.h" +#include "google/cloud/common_options.h" +#include "google/cloud/credentials.h" +#include "google/cloud/internal/rest_background_threads_impl.h" +#include "google/cloud/internal/rest_options.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_job_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr MakeJobServiceConnectionRest( + Options options) { + internal::CheckExpectedOptions< + CommonOptionList, RestOptionList, UnifiedCredentialsOptionList, + rest_internal::TargetApiVersionOption, JobServicePolicyOptionList>( + options, __func__); + options = bigquerycontrol_job_v2_internal::JobServiceDefaultOptions( + std::move(options)); + auto background = std::make_unique< + rest_internal::AutomaticallyCreatedRestBackgroundThreads>(); + auto stub = + bigquerycontrol_job_v2_internal::CreateDefaultJobServiceRestStub(options); + return bigquerycontrol_job_v2_internal::MakeJobServiceTracingConnection( + std::make_shared< + bigquerycontrol_job_v2_internal::JobServiceRestConnectionImpl>( + std::move(background), std::move(stub), std::move(options))); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_job_v2 +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/job/v2/job_rest_connection.h b/google/cloud/bigquerycontrol/job/v2/job_rest_connection.h new file mode 100644 index 0000000000000..76537432a131b --- /dev/null +++ b/google/cloud/bigquerycontrol/job/v2/job_rest_connection.h @@ -0,0 +1,64 @@ +// Copyright 2024 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/v2/job.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_JOB_REST_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_JOB_REST_CONNECTION_H + +#include "google/cloud/bigquerycontrol/job/v2/job_connection.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_job_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * A factory function to construct an object of type `JobServiceConnection` + * that uses REST over HTTP as transport in lieu of gRPC. REST transport should + * only be used for services that do not support gRPC or if the existing network + * configuration precludes using gRPC. + * + * The returned connection object should not be used directly; instead it + * should be passed as an argument to the constructor of JobServiceClient. + * + * The optional @p options argument may be used to configure aspects of the + * returned `JobServiceConnection`. Expected options are any of the types in + * the following option lists: + * + * - `google::cloud::CommonOptionList` + * - `google::cloud::RestOptionList` + * - `google::cloud::UnifiedCredentialsOptionList` + * - `google::cloud::bigquerycontrol_job_v2::JobServicePolicyOptionList` + * + * @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 `JobServiceConnection` created by + * this function. + */ +std::shared_ptr MakeJobServiceConnectionRest( + Options options = {}); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_job_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_JOB_REST_CONNECTION_H diff --git a/google/cloud/bigquerycontrol/job/v2/mocks/mock_job_connection.h b/google/cloud/bigquerycontrol/job/v2/mocks/mock_job_connection.h new file mode 100644 index 0000000000000..a5f167057d698 --- /dev/null +++ b/google/cloud/bigquerycontrol/job/v2/mocks/mock_job_connection.h @@ -0,0 +1,87 @@ +// Copyright 2024 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/v2/job.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_MOCKS_MOCK_JOB_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_MOCKS_MOCK_JOB_CONNECTION_H + +#include "google/cloud/bigquerycontrol/job/v2/job_connection.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_job_v2_mocks { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * A class to mock `JobServiceConnection`. + * + * Application developers may want to test their code with simulated responses, + * including errors, from an object of type `JobServiceClient`. To do so, + * construct an object of type `JobServiceClient` 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]: @cloud_cpp_docs_link{bigquery,bigquery-read-mock} + */ +class MockJobServiceConnection + : public bigquerycontrol_job_v2::JobServiceConnection { + public: + MOCK_METHOD(Options, options, (), (override)); + + MOCK_METHOD(StatusOr, + CancelJob, + (google::cloud::bigquery::v2::CancelJobRequest const& request), + (override)); + + MOCK_METHOD(StatusOr, GetJob, + (google::cloud::bigquery::v2::GetJobRequest const& request), + (override)); + + MOCK_METHOD(StatusOr, InsertJob, + (google::cloud::bigquery::v2::InsertJobRequest const& request), + (override)); + + MOCK_METHOD(Status, DeleteJob, + (google::cloud::bigquery::v2::DeleteJobRequest const& request), + (override)); + + MOCK_METHOD((StreamRange), + ListJobs, (google::cloud::bigquery::v2::ListJobsRequest request), + (override)); + + MOCK_METHOD( + StatusOr, + GetQueryResults, + (google::cloud::bigquery::v2::GetQueryResultsRequest const& request), + (override)); + + MOCK_METHOD(StatusOr, Query, + (google::cloud::bigquery::v2::PostQueryRequest const& request), + (override)); +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_job_v2_mocks +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_JOB_V2_MOCKS_MOCK_JOB_CONNECTION_H diff --git a/google/cloud/bigquerycontrol/job/v2/samples/job_client_samples.cc b/google/cloud/bigquerycontrol/job/v2/samples/job_client_samples.cc new file mode 100644 index 0000000000000..f9fcef1244735 --- /dev/null +++ b/google/cloud/bigquerycontrol/job/v2/samples/job_client_samples.cc @@ -0,0 +1,161 @@ +// Copyright 2024 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/v2/job.proto + +#include "google/cloud/bigquerycontrol/job/v2/job_client.h" +#include "google/cloud/bigquerycontrol/job/v2/job_connection_idempotency_policy.h" +#include "google/cloud/bigquerycontrol/job/v2/job_options.h" +#include "google/cloud/common_options.h" +#include "google/cloud/credentials.h" +#include "google/cloud/internal/getenv.h" +#include "google/cloud/testing_util/example_driver.h" +#include +#include +#include +#include + +// clang-format off +// main-dox-marker: bigquerycontrol_job_v2::JobServiceClient +// clang-format on +namespace { + +void SetClientEndpoint(std::vector const& argv) { + if (!argv.empty()) { + throw google::cloud::testing_util::Usage{"set-client-endpoint"}; + } + //! [set-client-endpoint] + // This configuration is common with Private Google Access: + // https://cloud.google.com/vpc/docs/private-google-access + auto options = google::cloud::Options{}.set( + "private.googleapis.com"); + auto client = google::cloud::bigquerycontrol_job_v2::JobServiceClient( + google::cloud::bigquerycontrol_job_v2::MakeJobServiceConnectionRest( + options)); + //! [set-client-endpoint] +} + +//! [custom-idempotency-policy] +class CustomIdempotencyPolicy : public google::cloud::bigquerycontrol_job_v2:: + JobServiceConnectionIdempotencyPolicy { + public: + ~CustomIdempotencyPolicy() override = default; + std::unique_ptr + clone() const override { + return std::make_unique(*this); + } + // Override inherited functions to define as needed. +}; +//! [custom-idempotency-policy] + +void SetRetryPolicy(std::vector const& argv) { + if (!argv.empty()) { + throw google::cloud::testing_util::Usage{"set-client-retry-policy"}; + } + //! [set-retry-policy] + auto options = google::cloud::Options{} + .set( + CustomIdempotencyPolicy().clone()) + .set( + google::cloud::bigquerycontrol_job_v2:: + JobServiceLimitedErrorCountRetryPolicy(3) + .clone()) + .set( + google::cloud::ExponentialBackoffPolicy( + /*initial_delay=*/std::chrono::milliseconds(200), + /*maximum_delay=*/std::chrono::seconds(45), + /*scaling=*/2.0) + .clone()); + auto connection = + google::cloud::bigquerycontrol_job_v2::MakeJobServiceConnectionRest( + options); + + // c1 and c2 share the same retry policies + auto c1 = google::cloud::bigquerycontrol_job_v2::JobServiceClient(connection); + auto c2 = google::cloud::bigquerycontrol_job_v2::JobServiceClient(connection); + + // You can override any of the policies in a new client. This new client + // will share the policies from c1 (or c2) *except* for the retry policy. + auto c3 = google::cloud::bigquerycontrol_job_v2::JobServiceClient( + connection, + google::cloud::Options{} + .set( + google::cloud::bigquerycontrol_job_v2:: + JobServiceLimitedTimeRetryPolicy(std::chrono::minutes(5)) + .clone())); + + // You can also override the policies in a single call: + // c3.SomeRpc(..., google::cloud::Options{} + // .set( + // google::cloud::bigquerycontrol_job_v2::JobServiceLimitedErrorCountRetryPolicy(10).clone())); + //! [set-retry-policy] +} + +void WithServiceAccount(std::vector const& argv) { + if (argv.size() != 1 || argv[0] == "--help") { + throw google::cloud::testing_util::Usage{"with-service-account "}; + } + //! [with-service-account] + [](std::string const& keyfile) { + auto is = std::ifstream(keyfile); + is.exceptions(std::ios::badbit); // Minimal error handling in examples + auto contents = std::string(std::istreambuf_iterator(is.rdbuf()), {}); + auto options = + google::cloud::Options{}.set( + google::cloud::MakeServiceAccountCredentials(contents)); + return google::cloud::bigquerycontrol_job_v2::JobServiceClient( + google::cloud::bigquerycontrol_job_v2::MakeJobServiceConnectionRest( + options)); + } + //! [with-service-account] + (argv.at(0)); +} + +void AutoRun(std::vector const& argv) { + namespace examples = ::google::cloud::testing_util; + using ::google::cloud::internal::GetEnv; + if (!argv.empty()) throw examples::Usage{"auto"}; + examples::CheckEnvironmentVariablesAreSet( + {"GOOGLE_CLOUD_CPP_TEST_SERVICE_ACCOUNT_KEYFILE"}); + auto const keyfile = + GetEnv("GOOGLE_CLOUD_CPP_TEST_SERVICE_ACCOUNT_KEYFILE").value(); + + std::cout << "\nRunning SetClientEndpoint() example" << std::endl; + SetClientEndpoint({}); + + std::cout << "\nRunning SetRetryPolicy() example" << std::endl; + SetRetryPolicy({}); + + std::cout << "\nRunning WithServiceAccount() example" << std::endl; + WithServiceAccount({keyfile}); +} + +} // namespace + +int main(int argc, char* argv[]) { // NOLINT(bugprone-exception-escape) + google::cloud::testing_util::Example example({ + {"set-client-endpoint", SetClientEndpoint}, + {"set-retry-policy", SetRetryPolicy}, + {"with-service-account", WithServiceAccount}, + {"auto", AutoRun}, + }); + return example.Run(argc, argv); +} diff --git a/google/cloud/bigquerycontrol/model/v2/internal/model_option_defaults.cc b/google/cloud/bigquerycontrol/model/v2/internal/model_option_defaults.cc new file mode 100644 index 0000000000000..9c7f37bacb90f --- /dev/null +++ b/google/cloud/bigquerycontrol/model/v2/internal/model_option_defaults.cc @@ -0,0 +1,69 @@ +// Copyright 2024 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/v2/model.proto + +#include "google/cloud/bigquerycontrol/model/v2/internal/model_option_defaults.h" +#include "google/cloud/bigquerycontrol/model/v2/model_connection.h" +#include "google/cloud/bigquerycontrol/model/v2/model_options.h" +#include "google/cloud/internal/populate_common_options.h" +#include "google/cloud/internal/populate_grpc_options.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_model_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +namespace { +auto constexpr kBackoffScaling = 2.0; +} // namespace + +Options ModelServiceDefaultOptions(Options options) { + options = internal::PopulateCommonOptions( + std::move(options), "GOOGLE_CLOUD_CPP_MODEL_SERVICE_ENDPOINT", "", + "GOOGLE_CLOUD_CPP_MODEL_SERVICE_AUTHORITY", "bigquery.googleapis.com"); + options = internal::PopulateGrpcOptions(std::move(options)); + if (!options.has()) { + options.set( + bigquerycontrol_model_v2::ModelServiceLimitedTimeRetryPolicy( + std::chrono::minutes(30)) + .clone()); + } + if (!options + .has()) { + options.set( + ExponentialBackoffPolicy( + std::chrono::seconds(0), std::chrono::seconds(1), + std::chrono::minutes(5), kBackoffScaling, kBackoffScaling) + .clone()); + } + if (!options.has()) { + options.set( + bigquerycontrol_model_v2:: + MakeDefaultModelServiceConnectionIdempotencyPolicy()); + } + + return options; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_model_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/model/v2/internal/model_option_defaults.h b/google/cloud/bigquerycontrol/model/v2/internal/model_option_defaults.h new file mode 100644 index 0000000000000..2e8446f3a3370 --- /dev/null +++ b/google/cloud/bigquerycontrol/model/v2/internal/model_option_defaults.h @@ -0,0 +1,37 @@ +// Copyright 2024 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/v2/model.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_INTERNAL_MODEL_OPTION_DEFAULTS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_INTERNAL_MODEL_OPTION_DEFAULTS_H + +#include "google/cloud/options.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace bigquerycontrol_model_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +Options ModelServiceDefaultOptions(Options options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_model_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_INTERNAL_MODEL_OPTION_DEFAULTS_H diff --git a/google/cloud/bigquerycontrol/model/v2/internal/model_rest_connection_impl.cc b/google/cloud/bigquerycontrol/model/v2/internal/model_rest_connection_impl.cc new file mode 100644 index 0000000000000..acf616e191bbd --- /dev/null +++ b/google/cloud/bigquerycontrol/model/v2/internal/model_rest_connection_impl.cc @@ -0,0 +1,124 @@ +// Copyright 2024 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/v2/model.proto + +#include "google/cloud/bigquerycontrol/model/v2/internal/model_rest_connection_impl.h" +#include "google/cloud/bigquerycontrol/model/v2/internal/model_rest_stub_factory.h" +#include "google/cloud/common_options.h" +#include "google/cloud/credentials.h" +#include "google/cloud/internal/pagination_range.h" +#include "google/cloud/internal/rest_retry_loop.h" +#include "google/cloud/rest_options.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_model_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ModelServiceRestConnectionImpl::ModelServiceRestConnectionImpl( + std::unique_ptr background, + std::shared_ptr + stub, + Options options) + : background_(std::move(background)), + stub_(std::move(stub)), + options_(internal::MergeOptions(std::move(options), + ModelServiceConnection::options())) {} + +StatusOr +ModelServiceRestConnectionImpl::GetModel( + google::cloud::bigquery::v2::GetModelRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::rest_internal::RestRetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->GetModel(request), + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::GetModelRequest const& request) { + return stub_->GetModel(rest_context, options, request); + }, + *current, request, __func__); +} + +StreamRange +ModelServiceRestConnectionImpl::ListModels( + google::cloud::bigquery::v2::ListModelsRequest request) { + request.clear_page_token(); + auto current = google::cloud::internal::SaveCurrentOptions(); + auto idempotency = idempotency_policy(*current)->ListModels(request); + char const* function_name = __func__; + return google::cloud::internal::MakePaginationRange< + StreamRange>( + current, std::move(request), + [idempotency, function_name, stub = stub_, + retry = + std::shared_ptr( + retry_policy(*current)), + backoff = std::shared_ptr(backoff_policy(*current))]( + Options const& options, + google::cloud::bigquery::v2::ListModelsRequest const& r) { + return google::cloud::rest_internal::RestRetryLoop( + retry->clone(), backoff->clone(), idempotency, + [stub]( + rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListModelsRequest const& request) { + return stub->ListModels(rest_context, options, request); + }, + options, r, function_name); + }, + [](google::cloud::bigquery::v2::ListModelsResponse r) { + std::vector result( + r.models().size()); + auto& messages = *r.mutable_models(); + std::move(messages.begin(), messages.end(), result.begin()); + return result; + }); +} + +StatusOr +ModelServiceRestConnectionImpl::PatchModel( + google::cloud::bigquery::v2::PatchModelRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::rest_internal::RestRetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->PatchModel(request), + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::PatchModelRequest const& request) { + return stub_->PatchModel(rest_context, options, request); + }, + *current, request, __func__); +} + +Status ModelServiceRestConnectionImpl::DeleteModel( + google::cloud::bigquery::v2::DeleteModelRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::rest_internal::RestRetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->DeleteModel(request), + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::DeleteModelRequest const& request) { + return stub_->DeleteModel(rest_context, options, request); + }, + *current, request, __func__); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_model_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/model/v2/internal/model_rest_connection_impl.h b/google/cloud/bigquerycontrol/model/v2/internal/model_rest_connection_impl.h new file mode 100644 index 0000000000000..bb7fa26b6d87e --- /dev/null +++ b/google/cloud/bigquerycontrol/model/v2/internal/model_rest_connection_impl.h @@ -0,0 +1,99 @@ +// Copyright 2024 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/v2/model.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_INTERNAL_MODEL_REST_CONNECTION_IMPL_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_INTERNAL_MODEL_REST_CONNECTION_IMPL_H + +#include "google/cloud/bigquerycontrol/model/v2/internal/model_rest_stub.h" +#include "google/cloud/bigquerycontrol/model/v2/internal/model_retry_traits.h" +#include "google/cloud/bigquerycontrol/model/v2/model_connection.h" +#include "google/cloud/bigquerycontrol/model/v2/model_connection_idempotency_policy.h" +#include "google/cloud/bigquerycontrol/model/v2/model_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 bigquerycontrol_model_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ModelServiceRestConnectionImpl + : public bigquerycontrol_model_v2::ModelServiceConnection { + public: + ~ModelServiceRestConnectionImpl() override = default; + + ModelServiceRestConnectionImpl( + std::unique_ptr background, + std::shared_ptr + stub, + Options options); + + Options options() override { return options_; } + + StatusOr GetModel( + google::cloud::bigquery::v2::GetModelRequest const& request) override; + + StreamRange ListModels( + google::cloud::bigquery::v2::ListModelsRequest request) override; + + StatusOr PatchModel( + google::cloud::bigquery::v2::PatchModelRequest const& request) override; + + Status DeleteModel( + google::cloud::bigquery::v2::DeleteModelRequest const& request) override; + + private: + static std::unique_ptr + retry_policy(Options const& options) { + return options + .get() + ->clone(); + } + + static std::unique_ptr backoff_policy(Options const& options) { + return options + .get() + ->clone(); + } + + static std::unique_ptr< + bigquerycontrol_model_v2::ModelServiceConnectionIdempotencyPolicy> + idempotency_policy(Options const& options) { + return options + .get() + ->clone(); + } + + std::unique_ptr background_; + std::shared_ptr + stub_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_model_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_INTERNAL_MODEL_REST_CONNECTION_IMPL_H diff --git a/google/cloud/bigquerycontrol/model/v2/internal/model_rest_logging_decorator.cc b/google/cloud/bigquerycontrol/model/v2/internal/model_rest_logging_decorator.cc new file mode 100644 index 0000000000000..906f1a6d025ef --- /dev/null +++ b/google/cloud/bigquerycontrol/model/v2/internal/model_rest_logging_decorator.cc @@ -0,0 +1,86 @@ +// Copyright 2024 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/v2/model.proto + +#include "google/cloud/bigquerycontrol/model/v2/internal/model_rest_logging_decorator.h" +#include "google/cloud/internal/log_wrapper.h" +#include "google/cloud/status_or.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_model_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ModelServiceRestLogging::ModelServiceRestLogging( + 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 ModelServiceRestLogging::GetModel( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::GetModelRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::GetModelRequest const& request) { + return child_->GetModel(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +StatusOr +ModelServiceRestLogging::ListModels( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::ListModelsRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::ListModelsRequest const& request) { + return child_->ListModels(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +StatusOr +ModelServiceRestLogging::PatchModel( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::PatchModelRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::PatchModelRequest const& request) { + return child_->PatchModel(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +Status ModelServiceRestLogging::DeleteModel( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::DeleteModelRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::DeleteModelRequest const& request) { + return child_->DeleteModel(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_model_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/model/v2/internal/model_rest_logging_decorator.h b/google/cloud/bigquerycontrol/model/v2/internal/model_rest_logging_decorator.h new file mode 100644 index 0000000000000..22caa867cd9af --- /dev/null +++ b/google/cloud/bigquerycontrol/model/v2/internal/model_rest_logging_decorator.h @@ -0,0 +1,75 @@ +// Copyright 2024 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/v2/model.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_INTERNAL_MODEL_REST_LOGGING_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_INTERNAL_MODEL_REST_LOGGING_DECORATOR_H + +#include "google/cloud/bigquerycontrol/model/v2/internal/model_rest_stub.h" +#include "google/cloud/future.h" +#include "google/cloud/internal/rest_context.h" +#include "google/cloud/tracing_options.h" +#include "google/cloud/version.h" +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_model_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ModelServiceRestLogging : public ModelServiceRestStub { + public: + ~ModelServiceRestLogging() override = default; + ModelServiceRestLogging(std::shared_ptr child, + TracingOptions tracing_options, + std::set components); + + StatusOr GetModel( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetModelRequest const& request) override; + + StatusOr ListModels( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListModelsRequest const& request) override; + + StatusOr PatchModel( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::PatchModelRequest const& request) override; + + Status DeleteModel( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::DeleteModelRequest const& request) override; + + private: + std::shared_ptr child_; + TracingOptions tracing_options_; + std::set components_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_model_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_INTERNAL_MODEL_REST_LOGGING_DECORATOR_H diff --git a/google/cloud/bigquerycontrol/model/v2/internal/model_rest_metadata_decorator.cc b/google/cloud/bigquerycontrol/model/v2/internal/model_rest_metadata_decorator.cc new file mode 100644 index 0000000000000..40786e99a1a27 --- /dev/null +++ b/google/cloud/bigquerycontrol/model/v2/internal/model_rest_metadata_decorator.cc @@ -0,0 +1,81 @@ +// Copyright 2024 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/v2/model.proto + +#include "google/cloud/bigquerycontrol/model/v2/internal/model_rest_metadata_decorator.h" +#include "google/cloud/internal/absl_str_cat_quiet.h" +#include "google/cloud/internal/api_client_header.h" +#include "google/cloud/internal/rest_set_metadata.h" +#include "google/cloud/status_or.h" +#include "absl/strings/str_format.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_model_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ModelServiceRestMetadata::ModelServiceRestMetadata( + std::shared_ptr child, std::string api_client_header) + : child_(std::move(child)), + api_client_header_( + api_client_header.empty() + ? google::cloud::internal::GeneratedLibClientHeader() + : std::move(api_client_header)) {} + +StatusOr ModelServiceRestMetadata::GetModel( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::GetModelRequest const& request) { + SetMetadata(rest_context, options); + return child_->GetModel(rest_context, options, request); +} + +StatusOr +ModelServiceRestMetadata::ListModels( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::ListModelsRequest const& request) { + SetMetadata(rest_context, options); + return child_->ListModels(rest_context, options, request); +} + +StatusOr +ModelServiceRestMetadata::PatchModel( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::PatchModelRequest const& request) { + SetMetadata(rest_context, options); + return child_->PatchModel(rest_context, options, request); +} + +Status ModelServiceRestMetadata::DeleteModel( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::DeleteModelRequest const& request) { + SetMetadata(rest_context, options); + return child_->DeleteModel(rest_context, options, request); +} + +void ModelServiceRestMetadata::SetMetadata( + rest_internal::RestContext& rest_context, Options const& options, + std::vector const& params) { + google::cloud::rest_internal::SetMetadata(rest_context, options, params, + api_client_header_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_model_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/model/v2/internal/model_rest_metadata_decorator.h b/google/cloud/bigquerycontrol/model/v2/internal/model_rest_metadata_decorator.h new file mode 100644 index 0000000000000..59593bdafad50 --- /dev/null +++ b/google/cloud/bigquerycontrol/model/v2/internal/model_rest_metadata_decorator.h @@ -0,0 +1,75 @@ +// Copyright 2024 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/v2/model.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_INTERNAL_MODEL_REST_METADATA_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_INTERNAL_MODEL_REST_METADATA_DECORATOR_H + +#include "google/cloud/bigquerycontrol/model/v2/internal/model_rest_stub.h" +#include "google/cloud/future.h" +#include "google/cloud/rest_options.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_model_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ModelServiceRestMetadata : public ModelServiceRestStub { + public: + ~ModelServiceRestMetadata() override = default; + explicit ModelServiceRestMetadata(std::shared_ptr child, + std::string api_client_header = ""); + + StatusOr GetModel( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetModelRequest const& request) override; + + StatusOr ListModels( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListModelsRequest const& request) override; + + StatusOr PatchModel( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::PatchModelRequest const& request) override; + + Status DeleteModel( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::DeleteModelRequest const& request) override; + + private: + void SetMetadata(rest_internal::RestContext& rest_context, + Options const& options, + std::vector const& params = {}); + + std::shared_ptr child_; + std::string api_client_header_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_model_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_INTERNAL_MODEL_REST_METADATA_DECORATOR_H diff --git a/google/cloud/bigquerycontrol/model/v2/internal/model_rest_stub.cc b/google/cloud/bigquerycontrol/model/v2/internal/model_rest_stub.cc new file mode 100644 index 0000000000000..298bc7e4be393 --- /dev/null +++ b/google/cloud/bigquerycontrol/model/v2/internal/model_rest_stub.cc @@ -0,0 +1,101 @@ +// Copyright 2024 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/v2/model.proto + +#include "google/cloud/bigquerycontrol/model/v2/internal/model_rest_stub.h" +#include "google/cloud/common_options.h" +#include "google/cloud/internal/absl_str_cat_quiet.h" +#include "google/cloud/internal/rest_stub_helpers.h" +#include "google/cloud/status_or.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_model_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +DefaultModelServiceRestStub::DefaultModelServiceRestStub(Options options) + : service_(rest_internal::MakePooledRestClient( + options.get(), options)), + options_(std::move(options)) {} + +DefaultModelServiceRestStub::DefaultModelServiceRestStub( + std::shared_ptr service, Options options) + : service_(std::move(service)), options_(std::move(options)) {} + +StatusOr +DefaultModelServiceRestStub::GetModel( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetModelRequest const& request) { + return rest_internal::Get( + *service_, rest_context, request, false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "datasets", "/", + request.dataset_id(), "/", "models", "/", + request.model_id())); +} + +StatusOr +DefaultModelServiceRestStub::ListModels( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListModelsRequest const& request) { + return rest_internal::Get( + *service_, rest_context, request, false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "datasets", "/", + request.dataset_id(), "/", "models"), + rest_internal::TrimEmptyQueryParameters( + {std::make_pair("page_token", request.page_token())})); +} + +StatusOr +DefaultModelServiceRestStub::PatchModel( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::PatchModelRequest const& request) { + return rest_internal::Patch( + *service_, rest_context, request.model(), false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "datasets", "/", + request.dataset_id(), "/", "models", "/", + request.model_id())); +} + +Status DefaultModelServiceRestStub::DeleteModel( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::DeleteModelRequest const& request) { + return rest_internal::Delete( + *service_, rest_context, request, false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "datasets", "/", + request.dataset_id(), "/", "models", "/", + request.model_id())); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_model_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/model/v2/internal/model_rest_stub.h b/google/cloud/bigquerycontrol/model/v2/internal/model_rest_stub.h new file mode 100644 index 0000000000000..940da0470c6fa --- /dev/null +++ b/google/cloud/bigquerycontrol/model/v2/internal/model_rest_stub.h @@ -0,0 +1,98 @@ +// Copyright 2024 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/v2/model.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_INTERNAL_MODEL_REST_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_INTERNAL_MODEL_REST_STUB_H + +#include "google/cloud/completion_queue.h" +#include "google/cloud/internal/rest_client.h" +#include "google/cloud/internal/rest_context.h" +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_model_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ModelServiceRestStub { + public: + virtual ~ModelServiceRestStub() = default; + + virtual StatusOr GetModel( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetModelRequest const& request) = 0; + + virtual StatusOr ListModels( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListModelsRequest const& request) = 0; + + virtual StatusOr PatchModel( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::PatchModelRequest const& request) = 0; + + virtual Status DeleteModel( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::DeleteModelRequest const& request) = 0; +}; + +class DefaultModelServiceRestStub : public ModelServiceRestStub { + public: + ~DefaultModelServiceRestStub() override = default; + + explicit DefaultModelServiceRestStub(Options options); + DefaultModelServiceRestStub( + std::shared_ptr service, Options options); + + StatusOr GetModel( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetModelRequest const& request) override; + + StatusOr ListModels( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListModelsRequest const& request) override; + + StatusOr PatchModel( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::PatchModelRequest const& request) override; + + Status DeleteModel( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::DeleteModelRequest const& request) override; + + private: + std::shared_ptr service_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_model_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_INTERNAL_MODEL_REST_STUB_H diff --git a/google/cloud/bigquerycontrol/model/v2/internal/model_rest_stub_factory.cc b/google/cloud/bigquerycontrol/model/v2/internal/model_rest_stub_factory.cc new file mode 100644 index 0000000000000..fe8dd3fe52a00 --- /dev/null +++ b/google/cloud/bigquerycontrol/model/v2/internal/model_rest_stub_factory.cc @@ -0,0 +1,56 @@ +// Copyright 2024 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/v2/model.proto + +#include "google/cloud/bigquerycontrol/model/v2/internal/model_rest_stub_factory.h" +#include "google/cloud/bigquerycontrol/model/v2/internal/model_rest_logging_decorator.h" +#include "google/cloud/bigquerycontrol/model/v2/internal/model_rest_metadata_decorator.h" +#include "google/cloud/bigquerycontrol/model/v2/internal/model_rest_stub.h" +#include "google/cloud/common_options.h" +#include "google/cloud/internal/algorithm.h" +#include "google/cloud/internal/populate_rest_options.h" +#include "google/cloud/log.h" +#include "google/cloud/options.h" +#include "google/cloud/rest_options.h" +#include "absl/strings/match.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_model_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultModelServiceRestStub( + Options const& options) { + auto opts = internal::PopulateRestOptions(options); + std::shared_ptr stub = + std::make_shared(std::move(opts)); + stub = std::make_shared(std::move(stub)); + if (internal::Contains(options.get(), "rpc")) { + GCP_LOG(INFO) << "Enabled logging for REST rpc calls"; + stub = std::make_shared( + std::move(stub), options.get(), + options.get()); + } + return stub; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_model_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/model/v2/internal/model_rest_stub_factory.h b/google/cloud/bigquerycontrol/model/v2/internal/model_rest_stub_factory.h new file mode 100644 index 0000000000000..61caa7b59c781 --- /dev/null +++ b/google/cloud/bigquerycontrol/model/v2/internal/model_rest_stub_factory.h @@ -0,0 +1,40 @@ +// Copyright 2024 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/v2/model.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_INTERNAL_MODEL_REST_STUB_FACTORY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_INTERNAL_MODEL_REST_STUB_FACTORY_H + +#include "google/cloud/bigquerycontrol/model/v2/internal/model_rest_stub.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_model_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultModelServiceRestStub( + Options const& options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_model_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_INTERNAL_MODEL_REST_STUB_FACTORY_H diff --git a/google/cloud/bigquerycontrol/model/v2/internal/model_retry_traits.h b/google/cloud/bigquerycontrol/model/v2/internal/model_retry_traits.h new file mode 100644 index 0000000000000..daf7d8c3c413c --- /dev/null +++ b/google/cloud/bigquerycontrol/model/v2/internal/model_retry_traits.h @@ -0,0 +1,43 @@ +// Copyright 2024 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/v2/model.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_INTERNAL_MODEL_RETRY_TRAITS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_INTERNAL_MODEL_RETRY_TRAITS_H + +#include "google/cloud/status.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace bigquerycontrol_model_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// Define the gRPC status code semantics for retrying requests. +struct ModelServiceRetryTraits { + static bool IsPermanentFailure(google::cloud::Status const& status) { + return status.code() != StatusCode::kOk && + status.code() != StatusCode::kUnavailable; + } +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_model_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_INTERNAL_MODEL_RETRY_TRAITS_H diff --git a/google/cloud/bigquerycontrol/model/v2/internal/model_sources.cc b/google/cloud/bigquerycontrol/model/v2/internal/model_sources.cc new file mode 100644 index 0000000000000..c3c86b2148f07 --- /dev/null +++ b/google/cloud/bigquerycontrol/model/v2/internal/model_sources.cc @@ -0,0 +1,31 @@ +// Copyright 2024 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/v2/model.proto + +// NOLINTBEGIN(bugprone-suspicious-include) +#include "google/cloud/bigquerycontrol/model/v2/internal/model_option_defaults.cc" +#include "google/cloud/bigquerycontrol/model/v2/internal/model_rest_connection_impl.cc" +#include "google/cloud/bigquerycontrol/model/v2/internal/model_rest_logging_decorator.cc" +#include "google/cloud/bigquerycontrol/model/v2/internal/model_rest_metadata_decorator.cc" +#include "google/cloud/bigquerycontrol/model/v2/internal/model_rest_stub.cc" +#include "google/cloud/bigquerycontrol/model/v2/internal/model_rest_stub_factory.cc" +#include "google/cloud/bigquerycontrol/model/v2/internal/model_tracing_connection.cc" +#include "google/cloud/bigquerycontrol/model/v2/model_client.cc" +#include "google/cloud/bigquerycontrol/model/v2/model_connection.cc" +#include "google/cloud/bigquerycontrol/model/v2/model_connection_idempotency_policy.cc" +#include "google/cloud/bigquerycontrol/model/v2/model_rest_connection.cc" +// NOLINTEND(bugprone-suspicious-include) diff --git a/google/cloud/bigquerycontrol/model/v2/internal/model_tracing_connection.cc b/google/cloud/bigquerycontrol/model/v2/internal/model_tracing_connection.cc new file mode 100644 index 0000000000000..51eb85d640bf1 --- /dev/null +++ b/google/cloud/bigquerycontrol/model/v2/internal/model_tracing_connection.cc @@ -0,0 +1,89 @@ +// Copyright 2024 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/v2/model.proto + +#include "google/cloud/bigquerycontrol/model/v2/internal/model_tracing_connection.h" +#include "google/cloud/internal/opentelemetry.h" +#include "google/cloud/internal/traced_stream_range.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_model_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +ModelServiceTracingConnection::ModelServiceTracingConnection( + std::shared_ptr child) + : child_(std::move(child)) {} + +StatusOr +ModelServiceTracingConnection::GetModel( + google::cloud::bigquery::v2::GetModelRequest const& request) { + auto span = internal::MakeSpan( + "bigquerycontrol_model_v2::ModelServiceConnection::GetModel"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->GetModel(request)); +} + +StreamRange +ModelServiceTracingConnection::ListModels( + google::cloud::bigquery::v2::ListModelsRequest request) { + auto span = internal::MakeSpan( + "bigquerycontrol_model_v2::ModelServiceConnection::ListModels"); + internal::OTelScope scope(span); + auto sr = child_->ListModels(std::move(request)); + return internal::MakeTracedStreamRange( + std::move(span), std::move(sr)); +} + +StatusOr +ModelServiceTracingConnection::PatchModel( + google::cloud::bigquery::v2::PatchModelRequest const& request) { + auto span = internal::MakeSpan( + "bigquerycontrol_model_v2::ModelServiceConnection::PatchModel"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->PatchModel(request)); +} + +Status ModelServiceTracingConnection::DeleteModel( + google::cloud::bigquery::v2::DeleteModelRequest const& request) { + auto span = internal::MakeSpan( + "bigquerycontrol_model_v2::ModelServiceConnection::DeleteModel"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->DeleteModel(request)); +} + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +std::shared_ptr +MakeModelServiceTracingConnection( + std::shared_ptr conn) { +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + if (internal::TracingEnabled(conn->options())) { + conn = std::make_shared(std::move(conn)); + } +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + return conn; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_model_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/model/v2/internal/model_tracing_connection.h b/google/cloud/bigquerycontrol/model/v2/internal/model_tracing_connection.h new file mode 100644 index 0000000000000..a0fe48a81bb35 --- /dev/null +++ b/google/cloud/bigquerycontrol/model/v2/internal/model_tracing_connection.h @@ -0,0 +1,76 @@ +// Copyright 2024 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/v2/model.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_INTERNAL_MODEL_TRACING_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_INTERNAL_MODEL_TRACING_CONNECTION_H + +#include "google/cloud/bigquerycontrol/model/v2/model_connection.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_model_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +class ModelServiceTracingConnection + : public bigquerycontrol_model_v2::ModelServiceConnection { + public: + ~ModelServiceTracingConnection() override = default; + + explicit ModelServiceTracingConnection( + std::shared_ptr child); + + Options options() override { return child_->options(); } + + StatusOr GetModel( + google::cloud::bigquery::v2::GetModelRequest const& request) override; + + StreamRange ListModels( + google::cloud::bigquery::v2::ListModelsRequest request) override; + + StatusOr PatchModel( + google::cloud::bigquery::v2::PatchModelRequest const& request) override; + + Status DeleteModel( + google::cloud::bigquery::v2::DeleteModelRequest const& request) override; + + private: + std::shared_ptr child_; +}; + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +/** + * Conditionally applies the tracing decorator to the given connection. + * + * The connection is only decorated if tracing is enabled (as determined by the + * connection's options). + */ +std::shared_ptr +MakeModelServiceTracingConnection( + std::shared_ptr conn); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_model_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_INTERNAL_MODEL_TRACING_CONNECTION_H diff --git a/google/cloud/bigquerycontrol/model/v2/mocks/mock_model_connection.h b/google/cloud/bigquerycontrol/model/v2/mocks/mock_model_connection.h new file mode 100644 index 0000000000000..2cda4cb3f0039 --- /dev/null +++ b/google/cloud/bigquerycontrol/model/v2/mocks/mock_model_connection.h @@ -0,0 +1,72 @@ +// Copyright 2024 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/v2/model.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_MOCKS_MOCK_MODEL_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_MOCKS_MOCK_MODEL_CONNECTION_H + +#include "google/cloud/bigquerycontrol/model/v2/model_connection.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_model_v2_mocks { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * A class to mock `ModelServiceConnection`. + * + * Application developers may want to test their code with simulated responses, + * including errors, from an object of type `ModelServiceClient`. To do so, + * construct an object of type `ModelServiceClient` 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]: @cloud_cpp_docs_link{bigquery,bigquery-read-mock} + */ +class MockModelServiceConnection + : public bigquerycontrol_model_v2::ModelServiceConnection { + public: + MOCK_METHOD(Options, options, (), (override)); + + MOCK_METHOD(StatusOr, GetModel, + (google::cloud::bigquery::v2::GetModelRequest const& request), + (override)); + + MOCK_METHOD((StreamRange), ListModels, + (google::cloud::bigquery::v2::ListModelsRequest request), + (override)); + + MOCK_METHOD(StatusOr, PatchModel, + (google::cloud::bigquery::v2::PatchModelRequest const& request), + (override)); + + MOCK_METHOD(Status, DeleteModel, + (google::cloud::bigquery::v2::DeleteModelRequest const& request), + (override)); +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_model_v2_mocks +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_MOCKS_MOCK_MODEL_CONNECTION_H diff --git a/google/cloud/bigquerycontrol/model/v2/model_client.cc b/google/cloud/bigquerycontrol/model/v2/model_client.cc new file mode 100644 index 0000000000000..75f3b5be7f56f --- /dev/null +++ b/google/cloud/bigquerycontrol/model/v2/model_client.cc @@ -0,0 +1,111 @@ +// Copyright 2024 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/v2/model.proto + +#include "google/cloud/bigquerycontrol/model/v2/model_client.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_model_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ModelServiceClient::ModelServiceClient( + std::shared_ptr connection, Options opts) + : connection_(std::move(connection)), + options_( + internal::MergeOptions(std::move(opts), connection_->options())) {} +ModelServiceClient::~ModelServiceClient() = default; + +StatusOr ModelServiceClient::GetModel( + std::string const& project_id, std::string const& dataset_id, + std::string const& model_id, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::bigquery::v2::GetModelRequest request; + request.set_project_id(project_id); + request.set_dataset_id(dataset_id); + request.set_model_id(model_id); + return connection_->GetModel(request); +} + +StatusOr ModelServiceClient::GetModel( + google::cloud::bigquery::v2::GetModelRequest const& request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->GetModel(request); +} + +StreamRange ModelServiceClient::ListModels( + std::string const& project_id, std::string const& dataset_id, + google::protobuf::UInt32Value const& max_results, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::bigquery::v2::ListModelsRequest request; + request.set_project_id(project_id); + request.set_dataset_id(dataset_id); + *request.mutable_max_results() = max_results; + return connection_->ListModels(request); +} + +StreamRange ModelServiceClient::ListModels( + google::cloud::bigquery::v2::ListModelsRequest request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->ListModels(std::move(request)); +} + +StatusOr ModelServiceClient::PatchModel( + std::string const& project_id, std::string const& dataset_id, + std::string const& model_id, + google::cloud::bigquery::v2::Model const& model, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::bigquery::v2::PatchModelRequest request; + request.set_project_id(project_id); + request.set_dataset_id(dataset_id); + request.set_model_id(model_id); + *request.mutable_model() = model; + return connection_->PatchModel(request); +} + +StatusOr ModelServiceClient::PatchModel( + google::cloud::bigquery::v2::PatchModelRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->PatchModel(request); +} + +Status ModelServiceClient::DeleteModel(std::string const& project_id, + std::string const& dataset_id, + std::string const& model_id, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + google::cloud::bigquery::v2::DeleteModelRequest request; + request.set_project_id(project_id); + request.set_dataset_id(dataset_id); + request.set_model_id(model_id); + return connection_->DeleteModel(request); +} + +Status ModelServiceClient::DeleteModel( + google::cloud::bigquery::v2::DeleteModelRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->DeleteModel(request); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_model_v2 +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/model/v2/model_client.h b/google/cloud/bigquerycontrol/model/v2/model_client.h new file mode 100644 index 0000000000000..07564509ad7f2 --- /dev/null +++ b/google/cloud/bigquerycontrol/model/v2/model_client.h @@ -0,0 +1,359 @@ +// Copyright 2024 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/v2/model.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_MODEL_CLIENT_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_MODEL_CLIENT_H + +#include "google/cloud/bigquerycontrol/model/v2/model_rest_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 +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_model_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// +/// This is an experimental RPC service definition for the BigQuery +/// Model Service. +/// +/// It should not be relied on for production use cases at this time. +/// +/// @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 ModelServiceClient { + public: + explicit ModelServiceClient( + std::shared_ptr connection, Options opts = {}); + ~ModelServiceClient(); + + ///@{ + /// @name Copy and move support + ModelServiceClient(ModelServiceClient const&) = default; + ModelServiceClient& operator=(ModelServiceClient const&) = default; + ModelServiceClient(ModelServiceClient&&) = default; + ModelServiceClient& operator=(ModelServiceClient&&) = default; + ///@} + + ///@{ + /// @name Equality + friend bool operator==(ModelServiceClient const& a, + ModelServiceClient const& b) { + return a.connection_ == b.connection_; + } + friend bool operator!=(ModelServiceClient const& a, + ModelServiceClient const& b) { + return !(a == b); + } + ///@} + + // clang-format off + /// + /// Gets the specified model resource by model ID. + /// + /// @param project_id Required. Project ID of the requested model. + /// @param dataset_id Required. Dataset ID of the requested model. + /// @param model_id Required. Model ID of the requested model. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return the result of the RPC. The response message type + /// ([google.cloud.bigquery.v2.Model]) + /// is mapped to a C++ class using the [Protobuf mapping rules]. + /// If the request fails, the [`StatusOr`] contains the error details. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.GetModelRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/model.proto#L1974} + /// [google.cloud.bigquery.v2.Model]: @googleapis_reference_link{google/cloud/bigquery/v2/model.proto#L152} + /// + // clang-format on + StatusOr GetModel( + std::string const& project_id, std::string const& dataset_id, + std::string const& model_id, Options opts = {}); + + // clang-format off + /// + /// Gets the specified model resource by model ID. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.GetModelRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return the result of the RPC. The response message type + /// ([google.cloud.bigquery.v2.Model]) + /// is mapped to a C++ class using the [Protobuf mapping rules]. + /// If the request fails, the [`StatusOr`] contains the error details. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.GetModelRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/model.proto#L1974} + /// [google.cloud.bigquery.v2.Model]: @googleapis_reference_link{google/cloud/bigquery/v2/model.proto#L152} + /// + // clang-format on + StatusOr GetModel( + google::cloud::bigquery::v2::GetModelRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Lists all models in the specified dataset. Requires the READER dataset + /// role. After retrieving the list of models, you can get information about a + /// particular model by calling the models.get method. + /// + /// @param project_id Required. Project ID of the models to list. + /// @param dataset_id Required. Dataset ID of the models to list. + /// @param max_results The maximum number of results to return in a single response page. + /// Leverage the page tokens to iterate through the entire collection. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return a [StreamRange](@ref google::cloud::StreamRange) + /// to iterate of the results. See the documentation of this type for + /// details. In brief, this class has `begin()` and `end()` member + /// functions returning a iterator class meeting the + /// [input iterator requirements]. The value type for this iterator is a + /// [`StatusOr`] as the iteration may fail even after some values are + /// retrieved successfully, for example, if there is a network disconnect. + /// An empty set of results does not indicate an error, it indicates + /// that there are no resources meeting the request criteria. + /// On a successful iteration the `StatusOr` contains elements of type + /// [google.cloud.bigquery.v2.Model], or rather, + /// the C++ class generated by Protobuf from that type. Please consult the + /// Protobuf documentation for details on the [Protobuf mapping rules]. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.ListModelsRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/model.proto#L2014} + /// [google.cloud.bigquery.v2.Model]: @googleapis_reference_link{google/cloud/bigquery/v2/model.proto#L152} + /// + // clang-format on + StreamRange ListModels( + std::string const& project_id, std::string const& dataset_id, + google::protobuf::UInt32Value const& max_results, Options opts = {}); + + // clang-format off + /// + /// Lists all models in the specified dataset. Requires the READER dataset + /// role. After retrieving the list of models, you can get information about a + /// particular model by calling the models.get method. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.ListModelsRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return a [StreamRange](@ref google::cloud::StreamRange) + /// to iterate of the results. See the documentation of this type for + /// details. In brief, this class has `begin()` and `end()` member + /// functions returning a iterator class meeting the + /// [input iterator requirements]. The value type for this iterator is a + /// [`StatusOr`] as the iteration may fail even after some values are + /// retrieved successfully, for example, if there is a network disconnect. + /// An empty set of results does not indicate an error, it indicates + /// that there are no resources meeting the request criteria. + /// On a successful iteration the `StatusOr` contains elements of type + /// [google.cloud.bigquery.v2.Model], or rather, + /// the C++ class generated by Protobuf from that type. Please consult the + /// Protobuf documentation for details on the [Protobuf mapping rules]. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.ListModelsRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/model.proto#L2014} + /// [google.cloud.bigquery.v2.Model]: @googleapis_reference_link{google/cloud/bigquery/v2/model.proto#L152} + /// + // clang-format on + StreamRange ListModels( + google::cloud::bigquery::v2::ListModelsRequest request, + Options opts = {}); + + // clang-format off + /// + /// Patch specific fields in the specified model. + /// + /// @param project_id Required. Project ID of the model to patch. + /// @param dataset_id Required. Dataset ID of the model to patch. + /// @param model_id Required. Model ID of the model to patch. + /// @param model Required. Patched model. + /// Follows RFC5789 patch semantics. Missing fields are not updated. + /// To clear a field, explicitly set to default value. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return the result of the RPC. The response message type + /// ([google.cloud.bigquery.v2.Model]) + /// is mapped to a C++ class using the [Protobuf mapping rules]. + /// If the request fails, the [`StatusOr`] contains the error details. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.Model]: @googleapis_reference_link{google/cloud/bigquery/v2/model.proto#L152} + /// [google.cloud.bigquery.v2.PatchModelRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/model.proto#L1985} + /// + // clang-format on + StatusOr PatchModel( + std::string const& project_id, std::string const& dataset_id, + std::string const& model_id, + google::cloud::bigquery::v2::Model const& model, Options opts = {}); + + // clang-format off + /// + /// Patch specific fields in the specified model. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.PatchModelRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return the result of the RPC. The response message type + /// ([google.cloud.bigquery.v2.Model]) + /// is mapped to a C++ class using the [Protobuf mapping rules]. + /// If the request fails, the [`StatusOr`] contains the error details. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.Model]: @googleapis_reference_link{google/cloud/bigquery/v2/model.proto#L152} + /// [google.cloud.bigquery.v2.PatchModelRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/model.proto#L1985} + /// + // clang-format on + StatusOr PatchModel( + google::cloud::bigquery::v2::PatchModelRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Deletes the model specified by modelId from the dataset. + /// + /// @param project_id Required. Project ID of the model to delete. + /// @param dataset_id Required. Dataset ID of the model to delete. + /// @param model_id Required. Model ID of the model to delete. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return a [`Status`] object. If the request failed, the + /// status contains the details of the failure. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.DeleteModelRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/model.proto#L2002} + /// + // clang-format on + Status DeleteModel(std::string const& project_id, + std::string const& dataset_id, std::string const& model_id, + Options opts = {}); + + // clang-format off + /// + /// Deletes the model specified by modelId from the dataset. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.DeleteModelRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return a [`Status`] object. If the request failed, the + /// status contains the details of the failure. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.DeleteModelRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/model.proto#L2002} + /// + // clang-format on + Status DeleteModel( + google::cloud::bigquery::v2::DeleteModelRequest const& request, + Options opts = {}); + + private: + std::shared_ptr connection_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_model_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_MODEL_CLIENT_H diff --git a/google/cloud/bigquerycontrol/model/v2/model_connection.cc b/google/cloud/bigquerycontrol/model/v2/model_connection.cc new file mode 100644 index 0000000000000..94e0c40a5f7c1 --- /dev/null +++ b/google/cloud/bigquerycontrol/model/v2/model_connection.cc @@ -0,0 +1,65 @@ +// Copyright 2024 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/v2/model.proto + +#include "google/cloud/bigquerycontrol/model/v2/model_connection.h" +#include "google/cloud/bigquerycontrol/model/v2/internal/model_option_defaults.h" +#include "google/cloud/bigquerycontrol/model/v2/internal/model_tracing_connection.h" +#include "google/cloud/bigquerycontrol/model/v2/model_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 "google/cloud/internal/unified_grpc_credentials.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_model_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ModelServiceConnection::~ModelServiceConnection() = default; + +StatusOr ModelServiceConnection::GetModel( + google::cloud::bigquery::v2::GetModelRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StreamRange +ModelServiceConnection::ListModels( + google::cloud::bigquery::v2:: + ListModelsRequest) { // NOLINT(performance-unnecessary-value-param) + return google::cloud::internal::MakeUnimplementedPaginationRange< + StreamRange>(); +} + +StatusOr ModelServiceConnection::PatchModel( + google::cloud::bigquery::v2::PatchModelRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +Status ModelServiceConnection::DeleteModel( + google::cloud::bigquery::v2::DeleteModelRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_model_v2 +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/model/v2/model_connection.h b/google/cloud/bigquerycontrol/model/v2/model_connection.h new file mode 100644 index 0000000000000..c25a37f712d4a --- /dev/null +++ b/google/cloud/bigquerycontrol/model/v2/model_connection.h @@ -0,0 +1,205 @@ +// Copyright 2024 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/v2/model.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_MODEL_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_MODEL_CONNECTION_H + +#include "google/cloud/bigquerycontrol/model/v2/internal/model_retry_traits.h" +#include "google/cloud/bigquerycontrol/model/v2/model_connection_idempotency_policy.h" +#include "google/cloud/backoff_policy.h" +#include "google/cloud/experimental_tag.h" +#include "google/cloud/internal/retry_policy_impl.h" +#include "google/cloud/options.h" +#include "google/cloud/status_or.h" +#include "google/cloud/stream_range.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_model_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// The retry policy for `ModelServiceConnection`. +class ModelServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ModelServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ModelServiceLimitedErrorCountRetryPolicy + : public ModelServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ModelServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ModelServiceLimitedErrorCountRetryPolicy( + ModelServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : ModelServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ModelServiceLimitedErrorCountRetryPolicy( + ModelServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : ModelServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ModelServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + bigquerycontrol_model_v2_internal::ModelServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `ModelServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ModelServiceLimitedTimeRetryPolicy : public ModelServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ModelServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ModelServiceLimitedTimeRetryPolicy( + ModelServiceLimitedTimeRetryPolicy&& rhs) noexcept + : ModelServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ModelServiceLimitedTimeRetryPolicy( + ModelServiceLimitedTimeRetryPolicy const& rhs) noexcept + : ModelServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ModelServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + bigquerycontrol_model_v2_internal::ModelServiceRetryTraits> + impl_; +}; + +/** + * The `ModelServiceConnection` object for `ModelServiceClient`. + * + * This interface defines virtual methods for each of the user-facing overload + * sets in `ModelServiceClient`. This allows users to inject custom behavior + * (e.g., with a Google Mock object) when writing tests that use objects of type + * `ModelServiceClient`. + * + * To create a concrete instance, see `MakeModelServiceConnection()`. + * + * For mocking, see + * `bigquerycontrol_model_v2_mocks::MockModelServiceConnection`. + */ +class ModelServiceConnection { + public: + virtual ~ModelServiceConnection() = 0; + + virtual Options options() { return Options{}; } + + virtual StatusOr GetModel( + google::cloud::bigquery::v2::GetModelRequest const& request); + + virtual StreamRange ListModels( + google::cloud::bigquery::v2::ListModelsRequest request); + + virtual StatusOr PatchModel( + google::cloud::bigquery::v2::PatchModelRequest const& request); + + virtual Status DeleteModel( + google::cloud::bigquery::v2::DeleteModelRequest const& request); +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_model_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_MODEL_CONNECTION_H diff --git a/google/cloud/bigquerycontrol/model/v2/model_connection_idempotency_policy.cc b/google/cloud/bigquerycontrol/model/v2/model_connection_idempotency_policy.cc new file mode 100644 index 0000000000000..36ae2739a0c7e --- /dev/null +++ b/google/cloud/bigquerycontrol/model/v2/model_connection_idempotency_policy.cc @@ -0,0 +1,65 @@ +// Copyright 2024 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/v2/model.proto + +#include "google/cloud/bigquerycontrol/model/v2/model_connection_idempotency_policy.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_model_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +using ::google::cloud::Idempotency; + +ModelServiceConnectionIdempotencyPolicy:: + ~ModelServiceConnectionIdempotencyPolicy() = default; + +std::unique_ptr +ModelServiceConnectionIdempotencyPolicy::clone() const { + return std::make_unique(*this); +} + +Idempotency ModelServiceConnectionIdempotencyPolicy::GetModel( + google::cloud::bigquery::v2::GetModelRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency ModelServiceConnectionIdempotencyPolicy::ListModels( + google::cloud::bigquery::v2::ListModelsRequest) { // NOLINT + return Idempotency::kIdempotent; +} + +Idempotency ModelServiceConnectionIdempotencyPolicy::PatchModel( + google::cloud::bigquery::v2::PatchModelRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency ModelServiceConnectionIdempotencyPolicy::DeleteModel( + google::cloud::bigquery::v2::DeleteModelRequest const&) { + return Idempotency::kNonIdempotent; +} + +std::unique_ptr +MakeDefaultModelServiceConnectionIdempotencyPolicy() { + return std::make_unique(); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_model_v2 +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/model/v2/model_connection_idempotency_policy.h b/google/cloud/bigquerycontrol/model/v2/model_connection_idempotency_policy.h new file mode 100644 index 0000000000000..2769d120fc8aa --- /dev/null +++ b/google/cloud/bigquerycontrol/model/v2/model_connection_idempotency_policy.h @@ -0,0 +1,61 @@ +// Copyright 2024 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/v2/model.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_MODEL_CONNECTION_IDEMPOTENCY_POLICY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_MODEL_CONNECTION_IDEMPOTENCY_POLICY_H + +#include "google/cloud/idempotency.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_model_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ModelServiceConnectionIdempotencyPolicy { + public: + virtual ~ModelServiceConnectionIdempotencyPolicy(); + + /// Create a new copy of this object. + virtual std::unique_ptr clone() + const; + + virtual google::cloud::Idempotency GetModel( + google::cloud::bigquery::v2::GetModelRequest const& request); + + virtual google::cloud::Idempotency ListModels( + google::cloud::bigquery::v2::ListModelsRequest request); + + virtual google::cloud::Idempotency PatchModel( + google::cloud::bigquery::v2::PatchModelRequest const& request); + + virtual google::cloud::Idempotency DeleteModel( + google::cloud::bigquery::v2::DeleteModelRequest const& request); +}; + +std::unique_ptr +MakeDefaultModelServiceConnectionIdempotencyPolicy(); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_model_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_MODEL_CONNECTION_IDEMPOTENCY_POLICY_H diff --git a/google/cloud/bigquerycontrol/model/v2/model_options.h b/google/cloud/bigquerycontrol/model/v2/model_options.h new file mode 100644 index 0000000000000..acbfe347366a2 --- /dev/null +++ b/google/cloud/bigquerycontrol/model/v2/model_options.h @@ -0,0 +1,75 @@ +// Copyright 2024 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/v2/model.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_MODEL_OPTIONS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_MODEL_OPTIONS_H + +#include "google/cloud/bigquerycontrol/model/v2/model_connection.h" +#include "google/cloud/bigquerycontrol/model/v2/model_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 bigquerycontrol_model_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * Use with `google::cloud::Options` to configure the retry policy. + * + * @ingroup google-cloud-bigquerycontrol-options + */ +struct ModelServiceRetryPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure the backoff policy. + * + * @ingroup google-cloud-bigquerycontrol-options + */ +struct ModelServiceBackoffPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure which operations are retried. + * + * @ingroup google-cloud-bigquerycontrol-options + */ +struct ModelServiceConnectionIdempotencyPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * The options applicable to ModelService. + * + * @ingroup google-cloud-bigquerycontrol-options + */ +using ModelServicePolicyOptionList = + OptionList; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_model_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_MODEL_OPTIONS_H diff --git a/google/cloud/bigquerycontrol/model/v2/model_rest_connection.cc b/google/cloud/bigquerycontrol/model/v2/model_rest_connection.cc new file mode 100644 index 0000000000000..33907dc931962 --- /dev/null +++ b/google/cloud/bigquerycontrol/model/v2/model_rest_connection.cc @@ -0,0 +1,59 @@ +// Copyright 2024 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/v2/model.proto + +#include "google/cloud/bigquerycontrol/model/v2/model_rest_connection.h" +#include "google/cloud/bigquerycontrol/model/v2/internal/model_option_defaults.h" +#include "google/cloud/bigquerycontrol/model/v2/internal/model_rest_connection_impl.h" +#include "google/cloud/bigquerycontrol/model/v2/internal/model_rest_stub_factory.h" +#include "google/cloud/bigquerycontrol/model/v2/internal/model_tracing_connection.h" +#include "google/cloud/bigquerycontrol/model/v2/model_options.h" +#include "google/cloud/common_options.h" +#include "google/cloud/credentials.h" +#include "google/cloud/internal/rest_background_threads_impl.h" +#include "google/cloud/internal/rest_options.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_model_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr MakeModelServiceConnectionRest( + Options options) { + internal::CheckExpectedOptions< + CommonOptionList, RestOptionList, UnifiedCredentialsOptionList, + rest_internal::TargetApiVersionOption, ModelServicePolicyOptionList>( + options, __func__); + options = bigquerycontrol_model_v2_internal::ModelServiceDefaultOptions( + std::move(options)); + auto background = std::make_unique< + rest_internal::AutomaticallyCreatedRestBackgroundThreads>(); + auto stub = + bigquerycontrol_model_v2_internal::CreateDefaultModelServiceRestStub( + options); + return bigquerycontrol_model_v2_internal::MakeModelServiceTracingConnection( + std::make_shared< + bigquerycontrol_model_v2_internal::ModelServiceRestConnectionImpl>( + std::move(background), std::move(stub), std::move(options))); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_model_v2 +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/model/v2/model_rest_connection.h b/google/cloud/bigquerycontrol/model/v2/model_rest_connection.h new file mode 100644 index 0000000000000..955a3583af035 --- /dev/null +++ b/google/cloud/bigquerycontrol/model/v2/model_rest_connection.h @@ -0,0 +1,64 @@ +// Copyright 2024 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/v2/model.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_MODEL_REST_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_MODEL_REST_CONNECTION_H + +#include "google/cloud/bigquerycontrol/model/v2/model_connection.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_model_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * A factory function to construct an object of type `ModelServiceConnection` + * that uses REST over HTTP as transport in lieu of gRPC. REST transport should + * only be used for services that do not support gRPC or if the existing network + * configuration precludes using gRPC. + * + * The returned connection object should not be used directly; instead it + * should be passed as an argument to the constructor of ModelServiceClient. + * + * The optional @p options argument may be used to configure aspects of the + * returned `ModelServiceConnection`. Expected options are any of the types in + * the following option lists: + * + * - `google::cloud::CommonOptionList` + * - `google::cloud::RestOptionList` + * - `google::cloud::UnifiedCredentialsOptionList` + * - `google::cloud::bigquerycontrol_model_v2::ModelServicePolicyOptionList` + * + * @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 `ModelServiceConnection` created by + * this function. + */ +std::shared_ptr MakeModelServiceConnectionRest( + Options options = {}); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_model_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_MODEL_V2_MODEL_REST_CONNECTION_H diff --git a/google/cloud/bigquerycontrol/model/v2/samples/model_client_samples.cc b/google/cloud/bigquerycontrol/model/v2/samples/model_client_samples.cc new file mode 100644 index 0000000000000..c5bb9ec47114d --- /dev/null +++ b/google/cloud/bigquerycontrol/model/v2/samples/model_client_samples.cc @@ -0,0 +1,163 @@ +// Copyright 2024 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/v2/model.proto + +#include "google/cloud/bigquerycontrol/model/v2/model_client.h" +#include "google/cloud/bigquerycontrol/model/v2/model_connection_idempotency_policy.h" +#include "google/cloud/bigquerycontrol/model/v2/model_options.h" +#include "google/cloud/common_options.h" +#include "google/cloud/credentials.h" +#include "google/cloud/internal/getenv.h" +#include "google/cloud/testing_util/example_driver.h" +#include +#include +#include +#include + +// clang-format off +// main-dox-marker: bigquerycontrol_model_v2::ModelServiceClient +// clang-format on +namespace { + +void SetClientEndpoint(std::vector const& argv) { + if (!argv.empty()) { + throw google::cloud::testing_util::Usage{"set-client-endpoint"}; + } + //! [set-client-endpoint] + // This configuration is common with Private Google Access: + // https://cloud.google.com/vpc/docs/private-google-access + auto options = google::cloud::Options{}.set( + "private.googleapis.com"); + auto client = google::cloud::bigquerycontrol_model_v2::ModelServiceClient( + google::cloud::bigquerycontrol_model_v2::MakeModelServiceConnectionRest( + options)); + //! [set-client-endpoint] +} + +//! [custom-idempotency-policy] +class CustomIdempotencyPolicy : public google::cloud::bigquerycontrol_model_v2:: + ModelServiceConnectionIdempotencyPolicy { + public: + ~CustomIdempotencyPolicy() override = default; + std::unique_ptr + clone() const override { + return std::make_unique(*this); + } + // Override inherited functions to define as needed. +}; +//! [custom-idempotency-policy] + +void SetRetryPolicy(std::vector const& argv) { + if (!argv.empty()) { + throw google::cloud::testing_util::Usage{"set-client-retry-policy"}; + } + //! [set-retry-policy] + auto options = google::cloud::Options{} + .set( + CustomIdempotencyPolicy().clone()) + .set( + google::cloud::bigquerycontrol_model_v2:: + ModelServiceLimitedErrorCountRetryPolicy(3) + .clone()) + .set( + google::cloud::ExponentialBackoffPolicy( + /*initial_delay=*/std::chrono::milliseconds(200), + /*maximum_delay=*/std::chrono::seconds(45), + /*scaling=*/2.0) + .clone()); + auto connection = + google::cloud::bigquerycontrol_model_v2::MakeModelServiceConnectionRest( + options); + + // c1 and c2 share the same retry policies + auto c1 = + google::cloud::bigquerycontrol_model_v2::ModelServiceClient(connection); + auto c2 = + google::cloud::bigquerycontrol_model_v2::ModelServiceClient(connection); + + // You can override any of the policies in a new client. This new client + // will share the policies from c1 (or c2) *except* for the retry policy. + auto c3 = google::cloud::bigquerycontrol_model_v2::ModelServiceClient( + connection, + google::cloud::Options{} + .set( + google::cloud::bigquerycontrol_model_v2:: + ModelServiceLimitedTimeRetryPolicy(std::chrono::minutes(5)) + .clone())); + + // You can also override the policies in a single call: + // c3.SomeRpc(..., google::cloud::Options{} + // .set( + // google::cloud::bigquerycontrol_model_v2::ModelServiceLimitedErrorCountRetryPolicy(10).clone())); + //! [set-retry-policy] +} + +void WithServiceAccount(std::vector const& argv) { + if (argv.size() != 1 || argv[0] == "--help") { + throw google::cloud::testing_util::Usage{"with-service-account "}; + } + //! [with-service-account] + [](std::string const& keyfile) { + auto is = std::ifstream(keyfile); + is.exceptions(std::ios::badbit); // Minimal error handling in examples + auto contents = std::string(std::istreambuf_iterator(is.rdbuf()), {}); + auto options = + google::cloud::Options{}.set( + google::cloud::MakeServiceAccountCredentials(contents)); + return google::cloud::bigquerycontrol_model_v2::ModelServiceClient( + google::cloud::bigquerycontrol_model_v2::MakeModelServiceConnectionRest( + options)); + } + //! [with-service-account] + (argv.at(0)); +} + +void AutoRun(std::vector const& argv) { + namespace examples = ::google::cloud::testing_util; + using ::google::cloud::internal::GetEnv; + if (!argv.empty()) throw examples::Usage{"auto"}; + examples::CheckEnvironmentVariablesAreSet( + {"GOOGLE_CLOUD_CPP_TEST_SERVICE_ACCOUNT_KEYFILE"}); + auto const keyfile = + GetEnv("GOOGLE_CLOUD_CPP_TEST_SERVICE_ACCOUNT_KEYFILE").value(); + + std::cout << "\nRunning SetClientEndpoint() example" << std::endl; + SetClientEndpoint({}); + + std::cout << "\nRunning SetRetryPolicy() example" << std::endl; + SetRetryPolicy({}); + + std::cout << "\nRunning WithServiceAccount() example" << std::endl; + WithServiceAccount({keyfile}); +} + +} // namespace + +int main(int argc, char* argv[]) { // NOLINT(bugprone-exception-escape) + google::cloud::testing_util::Example example({ + {"set-client-endpoint", SetClientEndpoint}, + {"set-retry-policy", SetRetryPolicy}, + {"with-service-account", WithServiceAccount}, + {"auto", AutoRun}, + }); + return example.Run(argc, argv); +} diff --git a/google/cloud/bigquerycontrol/project/v2/internal/project_option_defaults.cc b/google/cloud/bigquerycontrol/project/v2/internal/project_option_defaults.cc new file mode 100644 index 0000000000000..dfc54831c968c --- /dev/null +++ b/google/cloud/bigquerycontrol/project/v2/internal/project_option_defaults.cc @@ -0,0 +1,70 @@ +// Copyright 2024 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/v2/project.proto + +#include "google/cloud/bigquerycontrol/project/v2/internal/project_option_defaults.h" +#include "google/cloud/bigquerycontrol/project/v2/project_connection.h" +#include "google/cloud/bigquerycontrol/project/v2/project_options.h" +#include "google/cloud/internal/populate_common_options.h" +#include "google/cloud/internal/populate_grpc_options.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_project_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +namespace { +auto constexpr kBackoffScaling = 2.0; +} // namespace + +Options ProjectServiceDefaultOptions(Options options) { + options = internal::PopulateCommonOptions( + std::move(options), "GOOGLE_CLOUD_CPP_PROJECT_SERVICE_ENDPOINT", "", + "GOOGLE_CLOUD_CPP_PROJECT_SERVICE_AUTHORITY", "bigquery.googleapis.com"); + options = internal::PopulateGrpcOptions(std::move(options)); + if (!options.has< + bigquerycontrol_project_v2::ProjectServiceRetryPolicyOption>()) { + options.set( + bigquerycontrol_project_v2::ProjectServiceLimitedTimeRetryPolicy( + std::chrono::minutes(30)) + .clone()); + } + if (!options.has< + bigquerycontrol_project_v2::ProjectServiceBackoffPolicyOption>()) { + options.set( + ExponentialBackoffPolicy( + std::chrono::seconds(0), std::chrono::seconds(1), + std::chrono::minutes(5), kBackoffScaling, kBackoffScaling) + .clone()); + } + if (!options.has()) { + options.set( + bigquerycontrol_project_v2:: + MakeDefaultProjectServiceConnectionIdempotencyPolicy()); + } + + return options; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_project_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/project/v2/internal/project_option_defaults.h b/google/cloud/bigquerycontrol/project/v2/internal/project_option_defaults.h new file mode 100644 index 0000000000000..496e35258ba3e --- /dev/null +++ b/google/cloud/bigquerycontrol/project/v2/internal/project_option_defaults.h @@ -0,0 +1,37 @@ +// Copyright 2024 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/v2/project.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_INTERNAL_PROJECT_OPTION_DEFAULTS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_INTERNAL_PROJECT_OPTION_DEFAULTS_H + +#include "google/cloud/options.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace bigquerycontrol_project_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +Options ProjectServiceDefaultOptions(Options options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_project_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_INTERNAL_PROJECT_OPTION_DEFAULTS_H diff --git a/google/cloud/bigquerycontrol/project/v2/internal/project_rest_connection_impl.cc b/google/cloud/bigquerycontrol/project/v2/internal/project_rest_connection_impl.cc new file mode 100644 index 0000000000000..70999a4c29ad9 --- /dev/null +++ b/google/cloud/bigquerycontrol/project/v2/internal/project_rest_connection_impl.cc @@ -0,0 +1,61 @@ +// Copyright 2024 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/v2/project.proto + +#include "google/cloud/bigquerycontrol/project/v2/internal/project_rest_connection_impl.h" +#include "google/cloud/bigquerycontrol/project/v2/internal/project_rest_stub_factory.h" +#include "google/cloud/common_options.h" +#include "google/cloud/credentials.h" +#include "google/cloud/internal/rest_retry_loop.h" +#include "google/cloud/rest_options.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_project_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ProjectServiceRestConnectionImpl::ProjectServiceRestConnectionImpl( + std::unique_ptr background, + std::shared_ptr + stub, + Options options) + : background_(std::move(background)), + stub_(std::move(stub)), + options_(internal::MergeOptions(std::move(options), + ProjectServiceConnection::options())) {} + +StatusOr +ProjectServiceRestConnectionImpl::GetServiceAccount( + google::cloud::bigquery::v2::GetServiceAccountRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::rest_internal::RestRetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->GetServiceAccount(request), + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::GetServiceAccountRequest const& + request) { + return stub_->GetServiceAccount(rest_context, options, request); + }, + *current, request, __func__); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_project_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/project/v2/internal/project_rest_connection_impl.h b/google/cloud/bigquerycontrol/project/v2/internal/project_rest_connection_impl.h new file mode 100644 index 0000000000000..9f3425cc91439 --- /dev/null +++ b/google/cloud/bigquerycontrol/project/v2/internal/project_rest_connection_impl.h @@ -0,0 +1,91 @@ +// Copyright 2024 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/v2/project.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_INTERNAL_PROJECT_REST_CONNECTION_IMPL_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_INTERNAL_PROJECT_REST_CONNECTION_IMPL_H + +#include "google/cloud/bigquerycontrol/project/v2/internal/project_rest_stub.h" +#include "google/cloud/bigquerycontrol/project/v2/internal/project_retry_traits.h" +#include "google/cloud/bigquerycontrol/project/v2/project_connection.h" +#include "google/cloud/bigquerycontrol/project/v2/project_connection_idempotency_policy.h" +#include "google/cloud/bigquerycontrol/project/v2/project_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/version.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_project_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ProjectServiceRestConnectionImpl + : public bigquerycontrol_project_v2::ProjectServiceConnection { + public: + ~ProjectServiceRestConnectionImpl() override = default; + + ProjectServiceRestConnectionImpl( + std::unique_ptr background, + std::shared_ptr< + bigquerycontrol_project_v2_internal::ProjectServiceRestStub> + stub, + Options options); + + Options options() override { return options_; } + + StatusOr + GetServiceAccount(google::cloud::bigquery::v2::GetServiceAccountRequest const& + request) override; + + private: + static std::unique_ptr + retry_policy(Options const& options) { + return options + .get() + ->clone(); + } + + static std::unique_ptr backoff_policy(Options const& options) { + return options + .get() + ->clone(); + } + + static std::unique_ptr< + bigquerycontrol_project_v2::ProjectServiceConnectionIdempotencyPolicy> + idempotency_policy(Options const& options) { + return options + .get() + ->clone(); + } + + std::unique_ptr background_; + std::shared_ptr + stub_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_project_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_INTERNAL_PROJECT_REST_CONNECTION_IMPL_H diff --git a/google/cloud/bigquerycontrol/project/v2/internal/project_rest_logging_decorator.cc b/google/cloud/bigquerycontrol/project/v2/internal/project_rest_logging_decorator.cc new file mode 100644 index 0000000000000..5a64a5f70d3c1 --- /dev/null +++ b/google/cloud/bigquerycontrol/project/v2/internal/project_rest_logging_decorator.cc @@ -0,0 +1,53 @@ +// Copyright 2024 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/v2/project.proto + +#include "google/cloud/bigquerycontrol/project/v2/internal/project_rest_logging_decorator.h" +#include "google/cloud/internal/log_wrapper.h" +#include "google/cloud/status_or.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_project_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ProjectServiceRestLogging::ProjectServiceRestLogging( + 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 +ProjectServiceRestLogging::GetServiceAccount( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::GetServiceAccountRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::GetServiceAccountRequest const& + request) { + return child_->GetServiceAccount(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_project_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/project/v2/internal/project_rest_logging_decorator.h b/google/cloud/bigquerycontrol/project/v2/internal/project_rest_logging_decorator.h new file mode 100644 index 0000000000000..0cd7de088b52e --- /dev/null +++ b/google/cloud/bigquerycontrol/project/v2/internal/project_rest_logging_decorator.h @@ -0,0 +1,61 @@ +// Copyright 2024 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/v2/project.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_INTERNAL_PROJECT_REST_LOGGING_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_INTERNAL_PROJECT_REST_LOGGING_DECORATOR_H + +#include "google/cloud/bigquerycontrol/project/v2/internal/project_rest_stub.h" +#include "google/cloud/future.h" +#include "google/cloud/internal/rest_context.h" +#include "google/cloud/tracing_options.h" +#include "google/cloud/version.h" +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_project_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ProjectServiceRestLogging : public ProjectServiceRestStub { + public: + ~ProjectServiceRestLogging() override = default; + ProjectServiceRestLogging(std::shared_ptr child, + TracingOptions tracing_options, + std::set components); + + StatusOr + GetServiceAccount(google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetServiceAccountRequest const& + request) override; + + private: + std::shared_ptr child_; + TracingOptions tracing_options_; + std::set components_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_project_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_INTERNAL_PROJECT_REST_LOGGING_DECORATOR_H diff --git a/google/cloud/bigquerycontrol/project/v2/internal/project_rest_metadata_decorator.cc b/google/cloud/bigquerycontrol/project/v2/internal/project_rest_metadata_decorator.cc new file mode 100644 index 0000000000000..cf608aab4ad7e --- /dev/null +++ b/google/cloud/bigquerycontrol/project/v2/internal/project_rest_metadata_decorator.cc @@ -0,0 +1,60 @@ +// Copyright 2024 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/v2/project.proto + +#include "google/cloud/bigquerycontrol/project/v2/internal/project_rest_metadata_decorator.h" +#include "google/cloud/internal/absl_str_cat_quiet.h" +#include "google/cloud/internal/api_client_header.h" +#include "google/cloud/internal/rest_set_metadata.h" +#include "google/cloud/status_or.h" +#include "absl/strings/str_format.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_project_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ProjectServiceRestMetadata::ProjectServiceRestMetadata( + std::shared_ptr child, + std::string api_client_header) + : child_(std::move(child)), + api_client_header_( + api_client_header.empty() + ? google::cloud::internal::GeneratedLibClientHeader() + : std::move(api_client_header)) {} + +StatusOr +ProjectServiceRestMetadata::GetServiceAccount( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::GetServiceAccountRequest const& request) { + SetMetadata(rest_context, options); + return child_->GetServiceAccount(rest_context, options, request); +} + +void ProjectServiceRestMetadata::SetMetadata( + rest_internal::RestContext& rest_context, Options const& options, + std::vector const& params) { + google::cloud::rest_internal::SetMetadata(rest_context, options, params, + api_client_header_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_project_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/project/v2/internal/project_rest_metadata_decorator.h b/google/cloud/bigquerycontrol/project/v2/internal/project_rest_metadata_decorator.h new file mode 100644 index 0000000000000..8c4abd3072a3a --- /dev/null +++ b/google/cloud/bigquerycontrol/project/v2/internal/project_rest_metadata_decorator.h @@ -0,0 +1,62 @@ +// Copyright 2024 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/v2/project.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_INTERNAL_PROJECT_REST_METADATA_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_INTERNAL_PROJECT_REST_METADATA_DECORATOR_H + +#include "google/cloud/bigquerycontrol/project/v2/internal/project_rest_stub.h" +#include "google/cloud/future.h" +#include "google/cloud/rest_options.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_project_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ProjectServiceRestMetadata : public ProjectServiceRestStub { + public: + ~ProjectServiceRestMetadata() override = default; + explicit ProjectServiceRestMetadata( + std::shared_ptr child, + std::string api_client_header = ""); + + StatusOr + GetServiceAccount(google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetServiceAccountRequest const& + request) override; + + private: + void SetMetadata(rest_internal::RestContext& rest_context, + Options const& options, + std::vector const& params = {}); + + std::shared_ptr child_; + std::string api_client_header_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_project_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_INTERNAL_PROJECT_REST_METADATA_DECORATOR_H diff --git a/google/cloud/bigquerycontrol/project/v2/internal/project_rest_stub.cc b/google/cloud/bigquerycontrol/project/v2/internal/project_rest_stub.cc new file mode 100644 index 0000000000000..e3fefc9ea1b6c --- /dev/null +++ b/google/cloud/bigquerycontrol/project/v2/internal/project_rest_stub.cc @@ -0,0 +1,59 @@ +// Copyright 2024 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/v2/project.proto + +#include "google/cloud/bigquerycontrol/project/v2/internal/project_rest_stub.h" +#include "google/cloud/common_options.h" +#include "google/cloud/internal/absl_str_cat_quiet.h" +#include "google/cloud/internal/rest_stub_helpers.h" +#include "google/cloud/status_or.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_project_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +DefaultProjectServiceRestStub::DefaultProjectServiceRestStub(Options options) + : service_(rest_internal::MakePooledRestClient( + options.get(), options)), + options_(std::move(options)) {} + +DefaultProjectServiceRestStub::DefaultProjectServiceRestStub( + std::shared_ptr service, Options options) + : service_(std::move(service)), options_(std::move(options)) {} + +StatusOr +DefaultProjectServiceRestStub::GetServiceAccount( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetServiceAccountRequest const& request) { + return rest_internal::Get< + google::cloud::bigquery::v2::GetServiceAccountResponse>( + *service_, rest_context, request, false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", + "serviceAccount")); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_project_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/project/v2/internal/project_rest_stub.h b/google/cloud/bigquerycontrol/project/v2/internal/project_rest_stub.h new file mode 100644 index 0000000000000..b2395ca193282 --- /dev/null +++ b/google/cloud/bigquerycontrol/project/v2/internal/project_rest_stub.h @@ -0,0 +1,70 @@ +// Copyright 2024 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/v2/project.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_INTERNAL_PROJECT_REST_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_INTERNAL_PROJECT_REST_STUB_H + +#include "google/cloud/completion_queue.h" +#include "google/cloud/internal/rest_client.h" +#include "google/cloud/internal/rest_context.h" +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_project_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ProjectServiceRestStub { + public: + virtual ~ProjectServiceRestStub() = default; + + virtual StatusOr + GetServiceAccount( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetServiceAccountRequest const& request) = 0; +}; + +class DefaultProjectServiceRestStub : public ProjectServiceRestStub { + public: + ~DefaultProjectServiceRestStub() override = default; + + explicit DefaultProjectServiceRestStub(Options options); + DefaultProjectServiceRestStub( + std::shared_ptr service, Options options); + + StatusOr + GetServiceAccount(google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetServiceAccountRequest const& + request) override; + + private: + std::shared_ptr service_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_project_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_INTERNAL_PROJECT_REST_STUB_H diff --git a/google/cloud/bigquerycontrol/project/v2/internal/project_rest_stub_factory.cc b/google/cloud/bigquerycontrol/project/v2/internal/project_rest_stub_factory.cc new file mode 100644 index 0000000000000..c8c438fe2b5ca --- /dev/null +++ b/google/cloud/bigquerycontrol/project/v2/internal/project_rest_stub_factory.cc @@ -0,0 +1,56 @@ +// Copyright 2024 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/v2/project.proto + +#include "google/cloud/bigquerycontrol/project/v2/internal/project_rest_stub_factory.h" +#include "google/cloud/bigquerycontrol/project/v2/internal/project_rest_logging_decorator.h" +#include "google/cloud/bigquerycontrol/project/v2/internal/project_rest_metadata_decorator.h" +#include "google/cloud/bigquerycontrol/project/v2/internal/project_rest_stub.h" +#include "google/cloud/common_options.h" +#include "google/cloud/internal/algorithm.h" +#include "google/cloud/internal/populate_rest_options.h" +#include "google/cloud/log.h" +#include "google/cloud/options.h" +#include "google/cloud/rest_options.h" +#include "absl/strings/match.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_project_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultProjectServiceRestStub( + Options const& options) { + auto opts = internal::PopulateRestOptions(options); + std::shared_ptr stub = + std::make_shared(std::move(opts)); + stub = std::make_shared(std::move(stub)); + if (internal::Contains(options.get(), "rpc")) { + GCP_LOG(INFO) << "Enabled logging for REST rpc calls"; + stub = std::make_shared( + std::move(stub), options.get(), + options.get()); + } + return stub; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_project_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/project/v2/internal/project_rest_stub_factory.h b/google/cloud/bigquerycontrol/project/v2/internal/project_rest_stub_factory.h new file mode 100644 index 0000000000000..17c653c7141cb --- /dev/null +++ b/google/cloud/bigquerycontrol/project/v2/internal/project_rest_stub_factory.h @@ -0,0 +1,40 @@ +// Copyright 2024 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/v2/project.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_INTERNAL_PROJECT_REST_STUB_FACTORY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_INTERNAL_PROJECT_REST_STUB_FACTORY_H + +#include "google/cloud/bigquerycontrol/project/v2/internal/project_rest_stub.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_project_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultProjectServiceRestStub( + Options const& options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_project_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_INTERNAL_PROJECT_REST_STUB_FACTORY_H diff --git a/google/cloud/bigquerycontrol/project/v2/internal/project_retry_traits.h b/google/cloud/bigquerycontrol/project/v2/internal/project_retry_traits.h new file mode 100644 index 0000000000000..834e7bdfde6c9 --- /dev/null +++ b/google/cloud/bigquerycontrol/project/v2/internal/project_retry_traits.h @@ -0,0 +1,43 @@ +// Copyright 2024 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/v2/project.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_INTERNAL_PROJECT_RETRY_TRAITS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_INTERNAL_PROJECT_RETRY_TRAITS_H + +#include "google/cloud/status.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace bigquerycontrol_project_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// Define the gRPC status code semantics for retrying requests. +struct ProjectServiceRetryTraits { + static bool IsPermanentFailure(google::cloud::Status const& status) { + return status.code() != StatusCode::kOk && + status.code() != StatusCode::kUnavailable; + } +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_project_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_INTERNAL_PROJECT_RETRY_TRAITS_H diff --git a/google/cloud/bigquerycontrol/project/v2/internal/project_sources.cc b/google/cloud/bigquerycontrol/project/v2/internal/project_sources.cc new file mode 100644 index 0000000000000..94d6ceeee2059 --- /dev/null +++ b/google/cloud/bigquerycontrol/project/v2/internal/project_sources.cc @@ -0,0 +1,31 @@ +// Copyright 2024 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/v2/project.proto + +// NOLINTBEGIN(bugprone-suspicious-include) +#include "google/cloud/bigquerycontrol/project/v2/internal/project_option_defaults.cc" +#include "google/cloud/bigquerycontrol/project/v2/internal/project_rest_connection_impl.cc" +#include "google/cloud/bigquerycontrol/project/v2/internal/project_rest_logging_decorator.cc" +#include "google/cloud/bigquerycontrol/project/v2/internal/project_rest_metadata_decorator.cc" +#include "google/cloud/bigquerycontrol/project/v2/internal/project_rest_stub.cc" +#include "google/cloud/bigquerycontrol/project/v2/internal/project_rest_stub_factory.cc" +#include "google/cloud/bigquerycontrol/project/v2/internal/project_tracing_connection.cc" +#include "google/cloud/bigquerycontrol/project/v2/project_client.cc" +#include "google/cloud/bigquerycontrol/project/v2/project_connection.cc" +#include "google/cloud/bigquerycontrol/project/v2/project_connection_idempotency_policy.cc" +#include "google/cloud/bigquerycontrol/project/v2/project_rest_connection.cc" +// NOLINTEND(bugprone-suspicious-include) diff --git a/google/cloud/bigquerycontrol/project/v2/internal/project_tracing_connection.cc b/google/cloud/bigquerycontrol/project/v2/internal/project_tracing_connection.cc new file mode 100644 index 0000000000000..ab0699b2d4de6 --- /dev/null +++ b/google/cloud/bigquerycontrol/project/v2/internal/project_tracing_connection.cc @@ -0,0 +1,62 @@ +// Copyright 2024 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/v2/project.proto + +#include "google/cloud/bigquerycontrol/project/v2/internal/project_tracing_connection.h" +#include "google/cloud/internal/opentelemetry.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_project_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +ProjectServiceTracingConnection::ProjectServiceTracingConnection( + std::shared_ptr child) + : child_(std::move(child)) {} + +StatusOr +ProjectServiceTracingConnection::GetServiceAccount( + google::cloud::bigquery::v2::GetServiceAccountRequest const& request) { + auto span = internal::MakeSpan( + "bigquerycontrol_project_v2::ProjectServiceConnection::" + "GetServiceAccount"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->GetServiceAccount(request)); +} + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +std::shared_ptr +MakeProjectServiceTracingConnection( + std::shared_ptr + conn) { +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + if (internal::TracingEnabled(conn->options())) { + conn = std::make_shared(std::move(conn)); + } +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + return conn; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_project_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/project/v2/internal/project_tracing_connection.h b/google/cloud/bigquerycontrol/project/v2/internal/project_tracing_connection.h new file mode 100644 index 0000000000000..dc7d36647befc --- /dev/null +++ b/google/cloud/bigquerycontrol/project/v2/internal/project_tracing_connection.h @@ -0,0 +1,69 @@ +// Copyright 2024 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/v2/project.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_INTERNAL_PROJECT_TRACING_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_INTERNAL_PROJECT_TRACING_CONNECTION_H + +#include "google/cloud/bigquerycontrol/project/v2/project_connection.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_project_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +class ProjectServiceTracingConnection + : public bigquerycontrol_project_v2::ProjectServiceConnection { + public: + ~ProjectServiceTracingConnection() override = default; + + explicit ProjectServiceTracingConnection( + std::shared_ptr + child); + + Options options() override { return child_->options(); } + + StatusOr + GetServiceAccount(google::cloud::bigquery::v2::GetServiceAccountRequest const& + request) override; + + private: + std::shared_ptr child_; +}; + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +/** + * Conditionally applies the tracing decorator to the given connection. + * + * The connection is only decorated if tracing is enabled (as determined by the + * connection's options). + */ +std::shared_ptr +MakeProjectServiceTracingConnection( + std::shared_ptr conn); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_project_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_INTERNAL_PROJECT_TRACING_CONNECTION_H diff --git a/google/cloud/bigquerycontrol/project/v2/mocks/mock_project_connection.h b/google/cloud/bigquerycontrol/project/v2/mocks/mock_project_connection.h new file mode 100644 index 0000000000000..5377880bf0b91 --- /dev/null +++ b/google/cloud/bigquerycontrol/project/v2/mocks/mock_project_connection.h @@ -0,0 +1,62 @@ +// Copyright 2024 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/v2/project.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_MOCKS_MOCK_PROJECT_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_MOCKS_MOCK_PROJECT_CONNECTION_H + +#include "google/cloud/bigquerycontrol/project/v2/project_connection.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_project_v2_mocks { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * A class to mock `ProjectServiceConnection`. + * + * Application developers may want to test their code with simulated responses, + * including errors, from an object of type `ProjectServiceClient`. To do so, + * construct an object of type `ProjectServiceClient` 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]: @cloud_cpp_docs_link{bigquery,bigquery-read-mock} + */ +class MockProjectServiceConnection + : public bigquerycontrol_project_v2::ProjectServiceConnection { + public: + MOCK_METHOD(Options, options, (), (override)); + + MOCK_METHOD( + StatusOr, + GetServiceAccount, + (google::cloud::bigquery::v2::GetServiceAccountRequest const& request), + (override)); +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_project_v2_mocks +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_MOCKS_MOCK_PROJECT_CONNECTION_H diff --git a/google/cloud/bigquerycontrol/project/v2/project_client.cc b/google/cloud/bigquerycontrol/project/v2/project_client.cc new file mode 100644 index 0000000000000..89f3b346a980c --- /dev/null +++ b/google/cloud/bigquerycontrol/project/v2/project_client.cc @@ -0,0 +1,46 @@ +// Copyright 2024 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/v2/project.proto + +#include "google/cloud/bigquerycontrol/project/v2/project_client.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_project_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ProjectServiceClient::ProjectServiceClient( + std::shared_ptr connection, Options opts) + : connection_(std::move(connection)), + options_( + internal::MergeOptions(std::move(opts), connection_->options())) {} +ProjectServiceClient::~ProjectServiceClient() = default; + +StatusOr +ProjectServiceClient::GetServiceAccount( + google::cloud::bigquery::v2::GetServiceAccountRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->GetServiceAccount(request); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_project_v2 +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/project/v2/project_client.h b/google/cloud/bigquerycontrol/project/v2/project_client.h new file mode 100644 index 0000000000000..1a9c9f5bf2305 --- /dev/null +++ b/google/cloud/bigquerycontrol/project/v2/project_client.h @@ -0,0 +1,134 @@ +// Copyright 2024 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/v2/project.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_PROJECT_CLIENT_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_PROJECT_CLIENT_H + +#include "google/cloud/bigquerycontrol/project/v2/project_rest_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 bigquerycontrol_project_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// +/// This is an experimental RPC service definition for the BigQuery +/// Project Service. +/// +/// It should not be relied on for production use cases at this time. +/// +/// @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 ProjectServiceClient { + public: + explicit ProjectServiceClient( + std::shared_ptr connection, Options opts = {}); + ~ProjectServiceClient(); + + ///@{ + /// @name Copy and move support + ProjectServiceClient(ProjectServiceClient const&) = default; + ProjectServiceClient& operator=(ProjectServiceClient const&) = default; + ProjectServiceClient(ProjectServiceClient&&) = default; + ProjectServiceClient& operator=(ProjectServiceClient&&) = default; + ///@} + + ///@{ + /// @name Equality + friend bool operator==(ProjectServiceClient const& a, + ProjectServiceClient const& b) { + return a.connection_ == b.connection_; + } + friend bool operator!=(ProjectServiceClient const& a, + ProjectServiceClient const& b) { + return !(a == b); + } + ///@} + + // clang-format off + /// + /// RPC to get the service account for a project used for interactions with + /// Google Cloud KMS + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.GetServiceAccountRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return the result of the RPC. The response message type + /// ([google.cloud.bigquery.v2.GetServiceAccountResponse]) + /// is mapped to a C++ class using the [Protobuf mapping rules]. + /// If the request fails, the [`StatusOr`] contains the error details. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.GetServiceAccountRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/project.proto#L49} + /// [google.cloud.bigquery.v2.GetServiceAccountResponse]: @googleapis_reference_link{google/cloud/bigquery/v2/project.proto#L55} + /// + // clang-format on + StatusOr + GetServiceAccount( + google::cloud::bigquery::v2::GetServiceAccountRequest const& request, + Options opts = {}); + + private: + std::shared_ptr connection_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_project_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_PROJECT_CLIENT_H diff --git a/google/cloud/bigquerycontrol/project/v2/project_connection.cc b/google/cloud/bigquerycontrol/project/v2/project_connection.cc new file mode 100644 index 0000000000000..b5e41aec7041e --- /dev/null +++ b/google/cloud/bigquerycontrol/project/v2/project_connection.cc @@ -0,0 +1,47 @@ +// Copyright 2024 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/v2/project.proto + +#include "google/cloud/bigquerycontrol/project/v2/project_connection.h" +#include "google/cloud/bigquerycontrol/project/v2/internal/project_option_defaults.h" +#include "google/cloud/bigquerycontrol/project/v2/internal/project_tracing_connection.h" +#include "google/cloud/bigquerycontrol/project/v2/project_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/unified_grpc_credentials.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_project_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +ProjectServiceConnection::~ProjectServiceConnection() = default; + +StatusOr +ProjectServiceConnection::GetServiceAccount( + google::cloud::bigquery::v2::GetServiceAccountRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_project_v2 +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/project/v2/project_connection.h b/google/cloud/bigquerycontrol/project/v2/project_connection.h new file mode 100644 index 0000000000000..d198b49b2ccfa --- /dev/null +++ b/google/cloud/bigquerycontrol/project/v2/project_connection.h @@ -0,0 +1,196 @@ +// Copyright 2024 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/v2/project.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_PROJECT_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_PROJECT_CONNECTION_H + +#include "google/cloud/bigquerycontrol/project/v2/internal/project_retry_traits.h" +#include "google/cloud/bigquerycontrol/project/v2/project_connection_idempotency_policy.h" +#include "google/cloud/backoff_policy.h" +#include "google/cloud/experimental_tag.h" +#include "google/cloud/internal/retry_policy_impl.h" +#include "google/cloud/options.h" +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_project_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// The retry policy for `ProjectServiceConnection`. +class ProjectServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `ProjectServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ProjectServiceLimitedErrorCountRetryPolicy + : public ProjectServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit ProjectServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + ProjectServiceLimitedErrorCountRetryPolicy( + ProjectServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : ProjectServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + ProjectServiceLimitedErrorCountRetryPolicy( + ProjectServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : ProjectServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = ProjectServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + bigquerycontrol_project_v2_internal::ProjectServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `ProjectServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class ProjectServiceLimitedTimeRetryPolicy : public ProjectServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit ProjectServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + ProjectServiceLimitedTimeRetryPolicy( + ProjectServiceLimitedTimeRetryPolicy&& rhs) noexcept + : ProjectServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + ProjectServiceLimitedTimeRetryPolicy( + ProjectServiceLimitedTimeRetryPolicy const& rhs) noexcept + : ProjectServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = ProjectServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + bigquerycontrol_project_v2_internal::ProjectServiceRetryTraits> + impl_; +}; + +/** + * The `ProjectServiceConnection` object for `ProjectServiceClient`. + * + * This interface defines virtual methods for each of the user-facing overload + * sets in `ProjectServiceClient`. This allows users to inject custom behavior + * (e.g., with a Google Mock object) when writing tests that use objects of type + * `ProjectServiceClient`. + * + * To create a concrete instance, see `MakeProjectServiceConnection()`. + * + * For mocking, see + * `bigquerycontrol_project_v2_mocks::MockProjectServiceConnection`. + */ +class ProjectServiceConnection { + public: + virtual ~ProjectServiceConnection() = 0; + + virtual Options options() { return Options{}; } + + virtual StatusOr + GetServiceAccount( + google::cloud::bigquery::v2::GetServiceAccountRequest const& request); +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_project_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_PROJECT_CONNECTION_H diff --git a/google/cloud/bigquerycontrol/project/v2/project_connection_idempotency_policy.cc b/google/cloud/bigquerycontrol/project/v2/project_connection_idempotency_policy.cc new file mode 100644 index 0000000000000..273cb3ba84c34 --- /dev/null +++ b/google/cloud/bigquerycontrol/project/v2/project_connection_idempotency_policy.cc @@ -0,0 +1,50 @@ +// Copyright 2024 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/v2/project.proto + +#include "google/cloud/bigquerycontrol/project/v2/project_connection_idempotency_policy.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_project_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +using ::google::cloud::Idempotency; + +ProjectServiceConnectionIdempotencyPolicy:: + ~ProjectServiceConnectionIdempotencyPolicy() = default; + +std::unique_ptr +ProjectServiceConnectionIdempotencyPolicy::clone() const { + return std::make_unique(*this); +} + +Idempotency ProjectServiceConnectionIdempotencyPolicy::GetServiceAccount( + google::cloud::bigquery::v2::GetServiceAccountRequest const&) { + return Idempotency::kIdempotent; +} + +std::unique_ptr +MakeDefaultProjectServiceConnectionIdempotencyPolicy() { + return std::make_unique(); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_project_v2 +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/project/v2/project_connection_idempotency_policy.h b/google/cloud/bigquerycontrol/project/v2/project_connection_idempotency_policy.h new file mode 100644 index 0000000000000..04e8d9cc6eb7c --- /dev/null +++ b/google/cloud/bigquerycontrol/project/v2/project_connection_idempotency_policy.h @@ -0,0 +1,52 @@ +// Copyright 2024 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/v2/project.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_PROJECT_CONNECTION_IDEMPOTENCY_POLICY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_PROJECT_CONNECTION_IDEMPOTENCY_POLICY_H + +#include "google/cloud/idempotency.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_project_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class ProjectServiceConnectionIdempotencyPolicy { + public: + virtual ~ProjectServiceConnectionIdempotencyPolicy(); + + /// Create a new copy of this object. + virtual std::unique_ptr clone() + const; + + virtual google::cloud::Idempotency GetServiceAccount( + google::cloud::bigquery::v2::GetServiceAccountRequest const& request); +}; + +std::unique_ptr +MakeDefaultProjectServiceConnectionIdempotencyPolicy(); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_project_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_PROJECT_CONNECTION_IDEMPOTENCY_POLICY_H diff --git a/google/cloud/bigquerycontrol/project/v2/project_options.h b/google/cloud/bigquerycontrol/project/v2/project_options.h new file mode 100644 index 0000000000000..12bf5cab3897e --- /dev/null +++ b/google/cloud/bigquerycontrol/project/v2/project_options.h @@ -0,0 +1,76 @@ +// Copyright 2024 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/v2/project.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_PROJECT_OPTIONS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_PROJECT_OPTIONS_H + +#include "google/cloud/bigquerycontrol/project/v2/project_connection.h" +#include "google/cloud/bigquerycontrol/project/v2/project_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 bigquerycontrol_project_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * Use with `google::cloud::Options` to configure the retry policy. + * + * @ingroup google-cloud-bigquerycontrol-options + */ +struct ProjectServiceRetryPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure the backoff policy. + * + * @ingroup google-cloud-bigquerycontrol-options + */ +struct ProjectServiceBackoffPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure which operations are retried. + * + * @ingroup google-cloud-bigquerycontrol-options + */ +struct ProjectServiceConnectionIdempotencyPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * The options applicable to ProjectService. + * + * @ingroup google-cloud-bigquerycontrol-options + */ +using ProjectServicePolicyOptionList = + OptionList; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_project_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_PROJECT_OPTIONS_H diff --git a/google/cloud/bigquerycontrol/project/v2/project_rest_connection.cc b/google/cloud/bigquerycontrol/project/v2/project_rest_connection.cc new file mode 100644 index 0000000000000..9dee60d941493 --- /dev/null +++ b/google/cloud/bigquerycontrol/project/v2/project_rest_connection.cc @@ -0,0 +1,60 @@ +// Copyright 2024 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/v2/project.proto + +#include "google/cloud/bigquerycontrol/project/v2/project_rest_connection.h" +#include "google/cloud/bigquerycontrol/project/v2/internal/project_option_defaults.h" +#include "google/cloud/bigquerycontrol/project/v2/internal/project_rest_connection_impl.h" +#include "google/cloud/bigquerycontrol/project/v2/internal/project_rest_stub_factory.h" +#include "google/cloud/bigquerycontrol/project/v2/internal/project_tracing_connection.h" +#include "google/cloud/bigquerycontrol/project/v2/project_options.h" +#include "google/cloud/common_options.h" +#include "google/cloud/credentials.h" +#include "google/cloud/internal/rest_background_threads_impl.h" +#include "google/cloud/internal/rest_options.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_project_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr MakeProjectServiceConnectionRest( + Options options) { + internal::CheckExpectedOptions< + CommonOptionList, RestOptionList, UnifiedCredentialsOptionList, + rest_internal::TargetApiVersionOption, ProjectServicePolicyOptionList>( + options, __func__); + options = bigquerycontrol_project_v2_internal::ProjectServiceDefaultOptions( + std::move(options)); + auto background = std::make_unique< + rest_internal::AutomaticallyCreatedRestBackgroundThreads>(); + auto stub = + bigquerycontrol_project_v2_internal::CreateDefaultProjectServiceRestStub( + options); + return bigquerycontrol_project_v2_internal:: + MakeProjectServiceTracingConnection( + std::make_shared( + std::move(background), std::move(stub), std::move(options))); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_project_v2 +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/project/v2/project_rest_connection.h b/google/cloud/bigquerycontrol/project/v2/project_rest_connection.h new file mode 100644 index 0000000000000..334197820b6df --- /dev/null +++ b/google/cloud/bigquerycontrol/project/v2/project_rest_connection.h @@ -0,0 +1,64 @@ +// Copyright 2024 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/v2/project.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_PROJECT_REST_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_PROJECT_REST_CONNECTION_H + +#include "google/cloud/bigquerycontrol/project/v2/project_connection.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_project_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * A factory function to construct an object of type `ProjectServiceConnection` + * that uses REST over HTTP as transport in lieu of gRPC. REST transport should + * only be used for services that do not support gRPC or if the existing network + * configuration precludes using gRPC. + * + * The returned connection object should not be used directly; instead it + * should be passed as an argument to the constructor of ProjectServiceClient. + * + * The optional @p options argument may be used to configure aspects of the + * returned `ProjectServiceConnection`. Expected options are any of the types in + * the following option lists: + * + * - `google::cloud::CommonOptionList` + * - `google::cloud::RestOptionList` + * - `google::cloud::UnifiedCredentialsOptionList` + * - `google::cloud::bigquerycontrol_project_v2::ProjectServicePolicyOptionList` + * + * @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 `ProjectServiceConnection` created by + * this function. + */ +std::shared_ptr MakeProjectServiceConnectionRest( + Options options = {}); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_project_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_PROJECT_V2_PROJECT_REST_CONNECTION_H diff --git a/google/cloud/bigquerycontrol/project/v2/samples/project_client_samples.cc b/google/cloud/bigquerycontrol/project/v2/samples/project_client_samples.cc new file mode 100644 index 0000000000000..5bb3cfec1fa4d --- /dev/null +++ b/google/cloud/bigquerycontrol/project/v2/samples/project_client_samples.cc @@ -0,0 +1,163 @@ +// Copyright 2024 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/v2/project.proto + +#include "google/cloud/bigquerycontrol/project/v2/project_client.h" +#include "google/cloud/bigquerycontrol/project/v2/project_connection_idempotency_policy.h" +#include "google/cloud/bigquerycontrol/project/v2/project_options.h" +#include "google/cloud/common_options.h" +#include "google/cloud/credentials.h" +#include "google/cloud/internal/getenv.h" +#include "google/cloud/testing_util/example_driver.h" +#include +#include +#include +#include + +// clang-format off +// main-dox-marker: bigquerycontrol_project_v2::ProjectServiceClient +// clang-format on +namespace { + +void SetClientEndpoint(std::vector const& argv) { + if (!argv.empty()) { + throw google::cloud::testing_util::Usage{"set-client-endpoint"}; + } + //! [set-client-endpoint] + // This configuration is common with Private Google Access: + // https://cloud.google.com/vpc/docs/private-google-access + auto options = google::cloud::Options{}.set( + "private.googleapis.com"); + auto client = google::cloud::bigquerycontrol_project_v2::ProjectServiceClient( + google::cloud::bigquerycontrol_project_v2:: + MakeProjectServiceConnectionRest(options)); + //! [set-client-endpoint] +} + +//! [custom-idempotency-policy] +class CustomIdempotencyPolicy + : public google::cloud::bigquerycontrol_project_v2:: + ProjectServiceConnectionIdempotencyPolicy { + public: + ~CustomIdempotencyPolicy() override = default; + std::unique_ptr + clone() const override { + return std::make_unique(*this); + } + // Override inherited functions to define as needed. +}; +//! [custom-idempotency-policy] + +void SetRetryPolicy(std::vector const& argv) { + if (!argv.empty()) { + throw google::cloud::testing_util::Usage{"set-client-retry-policy"}; + } + //! [set-retry-policy] + auto options = google::cloud::Options{} + .set( + CustomIdempotencyPolicy().clone()) + .set( + google::cloud::bigquerycontrol_project_v2:: + ProjectServiceLimitedErrorCountRetryPolicy(3) + .clone()) + .set( + google::cloud::ExponentialBackoffPolicy( + /*initial_delay=*/std::chrono::milliseconds(200), + /*maximum_delay=*/std::chrono::seconds(45), + /*scaling=*/2.0) + .clone()); + auto connection = google::cloud::bigquerycontrol_project_v2:: + MakeProjectServiceConnectionRest(options); + + // c1 and c2 share the same retry policies + auto c1 = google::cloud::bigquerycontrol_project_v2::ProjectServiceClient( + connection); + auto c2 = google::cloud::bigquerycontrol_project_v2::ProjectServiceClient( + connection); + + // You can override any of the policies in a new client. This new client + // will share the policies from c1 (or c2) *except* for the retry policy. + auto c3 = google::cloud::bigquerycontrol_project_v2::ProjectServiceClient( + connection, + google::cloud::Options{} + .set( + google::cloud::bigquerycontrol_project_v2:: + ProjectServiceLimitedTimeRetryPolicy(std::chrono::minutes(5)) + .clone())); + + // You can also override the policies in a single call: + // c3.SomeRpc(..., google::cloud::Options{} + // .set( + // google::cloud::bigquerycontrol_project_v2::ProjectServiceLimitedErrorCountRetryPolicy(10).clone())); + //! [set-retry-policy] +} + +void WithServiceAccount(std::vector const& argv) { + if (argv.size() != 1 || argv[0] == "--help") { + throw google::cloud::testing_util::Usage{"with-service-account "}; + } + //! [with-service-account] + [](std::string const& keyfile) { + auto is = std::ifstream(keyfile); + is.exceptions(std::ios::badbit); // Minimal error handling in examples + auto contents = std::string(std::istreambuf_iterator(is.rdbuf()), {}); + auto options = + google::cloud::Options{}.set( + google::cloud::MakeServiceAccountCredentials(contents)); + return google::cloud::bigquerycontrol_project_v2::ProjectServiceClient( + google::cloud::bigquerycontrol_project_v2:: + MakeProjectServiceConnectionRest(options)); + } + //! [with-service-account] + (argv.at(0)); +} + +void AutoRun(std::vector const& argv) { + namespace examples = ::google::cloud::testing_util; + using ::google::cloud::internal::GetEnv; + if (!argv.empty()) throw examples::Usage{"auto"}; + examples::CheckEnvironmentVariablesAreSet( + {"GOOGLE_CLOUD_CPP_TEST_SERVICE_ACCOUNT_KEYFILE"}); + auto const keyfile = + GetEnv("GOOGLE_CLOUD_CPP_TEST_SERVICE_ACCOUNT_KEYFILE").value(); + + std::cout << "\nRunning SetClientEndpoint() example" << std::endl; + SetClientEndpoint({}); + + std::cout << "\nRunning SetRetryPolicy() example" << std::endl; + SetRetryPolicy({}); + + std::cout << "\nRunning WithServiceAccount() example" << std::endl; + WithServiceAccount({keyfile}); +} + +} // namespace + +int main(int argc, char* argv[]) { // NOLINT(bugprone-exception-escape) + google::cloud::testing_util::Example example({ + {"set-client-endpoint", SetClientEndpoint}, + {"set-retry-policy", SetRetryPolicy}, + {"with-service-account", WithServiceAccount}, + {"auto", AutoRun}, + }); + return example.Run(argc, argv); +} diff --git a/google/cloud/bigquerycontrol/quickstart/.bazelrc b/google/cloud/bigquerycontrol/quickstart/.bazelrc new file mode 100644 index 0000000000000..e676fbffccb52 --- /dev/null +++ b/google/cloud/bigquerycontrol/quickstart/.bazelrc @@ -0,0 +1,30 @@ +# Copyright 2024 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. + +# Use host-OS-specific config lines from bazelrc files. +build --enable_platform_specific_config=true + +# The project requires C++ >= 14. By default Bazel adds `-std=c++0x` which +# disables C++14 features, even if the compilers defaults to C++ >= 14 +build:linux --cxxopt=-std=c++14 +build:macos --cxxopt=-std=c++14 +# Protobuf and gRPC require (or soon will require) C++14 to compile the "host" +# targets, such as protoc and the grpc plugin. +build:linux --host_cxxopt=-std=c++14 +build:macos --host_cxxopt=-std=c++14 + +# Do not create the convenience links. They are inconvenient when the build +# runs inside a docker image or if one builds a quickstart and then builds +# the project separately. +build --experimental_convenience_symlinks=ignore diff --git a/google/cloud/bigquerycontrol/quickstart/BUILD.bazel b/google/cloud/bigquerycontrol/quickstart/BUILD.bazel new file mode 100644 index 0000000000000..09a9089349550 --- /dev/null +++ b/google/cloud/bigquerycontrol/quickstart/BUILD.bazel @@ -0,0 +1,25 @@ +# Copyright 2024 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. + +licenses(["notice"]) # Apache 2.0 + +cc_binary( + name = "quickstart", + srcs = [ + "quickstart.cc", + ], + deps = [ + "@google_cloud_cpp//:experimental-bigquerycontrol", + ], +) diff --git a/google/cloud/bigquerycontrol/quickstart/CMakeLists.txt b/google/cloud/bigquerycontrol/quickstart/CMakeLists.txt new file mode 100644 index 0000000000000..d30cca8999bbe --- /dev/null +++ b/google/cloud/bigquerycontrol/quickstart/CMakeLists.txt @@ -0,0 +1,32 @@ +# Copyright 2024 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. + +# This file shows how to use the BigQuery API C++ client library from a larger +# CMake project. + +cmake_minimum_required(VERSION 3.10...3.24) +project(google-cloud-cpp-bigquerycontrol-quickstart CXX) + +find_package(google_cloud_cpp_bigquerycontrol REQUIRED) + +# MSVC requires some additional code to select the correct runtime library +if (VCPKG_TARGET_TRIPLET MATCHES "-static$") + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") +else () + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") +endif () + +# Define your targets. +add_executable(quickstart quickstart.cc) +target_link_libraries(quickstart google-cloud-cpp::experimental-bigquerycontrol) diff --git a/google/cloud/bigquerycontrol/quickstart/Makefile b/google/cloud/bigquerycontrol/quickstart/Makefile new file mode 100644 index 0000000000000..ea9907a781256 --- /dev/null +++ b/google/cloud/bigquerycontrol/quickstart/Makefile @@ -0,0 +1,35 @@ +# Copyright 2024 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. + +# This is a minimal Makefile to show how to use the BigQuery API C++ client +# for developers who use make(1) as their build system. + +# The CXX, CXXFLAGS and CXXLD variables are hard-coded. These values work for +# our tests, but applications would typically make them configurable parameters. +CXX=g++ +CXXFLAGS= +CXXLD=$(CXX) +BIN=. + +all: $(BIN)/quickstart + +# Configuration variables to compile and link against the BigQuery API C++ +# client library. +CLIENT_MODULE := google_cloud_cpp_bigquerycontrol +CLIENT_CXXFLAGS := $(shell pkg-config $(CLIENT_MODULE) --cflags) +CLIENT_CXXLDFLAGS := $(shell pkg-config $(CLIENT_MODULE) --libs-only-L) +CLIENT_LIBS := $(shell pkg-config $(CLIENT_MODULE) --libs-only-l) + +$(BIN)/quickstart: quickstart.cc + $(CXXLD) $(CXXFLAGS) $(CLIENT_CXXFLAGS) $(CLIENT_CXXLDFLAGS) -o $@ $^ $(CLIENT_LIBS) diff --git a/google/cloud/bigquerycontrol/quickstart/README.md b/google/cloud/bigquerycontrol/quickstart/README.md new file mode 100644 index 0000000000000..c8255d277b343 --- /dev/null +++ b/google/cloud/bigquerycontrol/quickstart/README.md @@ -0,0 +1,154 @@ +# HOWTO: using the BigQuery API C++ client in your project + +This directory contains small examples showing how to use the BigQuery API C++ +client library in your own project. These instructions assume that you have some +experience as a C++ developer and that you have a working C++ toolchain +(compiler, linker, etc.) installed on your platform. + +- Packaging maintainers or developers who prefer to install the library in a + fixed directory (such as `/usr/local` or `/opt`) should consult the + [packaging guide](/doc/packaging.md). +- Developers who prefer using a package manager such as + [vcpkg](https://vcpkg.io), or [Conda](https://conda.io), should follow the + instructions for their package manager. +- Developers wanting to use the libraries as part of a larger CMake or Bazel + project should consult the current document. Note that there are similar + documents for each library in their corresponding directories. +- Developers wanting to compile the library just to run some examples or tests + should consult the + [building and installing](/README.md#building-and-installing) section of the + top-level README file. +- Contributors and developers to `google-cloud-cpp` should consult the guide to + [set up a development workstation][howto-setup-dev-workstation]. + +## Before you begin + +To run the quickstart examples you will need a working Google Cloud Platform +(GCP) project. The [quickstart][quickstart-link] covers the necessary steps in +detail. + +## Configuring authentication for the C++ Client Library + +Like most Google Cloud Platform (GCP) services, BigQuery API requires that your +application authenticates with the service before accessing any data. If you are +not familiar with GCP authentication please take this opportunity to review the +[Authentication Overview][authentication-quickstart]. This library uses the +`GOOGLE_APPLICATION_CREDENTIALS` environment variable to find the credentials +file. For example: + +| Shell | Command | +| :----------------- | ------------------------------------------------------------------------------------ | +| Bash/zsh/ksh/etc. | `export GOOGLE_APPLICATION_CREDENTIALS=[PATH]` | +| sh | `GOOGLE_APPLICATION_CREDENTIALS=[PATH];`
`export GOOGLE_APPLICATION_CREDENTIALS` | +| csh/tsch | `setenv GOOGLE_APPLICATION_CREDENTIALS [PATH]` | +| Windows Powershell | `$env:GOOGLE_APPLICATION_CREDENTIALS=[PATH]` | +| Windows cmd.exe | `set GOOGLE_APPLICATION_CREDENTIALS=[PATH]` | + +Setting this environment variable is the recommended way to configure the +authentication preferences, though if the environment variable is not set, the +library searches for a credentials file in the same location as the +[Cloud SDK](https://cloud.google.com/sdk/). For more information about +*Application Default Credentials*, see +https://cloud.google.com/docs/authentication/production + +## Using with Bazel + +> :warning: If you are using Windows or macOS there are additional instructions +> at the end of this document. + +1. Install Bazel using [the instructions][bazel-install] from the `bazel.build` + website. + +1. Compile this example using Bazel: + + ```bash + cd $HOME/google-cloud-cpp/google/cloud/bigquerycontrol/quickstart + bazel build ... + ``` + + Note that Bazel automatically downloads and compiles all dependencies of the + project. As it is often the case with C++ libraries, compiling these + dependencies may take several minutes. + +1. Run the example, changing the placeholder(s) to appropriate values: + + ```bash + bazel run :quickstart -- [...] + ``` + +## Using with CMake + +> :warning: If you are using Windows or macOS there are additional instructions +> at the end of this document. + +1. Install CMake. The package managers for most Linux distributions include a + package for CMake. Likewise, you can install CMake on Windows using a package + manager such as [chocolatey][choco-cmake-link], and on macOS using + [homebrew][homebrew-cmake-link]. You can also obtain the software directly + from the [cmake.org](https://cmake.org/download/). + +1. Install the dependencies with your favorite tools. As an example, if you use + [vcpkg](https://github.com/Microsoft/vcpkg.git): + + ```bash + cd $HOME/vcpkg + ./vcpkg install google-cloud-cpp[core,bigquerycontrol] + ``` + + Note that, as it is often the case with C++ libraries, compiling these + dependencies may take several minutes. + +1. Configure CMake, if necessary, configure the directory where you installed + the dependencies: + + ```bash + cd $HOME/google-cloud-cpp/google/cloud/bigquerycontrol/quickstart + cmake -S . -B .build -DCMAKE_TOOLCHAIN_FILE=$HOME/vcpkg/scripts/buildsystems/vcpkg.cmake + cmake --build .build + ``` + +1. Run the example, changing the placeholder(s) to appropriate values: + + ```bash + .build/quickstart [...] + ``` + +## Platform Specific Notes + +### macOS + +gRPC [requires][grpc-roots-pem-bug] an environment variable to configure the +trust store for SSL certificates, you can download and configure this using: + +```bash +curl -Lo roots.pem https://pki.google.com/roots.pem +export GRPC_DEFAULT_SSL_ROOTS_FILE_PATH="$PWD/roots.pem" +``` + +### Windows + +Bazel tends to create very long file names and paths. You may need to use a +short directory to store the build output, such as `c:\b`, and instruct Bazel to +use it via: + +```shell +bazel --output_user_root=c:\b build ... +``` + +gRPC [requires][grpc-roots-pem-bug] an environment variable to configure the +trust store for SSL certificates, you can download and configure this using: + +```console +@powershell -NoProfile -ExecutionPolicy unrestricted -Command ^ + (new-object System.Net.WebClient).Downloadfile( ^ + 'https://pki.google.com/roots.pem', 'roots.pem') +set GRPC_DEFAULT_SSL_ROOTS_FILE_PATH=%cd%\roots.pem +``` + +[authentication-quickstart]: https://cloud.google.com/docs/authentication/getting-started "Authentication Getting Started" +[bazel-install]: https://docs.bazel.build/versions/main/install.html +[choco-cmake-link]: https://chocolatey.org/packages/cmake +[grpc-roots-pem-bug]: https://github.com/grpc/grpc/issues/16571 +[homebrew-cmake-link]: https://formulae.brew.sh/formula/cmake +[howto-setup-dev-workstation]: /doc/contributor/howto-guide-setup-development-workstation.md +[quickstart-link]: https://cloud.google.com/bigquerycontrol/docs/quickstart diff --git a/google/cloud/bigquerycontrol/quickstart/WORKSPACE.bazel b/google/cloud/bigquerycontrol/quickstart/WORKSPACE.bazel new file mode 100644 index 0000000000000..84b5eeb39151f --- /dev/null +++ b/google/cloud/bigquerycontrol/quickstart/WORKSPACE.bazel @@ -0,0 +1,53 @@ +# Copyright 2024 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. + +# A minimal WORKSPACE file showing how to use the BigQuery API +# C++ client library in Bazel-based projects. +workspace(name = "qs") + +# Add the necessary Starlark functions to fetch google-cloud-cpp. +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +# Fetch the Google Cloud C++ libraries. +# NOTE: Update this version and SHA256 as needed. +http_archive( + name = "google_cloud_cpp", + sha256 = "91cd0552c68d85c0c07f9500771367034ea78f6814603275dcf8664472f8f37f", + strip_prefix = "google-cloud-cpp-2.26.0", + url = "https://github.com/googleapis/google-cloud-cpp/archive/v2.26.0.tar.gz", +) + +load("@google_cloud_cpp//bazel:workspace0.bzl", "gl_cpp_workspace0") + +gl_cpp_workspace0() + +load("@google_cloud_cpp//bazel:workspace1.bzl", "gl_cpp_workspace1") + +gl_cpp_workspace1() + +load("@google_cloud_cpp//bazel:workspace2.bzl", "gl_cpp_workspace2") + +gl_cpp_workspace2() + +load("@google_cloud_cpp//bazel:workspace3.bzl", "gl_cpp_workspace3") + +gl_cpp_workspace3() + +load("@google_cloud_cpp//bazel:workspace4.bzl", "gl_cpp_workspace4") + +gl_cpp_workspace4() + +load("@google_cloud_cpp//bazel:workspace5.bzl", "gl_cpp_workspace5") + +gl_cpp_workspace5() diff --git a/google/cloud/bigquerycontrol/quickstart/quickstart.cc b/google/cloud/bigquerycontrol/quickstart/quickstart.cc new file mode 100644 index 0000000000000..9f180474db7a5 --- /dev/null +++ b/google/cloud/bigquerycontrol/quickstart/quickstart.cc @@ -0,0 +1,42 @@ +// Copyright 2024 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. + +//! [all] +#include "google/cloud/bigquerycontrol/table/v2/ EDIT HERE _client.h" +#include "google/cloud/location.h" +#include + +int main(int argc, char* argv[]) try { + if (argc != 3) { + std::cerr << "Usage: " << argv[0] << " project-id location-id\n"; + return 1; + } + + auto const location = google::cloud::Location(argv[1], argv[2]); + + namespace bigquerycontrol = ::google::cloud::bigquerycontrol_table_v2; + auto client = bigquerycontrol::ServiceClient( + bigquerycontrol::MakeServiceConnection()); // EDIT HERE + + for (auto r : client.List /*EDIT HERE*/ (location.FullName())) { + if (!r) throw std::move(r).status(); + std::cout << r->DebugString() << "\n"; + } + + return 0; +} catch (google::cloud::Status const& status) { + std::cerr << "google::cloud::Status thrown: " << status << "\n"; + return 1; +} +//! [all] diff --git a/google/cloud/bigquerycontrol/routine/v2/internal/routine_option_defaults.cc b/google/cloud/bigquerycontrol/routine/v2/internal/routine_option_defaults.cc new file mode 100644 index 0000000000000..004f7baf23b00 --- /dev/null +++ b/google/cloud/bigquerycontrol/routine/v2/internal/routine_option_defaults.cc @@ -0,0 +1,70 @@ +// Copyright 2024 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/v2/routine.proto + +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_option_defaults.h" +#include "google/cloud/bigquerycontrol/routine/v2/routine_connection.h" +#include "google/cloud/bigquerycontrol/routine/v2/routine_options.h" +#include "google/cloud/internal/populate_common_options.h" +#include "google/cloud/internal/populate_grpc_options.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_routine_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +namespace { +auto constexpr kBackoffScaling = 2.0; +} // namespace + +Options RoutineServiceDefaultOptions(Options options) { + options = internal::PopulateCommonOptions( + std::move(options), "GOOGLE_CLOUD_CPP_ROUTINE_SERVICE_ENDPOINT", "", + "GOOGLE_CLOUD_CPP_ROUTINE_SERVICE_AUTHORITY", "bigquery.googleapis.com"); + options = internal::PopulateGrpcOptions(std::move(options)); + if (!options.has< + bigquerycontrol_routine_v2::RoutineServiceRetryPolicyOption>()) { + options.set( + bigquerycontrol_routine_v2::RoutineServiceLimitedTimeRetryPolicy( + std::chrono::minutes(30)) + .clone()); + } + if (!options.has< + bigquerycontrol_routine_v2::RoutineServiceBackoffPolicyOption>()) { + options.set( + ExponentialBackoffPolicy( + std::chrono::seconds(0), std::chrono::seconds(1), + std::chrono::minutes(5), kBackoffScaling, kBackoffScaling) + .clone()); + } + if (!options.has()) { + options.set( + bigquerycontrol_routine_v2:: + MakeDefaultRoutineServiceConnectionIdempotencyPolicy()); + } + + return options; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_routine_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/routine/v2/internal/routine_option_defaults.h b/google/cloud/bigquerycontrol/routine/v2/internal/routine_option_defaults.h new file mode 100644 index 0000000000000..2947810695f4f --- /dev/null +++ b/google/cloud/bigquerycontrol/routine/v2/internal/routine_option_defaults.h @@ -0,0 +1,37 @@ +// Copyright 2024 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/v2/routine.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_INTERNAL_ROUTINE_OPTION_DEFAULTS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_INTERNAL_ROUTINE_OPTION_DEFAULTS_H + +#include "google/cloud/options.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace bigquerycontrol_routine_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +Options RoutineServiceDefaultOptions(Options options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_routine_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_INTERNAL_ROUTINE_OPTION_DEFAULTS_H diff --git a/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_connection_impl.cc b/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_connection_impl.cc new file mode 100644 index 0000000000000..1321d7969e6ec --- /dev/null +++ b/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_connection_impl.cc @@ -0,0 +1,115 @@ +// Copyright 2024 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/v2/routine.proto + +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_connection_impl.h" +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_stub_factory.h" +#include "google/cloud/common_options.h" +#include "google/cloud/credentials.h" +#include "google/cloud/internal/rest_retry_loop.h" +#include "google/cloud/rest_options.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_routine_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +RoutineServiceRestConnectionImpl::RoutineServiceRestConnectionImpl( + std::unique_ptr background, + std::shared_ptr + stub, + Options options) + : background_(std::move(background)), + stub_(std::move(stub)), + options_(internal::MergeOptions(std::move(options), + RoutineServiceConnection::options())) {} + +StatusOr +RoutineServiceRestConnectionImpl::GetRoutine( + google::cloud::bigquery::v2::GetRoutineRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::rest_internal::RestRetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->GetRoutine(request), + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::GetRoutineRequest const& request) { + return stub_->GetRoutine(rest_context, options, request); + }, + *current, request, __func__); +} + +StatusOr +RoutineServiceRestConnectionImpl::InsertRoutine( + google::cloud::bigquery::v2::InsertRoutineRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::rest_internal::RestRetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->InsertRoutine(request), + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::InsertRoutineRequest const& request) { + return stub_->InsertRoutine(rest_context, options, request); + }, + *current, request, __func__); +} + +StatusOr +RoutineServiceRestConnectionImpl::UpdateRoutine( + google::cloud::bigquery::v2::UpdateRoutineRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::rest_internal::RestRetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->UpdateRoutine(request), + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::UpdateRoutineRequest const& request) { + return stub_->UpdateRoutine(rest_context, options, request); + }, + *current, request, __func__); +} + +Status RoutineServiceRestConnectionImpl::DeleteRoutine( + google::cloud::bigquery::v2::DeleteRoutineRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::rest_internal::RestRetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->DeleteRoutine(request), + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::DeleteRoutineRequest const& request) { + return stub_->DeleteRoutine(rest_context, options, request); + }, + *current, request, __func__); +} + +StatusOr +RoutineServiceRestConnectionImpl::ListRoutines( + google::cloud::bigquery::v2::ListRoutinesRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::rest_internal::RestRetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->ListRoutines(request), + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::ListRoutinesRequest const& request) { + return stub_->ListRoutines(rest_context, options, request); + }, + *current, request, __func__); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_routine_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_connection_impl.h b/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_connection_impl.h new file mode 100644 index 0000000000000..8d7f6419e2abf --- /dev/null +++ b/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_connection_impl.h @@ -0,0 +1,104 @@ +// Copyright 2024 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/v2/routine.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_INTERNAL_ROUTINE_REST_CONNECTION_IMPL_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_INTERNAL_ROUTINE_REST_CONNECTION_IMPL_H + +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_stub.h" +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_retry_traits.h" +#include "google/cloud/bigquerycontrol/routine/v2/routine_connection.h" +#include "google/cloud/bigquerycontrol/routine/v2/routine_connection_idempotency_policy.h" +#include "google/cloud/bigquerycontrol/routine/v2/routine_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/version.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_routine_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class RoutineServiceRestConnectionImpl + : public bigquerycontrol_routine_v2::RoutineServiceConnection { + public: + ~RoutineServiceRestConnectionImpl() override = default; + + RoutineServiceRestConnectionImpl( + std::unique_ptr background, + std::shared_ptr< + bigquerycontrol_routine_v2_internal::RoutineServiceRestStub> + stub, + Options options); + + Options options() override { return options_; } + + StatusOr GetRoutine( + google::cloud::bigquery::v2::GetRoutineRequest const& request) override; + + StatusOr InsertRoutine( + google::cloud::bigquery::v2::InsertRoutineRequest const& request) + override; + + StatusOr UpdateRoutine( + google::cloud::bigquery::v2::UpdateRoutineRequest const& request) + override; + + Status DeleteRoutine(google::cloud::bigquery::v2::DeleteRoutineRequest const& + request) override; + + StatusOr ListRoutines( + google::cloud::bigquery::v2::ListRoutinesRequest const& request) override; + + private: + static std::unique_ptr + retry_policy(Options const& options) { + return options + .get() + ->clone(); + } + + static std::unique_ptr backoff_policy(Options const& options) { + return options + .get() + ->clone(); + } + + static std::unique_ptr< + bigquerycontrol_routine_v2::RoutineServiceConnectionIdempotencyPolicy> + idempotency_policy(Options const& options) { + return options + .get() + ->clone(); + } + + std::unique_ptr background_; + std::shared_ptr + stub_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_routine_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_INTERNAL_ROUTINE_REST_CONNECTION_IMPL_H diff --git a/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_logging_decorator.cc b/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_logging_decorator.cc new file mode 100644 index 0000000000000..510eb3928ac5d --- /dev/null +++ b/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_logging_decorator.cc @@ -0,0 +1,99 @@ +// Copyright 2024 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/v2/routine.proto + +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_logging_decorator.h" +#include "google/cloud/internal/log_wrapper.h" +#include "google/cloud/status_or.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_routine_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +RoutineServiceRestLogging::RoutineServiceRestLogging( + 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 +RoutineServiceRestLogging::GetRoutine( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::GetRoutineRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::GetRoutineRequest const& request) { + return child_->GetRoutine(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +StatusOr +RoutineServiceRestLogging::InsertRoutine( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::InsertRoutineRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::InsertRoutineRequest const& request) { + return child_->InsertRoutine(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +StatusOr +RoutineServiceRestLogging::UpdateRoutine( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::UpdateRoutineRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::UpdateRoutineRequest const& request) { + return child_->UpdateRoutine(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +Status RoutineServiceRestLogging::DeleteRoutine( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::DeleteRoutineRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::DeleteRoutineRequest const& request) { + return child_->DeleteRoutine(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +StatusOr +RoutineServiceRestLogging::ListRoutines( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::ListRoutinesRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::ListRoutinesRequest const& request) { + return child_->ListRoutines(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_routine_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_logging_decorator.h b/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_logging_decorator.h new file mode 100644 index 0000000000000..66f8d2fb6875d --- /dev/null +++ b/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_logging_decorator.h @@ -0,0 +1,82 @@ +// Copyright 2024 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/v2/routine.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_INTERNAL_ROUTINE_REST_LOGGING_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_INTERNAL_ROUTINE_REST_LOGGING_DECORATOR_H + +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_stub.h" +#include "google/cloud/future.h" +#include "google/cloud/internal/rest_context.h" +#include "google/cloud/tracing_options.h" +#include "google/cloud/version.h" +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_routine_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class RoutineServiceRestLogging : public RoutineServiceRestStub { + public: + ~RoutineServiceRestLogging() override = default; + RoutineServiceRestLogging(std::shared_ptr child, + TracingOptions tracing_options, + std::set components); + + StatusOr GetRoutine( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetRoutineRequest const& request) override; + + StatusOr InsertRoutine( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::InsertRoutineRequest const& request) + override; + + StatusOr UpdateRoutine( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UpdateRoutineRequest const& request) + override; + + Status DeleteRoutine(google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::DeleteRoutineRequest const& + request) override; + + StatusOr ListRoutines( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListRoutinesRequest const& request) override; + + private: + std::shared_ptr child_; + TracingOptions tracing_options_; + std::set components_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_routine_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_INTERNAL_ROUTINE_REST_LOGGING_DECORATOR_H diff --git a/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_metadata_decorator.cc b/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_metadata_decorator.cc new file mode 100644 index 0000000000000..0695f39df85dc --- /dev/null +++ b/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_metadata_decorator.cc @@ -0,0 +1,91 @@ +// Copyright 2024 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/v2/routine.proto + +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_metadata_decorator.h" +#include "google/cloud/internal/absl_str_cat_quiet.h" +#include "google/cloud/internal/api_client_header.h" +#include "google/cloud/internal/rest_set_metadata.h" +#include "google/cloud/status_or.h" +#include "absl/strings/str_format.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_routine_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +RoutineServiceRestMetadata::RoutineServiceRestMetadata( + std::shared_ptr child, + std::string api_client_header) + : child_(std::move(child)), + api_client_header_( + api_client_header.empty() + ? google::cloud::internal::GeneratedLibClientHeader() + : std::move(api_client_header)) {} + +StatusOr +RoutineServiceRestMetadata::GetRoutine( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::GetRoutineRequest const& request) { + SetMetadata(rest_context, options); + return child_->GetRoutine(rest_context, options, request); +} + +StatusOr +RoutineServiceRestMetadata::InsertRoutine( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::InsertRoutineRequest const& request) { + SetMetadata(rest_context, options); + return child_->InsertRoutine(rest_context, options, request); +} + +StatusOr +RoutineServiceRestMetadata::UpdateRoutine( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::UpdateRoutineRequest const& request) { + SetMetadata(rest_context, options); + return child_->UpdateRoutine(rest_context, options, request); +} + +Status RoutineServiceRestMetadata::DeleteRoutine( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::DeleteRoutineRequest const& request) { + SetMetadata(rest_context, options); + return child_->DeleteRoutine(rest_context, options, request); +} + +StatusOr +RoutineServiceRestMetadata::ListRoutines( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::ListRoutinesRequest const& request) { + SetMetadata(rest_context, options); + return child_->ListRoutines(rest_context, options, request); +} + +void RoutineServiceRestMetadata::SetMetadata( + rest_internal::RestContext& rest_context, Options const& options, + std::vector const& params) { + google::cloud::rest_internal::SetMetadata(rest_context, options, params, + api_client_header_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_routine_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_metadata_decorator.h b/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_metadata_decorator.h new file mode 100644 index 0000000000000..3c164c987d8cb --- /dev/null +++ b/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_metadata_decorator.h @@ -0,0 +1,83 @@ +// Copyright 2024 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/v2/routine.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_INTERNAL_ROUTINE_REST_METADATA_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_INTERNAL_ROUTINE_REST_METADATA_DECORATOR_H + +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_stub.h" +#include "google/cloud/future.h" +#include "google/cloud/rest_options.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_routine_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class RoutineServiceRestMetadata : public RoutineServiceRestStub { + public: + ~RoutineServiceRestMetadata() override = default; + explicit RoutineServiceRestMetadata( + std::shared_ptr child, + std::string api_client_header = ""); + + StatusOr GetRoutine( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetRoutineRequest const& request) override; + + StatusOr InsertRoutine( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::InsertRoutineRequest const& request) + override; + + StatusOr UpdateRoutine( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UpdateRoutineRequest const& request) + override; + + Status DeleteRoutine(google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::DeleteRoutineRequest const& + request) override; + + StatusOr ListRoutines( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListRoutinesRequest const& request) override; + + private: + void SetMetadata(rest_internal::RestContext& rest_context, + Options const& options, + std::vector const& params = {}); + + std::shared_ptr child_; + std::string api_client_header_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_routine_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_INTERNAL_ROUTINE_REST_METADATA_DECORATOR_H diff --git a/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_stub.cc b/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_stub.cc new file mode 100644 index 0000000000000..ac1061ccb975b --- /dev/null +++ b/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_stub.cc @@ -0,0 +1,115 @@ +// Copyright 2024 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/v2/routine.proto + +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_stub.h" +#include "google/cloud/common_options.h" +#include "google/cloud/internal/absl_str_cat_quiet.h" +#include "google/cloud/internal/rest_stub_helpers.h" +#include "google/cloud/status_or.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_routine_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +DefaultRoutineServiceRestStub::DefaultRoutineServiceRestStub(Options options) + : service_(rest_internal::MakePooledRestClient( + options.get(), options)), + options_(std::move(options)) {} + +DefaultRoutineServiceRestStub::DefaultRoutineServiceRestStub( + std::shared_ptr service, Options options) + : service_(std::move(service)), options_(std::move(options)) {} + +StatusOr +DefaultRoutineServiceRestStub::GetRoutine( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetRoutineRequest const& request) { + return rest_internal::Get( + *service_, rest_context, request, false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "datasets", "/", + request.dataset_id(), "/", "routines", "/", + request.routine_id())); +} + +StatusOr +DefaultRoutineServiceRestStub::InsertRoutine( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::InsertRoutineRequest const& request) { + return rest_internal::Post( + *service_, rest_context, request.routine(), false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "datasets", "/", + request.dataset_id(), "/", "routines")); +} + +StatusOr +DefaultRoutineServiceRestStub::UpdateRoutine( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UpdateRoutineRequest const& request) { + return rest_internal::Put( + *service_, rest_context, request.routine(), false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "datasets", "/", + request.dataset_id(), "/", "routines", "/", + request.routine_id())); +} + +Status DefaultRoutineServiceRestStub::DeleteRoutine( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::DeleteRoutineRequest const& request) { + return rest_internal::Delete( + *service_, rest_context, request, false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "datasets", "/", + request.dataset_id(), "/", "routines", "/", + request.routine_id())); +} + +StatusOr +DefaultRoutineServiceRestStub::ListRoutines( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListRoutinesRequest const& request) { + return rest_internal::Get( + *service_, rest_context, request, false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "datasets", "/", + request.dataset_id(), "/", "routines"), + rest_internal::TrimEmptyQueryParameters( + {std::make_pair("page_token", request.page_token()), + std::make_pair("filter", request.filter())})); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_routine_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_stub.h b/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_stub.h new file mode 100644 index 0000000000000..36433608eb726 --- /dev/null +++ b/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_stub.h @@ -0,0 +1,111 @@ +// Copyright 2024 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/v2/routine.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_INTERNAL_ROUTINE_REST_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_INTERNAL_ROUTINE_REST_STUB_H + +#include "google/cloud/completion_queue.h" +#include "google/cloud/internal/rest_client.h" +#include "google/cloud/internal/rest_context.h" +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_routine_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class RoutineServiceRestStub { + public: + virtual ~RoutineServiceRestStub() = default; + + virtual StatusOr GetRoutine( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetRoutineRequest const& request) = 0; + + virtual StatusOr InsertRoutine( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::InsertRoutineRequest const& request) = 0; + + virtual StatusOr UpdateRoutine( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UpdateRoutineRequest const& request) = 0; + + virtual Status DeleteRoutine( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::DeleteRoutineRequest const& request) = 0; + + virtual StatusOr + ListRoutines( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListRoutinesRequest const& request) = 0; +}; + +class DefaultRoutineServiceRestStub : public RoutineServiceRestStub { + public: + ~DefaultRoutineServiceRestStub() override = default; + + explicit DefaultRoutineServiceRestStub(Options options); + DefaultRoutineServiceRestStub( + std::shared_ptr service, Options options); + + StatusOr GetRoutine( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetRoutineRequest const& request) override; + + StatusOr InsertRoutine( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::InsertRoutineRequest const& request) + override; + + StatusOr UpdateRoutine( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UpdateRoutineRequest const& request) + override; + + Status DeleteRoutine(google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::DeleteRoutineRequest const& + request) override; + + StatusOr ListRoutines( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListRoutinesRequest const& request) override; + + private: + std::shared_ptr service_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_routine_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_INTERNAL_ROUTINE_REST_STUB_H diff --git a/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_stub_factory.cc b/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_stub_factory.cc new file mode 100644 index 0000000000000..5bdf0289cc00d --- /dev/null +++ b/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_stub_factory.cc @@ -0,0 +1,56 @@ +// Copyright 2024 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/v2/routine.proto + +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_stub_factory.h" +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_logging_decorator.h" +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_metadata_decorator.h" +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_stub.h" +#include "google/cloud/common_options.h" +#include "google/cloud/internal/algorithm.h" +#include "google/cloud/internal/populate_rest_options.h" +#include "google/cloud/log.h" +#include "google/cloud/options.h" +#include "google/cloud/rest_options.h" +#include "absl/strings/match.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_routine_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultRoutineServiceRestStub( + Options const& options) { + auto opts = internal::PopulateRestOptions(options); + std::shared_ptr stub = + std::make_shared(std::move(opts)); + stub = std::make_shared(std::move(stub)); + if (internal::Contains(options.get(), "rpc")) { + GCP_LOG(INFO) << "Enabled logging for REST rpc calls"; + stub = std::make_shared( + std::move(stub), options.get(), + options.get()); + } + return stub; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_routine_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_stub_factory.h b/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_stub_factory.h new file mode 100644 index 0000000000000..478bf3c65b16b --- /dev/null +++ b/google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_stub_factory.h @@ -0,0 +1,40 @@ +// Copyright 2024 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/v2/routine.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_INTERNAL_ROUTINE_REST_STUB_FACTORY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_INTERNAL_ROUTINE_REST_STUB_FACTORY_H + +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_stub.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_routine_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultRoutineServiceRestStub( + Options const& options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_routine_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_INTERNAL_ROUTINE_REST_STUB_FACTORY_H diff --git a/google/cloud/bigquerycontrol/routine/v2/internal/routine_retry_traits.h b/google/cloud/bigquerycontrol/routine/v2/internal/routine_retry_traits.h new file mode 100644 index 0000000000000..6efd5b835de13 --- /dev/null +++ b/google/cloud/bigquerycontrol/routine/v2/internal/routine_retry_traits.h @@ -0,0 +1,43 @@ +// Copyright 2024 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/v2/routine.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_INTERNAL_ROUTINE_RETRY_TRAITS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_INTERNAL_ROUTINE_RETRY_TRAITS_H + +#include "google/cloud/status.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace bigquerycontrol_routine_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// Define the gRPC status code semantics for retrying requests. +struct RoutineServiceRetryTraits { + static bool IsPermanentFailure(google::cloud::Status const& status) { + return status.code() != StatusCode::kOk && + status.code() != StatusCode::kUnavailable; + } +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_routine_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_INTERNAL_ROUTINE_RETRY_TRAITS_H diff --git a/google/cloud/bigquerycontrol/routine/v2/internal/routine_sources.cc b/google/cloud/bigquerycontrol/routine/v2/internal/routine_sources.cc new file mode 100644 index 0000000000000..76079e7c1999e --- /dev/null +++ b/google/cloud/bigquerycontrol/routine/v2/internal/routine_sources.cc @@ -0,0 +1,31 @@ +// Copyright 2024 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/v2/routine.proto + +// NOLINTBEGIN(bugprone-suspicious-include) +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_option_defaults.cc" +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_connection_impl.cc" +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_logging_decorator.cc" +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_metadata_decorator.cc" +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_stub.cc" +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_stub_factory.cc" +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_tracing_connection.cc" +#include "google/cloud/bigquerycontrol/routine/v2/routine_client.cc" +#include "google/cloud/bigquerycontrol/routine/v2/routine_connection.cc" +#include "google/cloud/bigquerycontrol/routine/v2/routine_connection_idempotency_policy.cc" +#include "google/cloud/bigquerycontrol/routine/v2/routine_rest_connection.cc" +// NOLINTEND(bugprone-suspicious-include) diff --git a/google/cloud/bigquerycontrol/routine/v2/internal/routine_tracing_connection.cc b/google/cloud/bigquerycontrol/routine/v2/internal/routine_tracing_connection.cc new file mode 100644 index 0000000000000..94e09a8521e5a --- /dev/null +++ b/google/cloud/bigquerycontrol/routine/v2/internal/routine_tracing_connection.cc @@ -0,0 +1,105 @@ +// Copyright 2024 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/v2/routine.proto + +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_tracing_connection.h" +#include "google/cloud/internal/opentelemetry.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_routine_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +RoutineServiceTracingConnection::RoutineServiceTracingConnection( + std::shared_ptr child) + : child_(std::move(child)) {} + +StatusOr +RoutineServiceTracingConnection::GetRoutine( + google::cloud::bigquery::v2::GetRoutineRequest const& request) { + auto span = internal::MakeSpan( + "bigquerycontrol_routine_v2::RoutineServiceConnection::GetRoutine"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->GetRoutine(request)); +} + +StatusOr +RoutineServiceTracingConnection::InsertRoutine( + google::cloud::bigquery::v2::InsertRoutineRequest const& request) { + auto span = internal::MakeSpan( + "bigquerycontrol_routine_v2::RoutineServiceConnection::InsertRoutine"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->InsertRoutine(request)); +} + +StatusOr +RoutineServiceTracingConnection::UpdateRoutine( + google::cloud::bigquery::v2::UpdateRoutineRequest const& request) { + auto span = internal::MakeSpan( + "bigquerycontrol_routine_v2::RoutineServiceConnection::UpdateRoutine"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->UpdateRoutine(request)); +} + +StatusOr +RoutineServiceTracingConnection::PatchRoutine( + google::cloud::bigquery::v2::PatchRoutineRequest const& request) { + auto span = internal::MakeSpan( + "bigquerycontrol_routine_v2::RoutineServiceConnection::PatchRoutine"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->PatchRoutine(request)); +} + +Status RoutineServiceTracingConnection::DeleteRoutine( + google::cloud::bigquery::v2::DeleteRoutineRequest const& request) { + auto span = internal::MakeSpan( + "bigquerycontrol_routine_v2::RoutineServiceConnection::DeleteRoutine"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->DeleteRoutine(request)); +} + +StatusOr +RoutineServiceTracingConnection::ListRoutines( + google::cloud::bigquery::v2::ListRoutinesRequest const& request) { + auto span = internal::MakeSpan( + "bigquerycontrol_routine_v2::RoutineServiceConnection::ListRoutines"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->ListRoutines(request)); +} + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +std::shared_ptr +MakeRoutineServiceTracingConnection( + std::shared_ptr + conn) { +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + if (internal::TracingEnabled(conn->options())) { + conn = std::make_shared(std::move(conn)); + } +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + return conn; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_routine_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/routine/v2/internal/routine_tracing_connection.h b/google/cloud/bigquerycontrol/routine/v2/internal/routine_tracing_connection.h new file mode 100644 index 0000000000000..30ffb1712e76c --- /dev/null +++ b/google/cloud/bigquerycontrol/routine/v2/internal/routine_tracing_connection.h @@ -0,0 +1,85 @@ +// Copyright 2024 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/v2/routine.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_INTERNAL_ROUTINE_TRACING_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_INTERNAL_ROUTINE_TRACING_CONNECTION_H + +#include "google/cloud/bigquerycontrol/routine/v2/routine_connection.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_routine_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +class RoutineServiceTracingConnection + : public bigquerycontrol_routine_v2::RoutineServiceConnection { + public: + ~RoutineServiceTracingConnection() override = default; + + explicit RoutineServiceTracingConnection( + std::shared_ptr + child); + + Options options() override { return child_->options(); } + + StatusOr GetRoutine( + google::cloud::bigquery::v2::GetRoutineRequest const& request) override; + + StatusOr InsertRoutine( + google::cloud::bigquery::v2::InsertRoutineRequest const& request) + override; + + StatusOr UpdateRoutine( + google::cloud::bigquery::v2::UpdateRoutineRequest const& request) + override; + + StatusOr PatchRoutine( + google::cloud::bigquery::v2::PatchRoutineRequest const& request) override; + + Status DeleteRoutine(google::cloud::bigquery::v2::DeleteRoutineRequest const& + request) override; + + StatusOr ListRoutines( + google::cloud::bigquery::v2::ListRoutinesRequest const& request) override; + + private: + std::shared_ptr child_; +}; + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +/** + * Conditionally applies the tracing decorator to the given connection. + * + * The connection is only decorated if tracing is enabled (as determined by the + * connection's options). + */ +std::shared_ptr +MakeRoutineServiceTracingConnection( + std::shared_ptr conn); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_routine_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_INTERNAL_ROUTINE_TRACING_CONNECTION_H diff --git a/google/cloud/bigquerycontrol/routine/v2/mocks/mock_routine_connection.h b/google/cloud/bigquerycontrol/routine/v2/mocks/mock_routine_connection.h new file mode 100644 index 0000000000000..e8d50db5e859f --- /dev/null +++ b/google/cloud/bigquerycontrol/routine/v2/mocks/mock_routine_connection.h @@ -0,0 +1,84 @@ +// Copyright 2024 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/v2/routine.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_MOCKS_MOCK_ROUTINE_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_MOCKS_MOCK_ROUTINE_CONNECTION_H + +#include "google/cloud/bigquerycontrol/routine/v2/routine_connection.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_routine_v2_mocks { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * A class to mock `RoutineServiceConnection`. + * + * Application developers may want to test their code with simulated responses, + * including errors, from an object of type `RoutineServiceClient`. To do so, + * construct an object of type `RoutineServiceClient` 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]: @cloud_cpp_docs_link{bigquery,bigquery-read-mock} + */ +class MockRoutineServiceConnection + : public bigquerycontrol_routine_v2::RoutineServiceConnection { + public: + MOCK_METHOD(Options, options, (), (override)); + + MOCK_METHOD(StatusOr, GetRoutine, + (google::cloud::bigquery::v2::GetRoutineRequest const& request), + (override)); + + MOCK_METHOD( + StatusOr, InsertRoutine, + (google::cloud::bigquery::v2::InsertRoutineRequest const& request), + (override)); + + MOCK_METHOD( + StatusOr, UpdateRoutine, + (google::cloud::bigquery::v2::UpdateRoutineRequest const& request), + (override)); + + MOCK_METHOD(StatusOr, PatchRoutine, + (google::cloud::bigquery::v2::PatchRoutineRequest const& request), + (override)); + + MOCK_METHOD( + Status, DeleteRoutine, + (google::cloud::bigquery::v2::DeleteRoutineRequest const& request), + (override)); + + MOCK_METHOD(StatusOr, + ListRoutines, + (google::cloud::bigquery::v2::ListRoutinesRequest const& request), + (override)); +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_routine_v2_mocks +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_MOCKS_MOCK_ROUTINE_CONNECTION_H diff --git a/google/cloud/bigquerycontrol/routine/v2/routine_client.cc b/google/cloud/bigquerycontrol/routine/v2/routine_client.cc new file mode 100644 index 0000000000000..13b77fced5324 --- /dev/null +++ b/google/cloud/bigquerycontrol/routine/v2/routine_client.cc @@ -0,0 +1,84 @@ +// Copyright 2024 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/v2/routine.proto + +#include "google/cloud/bigquerycontrol/routine/v2/routine_client.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_routine_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +RoutineServiceClient::RoutineServiceClient( + std::shared_ptr connection, Options opts) + : connection_(std::move(connection)), + options_( + internal::MergeOptions(std::move(opts), connection_->options())) {} +RoutineServiceClient::~RoutineServiceClient() = default; + +StatusOr RoutineServiceClient::GetRoutine( + google::cloud::bigquery::v2::GetRoutineRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->GetRoutine(request); +} + +StatusOr +RoutineServiceClient::InsertRoutine( + google::cloud::bigquery::v2::InsertRoutineRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->InsertRoutine(request); +} + +StatusOr +RoutineServiceClient::UpdateRoutine( + google::cloud::bigquery::v2::UpdateRoutineRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->UpdateRoutine(request); +} + +StatusOr +RoutineServiceClient::PatchRoutine( + google::cloud::bigquery::v2::PatchRoutineRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->PatchRoutine(request); +} + +Status RoutineServiceClient::DeleteRoutine( + google::cloud::bigquery::v2::DeleteRoutineRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->DeleteRoutine(request); +} + +StatusOr +RoutineServiceClient::ListRoutines( + google::cloud::bigquery::v2::ListRoutinesRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->ListRoutines(request); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_routine_v2 +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/routine/v2/routine_client.h b/google/cloud/bigquerycontrol/routine/v2/routine_client.h new file mode 100644 index 0000000000000..74e9cd7fabd24 --- /dev/null +++ b/google/cloud/bigquerycontrol/routine/v2/routine_client.h @@ -0,0 +1,287 @@ +// Copyright 2024 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/v2/routine.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_ROUTINE_CLIENT_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_ROUTINE_CLIENT_H + +#include "google/cloud/bigquerycontrol/routine/v2/routine_rest_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 bigquerycontrol_routine_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// +/// This is an experimental RPC service definition for the BigQuery +/// Routine Service. +/// +/// It should not be relied on for production use cases at this time. +/// +/// @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 RoutineServiceClient { + public: + explicit RoutineServiceClient( + std::shared_ptr connection, Options opts = {}); + ~RoutineServiceClient(); + + ///@{ + /// @name Copy and move support + RoutineServiceClient(RoutineServiceClient const&) = default; + RoutineServiceClient& operator=(RoutineServiceClient const&) = default; + RoutineServiceClient(RoutineServiceClient&&) = default; + RoutineServiceClient& operator=(RoutineServiceClient&&) = default; + ///@} + + ///@{ + /// @name Equality + friend bool operator==(RoutineServiceClient const& a, + RoutineServiceClient const& b) { + return a.connection_ == b.connection_; + } + friend bool operator!=(RoutineServiceClient const& a, + RoutineServiceClient const& b) { + return !(a == b); + } + ///@} + + // clang-format off + /// + /// Gets the specified routine resource by routine ID. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.GetRoutineRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return the result of the RPC. The response message type + /// ([google.cloud.bigquery.v2.Routine]) + /// is mapped to a C++ class using the [Protobuf mapping rules]. + /// If the request fails, the [`StatusOr`] contains the error details. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.GetRoutineRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/routine.proto#L437} + /// [google.cloud.bigquery.v2.Routine]: @googleapis_reference_link{google/cloud/bigquery/v2/routine.proto#L88} + /// + // clang-format on + StatusOr GetRoutine( + google::cloud::bigquery::v2::GetRoutineRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Creates a new routine in the dataset. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.InsertRoutineRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return the result of the RPC. The response message type + /// ([google.cloud.bigquery.v2.Routine]) + /// is mapped to a C++ class using the [Protobuf mapping rules]. + /// If the request fails, the [`StatusOr`] contains the error details. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.InsertRoutineRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/routine.proto#L453} + /// [google.cloud.bigquery.v2.Routine]: @googleapis_reference_link{google/cloud/bigquery/v2/routine.proto#L88} + /// + // clang-format on + StatusOr InsertRoutine( + google::cloud::bigquery::v2::InsertRoutineRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Updates information in an existing routine. The update method replaces the + /// entire Routine resource. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.UpdateRoutineRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return the result of the RPC. The response message type + /// ([google.cloud.bigquery.v2.Routine]) + /// is mapped to a C++ class using the [Protobuf mapping rules]. + /// If the request fails, the [`StatusOr`] contains the error details. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.Routine]: @googleapis_reference_link{google/cloud/bigquery/v2/routine.proto#L88} + /// [google.cloud.bigquery.v2.UpdateRoutineRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/routine.proto#L465} + /// + // clang-format on + StatusOr UpdateRoutine( + google::cloud::bigquery::v2::UpdateRoutineRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Patches information in an existing routine. The patch method does a partial + /// update to an existing Routine resource. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.PatchRoutineRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return the result of the RPC. The response message type + /// ([google.cloud.bigquery.v2.Routine]) + /// is mapped to a C++ class using the [Protobuf mapping rules]. + /// If the request fails, the [`StatusOr`] contains the error details. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.PatchRoutineRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/routine.proto#L480} + /// [google.cloud.bigquery.v2.Routine]: @googleapis_reference_link{google/cloud/bigquery/v2/routine.proto#L88} + /// + // clang-format on + StatusOr PatchRoutine( + google::cloud::bigquery::v2::PatchRoutineRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Deletes the routine specified by routineId from the dataset. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.DeleteRoutineRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return a [`Status`] object. If the request failed, the + /// status contains the details of the failure. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.DeleteRoutineRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/routine.proto#L501} + /// + // clang-format on + Status DeleteRoutine( + google::cloud::bigquery::v2::DeleteRoutineRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Lists all routines in the specified dataset. Requires the READER dataset + /// role. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.ListRoutinesRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return the result of the RPC. The response message type + /// ([google.cloud.bigquery.v2.ListRoutinesResponse]) + /// is mapped to a C++ class using the [Protobuf mapping rules]. + /// If the request fails, the [`StatusOr`] contains the error details. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.ListRoutinesRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/routine.proto#L513} + /// [google.cloud.bigquery.v2.ListRoutinesResponse]: @googleapis_reference_link{google/cloud/bigquery/v2/routine.proto#L542} + /// + // clang-format on + StatusOr ListRoutines( + google::cloud::bigquery::v2::ListRoutinesRequest const& request, + Options opts = {}); + + private: + std::shared_ptr connection_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_routine_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_ROUTINE_CLIENT_H diff --git a/google/cloud/bigquerycontrol/routine/v2/routine_connection.cc b/google/cloud/bigquerycontrol/routine/v2/routine_connection.cc new file mode 100644 index 0000000000000..2589fa46218de --- /dev/null +++ b/google/cloud/bigquerycontrol/routine/v2/routine_connection.cc @@ -0,0 +1,76 @@ +// Copyright 2024 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/v2/routine.proto + +#include "google/cloud/bigquerycontrol/routine/v2/routine_connection.h" +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_option_defaults.h" +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_tracing_connection.h" +#include "google/cloud/bigquerycontrol/routine/v2/routine_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/unified_grpc_credentials.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_routine_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +RoutineServiceConnection::~RoutineServiceConnection() = default; + +StatusOr +RoutineServiceConnection::GetRoutine( + google::cloud::bigquery::v2::GetRoutineRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +RoutineServiceConnection::InsertRoutine( + google::cloud::bigquery::v2::InsertRoutineRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +RoutineServiceConnection::UpdateRoutine( + google::cloud::bigquery::v2::UpdateRoutineRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +RoutineServiceConnection::PatchRoutine( + google::cloud::bigquery::v2::PatchRoutineRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +Status RoutineServiceConnection::DeleteRoutine( + google::cloud::bigquery::v2::DeleteRoutineRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +RoutineServiceConnection::ListRoutines( + google::cloud::bigquery::v2::ListRoutinesRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_routine_v2 +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/routine/v2/routine_connection.h b/google/cloud/bigquerycontrol/routine/v2/routine_connection.h new file mode 100644 index 0000000000000..1230e96c6f157 --- /dev/null +++ b/google/cloud/bigquerycontrol/routine/v2/routine_connection.h @@ -0,0 +1,210 @@ +// Copyright 2024 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/v2/routine.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_ROUTINE_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_ROUTINE_CONNECTION_H + +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_retry_traits.h" +#include "google/cloud/bigquerycontrol/routine/v2/routine_connection_idempotency_policy.h" +#include "google/cloud/backoff_policy.h" +#include "google/cloud/experimental_tag.h" +#include "google/cloud/internal/retry_policy_impl.h" +#include "google/cloud/options.h" +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_routine_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// The retry policy for `RoutineServiceConnection`. +class RoutineServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `RoutineServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RoutineServiceLimitedErrorCountRetryPolicy + : public RoutineServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RoutineServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + RoutineServiceLimitedErrorCountRetryPolicy( + RoutineServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : RoutineServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + RoutineServiceLimitedErrorCountRetryPolicy( + RoutineServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : RoutineServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RoutineServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + bigquerycontrol_routine_v2_internal::RoutineServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `RoutineServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RoutineServiceLimitedTimeRetryPolicy : public RoutineServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RoutineServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RoutineServiceLimitedTimeRetryPolicy( + RoutineServiceLimitedTimeRetryPolicy&& rhs) noexcept + : RoutineServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + RoutineServiceLimitedTimeRetryPolicy( + RoutineServiceLimitedTimeRetryPolicy const& rhs) noexcept + : RoutineServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RoutineServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + bigquerycontrol_routine_v2_internal::RoutineServiceRetryTraits> + impl_; +}; + +/** + * The `RoutineServiceConnection` object for `RoutineServiceClient`. + * + * This interface defines virtual methods for each of the user-facing overload + * sets in `RoutineServiceClient`. This allows users to inject custom behavior + * (e.g., with a Google Mock object) when writing tests that use objects of type + * `RoutineServiceClient`. + * + * To create a concrete instance, see `MakeRoutineServiceConnection()`. + * + * For mocking, see + * `bigquerycontrol_routine_v2_mocks::MockRoutineServiceConnection`. + */ +class RoutineServiceConnection { + public: + virtual ~RoutineServiceConnection() = 0; + + virtual Options options() { return Options{}; } + + virtual StatusOr GetRoutine( + google::cloud::bigquery::v2::GetRoutineRequest const& request); + + virtual StatusOr InsertRoutine( + google::cloud::bigquery::v2::InsertRoutineRequest const& request); + + virtual StatusOr UpdateRoutine( + google::cloud::bigquery::v2::UpdateRoutineRequest const& request); + + virtual StatusOr PatchRoutine( + google::cloud::bigquery::v2::PatchRoutineRequest const& request); + + virtual Status DeleteRoutine( + google::cloud::bigquery::v2::DeleteRoutineRequest const& request); + + virtual StatusOr + ListRoutines(google::cloud::bigquery::v2::ListRoutinesRequest const& request); +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_routine_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_ROUTINE_CONNECTION_H diff --git a/google/cloud/bigquerycontrol/routine/v2/routine_connection_idempotency_policy.cc b/google/cloud/bigquerycontrol/routine/v2/routine_connection_idempotency_policy.cc new file mode 100644 index 0000000000000..1988edbeb2e7c --- /dev/null +++ b/google/cloud/bigquerycontrol/routine/v2/routine_connection_idempotency_policy.cc @@ -0,0 +1,75 @@ +// Copyright 2024 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/v2/routine.proto + +#include "google/cloud/bigquerycontrol/routine/v2/routine_connection_idempotency_policy.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_routine_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +using ::google::cloud::Idempotency; + +RoutineServiceConnectionIdempotencyPolicy:: + ~RoutineServiceConnectionIdempotencyPolicy() = default; + +std::unique_ptr +RoutineServiceConnectionIdempotencyPolicy::clone() const { + return std::make_unique(*this); +} + +Idempotency RoutineServiceConnectionIdempotencyPolicy::GetRoutine( + google::cloud::bigquery::v2::GetRoutineRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency RoutineServiceConnectionIdempotencyPolicy::InsertRoutine( + google::cloud::bigquery::v2::InsertRoutineRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency RoutineServiceConnectionIdempotencyPolicy::UpdateRoutine( + google::cloud::bigquery::v2::UpdateRoutineRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency RoutineServiceConnectionIdempotencyPolicy::PatchRoutine( + google::cloud::bigquery::v2::PatchRoutineRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency RoutineServiceConnectionIdempotencyPolicy::DeleteRoutine( + google::cloud::bigquery::v2::DeleteRoutineRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency RoutineServiceConnectionIdempotencyPolicy::ListRoutines( + google::cloud::bigquery::v2::ListRoutinesRequest const&) { + return Idempotency::kIdempotent; +} + +std::unique_ptr +MakeDefaultRoutineServiceConnectionIdempotencyPolicy() { + return std::make_unique(); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_routine_v2 +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/routine/v2/routine_connection_idempotency_policy.h b/google/cloud/bigquerycontrol/routine/v2/routine_connection_idempotency_policy.h new file mode 100644 index 0000000000000..687f19f6e033d --- /dev/null +++ b/google/cloud/bigquerycontrol/routine/v2/routine_connection_idempotency_policy.h @@ -0,0 +1,67 @@ +// Copyright 2024 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/v2/routine.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_ROUTINE_CONNECTION_IDEMPOTENCY_POLICY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_ROUTINE_CONNECTION_IDEMPOTENCY_POLICY_H + +#include "google/cloud/idempotency.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_routine_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class RoutineServiceConnectionIdempotencyPolicy { + public: + virtual ~RoutineServiceConnectionIdempotencyPolicy(); + + /// Create a new copy of this object. + virtual std::unique_ptr clone() + const; + + virtual google::cloud::Idempotency GetRoutine( + google::cloud::bigquery::v2::GetRoutineRequest const& request); + + virtual google::cloud::Idempotency InsertRoutine( + google::cloud::bigquery::v2::InsertRoutineRequest const& request); + + virtual google::cloud::Idempotency UpdateRoutine( + google::cloud::bigquery::v2::UpdateRoutineRequest const& request); + + virtual google::cloud::Idempotency PatchRoutine( + google::cloud::bigquery::v2::PatchRoutineRequest const& request); + + virtual google::cloud::Idempotency DeleteRoutine( + google::cloud::bigquery::v2::DeleteRoutineRequest const& request); + + virtual google::cloud::Idempotency ListRoutines( + google::cloud::bigquery::v2::ListRoutinesRequest const& request); +}; + +std::unique_ptr +MakeDefaultRoutineServiceConnectionIdempotencyPolicy(); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_routine_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_ROUTINE_CONNECTION_IDEMPOTENCY_POLICY_H diff --git a/google/cloud/bigquerycontrol/routine/v2/routine_options.h b/google/cloud/bigquerycontrol/routine/v2/routine_options.h new file mode 100644 index 0000000000000..f31724d205b10 --- /dev/null +++ b/google/cloud/bigquerycontrol/routine/v2/routine_options.h @@ -0,0 +1,76 @@ +// Copyright 2024 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/v2/routine.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_ROUTINE_OPTIONS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_ROUTINE_OPTIONS_H + +#include "google/cloud/bigquerycontrol/routine/v2/routine_connection.h" +#include "google/cloud/bigquerycontrol/routine/v2/routine_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 bigquerycontrol_routine_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * Use with `google::cloud::Options` to configure the retry policy. + * + * @ingroup google-cloud-bigquerycontrol-options + */ +struct RoutineServiceRetryPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure the backoff policy. + * + * @ingroup google-cloud-bigquerycontrol-options + */ +struct RoutineServiceBackoffPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure which operations are retried. + * + * @ingroup google-cloud-bigquerycontrol-options + */ +struct RoutineServiceConnectionIdempotencyPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * The options applicable to RoutineService. + * + * @ingroup google-cloud-bigquerycontrol-options + */ +using RoutineServicePolicyOptionList = + OptionList; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_routine_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_ROUTINE_OPTIONS_H diff --git a/google/cloud/bigquerycontrol/routine/v2/routine_rest_connection.cc b/google/cloud/bigquerycontrol/routine/v2/routine_rest_connection.cc new file mode 100644 index 0000000000000..22ca54fe4f0fb --- /dev/null +++ b/google/cloud/bigquerycontrol/routine/v2/routine_rest_connection.cc @@ -0,0 +1,60 @@ +// Copyright 2024 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/v2/routine.proto + +#include "google/cloud/bigquerycontrol/routine/v2/routine_rest_connection.h" +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_option_defaults.h" +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_connection_impl.h" +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_rest_stub_factory.h" +#include "google/cloud/bigquerycontrol/routine/v2/internal/routine_tracing_connection.h" +#include "google/cloud/bigquerycontrol/routine/v2/routine_options.h" +#include "google/cloud/common_options.h" +#include "google/cloud/credentials.h" +#include "google/cloud/internal/rest_background_threads_impl.h" +#include "google/cloud/internal/rest_options.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_routine_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr MakeRoutineServiceConnectionRest( + Options options) { + internal::CheckExpectedOptions< + CommonOptionList, RestOptionList, UnifiedCredentialsOptionList, + rest_internal::TargetApiVersionOption, RoutineServicePolicyOptionList>( + options, __func__); + options = bigquerycontrol_routine_v2_internal::RoutineServiceDefaultOptions( + std::move(options)); + auto background = std::make_unique< + rest_internal::AutomaticallyCreatedRestBackgroundThreads>(); + auto stub = + bigquerycontrol_routine_v2_internal::CreateDefaultRoutineServiceRestStub( + options); + return bigquerycontrol_routine_v2_internal:: + MakeRoutineServiceTracingConnection( + std::make_shared( + std::move(background), std::move(stub), std::move(options))); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_routine_v2 +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/routine/v2/routine_rest_connection.h b/google/cloud/bigquerycontrol/routine/v2/routine_rest_connection.h new file mode 100644 index 0000000000000..ab027d4d74eed --- /dev/null +++ b/google/cloud/bigquerycontrol/routine/v2/routine_rest_connection.h @@ -0,0 +1,64 @@ +// Copyright 2024 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/v2/routine.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_ROUTINE_REST_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_ROUTINE_REST_CONNECTION_H + +#include "google/cloud/bigquerycontrol/routine/v2/routine_connection.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_routine_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * A factory function to construct an object of type `RoutineServiceConnection` + * that uses REST over HTTP as transport in lieu of gRPC. REST transport should + * only be used for services that do not support gRPC or if the existing network + * configuration precludes using gRPC. + * + * The returned connection object should not be used directly; instead it + * should be passed as an argument to the constructor of RoutineServiceClient. + * + * The optional @p options argument may be used to configure aspects of the + * returned `RoutineServiceConnection`. Expected options are any of the types in + * the following option lists: + * + * - `google::cloud::CommonOptionList` + * - `google::cloud::RestOptionList` + * - `google::cloud::UnifiedCredentialsOptionList` + * - `google::cloud::bigquerycontrol_routine_v2::RoutineServicePolicyOptionList` + * + * @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 `RoutineServiceConnection` created by + * this function. + */ +std::shared_ptr MakeRoutineServiceConnectionRest( + Options options = {}); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_routine_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROUTINE_V2_ROUTINE_REST_CONNECTION_H diff --git a/google/cloud/bigquerycontrol/routine/v2/samples/routine_client_samples.cc b/google/cloud/bigquerycontrol/routine/v2/samples/routine_client_samples.cc new file mode 100644 index 0000000000000..059e31c7719cb --- /dev/null +++ b/google/cloud/bigquerycontrol/routine/v2/samples/routine_client_samples.cc @@ -0,0 +1,163 @@ +// Copyright 2024 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/v2/routine.proto + +#include "google/cloud/bigquerycontrol/routine/v2/routine_client.h" +#include "google/cloud/bigquerycontrol/routine/v2/routine_connection_idempotency_policy.h" +#include "google/cloud/bigquerycontrol/routine/v2/routine_options.h" +#include "google/cloud/common_options.h" +#include "google/cloud/credentials.h" +#include "google/cloud/internal/getenv.h" +#include "google/cloud/testing_util/example_driver.h" +#include +#include +#include +#include + +// clang-format off +// main-dox-marker: bigquerycontrol_routine_v2::RoutineServiceClient +// clang-format on +namespace { + +void SetClientEndpoint(std::vector const& argv) { + if (!argv.empty()) { + throw google::cloud::testing_util::Usage{"set-client-endpoint"}; + } + //! [set-client-endpoint] + // This configuration is common with Private Google Access: + // https://cloud.google.com/vpc/docs/private-google-access + auto options = google::cloud::Options{}.set( + "private.googleapis.com"); + auto client = google::cloud::bigquerycontrol_routine_v2::RoutineServiceClient( + google::cloud::bigquerycontrol_routine_v2:: + MakeRoutineServiceConnectionRest(options)); + //! [set-client-endpoint] +} + +//! [custom-idempotency-policy] +class CustomIdempotencyPolicy + : public google::cloud::bigquerycontrol_routine_v2:: + RoutineServiceConnectionIdempotencyPolicy { + public: + ~CustomIdempotencyPolicy() override = default; + std::unique_ptr + clone() const override { + return std::make_unique(*this); + } + // Override inherited functions to define as needed. +}; +//! [custom-idempotency-policy] + +void SetRetryPolicy(std::vector const& argv) { + if (!argv.empty()) { + throw google::cloud::testing_util::Usage{"set-client-retry-policy"}; + } + //! [set-retry-policy] + auto options = google::cloud::Options{} + .set( + CustomIdempotencyPolicy().clone()) + .set( + google::cloud::bigquerycontrol_routine_v2:: + RoutineServiceLimitedErrorCountRetryPolicy(3) + .clone()) + .set( + google::cloud::ExponentialBackoffPolicy( + /*initial_delay=*/std::chrono::milliseconds(200), + /*maximum_delay=*/std::chrono::seconds(45), + /*scaling=*/2.0) + .clone()); + auto connection = google::cloud::bigquerycontrol_routine_v2:: + MakeRoutineServiceConnectionRest(options); + + // c1 and c2 share the same retry policies + auto c1 = google::cloud::bigquerycontrol_routine_v2::RoutineServiceClient( + connection); + auto c2 = google::cloud::bigquerycontrol_routine_v2::RoutineServiceClient( + connection); + + // You can override any of the policies in a new client. This new client + // will share the policies from c1 (or c2) *except* for the retry policy. + auto c3 = google::cloud::bigquerycontrol_routine_v2::RoutineServiceClient( + connection, + google::cloud::Options{} + .set( + google::cloud::bigquerycontrol_routine_v2:: + RoutineServiceLimitedTimeRetryPolicy(std::chrono::minutes(5)) + .clone())); + + // You can also override the policies in a single call: + // c3.SomeRpc(..., google::cloud::Options{} + // .set( + // google::cloud::bigquerycontrol_routine_v2::RoutineServiceLimitedErrorCountRetryPolicy(10).clone())); + //! [set-retry-policy] +} + +void WithServiceAccount(std::vector const& argv) { + if (argv.size() != 1 || argv[0] == "--help") { + throw google::cloud::testing_util::Usage{"with-service-account "}; + } + //! [with-service-account] + [](std::string const& keyfile) { + auto is = std::ifstream(keyfile); + is.exceptions(std::ios::badbit); // Minimal error handling in examples + auto contents = std::string(std::istreambuf_iterator(is.rdbuf()), {}); + auto options = + google::cloud::Options{}.set( + google::cloud::MakeServiceAccountCredentials(contents)); + return google::cloud::bigquerycontrol_routine_v2::RoutineServiceClient( + google::cloud::bigquerycontrol_routine_v2:: + MakeRoutineServiceConnectionRest(options)); + } + //! [with-service-account] + (argv.at(0)); +} + +void AutoRun(std::vector const& argv) { + namespace examples = ::google::cloud::testing_util; + using ::google::cloud::internal::GetEnv; + if (!argv.empty()) throw examples::Usage{"auto"}; + examples::CheckEnvironmentVariablesAreSet( + {"GOOGLE_CLOUD_CPP_TEST_SERVICE_ACCOUNT_KEYFILE"}); + auto const keyfile = + GetEnv("GOOGLE_CLOUD_CPP_TEST_SERVICE_ACCOUNT_KEYFILE").value(); + + std::cout << "\nRunning SetClientEndpoint() example" << std::endl; + SetClientEndpoint({}); + + std::cout << "\nRunning SetRetryPolicy() example" << std::endl; + SetRetryPolicy({}); + + std::cout << "\nRunning WithServiceAccount() example" << std::endl; + WithServiceAccount({keyfile}); +} + +} // namespace + +int main(int argc, char* argv[]) { // NOLINT(bugprone-exception-escape) + google::cloud::testing_util::Example example({ + {"set-client-endpoint", SetClientEndpoint}, + {"set-retry-policy", SetRetryPolicy}, + {"with-service-account", WithServiceAccount}, + {"auto", AutoRun}, + }); + return example.Run(argc, argv); +} diff --git a/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_option_defaults.cc b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_option_defaults.cc new file mode 100644 index 0000000000000..e653d2286cd77 --- /dev/null +++ b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_option_defaults.cc @@ -0,0 +1,75 @@ +// Copyright 2024 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/v2/row_access_policy.proto + +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_option_defaults.h" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_connection.h" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_options.h" +#include "google/cloud/internal/populate_common_options.h" +#include "google/cloud/internal/populate_grpc_options.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_row_access_policy_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +namespace { +auto constexpr kBackoffScaling = 2.0; +} // namespace + +Options RowAccessPolicyServiceDefaultOptions(Options options) { + options = internal::PopulateCommonOptions( + std::move(options), "GOOGLE_CLOUD_CPP_ROW_ACCESS_POLICY_SERVICE_ENDPOINT", + "", "GOOGLE_CLOUD_CPP_ROW_ACCESS_POLICY_SERVICE_AUTHORITY", + "bigquery.googleapis.com"); + options = internal::PopulateGrpcOptions(std::move(options)); + if (!options.has()) { + options.set( + bigquerycontrol_row_access_policy_v2:: + RowAccessPolicyServiceLimitedTimeRetryPolicy( + std::chrono::minutes(30)) + .clone()); + } + if (!options.has()) { + options.set( + ExponentialBackoffPolicy( + std::chrono::seconds(0), std::chrono::seconds(1), + std::chrono::minutes(5), kBackoffScaling, kBackoffScaling) + .clone()); + } + if (!options.has< + bigquerycontrol_row_access_policy_v2:: + RowAccessPolicyServiceConnectionIdempotencyPolicyOption>()) { + options.set( + bigquerycontrol_row_access_policy_v2:: + MakeDefaultRowAccessPolicyServiceConnectionIdempotencyPolicy()); + } + + return options; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_row_access_policy_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_option_defaults.h b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_option_defaults.h new file mode 100644 index 0000000000000..5a293b858358b --- /dev/null +++ b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_option_defaults.h @@ -0,0 +1,37 @@ +// Copyright 2024 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/v2/row_access_policy.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_INTERNAL_ROW_ACCESS_POLICY_OPTION_DEFAULTS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_INTERNAL_ROW_ACCESS_POLICY_OPTION_DEFAULTS_H + +#include "google/cloud/options.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace bigquerycontrol_row_access_policy_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +Options RowAccessPolicyServiceDefaultOptions(Options options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_row_access_policy_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_INTERNAL_ROW_ACCESS_POLICY_OPTION_DEFAULTS_H diff --git a/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_connection_impl.cc b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_connection_impl.cc new file mode 100644 index 0000000000000..278a6066d6ffd --- /dev/null +++ b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_connection_impl.cc @@ -0,0 +1,88 @@ +// Copyright 2024 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/v2/row_access_policy.proto + +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_connection_impl.h" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_stub_factory.h" +#include "google/cloud/common_options.h" +#include "google/cloud/credentials.h" +#include "google/cloud/internal/pagination_range.h" +#include "google/cloud/internal/rest_retry_loop.h" +#include "google/cloud/rest_options.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_row_access_policy_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +RowAccessPolicyServiceRestConnectionImpl:: + RowAccessPolicyServiceRestConnectionImpl( + std::unique_ptr background, + std::shared_ptr + stub, + Options options) + : background_(std::move(background)), + stub_(std::move(stub)), + options_(internal::MergeOptions( + std::move(options), RowAccessPolicyServiceConnection::options())) {} + +StreamRange +RowAccessPolicyServiceRestConnectionImpl::ListRowAccessPolicies( + google::cloud::bigquery::v2::ListRowAccessPoliciesRequest request) { + request.clear_page_token(); + auto current = google::cloud::internal::SaveCurrentOptions(); + auto idempotency = + idempotency_policy(*current)->ListRowAccessPolicies(request); + char const* function_name = __func__; + return google::cloud::internal::MakePaginationRange< + StreamRange>( + current, std::move(request), + [idempotency, function_name, stub = stub_, + retry = std::shared_ptr( + retry_policy(*current)), + backoff = std::shared_ptr(backoff_policy(*current))]( + Options const& options, + google::cloud::bigquery::v2::ListRowAccessPoliciesRequest const& r) { + return google::cloud::rest_internal::RestRetryLoop( + retry->clone(), backoff->clone(), idempotency, + [stub]( + rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListRowAccessPoliciesRequest const& + request) { + return stub->ListRowAccessPolicies(rest_context, options, + request); + }, + options, r, function_name); + }, + [](google::cloud::bigquery::v2::ListRowAccessPoliciesResponse r) { + std::vector result( + r.row_access_policies().size()); + auto& messages = *r.mutable_row_access_policies(); + std::move(messages.begin(), messages.end(), result.begin()); + return result; + }); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_row_access_policy_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_connection_impl.h b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_connection_impl.h new file mode 100644 index 0000000000000..e40e82609c1b1 --- /dev/null +++ b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_connection_impl.h @@ -0,0 +1,98 @@ +// Copyright 2024 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/v2/row_access_policy.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_INTERNAL_ROW_ACCESS_POLICY_REST_CONNECTION_IMPL_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_INTERNAL_ROW_ACCESS_POLICY_REST_CONNECTION_IMPL_H + +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_stub.h" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_retry_traits.h" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_connection.h" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_connection_idempotency_policy.h" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_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 bigquerycontrol_row_access_policy_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class RowAccessPolicyServiceRestConnectionImpl + : public bigquerycontrol_row_access_policy_v2:: + RowAccessPolicyServiceConnection { + public: + ~RowAccessPolicyServiceRestConnectionImpl() override = default; + + RowAccessPolicyServiceRestConnectionImpl( + std::unique_ptr background, + std::shared_ptr + stub, + Options options); + + Options options() override { return options_; } + + StreamRange + ListRowAccessPolicies( + google::cloud::bigquery::v2::ListRowAccessPoliciesRequest request) + override; + + private: + static std::unique_ptr< + bigquerycontrol_row_access_policy_v2::RowAccessPolicyServiceRetryPolicy> + retry_policy(Options const& options) { + return options + .get() + ->clone(); + } + + static std::unique_ptr backoff_policy(Options const& options) { + return options + .get() + ->clone(); + } + + static std::unique_ptr + idempotency_policy(Options const& options) { + return options + .get() + ->clone(); + } + + std::unique_ptr background_; + std::shared_ptr + stub_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_row_access_policy_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_INTERNAL_ROW_ACCESS_POLICY_REST_CONNECTION_IMPL_H diff --git a/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_logging_decorator.cc b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_logging_decorator.cc new file mode 100644 index 0000000000000..0919f596925f9 --- /dev/null +++ b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_logging_decorator.cc @@ -0,0 +1,53 @@ +// Copyright 2024 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/v2/row_access_policy.proto + +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_logging_decorator.h" +#include "google/cloud/internal/log_wrapper.h" +#include "google/cloud/status_or.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_row_access_policy_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +RowAccessPolicyServiceRestLogging::RowAccessPolicyServiceRestLogging( + 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 +RowAccessPolicyServiceRestLogging::ListRowAccessPolicies( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::ListRowAccessPoliciesRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::ListRowAccessPoliciesRequest const& + request) { + return child_->ListRowAccessPolicies(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_row_access_policy_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_logging_decorator.h b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_logging_decorator.h new file mode 100644 index 0000000000000..be42fc7c763dc --- /dev/null +++ b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_logging_decorator.h @@ -0,0 +1,63 @@ +// Copyright 2024 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/v2/row_access_policy.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_INTERNAL_ROW_ACCESS_POLICY_REST_LOGGING_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_INTERNAL_ROW_ACCESS_POLICY_REST_LOGGING_DECORATOR_H + +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_stub.h" +#include "google/cloud/future.h" +#include "google/cloud/internal/rest_context.h" +#include "google/cloud/tracing_options.h" +#include "google/cloud/version.h" +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_row_access_policy_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class RowAccessPolicyServiceRestLogging + : public RowAccessPolicyServiceRestStub { + public: + ~RowAccessPolicyServiceRestLogging() override = default; + RowAccessPolicyServiceRestLogging( + std::shared_ptr child, + TracingOptions tracing_options, std::set components); + + StatusOr + ListRowAccessPolicies( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListRowAccessPoliciesRequest const& request) + override; + + private: + std::shared_ptr child_; + TracingOptions tracing_options_; + std::set components_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_row_access_policy_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_INTERNAL_ROW_ACCESS_POLICY_REST_LOGGING_DECORATOR_H diff --git a/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_metadata_decorator.cc b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_metadata_decorator.cc new file mode 100644 index 0000000000000..3449b316c6240 --- /dev/null +++ b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_metadata_decorator.cc @@ -0,0 +1,60 @@ +// Copyright 2024 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/v2/row_access_policy.proto + +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_metadata_decorator.h" +#include "google/cloud/internal/absl_str_cat_quiet.h" +#include "google/cloud/internal/api_client_header.h" +#include "google/cloud/internal/rest_set_metadata.h" +#include "google/cloud/status_or.h" +#include "absl/strings/str_format.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_row_access_policy_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +RowAccessPolicyServiceRestMetadata::RowAccessPolicyServiceRestMetadata( + std::shared_ptr child, + std::string api_client_header) + : child_(std::move(child)), + api_client_header_( + api_client_header.empty() + ? google::cloud::internal::GeneratedLibClientHeader() + : std::move(api_client_header)) {} + +StatusOr +RowAccessPolicyServiceRestMetadata::ListRowAccessPolicies( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::ListRowAccessPoliciesRequest const& request) { + SetMetadata(rest_context, options); + return child_->ListRowAccessPolicies(rest_context, options, request); +} + +void RowAccessPolicyServiceRestMetadata::SetMetadata( + rest_internal::RestContext& rest_context, Options const& options, + std::vector const& params) { + google::cloud::rest_internal::SetMetadata(rest_context, options, params, + api_client_header_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_row_access_policy_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_metadata_decorator.h b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_metadata_decorator.h new file mode 100644 index 0000000000000..5f2ced4c5bc79 --- /dev/null +++ b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_metadata_decorator.h @@ -0,0 +1,64 @@ +// Copyright 2024 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/v2/row_access_policy.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_INTERNAL_ROW_ACCESS_POLICY_REST_METADATA_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_INTERNAL_ROW_ACCESS_POLICY_REST_METADATA_DECORATOR_H + +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_stub.h" +#include "google/cloud/future.h" +#include "google/cloud/rest_options.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_row_access_policy_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class RowAccessPolicyServiceRestMetadata + : public RowAccessPolicyServiceRestStub { + public: + ~RowAccessPolicyServiceRestMetadata() override = default; + explicit RowAccessPolicyServiceRestMetadata( + std::shared_ptr child, + std::string api_client_header = ""); + + StatusOr + ListRowAccessPolicies( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListRowAccessPoliciesRequest const& request) + override; + + private: + void SetMetadata(rest_internal::RestContext& rest_context, + Options const& options, + std::vector const& params = {}); + + std::shared_ptr child_; + std::string api_client_header_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_row_access_policy_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_INTERNAL_ROW_ACCESS_POLICY_REST_METADATA_DECORATOR_H diff --git a/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_stub.cc b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_stub.cc new file mode 100644 index 0000000000000..af104552ab8fe --- /dev/null +++ b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_stub.cc @@ -0,0 +1,64 @@ +// Copyright 2024 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/v2/row_access_policy.proto + +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_stub.h" +#include "google/cloud/common_options.h" +#include "google/cloud/internal/absl_str_cat_quiet.h" +#include "google/cloud/internal/rest_stub_helpers.h" +#include "google/cloud/status_or.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_row_access_policy_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +DefaultRowAccessPolicyServiceRestStub::DefaultRowAccessPolicyServiceRestStub( + Options options) + : service_(rest_internal::MakePooledRestClient( + options.get(), options)), + options_(std::move(options)) {} + +DefaultRowAccessPolicyServiceRestStub::DefaultRowAccessPolicyServiceRestStub( + std::shared_ptr service, Options options) + : service_(std::move(service)), options_(std::move(options)) {} + +StatusOr +DefaultRowAccessPolicyServiceRestStub::ListRowAccessPolicies( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListRowAccessPoliciesRequest const& request) { + return rest_internal::Get< + google::cloud::bigquery::v2::ListRowAccessPoliciesResponse>( + *service_, rest_context, request, false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "datasets", "/", + request.dataset_id(), "/", "tables", "/", request.table_id(), + "/", "rowAccessPolicies"), + rest_internal::TrimEmptyQueryParameters( + {std::make_pair("page_token", request.page_token()), + std::make_pair("page_size", std::to_string(request.page_size()))})); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_row_access_policy_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_stub.h b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_stub.h new file mode 100644 index 0000000000000..88f2781466a3a --- /dev/null +++ b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_stub.h @@ -0,0 +1,73 @@ +// Copyright 2024 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/v2/row_access_policy.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_INTERNAL_ROW_ACCESS_POLICY_REST_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_INTERNAL_ROW_ACCESS_POLICY_REST_STUB_H + +#include "google/cloud/completion_queue.h" +#include "google/cloud/internal/rest_client.h" +#include "google/cloud/internal/rest_context.h" +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_row_access_policy_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class RowAccessPolicyServiceRestStub { + public: + virtual ~RowAccessPolicyServiceRestStub() = default; + + virtual StatusOr + ListRowAccessPolicies( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListRowAccessPoliciesRequest const& + request) = 0; +}; + +class DefaultRowAccessPolicyServiceRestStub + : public RowAccessPolicyServiceRestStub { + public: + ~DefaultRowAccessPolicyServiceRestStub() override = default; + + explicit DefaultRowAccessPolicyServiceRestStub(Options options); + DefaultRowAccessPolicyServiceRestStub( + std::shared_ptr service, Options options); + + StatusOr + ListRowAccessPolicies( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListRowAccessPoliciesRequest const& request) + override; + + private: + std::shared_ptr service_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_row_access_policy_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_INTERNAL_ROW_ACCESS_POLICY_REST_STUB_H diff --git a/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_stub_factory.cc b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_stub_factory.cc new file mode 100644 index 0000000000000..c08d89fb50aa9 --- /dev/null +++ b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_stub_factory.cc @@ -0,0 +1,56 @@ +// Copyright 2024 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/v2/row_access_policy.proto + +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_stub_factory.h" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_logging_decorator.h" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_metadata_decorator.h" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_stub.h" +#include "google/cloud/common_options.h" +#include "google/cloud/internal/algorithm.h" +#include "google/cloud/internal/populate_rest_options.h" +#include "google/cloud/log.h" +#include "google/cloud/options.h" +#include "google/cloud/rest_options.h" +#include "absl/strings/match.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_row_access_policy_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr +CreateDefaultRowAccessPolicyServiceRestStub(Options const& options) { + auto opts = internal::PopulateRestOptions(options); + std::shared_ptr stub = + std::make_shared(std::move(opts)); + stub = std::make_shared(std::move(stub)); + if (internal::Contains(options.get(), "rpc")) { + GCP_LOG(INFO) << "Enabled logging for REST rpc calls"; + stub = std::make_shared( + std::move(stub), options.get(), + options.get()); + } + return stub; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_row_access_policy_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_stub_factory.h b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_stub_factory.h new file mode 100644 index 0000000000000..bb725b585a017 --- /dev/null +++ b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_stub_factory.h @@ -0,0 +1,40 @@ +// Copyright 2024 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/v2/row_access_policy.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_INTERNAL_ROW_ACCESS_POLICY_REST_STUB_FACTORY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_INTERNAL_ROW_ACCESS_POLICY_REST_STUB_FACTORY_H + +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_stub.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_row_access_policy_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr +CreateDefaultRowAccessPolicyServiceRestStub(Options const& options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_row_access_policy_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_INTERNAL_ROW_ACCESS_POLICY_REST_STUB_FACTORY_H diff --git a/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_retry_traits.h b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_retry_traits.h new file mode 100644 index 0000000000000..93e3a6141f3c1 --- /dev/null +++ b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_retry_traits.h @@ -0,0 +1,43 @@ +// Copyright 2024 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/v2/row_access_policy.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_INTERNAL_ROW_ACCESS_POLICY_RETRY_TRAITS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_INTERNAL_ROW_ACCESS_POLICY_RETRY_TRAITS_H + +#include "google/cloud/status.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace bigquerycontrol_row_access_policy_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// Define the gRPC status code semantics for retrying requests. +struct RowAccessPolicyServiceRetryTraits { + static bool IsPermanentFailure(google::cloud::Status const& status) { + return status.code() != StatusCode::kOk && + status.code() != StatusCode::kUnavailable; + } +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_row_access_policy_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_INTERNAL_ROW_ACCESS_POLICY_RETRY_TRAITS_H diff --git a/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_sources.cc b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_sources.cc new file mode 100644 index 0000000000000..591f5e7ca7443 --- /dev/null +++ b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_sources.cc @@ -0,0 +1,31 @@ +// Copyright 2024 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/v2/row_access_policy.proto + +// NOLINTBEGIN(bugprone-suspicious-include) +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_option_defaults.cc" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_connection_impl.cc" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_logging_decorator.cc" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_metadata_decorator.cc" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_stub.cc" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_stub_factory.cc" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_tracing_connection.cc" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_client.cc" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_connection.cc" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_connection_idempotency_policy.cc" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_rest_connection.cc" +// NOLINTEND(bugprone-suspicious-include) diff --git a/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_tracing_connection.cc b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_tracing_connection.cc new file mode 100644 index 0000000000000..83017ea6be6ff --- /dev/null +++ b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_tracing_connection.cc @@ -0,0 +1,72 @@ +// Copyright 2024 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/v2/row_access_policy.proto + +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_tracing_connection.h" +#include "google/cloud/internal/opentelemetry.h" +#include "google/cloud/internal/traced_stream_range.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_row_access_policy_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +RowAccessPolicyServiceTracingConnection:: + RowAccessPolicyServiceTracingConnection( + std::shared_ptr + child) + : child_(std::move(child)) {} + +StreamRange +RowAccessPolicyServiceTracingConnection::ListRowAccessPolicies( + google::cloud::bigquery::v2::ListRowAccessPoliciesRequest request) { + auto span = internal::MakeSpan( + "bigquerycontrol_row_access_policy_v2::RowAccessPolicyServiceConnection::" + "ListRowAccessPolicies"); + internal::OTelScope scope(span); + auto sr = child_->ListRowAccessPolicies(std::move(request)); + return internal::MakeTracedStreamRange< + google::cloud::bigquery::v2::RowAccessPolicy>(std::move(span), + std::move(sr)); +} + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +std::shared_ptr< + bigquerycontrol_row_access_policy_v2::RowAccessPolicyServiceConnection> +MakeRowAccessPolicyServiceTracingConnection( + std::shared_ptr< + bigquerycontrol_row_access_policy_v2::RowAccessPolicyServiceConnection> + conn) { +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + if (internal::TracingEnabled(conn->options())) { + conn = std::make_shared( + std::move(conn)); + } +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + return conn; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_row_access_policy_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_tracing_connection.h b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_tracing_connection.h new file mode 100644 index 0000000000000..e9cecdadb472b --- /dev/null +++ b/google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_tracing_connection.h @@ -0,0 +1,77 @@ +// Copyright 2024 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/v2/row_access_policy.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_INTERNAL_ROW_ACCESS_POLICY_TRACING_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_INTERNAL_ROW_ACCESS_POLICY_TRACING_CONNECTION_H + +#include "google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_connection.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_row_access_policy_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +class RowAccessPolicyServiceTracingConnection + : public bigquerycontrol_row_access_policy_v2:: + RowAccessPolicyServiceConnection { + public: + ~RowAccessPolicyServiceTracingConnection() override = default; + + explicit RowAccessPolicyServiceTracingConnection( + std::shared_ptr + child); + + Options options() override { return child_->options(); } + + StreamRange + ListRowAccessPolicies( + google::cloud::bigquery::v2::ListRowAccessPoliciesRequest request) + override; + + private: + std::shared_ptr< + bigquerycontrol_row_access_policy_v2::RowAccessPolicyServiceConnection> + child_; +}; + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +/** + * Conditionally applies the tracing decorator to the given connection. + * + * The connection is only decorated if tracing is enabled (as determined by the + * connection's options). + */ +std::shared_ptr< + bigquerycontrol_row_access_policy_v2::RowAccessPolicyServiceConnection> +MakeRowAccessPolicyServiceTracingConnection( + std::shared_ptr< + bigquerycontrol_row_access_policy_v2::RowAccessPolicyServiceConnection> + conn); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_row_access_policy_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_INTERNAL_ROW_ACCESS_POLICY_TRACING_CONNECTION_H diff --git a/google/cloud/bigquerycontrol/row_access_policy/v2/mocks/mock_row_access_policy_connection.h b/google/cloud/bigquerycontrol/row_access_policy/v2/mocks/mock_row_access_policy_connection.h new file mode 100644 index 0000000000000..7db3952f8667a --- /dev/null +++ b/google/cloud/bigquerycontrol/row_access_policy/v2/mocks/mock_row_access_policy_connection.h @@ -0,0 +1,63 @@ +// Copyright 2024 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/v2/row_access_policy.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_MOCKS_MOCK_ROW_ACCESS_POLICY_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_MOCKS_MOCK_ROW_ACCESS_POLICY_CONNECTION_H + +#include "google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_connection.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_row_access_policy_v2_mocks { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * A class to mock `RowAccessPolicyServiceConnection`. + * + * Application developers may want to test their code with simulated responses, + * including errors, from an object of type `RowAccessPolicyServiceClient`. To + * do so, construct an object of type `RowAccessPolicyServiceClient` 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]: @cloud_cpp_docs_link{bigquery,bigquery-read-mock} + */ +class MockRowAccessPolicyServiceConnection + : public bigquerycontrol_row_access_policy_v2:: + RowAccessPolicyServiceConnection { + public: + MOCK_METHOD(Options, options, (), (override)); + + MOCK_METHOD( + (StreamRange), + ListRowAccessPolicies, + (google::cloud::bigquery::v2::ListRowAccessPoliciesRequest request), + (override)); +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_row_access_policy_v2_mocks +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_MOCKS_MOCK_ROW_ACCESS_POLICY_CONNECTION_H diff --git a/google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_client.cc b/google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_client.cc new file mode 100644 index 0000000000000..7cfb8a01752de --- /dev/null +++ b/google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_client.cc @@ -0,0 +1,46 @@ +// Copyright 2024 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/v2/row_access_policy.proto + +#include "google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_client.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_row_access_policy_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +RowAccessPolicyServiceClient::RowAccessPolicyServiceClient( + std::shared_ptr connection, Options opts) + : connection_(std::move(connection)), + options_( + internal::MergeOptions(std::move(opts), connection_->options())) {} +RowAccessPolicyServiceClient::~RowAccessPolicyServiceClient() = default; + +StreamRange +RowAccessPolicyServiceClient::ListRowAccessPolicies( + google::cloud::bigquery::v2::ListRowAccessPoliciesRequest request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->ListRowAccessPolicies(std::move(request)); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_row_access_policy_v2 +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_client.h b/google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_client.h new file mode 100644 index 0000000000000..208007b3f0965 --- /dev/null +++ b/google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_client.h @@ -0,0 +1,142 @@ +// Copyright 2024 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/v2/row_access_policy.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_ROW_ACCESS_POLICY_CLIENT_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_ROW_ACCESS_POLICY_CLIENT_H + +#include "google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_rest_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 bigquerycontrol_row_access_policy_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// +/// Service for interacting with row access policies. +/// +/// @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 RowAccessPolicyServiceClient { + public: + explicit RowAccessPolicyServiceClient( + std::shared_ptr connection, + Options opts = {}); + ~RowAccessPolicyServiceClient(); + + ///@{ + /// @name Copy and move support + RowAccessPolicyServiceClient(RowAccessPolicyServiceClient const&) = default; + RowAccessPolicyServiceClient& operator=(RowAccessPolicyServiceClient const&) = + default; + RowAccessPolicyServiceClient(RowAccessPolicyServiceClient&&) = default; + RowAccessPolicyServiceClient& operator=(RowAccessPolicyServiceClient&&) = + default; + ///@} + + ///@{ + /// @name Equality + friend bool operator==(RowAccessPolicyServiceClient const& a, + RowAccessPolicyServiceClient const& b) { + return a.connection_ == b.connection_; + } + friend bool operator!=(RowAccessPolicyServiceClient const& a, + RowAccessPolicyServiceClient const& b) { + return !(a == b); + } + ///@} + + // clang-format off + /// + /// Lists all row access policies on the specified table. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.ListRowAccessPoliciesRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return a [StreamRange](@ref google::cloud::StreamRange) + /// to iterate of the results. See the documentation of this type for + /// details. In brief, this class has `begin()` and `end()` member + /// functions returning a iterator class meeting the + /// [input iterator requirements]. The value type for this iterator is a + /// [`StatusOr`] as the iteration may fail even after some values are + /// retrieved successfully, for example, if there is a network disconnect. + /// An empty set of results does not indicate an error, it indicates + /// that there are no resources meeting the request criteria. + /// On a successful iteration the `StatusOr` contains elements of type + /// [google.cloud.bigquery.v2.RowAccessPolicy], or rather, + /// the C++ class generated by Protobuf from that type. Please consult the + /// Protobuf documentation for details on the [Protobuf mapping rules]. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.ListRowAccessPoliciesRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/row_access_policy.proto#L48} + /// [google.cloud.bigquery.v2.RowAccessPolicy]: @googleapis_reference_link{google/cloud/bigquery/v2/row_access_policy.proto#L79} + /// + // clang-format on + StreamRange + ListRowAccessPolicies( + google::cloud::bigquery::v2::ListRowAccessPoliciesRequest request, + Options opts = {}); + + private: + std::shared_ptr connection_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_row_access_policy_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_ROW_ACCESS_POLICY_CLIENT_H diff --git a/google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_connection.cc b/google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_connection.cc new file mode 100644 index 0000000000000..6ba003c539b55 --- /dev/null +++ b/google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_connection.cc @@ -0,0 +1,50 @@ +// Copyright 2024 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/v2/row_access_policy.proto + +#include "google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_connection.h" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_option_defaults.h" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_tracing_connection.h" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_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 "google/cloud/internal/unified_grpc_credentials.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_row_access_policy_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +RowAccessPolicyServiceConnection::~RowAccessPolicyServiceConnection() = default; + +StreamRange +RowAccessPolicyServiceConnection::ListRowAccessPolicies( + google::cloud::bigquery::v2:: + ListRowAccessPoliciesRequest) { // NOLINT(performance-unnecessary-value-param) + return google::cloud::internal::MakeUnimplementedPaginationRange< + StreamRange>(); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_row_access_policy_v2 +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_connection.h b/google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_connection.h new file mode 100644 index 0000000000000..9a97142bbdb06 --- /dev/null +++ b/google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_connection.h @@ -0,0 +1,205 @@ +// Copyright 2024 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/v2/row_access_policy.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_ROW_ACCESS_POLICY_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_ROW_ACCESS_POLICY_CONNECTION_H + +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_retry_traits.h" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_connection_idempotency_policy.h" +#include "google/cloud/backoff_policy.h" +#include "google/cloud/experimental_tag.h" +#include "google/cloud/internal/retry_policy_impl.h" +#include "google/cloud/options.h" +#include "google/cloud/status_or.h" +#include "google/cloud/stream_range.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_row_access_policy_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// The retry policy for `RowAccessPolicyServiceConnection`. +class RowAccessPolicyServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `RowAccessPolicyServiceConnection` based on counting + * errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RowAccessPolicyServiceLimitedErrorCountRetryPolicy + : public RowAccessPolicyServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit RowAccessPolicyServiceLimitedErrorCountRetryPolicy( + int maximum_failures) + : impl_(maximum_failures) {} + + RowAccessPolicyServiceLimitedErrorCountRetryPolicy( + RowAccessPolicyServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : RowAccessPolicyServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + RowAccessPolicyServiceLimitedErrorCountRetryPolicy( + RowAccessPolicyServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : RowAccessPolicyServiceLimitedErrorCountRetryPolicy( + rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = RowAccessPolicyServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + bigquerycontrol_row_access_policy_v2_internal:: + RowAccessPolicyServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `RowAccessPolicyServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class RowAccessPolicyServiceLimitedTimeRetryPolicy + : public RowAccessPolicyServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit RowAccessPolicyServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + RowAccessPolicyServiceLimitedTimeRetryPolicy( + RowAccessPolicyServiceLimitedTimeRetryPolicy&& rhs) noexcept + : RowAccessPolicyServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + RowAccessPolicyServiceLimitedTimeRetryPolicy( + RowAccessPolicyServiceLimitedTimeRetryPolicy const& rhs) noexcept + : RowAccessPolicyServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = RowAccessPolicyServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + bigquerycontrol_row_access_policy_v2_internal:: + RowAccessPolicyServiceRetryTraits> + impl_; +}; + +/** + * The `RowAccessPolicyServiceConnection` object for + * `RowAccessPolicyServiceClient`. + * + * This interface defines virtual methods for each of the user-facing overload + * sets in `RowAccessPolicyServiceClient`. This allows users to inject custom + * behavior (e.g., with a Google Mock object) when writing tests that use + * objects of type `RowAccessPolicyServiceClient`. + * + * To create a concrete instance, see `MakeRowAccessPolicyServiceConnection()`. + * + * For mocking, see + * `bigquerycontrol_row_access_policy_v2_mocks::MockRowAccessPolicyServiceConnection`. + */ +class RowAccessPolicyServiceConnection { + public: + virtual ~RowAccessPolicyServiceConnection() = 0; + + virtual Options options() { return Options{}; } + + virtual StreamRange + ListRowAccessPolicies( + google::cloud::bigquery::v2::ListRowAccessPoliciesRequest request); +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_row_access_policy_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_ROW_ACCESS_POLICY_CONNECTION_H diff --git a/google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_connection_idempotency_policy.cc b/google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_connection_idempotency_policy.cc new file mode 100644 index 0000000000000..3e8b5ab8651ea --- /dev/null +++ b/google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_connection_idempotency_policy.cc @@ -0,0 +1,52 @@ +// Copyright 2024 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/v2/row_access_policy.proto + +#include "google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_connection_idempotency_policy.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_row_access_policy_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +using ::google::cloud::Idempotency; + +RowAccessPolicyServiceConnectionIdempotencyPolicy:: + ~RowAccessPolicyServiceConnectionIdempotencyPolicy() = default; + +std::unique_ptr +RowAccessPolicyServiceConnectionIdempotencyPolicy::clone() const { + return std::make_unique( + *this); +} + +Idempotency +RowAccessPolicyServiceConnectionIdempotencyPolicy::ListRowAccessPolicies( + google::cloud::bigquery::v2::ListRowAccessPoliciesRequest) { // NOLINT + return Idempotency::kIdempotent; +} + +std::unique_ptr +MakeDefaultRowAccessPolicyServiceConnectionIdempotencyPolicy() { + return std::make_unique(); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_row_access_policy_v2 +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_connection_idempotency_policy.h b/google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_connection_idempotency_policy.h new file mode 100644 index 0000000000000..1772aa3b75d41 --- /dev/null +++ b/google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_connection_idempotency_policy.h @@ -0,0 +1,52 @@ +// Copyright 2024 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/v2/row_access_policy.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_ROW_ACCESS_POLICY_CONNECTION_IDEMPOTENCY_POLICY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_ROW_ACCESS_POLICY_CONNECTION_IDEMPOTENCY_POLICY_H + +#include "google/cloud/idempotency.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_row_access_policy_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class RowAccessPolicyServiceConnectionIdempotencyPolicy { + public: + virtual ~RowAccessPolicyServiceConnectionIdempotencyPolicy(); + + /// Create a new copy of this object. + virtual std::unique_ptr + clone() const; + + virtual google::cloud::Idempotency ListRowAccessPolicies( + google::cloud::bigquery::v2::ListRowAccessPoliciesRequest request); +}; + +std::unique_ptr +MakeDefaultRowAccessPolicyServiceConnectionIdempotencyPolicy(); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_row_access_policy_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_ROW_ACCESS_POLICY_CONNECTION_IDEMPOTENCY_POLICY_H diff --git a/google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_options.h b/google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_options.h new file mode 100644 index 0000000000000..93d01a0fdeece --- /dev/null +++ b/google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_options.h @@ -0,0 +1,77 @@ +// Copyright 2024 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/v2/row_access_policy.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_ROW_ACCESS_POLICY_OPTIONS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_ROW_ACCESS_POLICY_OPTIONS_H + +#include "google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_connection.h" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_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 bigquerycontrol_row_access_policy_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * Use with `google::cloud::Options` to configure the retry policy. + * + * @ingroup google-cloud-bigquerycontrol-options + */ +struct RowAccessPolicyServiceRetryPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure the backoff policy. + * + * @ingroup google-cloud-bigquerycontrol-options + */ +struct RowAccessPolicyServiceBackoffPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure which operations are retried. + * + * @ingroup google-cloud-bigquerycontrol-options + */ +struct RowAccessPolicyServiceConnectionIdempotencyPolicyOption { + using Type = + std::shared_ptr; +}; + +/** + * The options applicable to RowAccessPolicyService. + * + * @ingroup google-cloud-bigquerycontrol-options + */ +using RowAccessPolicyServicePolicyOptionList = + OptionList; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_row_access_policy_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_ROW_ACCESS_POLICY_OPTIONS_H diff --git a/google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_rest_connection.cc b/google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_rest_connection.cc new file mode 100644 index 0000000000000..f758acc58d59b --- /dev/null +++ b/google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_rest_connection.cc @@ -0,0 +1,60 @@ +// Copyright 2024 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/v2/row_access_policy.proto + +#include "google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_rest_connection.h" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_option_defaults.h" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_connection_impl.h" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_rest_stub_factory.h" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/internal/row_access_policy_tracing_connection.h" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_options.h" +#include "google/cloud/common_options.h" +#include "google/cloud/credentials.h" +#include "google/cloud/internal/rest_background_threads_impl.h" +#include "google/cloud/internal/rest_options.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_row_access_policy_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr +MakeRowAccessPolicyServiceConnectionRest(Options options) { + internal::CheckExpectedOptions( + options, __func__); + options = bigquerycontrol_row_access_policy_v2_internal:: + RowAccessPolicyServiceDefaultOptions(std::move(options)); + auto background = std::make_unique< + rest_internal::AutomaticallyCreatedRestBackgroundThreads>(); + auto stub = bigquerycontrol_row_access_policy_v2_internal:: + CreateDefaultRowAccessPolicyServiceRestStub(options); + return bigquerycontrol_row_access_policy_v2_internal:: + MakeRowAccessPolicyServiceTracingConnection( + std::make_shared( + std::move(background), std::move(stub), std::move(options))); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_row_access_policy_v2 +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_rest_connection.h b/google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_rest_connection.h new file mode 100644 index 0000000000000..cf67a834391b7 --- /dev/null +++ b/google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_rest_connection.h @@ -0,0 +1,66 @@ +// Copyright 2024 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/v2/row_access_policy.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_ROW_ACCESS_POLICY_REST_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_ROW_ACCESS_POLICY_REST_CONNECTION_H + +#include "google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_connection.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_row_access_policy_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * A factory function to construct an object of type + * `RowAccessPolicyServiceConnection` that uses REST over HTTP as transport in + * lieu of gRPC. REST transport should only be used for services that do not + * support gRPC or if the existing network configuration precludes using gRPC. + * + * The returned connection object should not be used directly; instead it + * should be passed as an argument to the constructor of + * RowAccessPolicyServiceClient. + * + * The optional @p options argument may be used to configure aspects of the + * returned `RowAccessPolicyServiceConnection`. Expected options are any of the + * types in the following option lists: + * + * - `google::cloud::CommonOptionList` + * - `google::cloud::RestOptionList` + * - `google::cloud::UnifiedCredentialsOptionList` + * - + * `google::cloud::bigquerycontrol_row_access_policy_v2::RowAccessPolicyServicePolicyOptionList` + * + * @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 `RowAccessPolicyServiceConnection` + * created by this function. + */ +std::shared_ptr +MakeRowAccessPolicyServiceConnectionRest(Options options = {}); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_row_access_policy_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_ROW_ACCESS_POLICY_V2_ROW_ACCESS_POLICY_REST_CONNECTION_H diff --git a/google/cloud/bigquerycontrol/row_access_policy/v2/samples/row_access_policy_client_samples.cc b/google/cloud/bigquerycontrol/row_access_policy/v2/samples/row_access_policy_client_samples.cc new file mode 100644 index 0000000000000..8fb36480702b5 --- /dev/null +++ b/google/cloud/bigquerycontrol/row_access_policy/v2/samples/row_access_policy_client_samples.cc @@ -0,0 +1,168 @@ +// Copyright 2024 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/v2/row_access_policy.proto + +#include "google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_client.h" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_connection_idempotency_policy.h" +#include "google/cloud/bigquerycontrol/row_access_policy/v2/row_access_policy_options.h" +#include "google/cloud/common_options.h" +#include "google/cloud/credentials.h" +#include "google/cloud/internal/getenv.h" +#include "google/cloud/testing_util/example_driver.h" +#include +#include +#include +#include + +// clang-format off +// main-dox-marker: bigquerycontrol_row_access_policy_v2::RowAccessPolicyServiceClient +// clang-format on +namespace { + +void SetClientEndpoint(std::vector const& argv) { + if (!argv.empty()) { + throw google::cloud::testing_util::Usage{"set-client-endpoint"}; + } + //! [set-client-endpoint] + // This configuration is common with Private Google Access: + // https://cloud.google.com/vpc/docs/private-google-access + auto options = google::cloud::Options{}.set( + "private.googleapis.com"); + auto client = google::cloud::bigquerycontrol_row_access_policy_v2:: + RowAccessPolicyServiceClient( + google::cloud::bigquerycontrol_row_access_policy_v2:: + MakeRowAccessPolicyServiceConnectionRest(options)); + //! [set-client-endpoint] +} + +//! [custom-idempotency-policy] +class CustomIdempotencyPolicy + : public google::cloud::bigquerycontrol_row_access_policy_v2:: + RowAccessPolicyServiceConnectionIdempotencyPolicy { + public: + ~CustomIdempotencyPolicy() override = default; + std::unique_ptr + clone() const override { + return std::make_unique(*this); + } + // Override inherited functions to define as needed. +}; +//! [custom-idempotency-policy] + +void SetRetryPolicy(std::vector const& argv) { + if (!argv.empty()) { + throw google::cloud::testing_util::Usage{"set-client-retry-policy"}; + } + //! [set-retry-policy] + auto options = + google::cloud::Options{} + .set( + CustomIdempotencyPolicy().clone()) + .set( + google::cloud::bigquerycontrol_row_access_policy_v2:: + RowAccessPolicyServiceLimitedErrorCountRetryPolicy(3) + .clone()) + .set( + google::cloud::ExponentialBackoffPolicy( + /*initial_delay=*/std::chrono::milliseconds(200), + /*maximum_delay=*/std::chrono::seconds(45), + /*scaling=*/2.0) + .clone()); + auto connection = google::cloud::bigquerycontrol_row_access_policy_v2:: + MakeRowAccessPolicyServiceConnectionRest(options); + + // c1 and c2 share the same retry policies + auto c1 = google::cloud::bigquerycontrol_row_access_policy_v2:: + RowAccessPolicyServiceClient(connection); + auto c2 = google::cloud::bigquerycontrol_row_access_policy_v2:: + RowAccessPolicyServiceClient(connection); + + // You can override any of the policies in a new client. This new client + // will share the policies from c1 (or c2) *except* for the retry policy. + auto c3 = google::cloud::bigquerycontrol_row_access_policy_v2:: + RowAccessPolicyServiceClient( + connection, + google::cloud::Options{} + .set( + google::cloud::bigquerycontrol_row_access_policy_v2:: + RowAccessPolicyServiceLimitedTimeRetryPolicy( + std::chrono::minutes(5)) + .clone())); + + // You can also override the policies in a single call: + // c3.SomeRpc(..., google::cloud::Options{} + // .set( + // google::cloud::bigquerycontrol_row_access_policy_v2::RowAccessPolicyServiceLimitedErrorCountRetryPolicy(10).clone())); + //! [set-retry-policy] +} + +void WithServiceAccount(std::vector const& argv) { + if (argv.size() != 1 || argv[0] == "--help") { + throw google::cloud::testing_util::Usage{"with-service-account "}; + } + //! [with-service-account] + [](std::string const& keyfile) { + auto is = std::ifstream(keyfile); + is.exceptions(std::ios::badbit); // Minimal error handling in examples + auto contents = std::string(std::istreambuf_iterator(is.rdbuf()), {}); + auto options = + google::cloud::Options{}.set( + google::cloud::MakeServiceAccountCredentials(contents)); + return google::cloud::bigquerycontrol_row_access_policy_v2:: + RowAccessPolicyServiceClient( + google::cloud::bigquerycontrol_row_access_policy_v2:: + MakeRowAccessPolicyServiceConnectionRest(options)); + } + //! [with-service-account] + (argv.at(0)); +} + +void AutoRun(std::vector const& argv) { + namespace examples = ::google::cloud::testing_util; + using ::google::cloud::internal::GetEnv; + if (!argv.empty()) throw examples::Usage{"auto"}; + examples::CheckEnvironmentVariablesAreSet( + {"GOOGLE_CLOUD_CPP_TEST_SERVICE_ACCOUNT_KEYFILE"}); + auto const keyfile = + GetEnv("GOOGLE_CLOUD_CPP_TEST_SERVICE_ACCOUNT_KEYFILE").value(); + + std::cout << "\nRunning SetClientEndpoint() example" << std::endl; + SetClientEndpoint({}); + + std::cout << "\nRunning SetRetryPolicy() example" << std::endl; + SetRetryPolicy({}); + + std::cout << "\nRunning WithServiceAccount() example" << std::endl; + WithServiceAccount({keyfile}); +} + +} // namespace + +int main(int argc, char* argv[]) { // NOLINT(bugprone-exception-escape) + google::cloud::testing_util::Example example({ + {"set-client-endpoint", SetClientEndpoint}, + {"set-retry-policy", SetRetryPolicy}, + {"with-service-account", WithServiceAccount}, + {"auto", AutoRun}, + }); + return example.Run(argc, argv); +} diff --git a/google/cloud/bigquerycontrol/table/v2/internal/table_option_defaults.cc b/google/cloud/bigquerycontrol/table/v2/internal/table_option_defaults.cc new file mode 100644 index 0000000000000..00056111bdc3f --- /dev/null +++ b/google/cloud/bigquerycontrol/table/v2/internal/table_option_defaults.cc @@ -0,0 +1,69 @@ +// Copyright 2024 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/v2/table.proto + +#include "google/cloud/bigquerycontrol/table/v2/internal/table_option_defaults.h" +#include "google/cloud/bigquerycontrol/table/v2/table_connection.h" +#include "google/cloud/bigquerycontrol/table/v2/table_options.h" +#include "google/cloud/internal/populate_common_options.h" +#include "google/cloud/internal/populate_grpc_options.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_table_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +namespace { +auto constexpr kBackoffScaling = 2.0; +} // namespace + +Options TableServiceDefaultOptions(Options options) { + options = internal::PopulateCommonOptions( + std::move(options), "GOOGLE_CLOUD_CPP_TABLE_SERVICE_ENDPOINT", "", + "GOOGLE_CLOUD_CPP_TABLE_SERVICE_AUTHORITY", "bigquery.googleapis.com"); + options = internal::PopulateGrpcOptions(std::move(options)); + if (!options.has()) { + options.set( + bigquerycontrol_table_v2::TableServiceLimitedTimeRetryPolicy( + std::chrono::minutes(30)) + .clone()); + } + if (!options + .has()) { + options.set( + ExponentialBackoffPolicy( + std::chrono::seconds(0), std::chrono::seconds(1), + std::chrono::minutes(5), kBackoffScaling, kBackoffScaling) + .clone()); + } + if (!options.has()) { + options.set( + bigquerycontrol_table_v2:: + MakeDefaultTableServiceConnectionIdempotencyPolicy()); + } + + return options; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_table_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/table/v2/internal/table_option_defaults.h b/google/cloud/bigquerycontrol/table/v2/internal/table_option_defaults.h new file mode 100644 index 0000000000000..8b58d32bf3384 --- /dev/null +++ b/google/cloud/bigquerycontrol/table/v2/internal/table_option_defaults.h @@ -0,0 +1,37 @@ +// Copyright 2024 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/v2/table.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_INTERNAL_TABLE_OPTION_DEFAULTS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_INTERNAL_TABLE_OPTION_DEFAULTS_H + +#include "google/cloud/options.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace bigquerycontrol_table_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +Options TableServiceDefaultOptions(Options options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_table_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_INTERNAL_TABLE_OPTION_DEFAULTS_H diff --git a/google/cloud/bigquerycontrol/table/v2/internal/table_rest_connection_impl.cc b/google/cloud/bigquerycontrol/table/v2/internal/table_rest_connection_impl.cc new file mode 100644 index 0000000000000..78394a29caff2 --- /dev/null +++ b/google/cloud/bigquerycontrol/table/v2/internal/table_rest_connection_impl.cc @@ -0,0 +1,154 @@ +// Copyright 2024 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/v2/table.proto + +#include "google/cloud/bigquerycontrol/table/v2/internal/table_rest_connection_impl.h" +#include "google/cloud/bigquerycontrol/table/v2/internal/table_rest_stub_factory.h" +#include "google/cloud/common_options.h" +#include "google/cloud/credentials.h" +#include "google/cloud/internal/pagination_range.h" +#include "google/cloud/internal/rest_retry_loop.h" +#include "google/cloud/rest_options.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_table_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +TableServiceRestConnectionImpl::TableServiceRestConnectionImpl( + std::unique_ptr background, + std::shared_ptr + stub, + Options options) + : background_(std::move(background)), + stub_(std::move(stub)), + options_(internal::MergeOptions(std::move(options), + TableServiceConnection::options())) {} + +StatusOr +TableServiceRestConnectionImpl::GetTable( + google::cloud::bigquery::v2::GetTableRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::rest_internal::RestRetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->GetTable(request), + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::GetTableRequest const& request) { + return stub_->GetTable(rest_context, options, request); + }, + *current, request, __func__); +} + +StatusOr +TableServiceRestConnectionImpl::InsertTable( + google::cloud::bigquery::v2::InsertTableRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::rest_internal::RestRetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->InsertTable(request), + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::InsertTableRequest const& request) { + return stub_->InsertTable(rest_context, options, request); + }, + *current, request, __func__); +} + +StatusOr +TableServiceRestConnectionImpl::PatchTable( + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::rest_internal::RestRetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->PatchTable(request), + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& + request) { + return stub_->PatchTable(rest_context, options, request); + }, + *current, request, __func__); +} + +StatusOr +TableServiceRestConnectionImpl::UpdateTable( + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::rest_internal::RestRetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->UpdateTable(request), + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& + request) { + return stub_->UpdateTable(rest_context, options, request); + }, + *current, request, __func__); +} + +Status TableServiceRestConnectionImpl::DeleteTable( + google::cloud::bigquery::v2::DeleteTableRequest const& request) { + auto current = google::cloud::internal::SaveCurrentOptions(); + return google::cloud::rest_internal::RestRetryLoop( + retry_policy(*current), backoff_policy(*current), + idempotency_policy(*current)->DeleteTable(request), + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::DeleteTableRequest const& request) { + return stub_->DeleteTable(rest_context, options, request); + }, + *current, request, __func__); +} + +StreamRange +TableServiceRestConnectionImpl::ListTables( + google::cloud::bigquery::v2::ListTablesRequest request) { + request.clear_page_token(); + auto current = google::cloud::internal::SaveCurrentOptions(); + auto idempotency = idempotency_policy(*current)->ListTables(request); + char const* function_name = __func__; + return google::cloud::internal::MakePaginationRange< + StreamRange>( + current, std::move(request), + [idempotency, function_name, stub = stub_, + retry = + std::shared_ptr( + retry_policy(*current)), + backoff = std::shared_ptr(backoff_policy(*current))]( + Options const& options, + google::cloud::bigquery::v2::ListTablesRequest const& r) { + return google::cloud::rest_internal::RestRetryLoop( + retry->clone(), backoff->clone(), idempotency, + [stub]( + rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListTablesRequest const& request) { + return stub->ListTables(rest_context, options, request); + }, + options, r, function_name); + }, + [](google::cloud::bigquery::v2::TableList r) { + std::vector result( + r.tables().size()); + auto& messages = *r.mutable_tables(); + std::move(messages.begin(), messages.end(), result.begin()); + return result; + }); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_table_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/table/v2/internal/table_rest_connection_impl.h b/google/cloud/bigquerycontrol/table/v2/internal/table_rest_connection_impl.h new file mode 100644 index 0000000000000..99d554f7ba3e9 --- /dev/null +++ b/google/cloud/bigquerycontrol/table/v2/internal/table_rest_connection_impl.h @@ -0,0 +1,107 @@ +// Copyright 2024 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/v2/table.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_INTERNAL_TABLE_REST_CONNECTION_IMPL_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_INTERNAL_TABLE_REST_CONNECTION_IMPL_H + +#include "google/cloud/bigquerycontrol/table/v2/internal/table_rest_stub.h" +#include "google/cloud/bigquerycontrol/table/v2/internal/table_retry_traits.h" +#include "google/cloud/bigquerycontrol/table/v2/table_connection.h" +#include "google/cloud/bigquerycontrol/table/v2/table_connection_idempotency_policy.h" +#include "google/cloud/bigquerycontrol/table/v2/table_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 bigquerycontrol_table_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class TableServiceRestConnectionImpl + : public bigquerycontrol_table_v2::TableServiceConnection { + public: + ~TableServiceRestConnectionImpl() override = default; + + TableServiceRestConnectionImpl( + std::unique_ptr background, + std::shared_ptr + stub, + Options options); + + Options options() override { return options_; } + + StatusOr GetTable( + google::cloud::bigquery::v2::GetTableRequest const& request) override; + + StatusOr InsertTable( + google::cloud::bigquery::v2::InsertTableRequest const& request) override; + + StatusOr PatchTable( + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request) + override; + + StatusOr UpdateTable( + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request) + override; + + Status DeleteTable( + google::cloud::bigquery::v2::DeleteTableRequest const& request) override; + + StreamRange ListTables( + google::cloud::bigquery::v2::ListTablesRequest request) override; + + private: + static std::unique_ptr + retry_policy(Options const& options) { + return options + .get() + ->clone(); + } + + static std::unique_ptr backoff_policy(Options const& options) { + return options + .get() + ->clone(); + } + + static std::unique_ptr< + bigquerycontrol_table_v2::TableServiceConnectionIdempotencyPolicy> + idempotency_policy(Options const& options) { + return options + .get() + ->clone(); + } + + std::unique_ptr background_; + std::shared_ptr + stub_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_table_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_INTERNAL_TABLE_REST_CONNECTION_IMPL_H diff --git a/google/cloud/bigquerycontrol/table/v2/internal/table_rest_logging_decorator.cc b/google/cloud/bigquerycontrol/table/v2/internal/table_rest_logging_decorator.cc new file mode 100644 index 0000000000000..af6e12fd86a79 --- /dev/null +++ b/google/cloud/bigquerycontrol/table/v2/internal/table_rest_logging_decorator.cc @@ -0,0 +1,112 @@ +// Copyright 2024 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/v2/table.proto + +#include "google/cloud/bigquerycontrol/table/v2/internal/table_rest_logging_decorator.h" +#include "google/cloud/internal/log_wrapper.h" +#include "google/cloud/status_or.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_table_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +TableServiceRestLogging::TableServiceRestLogging( + 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 TableServiceRestLogging::GetTable( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::GetTableRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::GetTableRequest const& request) { + return child_->GetTable(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +StatusOr +TableServiceRestLogging::InsertTable( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::InsertTableRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::InsertTableRequest const& request) { + return child_->InsertTable(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +StatusOr +TableServiceRestLogging::PatchTable( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& + request) { + return child_->PatchTable(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +StatusOr +TableServiceRestLogging::UpdateTable( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& + request) { + return child_->UpdateTable(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +Status TableServiceRestLogging::DeleteTable( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::DeleteTableRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::DeleteTableRequest const& request) { + return child_->DeleteTable(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +StatusOr +TableServiceRestLogging::ListTables( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::ListTablesRequest const& request) { + return google::cloud::internal::LogWrapper( + [this](rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::ListTablesRequest const& request) { + return child_->ListTables(rest_context, options, request); + }, + rest_context, options, request, __func__, tracing_options_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_table_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/table/v2/internal/table_rest_logging_decorator.h b/google/cloud/bigquerycontrol/table/v2/internal/table_rest_logging_decorator.h new file mode 100644 index 0000000000000..dae0cf2184efd --- /dev/null +++ b/google/cloud/bigquerycontrol/table/v2/internal/table_rest_logging_decorator.h @@ -0,0 +1,87 @@ +// Copyright 2024 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/v2/table.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_INTERNAL_TABLE_REST_LOGGING_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_INTERNAL_TABLE_REST_LOGGING_DECORATOR_H + +#include "google/cloud/bigquerycontrol/table/v2/internal/table_rest_stub.h" +#include "google/cloud/future.h" +#include "google/cloud/internal/rest_context.h" +#include "google/cloud/tracing_options.h" +#include "google/cloud/version.h" +#include +#include +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_table_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class TableServiceRestLogging : public TableServiceRestStub { + public: + ~TableServiceRestLogging() override = default; + TableServiceRestLogging(std::shared_ptr child, + TracingOptions tracing_options, + std::set components); + + StatusOr GetTable( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetTableRequest const& request) override; + + StatusOr InsertTable( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::InsertTableRequest const& request) override; + + StatusOr PatchTable( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request) + override; + + StatusOr UpdateTable( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request) + override; + + Status DeleteTable( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::DeleteTableRequest const& request) override; + + StatusOr ListTables( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListTablesRequest const& request) override; + + private: + std::shared_ptr child_; + TracingOptions tracing_options_; + std::set components_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_table_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_INTERNAL_TABLE_REST_LOGGING_DECORATOR_H diff --git a/google/cloud/bigquerycontrol/table/v2/internal/table_rest_metadata_decorator.cc b/google/cloud/bigquerycontrol/table/v2/internal/table_rest_metadata_decorator.cc new file mode 100644 index 0000000000000..dca897b3b0101 --- /dev/null +++ b/google/cloud/bigquerycontrol/table/v2/internal/table_rest_metadata_decorator.cc @@ -0,0 +1,97 @@ +// Copyright 2024 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/v2/table.proto + +#include "google/cloud/bigquerycontrol/table/v2/internal/table_rest_metadata_decorator.h" +#include "google/cloud/internal/absl_str_cat_quiet.h" +#include "google/cloud/internal/api_client_header.h" +#include "google/cloud/internal/rest_set_metadata.h" +#include "google/cloud/status_or.h" +#include "absl/strings/str_format.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_table_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +TableServiceRestMetadata::TableServiceRestMetadata( + std::shared_ptr child, std::string api_client_header) + : child_(std::move(child)), + api_client_header_( + api_client_header.empty() + ? google::cloud::internal::GeneratedLibClientHeader() + : std::move(api_client_header)) {} + +StatusOr TableServiceRestMetadata::GetTable( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::GetTableRequest const& request) { + SetMetadata(rest_context, options); + return child_->GetTable(rest_context, options, request); +} + +StatusOr +TableServiceRestMetadata::InsertTable( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::InsertTableRequest const& request) { + SetMetadata(rest_context, options); + return child_->InsertTable(rest_context, options, request); +} + +StatusOr +TableServiceRestMetadata::PatchTable( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request) { + SetMetadata(rest_context, options); + return child_->PatchTable(rest_context, options, request); +} + +StatusOr +TableServiceRestMetadata::UpdateTable( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request) { + SetMetadata(rest_context, options); + return child_->UpdateTable(rest_context, options, request); +} + +Status TableServiceRestMetadata::DeleteTable( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::DeleteTableRequest const& request) { + SetMetadata(rest_context, options); + return child_->DeleteTable(rest_context, options, request); +} + +StatusOr +TableServiceRestMetadata::ListTables( + rest_internal::RestContext& rest_context, Options const& options, + google::cloud::bigquery::v2::ListTablesRequest const& request) { + SetMetadata(rest_context, options); + return child_->ListTables(rest_context, options, request); +} + +void TableServiceRestMetadata::SetMetadata( + rest_internal::RestContext& rest_context, Options const& options, + std::vector const& params) { + google::cloud::rest_internal::SetMetadata(rest_context, options, params, + api_client_header_); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_table_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/table/v2/internal/table_rest_metadata_decorator.h b/google/cloud/bigquerycontrol/table/v2/internal/table_rest_metadata_decorator.h new file mode 100644 index 0000000000000..352b2a9217543 --- /dev/null +++ b/google/cloud/bigquerycontrol/table/v2/internal/table_rest_metadata_decorator.h @@ -0,0 +1,87 @@ +// Copyright 2024 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/v2/table.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_INTERNAL_TABLE_REST_METADATA_DECORATOR_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_INTERNAL_TABLE_REST_METADATA_DECORATOR_H + +#include "google/cloud/bigquerycontrol/table/v2/internal/table_rest_stub.h" +#include "google/cloud/future.h" +#include "google/cloud/rest_options.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_table_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class TableServiceRestMetadata : public TableServiceRestStub { + public: + ~TableServiceRestMetadata() override = default; + explicit TableServiceRestMetadata(std::shared_ptr child, + std::string api_client_header = ""); + + StatusOr GetTable( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetTableRequest const& request) override; + + StatusOr InsertTable( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::InsertTableRequest const& request) override; + + StatusOr PatchTable( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request) + override; + + StatusOr UpdateTable( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request) + override; + + Status DeleteTable( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::DeleteTableRequest const& request) override; + + StatusOr ListTables( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListTablesRequest const& request) override; + + private: + void SetMetadata(rest_internal::RestContext& rest_context, + Options const& options, + std::vector const& params = {}); + + std::shared_ptr child_; + std::string api_client_header_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_table_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_INTERNAL_TABLE_REST_METADATA_DECORATOR_H diff --git a/google/cloud/bigquerycontrol/table/v2/internal/table_rest_stub.cc b/google/cloud/bigquerycontrol/table/v2/internal/table_rest_stub.cc new file mode 100644 index 0000000000000..e46f0eb9d20a5 --- /dev/null +++ b/google/cloud/bigquerycontrol/table/v2/internal/table_rest_stub.cc @@ -0,0 +1,135 @@ +// Copyright 2024 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/v2/table.proto + +#include "google/cloud/bigquerycontrol/table/v2/internal/table_rest_stub.h" +#include "google/cloud/common_options.h" +#include "google/cloud/internal/absl_str_cat_quiet.h" +#include "google/cloud/internal/rest_stub_helpers.h" +#include "google/cloud/status_or.h" +#include +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_table_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +DefaultTableServiceRestStub::DefaultTableServiceRestStub(Options options) + : service_(rest_internal::MakePooledRestClient( + options.get(), options)), + options_(std::move(options)) {} + +DefaultTableServiceRestStub::DefaultTableServiceRestStub( + std::shared_ptr service, Options options) + : service_(std::move(service)), options_(std::move(options)) {} + +StatusOr +DefaultTableServiceRestStub::GetTable( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetTableRequest const& request) { + return rest_internal::Get( + *service_, rest_context, request, false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "datasets", "/", + request.dataset_id(), "/", "tables", "/", + request.table_id()), + rest_internal::TrimEmptyQueryParameters( + {std::make_pair("selected_fields", request.selected_fields()), + std::make_pair("view", std::to_string(request.view()))})); +} + +StatusOr +DefaultTableServiceRestStub::InsertTable( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::InsertTableRequest const& request) { + return rest_internal::Post( + *service_, rest_context, request.table(), false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "datasets", "/", + request.dataset_id(), "/", "tables")); +} + +StatusOr +DefaultTableServiceRestStub::PatchTable( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request) { + return rest_internal::Patch( + *service_, rest_context, request.table(), false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "datasets", "/", + request.dataset_id(), "/", "tables", "/", + request.table_id()), + rest_internal::TrimEmptyQueryParameters({std::make_pair( + "autodetect_schema", request.autodetect_schema() ? "1" : "0")})); +} + +StatusOr +DefaultTableServiceRestStub::UpdateTable( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request) { + return rest_internal::Put( + *service_, rest_context, request.table(), false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "datasets", "/", + request.dataset_id(), "/", "tables", "/", + request.table_id()), + rest_internal::TrimEmptyQueryParameters({std::make_pair( + "autodetect_schema", request.autodetect_schema() ? "1" : "0")})); +} + +Status DefaultTableServiceRestStub::DeleteTable( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::DeleteTableRequest const& request) { + return rest_internal::Delete( + *service_, rest_context, request, false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "datasets", "/", + request.dataset_id(), "/", "tables", "/", + request.table_id())); +} + +StatusOr +DefaultTableServiceRestStub::ListTables( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListTablesRequest const& request) { + return rest_internal::Get( + *service_, rest_context, request, false, + absl::StrCat("/", "bigquery", "/", + rest_internal::DetermineApiVersion("v2", options), "/", + "projects", "/", request.project_id(), "/", "datasets", "/", + request.dataset_id(), "/", "tables"), + rest_internal::TrimEmptyQueryParameters( + {std::make_pair("page_token", request.page_token())})); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_table_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/table/v2/internal/table_rest_stub.h b/google/cloud/bigquerycontrol/table/v2/internal/table_rest_stub.h new file mode 100644 index 0000000000000..707e8d382cbee --- /dev/null +++ b/google/cloud/bigquerycontrol/table/v2/internal/table_rest_stub.h @@ -0,0 +1,122 @@ +// Copyright 2024 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/v2/table.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_INTERNAL_TABLE_REST_STUB_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_INTERNAL_TABLE_REST_STUB_H + +#include "google/cloud/completion_queue.h" +#include "google/cloud/internal/rest_client.h" +#include "google/cloud/internal/rest_context.h" +#include "google/cloud/status_or.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_table_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class TableServiceRestStub { + public: + virtual ~TableServiceRestStub() = default; + + virtual StatusOr GetTable( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetTableRequest const& request) = 0; + + virtual StatusOr InsertTable( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::InsertTableRequest const& request) = 0; + + virtual StatusOr PatchTable( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& + request) = 0; + + virtual StatusOr UpdateTable( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& + request) = 0; + + virtual Status DeleteTable( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::DeleteTableRequest const& request) = 0; + + virtual StatusOr ListTables( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListTablesRequest const& request) = 0; +}; + +class DefaultTableServiceRestStub : public TableServiceRestStub { + public: + ~DefaultTableServiceRestStub() override = default; + + explicit DefaultTableServiceRestStub(Options options); + DefaultTableServiceRestStub( + std::shared_ptr service, Options options); + + StatusOr GetTable( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::GetTableRequest const& request) override; + + StatusOr InsertTable( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::InsertTableRequest const& request) override; + + StatusOr PatchTable( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request) + override; + + StatusOr UpdateTable( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request) + override; + + Status DeleteTable( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::DeleteTableRequest const& request) override; + + StatusOr ListTables( + google::cloud::rest_internal::RestContext& rest_context, + Options const& options, + google::cloud::bigquery::v2::ListTablesRequest const& request) override; + + private: + std::shared_ptr service_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_table_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_INTERNAL_TABLE_REST_STUB_H diff --git a/google/cloud/bigquerycontrol/table/v2/internal/table_rest_stub_factory.cc b/google/cloud/bigquerycontrol/table/v2/internal/table_rest_stub_factory.cc new file mode 100644 index 0000000000000..7d2212a7f247d --- /dev/null +++ b/google/cloud/bigquerycontrol/table/v2/internal/table_rest_stub_factory.cc @@ -0,0 +1,56 @@ +// Copyright 2024 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/v2/table.proto + +#include "google/cloud/bigquerycontrol/table/v2/internal/table_rest_stub_factory.h" +#include "google/cloud/bigquerycontrol/table/v2/internal/table_rest_logging_decorator.h" +#include "google/cloud/bigquerycontrol/table/v2/internal/table_rest_metadata_decorator.h" +#include "google/cloud/bigquerycontrol/table/v2/internal/table_rest_stub.h" +#include "google/cloud/common_options.h" +#include "google/cloud/internal/algorithm.h" +#include "google/cloud/internal/populate_rest_options.h" +#include "google/cloud/log.h" +#include "google/cloud/options.h" +#include "google/cloud/rest_options.h" +#include "absl/strings/match.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_table_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultTableServiceRestStub( + Options const& options) { + auto opts = internal::PopulateRestOptions(options); + std::shared_ptr stub = + std::make_shared(std::move(opts)); + stub = std::make_shared(std::move(stub)); + if (internal::Contains(options.get(), "rpc")) { + GCP_LOG(INFO) << "Enabled logging for REST rpc calls"; + stub = std::make_shared( + std::move(stub), options.get(), + options.get()); + } + return stub; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_table_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/table/v2/internal/table_rest_stub_factory.h b/google/cloud/bigquerycontrol/table/v2/internal/table_rest_stub_factory.h new file mode 100644 index 0000000000000..650e362baae85 --- /dev/null +++ b/google/cloud/bigquerycontrol/table/v2/internal/table_rest_stub_factory.h @@ -0,0 +1,40 @@ +// Copyright 2024 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/v2/table.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_INTERNAL_TABLE_REST_STUB_FACTORY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_INTERNAL_TABLE_REST_STUB_FACTORY_H + +#include "google/cloud/bigquerycontrol/table/v2/internal/table_rest_stub.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_table_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr CreateDefaultTableServiceRestStub( + Options const& options); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_table_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_INTERNAL_TABLE_REST_STUB_FACTORY_H diff --git a/google/cloud/bigquerycontrol/table/v2/internal/table_retry_traits.h b/google/cloud/bigquerycontrol/table/v2/internal/table_retry_traits.h new file mode 100644 index 0000000000000..9b359b08c03ff --- /dev/null +++ b/google/cloud/bigquerycontrol/table/v2/internal/table_retry_traits.h @@ -0,0 +1,43 @@ +// Copyright 2024 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/v2/table.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_INTERNAL_TABLE_RETRY_TRAITS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_INTERNAL_TABLE_RETRY_TRAITS_H + +#include "google/cloud/status.h" +#include "google/cloud/version.h" + +namespace google { +namespace cloud { +namespace bigquerycontrol_table_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// Define the gRPC status code semantics for retrying requests. +struct TableServiceRetryTraits { + static bool IsPermanentFailure(google::cloud::Status const& status) { + return status.code() != StatusCode::kOk && + status.code() != StatusCode::kUnavailable; + } +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_table_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_INTERNAL_TABLE_RETRY_TRAITS_H diff --git a/google/cloud/bigquerycontrol/table/v2/internal/table_sources.cc b/google/cloud/bigquerycontrol/table/v2/internal/table_sources.cc new file mode 100644 index 0000000000000..7466eb0e774f1 --- /dev/null +++ b/google/cloud/bigquerycontrol/table/v2/internal/table_sources.cc @@ -0,0 +1,31 @@ +// Copyright 2024 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/v2/table.proto + +// NOLINTBEGIN(bugprone-suspicious-include) +#include "google/cloud/bigquerycontrol/table/v2/internal/table_option_defaults.cc" +#include "google/cloud/bigquerycontrol/table/v2/internal/table_rest_connection_impl.cc" +#include "google/cloud/bigquerycontrol/table/v2/internal/table_rest_logging_decorator.cc" +#include "google/cloud/bigquerycontrol/table/v2/internal/table_rest_metadata_decorator.cc" +#include "google/cloud/bigquerycontrol/table/v2/internal/table_rest_stub.cc" +#include "google/cloud/bigquerycontrol/table/v2/internal/table_rest_stub_factory.cc" +#include "google/cloud/bigquerycontrol/table/v2/internal/table_tracing_connection.cc" +#include "google/cloud/bigquerycontrol/table/v2/table_client.cc" +#include "google/cloud/bigquerycontrol/table/v2/table_connection.cc" +#include "google/cloud/bigquerycontrol/table/v2/table_connection_idempotency_policy.cc" +#include "google/cloud/bigquerycontrol/table/v2/table_rest_connection.cc" +// NOLINTEND(bugprone-suspicious-include) diff --git a/google/cloud/bigquerycontrol/table/v2/internal/table_tracing_connection.cc b/google/cloud/bigquerycontrol/table/v2/internal/table_tracing_connection.cc new file mode 100644 index 0000000000000..38d02ac2a085d --- /dev/null +++ b/google/cloud/bigquerycontrol/table/v2/internal/table_tracing_connection.cc @@ -0,0 +1,108 @@ +// Copyright 2024 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/v2/table.proto + +#include "google/cloud/bigquerycontrol/table/v2/internal/table_tracing_connection.h" +#include "google/cloud/internal/opentelemetry.h" +#include "google/cloud/internal/traced_stream_range.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_table_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +TableServiceTracingConnection::TableServiceTracingConnection( + std::shared_ptr child) + : child_(std::move(child)) {} + +StatusOr +TableServiceTracingConnection::GetTable( + google::cloud::bigquery::v2::GetTableRequest const& request) { + auto span = internal::MakeSpan( + "bigquerycontrol_table_v2::TableServiceConnection::GetTable"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->GetTable(request)); +} + +StatusOr +TableServiceTracingConnection::InsertTable( + google::cloud::bigquery::v2::InsertTableRequest const& request) { + auto span = internal::MakeSpan( + "bigquerycontrol_table_v2::TableServiceConnection::InsertTable"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->InsertTable(request)); +} + +StatusOr +TableServiceTracingConnection::PatchTable( + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request) { + auto span = internal::MakeSpan( + "bigquerycontrol_table_v2::TableServiceConnection::PatchTable"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->PatchTable(request)); +} + +StatusOr +TableServiceTracingConnection::UpdateTable( + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request) { + auto span = internal::MakeSpan( + "bigquerycontrol_table_v2::TableServiceConnection::UpdateTable"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->UpdateTable(request)); +} + +Status TableServiceTracingConnection::DeleteTable( + google::cloud::bigquery::v2::DeleteTableRequest const& request) { + auto span = internal::MakeSpan( + "bigquerycontrol_table_v2::TableServiceConnection::DeleteTable"); + auto scope = opentelemetry::trace::Scope(span); + return internal::EndSpan(*span, child_->DeleteTable(request)); +} + +StreamRange +TableServiceTracingConnection::ListTables( + google::cloud::bigquery::v2::ListTablesRequest request) { + auto span = internal::MakeSpan( + "bigquerycontrol_table_v2::TableServiceConnection::ListTables"); + internal::OTelScope scope(span); + auto sr = child_->ListTables(std::move(request)); + return internal::MakeTracedStreamRange< + google::cloud::bigquery::v2::ListFormatTable>(std::move(span), + std::move(sr)); +} + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +std::shared_ptr +MakeTableServiceTracingConnection( + std::shared_ptr conn) { +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + if (internal::TracingEnabled(conn->options())) { + conn = std::make_shared(std::move(conn)); + } +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + return conn; +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_table_v2_internal +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/table/v2/internal/table_tracing_connection.h b/google/cloud/bigquerycontrol/table/v2/internal/table_tracing_connection.h new file mode 100644 index 0000000000000..67a12440c4e82 --- /dev/null +++ b/google/cloud/bigquerycontrol/table/v2/internal/table_tracing_connection.h @@ -0,0 +1,84 @@ +// Copyright 2024 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/v2/table.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_INTERNAL_TABLE_TRACING_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_INTERNAL_TABLE_TRACING_CONNECTION_H + +#include "google/cloud/bigquerycontrol/table/v2/table_connection.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_table_v2_internal { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +#ifdef GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +class TableServiceTracingConnection + : public bigquerycontrol_table_v2::TableServiceConnection { + public: + ~TableServiceTracingConnection() override = default; + + explicit TableServiceTracingConnection( + std::shared_ptr child); + + Options options() override { return child_->options(); } + + StatusOr GetTable( + google::cloud::bigquery::v2::GetTableRequest const& request) override; + + StatusOr InsertTable( + google::cloud::bigquery::v2::InsertTableRequest const& request) override; + + StatusOr PatchTable( + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request) + override; + + StatusOr UpdateTable( + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request) + override; + + Status DeleteTable( + google::cloud::bigquery::v2::DeleteTableRequest const& request) override; + + StreamRange ListTables( + google::cloud::bigquery::v2::ListTablesRequest request) override; + + private: + std::shared_ptr child_; +}; + +#endif // GOOGLE_CLOUD_CPP_HAVE_OPENTELEMETRY + +/** + * Conditionally applies the tracing decorator to the given connection. + * + * The connection is only decorated if tracing is enabled (as determined by the + * connection's options). + */ +std::shared_ptr +MakeTableServiceTracingConnection( + std::shared_ptr conn); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_table_v2_internal +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_INTERNAL_TABLE_TRACING_CONNECTION_H diff --git a/google/cloud/bigquerycontrol/table/v2/mocks/mock_table_connection.h b/google/cloud/bigquerycontrol/table/v2/mocks/mock_table_connection.h new file mode 100644 index 0000000000000..61393319f895a --- /dev/null +++ b/google/cloud/bigquerycontrol/table/v2/mocks/mock_table_connection.h @@ -0,0 +1,83 @@ +// Copyright 2024 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/v2/table.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_MOCKS_MOCK_TABLE_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_MOCKS_MOCK_TABLE_CONNECTION_H + +#include "google/cloud/bigquerycontrol/table/v2/table_connection.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_table_v2_mocks { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * A class to mock `TableServiceConnection`. + * + * Application developers may want to test their code with simulated responses, + * including errors, from an object of type `TableServiceClient`. To do so, + * construct an object of type `TableServiceClient` 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]: @cloud_cpp_docs_link{bigquery,bigquery-read-mock} + */ +class MockTableServiceConnection + : public bigquerycontrol_table_v2::TableServiceConnection { + public: + MOCK_METHOD(Options, options, (), (override)); + + MOCK_METHOD(StatusOr, GetTable, + (google::cloud::bigquery::v2::GetTableRequest const& request), + (override)); + + MOCK_METHOD(StatusOr, InsertTable, + (google::cloud::bigquery::v2::InsertTableRequest const& request), + (override)); + + MOCK_METHOD( + StatusOr, PatchTable, + (google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request), + (override)); + + MOCK_METHOD( + StatusOr, UpdateTable, + (google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request), + (override)); + + MOCK_METHOD(Status, DeleteTable, + (google::cloud::bigquery::v2::DeleteTableRequest const& request), + (override)); + + MOCK_METHOD((StreamRange), + ListTables, + (google::cloud::bigquery::v2::ListTablesRequest request), + (override)); +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_table_v2_mocks +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_MOCKS_MOCK_TABLE_CONNECTION_H diff --git a/google/cloud/bigquerycontrol/table/v2/samples/table_client_samples.cc b/google/cloud/bigquerycontrol/table/v2/samples/table_client_samples.cc new file mode 100644 index 0000000000000..7adf1c27e2734 --- /dev/null +++ b/google/cloud/bigquerycontrol/table/v2/samples/table_client_samples.cc @@ -0,0 +1,163 @@ +// Copyright 2024 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/v2/table.proto + +#include "google/cloud/bigquerycontrol/table/v2/table_client.h" +#include "google/cloud/bigquerycontrol/table/v2/table_connection_idempotency_policy.h" +#include "google/cloud/bigquerycontrol/table/v2/table_options.h" +#include "google/cloud/common_options.h" +#include "google/cloud/credentials.h" +#include "google/cloud/internal/getenv.h" +#include "google/cloud/testing_util/example_driver.h" +#include +#include +#include +#include + +// clang-format off +// main-dox-marker: bigquerycontrol_table_v2::TableServiceClient +// clang-format on +namespace { + +void SetClientEndpoint(std::vector const& argv) { + if (!argv.empty()) { + throw google::cloud::testing_util::Usage{"set-client-endpoint"}; + } + //! [set-client-endpoint] + // This configuration is common with Private Google Access: + // https://cloud.google.com/vpc/docs/private-google-access + auto options = google::cloud::Options{}.set( + "private.googleapis.com"); + auto client = google::cloud::bigquerycontrol_table_v2::TableServiceClient( + google::cloud::bigquerycontrol_table_v2::MakeTableServiceConnectionRest( + options)); + //! [set-client-endpoint] +} + +//! [custom-idempotency-policy] +class CustomIdempotencyPolicy : public google::cloud::bigquerycontrol_table_v2:: + TableServiceConnectionIdempotencyPolicy { + public: + ~CustomIdempotencyPolicy() override = default; + std::unique_ptr + clone() const override { + return std::make_unique(*this); + } + // Override inherited functions to define as needed. +}; +//! [custom-idempotency-policy] + +void SetRetryPolicy(std::vector const& argv) { + if (!argv.empty()) { + throw google::cloud::testing_util::Usage{"set-client-retry-policy"}; + } + //! [set-retry-policy] + auto options = google::cloud::Options{} + .set( + CustomIdempotencyPolicy().clone()) + .set( + google::cloud::bigquerycontrol_table_v2:: + TableServiceLimitedErrorCountRetryPolicy(3) + .clone()) + .set( + google::cloud::ExponentialBackoffPolicy( + /*initial_delay=*/std::chrono::milliseconds(200), + /*maximum_delay=*/std::chrono::seconds(45), + /*scaling=*/2.0) + .clone()); + auto connection = + google::cloud::bigquerycontrol_table_v2::MakeTableServiceConnectionRest( + options); + + // c1 and c2 share the same retry policies + auto c1 = + google::cloud::bigquerycontrol_table_v2::TableServiceClient(connection); + auto c2 = + google::cloud::bigquerycontrol_table_v2::TableServiceClient(connection); + + // You can override any of the policies in a new client. This new client + // will share the policies from c1 (or c2) *except* for the retry policy. + auto c3 = google::cloud::bigquerycontrol_table_v2::TableServiceClient( + connection, + google::cloud::Options{} + .set( + google::cloud::bigquerycontrol_table_v2:: + TableServiceLimitedTimeRetryPolicy(std::chrono::minutes(5)) + .clone())); + + // You can also override the policies in a single call: + // c3.SomeRpc(..., google::cloud::Options{} + // .set( + // google::cloud::bigquerycontrol_table_v2::TableServiceLimitedErrorCountRetryPolicy(10).clone())); + //! [set-retry-policy] +} + +void WithServiceAccount(std::vector const& argv) { + if (argv.size() != 1 || argv[0] == "--help") { + throw google::cloud::testing_util::Usage{"with-service-account "}; + } + //! [with-service-account] + [](std::string const& keyfile) { + auto is = std::ifstream(keyfile); + is.exceptions(std::ios::badbit); // Minimal error handling in examples + auto contents = std::string(std::istreambuf_iterator(is.rdbuf()), {}); + auto options = + google::cloud::Options{}.set( + google::cloud::MakeServiceAccountCredentials(contents)); + return google::cloud::bigquerycontrol_table_v2::TableServiceClient( + google::cloud::bigquerycontrol_table_v2::MakeTableServiceConnectionRest( + options)); + } + //! [with-service-account] + (argv.at(0)); +} + +void AutoRun(std::vector const& argv) { + namespace examples = ::google::cloud::testing_util; + using ::google::cloud::internal::GetEnv; + if (!argv.empty()) throw examples::Usage{"auto"}; + examples::CheckEnvironmentVariablesAreSet( + {"GOOGLE_CLOUD_CPP_TEST_SERVICE_ACCOUNT_KEYFILE"}); + auto const keyfile = + GetEnv("GOOGLE_CLOUD_CPP_TEST_SERVICE_ACCOUNT_KEYFILE").value(); + + std::cout << "\nRunning SetClientEndpoint() example" << std::endl; + SetClientEndpoint({}); + + std::cout << "\nRunning SetRetryPolicy() example" << std::endl; + SetRetryPolicy({}); + + std::cout << "\nRunning WithServiceAccount() example" << std::endl; + WithServiceAccount({keyfile}); +} + +} // namespace + +int main(int argc, char* argv[]) { // NOLINT(bugprone-exception-escape) + google::cloud::testing_util::Example example({ + {"set-client-endpoint", SetClientEndpoint}, + {"set-retry-policy", SetRetryPolicy}, + {"with-service-account", WithServiceAccount}, + {"auto", AutoRun}, + }); + return example.Run(argc, argv); +} diff --git a/google/cloud/bigquerycontrol/table/v2/table_client.cc b/google/cloud/bigquerycontrol/table/v2/table_client.cc new file mode 100644 index 0000000000000..427786998c1e7 --- /dev/null +++ b/google/cloud/bigquerycontrol/table/v2/table_client.cc @@ -0,0 +1,79 @@ +// Copyright 2024 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/v2/table.proto + +#include "google/cloud/bigquerycontrol/table/v2/table_client.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_table_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +TableServiceClient::TableServiceClient( + std::shared_ptr connection, Options opts) + : connection_(std::move(connection)), + options_( + internal::MergeOptions(std::move(opts), connection_->options())) {} +TableServiceClient::~TableServiceClient() = default; + +StatusOr TableServiceClient::GetTable( + google::cloud::bigquery::v2::GetTableRequest const& request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->GetTable(request); +} + +StatusOr TableServiceClient::InsertTable( + google::cloud::bigquery::v2::InsertTableRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->InsertTable(request); +} + +StatusOr TableServiceClient::PatchTable( + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->PatchTable(request); +} + +StatusOr TableServiceClient::UpdateTable( + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->UpdateTable(request); +} + +Status TableServiceClient::DeleteTable( + google::cloud::bigquery::v2::DeleteTableRequest const& request, + Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->DeleteTable(request); +} + +StreamRange +TableServiceClient::ListTables( + google::cloud::bigquery::v2::ListTablesRequest request, Options opts) { + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); + return connection_->ListTables(std::move(request)); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_table_v2 +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/table/v2/table_client.h b/google/cloud/bigquerycontrol/table/v2/table_client.h new file mode 100644 index 0000000000000..2ecd69dc14dff --- /dev/null +++ b/google/cloud/bigquerycontrol/table/v2/table_client.h @@ -0,0 +1,303 @@ +// Copyright 2024 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/v2/table.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_TABLE_CLIENT_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_TABLE_CLIENT_H + +#include "google/cloud/bigquerycontrol/table/v2/table_rest_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 +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_table_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// +/// This is an experimental RPC service definition for the BigQuery +/// Table Service. +/// +/// It should not be relied on for production use cases at this time. +/// +/// @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 TableServiceClient { + public: + explicit TableServiceClient( + std::shared_ptr connection, Options opts = {}); + ~TableServiceClient(); + + ///@{ + /// @name Copy and move support + TableServiceClient(TableServiceClient const&) = default; + TableServiceClient& operator=(TableServiceClient const&) = default; + TableServiceClient(TableServiceClient&&) = default; + TableServiceClient& operator=(TableServiceClient&&) = default; + ///@} + + ///@{ + /// @name Equality + friend bool operator==(TableServiceClient const& a, + TableServiceClient const& b) { + return a.connection_ == b.connection_; + } + friend bool operator!=(TableServiceClient const& a, + TableServiceClient const& b) { + return !(a == b); + } + ///@} + + // clang-format off + /// + /// Gets the specified table resource by table ID. + /// This method does not return the data in the table, it only returns the + /// table resource, which describes the structure of this table. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.GetTableRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return the result of the RPC. The response message type + /// ([google.cloud.bigquery.v2.Table]) + /// is mapped to a C++ class using the [Protobuf mapping rules]. + /// If the request fails, the [`StatusOr`] contains the error details. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.GetTableRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/table.proto#L550} + /// [google.cloud.bigquery.v2.Table]: @googleapis_reference_link{google/cloud/bigquery/v2/table.proto#L282} + /// + // clang-format on + StatusOr GetTable( + google::cloud::bigquery::v2::GetTableRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Creates a new, empty table in the dataset. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.InsertTableRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return the result of the RPC. The response message type + /// ([google.cloud.bigquery.v2.Table]) + /// is mapped to a C++ class using the [Protobuf mapping rules]. + /// If the request fails, the [`StatusOr`] contains the error details. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.InsertTableRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/table.proto#L597} + /// [google.cloud.bigquery.v2.Table]: @googleapis_reference_link{google/cloud/bigquery/v2/table.proto#L282} + /// + // clang-format on + StatusOr InsertTable( + google::cloud::bigquery::v2::InsertTableRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Updates information in an existing table. The update method replaces the + /// entire table resource, whereas the patch method only replaces fields that + /// are provided in the submitted table resource. + /// This method supports RFC5789 patch semantics. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.UpdateOrPatchTableRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return the result of the RPC. The response message type + /// ([google.cloud.bigquery.v2.Table]) + /// is mapped to a C++ class using the [Protobuf mapping rules]. + /// If the request fails, the [`StatusOr`] contains the error details. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.Table]: @googleapis_reference_link{google/cloud/bigquery/v2/table.proto#L282} + /// [google.cloud.bigquery.v2.UpdateOrPatchTableRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/table.proto#L608} + /// + // clang-format on + StatusOr PatchTable( + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Updates information in an existing table. The update method replaces the + /// entire Table resource, whereas the patch method only replaces fields that + /// are provided in the submitted Table resource. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.UpdateOrPatchTableRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return the result of the RPC. The response message type + /// ([google.cloud.bigquery.v2.Table]) + /// is mapped to a C++ class using the [Protobuf mapping rules]. + /// If the request fails, the [`StatusOr`] contains the error details. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.Table]: @googleapis_reference_link{google/cloud/bigquery/v2/table.proto#L282} + /// [google.cloud.bigquery.v2.UpdateOrPatchTableRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/table.proto#L608} + /// + // clang-format on + StatusOr UpdateTable( + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Deletes the table specified by tableId from the dataset. + /// If the table contains data, all the data will be deleted. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.DeleteTableRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return a [`Status`] object. If the request failed, the + /// status contains the details of the failure. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.DeleteTableRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/table.proto#L626} + /// + // clang-format on + Status DeleteTable( + google::cloud::bigquery::v2::DeleteTableRequest const& request, + Options opts = {}); + + // clang-format off + /// + /// Lists all tables in the specified dataset. Requires the READER dataset + /// role. + /// + /// @param request Unary RPCs, such as the one wrapped by this + /// function, receive a single `request` proto message which includes all + /// the inputs for the RPC. In this case, the proto message is a + /// [google.cloud.bigquery.v2.ListTablesRequest]. + /// Proto messages are converted to C++ classes by Protobuf, using the + /// [Protobuf mapping rules]. + /// @param opts Optional. Override the class-level options, such as retry and + /// backoff policies. + /// @return a [StreamRange](@ref google::cloud::StreamRange) + /// to iterate of the results. See the documentation of this type for + /// details. In brief, this class has `begin()` and `end()` member + /// functions returning a iterator class meeting the + /// [input iterator requirements]. The value type for this iterator is a + /// [`StatusOr`] as the iteration may fail even after some values are + /// retrieved successfully, for example, if there is a network disconnect. + /// An empty set of results does not indicate an error, it indicates + /// that there are no resources meeting the request criteria. + /// On a successful iteration the `StatusOr` contains elements of type + /// [google.cloud.bigquery.v2.ListFormatTable], or rather, + /// the C++ class generated by Protobuf from that type. Please consult the + /// Protobuf documentation for details on the [Protobuf mapping rules]. + /// + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string + /// [`future`]: @ref google::cloud::future + /// [`StatusOr`]: @ref google::cloud::StatusOr + /// [`Status`]: @ref google::cloud::Status + /// [google.cloud.bigquery.v2.ListFormatTable]: @googleapis_reference_link{google/cloud/bigquery/v2/table.proto#L664} + /// [google.cloud.bigquery.v2.ListTablesRequest]: @googleapis_reference_link{google/cloud/bigquery/v2/table.proto#L638} + /// + // clang-format on + StreamRange ListTables( + google::cloud::bigquery::v2::ListTablesRequest request, + Options opts = {}); + + private: + std::shared_ptr connection_; + Options options_; +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_table_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_TABLE_CLIENT_H diff --git a/google/cloud/bigquerycontrol/table/v2/table_connection.cc b/google/cloud/bigquerycontrol/table/v2/table_connection.cc new file mode 100644 index 0000000000000..a1fa0d5c9401b --- /dev/null +++ b/google/cloud/bigquerycontrol/table/v2/table_connection.cc @@ -0,0 +1,77 @@ +// Copyright 2024 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/v2/table.proto + +#include "google/cloud/bigquerycontrol/table/v2/table_connection.h" +#include "google/cloud/bigquerycontrol/table/v2/internal/table_option_defaults.h" +#include "google/cloud/bigquerycontrol/table/v2/internal/table_tracing_connection.h" +#include "google/cloud/bigquerycontrol/table/v2/table_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 "google/cloud/internal/unified_grpc_credentials.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_table_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +TableServiceConnection::~TableServiceConnection() = default; + +StatusOr TableServiceConnection::GetTable( + google::cloud::bigquery::v2::GetTableRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +TableServiceConnection::InsertTable( + google::cloud::bigquery::v2::InsertTableRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr TableServiceConnection::PatchTable( + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StatusOr +TableServiceConnection::UpdateTable( + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +Status TableServiceConnection::DeleteTable( + google::cloud::bigquery::v2::DeleteTableRequest const&) { + return Status(StatusCode::kUnimplemented, "not implemented"); +} + +StreamRange +TableServiceConnection::ListTables( + google::cloud::bigquery::v2:: + ListTablesRequest) { // NOLINT(performance-unnecessary-value-param) + return google::cloud::internal::MakeUnimplementedPaginationRange< + StreamRange>(); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_table_v2 +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/table/v2/table_connection.h b/google/cloud/bigquerycontrol/table/v2/table_connection.h new file mode 100644 index 0000000000000..5f6bcfd465396 --- /dev/null +++ b/google/cloud/bigquerycontrol/table/v2/table_connection.h @@ -0,0 +1,211 @@ +// Copyright 2024 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/v2/table.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_TABLE_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_TABLE_CONNECTION_H + +#include "google/cloud/bigquerycontrol/table/v2/internal/table_retry_traits.h" +#include "google/cloud/bigquerycontrol/table/v2/table_connection_idempotency_policy.h" +#include "google/cloud/backoff_policy.h" +#include "google/cloud/experimental_tag.h" +#include "google/cloud/internal/retry_policy_impl.h" +#include "google/cloud/options.h" +#include "google/cloud/status_or.h" +#include "google/cloud/stream_range.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_table_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/// The retry policy for `TableServiceConnection`. +class TableServiceRetryPolicy : public ::google::cloud::RetryPolicy { + public: + /// Creates a new instance of the policy, reset to the initial state. + virtual std::unique_ptr clone() const = 0; +}; + +/** + * A retry policy for `TableServiceConnection` based on counting errors. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - More than a prescribed number of transient failures is detected. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TableServiceLimitedErrorCountRetryPolicy + : public TableServiceRetryPolicy { + public: + /** + * Create an instance that tolerates up to @p maximum_failures transient + * errors. + * + * @note Disable the retry loop by providing an instance of this policy with + * @p maximum_failures == 0. + */ + explicit TableServiceLimitedErrorCountRetryPolicy(int maximum_failures) + : impl_(maximum_failures) {} + + TableServiceLimitedErrorCountRetryPolicy( + TableServiceLimitedErrorCountRetryPolicy&& rhs) noexcept + : TableServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + TableServiceLimitedErrorCountRetryPolicy( + TableServiceLimitedErrorCountRetryPolicy const& rhs) noexcept + : TableServiceLimitedErrorCountRetryPolicy(rhs.maximum_failures()) {} + + int maximum_failures() const { return impl_.maximum_failures(); } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_failures()); + } + + // This is provided only for backwards compatibility. + using BaseType = TableServiceRetryPolicy; + + private: + google::cloud::internal::LimitedErrorCountRetryPolicy< + bigquerycontrol_table_v2_internal::TableServiceRetryTraits> + impl_; +}; + +/** + * A retry policy for `TableServiceConnection` based on elapsed time. + * + * This policy stops retrying if: + * - An RPC returns a non-transient error. + * - The elapsed time in the retry loop exceeds a prescribed duration. + * + * In this class the following status codes are treated as transient errors: + * - [`kUnavailable`](@ref google::cloud::StatusCode) + */ +class TableServiceLimitedTimeRetryPolicy : public TableServiceRetryPolicy { + public: + /** + * Constructor given a `std::chrono::duration<>` object. + * + * @tparam DurationRep a placeholder to match the `Rep` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the underlying + * arithmetic type used to store the number of ticks. For our purposes it + * is simply a formal parameter. + * @tparam DurationPeriod a placeholder to match the `Period` tparam for @p + * duration's type. The semantics of this template parameter are + * documented in `std::chrono::duration<>`. In brief, the length of the + * tick in seconds, expressed as a `std::ratio<>`. For our purposes it is + * simply a formal parameter. + * @param maximum_duration the maximum time allowed before the policy expires. + * While the application can express this time in any units they desire, + * the class truncates to milliseconds. + * + * @see https://en.cppreference.com/w/cpp/chrono/duration for more information + * about `std::chrono::duration`. + */ + template + explicit TableServiceLimitedTimeRetryPolicy( + std::chrono::duration maximum_duration) + : impl_(maximum_duration) {} + + TableServiceLimitedTimeRetryPolicy( + TableServiceLimitedTimeRetryPolicy&& rhs) noexcept + : TableServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + TableServiceLimitedTimeRetryPolicy( + TableServiceLimitedTimeRetryPolicy const& rhs) noexcept + : TableServiceLimitedTimeRetryPolicy(rhs.maximum_duration()) {} + + std::chrono::milliseconds maximum_duration() const { + return impl_.maximum_duration(); + } + + bool OnFailure(Status const& status) override { + return impl_.OnFailure(status); + } + bool IsExhausted() const override { return impl_.IsExhausted(); } + bool IsPermanentFailure(Status const& status) const override { + return impl_.IsPermanentFailure(status); + } + std::unique_ptr clone() const override { + return std::make_unique( + maximum_duration()); + } + + // This is provided only for backwards compatibility. + using BaseType = TableServiceRetryPolicy; + + private: + google::cloud::internal::LimitedTimeRetryPolicy< + bigquerycontrol_table_v2_internal::TableServiceRetryTraits> + impl_; +}; + +/** + * The `TableServiceConnection` object for `TableServiceClient`. + * + * This interface defines virtual methods for each of the user-facing overload + * sets in `TableServiceClient`. This allows users to inject custom behavior + * (e.g., with a Google Mock object) when writing tests that use objects of type + * `TableServiceClient`. + * + * To create a concrete instance, see `MakeTableServiceConnection()`. + * + * For mocking, see + * `bigquerycontrol_table_v2_mocks::MockTableServiceConnection`. + */ +class TableServiceConnection { + public: + virtual ~TableServiceConnection() = 0; + + virtual Options options() { return Options{}; } + + virtual StatusOr GetTable( + google::cloud::bigquery::v2::GetTableRequest const& request); + + virtual StatusOr InsertTable( + google::cloud::bigquery::v2::InsertTableRequest const& request); + + virtual StatusOr PatchTable( + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request); + + virtual StatusOr UpdateTable( + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request); + + virtual Status DeleteTable( + google::cloud::bigquery::v2::DeleteTableRequest const& request); + + virtual StreamRange ListTables( + google::cloud::bigquery::v2::ListTablesRequest request); +}; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_table_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_TABLE_CONNECTION_H diff --git a/google/cloud/bigquerycontrol/table/v2/table_connection_idempotency_policy.cc b/google/cloud/bigquerycontrol/table/v2/table_connection_idempotency_policy.cc new file mode 100644 index 0000000000000..fc7039a921413 --- /dev/null +++ b/google/cloud/bigquerycontrol/table/v2/table_connection_idempotency_policy.cc @@ -0,0 +1,75 @@ +// Copyright 2024 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/v2/table.proto + +#include "google/cloud/bigquerycontrol/table/v2/table_connection_idempotency_policy.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_table_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +using ::google::cloud::Idempotency; + +TableServiceConnectionIdempotencyPolicy:: + ~TableServiceConnectionIdempotencyPolicy() = default; + +std::unique_ptr +TableServiceConnectionIdempotencyPolicy::clone() const { + return std::make_unique(*this); +} + +Idempotency TableServiceConnectionIdempotencyPolicy::GetTable( + google::cloud::bigquery::v2::GetTableRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency TableServiceConnectionIdempotencyPolicy::InsertTable( + google::cloud::bigquery::v2::InsertTableRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency TableServiceConnectionIdempotencyPolicy::PatchTable( + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency TableServiceConnectionIdempotencyPolicy::UpdateTable( + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const&) { + return Idempotency::kIdempotent; +} + +Idempotency TableServiceConnectionIdempotencyPolicy::DeleteTable( + google::cloud::bigquery::v2::DeleteTableRequest const&) { + return Idempotency::kNonIdempotent; +} + +Idempotency TableServiceConnectionIdempotencyPolicy::ListTables( + google::cloud::bigquery::v2::ListTablesRequest) { // NOLINT + return Idempotency::kIdempotent; +} + +std::unique_ptr +MakeDefaultTableServiceConnectionIdempotencyPolicy() { + return std::make_unique(); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_table_v2 +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/table/v2/table_connection_idempotency_policy.h b/google/cloud/bigquerycontrol/table/v2/table_connection_idempotency_policy.h new file mode 100644 index 0000000000000..ee533de1a4b18 --- /dev/null +++ b/google/cloud/bigquerycontrol/table/v2/table_connection_idempotency_policy.h @@ -0,0 +1,67 @@ +// Copyright 2024 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/v2/table.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_TABLE_CONNECTION_IDEMPOTENCY_POLICY_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_TABLE_CONNECTION_IDEMPOTENCY_POLICY_H + +#include "google/cloud/idempotency.h" +#include "google/cloud/version.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_table_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +class TableServiceConnectionIdempotencyPolicy { + public: + virtual ~TableServiceConnectionIdempotencyPolicy(); + + /// Create a new copy of this object. + virtual std::unique_ptr clone() + const; + + virtual google::cloud::Idempotency GetTable( + google::cloud::bigquery::v2::GetTableRequest const& request); + + virtual google::cloud::Idempotency InsertTable( + google::cloud::bigquery::v2::InsertTableRequest const& request); + + virtual google::cloud::Idempotency PatchTable( + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request); + + virtual google::cloud::Idempotency UpdateTable( + google::cloud::bigquery::v2::UpdateOrPatchTableRequest const& request); + + virtual google::cloud::Idempotency DeleteTable( + google::cloud::bigquery::v2::DeleteTableRequest const& request); + + virtual google::cloud::Idempotency ListTables( + google::cloud::bigquery::v2::ListTablesRequest request); +}; + +std::unique_ptr +MakeDefaultTableServiceConnectionIdempotencyPolicy(); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_table_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_TABLE_CONNECTION_IDEMPOTENCY_POLICY_H diff --git a/google/cloud/bigquerycontrol/table/v2/table_options.h b/google/cloud/bigquerycontrol/table/v2/table_options.h new file mode 100644 index 0000000000000..9c71df23165b2 --- /dev/null +++ b/google/cloud/bigquerycontrol/table/v2/table_options.h @@ -0,0 +1,75 @@ +// Copyright 2024 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/v2/table.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_TABLE_OPTIONS_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_TABLE_OPTIONS_H + +#include "google/cloud/bigquerycontrol/table/v2/table_connection.h" +#include "google/cloud/bigquerycontrol/table/v2/table_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 bigquerycontrol_table_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * Use with `google::cloud::Options` to configure the retry policy. + * + * @ingroup google-cloud-bigquerycontrol-options + */ +struct TableServiceRetryPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure the backoff policy. + * + * @ingroup google-cloud-bigquerycontrol-options + */ +struct TableServiceBackoffPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * Use with `google::cloud::Options` to configure which operations are retried. + * + * @ingroup google-cloud-bigquerycontrol-options + */ +struct TableServiceConnectionIdempotencyPolicyOption { + using Type = std::shared_ptr; +}; + +/** + * The options applicable to TableService. + * + * @ingroup google-cloud-bigquerycontrol-options + */ +using TableServicePolicyOptionList = + OptionList; + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_table_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_TABLE_OPTIONS_H diff --git a/google/cloud/bigquerycontrol/table/v2/table_rest_connection.cc b/google/cloud/bigquerycontrol/table/v2/table_rest_connection.cc new file mode 100644 index 0000000000000..f48a471beff16 --- /dev/null +++ b/google/cloud/bigquerycontrol/table/v2/table_rest_connection.cc @@ -0,0 +1,59 @@ +// Copyright 2024 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/v2/table.proto + +#include "google/cloud/bigquerycontrol/table/v2/table_rest_connection.h" +#include "google/cloud/bigquerycontrol/table/v2/internal/table_option_defaults.h" +#include "google/cloud/bigquerycontrol/table/v2/internal/table_rest_connection_impl.h" +#include "google/cloud/bigquerycontrol/table/v2/internal/table_rest_stub_factory.h" +#include "google/cloud/bigquerycontrol/table/v2/internal/table_tracing_connection.h" +#include "google/cloud/bigquerycontrol/table/v2/table_options.h" +#include "google/cloud/common_options.h" +#include "google/cloud/credentials.h" +#include "google/cloud/internal/rest_background_threads_impl.h" +#include "google/cloud/internal/rest_options.h" +#include +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_table_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +std::shared_ptr MakeTableServiceConnectionRest( + Options options) { + internal::CheckExpectedOptions< + CommonOptionList, RestOptionList, UnifiedCredentialsOptionList, + rest_internal::TargetApiVersionOption, TableServicePolicyOptionList>( + options, __func__); + options = bigquerycontrol_table_v2_internal::TableServiceDefaultOptions( + std::move(options)); + auto background = std::make_unique< + rest_internal::AutomaticallyCreatedRestBackgroundThreads>(); + auto stub = + bigquerycontrol_table_v2_internal::CreateDefaultTableServiceRestStub( + options); + return bigquerycontrol_table_v2_internal::MakeTableServiceTracingConnection( + std::make_shared< + bigquerycontrol_table_v2_internal::TableServiceRestConnectionImpl>( + std::move(background), std::move(stub), std::move(options))); +} + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_table_v2 +} // namespace cloud +} // namespace google diff --git a/google/cloud/bigquerycontrol/table/v2/table_rest_connection.h b/google/cloud/bigquerycontrol/table/v2/table_rest_connection.h new file mode 100644 index 0000000000000..7fec0b3389bd2 --- /dev/null +++ b/google/cloud/bigquerycontrol/table/v2/table_rest_connection.h @@ -0,0 +1,64 @@ +// Copyright 2024 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/v2/table.proto + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_TABLE_REST_CONNECTION_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_TABLE_REST_CONNECTION_H + +#include "google/cloud/bigquerycontrol/table/v2/table_connection.h" +#include "google/cloud/options.h" +#include "google/cloud/version.h" +#include + +namespace google { +namespace cloud { +namespace bigquerycontrol_table_v2 { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN + +/** + * A factory function to construct an object of type `TableServiceConnection` + * that uses REST over HTTP as transport in lieu of gRPC. REST transport should + * only be used for services that do not support gRPC or if the existing network + * configuration precludes using gRPC. + * + * The returned connection object should not be used directly; instead it + * should be passed as an argument to the constructor of TableServiceClient. + * + * The optional @p options argument may be used to configure aspects of the + * returned `TableServiceConnection`. Expected options are any of the types in + * the following option lists: + * + * - `google::cloud::CommonOptionList` + * - `google::cloud::RestOptionList` + * - `google::cloud::UnifiedCredentialsOptionList` + * - `google::cloud::bigquerycontrol_table_v2::TableServicePolicyOptionList` + * + * @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 `TableServiceConnection` created by + * this function. + */ +std::shared_ptr MakeTableServiceConnectionRest( + Options options = {}); + +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace bigquerycontrol_table_v2 +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGQUERYCONTROL_TABLE_V2_TABLE_REST_CONNECTION_H diff --git a/libraries.bzl b/libraries.bzl index 06df6df34f67f..2fe65b72e3663 100644 --- a/libraries.bzl +++ b/libraries.bzl @@ -17,6 +17,7 @@ """Automatically generated unit tests list - DO NOT EDIT.""" GOOGLE_CLOUD_CPP_EXPERIMENTAL_LIBRARIES = [ + "bigquerycontrol", "pubsublite", ]