diff --git a/doc/v3-migration-guide.md b/doc/v3-migration-guide.md
index b2ea23f60a432..f6de9f20fb103 100644
--- a/doc/v3-migration-guide.md
+++ b/doc/v3-migration-guide.md
@@ -487,6 +487,120 @@ internal legacy files.
+
+Removed bigtable::AdminClient and bigtable::TableAdmin
+
+The `bigtable::AdminClient` class and `bigtable::TableAdmin` class have been
+replaced with `bigtable_admin::BigtableTableAdminClient`.
+
+**Before:**
+
+```cpp
+
+std::shared_ptr admin_client =
+ bigtable::MakeAdminClient("project-id");
+auto table_admin = std::make_unique(
+ admin_client, "instance-id");
+
+// Drop a selection of rows by key prefix.
+auto result = table_admin.DropRowByPrefix("table-id", "row-key-prefix");
+
+// Drop all rows.
+result = table_admin.DropAllRows("table-id");
+```
+
+**After:**
+
+```cpp
+#include "google/cloud/bigtable/admin/bigtable_table_admin_client.h"
+
+auto table_admin = bigtable_admin::BigtableTableAdminClient(
+ bigtable_admin::MakeBigtableAdminConnection());
+auto table_name = bigtable::TableName("project-id", "instance-id", "table-id");
+
+// Drop a selection of rows by key prefix.
+google::bigtable::admin::v2::DropRowRangeRequest drop_rows_by_prefix;
+drop_rows_by_prefix.set_name(table_name);
+drop_rows_by_prefix.set_row_key_prefix("row-key-prefix");
+auto result = table_admin.DropRowRange(drop_rows_by_prefix);
+
+// Drop all rows.
+google::bigtable::admin::v2::DropRowRangeRequest drop_all_rows;
+drop_all_rows.set_name(table_name);
+drop_all_rows.set_delete_all_data_from_table(true);
+result = table_admin.DropRowRange(drop_all_rows);
+```
+
+
+
+WaitForConsistency is now a free function
+
+With the removal of the `bigtable::TableAdmin` class, `WaitForConsistency` is
+now a free function.
+
+**Before:**
+
+```cpp
+
+std::shared_ptr admin_client =
+ bigtable::MakeAdminClient("project-id");
+auto table_admin = std::make_unique(
+ admin_client, "instance-id");
+
+auto token = table_admin.GenerateConsistencyToken("table-id");
+if (!token) throw std::runtime_error(token.status().message());
+auto result = table_admin.WaitForConsistency("table-id", *token);
+```
+
+**After:**
+
+```cpp
+#include "google/cloud/bigtable/admin/bigtable_table_admin_client.h"
+#include "google/cloud/bigtable/wait_for_consistency.h"
+
+auto connection = bigtable_admin::MakeBigtableAdminConnection();
+auto table_admin = bigtable_admin::BigtableTableAdminClient(connection);
+auto table_name = bigtable::TableName("project-id", "instance-id", "table-id");
+
+auto token = table_admin.GenerateConsistencyToken(table_name);
+if (!token) throw std::runtime_error(token.status().message());
+auto result = bigtable_admin::WaitForConsistency(connection, table_name,
+ token->consistency_token());
+```
+
+
+
+
+Removed bigtable::InstanceAdminClient and bigtable::InstanceAdmin
+
+The `bigtable::InstanceAdminClient` class and `bigtable::InstanceAdmin` class
+have been replaced with `bigtable_admin::BigtableInstanceAdminClient`.
+
+**Before:**
+
+```cpp
+auto instance_admin_client = bigtable::MakeInstanceAdminClient("project-id");
+auto instance_admin =
+ std::make_unique(instance_admin_client);
+
+auto clusters = instance_admin->ListClusters();
+```
+
+**After:**
+
+```cpp
+#include "google/cloud/bigtable/admin/bigtable_instance_admin_client.h"
+
+auto instance_admin =
+ std::make_unique(
+ bigtable_admin::MakeBigtableInstanceAdminConnection());
+
+auto clusters = instance_admin->ListClusters(
+ InstanceName("project-id", "instance-id"));
+```
+
+
+
### Pubsub
diff --git a/generator/generator_config.proto b/generator/generator_config.proto
index 7743c2e80e90f..ccfda6028c6ca 100644
--- a/generator/generator_config.proto
+++ b/generator/generator_config.proto
@@ -168,11 +168,14 @@ message ServiceConfiguration {
// generated.
bool omit_streaming_updater = 29;
- // In rare cases, specifically bigtable::WaitForConsistency, the
- // CompletionQueue from the BackgroundThreads owned by the Connection is
- // needed elsewhere. This emits a protected accessor and friend function for
- // that purpose.
- bool emit_completion_queue_accessor = 30;
+ message BespokeMethod {
+ string client_comments = 1;
+ string name = 2;
+ string return_type = 3;
+ string parameters = 4;
+ }
+
+ repeated BespokeMethod bespoke_methods = 30;
}
message DiscoveryDocumentDefinedProduct {
diff --git a/generator/generator_config.textproto b/generator/generator_config.textproto
index 380d664e48846..409a353df13ee 100644
--- a/generator/generator_config.textproto
+++ b/generator/generator_config.textproto
@@ -588,7 +588,12 @@ service {
{rpc_name: "BigtableTableAdmin.CheckConsistency", idempotency: IDEMPOTENT}
]
omit_repo_metadata: true
- emit_completion_queue_accessor: true
+ bespoke_methods : [
+ {
+ client_comments: "Polls until the table is consistent or until the retry policy has expired.",
+ name: "WaitForConsistency",
+ return_type: "future>",
+ parameters: "(google::bigtable::admin::v2::CheckConsistencyRequest const& request, Options opts = {})"}]
}
# Billing
diff --git a/generator/internal/client_generator.cc b/generator/internal/client_generator.cc
index 2e81d9431f5a6..2acfc6d584676 100644
--- a/generator/internal/client_generator.cc
+++ b/generator/internal/client_generator.cc
@@ -21,6 +21,7 @@
#include "generator/internal/predicate_utils.h"
#include "generator/internal/printer.h"
#include "absl/strings/str_cat.h"
+#include "absl/strings/str_replace.h"
#include "google/api/client.pb.h"
#include
@@ -380,6 +381,12 @@ R"""( std::unique_ptr<::google::cloud::AsyncStreamingReadWriteRpc<
__FILE__, __LINE__);
}
+ for (auto const& method : bespoke_methods()) {
+ HeaderPrint("\n");
+ HeaderPrint(absl::StrCat(method.return_type(), " ", method.name(),
+ method.parameters(), ";"));
+ }
+
HeaderPrint( // clang-format off
"\n"
" private:\n"
@@ -716,6 +723,19 @@ std::unique_ptr<::google::cloud::AsyncStreamingReadWriteRpc<
__FILE__, __LINE__);
}
+ for (auto const& method : bespoke_methods()) {
+ CcPrint("\n");
+ CcPrint(absl::StrCat(
+ method.return_type(), R"""( $client_class_name$::)""", method.name(),
+ absl::StrReplaceAll(method.parameters(), {{" = {}", ""}}),
+ absl::StrFormat(R"""( {
+ internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_));
+ return connection_->%s(request);
+}
+)""",
+ method.name())));
+ }
+
CcCloseNamespaces();
return {};
}
diff --git a/generator/internal/codegen_utils.cc b/generator/internal/codegen_utils.cc
index 5be555f1918e2..3e5be23b867d1 100644
--- a/generator/internal/codegen_utils.cc
+++ b/generator/internal/codegen_utils.cc
@@ -111,6 +111,11 @@ void ProcessArgOmitRpc(
ProcessRepeated("omit_rpc", "omitted_rpcs", command_line_args);
}
+void ProcessArgBespokeMethod(
+ std::vector>& command_line_args) {
+ ProcessRepeated("bespoke_method", "bespoke_methods", command_line_args);
+}
+
void ProcessArgServiceEndpointEnvVar(
std::vector>& command_line_args) {
auto service_endpoint_env_var =
@@ -269,6 +274,7 @@ ProcessCommandLineArgs(std::string const& parameters) {
ProcessArgCopyrightYear(command_line_args);
ProcessArgOmitService(command_line_args);
ProcessArgOmitRpc(command_line_args);
+ ProcessArgBespokeMethod(command_line_args);
ProcessArgServiceEndpointEnvVar(command_line_args);
ProcessArgEmulatorEndpointEnvVar(command_line_args);
ProcessArgEndpointLocationStyle(command_line_args);
diff --git a/generator/internal/connection_generator.cc b/generator/internal/connection_generator.cc
index 1130dd396a65e..0b093fa339333 100644
--- a/generator/internal/connection_generator.cc
+++ b/generator/internal/connection_generator.cc
@@ -19,6 +19,7 @@
#include "generator/internal/pagination.h"
#include "generator/internal/predicate_utils.h"
#include "generator/internal/printer.h"
+#include "absl/strings/str_replace.h"
#include "absl/strings/str_split.h"
#include
@@ -57,8 +58,6 @@ Status ConnectionGenerator::GenerateHeader() {
{vars("idempotency_policy_header_path"), vars("retry_traits_header_path"),
HasLongrunningMethod() ? "google/cloud/no_await_tag.h" : "",
IsExperimental() ? "google/cloud/experimental_tag.h" : "",
- HasEmitCompletionQueueAccessor() ? "google/cloud/completion_queue.h"
- : "",
"google/cloud/backoff_policy.h",
HasLongrunningMethod() || HasAsyncMethod() ? "google/cloud/future.h"
: "",
@@ -93,21 +92,7 @@ Status ConnectionGenerator::GenerateHeader() {
}
}
- Status result;
- if (HasEmitCompletionQueueAccessor()) {
- result = HeaderOpenNamespaces();
- if (!result.ok()) return result;
- HeaderPrint(R"""(class $connection_class_name$;)""");
- HeaderCloseNamespaces();
-
- result = HeaderOpenNamespaces(NamespaceType::kInternal);
- if (!result.ok()) return result;
- HeaderPrint(
- R"""(StatusOr completion_queue($product_namespace$::$connection_class_name$ const& conn);)""");
- HeaderCloseNamespaces();
- }
-
- result = HeaderOpenNamespaces();
+ auto result = HeaderOpenNamespaces();
if (!result.ok()) return result;
HeaderPrint(R"""(
@@ -331,13 +316,14 @@ class $connection_class_name$ {
__FILE__, __LINE__);
}
- if (HasEmitCompletionQueueAccessor()) {
- HeaderPrint(R"""( protected:
- friend StatusOr $product_internal_namespace$::completion_queue(
- $connection_class_name$ const& conn);
- virtual StatusOr completion_queue() const;
-)""");
+ for (auto const& method : bespoke_methods()) {
+ HeaderPrint("\n");
+ HeaderPrint(absl::StrCat(
+ "virtual ", method.return_type(), " ", method.name(),
+ absl::StrReplaceAll(method.parameters(), {{", Options opts = {}", ""}}),
+ ";"));
}
+
// close abstract interface Connection base class
HeaderPrint("};\n");
@@ -513,13 +499,24 @@ future>
__FILE__, __LINE__);
}
- if (HasEmitCompletionQueueAccessor()) {
+ for (auto const& method : bespoke_methods()) {
+ CcPrint("\n");
+ std::string make_return =
+ absl::StrContains(method.return_type(), "future")
+ ? absl::StrCat("google::cloud::make_ready_", method.return_type())
+ : method.return_type();
+
CcPrint(
- R"""(
-StatusOr $connection_class_name$::completion_queue() const {
- return Status(StatusCode::kUnimplemented, "not implemented");
+ absl::StrCat(method.return_type(), R"""( $connection_class_name$::)""",
+ method.name(),
+ absl::StrReplaceAll(method.parameters(),
+ {{" request, Options opts = {}", ""}}),
+ " {\n",
+ absl::StrFormat(R"""( return %s(
+ Status(StatusCode::kUnimplemented, "not implemented"));
}
-)""");
+)""",
+ make_return)));
}
if (HasGenerateGrpcTransport()) {
diff --git a/generator/internal/connection_impl_generator.cc b/generator/internal/connection_impl_generator.cc
index dda37fc86532e..cb1ac65aa51a7 100644
--- a/generator/internal/connection_impl_generator.cc
+++ b/generator/internal/connection_impl_generator.cc
@@ -19,6 +19,7 @@
#include "generator/internal/predicate_utils.h"
#include "generator/internal/printer.h"
#include "absl/strings/str_cat.h"
+#include "absl/strings/str_replace.h"
#include
namespace google {
@@ -120,6 +121,14 @@ class $connection_class_name$Impl
HeaderPrintMethod(method, __FILE__, __LINE__, AsyncMethodDeclaration());
}
+ for (auto const& method : bespoke_methods()) {
+ HeaderPrint("\n");
+ HeaderPrint(absl::StrCat(
+ method.return_type(), " ", method.name(),
+ absl::StrReplaceAll(method.parameters(), {{", Options opts = {}", ""}}),
+ " override;"));
+ }
+
HeaderPrint(R"""(
private:
std::unique_ptr background_;
@@ -133,13 +142,6 @@ class $connection_class_name$Impl
std::make_shared();)""");
}
- if (HasEmitCompletionQueueAccessor()) {
- HeaderPrint(
- R"""(
- StatusOr completion_queue() const override;
-)""");
- }
-
// This closes the *ConnectionImpl class definition.
HeaderPrint("\n};\n");
@@ -215,15 +217,6 @@ std::unique_ptr polling_policy(Options const& options) {
} // namespace
)""");
- if (HasEmitCompletionQueueAccessor()) {
- CcPrint(R"""(
-StatusOr completion_queue(
- $product_namespace$::$connection_class_name$ const& conn) {
- return conn.completion_queue();
-}
-)""");
- }
-
// streaming updater functions
if (!OmitStreamingUpdater(vars())) {
for (auto const& method : methods()) {
@@ -258,14 +251,6 @@ void $service_name$$method_name$StreamingUpdater(
CcPrintMethod(method, __FILE__, __LINE__, AsyncMethodDefinition(method));
}
- if (HasEmitCompletionQueueAccessor()) {
- CcPrint(R"""(
-StatusOr $connection_class_name$Impl::completion_queue() const {
- return background_->cq();
-}
-)""");
- }
-
CcCloseNamespaces();
return {};
}
diff --git a/generator/internal/service_code_generator.cc b/generator/internal/service_code_generator.cc
index 87138654c0765..02b250cc4056e 100644
--- a/generator/internal/service_code_generator.cc
+++ b/generator/internal/service_code_generator.cc
@@ -482,6 +482,23 @@ void ServiceCodeGenerator::SetMethods() {
for (auto const& mixin_method : mixin_methods_) {
methods_.emplace_back(mixin_method.method.get());
}
+
+ auto bespoke_methods_var = service_vars_.find("bespoke_methods");
+ if (bespoke_methods_var != service_vars_.end()) {
+ auto methods = absl::StrSplit(bespoke_methods_var->second, ",");
+ for (auto const& method : methods) {
+ std::vector pieces = absl::StrSplit(method, "@@");
+ assert(pieces.size() == 4);
+ cpp::generator::ServiceConfiguration::BespokeMethod bespoke_method;
+ bespoke_method.set_client_comments(SafeReplaceAll(pieces[0], "@", ","));
+ bespoke_method.set_name(SafeReplaceAll(pieces[1], "@", ","));
+ bespoke_method.set_return_type(SafeReplaceAll(pieces[2], "@", ","));
+ bespoke_method.set_parameters(SafeReplaceAll(pieces[3], "@", ","));
+ std::cout << __func__
+ << ": bespoke_method=" << bespoke_method.DebugString() << "\n";
+ bespoke_methods_.emplace_back(std::move(bespoke_method));
+ }
+ }
}
std::string ServiceCodeGenerator::GetPbIncludeByTransport() const {
@@ -511,11 +528,6 @@ bool ServiceCodeGenerator::IsDeprecated() const {
return service_descriptor_->options().deprecated();
}
-bool ServiceCodeGenerator::HasEmitCompletionQueueAccessor() const {
- return vars().find("emit_completion_queue_accessor") != vars().end() &&
- vars().at("emit_completion_queue_accessor") == "true";
-}
-
} // namespace generator_internal
} // namespace cloud
} // namespace google
diff --git a/generator/internal/service_code_generator.h b/generator/internal/service_code_generator.h
index e4347db6e0a9e..c267430e08397 100644
--- a/generator/internal/service_code_generator.h
+++ b/generator/internal/service_code_generator.h
@@ -68,6 +68,10 @@ class ServiceCodeGenerator : public GeneratorInterface {
std::string vars(std::string const& key) const;
MethodDescriptorList const& methods() const { return methods_; }
MethodDescriptorList const& async_methods() const { return async_methods_; }
+ std::vector const&
+ bespoke_methods() const {
+ return bespoke_methods_;
+ }
void SetVars(absl::string_view header_path);
VarsDictionary MergeServiceAndMethodVars(
google::protobuf::MethodDescriptor const& method) const;
@@ -246,8 +250,6 @@ class ServiceCodeGenerator : public GeneratorInterface {
*/
bool IsDeprecated() const;
- bool HasEmitCompletionQueueAccessor() const;
-
private:
void SetMethods();
@@ -270,6 +272,8 @@ class ServiceCodeGenerator : public GeneratorInterface {
bool pb_h_system_includes_ = false;
MethodDescriptorList methods_;
MethodDescriptorList async_methods_;
+ std::vector
+ bespoke_methods_;
Printer header_;
Printer cc_;
std::vector mixin_methods_;
diff --git a/generator/standalone_main.cc b/generator/standalone_main.cc
index 44f626ccd85a5..a5023c2dbf5ca 100644
--- a/generator/standalone_main.cc
+++ b/generator/standalone_main.cc
@@ -281,6 +281,16 @@ std::vector> GenerateCodeFromProtos(
args.emplace_back(absl::StrCat("--cpp_codegen_opt=omit_rpc=",
SafeReplaceAll(omit_rpc, ",", "@")));
}
+ for (auto const& bespoke_method : service.bespoke_methods()) {
+ args.emplace_back(absl::StrCat(
+ "--cpp_codegen_opt=bespoke_method=",
+ absl::StrJoin(
+ {SafeReplaceAll(bespoke_method.client_comments(), ",", "@"),
+ SafeReplaceAll(bespoke_method.name(), ",", "@"),
+ SafeReplaceAll(bespoke_method.return_type(), ",", "@"),
+ SafeReplaceAll(bespoke_method.parameters(), ",", "@")},
+ "@@")));
+ }
for (auto const& retry_code : service.retryable_status_codes()) {
args.emplace_back("--cpp_codegen_opt=retry_status_code=" + retry_code);
}
@@ -296,11 +306,6 @@ std::vector> GenerateCodeFromProtos(
if (service.omit_streaming_updater()) {
args.emplace_back("--cpp_codegen_opt=omit_streaming_updater=true");
}
- if (service.emit_completion_queue_accessor()) {
- args.emplace_back(
- "--cpp_codegen_opt=emit_completion_queue_accessor=true");
- }
-
if (service.generate_round_robin_decorator()) {
args.emplace_back(
"--cpp_codegen_opt=generate_round_robin_decorator=true");
diff --git a/google/cloud/bigtable/CMakeLists.txt b/google/cloud/bigtable/CMakeLists.txt
index 167b66bd2cb09..67d32ef4ed3cd 100644
--- a/google/cloud/bigtable/CMakeLists.txt
+++ b/google/cloud/bigtable/CMakeLists.txt
@@ -89,6 +89,7 @@ add_library(
admin/internal/bigtable_table_admin_auth_decorator.h
admin/internal/bigtable_table_admin_connection_impl.cc
admin/internal/bigtable_table_admin_connection_impl.h
+ admin/internal/bigtable_table_admin_connection_impl_bespoke.cc
admin/internal/bigtable_table_admin_logging_decorator.cc
admin/internal/bigtable_table_admin_logging_decorator.h
admin/internal/bigtable_table_admin_metadata_decorator.cc
@@ -104,8 +105,6 @@ add_library(
admin/internal/bigtable_table_admin_tracing_connection.h
admin/internal/bigtable_table_admin_tracing_stub.cc
admin/internal/bigtable_table_admin_tracing_stub.h
- admin_client.cc
- admin_client.h
app_profile_config.cc
app_profile_config.h
bound_query.cc
@@ -131,10 +130,6 @@ add_library(
iam_policy.h
idempotent_mutation_policy.cc
idempotent_mutation_policy.h
- instance_admin.cc
- instance_admin.h
- instance_admin_client.cc
- instance_admin_client.h
instance_config.cc
instance_config.h
instance_list_responses.h
@@ -259,8 +254,6 @@ add_library(
sql_statement.h
table.cc
table.h
- table_admin.cc
- table_admin.h
table_config.cc
table_config.h
table_resource.cc
@@ -424,7 +417,6 @@ if (BUILD_TESTING)
# List the unit tests, then setup the targets and dependencies.
set(bigtable_client_unit_tests
# cmake-format: sort
- admin_client_test.cc
app_profile_config_test.cc
async_read_stream_test.cc
bigtable_version_test.cc
@@ -441,8 +433,6 @@ if (BUILD_TESTING)
iam_binding_test.cc
iam_policy_test.cc
idempotent_mutation_policy_test.cc
- instance_admin_client_test.cc
- instance_admin_test.cc
instance_config_test.cc
instance_resource_test.cc
instance_update_config_test.cc
@@ -490,7 +480,6 @@ if (BUILD_TESTING)
rpc_backoff_policy_test.cc
rpc_retry_policy_test.cc
sql_statement_test.cc
- table_admin_test.cc
table_config_test.cc
table_resource_test.cc
table_test.cc
diff --git a/google/cloud/bigtable/admin/bigtable_table_admin_client.cc b/google/cloud/bigtable/admin/bigtable_table_admin_client.cc
index a30ce9aac2bca..347aa10bba977 100644
--- a/google/cloud/bigtable/admin/bigtable_table_admin_client.cc
+++ b/google/cloud/bigtable/admin/bigtable_table_admin_client.cc
@@ -821,6 +821,14 @@ BigtableTableAdminClient::AsyncCheckConsistency(
return connection_->AsyncCheckConsistency(request);
}
+future>
+BigtableTableAdminClient::WaitForConsistency(
+ google::bigtable::admin::v2::CheckConsistencyRequest const& request,
+ Options opts) {
+ internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_));
+ return connection_->WaitForConsistency(request);
+}
+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
} // namespace bigtable_admin
} // namespace cloud
diff --git a/google/cloud/bigtable/admin/bigtable_table_admin_client.h b/google/cloud/bigtable/admin/bigtable_table_admin_client.h
index b9049768b5d7e..07ceb1ae753e2 100644
--- a/google/cloud/bigtable/admin/bigtable_table_admin_client.h
+++ b/google/cloud/bigtable/admin/bigtable_table_admin_client.h
@@ -2581,6 +2581,11 @@ class BigtableTableAdminClient {
google::bigtable::admin::v2::CheckConsistencyRequest const& request,
Options opts = {});
+ future>
+ WaitForConsistency(
+ google::bigtable::admin::v2::CheckConsistencyRequest const& request,
+ Options opts = {});
+
private:
std::shared_ptr connection_;
Options options_;
diff --git a/google/cloud/bigtable/admin/bigtable_table_admin_connection.cc b/google/cloud/bigtable/admin/bigtable_table_admin_connection.cc
index 26613c3f155e6..6413380c8ad91 100644
--- a/google/cloud/bigtable/admin/bigtable_table_admin_connection.cc
+++ b/google/cloud/bigtable/admin/bigtable_table_admin_connection.cc
@@ -382,9 +382,12 @@ BigtableTableAdminConnection::AsyncCheckConsistency(
Status(StatusCode::kUnimplemented, "not implemented"));
}
-StatusOr BigtableTableAdminConnection::completion_queue()
- const {
- return Status(StatusCode::kUnimplemented, "not implemented");
+future>
+BigtableTableAdminConnection::WaitForConsistency(
+ google::bigtable::admin::v2::CheckConsistencyRequest const&) {
+ return google::cloud::make_ready_future<
+ StatusOr>(
+ Status(StatusCode::kUnimplemented, "not implemented"));
}
std::shared_ptr MakeBigtableTableAdminConnection(
diff --git a/google/cloud/bigtable/admin/bigtable_table_admin_connection.h b/google/cloud/bigtable/admin/bigtable_table_admin_connection.h
index e7cc3987491a4..37aa96079d46b 100644
--- a/google/cloud/bigtable/admin/bigtable_table_admin_connection.h
+++ b/google/cloud/bigtable/admin/bigtable_table_admin_connection.h
@@ -22,7 +22,6 @@
#include "google/cloud/bigtable/admin/bigtable_table_admin_connection_idempotency_policy.h"
#include "google/cloud/bigtable/admin/internal/bigtable_table_admin_retry_traits.h"
#include "google/cloud/backoff_policy.h"
-#include "google/cloud/completion_queue.h"
#include "google/cloud/future.h"
#include "google/cloud/internal/retry_policy_impl.h"
#include "google/cloud/no_await_tag.h"
@@ -35,27 +34,6 @@
#include "google/longrunning/operations.grpc.pb.h"
#include
-namespace google {
-namespace cloud {
-namespace bigtable_admin {
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
-class BigtableTableAdminConnection;
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
-} // namespace bigtable_admin
-} // namespace cloud
-} // namespace google
-
-namespace google {
-namespace cloud {
-namespace bigtable_admin_internal {
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
-StatusOr completion_queue(
- bigtable_admin::BigtableTableAdminConnection const& conn);
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
-} // namespace bigtable_admin_internal
-} // namespace cloud
-} // namespace google
-
namespace google {
namespace cloud {
namespace bigtable_admin {
@@ -382,10 +360,10 @@ class BigtableTableAdminConnection {
AsyncCheckConsistency(
google::bigtable::admin::v2::CheckConsistencyRequest const& request);
- protected:
- friend StatusOr bigtable_admin_internal::completion_queue(
- BigtableTableAdminConnection const& conn);
- virtual StatusOr completion_queue() const;
+ virtual future<
+ StatusOr>
+ WaitForConsistency(
+ google::bigtable::admin::v2::CheckConsistencyRequest const& request);
};
/**
diff --git a/google/cloud/bigtable/admin/internal/bigtable_table_admin_connection_impl.cc b/google/cloud/bigtable/admin/internal/bigtable_table_admin_connection_impl.cc
index c2cc66d3cff53..233be86979261 100644
--- a/google/cloud/bigtable/admin/internal/bigtable_table_admin_connection_impl.cc
+++ b/google/cloud/bigtable/admin/internal/bigtable_table_admin_connection_impl.cc
@@ -60,11 +60,6 @@ std::unique_ptr polling_policy(Options const& options) {
} // namespace
-StatusOr completion_queue(
- bigtable_admin::BigtableTableAdminConnection const& conn) {
- return conn.completion_queue();
-}
-
BigtableTableAdminConnectionImpl::BigtableTableAdminConnectionImpl(
std::unique_ptr background,
std::shared_ptr stub,
@@ -1298,11 +1293,6 @@ BigtableTableAdminConnectionImpl::AsyncCheckConsistency(
std::move(current), std::move(request_copy), __func__);
}
-StatusOr BigtableTableAdminConnectionImpl::completion_queue()
- const {
- return background_->cq();
-}
-
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
} // namespace bigtable_admin_internal
} // namespace cloud
diff --git a/google/cloud/bigtable/admin/internal/bigtable_table_admin_connection_impl.h b/google/cloud/bigtable/admin/internal/bigtable_table_admin_connection_impl.h
index 0fa8d168eabb1..ecdddaa38bd66 100644
--- a/google/cloud/bigtable/admin/internal/bigtable_table_admin_connection_impl.h
+++ b/google/cloud/bigtable/admin/internal/bigtable_table_admin_connection_impl.h
@@ -234,11 +234,14 @@ class BigtableTableAdminConnectionImpl
google::bigtable::admin::v2::CheckConsistencyRequest const& request)
override;
+ future>
+ WaitForConsistency(google::bigtable::admin::v2::CheckConsistencyRequest const&
+ request) override;
+
private:
std::unique_ptr background_;
std::shared_ptr stub_;
Options options_;
- StatusOr completion_queue() const override;
};
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
diff --git a/google/cloud/bigtable/admin/internal/bigtable_table_admin_connection_impl_bespoke.cc b/google/cloud/bigtable/admin/internal/bigtable_table_admin_connection_impl_bespoke.cc
new file mode 100644
index 0000000000000..43b364397c734
--- /dev/null
+++ b/google/cloud/bigtable/admin/internal/bigtable_table_admin_connection_impl_bespoke.cc
@@ -0,0 +1,82 @@
+// Copyright 2021 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// 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 "google/cloud/bigtable/admin/internal/bigtable_table_admin_connection_impl.h"
+#include "google/cloud/bigtable/admin/internal/bigtable_table_admin_option_defaults.h"
+#include "google/cloud/background_threads.h"
+#include "google/cloud/common_options.h"
+#include "google/cloud/grpc_options.h"
+#include "google/cloud/internal/async_long_running_operation.h"
+#include "google/cloud/internal/async_retry_loop.h"
+#include "google/cloud/internal/pagination_range.h"
+#include "google/cloud/internal/retry_loop.h"
+#include
+#include
+
+namespace google {
+namespace cloud {
+namespace bigtable_admin_internal {
+GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
+namespace {
+
+std::unique_ptr retry_policy(
+ Options const& options) {
+ return options.get()
+ ->clone();
+}
+
+std::unique_ptr backoff_policy(Options const& options) {
+ return options.get()
+ ->clone();
+}
+
+std::unique_ptr
+idempotency_policy(Options const& options) {
+ return options
+ .get<
+ bigtable_admin::BigtableTableAdminConnectionIdempotencyPolicyOption>()
+ ->clone();
+}
+
+} // namespace
+
+future>
+BigtableTableAdminConnectionImpl::WaitForConsistency(
+ google::bigtable::admin::v2::CheckConsistencyRequest const& request) {
+ auto current = google::cloud::internal::SaveCurrentOptions();
+ auto request_copy = request;
+ auto const idempotent =
+ idempotency_policy(*current)->CheckConsistency(request_copy);
+ auto retry = retry_policy(*current);
+ auto backoff = backoff_policy(*current);
+ auto attempt_predicate =
+ [](StatusOr const&
+ r) { return r.ok() && r->consistent(); };
+ return google::cloud::internal::AsyncRetryLoop(
+ std::move(retry), std::move(backoff), idempotent, background_->cq(),
+ [stub = stub_](
+ CompletionQueue& cq, std::shared_ptr context,
+ google::cloud::internal::ImmutableOptions options,
+ google::bigtable::admin::v2::CheckConsistencyRequest const& request) {
+ return stub->AsyncCheckConsistency(cq, std::move(context),
+ std::move(options), request);
+ },
+ std::move(current), std::move(request_copy), __func__,
+ std::move(attempt_predicate));
+}
+
+GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
+} // namespace bigtable_admin_internal
+} // namespace cloud
+} // namespace google
diff --git a/google/cloud/bigtable/admin_client.cc b/google/cloud/bigtable/admin_client.cc
deleted file mode 100644
index 4bcf80c036e36..0000000000000
--- a/google/cloud/bigtable/admin_client.cc
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2017 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 "google/cloud/bigtable/admin_client.h"
-#include "google/cloud/bigtable/internal/defaults.h"
-
-namespace google {
-namespace cloud {
-namespace bigtable {
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
-
-std::shared_ptr MakeAdminClient(std::string project,
- Options options) {
- auto params = bigtable_internal::AdminClientParams(
- internal::DefaultTableAdminOptions(std::move(options)));
- return std::shared_ptr(
- new AdminClient(std::move(project), std::move(params)));
-}
-
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
-} // namespace bigtable
-} // namespace cloud
-} // namespace google
diff --git a/google/cloud/bigtable/admin_client.h b/google/cloud/bigtable/admin_client.h
deleted file mode 100644
index 9f8dd1b5b9aab..0000000000000
--- a/google/cloud/bigtable/admin_client.h
+++ /dev/null
@@ -1,73 +0,0 @@
-// Copyright 2017 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.
-
-#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_ADMIN_CLIENT_H
-#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_ADMIN_CLIENT_H
-
-#include "google/cloud/bigtable/admin/bigtable_table_admin_connection.h"
-#include "google/cloud/bigtable/internal/admin_client_params.h"
-#include "google/cloud/bigtable/version.h"
-#include "google/cloud/grpc_options.h"
-#include "google/cloud/options.h"
-#include
-#include
-
-namespace google {
-namespace cloud {
-namespace bigtable {
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
-
-/**
- * Creates a `bigtable_admin::BigtableTableAdminConnection` and a
- * `CompletionQueue` for `bigtable::TableAdmin` to use.
- *
- * This class is used to initiate a connection to the Cloud Bigtable Table
- * Admin service. It is maintained only for backwards compatibility.
- *
- * @note Please prefer using `bigtable_admin::BigtableTableAdminConnection` to
- * configure `bigtable_admin::BigtableTableAdminClient`, instead of using
- * this class to configure `bigtable::TableAdmin`.
- */
-class AdminClient final {
- public:
- /// The project id that this AdminClient works on.
- std::string const& project() { return project_; };
-
- private:
- friend class TableAdmin;
- friend std::shared_ptr MakeAdminClient(std::string, Options);
-
- AdminClient(std::string project, bigtable_internal::AdminClientParams params)
- : project_(std::move(project)),
- cq_(params.options.get()),
- background_threads_(std::move(params.background_threads)),
- connection_(bigtable_admin::MakeBigtableTableAdminConnection(
- std::move(params.options))) {}
-
- std::string project_;
- CompletionQueue cq_;
- std::shared_ptr background_threads_;
- std::shared_ptr connection_;
-};
-
-/// Create a new table admin client configured via @p options.
-std::shared_ptr MakeAdminClient(std::string project,
- Options options = {});
-
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
-} // namespace bigtable
-} // namespace cloud
-} // namespace google
-
-#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_ADMIN_CLIENT_H
diff --git a/google/cloud/bigtable/admin_client_test.cc b/google/cloud/bigtable/admin_client_test.cc
deleted file mode 100644
index d723f8a64ff1b..0000000000000
--- a/google/cloud/bigtable/admin_client_test.cc
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2017 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 "google/cloud/bigtable/admin_client.h"
-#include
-
-namespace google {
-namespace cloud {
-namespace bigtable {
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
-namespace {
-
-TEST(AdminClientTest, MakeClient) {
- auto admin_client = MakeAdminClient("test-project");
- ASSERT_TRUE(admin_client);
- EXPECT_EQ("test-project", admin_client->project());
-}
-
-} // namespace
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
-} // namespace bigtable
-} // namespace cloud
-} // namespace google
diff --git a/google/cloud/bigtable/bigtable_client_unit_tests.bzl b/google/cloud/bigtable/bigtable_client_unit_tests.bzl
index 471fcefdadcd3..3a5760e1ae6e3 100644
--- a/google/cloud/bigtable/bigtable_client_unit_tests.bzl
+++ b/google/cloud/bigtable/bigtable_client_unit_tests.bzl
@@ -17,7 +17,6 @@
"""Automatically generated unit tests list - DO NOT EDIT."""
bigtable_client_unit_tests = [
- "admin_client_test.cc",
"app_profile_config_test.cc",
"async_read_stream_test.cc",
"bigtable_version_test.cc",
@@ -34,8 +33,6 @@ bigtable_client_unit_tests = [
"iam_binding_test.cc",
"iam_policy_test.cc",
"idempotent_mutation_policy_test.cc",
- "instance_admin_client_test.cc",
- "instance_admin_test.cc",
"instance_config_test.cc",
"instance_resource_test.cc",
"instance_update_config_test.cc",
@@ -83,7 +80,6 @@ bigtable_client_unit_tests = [
"rpc_backoff_policy_test.cc",
"rpc_retry_policy_test.cc",
"sql_statement_test.cc",
- "table_admin_test.cc",
"table_config_test.cc",
"table_resource_test.cc",
"table_test.cc",
diff --git a/google/cloud/bigtable/ci/run_integration_tests_emulator_bazel.sh b/google/cloud/bigtable/ci/run_integration_tests_emulator_bazel.sh
index 966435e0bb52e..ba218743f7e64 100755
--- a/google/cloud/bigtable/ci/run_integration_tests_emulator_bazel.sh
+++ b/google/cloud/bigtable/ci/run_integration_tests_emulator_bazel.sh
@@ -59,8 +59,8 @@ source module /google/cloud/bigtable/tools/run_emulator_utils.sh
production_only_targets=(
"//google/cloud/bigtable/examples:bigtable_table_admin_backup_snippets"
"//google/cloud/bigtable/examples:table_admin_iam_policy_snippets"
- "//google/cloud/bigtable/tests:admin_backup_integration_test"
- "//google/cloud/bigtable/tests:admin_iam_policy_integration_test"
+ "//google/cloud/bigtable/tests:table_admin_backup_integration_test"
+ "//google/cloud/bigtable/tests:table_admin_iam_policy_integration_test"
)
# Coverage builds are more subject to flakiness, as we must explicitly disable
diff --git a/google/cloud/bigtable/examples/table_admin_snippets.cc b/google/cloud/bigtable/examples/table_admin_snippets.cc
index e3d2ae8b08a14..062f73ad9ff01 100644
--- a/google/cloud/bigtable/examples/table_admin_snippets.cc
+++ b/google/cloud/bigtable/examples/table_admin_snippets.cc
@@ -14,7 +14,6 @@
#include "google/cloud/bigtable/admin/bigtable_table_admin_client.h"
#include "google/cloud/bigtable/examples/bigtable_examples_common.h"
-#include "google/cloud/bigtable/table_admin.h"
#include "google/cloud/bigtable/testing/cleanup_stale_resources.h"
#include "google/cloud/bigtable/testing/random_names.h"
#include "google/cloud/bigtable/wait_for_consistency.h"
@@ -633,30 +632,27 @@ void WaitForConsistencyCheck(
using ::google::cloud::future;
using ::google::cloud::Status;
using ::google::cloud::StatusOr;
- [](cbta::BigtableTableAdminClient admin, std::string const& project_id,
+ [](cbta::BigtableTableAdminClient, std::string const& project_id,
std::string const& instance_id, std::string const& table_id) {
+ auto connection = cbta::MakeBigtableTableAdminConnection();
+ auto client = cbta::BigtableTableAdminClient(connection);
std::string table_name = cbt::TableName(project_id, instance_id, table_id);
StatusOr
- consistency_token = admin.GenerateConsistencyToken(table_name);
+ consistency_token = client.GenerateConsistencyToken(table_name);
if (!consistency_token) {
throw std::move(consistency_token).status();
}
- // Start a thread to perform the background work.
- CompletionQueue cq;
- std::thread cq_runner([&cq] { cq.Run(); });
-
- std::string token = consistency_token->consistency_token();
- future consistent_future =
- cbta::AsyncWaitForConsistency(cq, admin, table_name, token);
-
- // Simplify the example by blocking until the operation is done.
- Status status = consistent_future.get();
- if (!status.ok()) throw std::runtime_error(status.message());
+ auto token = consistency_token->consistency_token();
+ // auto consistency_future =
+ // cbta::WaitForConsistency(connection, table_name, token);
+
+ google::bigtable::admin::v2::CheckConsistencyRequest wait_request;
+ wait_request.set_name(table_name);
+ wait_request.set_consistency_token(token);
+ auto consistency_future = client.WaitForConsistency(wait_request);
+ auto consistency = consistency_future.get();
+ if (!consistency) throw std::runtime_error(consistency.status().message());
std::cout << "Table is consistent with token " << token << "\n";
-
- // Shutdown the work queue and join the background thread
- cq.Shutdown();
- cq_runner.join();
}
//! [wait for consistency check]
(std::move(admin), argv.at(0), argv.at(1), argv.at(2));
diff --git a/google/cloud/bigtable/google_cloud_cpp_bigtable.bzl b/google/cloud/bigtable/google_cloud_cpp_bigtable.bzl
index ab40205c5efe5..3ee092bd083a4 100644
--- a/google/cloud/bigtable/google_cloud_cpp_bigtable.bzl
+++ b/google/cloud/bigtable/google_cloud_cpp_bigtable.bzl
@@ -45,7 +45,6 @@ google_cloud_cpp_bigtable_hdrs = [
"admin/internal/bigtable_table_admin_stub_factory.h",
"admin/internal/bigtable_table_admin_tracing_connection.h",
"admin/internal/bigtable_table_admin_tracing_stub.h",
- "admin_client.h",
"app_profile_config.h",
"bound_query.h",
"bytes.h",
@@ -61,8 +60,6 @@ google_cloud_cpp_bigtable_hdrs = [
"iam_binding.h",
"iam_policy.h",
"idempotent_mutation_policy.h",
- "instance_admin.h",
- "instance_admin_client.h",
"instance_config.h",
"instance_list_responses.h",
"instance_resource.h",
@@ -135,7 +132,6 @@ google_cloud_cpp_bigtable_hdrs = [
"rpc_retry_policy.h",
"sql_statement.h",
"table.h",
- "table_admin.h",
"table_config.h",
"table_resource.h",
"timestamp.h",
@@ -163,6 +159,7 @@ google_cloud_cpp_bigtable_srcs = [
"admin/internal/bigtable_instance_admin_tracing_stub.cc",
"admin/internal/bigtable_table_admin_auth_decorator.cc",
"admin/internal/bigtable_table_admin_connection_impl.cc",
+ "admin/internal/bigtable_table_admin_connection_impl_bespoke.cc",
"admin/internal/bigtable_table_admin_logging_decorator.cc",
"admin/internal/bigtable_table_admin_metadata_decorator.cc",
"admin/internal/bigtable_table_admin_option_defaults.cc",
@@ -170,7 +167,6 @@ google_cloud_cpp_bigtable_srcs = [
"admin/internal/bigtable_table_admin_stub_factory.cc",
"admin/internal/bigtable_table_admin_tracing_connection.cc",
"admin/internal/bigtable_table_admin_tracing_stub.cc",
- "admin_client.cc",
"app_profile_config.cc",
"bound_query.cc",
"bytes.cc",
@@ -181,8 +177,6 @@ google_cloud_cpp_bigtable_srcs = [
"iam_binding.cc",
"iam_policy.cc",
"idempotent_mutation_policy.cc",
- "instance_admin.cc",
- "instance_admin_client.cc",
"instance_config.cc",
"instance_resource.cc",
"instance_update_config.cc",
@@ -235,7 +229,6 @@ google_cloud_cpp_bigtable_srcs = [
"rpc_retry_policy.cc",
"sql_statement.cc",
"table.cc",
- "table_admin.cc",
"table_config.cc",
"table_resource.cc",
"timestamp.cc",
diff --git a/google/cloud/bigtable/instance_admin.cc b/google/cloud/bigtable/instance_admin.cc
deleted file mode 100644
index b5a283c6355e2..0000000000000
--- a/google/cloud/bigtable/instance_admin.cc
+++ /dev/null
@@ -1,232 +0,0 @@
-// Copyright 2018 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 "google/cloud/bigtable/instance_admin.h"
-#include "google/cloud/location.h"
-#include
-#include
-#include
-
-namespace btadmin = ::google::bigtable::admin::v2;
-
-namespace google {
-namespace cloud {
-namespace bigtable {
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
-
-static_assert(std::is_copy_assignable::value,
- "bigtable::InstanceAdmin must be CopyAssignable");
-
-StatusOr InstanceAdmin::ListInstances() {
- google::cloud::internal::OptionsSpan span(options_);
- InstanceList result;
-
- // Build the RPC request, try to minimize copying.
- btadmin::ListInstancesRequest request;
- request.set_parent(project_name());
- auto sor = connection_->ListInstances(request);
- if (!sor) return std::move(sor).status();
- auto response = *std::move(sor);
- auto& instances = *response.mutable_instances();
- std::move(instances.begin(), instances.end(),
- std::back_inserter(result.instances));
- auto& failed_locations = *response.mutable_failed_locations();
- std::move(failed_locations.begin(), failed_locations.end(),
- std::back_inserter(result.failed_locations));
- return result;
-}
-
-future> InstanceAdmin::CreateInstance(
- InstanceConfig instance_config) {
- google::cloud::internal::OptionsSpan span(options_);
- auto request = std::move(instance_config).as_proto();
- request.set_parent(project_name());
- for (auto& kv : *request.mutable_clusters()) {
- kv.second.set_location(
- Location(project_id(), kv.second.location()).FullName());
- }
- return connection_->CreateInstance(request);
-}
-
-future> InstanceAdmin::CreateCluster(
- ClusterConfig cluster_config, std::string const& instance_id,
- std::string const& cluster_id) {
- google::cloud::internal::OptionsSpan span(options_);
- auto cluster = std::move(cluster_config).as_proto();
- cluster.set_location(Location(project_id(), cluster.location()).FullName());
- btadmin::CreateClusterRequest request;
- request.mutable_cluster()->Swap(&cluster);
- request.set_parent(InstanceName(instance_id));
- request.set_cluster_id(cluster_id);
- return connection_->CreateCluster(request);
-}
-
-future>
-InstanceAdmin::UpdateInstance(InstanceUpdateConfig instance_update_config) {
- google::cloud::internal::OptionsSpan span(options_);
- auto request = std::move(instance_update_config).as_proto();
- return connection_->PartialUpdateInstance(request);
-}
-
-StatusOr InstanceAdmin::GetInstance(
- std::string const& instance_id) {
- google::cloud::internal::OptionsSpan span(options_);
- btadmin::GetInstanceRequest request;
- request.set_name(InstanceName(instance_id));
- return connection_->GetInstance(request);
-}
-
-Status InstanceAdmin::DeleteInstance(std::string const& instance_id) {
- google::cloud::internal::OptionsSpan span(options_);
- btadmin::DeleteInstanceRequest request;
- request.set_name(InstanceName(instance_id));
- return connection_->DeleteInstance(request);
-}
-
-StatusOr InstanceAdmin::GetCluster(
- std::string const& instance_id, std::string const& cluster_id) {
- google::cloud::internal::OptionsSpan span(options_);
- btadmin::GetClusterRequest request;
- request.set_name(ClusterName(instance_id, cluster_id));
- return connection_->GetCluster(request);
-}
-
-StatusOr InstanceAdmin::ListClusters() {
- return ListClusters("-");
-}
-
-StatusOr InstanceAdmin::ListClusters(
- std::string const& instance_id) {
- google::cloud::internal::OptionsSpan span(options_);
- ClusterList result;
-
- btadmin::ListClustersRequest request;
- request.set_parent(InstanceName(instance_id));
- auto sor = connection_->ListClusters(request);
- if (!sor) return std::move(sor).status();
- auto response = *std::move(sor);
- auto& clusters = *response.mutable_clusters();
- std::move(clusters.begin(), clusters.end(),
- std::back_inserter(result.clusters));
- auto& failed_locations = *response.mutable_failed_locations();
- std::move(failed_locations.begin(), failed_locations.end(),
- std::back_inserter(result.failed_locations));
- return result;
-}
-
-future>
-InstanceAdmin::UpdateCluster(ClusterConfig cluster_config) {
- google::cloud::internal::OptionsSpan span(options_);
- auto request = std::move(cluster_config).as_proto();
- return connection_->UpdateCluster(request);
-}
-
-Status InstanceAdmin::DeleteCluster(std::string const& instance_id,
- std::string const& cluster_id) {
- google::cloud::internal::OptionsSpan span(options_);
- btadmin::DeleteClusterRequest request;
- request.set_name(ClusterName(instance_id, cluster_id));
- return connection_->DeleteCluster(request);
-}
-
-StatusOr InstanceAdmin::CreateAppProfile(
- std::string const& instance_id, AppProfileConfig config) {
- google::cloud::internal::OptionsSpan span(options_);
- auto request = std::move(config).as_proto();
- request.set_parent(InstanceName(instance_id));
- return connection_->CreateAppProfile(request);
-}
-
-StatusOr InstanceAdmin::GetAppProfile(
- std::string const& instance_id, std::string const& profile_id) {
- google::cloud::internal::OptionsSpan span(options_);
- btadmin::GetAppProfileRequest request;
- request.set_name(AppProfileName(instance_id, profile_id));
- return connection_->GetAppProfile(request);
-}
-
-future> InstanceAdmin::UpdateAppProfile(
- std::string const& instance_id, std::string const& profile_id,
- AppProfileUpdateConfig config) {
- google::cloud::internal::OptionsSpan span(options_);
- auto request = std::move(config).as_proto();
- request.mutable_app_profile()->set_name(
- AppProfileName(instance_id, profile_id));
- return connection_->UpdateAppProfile(request);
-}
-
-StatusOr> InstanceAdmin::ListAppProfiles(
- std::string const& instance_id) {
- google::cloud::internal::OptionsSpan span(options_);
- std::vector result;
-
- btadmin::ListAppProfilesRequest request;
- request.set_parent(InstanceName(instance_id));
- auto sr = connection_->ListAppProfiles(request);
- for (auto& ap : sr) {
- if (!ap) return std::move(ap).status();
- result.emplace_back(*std::move(ap));
- }
- return result;
-}
-
-Status InstanceAdmin::DeleteAppProfile(std::string const& instance_id,
- std::string const& profile_id,
- bool ignore_warnings) {
- google::cloud::internal::OptionsSpan span(options_);
- btadmin::DeleteAppProfileRequest request;
- request.set_name(AppProfileName(instance_id, profile_id));
- request.set_ignore_warnings(ignore_warnings);
- return connection_->DeleteAppProfile(request);
-}
-
-StatusOr InstanceAdmin::GetNativeIamPolicy(
- std::string const& instance_id) {
- google::cloud::internal::OptionsSpan span(options_);
- google::iam::v1::GetIamPolicyRequest request;
- request.set_resource(InstanceName(instance_id));
- return connection_->GetIamPolicy(request);
-}
-
-StatusOr InstanceAdmin::SetIamPolicy(
- std::string const& instance_id, google::iam::v1::Policy const& iam_policy) {
- google::cloud::internal::OptionsSpan span(options_);
- google::iam::v1::SetIamPolicyRequest request;
- request.set_resource(InstanceName(instance_id));
- *request.mutable_policy() = iam_policy;
- return connection_->SetIamPolicy(request);
-}
-
-StatusOr> InstanceAdmin::TestIamPermissions(
- std::string const& instance_id,
- std::vector const& permissions) {
- google::cloud::internal::OptionsSpan span(options_);
- google::iam::v1::TestIamPermissionsRequest request;
- request.set_resource(InstanceName(instance_id));
- for (auto const& permission : permissions) {
- request.add_permissions(permission);
- }
- auto sor = connection_->TestIamPermissions(request);
- if (!sor) return std::move(sor).status();
- auto response = *std::move(sor);
- std::vector result;
- auto& ps = *response.mutable_permissions();
- std::move(ps.begin(), ps.end(), std::back_inserter(result));
- return result;
-}
-
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
-} // namespace bigtable
-} // namespace cloud
-} // namespace google
diff --git a/google/cloud/bigtable/instance_admin.h b/google/cloud/bigtable/instance_admin.h
deleted file mode 100644
index e7f218261fd07..0000000000000
--- a/google/cloud/bigtable/instance_admin.h
+++ /dev/null
@@ -1,732 +0,0 @@
-// Copyright 2018 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.
-
-#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_INSTANCE_ADMIN_H
-#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_INSTANCE_ADMIN_H
-
-#include "google/cloud/bigtable/admin/bigtable_instance_admin_connection.h"
-#include "google/cloud/bigtable/admin/bigtable_instance_admin_options.h"
-#include "google/cloud/bigtable/app_profile_config.h"
-#include "google/cloud/bigtable/cluster_config.h"
-#include "google/cloud/bigtable/cluster_list_responses.h"
-#include "google/cloud/bigtable/completion_queue.h"
-#include "google/cloud/bigtable/iam_policy.h"
-#include "google/cloud/bigtable/instance_admin_client.h"
-#include "google/cloud/bigtable/instance_config.h"
-#include "google/cloud/bigtable/instance_list_responses.h"
-#include "google/cloud/bigtable/instance_update_config.h"
-#include "google/cloud/bigtable/internal/convert_policies.h"
-#include "google/cloud/bigtable/polling_policy.h"
-#include "google/cloud/bigtable/resource_names.h"
-#include "google/cloud/bigtable/version.h"
-#include "google/cloud/future.h"
-#include "google/cloud/project.h"
-#include "google/cloud/status_or.h"
-#include
-#include
-#include
-#include
-
-namespace google {
-namespace cloud {
-namespace bigtable_internal {
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
-class InstanceAdminTester;
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
-} // namespace bigtable_internal
-namespace bigtable {
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
-
-/**
- * Implements the APIs to administer Cloud Bigtable instances.
- *
- * @par Thread-safety
- * Instances of this class created via copy-construction or copy-assignment
- * share the underlying pool of connections. Access to these copies via multiple
- * threads is guaranteed to work. Two threads operating concurrently on the same
- * instance of this class is not guaranteed to work.
- *
- * @par Cost
- * Creating a new object of type `InstanceAdmin` is comparable to creating a few
- * objects of type `std::string` or a few objects of type
- * `std::shared_ptr`. The class represents a shallow handle to a remote
- * object.
- *
- * @par Error Handling
- * This class uses `StatusOr` to report errors. When an operation fails to
- * perform its work the returned `StatusOr` contains the error details. If
- * the `ok()` member function in the `StatusOr` returns `true` then it
- * contains the expected result. Operations that do not return a value simply
- * return a `google::cloud::Status` indicating success or the details of the
- * error Please consult the [`StatusOr`
- * documentation](#google::cloud::StatusOr) for more details.
- *
- * @code
- * namespace cbt = google::cloud::bigtable;
- * namespace btadmin = google::bigtable::admin::v2;
- * cbt::InstanceAdmin admin = ...;
- * google::cloud::StatusOr instance = admin.GetInstance(...);
- *
- * if (!instance) {
- * std::cerr << "Error fetching instance\n";
- * return;
- * }
- *
- * // Use `instance` as a smart pointer here, e.g.:
- * std::cout << "The full instance name is " << instance->name() << "\n";
- * @endcode
- *
- * In addition, the @ref index "main page" contains examples using `StatusOr`
- * to handle errors.
- *
- * @par Retry, Backoff, and Idempotency Policies
- * The library automatically retries requests that fail with transient errors,
- * and uses [truncated exponential backoff][backoff-link] to backoff between
- * retries. The default policies are to continue retrying for up to 10 minutes.
- * On each transient failure the backoff period is doubled, starting with an
- * initial backoff of 100 milliseconds. The backoff period growth is truncated
- * at 60 seconds. The default idempotency policy is to only retry idempotent
- * operations. Note that most operations that change state are **not**
- * idempotent.
- *
- * The application can override these policies when constructing objects of this
- * class. The documentation for the constructors show examples of this in
- * action.
- *
- * [backoff-link]: https://cloud.google.com/storage/docs/exponential-backoff
- *
- * @see https://cloud.google.com/bigtable/ for an overview of Cloud Bigtable.
- *
- * @see https://cloud.google.com/bigtable/docs/overview for an overview of the
- * Cloud Bigtable data model.
- *
- * @see https://cloud.google.com/bigtable/docs/instances-clusters-nodes for an
- * introduction of the main APIs into Cloud Bigtable.
- *
- * @see https://cloud.google.com/bigtable/docs/reference/service-apis-overview
- * for an overview of the underlying Cloud Bigtable API.
- *
- * @see #google::cloud::StatusOr for a description of the error reporting class
- * used by this library.
- *
- * @see `LimitedTimeRetryPolicy` and `LimitedErrorCountRetryPolicy` for
- * alternative retry policies.
- *
- * @see `ExponentialBackoffPolicy` to configure different parameters for the
- * exponential backoff policy.
- *
- * @see `SafeIdempotentMutationPolicy` and `AlwaysRetryMutationPolicy` for
- * alternative idempotency policies.
- */
-class InstanceAdmin {
- public:
- explicit InstanceAdmin(
- std::shared_ptr
- connection,
- std::string project)
- : connection_(std::move(connection)),
- project_id_(std::move(project)),
- project_name_(Project(project_id_).FullName()),
- retry_prototype_(
- DefaultRPCRetryPolicy(internal::kBigtableInstanceAdminLimits)),
- backoff_prototype_(
- DefaultRPCBackoffPolicy(internal::kBigtableInstanceAdminLimits)),
- polling_prototype_(
- DefaultPollingPolicy(internal::kBigtableInstanceAdminLimits)),
- options_(google::cloud::internal::MergeOptions(
- bigtable_internal::MakeInstanceAdminOptions(
- retry_prototype_, backoff_prototype_, polling_prototype_),
- connection_->options())) {}
-
- /**
- * @param client the interface to create grpc stubs, report errors, etc.
- */
- // NOLINTNEXTLINE(performance-unnecessary-value-param)
- explicit InstanceAdmin(std::shared_ptr client)
- : InstanceAdmin(client->connection_, client->project()) {}
-
- /**
- * Create a new InstanceAdmin using explicit policies to handle RPC errors.
- *
- * @param client the interface to create grpc stubs, report errors, etc.
- * @param policies the set of policy overrides for this object.
- * @tparam Policies the types of the policies to override, the types must
- * derive from one of the following types:
- * - `RPCBackoffPolicy` how to backoff from a failed RPC. Currently only
- * `ExponentialBackoffPolicy` is implemented. You can also create your
- * own policies that backoff using a different algorithm.
- * - `RPCRetryPolicy` for how long to retry failed RPCs. Use
- * `LimitedErrorCountRetryPolicy` to limit the number of failures
- * allowed. Use `LimitedTimeRetryPolicy` to bound the time for any
- * request. You can also create your own policies that combine time and
- * error counts.
- * - `PollingPolicy` for how long will the class wait for
- * `google.longrunning.Operation` to complete. This class combines both
- * the backoff policy for checking long running operations and the
- * retry policy.
- *
- * @see GenericPollingPolicy, ExponentialBackoffPolicy,
- * LimitedErrorCountRetryPolicy, LimitedTimeRetryPolicy.
- */
- template
- // NOLINTNEXTLINE(performance-unnecessary-value-param)
- explicit InstanceAdmin(std::shared_ptr client,
- Policies&&... policies)
- : connection_(client->connection_),
- project_id_(client->project()),
- project_name_(Project(project_id_).FullName()),
- retry_prototype_(
- DefaultRPCRetryPolicy(internal::kBigtableInstanceAdminLimits)),
- backoff_prototype_(
- DefaultRPCBackoffPolicy(internal::kBigtableInstanceAdminLimits)),
- polling_prototype_(
- DefaultPollingPolicy(internal::kBigtableInstanceAdminLimits)) {
- ChangePolicies(std::forward(policies)...);
- options_ = google::cloud::internal::MergeOptions(
- bigtable_internal::MakeInstanceAdminOptions(
- retry_prototype_, backoff_prototype_, polling_prototype_),
- connection_->options());
- }
-
- /// The full name (`projects/`) of the project.
- std::string const& project_name() const { return project_name_; }
- /// The project id, i.e., `project_name()` without the `projects/` prefix.
- std::string const& project_id() const { return project_id_; }
-
- /**
- * Returns an InstanceAdmin that reuses the connection and configuration of
- * this InstanceAdmin, but with a different resource name.
- */
- InstanceAdmin WithNewTarget(std::string project_id) const {
- auto admin = *this;
- admin.project_id_ = std::move(project_id);
- admin.project_name_ = Project(admin.project_id_).FullName();
- return admin;
- }
-
- /// Return the fully qualified name of the given instance_id.
- std::string InstanceName(std::string const& instance_id) const {
- return google::cloud::bigtable::InstanceName(project_id_, instance_id);
- }
-
- /// Return the fully qualified name of the given cluster_id in give
- /// instance_id.
- std::string ClusterName(std::string const& instance_id,
- std::string const& cluster_id) const {
- return google::cloud::bigtable::ClusterName(project_id_, instance_id,
- cluster_id);
- }
-
- std::string AppProfileName(std::string const& instance_id,
- std::string const& profile_id) const {
- return google::cloud::bigtable::AppProfileName(project_id_, instance_id,
- profile_id);
- }
-
- /**
- * Create a new instance of Cloud Bigtable.
- *
- * @warning Note that this is operation can take seconds or minutes to
- * complete. The application may prefer to perform other work while waiting
- * for this operation.
- *
- * @param instance_config a description of the new instance to be created.
- * instance_id and a display_name parameters must be set in instance_config,
- * - instance_id : must be between 6 and 33 characters.
- * - display_name : must be between 4 and 30 characters.
- * @return a future that becomes satisfied when (a) the operation has
- * completed successfully, in which case it returns a proto with the
- * Instance details, (b) the operation has failed, in which case the future
- * contains an `google::cloud::Status` with the details of the failure, or
- * (c) the state of the operation is unknown after the time allocated by the
- * retry policies has expired, in which case the future contains the last
- * error status.
- *
- * @par Idempotency
- * This operation is always treated as non-idempotent.
- *
- * @par Thread-safety
- * Two threads concurrently calling this member function on the same instance
- * of this class are **not** guaranteed to work. Consider copying the object
- * and using different copies in each thread.
- *
- * @par Example
- * @snippet bigtable_instance_admin_snippets.cc create instance
- */
- future> CreateInstance(
- InstanceConfig instance_config);
-
- /**
- * Create a new Cluster of Cloud Bigtable.
- *
- * @param cluster_config a description of the new cluster to be created.
- * @param instance_id the id of the instance in the project
- * @param cluster_id the id of the cluster in the project that needs to be
- * created. It must be between 6 and 30 characters.
- *
- * @par Idempotency
- * This operation is always treated as non-idempotent.
- *
- * @par Thread-safety
- * Two threads concurrently calling this member function on the same instance
- * of this class are **not** guaranteed to work. Consider copying the object
- * and using different copies in each thread.
- *
- * @par Example
- * @snippet bigtable_instance_admin_snippets.cc create cluster
- */
- future> CreateCluster(
- ClusterConfig cluster_config, std::string const& instance_id,
- std::string const& cluster_id);
-
- /**
- * Update an existing instance of Cloud Bigtable.
- *
- * @warning Note that this is operation can take seconds or minutes to
- * complete. The application may prefer to perform other work while waiting
- * for this operation.
- *
- * @param instance_update_config config with modified instance.
- * @return a future that becomes satisfied when (a) the operation has
- * completed successfully, in which case it returns a proto with the
- * Instance details, (b) the operation has failed, in which case the future
- * contains an exception (typically `bigtable::GrpcError`) with the details
- * of the failure, or (c) the state of the operation is unknown after the
- * time allocated by the retry policies has expired, in which case the
- * future contains an exception of type `bigtable::PollTimeout`.
- *
- * @par Idempotency
- * This operation is always treated as non-idempotent.
- *
- * @par Thread-safety
- * Two threads concurrently calling this member function on the same instance
- * of this class are **not** guaranteed to work. Consider copying the object
- * and using different copies in each thread.
- *
- * @par Example
- * @snippet bigtable_instance_admin_snippets.cc update instance
- */
- future> UpdateInstance(
- InstanceUpdateConfig instance_update_config);
-
- /**
- * Obtain the list of instances in the project.
- *
- * @note In some circumstances Cloud Bigtable may be unable to obtain the full
- * list of instances, typically because some transient failure has made
- * specific zones unavailable. In this cases the service returns a separate
- * list of `failed_locations` that represent the unavailable zones.
- * Applications may want to retry the operation after the transient
- * conditions have cleared.
- *
- * @par Idempotency
- * This operation is read-only and therefore it is always idempotent.
- *
- * @par Thread-safety
- * Two threads concurrently calling this member function on the same instance
- * of this class are **not** guaranteed to work. Consider copying the object
- * and using different copies in each thread.
- *
- * @par Example
- * @snippet bigtable_instance_admin_snippets.cc list instances
- */
- StatusOr ListInstances();
-
- /**
- * Return the details of @p instance_id.
- *
- * @par Idempotency
- * This operation is read-only and therefore it is always idempotent.
- *
- * @par Thread-safety
- * Two threads concurrently calling this member function on the same instance
- * of this class are **not** guaranteed to work. Consider copying the object
- * and using different copies in each thread.
- *
- * @par Example
- * @snippet bigtable_instance_admin_snippets.cc get instance
- */
- StatusOr GetInstance(
- std::string const& instance_id);
-
- /**
- * Deletes the instances in the project.
- *
- * @param instance_id the id of the instance in the project that needs to be
- * deleted
- *
- * @par Idempotency
- * This operation is always treated as non-idempotent.
- *
- * @par Thread-safety
- * Two threads concurrently calling this member function on the same instance
- * of this class are **not** guaranteed to work. Consider copying the object
- * and using different copies in each thread.
- *
- * @par Example
- * @snippet bigtable_instance_admin_snippets.cc delete instance
- */
- Status DeleteInstance(std::string const& instance_id);
-
- /**
- * Obtain the list of clusters in an instance.
- *
- * @note In some circumstances Cloud Bigtable may be unable to obtain the full
- * list of clusters, typically because some transient failure has made
- * specific zones unavailable. In this cases the service returns a separate
- * list of `failed_locations` that represent the unavailable zones.
- * Applications may want to retry the operation after the transient
- * conditions have cleared.
- *
- * @par Idempotency
- * This operation is read-only and therefore it is always idempotent.
- *
- * @par Thread-safety
- * Two threads concurrently calling this member function on the same instance
- * of this class are **not** guaranteed to work. Consider copying the object
- * and using different copies in each thread.
- *
- * @par Example
- * @snippet bigtable_instance_admin_snippets.cc list clusters
- */
- StatusOr ListClusters();
-
- /**
- * Obtain the list of clusters in an instance.
- *
- * @note In some circumstances Cloud Bigtable may be unable to obtain the full
- * list of clusters, typically because some transient failure has made
- * specific zones unavailable. In this cases the service returns a separate
- * list of `failed_locations` that represent the unavailable zones.
- * Applications may want to retry the operation after the transient
- * conditions have cleared.
- *
- * @par Idempotency
- * This operation is read-only and therefore it is always idempotent.
- *
- * @par Thread-safety
- * Two threads concurrently calling this member function on the same instance
- * of this class are **not** guaranteed to work. Consider copying the object
- * and using different copies in each thread.
- *
- * @par Example
- * @snippet bigtable_instance_admin_snippets.cc list clusters
- */
- StatusOr ListClusters(std::string const& instance_id);
-
- /**
- * Update an existing cluster of Cloud Bigtable.
- *
- * @warning Note that this is operation can take seconds or minutes to
- * complete. The application may prefer to perform other work while waiting
- * for this operation.
- *
- * @param cluster_config cluster with updated values.
- * @return a future that becomes satisfied when (a) the operation has
- * completed successfully, in which case it returns a proto with the
- * Instance details, (b) the operation has failed, in which case the future
- * contains an exception (typically `bigtable::GrpcError`) with the details
- * of the failure, or (c) the state of the operation is unknown after the
- * time allocated by the retry policies has expired, in which case the
- * future contains an exception of type `bigtable::PollTimeout`.
- *
- * @par Idempotency
- * This operation is always treated as non-idempotent.
- *
- * @par Thread-safety
- * Two threads concurrently calling this member function on the same instance
- * of this class are **not** guaranteed to work. Consider copying the object
- * and using different copies in each thread.
- *
- * @par Example
- * @snippet bigtable_instance_admin_snippets.cc update cluster
- */
- future> UpdateCluster(
- ClusterConfig cluster_config);
-
- /**
- * Deletes the specified cluster of an instance in the project.
- *
- * @param instance_id the id of the instance in the project
- * @param cluster_id the id of the cluster in the project that needs to be
- * deleted
- *
- * @par Idempotency
- * This operation is always treated as non-idempotent.
- *
- * @par Thread-safety
- * Two threads concurrently calling this member function on the same instance
- * of this class are **not** guaranteed to work. Consider copying the object
- * and using different copies in each thread.
- *
- * @par Example
- * @snippet bigtable_instance_admin_snippets.cc delete cluster
- */
- Status DeleteCluster(std::string const& instance_id,
- std::string const& cluster_id);
-
- /**
- * Gets the specified cluster of an instance in the project.
- *
- * @param instance_id the id of the instance in the project
- * @param cluster_id the id of the cluster in the project that needs to be
- * deleted
- * @return a Cluster for given instance_id and cluster_id.
- *
- * @par Idempotency
- * This operation is read-only and therefore it is always idempotent.
- *
- * @par Thread-safety
- * Two threads concurrently calling this member function on the same instance
- * of this class are **not** guaranteed to work. Consider copying the object
- * and using different copies in each thread.
- *
- * @par Example
- * @snippet bigtable_instance_admin_snippets.cc get cluster
- */
- StatusOr GetCluster(
- std::string const& instance_id, std::string const& cluster_id);
-
- /**
- * Create a new application profile.
- *
- * @param instance_id the instance for the new application profile.
- * @param config the configuration for the new application profile.
- * @return The proto describing the new application profile.
- *
- * @par Idempotency
- * This operation is always treated as non-idempotent.
- *
- * @par Thread-safety
- * Two threads concurrently calling this member function on the same instance
- * of this class are **not** guaranteed to work. Consider copying the object
- * and using different copies in each thread.
- *
- * @par Multi-cluster Routing Example
- * @snippet bigtable_instance_admin_snippets.cc create app profile
- *
- * @par Single Cluster Routing Example
- * @snippet bigtable_instance_admin_snippets.cc create app profile cluster
- */
- StatusOr CreateAppProfile(
- std::string const& instance_id, AppProfileConfig config);
-
- /**
- * Fetch the detailed information about an existing application profile.
- *
- * @param instance_id the instance to look the profile in.
- * @param profile_id the id of the profile within that instance.
- * @return The proto describing the application profile.
- *
- * @par Idempotency
- * This operation is read-only and therefore it is always idempotent.
- *
- * @par Thread-safety
- * Two threads concurrently calling this member function on the same instance
- * of this class are **not** guaranteed to work. Consider copying the object
- * and using different copies in each thread.
- *
- * @par Example
- * @snippet bigtable_instance_admin_snippets.cc get app profile
- */
- StatusOr GetAppProfile(
- std::string const& instance_id, std::string const& profile_id);
-
- /**
- * Updates an existing application profile.
- *
- * @param instance_id the instance for the new application profile.
- * @param profile_id the id (not the full name) of the profile to update.
- * @param config the configuration for the new application profile.
- * @return The proto describing the new application profile.
- *
- * @par Idempotency
- * This operation is always treated as non-idempotent.
- *
- * @par Thread-safety
- * Two threads concurrently calling this member function on the same instance
- * of this class are **not** guaranteed to work. Consider copying the object
- * and using different copies in each thread.
- *
- * @par Change Description Example
- * @snippet bigtable_instance_admin_snippets.cc update app profile description
- *
- * @par Change Routing to Any Cluster Example
- * @snippet bigtable_instance_admin_snippets.cc update app profile routing any
- *
- * @par Change Routing to a Specific Cluster Example
- * @snippet bigtable_instance_admin_snippets.cc update app profile routing
- */
- future> UpdateAppProfile(
- std::string const& instance_id, std::string const& profile_id,
- AppProfileUpdateConfig config);
-
- /**
- * List the application profiles in an instance.
- *
- * @param instance_id the instance to list the profiles for.
- * @return a std::vector with the protos describing any profiles.
- *
- * @par Idempotency
- * This operation is read-only and therefore it is always idempotent.
- *
- * @par Thread-safety
- * Two threads concurrently calling this member function on the same instance
- * of this class are **not** guaranteed to work. Consider copying the object
- * and using different copies in each thread.
- *
- * @par Example
- * @snippet bigtable_instance_admin_snippets.cc list app profiles
- */
- StatusOr>
- ListAppProfiles(std::string const& instance_id);
-
- /**
- * Delete an existing application profile.
- *
- * @param instance_id the instance to look the profile in.
- * @param profile_id the id of the profile within that instance.
- * @param ignore_warnings if true, ignore safety checks when deleting the
- * application profile. This value is to to `true` by default. Passing
- * `false` causes this function to fail even when no operations are
- * pending.
- *
- * @par Idempotency
- * This operation is always treated as non-idempotent.
- *
- * @par Thread-safety
- * Two threads concurrently calling this member function on the same instance
- * of this class are **not** guaranteed to work. Consider copying the object
- * and using different copies in each thread.
- *
- * @par Example
- * @snippet bigtable_instance_admin_snippets.cc delete app profile
- */
- Status DeleteAppProfile(std::string const& instance_id,
- std::string const& profile_id,
- bool ignore_warnings = true);
-
- /**
- * Gets the native policy for @p instance_id.
- *
- * @param instance_id the instance to query.
- * @return google::iam::v1::Policy the full IAM policy for the instance.
- *
- * @par Idempotency
- * This operation is read-only and therefore it is always idempotent.
- *
- * @par Thread-safety
- * Two threads concurrently calling this member function on the same instance
- * of this class are **not** guaranteed to work. Consider copying the object
- * and using different copies in each thread.
- *
- * @par Example
- * @snippet bigtable_instance_admin_snippets.cc get native iam policy
- */
- StatusOr GetNativeIamPolicy(
- std::string const& instance_id);
-
- /**
- * Sets the IAM policy for an instance.
- *
- * @param instance_id which instance to set the IAM policy for.
- * @param iam_policy google::iam::v1::Policy object containing role and
- * members.
- * @return google::iam::v1::Policy the current IAM policy for the instance.
- *
- * @warning ETags are currently not used by Cloud Bigtable.
- *
- * @par Idempotency
- * This operation is always treated as non-idempotent.
- *
- * @par Thread-safety
- * Two threads concurrently calling this member function on the same instance
- * of this class are **not** guaranteed to work. Consider copying the object
- * and using different copies in each thread.
- *
- * @par Example
- * @snippet bigtable_instance_admin_snippets.cc set native iam policy
- */
- StatusOr SetIamPolicy(
- std::string const& instance_id,
- google::iam::v1::Policy const& iam_policy);
-
- /**
- * Returns a permission set that the caller has on the specified instance.
- *
- * @param instance_id the ID of the instance to query.
- * @param permissions set of permissions to check for the resource.
- *
- * @par Idempotency
- * This operation is read-only and therefore it is always idempotent.
- *
- * @par Thread-safety
- * Two threads concurrently calling this member function on the same instance
- * of this class are **not** guaranteed to work. Consider copying the object
- * and using different copies in each thread.
- *
- * @par Example
- * @snippet bigtable_instance_admin_snippets.cc test iam permissions
- *
- * @see https://cloud.google.com/bigtable/docs/access-control for a list of
- * valid permissions on Google Cloud Bigtable.
- */
- StatusOr> TestIamPermissions(
- std::string const& instance_id,
- std::vector const& permissions);
-
- private:
- friend class bigtable_internal::InstanceAdminTester;
-
- ///@{
- /// @name Helper functions to implement constructors with changed policies.
- void ChangePolicy(RPCRetryPolicy const& policy) {
- retry_prototype_ = policy.clone();
- }
-
- void ChangePolicy(RPCBackoffPolicy const& policy) {
- backoff_prototype_ = policy.clone();
- }
-
- void ChangePolicy(PollingPolicy const& policy) {
- polling_prototype_ = policy.clone();
- }
-
- template
- void ChangePolicies(Policy&& policy, Policies&&... policies) {
- ChangePolicy(policy);
- ChangePolicies(std::forward(policies)...);
- }
- void ChangePolicies() {}
- ///@}
-
- std::shared_ptr connection_;
- std::string project_id_;
- std::string project_name_;
- ///@{
- /// These prototypes are only used as temporary storage during construction of
- /// the class, where they are consolidated as common policies in `options_`.
- std::shared_ptr retry_prototype_;
- std::shared_ptr backoff_prototype_;
- std::shared_ptr polling_prototype_;
- ///}
- Options options_;
-};
-
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
-} // namespace bigtable
-} // namespace cloud
-} // namespace google
-
-#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_INSTANCE_ADMIN_H
diff --git a/google/cloud/bigtable/instance_admin_client.cc b/google/cloud/bigtable/instance_admin_client.cc
deleted file mode 100644
index 1309858e2d537..0000000000000
--- a/google/cloud/bigtable/instance_admin_client.cc
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright 2018 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 "google/cloud/bigtable/instance_admin_client.h"
-#include "google/cloud/bigtable/internal/defaults.h"
-
-namespace google {
-namespace cloud {
-namespace bigtable {
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
-
-std::shared_ptr MakeInstanceAdminClient(
- std::string project, Options options) {
- options = internal::DefaultInstanceAdminOptions(std::move(options));
- return std::shared_ptr(
- new InstanceAdminClient(std::move(project), std::move(options)));
-}
-
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
-} // namespace bigtable
-} // namespace cloud
-} // namespace google
diff --git a/google/cloud/bigtable/instance_admin_client.h b/google/cloud/bigtable/instance_admin_client.h
deleted file mode 100644
index e5c9e1acfb394..0000000000000
--- a/google/cloud/bigtable/instance_admin_client.h
+++ /dev/null
@@ -1,69 +0,0 @@
-// Copyright 2018 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.
-
-#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_INSTANCE_ADMIN_CLIENT_H
-#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_INSTANCE_ADMIN_CLIENT_H
-
-#include "google/cloud/bigtable/admin/bigtable_instance_admin_connection.h"
-#include "google/cloud/bigtable/version.h"
-#include
-#include
-
-namespace google {
-namespace cloud {
-namespace bigtable {
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
-
-/**
- * Creates a `bigtable_admin::BigtableInstanceAdminConnection` for
- * `bigtable::InstanceAdmin` to use.
- *
- * This class is used to initiate a connection to the Cloud Bigtable Instance
- * Admin service. It is maintained only for backwards compatibility.
- *
- * @deprecated Please use `bigtable_admin::BigtableInstanceAdminConnection` to
- * configure `bigtable_admin::BigtableInstanceAdminClient`, instead of using
- * this class to configure `bigtable::InstanceAdmin`.
- */
-class InstanceAdminClient final {
- public:
- virtual ~InstanceAdminClient() = default;
-
- /// The project id that this AdminClient works on.
- virtual std::string const& project() { return project_; }
-
- private:
- friend class InstanceAdmin;
- friend std::shared_ptr MakeInstanceAdminClient(
- std::string, Options);
-
- InstanceAdminClient(std::string project, Options options)
- : project_(std::move(project)),
- connection_(bigtable_admin::MakeBigtableInstanceAdminConnection(
- std::move(options))) {}
-
- std::string project_;
- std::shared_ptr connection_;
-};
-
-/// Create a new instance admin client configured via @p options.
-std::shared_ptr MakeInstanceAdminClient(
- std::string project, Options options = {});
-
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
-} // namespace bigtable
-} // namespace cloud
-} // namespace google
-
-#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_INSTANCE_ADMIN_CLIENT_H
diff --git a/google/cloud/bigtable/instance_admin_client_test.cc b/google/cloud/bigtable/instance_admin_client_test.cc
deleted file mode 100644
index a6cff0f75240a..0000000000000
--- a/google/cloud/bigtable/instance_admin_client_test.cc
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2018 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 "google/cloud/bigtable/instance_admin_client.h"
-#include
-
-namespace google {
-namespace cloud {
-namespace bigtable {
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
-namespace {
-
-TEST(InstanceAdminClientTest, MakeClient) {
- auto admin_client = MakeInstanceAdminClient("test-project");
- ASSERT_TRUE(admin_client);
- EXPECT_EQ("test-project", admin_client->project());
-}
-
-} // namespace
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
-} // namespace bigtable
-} // namespace cloud
-} // namespace google
diff --git a/google/cloud/bigtable/instance_admin_test.cc b/google/cloud/bigtable/instance_admin_test.cc
deleted file mode 100644
index 433eb80c5dc89..0000000000000
--- a/google/cloud/bigtable/instance_admin_test.cc
+++ /dev/null
@@ -1,694 +0,0 @@
-// Copyright 2022 Google LLC
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// https://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include "google/cloud/bigtable/instance_admin.h"
-#include "google/cloud/bigtable/admin/mocks/mock_bigtable_instance_admin_connection.h"
-#include "google/cloud/bigtable/testing/mock_policies.h"
-#include "google/cloud/grpc_options.h"
-#include "google/cloud/location.h"
-#include "google/cloud/project.h"
-#include "google/cloud/testing_util/status_matchers.h"
-#include
-
-namespace google {
-namespace cloud {
-namespace bigtable_internal {
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
-
-// Helper class for checking that the legacy API still functions correctly
-class InstanceAdminTester {
- public:
- static std::shared_ptr
- Connection(bigtable::InstanceAdmin const& admin) {
- return admin.connection_;
- }
-
- static ::google::cloud::Options Options(
- bigtable::InstanceAdmin const& admin) {
- return admin.options_;
- }
-};
-
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
-} // namespace bigtable_internal
-namespace bigtable {
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
-namespace {
-
-namespace btadmin = ::google::bigtable::admin::v2;
-namespace iamproto = ::google::iam::v1;
-
-using ::google::cloud::bigtable::testing::MockBackoffPolicy;
-using ::google::cloud::bigtable::testing::MockPollingPolicy;
-using ::google::cloud::bigtable::testing::MockRetryPolicy;
-using ::google::cloud::bigtable_internal::InstanceAdminTester;
-using ::google::cloud::testing_util::StatusIs;
-using ::testing::An;
-using ::testing::Contains;
-using ::testing::ElementsAreArray;
-using ::testing::NotNull;
-using ::testing::Return;
-using ::testing::UnorderedElementsAreArray;
-
-using MockConnection =
- ::google::cloud::bigtable_admin_mocks::MockBigtableInstanceAdminConnection;
-
-auto const kProjectId = "the-project";
-auto const kInstanceId = "the-instance";
-auto const kClusterId = "the-cluster";
-auto const kProfileId = "the-profile";
-auto const kProjectName = "projects/the-project";
-auto const kInstanceName = "projects/the-project/instances/the-instance";
-auto const kClusterName =
- "projects/the-project/instances/the-instance/clusters/the-cluster";
-auto const kProfileName =
- "projects/the-project/instances/the-instance/appProfiles/the-profile";
-
-std::string LocationName(std::string const& location) {
- return Location(Project(kProjectId), location).FullName();
-}
-
-Status FailingStatus() { return Status(StatusCode::kPermissionDenied, "fail"); }
-
-struct TestOption {
- using Type = int;
-};
-
-Options TestOptions() {
- return Options{}
- .set(grpc::InsecureChannelCredentials())
- .set(1);
-}
-
-void CheckOptions(Options const& options) {
- EXPECT_TRUE(
- options.has());
- EXPECT_TRUE(
- options.has());
- EXPECT_TRUE(
- options.has());
- EXPECT_TRUE(options.has());
- EXPECT_TRUE(options.has());
- EXPECT_TRUE(options.has());
-}
-
-/// A fixture for the bigtable::InstanceAdmin tests.
-class InstanceAdminTest : public ::testing::Test {
- protected:
- InstanceAdmin DefaultInstanceAdmin() {
- EXPECT_CALL(*connection_, options())
- .WillRepeatedly(Return(Options{}.set(1)));
- return InstanceAdmin(connection_, kProjectId);
- }
-
- std::shared_ptr connection_ =
- std::make_shared();
-};
-
-TEST_F(InstanceAdminTest, Project) {
- InstanceAdmin tested(MakeInstanceAdminClient(kProjectId, TestOptions()));
- EXPECT_EQ(kProjectId, tested.project_id());
- EXPECT_EQ(kProjectName, tested.project_name());
-}
-
-TEST_F(InstanceAdminTest, CopyConstructor) {
- auto source = InstanceAdmin(connection_, kProjectId);
- std::string const& expected = source.project_id();
- // NOLINTNEXTLINE(performance-unnecessary-copy-initialization)
- InstanceAdmin copy(source);
- EXPECT_EQ(expected, copy.project_id());
-}
-
-TEST_F(InstanceAdminTest, MoveConstructor) {
- auto source = InstanceAdmin(connection_, kProjectId);
- std::string expected = source.project_id();
- InstanceAdmin copy(std::move(source));
- EXPECT_EQ(expected, copy.project_id());
-}
-
-TEST_F(InstanceAdminTest, CopyAssignment) {
- std::shared_ptr other_client =
- std::make_shared();
-
- auto source = InstanceAdmin(connection_, kProjectId);
- std::string const& expected = source.project_id();
- auto dest = InstanceAdmin(other_client, "other-project");
- EXPECT_NE(expected, dest.project_id());
- dest = source;
- EXPECT_EQ(expected, dest.project_id());
-}
-
-TEST_F(InstanceAdminTest, MoveAssignment) {
- std::shared_ptr other_client =
- std::make_shared();
-
- auto source = InstanceAdmin(connection_, kProjectId);
- std::string expected = source.project_id();
- auto dest = InstanceAdmin(other_client, "other-project");
- EXPECT_NE(expected, dest.project_id());
- dest = std::move(source);
- EXPECT_EQ(expected, dest.project_id());
-}
-
-TEST_F(InstanceAdminTest, WithNewTarget) {
- auto admin = InstanceAdmin(connection_, kProjectId);
- auto other_admin = admin.WithNewTarget("other-project");
- EXPECT_EQ(other_admin.project_id(), "other-project");
- EXPECT_EQ(other_admin.project_name(), Project("other-project").FullName());
-}
-
-TEST_F(InstanceAdminTest, LegacyConstructorSharesConnection) {
- auto admin_client = MakeInstanceAdminClient("test-project", TestOptions());
- auto admin_1 = InstanceAdmin(admin_client);
- auto admin_2 = InstanceAdmin(admin_client);
- auto conn_1 = InstanceAdminTester::Connection(admin_1);
- auto conn_2 = InstanceAdminTester::Connection(admin_2);
-
- EXPECT_EQ(conn_1, conn_2);
- EXPECT_THAT(conn_1, NotNull());
-}
-
-TEST_F(InstanceAdminTest, LegacyConstructorDefaultsPolicies) {
- auto admin_client = MakeInstanceAdminClient("test-project", TestOptions());
- auto admin = InstanceAdmin(std::move(admin_client));
- auto options = InstanceAdminTester::Options(admin);
- CheckOptions(options);
-}
-
-TEST_F(InstanceAdminTest, LegacyConstructorWithPolicies) {
- // In this test, we make a series of simple calls to verify that the policies
- // passed to the `InstanceAdmin` constructor are actually collected as
- // `Options`.
- //
- // Upon construction of an InstanceAdmin, each policy is cloned twice: Once
- // while processing the variadic parameters, once while converting from
- // Bigtable policies to common policies. This should explain the nested mocks
- // below.
-
- auto mock_r = std::make_shared();
- auto mock_b = std::make_shared();
- auto mock_p = std::make_shared();
-
- EXPECT_CALL(*mock_r, clone).WillOnce([] {
- auto clone_1 = std::make_unique();
- EXPECT_CALL(*clone_1, clone).WillOnce([] {
- auto clone_2 = std::make_unique();
- EXPECT_CALL(*clone_2, OnFailure(An()));
- return clone_2;
- });
- return clone_1;
- });
-
- EXPECT_CALL(*mock_b, clone).WillOnce([] {
- auto clone_1 = std::make_unique();
- EXPECT_CALL(*clone_1, clone).WillOnce([] {
- auto clone_2 = std::make_unique();
- EXPECT_CALL(*clone_2, OnCompletion(An()));
- return clone_2;
- });
- return clone_1;
- });
-
- EXPECT_CALL(*mock_p, clone).WillOnce([] {
- auto clone_1 = std::make_unique();
- EXPECT_CALL(*clone_1, clone).WillOnce([] {
- auto clone_2 = std::make_unique();
- EXPECT_CALL(*clone_2, WaitPeriod);
- return clone_2;
- });
- return clone_1;
- });
-
- auto admin_client = MakeInstanceAdminClient("test-project", TestOptions());
- auto admin =
- InstanceAdmin(std::move(admin_client), *mock_r, *mock_b, *mock_p);
- auto options = InstanceAdminTester::Options(admin);
- CheckOptions(options);
-
- auto const& common_retry =
- options.get();
- (void)common_retry->OnFailure({});
-
- auto const& common_backoff =
- options.get();
- (void)common_backoff->OnCompletion();
-
- auto const& common_polling =
- options.get();
- (void)common_polling->WaitPeriod();
-}
-
-TEST_F(InstanceAdminTest, ListInstancesSuccess) {
- auto tested = DefaultInstanceAdmin();
- std::vector const expected_names = {
- InstanceName(kProjectId, "i0"), InstanceName(kProjectId, "i1")};
- std::vector const expected_fails = {"l0", "l1"};
-
- EXPECT_CALL(*connection_, ListInstances)
- .WillOnce([&expected_names, &expected_fails](
- btadmin::ListInstancesRequest const& request) {
- CheckOptions(google::cloud::internal::CurrentOptions());
- EXPECT_EQ(kProjectName, request.parent());
-
- btadmin::ListInstancesResponse response;
- for (auto const& name : expected_names) {
- auto& instance = *response.add_instances();
- instance.set_name(name);
- }
- for (auto const& loc : expected_fails) {
- *response.add_failed_locations() = loc;
- }
- return make_status_or(response);
- });
-
- auto actual = tested.ListInstances();
- ASSERT_STATUS_OK(actual);
- std::vector actual_names;
- std::transform(actual->instances.begin(), actual->instances.end(),
- std::back_inserter(actual_names),
- [](btadmin::Instance const& i) { return i.name(); });
-
- EXPECT_THAT(actual_names, ElementsAreArray(expected_names));
- EXPECT_THAT(actual->failed_locations, ElementsAreArray(expected_fails));
-}
-
-TEST_F(InstanceAdminTest, ListInstancesFailure) {
- auto tested = DefaultInstanceAdmin();
-
- EXPECT_CALL(*connection_, ListInstances).WillOnce(Return(FailingStatus()));
-
- EXPECT_THAT(tested.ListInstances(), StatusIs(StatusCode::kPermissionDenied));
-}
-
-TEST_F(InstanceAdminTest, CreateInstance) {
- auto tested = DefaultInstanceAdmin();
- auto constexpr kDisplayName = "display name";
- std::vector const expected_location_names = {LocationName("l0"),
- LocationName("l1")};
- std::map cluster_map = {
- {"c0", ClusterConfig("l0", 3, btadmin::HDD)},
- {"c1", ClusterConfig("l1", 3, btadmin::HDD)}};
- auto config = InstanceConfig(kInstanceId, kDisplayName, cluster_map);
-
- EXPECT_CALL(*connection_,
- CreateInstance(An()))
- .WillOnce([&](btadmin::CreateInstanceRequest const& request) {
- CheckOptions(google::cloud::internal::CurrentOptions());
- EXPECT_EQ(kInstanceId, request.instance_id());
- EXPECT_EQ(kProjectName, request.parent());
- EXPECT_EQ(kDisplayName, request.instance().display_name());
- std::vector actual_location_names;
- for (auto&& c : request.clusters()) {
- actual_location_names.emplace_back(c.second.location());
- }
- EXPECT_THAT(actual_location_names,
- UnorderedElementsAreArray(expected_location_names));
- return make_ready_future>(FailingStatus());
- });
-
- EXPECT_THAT(tested.CreateInstance(config).get(),
- StatusIs(StatusCode::kPermissionDenied));
-}
-
-TEST_F(InstanceAdminTest, CreateCluster) {
- auto tested = DefaultInstanceAdmin();
- auto const location_name = LocationName("the-location");
- auto config = ClusterConfig("the-location", 3, btadmin::HDD);
-
- EXPECT_CALL(*connection_,
- CreateCluster(An()))
- .WillOnce([&](btadmin::CreateClusterRequest const& request) {
- CheckOptions(google::cloud::internal::CurrentOptions());
- EXPECT_EQ(kClusterId, request.cluster_id());
- EXPECT_EQ(kInstanceName, request.parent());
- EXPECT_EQ(location_name, request.cluster().location());
- EXPECT_EQ(3, request.cluster().serve_nodes());
- EXPECT_EQ(btadmin::HDD, request.cluster().default_storage_type());
- return make_ready_future>(FailingStatus());
- });
-
- EXPECT_THAT(tested.CreateCluster(config, kInstanceId, kClusterId).get(),
- StatusIs(StatusCode::kPermissionDenied));
-}
-
-TEST_F(InstanceAdminTest, UpdateInstance) {
- auto tested = DefaultInstanceAdmin();
- auto constexpr kDisplayName = "updated display name";
- InstanceUpdateConfig config({});
- config.set_display_name(kDisplayName);
-
- EXPECT_CALL(
- *connection_,
- PartialUpdateInstance(An()))
- .WillOnce([&](btadmin::PartialUpdateInstanceRequest const& request) {
- CheckOptions(google::cloud::internal::CurrentOptions());
- EXPECT_EQ(kDisplayName, request.instance().display_name());
- EXPECT_THAT(request.update_mask().paths(), Contains("display_name"));
- return make_ready_future>(FailingStatus());
- });
-
- EXPECT_THAT(tested.UpdateInstance(config).get(),
- StatusIs(StatusCode::kPermissionDenied));
-}
-
-TEST_F(InstanceAdminTest, GetInstance) {
- auto tested = DefaultInstanceAdmin();
-
- EXPECT_CALL(*connection_, GetInstance)
- .WillOnce([&](btadmin::GetInstanceRequest const& request) {
- CheckOptions(google::cloud::internal::CurrentOptions());
- EXPECT_EQ(kInstanceName, request.name());
- return FailingStatus();
- });
-
- EXPECT_THAT(tested.GetInstance(kInstanceId),
- StatusIs(StatusCode::kPermissionDenied));
-}
-
-TEST_F(InstanceAdminTest, DeleteInstance) {
- auto tested = DefaultInstanceAdmin();
-
- EXPECT_CALL(*connection_, DeleteInstance)
- .WillOnce([&](btadmin::DeleteInstanceRequest const& request) {
- CheckOptions(google::cloud::internal::CurrentOptions());
- EXPECT_EQ(kInstanceName, request.name());
- return Status();
- });
-
- EXPECT_STATUS_OK(tested.DeleteInstance(kInstanceId));
-}
-
-TEST_F(InstanceAdminTest, GetCluster) {
- auto tested = DefaultInstanceAdmin();
-
- EXPECT_CALL(*connection_, GetCluster)
- .WillOnce([&](btadmin::GetClusterRequest const& request) {
- CheckOptions(google::cloud::internal::CurrentOptions());
- EXPECT_EQ(kClusterName, request.name());
- return FailingStatus();
- });
-
- EXPECT_THAT(tested.GetCluster(kInstanceId, kClusterId),
- StatusIs(StatusCode::kPermissionDenied));
-}
-
-TEST_F(InstanceAdminTest, ListClustersSuccess) {
- auto tested = DefaultInstanceAdmin();
- std::vector const expected_names = {
- ClusterName(kProjectId, kInstanceId, "c0"),
- ClusterName(kProjectId, kInstanceId, "c1")};
- std::vector const expected_fails = {"l0", "l1"};
-
- EXPECT_CALL(*connection_, ListClusters)
- .WillOnce([&](btadmin::ListClustersRequest const& request) {
- CheckOptions(google::cloud::internal::CurrentOptions());
- EXPECT_EQ(kInstanceName, request.parent());
-
- btadmin::ListClustersResponse response;
- for (auto const& name : expected_names) {
- auto& cluster = *response.add_clusters();
- cluster.set_name(name);
- }
- for (auto const& loc : expected_fails) {
- *response.add_failed_locations() = loc;
- }
- return make_status_or(response);
- });
-
- auto actual = tested.ListClusters(kInstanceId);
- ASSERT_STATUS_OK(actual);
- std::vector actual_names;
- std::transform(actual->clusters.begin(), actual->clusters.end(),
- std::back_inserter(actual_names),
- [](btadmin::Cluster const& c) { return c.name(); });
-
- EXPECT_THAT(actual_names, ElementsAreArray(expected_names));
- EXPECT_THAT(actual->failed_locations, ElementsAreArray(expected_fails));
-}
-
-TEST_F(InstanceAdminTest, ListClustersFailure) {
- auto tested = DefaultInstanceAdmin();
-
- EXPECT_CALL(*connection_, ListClusters)
- .WillOnce([&](btadmin::ListClustersRequest const& request) {
- CheckOptions(google::cloud::internal::CurrentOptions());
- // Verify that calling `ListClusters` with no arguments sets the
- // instance-id to "-"
- auto const instance_name = InstanceName(kProjectId, "-");
- EXPECT_EQ(instance_name, request.parent());
- return FailingStatus();
- });
-
- EXPECT_THAT(tested.ListClusters(), StatusIs(StatusCode::kPermissionDenied));
-}
-
-TEST_F(InstanceAdminTest, UpdateCluster) {
- auto tested = DefaultInstanceAdmin();
- auto const location_name = LocationName("the-location");
- btadmin::Cluster c;
- c.set_name(kClusterName);
- c.set_location(location_name);
- c.set_serve_nodes(3);
- c.set_default_storage_type(btadmin::HDD);
- auto config = ClusterConfig(std::move(c));
-
- EXPECT_CALL(*connection_, UpdateCluster(An()))
- .WillOnce([&](btadmin::Cluster const& cluster) {
- CheckOptions(google::cloud::internal::CurrentOptions());
- EXPECT_EQ(kClusterName, cluster.name());
- EXPECT_EQ(location_name, cluster.location());
- EXPECT_EQ(3, cluster.serve_nodes());
- EXPECT_EQ(btadmin::HDD, cluster.default_storage_type());
- return make_ready_future>(FailingStatus());
- });
-
- EXPECT_THAT(tested.UpdateCluster(config).get(),
- StatusIs(StatusCode::kPermissionDenied));
-}
-
-TEST_F(InstanceAdminTest, DeleteCluster) {
- auto tested = DefaultInstanceAdmin();
-
- EXPECT_CALL(*connection_, DeleteCluster)
- .WillOnce([&](btadmin::DeleteClusterRequest const& request) {
- CheckOptions(google::cloud::internal::CurrentOptions());
- EXPECT_EQ(kClusterName, request.name());
- return Status();
- });
-
- EXPECT_STATUS_OK(tested.DeleteCluster(kInstanceId, kClusterId));
-}
-
-TEST_F(InstanceAdminTest, CreateAppProfile) {
- auto tested = DefaultInstanceAdmin();
- auto config = AppProfileConfig::MultiClusterUseAny(kProfileId);
-
- EXPECT_CALL(*connection_, CreateAppProfile)
- .WillOnce([&](btadmin::CreateAppProfileRequest const& request) {
- CheckOptions(google::cloud::internal::CurrentOptions());
- EXPECT_EQ(kProfileId, request.app_profile_id());
- EXPECT_EQ(kInstanceName, request.parent());
- return FailingStatus();
- });
-
- EXPECT_THAT(tested.CreateAppProfile(kInstanceId, config),
- StatusIs(StatusCode::kPermissionDenied));
-}
-
-TEST_F(InstanceAdminTest, GetAppProfile) {
- auto tested = DefaultInstanceAdmin();
-
- EXPECT_CALL(*connection_, GetAppProfile)
- .WillOnce([&](btadmin::GetAppProfileRequest const& request) {
- CheckOptions(google::cloud::internal::CurrentOptions());
- EXPECT_EQ(kProfileName, request.name());
- return FailingStatus();
- });
-
- EXPECT_THAT(tested.GetAppProfile(kInstanceId, kProfileId),
- StatusIs(StatusCode::kPermissionDenied));
-}
-
-TEST_F(InstanceAdminTest, UpdateAppProfile) {
- auto tested = DefaultInstanceAdmin();
- auto constexpr kDescription = "description";
- auto config = AppProfileUpdateConfig().set_description(kDescription);
-
- EXPECT_CALL(*connection_,
- UpdateAppProfile(An()))
- .WillOnce([&](btadmin::UpdateAppProfileRequest const& request) {
- CheckOptions(google::cloud::internal::CurrentOptions());
- EXPECT_EQ(kProfileName, request.app_profile().name());
- EXPECT_EQ(kDescription, request.app_profile().description());
- return make_ready_future>(
- FailingStatus());
- });
-
- EXPECT_THAT(tested.UpdateAppProfile(kInstanceId, kProfileId, config).get(),
- StatusIs(StatusCode::kPermissionDenied));
-}
-
-TEST_F(InstanceAdminTest, ListAppProfilesSuccess) {
- auto tested = DefaultInstanceAdmin();
- std::vector const expected_names = {
- AppProfileName(kProjectId, kInstanceId, "p0"),
- AppProfileName(kProjectId, kInstanceId, "p1")};
-
- auto iter = expected_names.begin();
- EXPECT_CALL(*connection_, ListAppProfiles)
- .WillOnce([&iter, &expected_names](
- btadmin::ListAppProfilesRequest const& request) {
- CheckOptions(google::cloud::internal::CurrentOptions());
- EXPECT_EQ(kInstanceName, request.parent());
-
- using ::google::cloud::internal::MakeStreamRange;
- using ::google::cloud::internal::StreamReader;
- auto reader = [&iter, &expected_names]()
- -> StreamReader::result_type {
- if (iter != expected_names.end()) {
- btadmin::AppProfile p;
- p.set_name(*iter);
- ++iter;
- return p;
- }
- return Status();
- };
- return MakeStreamRange(std::move(reader));
- });
-
- auto profiles = tested.ListAppProfiles(kInstanceId);
- ASSERT_STATUS_OK(profiles);
- std::vector names;
- std::transform(profiles->begin(), profiles->end(), std::back_inserter(names),
- [](btadmin::AppProfile const& p) { return p.name(); });
-
- EXPECT_THAT(names, ElementsAreArray(expected_names));
-}
-
-TEST_F(InstanceAdminTest, ListAppProfilesFailure) {
- auto tested = DefaultInstanceAdmin();
-
- EXPECT_CALL(*connection_, ListAppProfiles)
- .WillOnce([&](btadmin::ListAppProfilesRequest const& request) {
- CheckOptions(google::cloud::internal::CurrentOptions());
- EXPECT_EQ(kInstanceName, request.parent());
-
- using ::google::cloud::internal::MakeStreamRange;
- return MakeStreamRange(
- [] { return FailingStatus(); });
- });
-
- EXPECT_THAT(tested.ListAppProfiles(kInstanceId),
- StatusIs(StatusCode::kPermissionDenied));
-}
-
-TEST_F(InstanceAdminTest, DeleteAppProfile) {
- auto tested = DefaultInstanceAdmin();
-
- EXPECT_CALL(*connection_, DeleteAppProfile)
- .WillOnce([&](btadmin::DeleteAppProfileRequest const& request) {
- CheckOptions(google::cloud::internal::CurrentOptions());
- EXPECT_EQ(kProfileName, request.name());
- EXPECT_EQ(true, request.ignore_warnings());
- return Status();
- });
-
- EXPECT_STATUS_OK(tested.DeleteAppProfile(kInstanceId, kProfileId, true));
-}
-
-TEST_F(InstanceAdminTest, GetNativeIamPolicy) {
- auto tested = DefaultInstanceAdmin();
-
- EXPECT_CALL(*connection_, GetIamPolicy)
- .WillOnce([&](iamproto::GetIamPolicyRequest const& request) {
- CheckOptions(google::cloud::internal::CurrentOptions());
- EXPECT_EQ(kInstanceName, request.resource());
- return FailingStatus();
- });
-
- EXPECT_THAT(tested.GetNativeIamPolicy(kInstanceId),
- StatusIs(StatusCode::kPermissionDenied));
-}
-
-TEST_F(InstanceAdminTest, SetNativeIamPolicy) {
- auto tested = DefaultInstanceAdmin();
- iamproto::Policy policy;
- policy.set_etag("tag");
- policy.set_version(3);
-
- EXPECT_CALL(*connection_, SetIamPolicy)
- .WillOnce([&](iamproto::SetIamPolicyRequest const& request) {
- CheckOptions(google::cloud::internal::CurrentOptions());
- EXPECT_EQ(kInstanceName, request.resource());
- EXPECT_EQ("tag", request.policy().etag());
- EXPECT_EQ(3, request.policy().version());
- return FailingStatus();
- });
-
- EXPECT_THAT(tested.SetIamPolicy(kInstanceId, policy),
- StatusIs(StatusCode::kPermissionDenied));
-}
-
-TEST_F(InstanceAdminTest, TestIamPermissionsSuccess) {
- auto tested = DefaultInstanceAdmin();
- std::vector const expected_permissions = {"writer", "reader"};
- std::vector const returned_permissions = {"reader"};
-
- EXPECT_CALL(*connection_, TestIamPermissions)
- .WillOnce([&](iamproto::TestIamPermissionsRequest const& request) {
- CheckOptions(google::cloud::internal::CurrentOptions());
- EXPECT_EQ(kInstanceName, request.resource());
- std::vector actual_permissions;
- for (auto const& c : request.permissions()) {
- actual_permissions.emplace_back(c);
- }
- EXPECT_THAT(actual_permissions,
- UnorderedElementsAreArray(expected_permissions));
-
- iamproto::TestIamPermissionsResponse r;
- for (auto const& p : returned_permissions) r.add_permissions(p);
- return r;
- });
-
- auto resp = tested.TestIamPermissions(kInstanceId, expected_permissions);
- ASSERT_STATUS_OK(resp);
- EXPECT_THAT(*resp, ElementsAreArray(returned_permissions));
-}
-
-TEST_F(InstanceAdminTest, TestIamPermissionsFailure) {
- auto tested = DefaultInstanceAdmin();
- std::vector const expected_permissions = {"writer", "reader"};
-
- EXPECT_CALL(*connection_, TestIamPermissions)
- .WillOnce([&](iamproto::TestIamPermissionsRequest const& request) {
- CheckOptions(google::cloud::internal::CurrentOptions());
- EXPECT_EQ(kInstanceName, request.resource());
- std::vector actual_permissions;
- for (auto const& c : request.permissions()) {
- actual_permissions.emplace_back(c);
- }
- EXPECT_THAT(actual_permissions,
- UnorderedElementsAreArray(expected_permissions));
- return FailingStatus();
- });
-
- EXPECT_THAT(tested.TestIamPermissions(kInstanceId, expected_permissions),
- StatusIs(StatusCode::kPermissionDenied));
-}
-
-} // namespace
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
-} // namespace bigtable
-} // namespace cloud
-} // namespace google
diff --git a/google/cloud/bigtable/table_admin.cc b/google/cloud/bigtable/table_admin.cc
deleted file mode 100644
index fb7758553c062..0000000000000
--- a/google/cloud/bigtable/table_admin.cc
+++ /dev/null
@@ -1,349 +0,0 @@
-// Copyright 2017 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 "google/cloud/bigtable/table_admin.h"
-#include "google/cloud/bigtable/admin/bigtable_table_admin_client.h"
-#include "google/cloud/bigtable/wait_for_consistency.h"
-#include "google/cloud/internal/time_utils.h"
-#include "google/protobuf/duration.pb.h"
-#include
-
-namespace btadmin = ::google::bigtable::admin::v2;
-
-namespace google {
-namespace cloud {
-namespace bigtable {
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
-static_assert(std::is_copy_constructible::value,
- "bigtable::TableAdmin must be constructible");
-static_assert(std::is_copy_assignable::value,
- "bigtable::TableAdmin must be assignable");
-
-// NOLINTNEXTLINE(readability-identifier-naming)
-constexpr TableAdmin::TableView TableAdmin::ENCRYPTION_VIEW;
-// NOLINTNEXTLINE(readability-identifier-naming)
-constexpr TableAdmin::TableView TableAdmin::FULL;
-// NOLINTNEXTLINE(readability-identifier-naming)
-constexpr TableAdmin::TableView TableAdmin::NAME_ONLY;
-// NOLINTNEXTLINE(readability-identifier-naming)
-constexpr TableAdmin::TableView TableAdmin::REPLICATION_VIEW;
-// NOLINTNEXTLINE(readability-identifier-naming)
-constexpr TableAdmin::TableView TableAdmin::SCHEMA_VIEW;
-// NOLINTNEXTLINE(readability-identifier-naming)
-constexpr TableAdmin::TableView TableAdmin::VIEW_UNSPECIFIED;
-
-StatusOr TableAdmin::CreateTable(std::string table_id,
- TableConfig config) {
- google::cloud::internal::OptionsSpan span(options_);
- auto request = std::move(config).as_proto();
- request.set_parent(instance_name());
- request.set_table_id(std::move(table_id));
- return connection_->CreateTable(request);
-}
-
-StatusOr> TableAdmin::ListTables(
- btadmin::Table::View view) {
- google::cloud::internal::OptionsSpan span(options_);
- std::vector result;
-
- btadmin::ListTablesRequest request;
- request.set_parent(instance_name());
- request.set_view(view);
- auto sr = connection_->ListTables(request);
- for (auto& t : sr) {
- if (!t) return std::move(t).status();
- result.emplace_back(*std::move(t));
- }
- return result;
-}
-
-StatusOr TableAdmin::GetTable(std::string const& table_id,
- btadmin::Table::View view) {
- google::cloud::internal::OptionsSpan span(options_);
- btadmin::GetTableRequest request;
- request.set_name(TableName(table_id));
- request.set_view(view);
- return connection_->GetTable(request);
-}
-
-Status TableAdmin::DeleteTable(std::string const& table_id) {
- google::cloud::internal::OptionsSpan span(options_);
- btadmin::DeleteTableRequest request;
- request.set_name(TableName(table_id));
- return connection_->DeleteTable(request);
-}
-
-btadmin::CreateBackupRequest TableAdmin::CreateBackupParams::AsProto(
- std::string instance_name) const {
- btadmin::CreateBackupRequest proto;
- proto.set_parent(instance_name + "/clusters/" + cluster_id);
- proto.set_backup_id(backup_id);
- proto.mutable_backup()->set_source_table(std::move(instance_name) +
- "/tables/" + table_name);
- *proto.mutable_backup()->mutable_expire_time() =
- google::cloud::internal::ToProtoTimestamp(expire_time);
- return proto;
-}
-
-StatusOr TableAdmin::CreateBackup(
- CreateBackupParams const& params) {
- google::cloud::internal::OptionsSpan span(options_);
- auto request = params.AsProto(instance_name());
- return connection_->CreateBackup(request).get();
-}
-
-StatusOr TableAdmin::GetBackup(std::string const& cluster_id,
- std::string const& backup_id) {
- google::cloud::internal::OptionsSpan span(options_);
- btadmin::GetBackupRequest request;
- request.set_name(BackupName(cluster_id, backup_id));
- return connection_->GetBackup(request);
-}
-
-btadmin::UpdateBackupRequest TableAdmin::UpdateBackupParams::AsProto(
- std::string const& instance_name) const {
- btadmin::UpdateBackupRequest proto;
- proto.mutable_backup()->set_name(instance_name + "/clusters/" + cluster_id +
- "/backups/" + backup_name);
- *proto.mutable_backup()->mutable_expire_time() =
- google::cloud::internal::ToProtoTimestamp(expire_time);
- proto.mutable_update_mask()->add_paths("expire_time");
- return proto;
-}
-
-StatusOr TableAdmin::UpdateBackup(
- UpdateBackupParams const& params) {
- google::cloud::internal::OptionsSpan span(options_);
- btadmin::UpdateBackupRequest request = params.AsProto(instance_name());
- return connection_->UpdateBackup(request);
-}
-
-Status TableAdmin::DeleteBackup(btadmin::Backup const& backup) {
- google::cloud::internal::OptionsSpan span(options_);
- btadmin::DeleteBackupRequest request;
- request.set_name(backup.name());
- return connection_->DeleteBackup(request);
-}
-
-Status TableAdmin::DeleteBackup(std::string const& cluster_id,
- std::string const& backup_id) {
- google::cloud::internal::OptionsSpan span(options_);
- btadmin::DeleteBackupRequest request;
- request.set_name(BackupName(cluster_id, backup_id));
- return connection_->DeleteBackup(request);
-}
-
-btadmin::ListBackupsRequest TableAdmin::ListBackupsParams::AsProto(
- std::string const& instance_name) const {
- btadmin::ListBackupsRequest proto;
- proto.set_parent(cluster_id ? instance_name + "/clusters/" + *cluster_id
- : instance_name + "/clusters/-");
- if (filter) *proto.mutable_filter() = *filter;
- if (order_by) *proto.mutable_order_by() = *order_by;
- return proto;
-}
-
-StatusOr> TableAdmin::ListBackups(
- ListBackupsParams const& params) {
- google::cloud::internal::OptionsSpan span(options_);
- std::vector result;
-
- btadmin::ListBackupsRequest request = params.AsProto(instance_name());
- auto sr = connection_->ListBackups(request);
- for (auto& b : sr) {
- if (!b) return std::move(b).status();
- result.emplace_back(*std::move(b));
- }
- return result;
-}
-
-btadmin::RestoreTableRequest TableAdmin::RestoreTableParams::AsProto(
- std::string const& instance_name) const {
- btadmin::RestoreTableRequest proto;
- proto.set_parent(instance_name);
- proto.set_table_id(table_id);
- proto.set_backup(instance_name + "/clusters/" + cluster_id + "/backups/" +
- backup_id);
- return proto;
-}
-
-StatusOr TableAdmin::RestoreTable(
- RestoreTableParams const& params) {
- auto p = RestoreTableFromInstanceParams{
- params.table_id, BackupName(params.cluster_id, params.backup_id)};
- return RestoreTable(std::move(p));
-}
-
-btadmin::RestoreTableRequest AsProto(
- std::string const& instance_name,
- TableAdmin::RestoreTableFromInstanceParams p) {
- btadmin::RestoreTableRequest proto;
- proto.set_parent(instance_name);
- proto.set_table_id(std::move(p.table_id));
- proto.set_backup(std::move(p.backup_name));
- return proto;
-}
-
-StatusOr TableAdmin::RestoreTable(
- RestoreTableFromInstanceParams params) {
- google::cloud::internal::OptionsSpan span(options_);
- auto request = AsProto(instance_name(), std::move(params));
- return connection_->RestoreTable(request).get();
-}
-
-StatusOr TableAdmin::ModifyColumnFamilies(
- std::string const& table_id,
- std::vector modifications) {
- google::cloud::internal::OptionsSpan span(options_);
- btadmin::ModifyColumnFamiliesRequest request;
- request.set_name(TableName(table_id));
- for (auto& m : modifications) {
- google::cloud::internal::OptionsSpan span(options_);
- *request.add_modifications() = std::move(m).as_proto();
- }
- return connection_->ModifyColumnFamilies(request);
-}
-
-Status TableAdmin::DropRowsByPrefix(std::string const& table_id,
- std::string row_key_prefix) {
- google::cloud::internal::OptionsSpan span(options_);
- btadmin::DropRowRangeRequest request;
- request.set_name(TableName(table_id));
- request.set_row_key_prefix(std::move(row_key_prefix));
- return connection_->DropRowRange(request);
-}
-
-future> TableAdmin::WaitForConsistency(
- std::string const& table_id, std::string const& consistency_token) {
- // We avoid lifetime issues due to ownership cycles, by holding the
- // `BackgroundThreads` which run the `CompletionQueue` outside of the
- // operation, in this class. If the `BackgroundThreads` running the
- // `CompletionQueue` were instead owned by the Connection, we would have an
- // ownership cycle. We have made this mistake before. See #7740 for more
- // details.
- auto client = bigtable_admin::BigtableTableAdminClient(connection_);
- return bigtable_admin::AsyncWaitForConsistency(cq_, std::move(client),
- TableName(table_id),
- consistency_token, options_)
- .then([](future f) -> StatusOr {
- auto s = f.get();
- if (!s.ok()) return s;
- return Consistency::kConsistent;
- });
-}
-
-Status TableAdmin::DropAllRows(std::string const& table_id) {
- google::cloud::internal::OptionsSpan span(options_);
- btadmin::DropRowRangeRequest request;
- request.set_name(TableName(table_id));
- request.set_delete_all_data_from_table(true);
- return connection_->DropRowRange(request);
-}
-
-StatusOr TableAdmin::GenerateConsistencyToken(
- std::string const& table_id) {
- google::cloud::internal::OptionsSpan span(options_);
- btadmin::GenerateConsistencyTokenRequest request;
- request.set_name(TableName(table_id));
- auto sor = connection_->GenerateConsistencyToken(request);
- if (!sor) return std::move(sor).status();
- return std::move(*sor->mutable_consistency_token());
-}
-
-StatusOr TableAdmin::CheckConsistency(
- std::string const& table_id, std::string const& consistency_token) {
- google::cloud::internal::OptionsSpan span(options_);
- btadmin::CheckConsistencyRequest request;
- request.set_name(TableName(table_id));
- request.set_consistency_token(consistency_token);
- auto sor = connection_->CheckConsistency(request);
- if (!sor) return std::move(sor).status();
- return sor->consistent() ? Consistency::kConsistent
- : Consistency::kInconsistent;
-}
-
-StatusOr TableAdmin::GetIamPolicy(
- std::string const& table_id) {
- return GetIamPolicyImpl(TableName(table_id));
-}
-
-StatusOr TableAdmin::GetIamPolicy(
- std::string const& cluster_id, std::string const& backup_id) {
- return GetIamPolicyImpl(BackupName(cluster_id, backup_id));
-}
-
-StatusOr TableAdmin::GetIamPolicyImpl(
- std::string resource) {
- google::cloud::internal::OptionsSpan span(options_);
- ::google::iam::v1::GetIamPolicyRequest request;
- request.set_resource(std::move(resource));
- return connection_->GetIamPolicy(request);
-}
-
-StatusOr TableAdmin::SetIamPolicy(
- std::string const& table_id, google::iam::v1::Policy const& iam_policy) {
- return SetIamPolicyImpl(TableName(table_id), iam_policy);
-}
-
-StatusOr TableAdmin::SetIamPolicy(
- std::string const& cluster_id, std::string const& backup_id,
- google::iam::v1::Policy const& iam_policy) {
- return SetIamPolicyImpl(BackupName(cluster_id, backup_id), iam_policy);
-}
-
-StatusOr TableAdmin::SetIamPolicyImpl(
- std::string resource, google::iam::v1::Policy const& iam_policy) {
- google::cloud::internal::OptionsSpan span(options_);
- ::google::iam::v1::SetIamPolicyRequest request;
- request.set_resource(std::move(resource));
- *request.mutable_policy() = iam_policy;
- return connection_->SetIamPolicy(request);
-}
-
-StatusOr> TableAdmin::TestIamPermissions(
- std::string const& table_id, std::vector const& permissions) {
- return TestIamPermissionsImpl(TableName(table_id), permissions);
-}
-
-StatusOr> TableAdmin::TestIamPermissions(
- std::string const& cluster_id, std::string const& backup_id,
- std::vector const& permissions) {
- return TestIamPermissionsImpl(BackupName(cluster_id, backup_id), permissions);
-}
-
-StatusOr> TableAdmin::TestIamPermissionsImpl(
- std::string resource, std::vector const& permissions) {
- google::cloud::internal::OptionsSpan span(options_);
- ::google::iam::v1::TestIamPermissionsRequest request;
- request.set_resource(std::move(resource));
- for (auto const& permission : permissions) {
- request.add_permissions(permission);
- }
- auto sor = connection_->TestIamPermissions(request);
- if (!sor) return std::move(sor).status();
- auto response = *std::move(sor);
- std::vector result;
- auto& ps = *response.mutable_permissions();
- std::move(ps.begin(), ps.end(), std::back_inserter(result));
- return result;
-}
-
-std::string TableAdmin::InstanceName() const {
- return google::cloud::bigtable::InstanceName(project_id_, instance_id_);
-}
-
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
-} // namespace bigtable
-} // namespace cloud
-} // namespace google
diff --git a/google/cloud/bigtable/table_admin.h b/google/cloud/bigtable/table_admin.h
deleted file mode 100644
index a53831d073b13..0000000000000
--- a/google/cloud/bigtable/table_admin.h
+++ /dev/null
@@ -1,1136 +0,0 @@
-// Copyright 2017 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.
-
-#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_TABLE_ADMIN_H
-#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_TABLE_ADMIN_H
-
-#include "google/cloud/bigtable/admin/bigtable_table_admin_connection.h"
-#include "google/cloud/bigtable/admin_client.h"
-#include "google/cloud/bigtable/column_family.h"
-#include "google/cloud/bigtable/completion_queue.h"
-#include "google/cloud/bigtable/iam_policy.h"
-#include "google/cloud/bigtable/internal/convert_policies.h"
-#include "google/cloud/bigtable/polling_policy.h"
-#include "google/cloud/bigtable/resource_names.h"
-#include "google/cloud/bigtable/table_config.h"
-#include "google/cloud/bigtable/version.h"
-#include "google/cloud/future.h"
-#include "google/cloud/grpc_error_delegate.h"
-#include "google/cloud/options.h"
-#include "google/cloud/status_or.h"
-#include "absl/types/optional.h"
-#include
-#include
-#include
-#include
-#include
-
-namespace google {
-namespace cloud {
-namespace bigtable_internal {
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
-class TableAdminTester;
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
-} // namespace bigtable_internal
-namespace bigtable {
-GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
-/// The result of checking replication against a given token.
-enum class Consistency {
- /// Some of the mutations created before the consistency token have not been
- /// received by all the table replicas.
- kInconsistent,
- /// All mutations created before the consistency token have been received by
- /// all the table replicas.
- kConsistent,
-};
-
-/**
- * Implements the API to administer tables in a Cloud Bigtable instance.
- *
- * @par Thread-safety
- * Instances of this class created via copy-construction or copy-assignment
- * share the underlying pool of connections. Access to these copies via multiple
- * threads is guaranteed to work. Two threads operating concurrently on the same
- * instance of this class is not guaranteed to work.
- *
- * @par Cost
- * Creating a new object of type `TableAdmin` is comparable to creating a few
- * objects of type `std::string` or a few objects of type
- * `std::shared_ptr`. The class represents a shallow handle to a remote
- * object.
- *
- * @par Error Handling
- * This class uses `StatusOr` to report errors. When an operation fails to
- * perform its work the returned `StatusOr` contains the error details. If
- * the `ok()` member function in the `StatusOr` returns `true` then it
- * contains the expected result. Operations that do not return a value simply
- * return a `google::cloud::Status` indicating success or the details of the
- * error Please consult the [`StatusOr`
- * documentation](#google::cloud::StatusOr) for more details.
- *
- * @code
- * namespace cbt = google::cloud::bigtable;
- * namespace btadmin = google::bigtable::admin::v2;
- * cbt::TableAdmin admin = ...;
- * google::cloud::StatusOr metadata = admin.GetTable(...);
- *
- * if (!metadata) {
- * std::cerr << "Error fetching table metadata\n";
- * return;
- * }
- *
- * // Use "metadata" as a smart pointer here, e.g.:
- * std::cout << "The full table name is " << table->name() << " the table has "
- * << table->column_families_size() << " column families\n";
- * @endcode
- *
- * In addition, the @ref index "main page" contains examples using `StatusOr`
- * to handle errors.
- *
- * @par Retry, Backoff, and Idempotency Policies
- * The library automatically retries requests that fail with transient errors,
- * and uses [truncated exponential backoff][backoff-link] to backoff between
- * retries. The default policies are to continue retrying for up to 10 minutes.
- * On each transient failure the backoff period is doubled, starting with an
- * initial backoff of 100 milliseconds. The backoff period growth is truncated
- * at 60 seconds. The default idempotency policy is to only retry idempotent
- * operations. Note that most operations that change state are **not**
- * idempotent.
- *
- * The application can override these policies when constructing objects of this
- * class. The documentation for the constructors show examples of this in
- * action.
- *
- * [backoff-link]: https://cloud.google.com/storage/docs/exponential-backoff
- *
- * @par Equality
- * `TableAdmin` objects will compare equal iff they were created with the
- * same `DataClient` and target the same Instance resource. Note that
- * `TableAdmin` objects can compare equal with different retry/backoff/polling
- * policies.
- *
- * @see https://cloud.google.com/bigtable/ for an overview of Cloud Bigtable.
- *
- * @see https://cloud.google.com/bigtable/docs/overview for an overview of the
- * Cloud Bigtable data model.
- *
- * @see https://cloud.google.com/bigtable/docs/instances-clusters-nodes for an
- * introduction of the main APIs into Cloud Bigtable.
- *
- * @see https://cloud.google.com/bigtable/docs/reference/service-apis-overview
- * for an overview of the underlying Cloud Bigtable API.
- *
- * @see #google::cloud::StatusOr for a description of the error reporting class
- * used by this library.
- *
- * @see `LimitedTimeRetryPolicy` and `LimitedErrorCountRetryPolicy` for
- * alternative retry policies.
- *
- * @see `ExponentialBackoffPolicy` to configure different parameters for the
- * exponential backoff policy.
- *
- * @see `SafeIdempotentMutationPolicy` and `AlwaysRetryMutationPolicy` for
- * alternative idempotency policies.
- */
-class TableAdmin {
- public:
- /**
- * @param client the interface to create grpc stubs, report errors, etc.
- * @param instance_id the id of the instance, e.g., "my-instance", the full
- * name (e.g. '/projects/my-project/instances/my-instance') is built using
- * the project id in the @p client parameter.
- */
- // NOLINTNEXTLINE(performance-unnecessary-value-param)
- TableAdmin(std::shared_ptr client, std::string instance_id)
- : connection_(client->connection_),
- cq_(client->cq_),
- background_threads_(client->background_threads_),
- project_id_(client->project()),
- instance_id_(std::move(instance_id)),
- instance_name_(InstanceName()),
- retry_prototype_(
- DefaultRPCRetryPolicy(internal::kBigtableTableAdminLimits)),
- backoff_prototype_(
- DefaultRPCBackoffPolicy(internal::kBigtableTableAdminLimits)),
- polling_prototype_(
- DefaultPollingPolicy(internal::kBigtableTableAdminLimits)),
- options_(google::cloud::internal::MergeOptions(
- bigtable_internal::MakeTableAdminOptions(
- retry_prototype_, backoff_prototype_, polling_prototype_),
- connection_->options())) {}
-
- /**
- * Create a new TableAdmin using explicit policies to handle RPC errors.
- *
- * @param client the interface to create grpc stubs, report errors, etc.
- * @param instance_id the id of the instance, e.g., "my-instance", the full
- * name (e.g. '/projects/my-project/instances/my-instance') is built using
- * the project id in the @p client parameter.
- * @param policies the set of policy overrides for this object.
- * @tparam Policies the types of the policies to override, the types must
- * derive from one of the following types:
- * - `RPCBackoffPolicy` how to backoff from a failed RPC. Currently only
- * `ExponentialBackoffPolicy` is implemented. You can also create your
- * own policies that backoff using a different algorithm.
- * - `RPCRetryPolicy` for how long to retry failed RPCs. Use
- * `LimitedErrorCountRetryPolicy` to limit the number of failures
- * allowed. Use `LimitedTimeRetryPolicy` to bound the time for any
- * request. You can also create your own policies that combine time and
- * error counts.
- * - `PollingPolicy` for how long will the class wait for
- * `google.longrunning.Operation` to complete. This class combines both
- * the backoff policy for checking long running operations and the
- * retry policy.
- *
- * @see GenericPollingPolicy, ExponentialBackoffPolicy,
- * LimitedErrorCountRetryPolicy, LimitedTimeRetryPolicy.
- */
- template
- // NOLINTNEXTLINE(performance-unnecessary-value-param)
- TableAdmin(std::shared_ptr client, std::string instance_id,
- Policies&&... policies)
- : connection_(client->connection_),
- cq_(client->cq_),
- background_threads_(client->background_threads_),
- project_id_(client->project()),
- instance_id_(std::move(instance_id)),
- instance_name_(InstanceName()),
- retry_prototype_(
- DefaultRPCRetryPolicy(internal::kBigtableTableAdminLimits)),
- backoff_prototype_(
- DefaultRPCBackoffPolicy(internal::kBigtableTableAdminLimits)),
- polling_prototype_(
- DefaultPollingPolicy(internal::kBigtableTableAdminLimits)) {
- ChangePolicies(std::forward(policies)...);
- options_ = google::cloud::internal::MergeOptions(
- bigtable_internal::MakeTableAdminOptions(
- retry_prototype_, backoff_prototype_, polling_prototype_),
- connection_->options());
- }
-
- TableAdmin(TableAdmin const&) = default;
- TableAdmin& operator=(TableAdmin const&) = default;
-
- friend bool operator==(TableAdmin const& a, TableAdmin const& b) noexcept {
- return a.connection_ == b.connection_ &&
- a.instance_name_ == b.instance_name_;
- }
- friend bool operator!=(TableAdmin const& a, TableAdmin const& b) noexcept {
- return !(a == b);
- }
-
- ///@{
- /// @name Convenience shorthands for the schema views.
- using TableView = ::google::bigtable::admin::v2::Table::View;
- /// Only populate 'name' and fields related to the table's encryption state.
- static auto constexpr ENCRYPTION_VIEW = // NOLINT(readability-identifier-naming)
- google::bigtable::admin::v2::Table::ENCRYPTION_VIEW;
- /// Populate all the fields in the response.
- static auto constexpr FULL = // NOLINT(readability-identifier-naming)
- google::bigtable::admin::v2::Table::FULL;
- /// Populate only the name in the responses.
- static auto constexpr NAME_ONLY = // NOLINT(readability-identifier-naming)
- google::bigtable::admin::v2::Table::NAME_ONLY;
- /// Populate only the name and the fields related to the table replication
- /// state.
- static auto constexpr REPLICATION_VIEW = // NOLINT(readability-identifier-naming)
- google::bigtable::admin::v2::Table::REPLICATION_VIEW;
- /// Populate only the name and the fields related to the table schema.
- static auto constexpr SCHEMA_VIEW = // NOLINT(readability-identifier-naming)
- google::bigtable::admin::v2::Table::SCHEMA_VIEW;
- /// Use the default view as defined for each function.
- static auto constexpr VIEW_UNSPECIFIED = // NOLINT(readability-identifier-naming)
- google::bigtable::admin::v2::Table::VIEW_UNSPECIFIED;
- ///@}
-
- std::string const& project() const { return project_id_; }
- std::string const& instance_id() const { return instance_id_; }
- std::string const& instance_name() const { return instance_name_; }
-
- /**
- * Returns a TableAdmin that reuses the connection and configuration of this
- * TableAdmin, but with a different resource name.
- */
- TableAdmin WithNewTarget(std::string project_id,
- std::string instance_id) const {
- auto table = *this;
- table.project_id_ = std::move(project_id);
- table.instance_id_ = std::move(instance_id);
- table.instance_name_ = table.InstanceName();
- return table;
- }
-
- /**
- * Create a new table in the instance.
- *
- * @param table_id the name of the table relative to the instance managed by
- * this object. The full table name is
- * `projects//instances//tables/`
- * where PROJECT_ID is obtained from the associated AdminClient and
- * INSTANCE_ID is the instance_id() of this object.
- * @param config the initial schema for the table.
- * @return the attributes of the newly created table. Notice that the server
- * only populates the table_name() field at this time.
- *
- * @par Idempotency
- * This operation is always treated as non-idempotent.
- *
- * @par Thread-safety
- * Two threads concurrently calling this member function on the same instance
- * of this class are **not** guaranteed to work. Consider copying the object
- * and using different copies in each thread.
- *
- * @par Example
- * @snippet table_admin_snippets.cc create table
- */
- StatusOr<::google::bigtable::admin::v2::Table> CreateTable(
- std::string table_id, TableConfig config);
-
- /**
- * Return all the tables in the instance.
- *
- * @param view define what information about the tables is retrieved.
- * - `VIEW_UNSPECIFIED`: equivalent to `VIEW_SCHEMA`.
- * - `NAME`: return only the name of the table.
- * - `VIEW_SCHEMA`: return the name and the schema.
- * - `FULL`: return all the information about the table.
- *
- * @par Idempotency
- * This operation is read-only and therefore it is always idempotent.
- *
- * @par Thread-safety
- * Two threads concurrently calling this member function on the same instance
- * of this class are **not** guaranteed to work. Consider copying the object
- * and using different copies in each thread.
- *
- * @par Example
- * @snippet table_admin_snippets.cc list tables
- */
- StatusOr> ListTables(
- ::google::bigtable::admin::v2::Table::View view);
-
- /**
- * Get information about a single table.
- *
- * @param table_id the id of the table within the instance associated with
- * this object. The full name of the table is
- * `this->instance_name() + "/tables/" + table_id`
- * @param view describes how much information to get about the name.
- * - VIEW_UNSPECIFIED: equivalent to VIEW_SCHEMA.
- * - NAME: return only the name of the table.
- * - VIEW_SCHEMA: return the name and the schema.
- * - FULL: return all the information about the table.
- * @return the information about the table or status.
- *
- * @par Idempotency
- * This operation is read-only and therefore it is always idempotent.
- *
- * @par Thread-safety
- * Two threads concurrently calling this member function on the same instance
- * of this class are **not** guaranteed to work. Consider copying the object
- * and using different copies in each thread.
- *
- * @par Example
- * @snippet table_admin_snippets.cc get table
- */
- StatusOr<::google::bigtable::admin::v2::Table> GetTable(
- std::string const& table_id, TableView view = SCHEMA_VIEW);
-
- /**
- * Delete a table.
- *
- * @param table_id the id of the table within the instance associated with
- * this object. The full name of the table is
- * `this->instance_name() + "/tables/" + table_id`
- *
- * @return status of the operation.
- *
- * @par Idempotency
- * This operation is always treated as non-idempotent.
- *
- * @par Thread-safety
- * Two threads concurrently calling this member function on the same instance
- * of this class are **not** guaranteed to work. Consider copying the object
- * and using different copies in each thread.
- *
- * @par Example
- * @snippet table_admin_snippets.cc delete table
- */
- Status DeleteTable(std::string const& table_id);
-
- /**
- * Parameters for `CreateBackup`.
- *
- * @param cluster_id the name of the cluster relative to the instance managed
- * by the `TableAdmin` object. The full cluster name is
- * `projects//instances//clusters/