19 #include "google/cloud/spanner/admin/database_admin_connection.h"
20 #include "google/cloud/spanner/admin/database_admin_options.h"
21 #include "google/cloud/spanner/admin/internal/database_admin_option_defaults.h"
22 #include "google/cloud/spanner/admin/internal/database_admin_stub_factory.h"
23 #include "google/cloud/background_threads.h"
24 #include "google/cloud/grpc_options.h"
25 #include "google/cloud/internal/async_long_running_operation.h"
26 #include "google/cloud/internal/pagination_range.h"
27 #include "google/cloud/internal/retry_loop.h"
37 StreamRange<
google::spanner::admin::database::v1::Database>
39 google::spanner::admin::database::v1::ListDatabasesRequest request) {
40 return google::
cloud::internal::MakePaginationRange<
41 StreamRange<
google::spanner::admin::database::v1::Database>>(
43 [](
google::spanner::admin::database::v1::ListDatabasesRequest
const&) {
47 [](
google::spanner::admin::database::v1::ListDatabasesResponse
const&) {
48 return std::vector<
google::spanner::admin::database::v1::Database>();
52 future<StatusOr<
google::spanner::admin::database::v1::Database>>
54 google::spanner::admin::database::v1::CreateDatabaseRequest
const&) {
60 StatusOr<
google::spanner::admin::database::v1::Database>
62 google::spanner::admin::database::v1::GetDatabaseRequest
const&) {
67 StatusOr<
google::spanner::admin::database::v1::UpdateDatabaseDdlMetadata>>
69 google::spanner::admin::database::v1::UpdateDatabaseDdlRequest
const&) {
76 google::spanner::admin::database::v1::DropDatabaseRequest
const&) {
80 StatusOr<
google::spanner::admin::database::v1::GetDatabaseDdlResponse>
82 google::spanner::admin::database::v1::GetDatabaseDdlRequest
const&) {
87 google::iam::v1::SetIamPolicyRequest
const&) {
92 google::iam::v1::GetIamPolicyRequest
const&) {
96 StatusOr<
google::iam::v1::TestIamPermissionsResponse>
98 google::iam::v1::TestIamPermissionsRequest
const&) {
102 future<StatusOr<
google::spanner::admin::database::v1::Backup>>
104 google::spanner::admin::database::v1::CreateBackupRequest
const&) {
110 StatusOr<
google::spanner::admin::database::v1::Backup>
112 google::spanner::admin::database::v1::GetBackupRequest
const&) {
116 StatusOr<
google::spanner::admin::database::v1::Backup>
118 google::spanner::admin::database::v1::UpdateBackupRequest
const&) {
123 google::spanner::admin::database::v1::DeleteBackupRequest
const&) {
127 StreamRange<
google::spanner::admin::database::v1::Backup>
129 google::spanner::admin::database::v1::ListBackupsRequest request) {
130 return google::
cloud::internal::MakePaginationRange<
131 StreamRange<
google::spanner::admin::database::v1::Backup>>(
133 [](
google::spanner::admin::database::v1::ListBackupsRequest
const&) {
137 [](
google::spanner::admin::database::v1::ListBackupsResponse
const&) {
138 return std::vector<
google::spanner::admin::database::v1::Backup>();
142 future<StatusOr<
google::spanner::admin::database::v1::Database>>
144 google::spanner::admin::database::v1::RestoreDatabaseRequest
const&) {
150 StreamRange<
google::longrunning::Operation>
152 google::spanner::admin::database::v1::ListDatabaseOperationsRequest
154 return google::
cloud::internal::MakePaginationRange<
155 StreamRange<
google::longrunning::Operation>>(
157 [](
google::spanner::admin::database::v1::
158 ListDatabaseOperationsRequest
const&) {
160 ListDatabaseOperationsResponse
>{};
162 [](
google::spanner::admin::database::v1::
163 ListDatabaseOperationsResponse
const&) {
164 return std::vector<
google::longrunning::Operation>();
168 StreamRange<
google::longrunning::Operation>
170 google::spanner::admin::database::v1::ListBackupOperationsRequest request) {
171 return google::
cloud::internal::MakePaginationRange<
172 StreamRange<
google::longrunning::Operation>>(
174 [](
google::spanner::admin::database::v1::
175 ListBackupOperationsRequest
const&) {
177 ListBackupOperationsResponse
>{};
179 [](
google::spanner::admin::database::v1::
180 ListBackupOperationsResponse
const&) {
181 return std::vector<
google::longrunning::Operation>();
188 DatabaseAdminConnectionImpl(
192 : background_(std::move(background)),
193 stub_(std::move(stub)),
194 retry_policy_prototype_(
196 backoff_policy_prototype_(
198 polling_policy_prototype_(
204 ~DatabaseAdminConnectionImpl()
override =
default;
206 StreamRange<
google::spanner::admin::database::v1::Database> ListDatabases(
207 google::spanner::admin::database::v1::ListDatabasesRequest request)
209 request.clear_page_token();
211 auto retry = std::shared_ptr<DatabaseAdminRetryPolicy
const>(
212 retry_policy_prototype_->clone());
213 auto backoff = std::shared_ptr<BackoffPolicy
const>(
214 backoff_policy_prototype_->clone());
216 char const* function_name =
__func__;
217 return google::
cloud::internal::MakePaginationRange<
218 StreamRange<
google::spanner::admin::database::v1::Database>>(
220 [stub, retry, backoff, idempotency, function_name](
221 google::spanner::admin::database::v1::ListDatabasesRequest
const&
224 retry->clone(), backoff->clone(), idempotency,
225 [stub](grpc::ClientContext& context,
226 google::spanner::admin::database::v1::
227 ListDatabasesRequest
const& request) {
232 [](
google::spanner::admin::database::v1::ListDatabasesResponse r) {
233 std::vector<
google::spanner::admin::database::v1::Database> result(
234 r.databases().size());
235 auto& messages = *r.mutable_databases();
236 std::move(messages.begin(), messages.end(), result.begin());
241 future<StatusOr<
google::spanner::admin::database::v1::Database>>
243 google::spanner::admin::database::v1::CreateDatabaseRequest
const&
246 return google::
cloud::internal::AsyncLongRunningOperation<
247 google::spanner::admin::database::v1::Database>(
248 background_->
cq(), request,
251 std::unique_ptr<grpc::ClientContext> context,
252 google::spanner::admin::database::v1::CreateDatabaseRequest
const&
257 std::unique_ptr<grpc::ClientContext> context,
258 google::longrunning::GetOperationRequest
const& request) {
262 std::unique_ptr<grpc::ClientContext> context,
263 google::longrunning::CancelOperationRequest
const& request) {
266 &
google::
cloud::internal::ExtractLongRunningResultResponse<
267 google::spanner::admin::database::v1::Database>,
268 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
270 polling_policy_prototype_->
clone(),
__func__);
273 StatusOr<
google::spanner::admin::database::v1::Database> GetDatabase(
274 google::spanner::admin::database::v1::GetDatabaseRequest
const& request)
277 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
279 [
this](grpc::ClientContext& context,
280 google::spanner::admin::database::v1::GetDatabaseRequest
const&
286 StatusOr<
google::spanner::admin::database::v1::UpdateDatabaseDdlMetadata>>
288 google::spanner::admin::database::v1::UpdateDatabaseDdlRequest
const&
291 return google::
cloud::internal::AsyncLongRunningOperation<
292 google::spanner::admin::database::v1::UpdateDatabaseDdlMetadata>(
293 background_->
cq(), request,
295 std::unique_ptr<grpc::ClientContext> context,
296 google::spanner::admin::database::v1::
297 UpdateDatabaseDdlRequest
const& request) {
301 std::unique_ptr<grpc::ClientContext> context,
302 google::longrunning::GetOperationRequest
const& request) {
306 std::unique_ptr<grpc::ClientContext> context,
307 google::longrunning::CancelOperationRequest
const& request) {
310 &
google::
cloud::internal::ExtractLongRunningResultMetadata<
311 google::spanner::admin::database::v1::UpdateDatabaseDdlMetadata>,
312 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
314 polling_policy_prototype_->
clone(),
__func__);
318 google::spanner::admin::database::v1::DropDatabaseRequest
const& request)
321 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
323 [
this](grpc::ClientContext& context,
324 google::spanner::admin::database::v1::DropDatabaseRequest
const&
329 StatusOr<
google::spanner::admin::database::v1::GetDatabaseDdlResponse>
331 google::spanner::admin::database::v1::GetDatabaseDdlRequest
const&
334 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
337 grpc::ClientContext& context,
338 google::spanner::admin::database::v1::GetDatabaseDdlRequest
const&
343 StatusOr<
google::iam::v1::Policy> SetIamPolicy(
344 google::iam::v1::SetIamPolicyRequest
const& request)
override {
346 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
348 [
this](grpc::ClientContext& context,
349 google::iam::v1::SetIamPolicyRequest
const& request) {
355 StatusOr<
google::iam::v1::Policy> GetIamPolicy(
356 google::iam::v1::GetIamPolicyRequest
const& request)
override {
358 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
360 [
this](grpc::ClientContext& context,
361 google::iam::v1::GetIamPolicyRequest
const& request) {
367 StatusOr<
google::iam::v1::TestIamPermissionsResponse> TestIamPermissions(
368 google::iam::v1::TestIamPermissionsRequest
const& request)
override {
370 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
372 [
this](grpc::ClientContext& context,
373 google::iam::v1::TestIamPermissionsRequest
const& request) {
379 future<StatusOr<
google::spanner::admin::database::v1::Backup>> CreateBackup(
380 google::spanner::admin::database::v1::CreateBackupRequest
const& request)
383 return google::
cloud::internal::AsyncLongRunningOperation<
384 google::spanner::admin::database::v1::Backup>(
385 background_->
cq(), request,
387 std::unique_ptr<grpc::ClientContext> context,
388 google::spanner::admin::database::v1::CreateBackupRequest
const&
393 std::unique_ptr<grpc::ClientContext> context,
394 google::longrunning::GetOperationRequest
const& request) {
398 std::unique_ptr<grpc::ClientContext> context,
399 google::longrunning::CancelOperationRequest
const& request) {
402 &
google::
cloud::internal::ExtractLongRunningResultResponse<
403 google::spanner::admin::database::v1::Backup>,
404 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
406 polling_policy_prototype_->
clone(),
__func__);
409 StatusOr<
google::spanner::admin::database::v1::Backup> GetBackup(
410 google::spanner::admin::database::v1::GetBackupRequest
const& request)
413 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
415 [
this](grpc::ClientContext& context,
416 google::spanner::admin::database::v1::GetBackupRequest
const&
417 request) {
return stub_->
GetBackup(context
, request
); },
421 StatusOr<
google::spanner::admin::database::v1::Backup> UpdateBackup(
422 google::spanner::admin::database::v1::UpdateBackupRequest
const& request)
425 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
427 [
this](grpc::ClientContext& context,
428 google::spanner::admin::database::v1::UpdateBackupRequest
const&
434 google::spanner::admin::database::v1::DeleteBackupRequest
const& request)
437 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
439 [
this](grpc::ClientContext& context,
440 google::spanner::admin::database::v1::DeleteBackupRequest
const&
445 StreamRange<
google::spanner::admin::database::v1::Backup> ListBackups(
446 google::spanner::admin::database::v1::ListBackupsRequest request)
448 request.clear_page_token();
450 auto retry = std::shared_ptr<DatabaseAdminRetryPolicy
const>(
451 retry_policy_prototype_->clone());
452 auto backoff = std::shared_ptr<BackoffPolicy
const>(
453 backoff_policy_prototype_->clone());
454 auto idempotency = idempotency_policy_->
ListBackups(request
);
455 char const* function_name =
__func__;
456 return google::
cloud::internal::MakePaginationRange<
457 StreamRange<
google::spanner::admin::database::v1::Backup>>(
459 [stub, retry, backoff, idempotency, function_name](
460 google::spanner::admin::database::v1::ListBackupsRequest
const& r) {
462 retry->clone(), backoff->clone(), idempotency,
463 [stub](grpc::ClientContext& context,
464 google::spanner::admin::database::v1::
465 ListBackupsRequest
const& request) {
470 [](
google::spanner::admin::database::v1::ListBackupsResponse r) {
471 std::vector<
google::spanner::admin::database::v1::Backup> result(
473 auto& messages = *r.mutable_backups();
474 std::move(messages.begin(), messages.end(), result.begin());
479 future<StatusOr<
google::spanner::admin::database::v1::Database>>
481 google::spanner::admin::database::v1::RestoreDatabaseRequest
const&
484 return google::
cloud::internal::AsyncLongRunningOperation<
485 google::spanner::admin::database::v1::Database>(
486 background_->
cq(), request,
489 std::unique_ptr<grpc::ClientContext> context,
490 google::spanner::admin::database::v1::RestoreDatabaseRequest
const&
495 std::unique_ptr<grpc::ClientContext> context,
496 google::longrunning::GetOperationRequest
const& request) {
500 std::unique_ptr<grpc::ClientContext> context,
501 google::longrunning::CancelOperationRequest
const& request) {
504 &
google::
cloud::internal::ExtractLongRunningResultResponse<
505 google::spanner::admin::database::v1::Database>,
506 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
508 polling_policy_prototype_->
clone(),
__func__);
511 StreamRange<
google::longrunning::Operation> ListDatabaseOperations(
512 google::spanner::admin::database::v1::ListDatabaseOperationsRequest
514 request.clear_page_token();
516 auto retry = std::shared_ptr<DatabaseAdminRetryPolicy
const>(
517 retry_policy_prototype_->clone());
518 auto backoff = std::shared_ptr<BackoffPolicy
const>(
519 backoff_policy_prototype_->clone());
521 char const* function_name =
__func__;
522 return google::
cloud::internal::MakePaginationRange<
523 StreamRange<
google::longrunning::Operation>>(
525 [stub, retry, backoff, idempotency,
526 function_name](
google::spanner::admin::database::v1::
527 ListDatabaseOperationsRequest
const& r) {
529 retry->clone(), backoff->clone(), idempotency,
530 [stub](grpc::ClientContext& context,
531 google::spanner::admin::database::v1::
532 ListDatabaseOperationsRequest
const& request) {
537 [](
google::spanner::admin::database::v1::ListDatabaseOperationsResponse
539 std::vector<
google::longrunning::Operation> result(
540 r.operations().size());
541 auto& messages = *r.mutable_operations();
542 std::move(messages.begin(), messages.end(), result.begin());
547 StreamRange<
google::longrunning::Operation> ListBackupOperations(
548 google::spanner::admin::database::v1::ListBackupOperationsRequest request)
550 request.clear_page_token();
552 auto retry = std::shared_ptr<DatabaseAdminRetryPolicy
const>(
553 retry_policy_prototype_->clone());
554 auto backoff = std::shared_ptr<BackoffPolicy
const>(
555 backoff_policy_prototype_->clone());
557 char const* function_name =
__func__;
558 return google::
cloud::internal::MakePaginationRange<
559 StreamRange<
google::longrunning::Operation>>(
561 [stub, retry, backoff, idempotency,
562 function_name](
google::spanner::admin::database::v1::
563 ListBackupOperationsRequest
const& r) {
565 retry->clone(), backoff->clone(), idempotency,
566 [stub](grpc::ClientContext& context,
567 google::spanner::admin::database::v1::
568 ListBackupOperationsRequest
const& request) {
573 [](
google::spanner::admin::database::v1::ListBackupOperationsResponse
575 std::vector<
google::longrunning::Operation> result(
576 r.operations().size());
577 auto& messages = *r.mutable_operations();
578 std::move(messages.begin(), messages.end(), result.begin());
586 std::unique_ptr<DatabaseAdminRetryPolicy
const> retry_policy_prototype_;
587 std::unique_ptr<BackoffPolicy
const> backoff_policy_prototype_;
588 std::unique_ptr<
PollingPolicy const> polling_policy_prototype_;
597 auto background = internal::MakeBackgroundThreadsFactory(options)();
599 background->
cq(), options
);
600 return std::make_shared<DatabaseAdminConnectionImpl>(
601 std::move(background), std::move(stub), options);
618 return std::make_shared<
spanner_admin::DatabaseAdminConnectionImpl>(
619 internal::MakeBackgroundThreadsFactory(options)(), std::move(stub),