Google Cloud Bigtable C++ Client 2.13.0
A C++ Client Library for Google Cloud Bigtable
Loading...
Searching...
No Matches
instance_admin.h
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// https://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#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_INSTANCE_ADMIN_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_INSTANCE_ADMIN_H
17
18#include "google/cloud/bigtable/admin/bigtable_instance_admin_connection.h"
19#include "google/cloud/bigtable/admin/bigtable_instance_admin_options.h"
20#include "google/cloud/bigtable/app_profile_config.h"
21#include "google/cloud/bigtable/cluster_config.h"
22#include "google/cloud/bigtable/cluster_list_responses.h"
23#include "google/cloud/bigtable/completion_queue.h"
24#include "google/cloud/bigtable/iam_policy.h"
25#include "google/cloud/bigtable/instance_admin_client.h"
26#include "google/cloud/bigtable/instance_config.h"
27#include "google/cloud/bigtable/instance_list_responses.h"
28#include "google/cloud/bigtable/instance_update_config.h"
29#include "google/cloud/bigtable/internal/convert_policies.h"
30#include "google/cloud/bigtable/polling_policy.h"
31#include "google/cloud/bigtable/resource_names.h"
32#include "google/cloud/bigtable/version.h"
33#include "google/cloud/future.h"
34#include "google/cloud/project.h"
35#include "google/cloud/status_or.h"
36#include <future>
37#include <memory>
38#include <string>
39#include <vector>
40
41namespace google {
42namespace cloud {
43namespace bigtable_internal {
44GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
45class InstanceAdminTester;
46GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
47} // namespace bigtable_internal
48namespace bigtable {
49GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
50
51/**
52 * Implements the APIs to administer Cloud Bigtable instances.
53 *
54 * @par Thread-safety
55 * Instances of this class created via copy-construction or copy-assignment
56 * share the underlying pool of connections. Access to these copies via multiple
57 * threads is guaranteed to work. Two threads operating concurrently on the same
58 * instance of this class is not guaranteed to work.
59 *
60 * @par Cost
61 * Creating a new object of type `InstanceAdmin` is comparable to creating a few
62 * objects of type `std::string` or a few objects of type
63 * `std::shared_ptr<int>`. The class represents a shallow handle to a remote
64 * object.
65 *
66 * @par Error Handling
67 * This class uses `StatusOr<T>` to report errors. When an operation fails to
68 * perform its work the returned `StatusOr<T>` contains the error details. If
69 * the `ok()` member function in the `StatusOr<T>` returns `true` then it
70 * contains the expected result. Operations that do not return a value simply
71 * return a `google::cloud::Status` indicating success or the details of the
72 * error Please consult the [`StatusOr<T>`
73 * documentation](#google::cloud::StatusOr) for more details.
74 *
75 * @code
76 * namespace cbt = google::cloud::bigtable;
77 * namespace btadmin = google::bigtable::admin::v2;
78 * cbt::InstanceAdmin admin = ...;
79 * google::cloud::StatusOr<btadmin::Instance> instance = admin.GetInstance(...);
80 *
81 * if (!instance) {
82 * std::cerr << "Error fetching instance\n";
83 * return;
84 * }
85 *
86 * // Use `instance` as a smart pointer here, e.g.:
87 * std::cout << "The full instance name is " << instance->name() << "\n";
88 * @endcode
89 *
90 * In addition, the @ref index "main page" contains examples using `StatusOr<T>`
91 * to handle errors.
92 *
93 * @par Retry, Backoff, and Idempotency Policies
94 * The library automatically retries requests that fail with transient errors,
95 * and uses [truncated exponential backoff][backoff-link] to backoff between
96 * retries. The default policies are to continue retrying for up to 10 minutes.
97 * On each transient failure the backoff period is doubled, starting with an
98 * initial backoff of 100 milliseconds. The backoff period growth is truncated
99 * at 60 seconds. The default idempotency policy is to only retry idempotent
100 * operations. Note that most operations that change state are **not**
101 * idempotent.
102 *
103 * The application can override these policies when constructing objects of this
104 * class. The documentation for the constructors show examples of this in
105 * action.
106 *
107 * [backoff-link]: https://cloud.google.com/storage/docs/exponential-backoff
108 *
109 * @see https://cloud.google.com/bigtable/ for an overview of Cloud Bigtable.
110 *
111 * @see https://cloud.google.com/bigtable/docs/overview for an overview of the
112 * Cloud Bigtable data model.
113 *
114 * @see https://cloud.google.com/bigtable/docs/instances-clusters-nodes for an
115 * introduction of the main APIs into Cloud Bigtable.
116 *
117 * @see https://cloud.google.com/bigtable/docs/reference/service-apis-overview
118 * for an overview of the underlying Cloud Bigtable API.
119 *
120 * @see #google::cloud::StatusOr for a description of the error reporting class
121 * used by this library.
122 *
123 * @see `LimitedTimeRetryPolicy` and `LimitedErrorCountRetryPolicy` for
124 * alternative retry policies.
125 *
126 * @see `ExponentialBackoffPolicy` to configure different parameters for the
127 * exponential backoff policy.
128 *
129 * @see `SafeIdempotentMutationPolicy` and `AlwaysRetryMutationPolicy` for
130 * alternative idempotency policies.
131 */
132class InstanceAdmin {
133 public:
134 explicit InstanceAdmin(
136 connection,
137 std::string project)
138 : connection_(std::move(connection)),
139 project_id_(std::move(project)),
140 project_name_(Project(project_id_).FullName()),
141 retry_prototype_(
142 DefaultRPCRetryPolicy(internal::kBigtableInstanceAdminLimits)),
143 backoff_prototype_(
144 DefaultRPCBackoffPolicy(internal::kBigtableInstanceAdminLimits)),
145 polling_prototype_(
146 DefaultPollingPolicy(internal::kBigtableInstanceAdminLimits)),
147 options_(google::cloud::internal::MergeOptions(
148 bigtable_internal::MakeInstanceAdminOptions(
149 retry_prototype_, backoff_prototype_, polling_prototype_),
150 connection_->options())) {}
151
152 /**
153 * @param client the interface to create grpc stubs, report errors, etc.
154 */
155 // NOLINTNEXTLINE(performance-unnecessary-value-param)
156 explicit InstanceAdmin(std::shared_ptr<InstanceAdminClient> client)
157 : InstanceAdmin(client->connection_, client->project()) {}
158
159 /**
160 * Create a new InstanceAdmin using explicit policies to handle RPC errors.
161 *
162 * @param client the interface to create grpc stubs, report errors, etc.
163 * @param policies the set of policy overrides for this object.
164 * @tparam Policies the types of the policies to override, the types must
165 * derive from one of the following types:
166 * - `RPCBackoffPolicy` how to backoff from a failed RPC. Currently only
167 * `ExponentialBackoffPolicy` is implemented. You can also create your
168 * own policies that backoff using a different algorithm.
169 * - `RPCRetryPolicy` for how long to retry failed RPCs. Use
170 * `LimitedErrorCountRetryPolicy` to limit the number of failures
171 * allowed. Use `LimitedTimeRetryPolicy` to bound the time for any
172 * request. You can also create your own policies that combine time and
173 * error counts.
174 * - `PollingPolicy` for how long will the class wait for
175 * `google.longrunning.Operation` to complete. This class combines both
176 * the backoff policy for checking long running operations and the
177 * retry policy.
178 *
179 * @see GenericPollingPolicy, ExponentialBackoffPolicy,
180 * LimitedErrorCountRetryPolicy, LimitedTimeRetryPolicy.
181 */
182 template <typename... Policies>
183 // NOLINTNEXTLINE(performance-unnecessary-value-param)
184 explicit InstanceAdmin(std::shared_ptr<InstanceAdminClient> client,
185 Policies&&... policies)
186 : connection_(client->connection_),
187 project_id_(client->project()),
188 project_name_(Project(project_id_).FullName()),
189 retry_prototype_(
190 DefaultRPCRetryPolicy(internal::kBigtableInstanceAdminLimits)),
191 backoff_prototype_(
192 DefaultRPCBackoffPolicy(internal::kBigtableInstanceAdminLimits)),
193 polling_prototype_(
194 DefaultPollingPolicy(internal::kBigtableInstanceAdminLimits)) {
195 ChangePolicies(std::forward<Policies>(policies)...);
196 options_ = google::cloud::internal::MergeOptions(
197 bigtable_internal::MakeInstanceAdminOptions(
198 retry_prototype_, backoff_prototype_, polling_prototype_),
199 connection_->options());
200 }
201
202 /// The full name (`projects/<project_id>`) of the project.
203 std::string const& project_name() const { return project_name_; }
204 /// The project id, i.e., `project_name()` without the `projects/` prefix.
205 std::string const& project_id() const { return project_id_; }
206
207 /**
208 * Returns an InstanceAdmin that reuses the connection and configuration of
209 * this InstanceAdmin, but with a different resource name.
210 */
211 InstanceAdmin WithNewTarget(std::string project_id) const {
212 auto admin = *this;
213 admin.project_id_ = std::move(project_id);
214 admin.project_name_ = Project(admin.project_id_).FullName();
215 return admin;
216 }
217
218 /// Return the fully qualified name of the given instance_id.
219 std::string InstanceName(std::string const& instance_id) const {
220 return google::cloud::bigtable::InstanceName(project_id_, instance_id);
221 }
222
223 /// Return the fully qualified name of the given cluster_id in give
224 /// instance_id.
225 std::string ClusterName(std::string const& instance_id,
226 std::string const& cluster_id) const {
227 return google::cloud::bigtable::ClusterName(project_id_, instance_id,
228 cluster_id);
229 }
230
231 std::string AppProfileName(std::string const& instance_id,
232 std::string const& profile_id) const {
233 return google::cloud::bigtable::AppProfileName(project_id_, instance_id,
234 profile_id);
235 }
236
237 /**
238 * Create a new instance of Cloud Bigtable.
239 *
240 * @warning Note that this is operation can take seconds or minutes to
241 * complete. The application may prefer to perform other work while waiting
242 * for this operation.
243 *
244 * @param instance_config a description of the new instance to be created.
245 * instance_id and a display_name parameters must be set in instance_config,
246 * - instance_id : must be between 6 and 33 characters.
247 * - display_name : must be between 4 and 30 characters.
248 * @return a future that becomes satisfied when (a) the operation has
249 * completed successfully, in which case it returns a proto with the
250 * Instance details, (b) the operation has failed, in which case the future
251 * contains an `google::cloud::Status` with the details of the failure, or
252 * (c) the state of the operation is unknown after the time allocated by the
253 * retry policies has expired, in which case the future contains the last
254 * error status.
255 *
256 * @par Idempotency
257 * This operation is always treated as non-idempotent.
258 *
259 * @par Thread-safety
260 * Two threads concurrently calling this member function on the same instance
261 * of this class are **not** guaranteed to work. Consider copying the object
262 * and using different copies in each thread.
263 *
264 * @par Example
265 * @snippet bigtable_instance_admin_snippets.cc create instance
266 */
267 future<StatusOr<google::bigtable::admin::v2::Instance>> CreateInstance(
268 InstanceConfig instance_config);
269
270 /**
271 * Create a new Cluster of Cloud Bigtable.
272 *
273 * @param cluster_config a description of the new cluster to be created.
274 * @param instance_id the id of the instance in the project
275 * @param cluster_id the id of the cluster in the project that needs to be
276 * created. It must be between 6 and 30 characters.
277 *
278 * @par Idempotency
279 * This operation is always treated as non-idempotent.
280 *
281 * @par Thread-safety
282 * Two threads concurrently calling this member function on the same instance
283 * of this class are **not** guaranteed to work. Consider copying the object
284 * and using different copies in each thread.
285 *
286 * @par Example
287 * @snippet bigtable_instance_admin_snippets.cc create cluster
288 */
289 future<StatusOr<google::bigtable::admin::v2::Cluster>> CreateCluster(
290 ClusterConfig cluster_config, std::string const& instance_id,
291 std::string const& cluster_id);
292
293 /**
294 * Update an existing instance of Cloud Bigtable.
295 *
296 * @warning Note that this is operation can take seconds or minutes to
297 * complete. The application may prefer to perform other work while waiting
298 * for this operation.
299 *
300 * @param instance_update_config config with modified instance.
301 * @return a future that becomes satisfied when (a) the operation has
302 * completed successfully, in which case it returns a proto with the
303 * Instance details, (b) the operation has failed, in which case the future
304 * contains an exception (typically `bigtable::GrpcError`) with the details
305 * of the failure, or (c) the state of the operation is unknown after the
306 * time allocated by the retry policies has expired, in which case the
307 * future contains an exception of type `bigtable::PollTimeout`.
308 *
309 * @par Idempotency
310 * This operation is always treated as non-idempotent.
311 *
312 * @par Thread-safety
313 * Two threads concurrently calling this member function on the same instance
314 * of this class are **not** guaranteed to work. Consider copying the object
315 * and using different copies in each thread.
316 *
317 * @par Example
318 * @snippet bigtable_instance_admin_snippets.cc update instance
319 */
320 future<StatusOr<google::bigtable::admin::v2::Instance>> UpdateInstance(
321 InstanceUpdateConfig instance_update_config);
322
323 /**
324 * Obtain the list of instances in the project.
325 *
326 * @note In some circumstances Cloud Bigtable may be unable to obtain the full
327 * list of instances, typically because some transient failure has made
328 * specific zones unavailable. In this cases the service returns a separate
329 * list of `failed_locations` that represent the unavailable zones.
330 * Applications may want to retry the operation after the transient
331 * conditions have cleared.
332 *
333 * @par Idempotency
334 * This operation is read-only and therefore it is always idempotent.
335 *
336 * @par Thread-safety
337 * Two threads concurrently calling this member function on the same instance
338 * of this class are **not** guaranteed to work. Consider copying the object
339 * and using different copies in each thread.
340 *
341 * @par Example
342 * @snippet bigtable_instance_admin_snippets.cc list instances
343 */
344 StatusOr<InstanceList> ListInstances();
345
346 /**
347 * Return the details of @p instance_id.
348 *
349 * @par Idempotency
350 * This operation is read-only and therefore it is always idempotent.
351 *
352 * @par Thread-safety
353 * Two threads concurrently calling this member function on the same instance
354 * of this class are **not** guaranteed to work. Consider copying the object
355 * and using different copies in each thread.
356 *
357 * @par Example
358 * @snippet bigtable_instance_admin_snippets.cc get instance
359 */
360 StatusOr<google::bigtable::admin::v2::Instance> GetInstance(
361 std::string const& instance_id);
362
363 /**
364 * Deletes the instances in the project.
365 *
366 * @param instance_id the id of the instance in the project that needs to be
367 * deleted
368 *
369 * @par Idempotency
370 * This operation is always treated as non-idempotent.
371 *
372 * @par Thread-safety
373 * Two threads concurrently calling this member function on the same instance
374 * of this class are **not** guaranteed to work. Consider copying the object
375 * and using different copies in each thread.
376 *
377 * @par Example
378 * @snippet bigtable_instance_admin_snippets.cc delete instance
379 */
380 Status DeleteInstance(std::string const& instance_id);
381
382 /**
383 * Obtain the list of clusters in an instance.
384 *
385 * @note In some circumstances Cloud Bigtable may be unable to obtain the full
386 * list of clusters, typically because some transient failure has made
387 * specific zones unavailable. In this cases the service returns a separate
388 * list of `failed_locations` that represent the unavailable zones.
389 * Applications may want to retry the operation after the transient
390 * conditions have cleared.
391 *
392 * @par Idempotency
393 * This operation is read-only and therefore it is always idempotent.
394 *
395 * @par Thread-safety
396 * Two threads concurrently calling this member function on the same instance
397 * of this class are **not** guaranteed to work. Consider copying the object
398 * and using different copies in each thread.
399 *
400 * @par Example
401 * @snippet bigtable_instance_admin_snippets.cc list clusters
402 */
403 StatusOr<ClusterList> ListClusters();
404
405 /**
406 * Obtain the list of clusters in an instance.
407 *
408 * @note In some circumstances Cloud Bigtable may be unable to obtain the full
409 * list of clusters, typically because some transient failure has made
410 * specific zones unavailable. In this cases the service returns a separate
411 * list of `failed_locations` that represent the unavailable zones.
412 * Applications may want to retry the operation after the transient
413 * conditions have cleared.
414 *
415 * @par Idempotency
416 * This operation is read-only and therefore it is always idempotent.
417 *
418 * @par Thread-safety
419 * Two threads concurrently calling this member function on the same instance
420 * of this class are **not** guaranteed to work. Consider copying the object
421 * and using different copies in each thread.
422 *
423 * @par Example
424 * @snippet bigtable_instance_admin_snippets.cc list clusters
425 */
426 StatusOr<ClusterList> ListClusters(std::string const& instance_id);
427
428 /**
429 * Update an existing cluster of Cloud Bigtable.
430 *
431 * @warning Note that this is operation can take seconds or minutes to
432 * complete. The application may prefer to perform other work while waiting
433 * for this operation.
434 *
435 * @param cluster_config cluster with updated values.
436 * @return a future that becomes satisfied when (a) the operation has
437 * completed successfully, in which case it returns a proto with the
438 * Instance details, (b) the operation has failed, in which case the future
439 * contains an exception (typically `bigtable::GrpcError`) with the details
440 * of the failure, or (c) the state of the operation is unknown after the
441 * time allocated by the retry policies has expired, in which case the
442 * future contains an exception of type `bigtable::PollTimeout`.
443 *
444 * @par Idempotency
445 * This operation is always treated as non-idempotent.
446 *
447 * @par Thread-safety
448 * Two threads concurrently calling this member function on the same instance
449 * of this class are **not** guaranteed to work. Consider copying the object
450 * and using different copies in each thread.
451 *
452 * @par Example
453 * @snippet bigtable_instance_admin_snippets.cc update cluster
454 */
455 future<StatusOr<google::bigtable::admin::v2::Cluster>> UpdateCluster(
456 ClusterConfig cluster_config);
457
458 /**
459 * Deletes the specified cluster of an instance in the project.
460 *
461 * @param instance_id the id of the instance in the project
462 * @param cluster_id the id of the cluster in the project that needs to be
463 * deleted
464 *
465 * @par Idempotency
466 * This operation is always treated as non-idempotent.
467 *
468 * @par Thread-safety
469 * Two threads concurrently calling this member function on the same instance
470 * of this class are **not** guaranteed to work. Consider copying the object
471 * and using different copies in each thread.
472 *
473 * @par Example
474 * @snippet bigtable_instance_admin_snippets.cc delete cluster
475 */
476 Status DeleteCluster(std::string const& instance_id,
477 std::string const& cluster_id);
478
479 /**
480 * Gets the specified cluster of an instance in the project.
481 *
482 * @param instance_id the id of the instance in the project
483 * @param cluster_id the id of the cluster in the project that needs to be
484 * deleted
485 * @return a Cluster for given instance_id and cluster_id.
486 *
487 * @par Idempotency
488 * This operation is read-only and therefore it is always idempotent.
489 *
490 * @par Thread-safety
491 * Two threads concurrently calling this member function on the same instance
492 * of this class are **not** guaranteed to work. Consider copying the object
493 * and using different copies in each thread.
494 *
495 * @par Example
496 * @snippet bigtable_instance_admin_snippets.cc get cluster
497 */
498 StatusOr<google::bigtable::admin::v2::Cluster> GetCluster(
499 std::string const& instance_id, std::string const& cluster_id);
500
501 /**
502 * Create a new application profile.
503 *
504 * @param instance_id the instance for the new application profile.
505 * @param config the configuration for the new application profile.
506 * @return The proto describing the new application profile.
507 *
508 * @par Idempotency
509 * This operation is always treated as non-idempotent.
510 *
511 * @par Thread-safety
512 * Two threads concurrently calling this member function on the same instance
513 * of this class are **not** guaranteed to work. Consider copying the object
514 * and using different copies in each thread.
515 *
516 * @par Multi-cluster Routing Example
517 * @snippet bigtable_instance_admin_snippets.cc create app profile
518 *
519 * @par Single Cluster Routing Example
520 * @snippet bigtable_instance_admin_snippets.cc create app profile cluster
521 */
522 StatusOr<google::bigtable::admin::v2::AppProfile> CreateAppProfile(
523 std::string const& instance_id, AppProfileConfig config);
524
525 /**
526 * Fetch the detailed information about an existing application profile.
527 *
528 * @param instance_id the instance to look the profile in.
529 * @param profile_id the id of the profile within that instance.
530 * @return The proto describing the application profile.
531 *
532 * @par Idempotency
533 * This operation is read-only and therefore it is always idempotent.
534 *
535 * @par Thread-safety
536 * Two threads concurrently calling this member function on the same instance
537 * of this class are **not** guaranteed to work. Consider copying the object
538 * and using different copies in each thread.
539 *
540 * @par Example
541 * @snippet bigtable_instance_admin_snippets.cc get app profile
542 */
543 StatusOr<google::bigtable::admin::v2::AppProfile> GetAppProfile(
544 std::string const& instance_id, std::string const& profile_id);
545
546 /**
547 * Updates an existing application profile.
548 *
549 * @param instance_id the instance for the new application profile.
550 * @param profile_id the id (not the full name) of the profile to update.
551 * @param config the configuration for the new application profile.
552 * @return The proto describing the new application profile.
553 *
554 * @par Idempotency
555 * This operation is always treated as non-idempotent.
556 *
557 * @par Thread-safety
558 * Two threads concurrently calling this member function on the same instance
559 * of this class are **not** guaranteed to work. Consider copying the object
560 * and using different copies in each thread.
561 *
562 * @par Change Description Example
563 * @snippet bigtable_instance_admin_snippets.cc update app profile description
564 *
565 * @par Change Routing to Any Cluster Example
566 * @snippet bigtable_instance_admin_snippets.cc update app profile routing any
567 *
568 * @par Change Routing to a Specific Cluster Example
569 * @snippet bigtable_instance_admin_snippets.cc update app profile routing
570 */
571 future<StatusOr<google::bigtable::admin::v2::AppProfile>> UpdateAppProfile(
572 std::string const& instance_id, std::string const& profile_id,
574
575 /**
576 * List the application profiles in an instance.
577 *
578 * @param instance_id the instance to list the profiles for.
579 * @return a std::vector with the protos describing any profiles.
580 *
581 * @par Idempotency
582 * This operation is read-only and therefore it is always idempotent.
583 *
584 * @par Thread-safety
585 * Two threads concurrently calling this member function on the same instance
586 * of this class are **not** guaranteed to work. Consider copying the object
587 * and using different copies in each thread.
588 *
589 * @par Example
590 * @snippet bigtable_instance_admin_snippets.cc list app profiles
591 */
592 StatusOr<std::vector<google::bigtable::admin::v2::AppProfile>>
593 ListAppProfiles(std::string const& instance_id);
594
595 /**
596 * Delete an existing application profile.
597 *
598 * @param instance_id the instance to look the profile in.
599 * @param profile_id the id of the profile within that instance.
600 * @param ignore_warnings if true, ignore safety checks when deleting the
601 * application profile. This value is to to `true` by default. Passing
602 * `false` causes this function to fail even when no operations are
603 * pending.
604 *
605 * @par Idempotency
606 * This operation is always treated as non-idempotent.
607 *
608 * @par Thread-safety
609 * Two threads concurrently calling this member function on the same instance
610 * of this class are **not** guaranteed to work. Consider copying the object
611 * and using different copies in each thread.
612 *
613 * @par Example
614 * @snippet bigtable_instance_admin_snippets.cc delete app profile
615 */
616 Status DeleteAppProfile(std::string const& instance_id,
617 std::string const& profile_id,
618 bool ignore_warnings = true);
619
620 /**
621 * Gets the native policy for @p instance_id.
622 *
623 * @param instance_id the instance to query.
624 * @return google::iam::v1::Policy the full IAM policy for the instance.
625 *
626 * @par Idempotency
627 * This operation is read-only and therefore it is always idempotent.
628 *
629 * @par Thread-safety
630 * Two threads concurrently calling this member function on the same instance
631 * of this class are **not** guaranteed to work. Consider copying the object
632 * and using different copies in each thread.
633 *
634 * @par Example
635 * @snippet bigtable_instance_admin_snippets.cc get native iam policy
636 */
637 StatusOr<google::iam::v1::Policy> GetNativeIamPolicy(
638 std::string const& instance_id);
639
640 /**
641 * Sets the IAM policy for an instance.
642 *
643 * @param instance_id which instance to set the IAM policy for.
644 * @param iam_policy google::iam::v1::Policy object containing role and
645 * members.
646 * @return google::iam::v1::Policy the current IAM policy for the instance.
647 *
648 * @warning ETags are currently not used by Cloud Bigtable.
649 *
650 * @par Idempotency
651 * This operation is always treated as non-idempotent.
652 *
653 * @par Thread-safety
654 * Two threads concurrently calling this member function on the same instance
655 * of this class are **not** guaranteed to work. Consider copying the object
656 * and using different copies in each thread.
657 *
658 * @par Example
659 * @snippet bigtable_instance_admin_snippets.cc set native iam policy
660 */
661 StatusOr<google::iam::v1::Policy> SetIamPolicy(
662 std::string const& instance_id,
663 google::iam::v1::Policy const& iam_policy);
664
665 /**
666 * Returns a permission set that the caller has on the specified instance.
667 *
668 * @param instance_id the ID of the instance to query.
669 * @param permissions set of permissions to check for the resource.
670 *
671 * @par Idempotency
672 * This operation is read-only and therefore it is always idempotent.
673 *
674 * @par Thread-safety
675 * Two threads concurrently calling this member function on the same instance
676 * of this class are **not** guaranteed to work. Consider copying the object
677 * and using different copies in each thread.
678 *
679 * @par Example
680 * @snippet bigtable_instance_admin_snippets.cc test iam permissions
681 *
682 * @see https://cloud.google.com/bigtable/docs/access-control for a list of
683 * valid permissions on Google Cloud Bigtable.
684 */
685 StatusOr<std::vector<std::string>> TestIamPermissions(
686 std::string const& instance_id,
687 std::vector<std::string> const& permissions);
688
689 private:
690 friend class bigtable_internal::InstanceAdminTester;
691
692 ///@{
693 /// @name Helper functions to implement constructors with changed policies.
694 void ChangePolicy(RPCRetryPolicy const& policy) {
695 retry_prototype_ = policy.clone();
696 }
697
698 void ChangePolicy(RPCBackoffPolicy const& policy) {
699 backoff_prototype_ = policy.clone();
700 }
701
702 void ChangePolicy(PollingPolicy const& policy) {
703 polling_prototype_ = policy.clone();
704 }
705
706 template <typename Policy, typename... Policies>
707 void ChangePolicies(Policy&& policy, Policies&&... policies) {
708 ChangePolicy(policy);
709 ChangePolicies(std::forward<Policies>(policies)...);
710 }
711 void ChangePolicies() {}
712 ///@}
713
714 std::shared_ptr<bigtable_admin::BigtableInstanceAdminConnection> connection_;
715 std::string project_id_;
716 std::string project_name_;
717 ///@{
718 /// These prototypes are only used as temporary storage during construction of
719 /// the class, where they are consolidated as common policies in `options_`.
720 std::shared_ptr<RPCRetryPolicy> retry_prototype_;
721 std::shared_ptr<RPCBackoffPolicy> backoff_prototype_;
722 std::shared_ptr<PollingPolicy> polling_prototype_;
723 ///}
724 Options options_;
725};
726
727GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
728} // namespace bigtable
729} // namespace cloud
730} // namespace google
731
732#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_INSTANCE_ADMIN_H
Options & operator=(Options &&)=default
Project(std::string project_id)
std::string FullName() const
Specify the initial configuration for an application profile.
Definition: app_profile_config.h:27
Build a proto to update an Application Profile configuration.
Definition: app_profile_config.h:99
Specify the initial configuration for a new cluster.
Definition: cluster_config.h:28
virtual std::string const & project()
The project id that this AdminClient works on.
Definition: instance_admin_client.h:45
Implements the APIs to administer Cloud Bigtable instances.
Definition: instance_admin.h:132
StatusOr< ClusterList > ListClusters(std::string const &instance_id)
Obtain the list of clusters in an instance.
StatusOr< std::vector< std::string > > TestIamPermissions(std::string const &instance_id, std::vector< std::string > const &permissions)
Returns a permission set that the caller has on the specified instance.
std::string const & project_name() const
The full name (projects/<project_id>) of the project.
Definition: instance_admin.h:203
future< StatusOr< google::bigtable::admin::v2::Instance > > CreateInstance(InstanceConfig instance_config)
Create a new instance of Cloud Bigtable.
std::string AppProfileName(std::string const &instance_id, std::string const &profile_id) const
Definition: instance_admin.h:231
InstanceAdmin WithNewTarget(std::string project_id) const
Returns an InstanceAdmin that reuses the connection and configuration of this InstanceAdmin,...
Definition: instance_admin.h:211
Status DeleteInstance(std::string const &instance_id)
Deletes the instances in the project.
StatusOr< ClusterList > ListClusters()
Obtain the list of clusters in an instance.
StatusOr< google::bigtable::admin::v2::AppProfile > GetAppProfile(std::string const &instance_id, std::string const &profile_id)
Fetch the detailed information about an existing application profile.
future< StatusOr< google::bigtable::admin::v2::Cluster > > CreateCluster(ClusterConfig cluster_config, std::string const &instance_id, std::string const &cluster_id)
Create a new Cluster of Cloud Bigtable.
StatusOr< std::vector< google::bigtable::admin::v2::AppProfile > > ListAppProfiles(std::string const &instance_id)
List the application profiles in an instance.
future< StatusOr< google::bigtable::admin::v2::Cluster > > UpdateCluster(ClusterConfig cluster_config)
Update an existing cluster of Cloud Bigtable.
future< StatusOr< google::bigtable::admin::v2::Instance > > UpdateInstance(InstanceUpdateConfig instance_update_config)
Update an existing instance of Cloud Bigtable.
StatusOr< google::iam::v1::Policy > GetNativeIamPolicy(std::string const &instance_id)
Gets the native policy for instance_id.
StatusOr< google::bigtable::admin::v2::Instance > GetInstance(std::string const &instance_id)
Return the details of instance_id.
InstanceAdmin(std::shared_ptr< bigtable_admin::BigtableInstanceAdminConnection > connection, std::string project)
Definition: instance_admin.h:134
StatusOr< google::iam::v1::Policy > SetIamPolicy(std::string const &instance_id, google::iam::v1::Policy const &iam_policy)
Sets the IAM policy for an instance.
InstanceAdmin(std::shared_ptr< InstanceAdminClient > client)
Definition: instance_admin.h:156
StatusOr< google::bigtable::admin::v2::Cluster > GetCluster(std::string const &instance_id, std::string const &cluster_id)
Gets the specified cluster of an instance in the project.
std::string const & project_id() const
The project id, i.e., project_name() without the projects/ prefix.
Definition: instance_admin.h:205
StatusOr< google::bigtable::admin::v2::AppProfile > CreateAppProfile(std::string const &instance_id, AppProfileConfig config)
Create a new application profile.
std::string ClusterName(std::string const &instance_id, std::string const &cluster_id) const
Return the fully qualified name of the given cluster_id in give instance_id.
Definition: instance_admin.h:225
future< StatusOr< google::bigtable::admin::v2::AppProfile > > UpdateAppProfile(std::string const &instance_id, std::string const &profile_id, AppProfileUpdateConfig config)
Updates an existing application profile.
StatusOr< InstanceList > ListInstances()
Obtain the list of instances in the project.
Status DeleteAppProfile(std::string const &instance_id, std::string const &profile_id, bool ignore_warnings=true)
Delete an existing application profile.
InstanceAdmin(std::shared_ptr< InstanceAdminClient > client, Policies &&... policies)
Create a new InstanceAdmin using explicit policies to handle RPC errors.
Definition: instance_admin.h:184
Status DeleteCluster(std::string const &instance_id, std::string const &cluster_id)
Deletes the specified cluster of an instance in the project.
std::string InstanceName(std::string const &instance_id) const
Return the fully qualified name of the given instance_id.
Definition: instance_admin.h:219
Specify the initial configuration for a new instance.
Definition: instance_config.h:30
Specify the initial configuration for updating an instance.
Definition: instance_update_config.h:33
Define the interface for providing asynchronous repetitive call rules.
Definition: polling_policy.h:34
virtual std::unique_ptr< PollingPolicy > clone() const =0
Return a new copy of this object.
Define the interface for controlling how the Bigtable client backsoff from failed RPC operations.
Definition: rpc_backoff_policy.h:44
virtual std::unique_ptr< RPCBackoffPolicy > clone() const =0
Return a new copy of this object.
Define the interface for controlling how the Bigtable client retries RPC operations.
Definition: rpc_retry_policy.h:78
virtual std::unique_ptr< RPCRetryPolicy > clone() const =0
Return a new copy of this object.
The BigtableInstanceAdminConnection object for BigtableInstanceAdminClient.
Definition: bigtable_instance_admin_connection.h:65
virtual Options options()
Definition: bigtable_instance_admin_connection.h:69
friend friend class future
Definition: bigtable_instance_admin_client.h:35
Contains all the Cloud Bigtable C++ client APIs.
Definition: admin_client.h:28
std::unique_ptr< RPCBackoffPolicy > DefaultRPCBackoffPolicy(internal::RPCPolicyParameters defaults)
Return an instance of the default RPCBackoffPolicy.
std::string InstanceName(std::string const &project_id, std::string const &instance_id)
std::string ClusterName(std::string const &project_id, std::string const &instance_id, std::string const &cluster_id)
std::unique_ptr< RPCRetryPolicy > DefaultRPCRetryPolicy(internal::RPCPolicyParameters defaults)
Return an instance of the default RPCRetryPolicy.
std::unique_ptr< PollingPolicy > DefaultPollingPolicy(internal::RPCPolicyParameters defaults)
std::string AppProfileName(std::string const &project_id, std::string const &instance_id, std::string const &app_profile_id)
The response for an asynchronous request listing all the clusters.
Definition: cluster_list_responses.h:30
The response for an asynchronous request listing all the instances.
Definition: instance_list_responses.h:30