Google Cloud Bigtable C++ Client  1.1.0
A C++ Client Library for Google Cloud Bigtable
instance_admin.cc
Go to the documentation of this file.
1 // Copyright 2018 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "google/cloud/bigtable/instance_admin.h"
16 #include "google/cloud/bigtable/internal/async_retry_multi_page.h"
17 #include "google/cloud/bigtable/internal/async_retry_unary_rpc_and_poll.h"
18 #include "google/cloud/bigtable/internal/unary_client_utils.h"
19 #include "google/cloud/grpc_utils/grpc_error_delegate.h"
20 #include "google/cloud/internal/throw_delegate.h"
21 #include <google/longrunning/operations.grpc.pb.h>
22 #include <google/protobuf/descriptor.h>
23 #include <google/protobuf/text_format.h>
24 #include <type_traits>
25 #include <unordered_set>
26 
27 namespace btadmin = ::google::bigtable::admin::v2;
28 
29 namespace google {
30 namespace cloud {
31 namespace bigtable {
32 inline namespace BIGTABLE_CLIENT_NS {
34  "bigtable::InstanceAdmin must be CopyAssignable");
35 
37 
41  // Copy the policies in effect for the operation.
44 
45  // Build the RPC request, try to minimize copying.
48  do {
52 
56  "InstanceAdmin::ListInstances", status, true);
57  if (!status.ok()) {
58  break;
59  }
60 
65  std::move(
68 
70  } while (!page_token.empty());
71 
72  if (!status.ok()) {
74  }
75 
78  return result;
79 }
80 
85  auto client = client_;
88 
89  struct Accumulator {
92  };
93 
101  },
109  response.instances().end(),
111  return acc;
112  },
113  cq)
115  -> StatusOr<InstanceList> {
116  auto acc = acc_future.get();
117  if (!acc) {
118  return acc.status();
119  }
124  return res;
125  });
126 }
127 
131  std::thread([](CompletionQueue cq) { cq.Run(); }, cq).detach();
132 
134  .then([cq](future<StatusOr<btadmin::Instance>> f) mutable {
135  cq.Shutdown();
136  return f.get();
137  });
138 }
139 
145  for (auto& kv : *request.mutable_clusters()) {
146  kv.second.set_location(project_name() + "/locations/" +
147  kv.second.location());
148  }
155  [client](
158  grpc::CompletionQueue* cq) {
160  },
161  std::move(request), cq);
162 }
163 
166  std::string const& cluster_id) {
168  std::thread([](CompletionQueue cq) { cq.Run(); }, cq).detach();
169 
171  cluster_id)
172  .then([cq](future<StatusOr<btadmin::Cluster>> f) mutable {
173  cq.Shutdown();
174  return f.get();
175  });
176 }
177 
181  std::string const& instance_id,
182  std::string const& cluster_id) {
184  cluster.set_location(project_name() + "/locations/" + cluster.location());
187  request.set_parent(project_name() + "/instances/" + instance_id);
189 
198  grpc::CompletionQueue* cq) {
200  },
201  std::move(request), cq);
202 }
203 
207  std::thread([](CompletionQueue cq) { cq.Run(); }, cq).detach();
208 
210  .then([cq](future<StatusOr<btadmin::Instance>> f) mutable {
211  cq.Shutdown();
212  return f.get();
213  });
214 }
215 
220 
229  request,
230  grpc::CompletionQueue* cq) {
232  },
233  std::move(request), cq);
234 }
235 
237  std::string const& instance_id) {
238  grpc::Status status;
239  // Copy the policies in effect for the operation.
242 
244  // Setting instance name.
245  request.set_name(project_name() + "/instances/" + instance_id);
246 
247  // Call RPC call to get response
248  auto result = ClientUtils::MakeCall(
250  &InstanceAdminClient::GetInstance, request, "InstanceAdmin::GetInstance",
251  status, true);
252  if (!status.ok()) {
254  }
255  return result;
256 }
257 
261  // Setting instance name.
262  request.set_name(project_name() + "/instances/" + instance_id);
263 
264  auto client = client_;
270  grpc::CompletionQueue* cq) {
272  },
273  std::move(request), cq);
274 }
275 
277  grpc::Status status;
280 
281  // This API is not idempotent, lets call it without retry
285  "InstanceAdmin::DeleteInstance", status);
287 }
288 
291  std::string const& cluster_id) {
294 
295  auto client = client_;
302  grpc::CompletionQueue* cq) {
304  },
305  std::move(request), cq)
307  auto res = fut.get();
308  if (res) {
309  return google::cloud::Status();
310  }
311  return res.status();
312  });
313 }
314 
318  // Setting instance name.
320 
321  auto client = client_;
328  request,
329  grpc::CompletionQueue* cq) {
331  },
332  std::move(request), cq)
334  return r.get().status();
335  });
336 }
337 
339  std::string const& instance_id, std::string const& cluster_id) {
340  grpc::Status status;
343 
346 
347  auto result = ClientUtils::MakeCall(
349  &InstanceAdminClient::GetCluster, request, "InstanceAdmin::GetCluster",
350  status, true);
351  if (!status.ok()) {
353  }
354  return result;
355 }
356 
359  std::string const& cluster_id) {
361  auto result = p.get_future();
363  // Setting cluster name.
365  auto client = client_;
371  grpc::CompletionQueue* cq) {
373  },
374  std::move(request), cq);
375 }
376 
378  return ListClusters("-");
379 }
380 
382  std::string const& instance_id) {
383  grpc::Status status;
387 
388  // Copy the policies in effect for the operation.
391 
392  do {
393  // Build the RPC request, try to minimize copying.
397 
398  auto response = ClientUtils::MakeCall(
401  "InstanceAdmin::ListClusters", status, true);
402  if (!status.ok()) {
403  break;
404  }
405 
410  std::move(
414  } while (!page_token.empty());
415 
416  if (!status.ok()) {
418  }
419 
422  return result;
423 }
424 
426  CompletionQueue& cq) {
427  return AsyncListClusters(cq, "-");
428 }
429 
432  auto client = client_;
435 
436  struct Accumulator {
439  };
440 
446  grpc::CompletionQueue* cq) {
448  },
457  return acc;
458  },
459  cq)
461  -> StatusOr<ClusterList> {
462  auto acc = acc_future.get();
463  if (!acc) {
464  return acc.status();
465  }
470  return res;
471  });
472 }
473 
477  std::thread([](CompletionQueue cq) { cq.Run(); }, cq).detach();
478 
480  .then([cq](future<StatusOr<btadmin::Cluster>> f) mutable {
481  cq.Shutdown();
482  return f.get();
483  });
484 }
485 
490 
498  google::bigtable::admin::v2::Cluster const& request,
499  grpc::CompletionQueue* cq) {
501  },
502  std::move(request), cq);
503 }
504 
506  std::string const& cluster_id) {
507  grpc::Status status;
510 
513 
514  // This API is not idempotent, lets call it without retry
518  "InstanceAdmin::DeleteCluster", status);
520 }
521 
524  grpc::Status status;
525  auto request = std::move(config).as_proto();
527 
528  // This is a non-idempotent API, use the correct retry loop for this type of
529  // operation.
533  "InstanceAdmin::CreateAppProfile", status);
534 
535  if (!status.ok()) {
537  }
538  return result;
539 }
540 
543  std::string const& instance_id,
545  auto request = std::move(config).as_proto();
547 
555  grpc::CompletionQueue* cq) {
557  },
558  std::move(request), cq);
559 }
560 
562  std::string const& instance_id, std::string const& profile_id) {
563  grpc::Status status;
565  request.set_name(InstanceName(instance_id) + "/appProfiles/" + profile_id);
566 
567  auto result = ClientUtils::MakeCall(
570  "InstanceAdmin::GetAppProfile", status, true);
571 
572  if (!status.ok()) {
574  }
575  return result;
576 }
577 
580  std::string const& instance_id,
581  std::string const& profile_id) {
583  request.set_name(InstanceName(instance_id) + "/appProfiles/" + profile_id);
584 
591  grpc::CompletionQueue* cq) {
593  },
594  std::move(request), cq);
595 }
596 
598  std::string const& instance_id, std::string const& profile_id,
601  std::thread([](CompletionQueue cq) { cq.Run(); }, cq).detach();
602 
604  .then([cq](future<StatusOr<btadmin::AppProfile>> f) mutable {
605  cq.Shutdown();
606  return f.get();
607  });
608 }
609 
612  std::string const& instance_id,
613  std::string const& profile_id,
615  auto request = std::move(config).as_proto();
617  InstanceName(instance_id + "/appProfiles/" + profile_id));
618 
625  [client](
628  grpc::CompletionQueue* cq) {
630  },
631  std::move(request), cq);
632 }
633 
635  std::string const& instance_id) {
636  grpc::Status status;
639  // Copy the policies in effect for the operation.
642 
643  do {
644  // Build the RPC request, try to minimize copying.
648 
649  auto response = ClientUtils::MakeCall(
652  "InstanceAdmin::ListAppProfiles", status, true);
653  if (!status.ok()) {
654  break;
655  }
656 
657  for (auto& x : *response.mutable_app_profiles()) {
659  }
661  } while (!page_token.empty());
662 
663  if (!status.ok()) {
665  }
666  return result;
667 }
668 
671  std::string const& instance_id) {
672  auto client = client_;
675 
681  grpc::CompletionQueue* cq) {
683  },
689  return acc;
690  },
691  cq);
692 }
693 
695  std::string const& profile_id,
696  bool ignore_warnings) {
697  grpc::Status status;
699  request.set_name(InstanceName(instance_id) + "/appProfiles/" + profile_id);
701 
705  "InstanceAdmin::DeleteAppProfile", status);
706 
708 }
709 
712  std::string const& profile_id, bool ignore_warnings) {
714  request.set_name(InstanceName(instance_id) + "/appProfiles/" + profile_id);
716 
724  grpc::CompletionQueue* cq) {
726  },
727  std::move(request), cq)
729  auto res = fut.get();
730  if (res) {
731  return google::cloud::Status();
732  }
733  return res.status();
734  });
735 }
736 
738  std::string const& instance_id) {
739  grpc::Status status;
742 
745 
748 
749  auto proto = ClientUtils::MakeCall(
752  "InstanceAdmin::GetIamPolicy", status, true);
753 
754  if (!status.ok()) {
756  }
757 
758  return ProtoToWrapper(std::move(proto));
759 }
760 
762  std::string const& instance_id) {
763  grpc::Status status;
766 
769 
772 
773  auto proto = ClientUtils::MakeCall(
776  "InstanceAdmin::GetIamPolicy", status, true);
777 
778  if (!status.ok()) {
780  }
781 
782  return proto;
783 }
784 
789 
797  grpc::CompletionQueue* cq) {
799  },
800  std::move(request), cq)
801  .then([](future<StatusOr<::google::iam::v1::Policy>> fut)
803  auto res = fut.get();
804  if (!res) {
805  return res.status();
806  }
807  return ProtoToWrapper(std::move(*res));
808  });
809 }
810 
813  std::string const& instance_id) {
816 
824  grpc::CompletionQueue* cq) {
826  },
827  std::move(request), cq);
828 }
829 
831  std::string const& instance_id,
832  google::cloud::IamBindings const& iam_bindings, std::string const& etag) {
833  grpc::Status status;
836 
837  ::google::iam::v1::Policy policy;
840  for (auto& binding : role_bindings) {
843  for (auto& member : binding.second) {
845  }
846  }
847 
851 
854 
855  auto proto = ClientUtils::MakeCall(
858  "InstanceAdmin::SetIamPolicy", status, true);
859 
860  if (!status.ok()) {
862  }
863 
864  return ProtoToWrapper(std::move(proto));
865 }
866 
868  std::string const& instance_id, google::iam::v1::Policy const& iam_policy) {
869  grpc::Status status;
872 
876 
879 
880  auto proto = ClientUtils::MakeCall(
883  "InstanceAdmin::SetIamPolicy", status, true);
884 
885  if (!status.ok()) {
887  }
888 
889  return proto;
890 }
891 
894  google::cloud::IamBindings const& iam_bindings, std::string const& etag) {
895  ::google::iam::v1::Policy policy;
898  for (auto& binding : role_bindings) {
901  for (auto& member : binding.second) {
903  }
904  }
905 
909 
917  grpc::CompletionQueue* cq) {
919  },
920  std::move(request), cq)
923  auto response = response_fut.get();
924  if (!response) {
925  return response.status();
926  }
927  return ProtoToWrapper(std::move(*response));
928  });
929 }
930 
933  google::iam::v1::Policy const& iam_policy) {
937 
945  grpc::CompletionQueue* cq) {
947  },
948  std::move(request), cq);
949 }
950 
952  std::string const& instance_id,
953  std::vector<std::string> const& permissions) {
954  grpc::Status status;
957 
958  // Copy the policies in effect for the operation.
961 
962  for (auto& permission : permissions) {
964  }
965 
968 
969  auto response = ClientUtils::MakeCall(
972  "InstanceAdmin::TestIamPermissions", status, true);
973 
975 
976  for (auto& permission : *response.mutable_permissions()) {
978  }
979 
980  if (!status.ok()) {
982  }
983 
984  return resource_permissions;
985 }
986 
990  std::vector<std::string> const& permissions) {
993  for (auto& permission : permissions) {
995  }
996 
997  auto client = client_;
1002  [client](
1005  grpc::CompletionQueue* cq) {
1007  },
1008  std::move(request), cq)
1011  auto response = response_fut.get();
1012  if (!response) {
1013  return response.status();
1014  }
1015  std::vector<std::string> res;
1019  std::back_inserter(res));
1020  return res;
1021  });
1022 }
1023 
1025  google::iam::v1::Policy proto) {
1029  for (auto& binding : *proto.mutable_bindings()) {
1032  for (auto field_desc : field_descs) {
1033  if (field_desc->name() != "members" && field_desc->name() != "role") {
1034  std::stringstream os;
1035  // TODO(#2732): Advise alternative API after it's implemented.
1036  os << "IamBinding field \"" << field_desc->name()
1037  << "\" is unknown to Bigtable C++ client. Please use a client in "
1038  "another language.";
1039  return Status(StatusCode::kUnimplemented, os.str());
1040  }
1041  }
1042  for (auto& member : *binding.mutable_members()) {
1044  }
1045  }
1046  return result;
1047 }
1048 
1049 } // namespace BIGTABLE_CLIENT_NS
1050 } // namespace bigtable
1051 } // namespace cloud
1052 } // namespace google
#define BIGTABLE_CLIENT_NS
Definition: version.h:22
bigtable::internal::UnaryClientUtils< InstanceAdminClient > ClientUtils
Shortcuts to avoid typing long names over and over.