Google Cloud Bigtable C++ Client  1.40.2
A C++ Client Library for Google Cloud Bigtable
Public Member Functions | List of all members
google::cloud::bigtable::InstanceAdmin Class Reference

Implements the APIs to administer Cloud Bigtable instances. More...

#include <google/cloud/bigtable/instance_admin.h>

Public Member Functions

 InstanceAdmin (std::shared_ptr< bigtable_admin::BigtableInstanceAdminConnection > connection, std::string project)
 
 InstanceAdmin (std::shared_ptr< InstanceAdminClient > client)
 
template<typename... Policies>
 InstanceAdmin (std::shared_ptr< InstanceAdminClient > client, Policies &&... policies)
 Create a new InstanceAdmin using explicit policies to handle RPC errors. More...
 
std::string const & project_name () const
 The full name (projects/<project_id>) of the project. More...
 
std::string const & project_id () const
 The project id, i.e., project_name() without the projects/ prefix. More...
 
InstanceAdmin WithNewTarget (std::string project_id) const
 Returns an InstanceAdmin that reuses the connection and configuration of this InstanceAdmin, but with a different resource name. More...
 
std::string InstanceName (std::string const &instance_id) const
 Return the fully qualified name of the given instance_id. More...
 
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. More...
 
std::string AppProfileName (std::string const &instance_id, std::string const &profile_id) const
 
future< StatusOr< google::bigtable::admin::v2::Instance > > CreateInstance (InstanceConfig instance_config)
 Create a new instance of Cloud Bigtable. More...
 
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. More...
 
future< StatusOr< google::bigtable::admin::v2::Instance > > UpdateInstance (InstanceUpdateConfig instance_update_config)
 Update an existing instance of Cloud Bigtable. More...
 
StatusOr< InstanceListListInstances ()
 Obtain the list of instances in the project. More...
 
StatusOr< google::bigtable::admin::v2::Instance > GetInstance (std::string const &instance_id)
 Return the details of instance_id. More...
 
Status DeleteInstance (std::string const &instance_id)
 Deletes the instances in the project. More...
 
StatusOr< ClusterListListClusters ()
 Obtain the list of clusters in an instance. More...
 
StatusOr< ClusterListListClusters (std::string const &instance_id)
 Obtain the list of clusters in an instance. More...
 
future< StatusOr< google::bigtable::admin::v2::Cluster > > UpdateCluster (ClusterConfig cluster_config)
 Update an existing cluster of Cloud Bigtable. More...
 
Status DeleteCluster (std::string const &instance_id, std::string const &cluster_id)
 Deletes the specified cluster of an instance in the project. More...
 
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. More...
 
StatusOr< google::bigtable::admin::v2::AppProfile > CreateAppProfile (std::string const &instance_id, AppProfileConfig config)
 Create a new application profile. More...
 
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. More...
 
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. More...
 
StatusOr< std::vector< google::bigtable::admin::v2::AppProfile > > ListAppProfiles (std::string const &instance_id)
 List the application profiles in an instance. More...
 
Status DeleteAppProfile (std::string const &instance_id, std::string const &profile_id, bool ignore_warnings=true)
 Delete an existing application profile. More...
 
StatusOr< google::iam::v1::Policy > GetNativeIamPolicy (std::string const &instance_id)
 Gets the native policy for instance_id. More...
 
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. More...
 
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. More...
 

Detailed Description

Implements the APIs to administer Cloud Bigtable instances.

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.
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<int>. The class represents a shallow handle to a remote object.
Error Handling
This class uses StatusOr<T> to report errors. When an operation fails to perform its work the returned StatusOr<T> contains the error details. If the ok() member function in the StatusOr<T> 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<T> documentation for more details.
namespace cbt = google::cloud::bigtable;
namespace btadmin = google::bigtable::admin::v2;
cbt::InstanceAdmin admin = ...;
google::cloud::StatusOr<btadmin::Instance> 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";
Contains all the Cloud Bigtable C++ client APIs.
Definition: admin_client.h:28

In addition, the main page contains examples using StatusOr<T> to handle errors.

Retry, Backoff, and Idempotency Policies
The library automatically retries requests that fail with transient errors, and uses truncated exponential backoff 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.

See also
https://cloud.google.com/bigtable/ for an overview of Cloud Bigtable.
https://cloud.google.com/bigtable/docs/overview for an overview of the Cloud Bigtable data model.
https://cloud.google.com/bigtable/docs/instances-clusters-nodes for an introduction of the main APIs into Cloud Bigtable.
https://cloud.google.com/bigtable/docs/reference/service-apis-overview for an overview of the underlying Cloud Bigtable API.
google::cloud::StatusOr for a description of the error reporting class used by this library.
LimitedTimeRetryPolicy and LimitedErrorCountRetryPolicy for alternative retry policies.
ExponentialBackoffPolicy to configure different parameters for the exponential backoff policy.
SafeIdempotentMutationPolicy and AlwaysRetryMutationPolicy for alternative idempotency policies.

Definition at line 132 of file instance_admin.h.

Constructor & Destructor Documentation

◆ InstanceAdmin() [1/3]

google::cloud::bigtable::InstanceAdmin::InstanceAdmin ( std::shared_ptr< bigtable_admin::BigtableInstanceAdminConnection connection,
std::string  project 
)
inlineexplicit

Definition at line 134 of file instance_admin.h.

◆ InstanceAdmin() [2/3]

google::cloud::bigtable::InstanceAdmin::InstanceAdmin ( std::shared_ptr< InstanceAdminClient client)
inlineexplicit
Parameters
clientthe interface to create grpc stubs, report errors, etc.

Definition at line 154 of file instance_admin.h.

◆ InstanceAdmin() [3/3]

template<typename... Policies>
google::cloud::bigtable::InstanceAdmin::InstanceAdmin ( std::shared_ptr< InstanceAdminClient client,
Policies &&...  policies 
)
inlineexplicit

Create a new InstanceAdmin using explicit policies to handle RPC errors.

Parameters
clientthe interface to create grpc stubs, report errors, etc.
policiesthe set of policy overrides for this object.
Template Parameters
Policiesthe 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 also
GenericPollingPolicy, ExponentialBackoffPolicy, LimitedErrorCountRetryPolicy, LimitedTimeRetryPolicy.

Definition at line 182 of file instance_admin.h.

Member Function Documentation

◆ AppProfileName()

std::string google::cloud::bigtable::InstanceAdmin::AppProfileName ( std::string const &  instance_id,
std::string const &  profile_id 
) const
inline

Definition at line 227 of file instance_admin.h.

◆ ClusterName()

std::string google::cloud::bigtable::InstanceAdmin::ClusterName ( std::string const &  instance_id,
std::string const &  cluster_id 
) const
inline

Return the fully qualified name of the given cluster_id in give instance_id.

Definition at line 221 of file instance_admin.h.

◆ CreateAppProfile()

StatusOr<google::bigtable::admin::v2::AppProfile> google::cloud::bigtable::InstanceAdmin::CreateAppProfile ( std::string const &  instance_id,
AppProfileConfig  config 
)

Create a new application profile.

Parameters
instance_idthe instance for the new application profile.
configthe configuration for the new application profile.
Returns
The proto describing the new application profile.
Idempotency
This operation is always treated as non-idempotent.
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.
Multi-cluster Routing Example
namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::StatusOr;
[](cbta::BigtableInstanceAdminClient instance_admin,
std::string const& project_id, std::string const& instance_id,
std::string const& profile_id) {
std::string instance_name = cbt::InstanceName(project_id, instance_id);
google::bigtable::admin::v2::AppProfile ap;
ap.mutable_multi_cluster_routing_use_any()->Clear();
StatusOr<google::bigtable::admin::v2::AppProfile> profile =
instance_admin.CreateAppProfile(instance_name, profile_id,
std::move(ap));
if (!profile) throw std::runtime_error(profile.status().message());
std::cout << "New profile created with name=" << profile->name() << "\n";
}
std::string const & project_id() const
The project id, i.e., project_name() without the projects/ prefix.
std::string InstanceName(std::shared_ptr< DataClient > const &client)
Return the fully qualified instance name for the client.
Definition: data_client.h:215
Single Cluster Routing Example
namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::StatusOr;
[](cbta::BigtableInstanceAdminClient instance_admin,
std::string const& project_id, std::string const& instance_id,
std::string const& profile_id, std::string const& cluster_id) {
std::string instance_name = cbt::InstanceName(project_id, instance_id);
google::bigtable::admin::v2::AppProfile ap;
ap.mutable_single_cluster_routing()->set_cluster_id(cluster_id);
StatusOr<google::bigtable::admin::v2::AppProfile> profile =
instance_admin.CreateAppProfile(instance_name, profile_id,
std::move(ap));
if (!profile) throw std::runtime_error(profile.status().message());
std::cout << "New profile created with name=" << profile->name() << "\n";
}

◆ CreateCluster()

future<StatusOr<google::bigtable::admin::v2::Cluster> > google::cloud::bigtable::InstanceAdmin::CreateCluster ( ClusterConfig  cluster_config,
std::string const &  instance_id,
std::string const &  cluster_id 
)

Create a new Cluster of Cloud Bigtable.

Parameters
cluster_configa description of the new cluster to be created.
instance_idthe id of the instance in the project
cluster_idthe id of the cluster in the project that needs to be created. It must be between 6 and 30 characters.
Idempotency
This operation is always treated as non-idempotent.
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.
Example
namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::future;
using ::google::cloud::Project;
using ::google::cloud::StatusOr;
[](cbta::BigtableInstanceAdminClient instance_admin,
std::string const& project_id, std::string const& instance_id,
std::string const& cluster_id, std::string const& zone) {
std::string project_name = Project(project_id).FullName();
std::string instance_name = cbt::InstanceName(project_id, instance_id);
google::bigtable::admin::v2::Cluster c;
c.set_location(project_name + "/locations/" + zone);
c.set_serve_nodes(3);
c.set_default_storage_type(google::bigtable::admin::v2::HDD);
future<StatusOr<google::bigtable::admin::v2::Cluster>> cluster_future =
instance_admin.CreateCluster(instance_name, cluster_id, std::move(c));
// Applications can wait asynchronously, in this example we just block.
auto cluster = cluster_future.get();
if (!cluster) throw std::runtime_error(cluster.status().message());
std::cout << "Successfully created cluster " << cluster->name() << "\n";
}
std::string const & project_name() const
The full name (projects/<project_id>) of the project.

◆ CreateInstance()

future<StatusOr<google::bigtable::admin::v2::Instance> > google::cloud::bigtable::InstanceAdmin::CreateInstance ( InstanceConfig  instance_config)

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.
Parameters
instance_configa 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.
Returns
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.
Idempotency
This operation is always treated as non-idempotent.
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.
Example
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::future;
using ::google::cloud::Project;
using ::google::cloud::StatusOr;
[](cbta::BigtableInstanceAdminClient instance_admin,
std::string const& project_id, std::string const& instance_id,
std::string const& zone) {
std::string project_name = Project(project_id).FullName();
std::string cluster_id = instance_id + "-c1";
in.set_type(google::bigtable::admin::v2::Instance::PRODUCTION);
in.set_display_name("Put description here");
google::bigtable::admin::v2::Cluster cluster;
cluster.set_location(project_name + "/locations/" + zone);
cluster.set_serve_nodes(3);
cluster.set_default_storage_type(google::bigtable::admin::v2::HDD);
std::map<std::string, google::bigtable::admin::v2::Cluster> cluster_map = {
{cluster_id, std::move(cluster)}};
future<StatusOr<google::bigtable::admin::v2::Instance>> instance_future =
instance_admin.CreateInstance(project_name, instance_id, std::move(in),
std::move(cluster_map));
// Show how to perform additional work while the long running operation
// completes. The application could use future.then() instead.
std::cout << "Waiting for instance creation to complete " << std::flush;
instance_future.wait_for(std::chrono::seconds(1));
std::cout << '.' << std::flush;
auto instance = instance_future.get();
if (!instance) throw std::runtime_error(instance.status().message());
std::cout << "DONE, details=" << instance->DebugString() << "\n";
}
::google::bigtable::admin::v2::Instance Instance

◆ DeleteAppProfile()

Status google::cloud::bigtable::InstanceAdmin::DeleteAppProfile ( std::string const &  instance_id,
std::string const &  profile_id,
bool  ignore_warnings = true 
)

Delete an existing application profile.

Parameters
instance_idthe instance to look the profile in.
profile_idthe id of the profile within that instance.
ignore_warningsif 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.
Idempotency
This operation is always treated as non-idempotent.
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.
Example
namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::Status;
[](cbta::BigtableInstanceAdminClient instance_admin,
std::string const& project_id, std::string const& instance_id,
std::string const& profile_id, bool ignore_warnings) {
std::string profile_name =
cbt::AppProfileName(project_id, instance_id, profile_id);
google::bigtable::admin::v2::DeleteAppProfileRequest req;
req.set_name(profile_name);
req.set_ignore_warnings(ignore_warnings);
Status status = instance_admin.DeleteAppProfile(std::move(req));
if (!status.ok()) throw std::runtime_error(status.message());
std::cout << "Application Profile deleted\n";
}
std::string AppProfileName(std::string const &project_id, std::string const &instance_id, std::string const &app_profile_id)

◆ DeleteCluster()

Status google::cloud::bigtable::InstanceAdmin::DeleteCluster ( std::string const &  instance_id,
std::string const &  cluster_id 
)

Deletes the specified cluster of an instance in the project.

Parameters
instance_idthe id of the instance in the project
cluster_idthe id of the cluster in the project that needs to be deleted
Idempotency
This operation is always treated as non-idempotent.
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.
Example
namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::Status;
[](cbta::BigtableInstanceAdminClient instance_admin,
std::string const& project_id, std::string const& instance_id,
std::string const& cluster_id) {
std::string cluster_name =
cbt::ClusterName(project_id, instance_id, cluster_id);
Status status = instance_admin.DeleteCluster(cluster_name);
if (!status.ok()) throw std::runtime_error(status.message());
}
std::string ClusterName(std::string const &project_id, std::string const &instance_id, std::string const &cluster_id)

◆ DeleteInstance()

Status google::cloud::bigtable::InstanceAdmin::DeleteInstance ( std::string const &  instance_id)

Deletes the instances in the project.

Parameters
instance_idthe id of the instance in the project that needs to be deleted
Idempotency
This operation is always treated as non-idempotent.
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.
Example
namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::Status;
[](cbta::BigtableInstanceAdminClient instance_admin,
std::string const& project_id, std::string const& instance_id) {
std::string instance_name = cbt::InstanceName(project_id, instance_id);
Status status = instance_admin.DeleteInstance(instance_name);
if (!status.ok()) throw std::runtime_error(status.message());
std::cout << "Successfully deleted the instance " << instance_id << "\n";
}

◆ GetAppProfile()

StatusOr<google::bigtable::admin::v2::AppProfile> google::cloud::bigtable::InstanceAdmin::GetAppProfile ( std::string const &  instance_id,
std::string const &  profile_id 
)

Fetch the detailed information about an existing application profile.

Parameters
instance_idthe instance to look the profile in.
profile_idthe id of the profile within that instance.
Returns
The proto describing the application profile.
Idempotency
This operation is read-only and therefore it is always idempotent.
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.
Example
namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::StatusOr;
[](cbta::BigtableInstanceAdminClient instance_admin,
std::string const& project_id, std::string const& instance_id,
std::string const& profile_id) {
std::string profile_name =
cbt::AppProfileName(project_id, instance_id, profile_id);
StatusOr<google::bigtable::admin::v2::AppProfile> profile =
instance_admin.GetAppProfile(profile_name);
if (!profile) throw std::runtime_error(profile.status().message());
std::cout << "Application Profile details=" << profile->DebugString()
<< "\n";
}

◆ GetCluster()

StatusOr<google::bigtable::admin::v2::Cluster> google::cloud::bigtable::InstanceAdmin::GetCluster ( std::string const &  instance_id,
std::string const &  cluster_id 
)

Gets the specified cluster of an instance in the project.

Parameters
instance_idthe id of the instance in the project
cluster_idthe id of the cluster in the project that needs to be deleted
Returns
a Cluster for given instance_id and cluster_id.
Idempotency
This operation is read-only and therefore it is always idempotent.
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.
Example
namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::StatusOr;
[](cbta::BigtableInstanceAdminClient instance_admin,
std::string const& project_id, std::string const& instance_id,
std::string const& cluster_id) {
std::string cluster_name =
cbt::ClusterName(project_id, instance_id, cluster_id);
StatusOr<google::bigtable::admin::v2::Cluster> cluster =
instance_admin.GetCluster(cluster_name);
if (!cluster) throw std::runtime_error(cluster.status().message());
std::cout << "GetCluster details : " << cluster->DebugString() << "\n";
}

◆ GetInstance()

StatusOr<google::bigtable::admin::v2::Instance> google::cloud::bigtable::InstanceAdmin::GetInstance ( std::string const &  instance_id)

Return the details of instance_id.

Idempotency
This operation is read-only and therefore it is always idempotent.
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.
Example
namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::StatusOr;
[](cbta::BigtableInstanceAdminClient instance_admin,
std::string const& project_id, std::string const& instance_id) {
std::string instance_name = cbt::InstanceName(project_id, instance_id);
StatusOr<google::bigtable::admin::v2::Instance> instance =
instance_admin.GetInstance(instance_name);
if (!instance) throw std::runtime_error(instance.status().message());
std::cout << "GetInstance details : " << instance->DebugString() << "\n";
}

◆ GetNativeIamPolicy()

StatusOr<google::iam::v1::Policy> google::cloud::bigtable::InstanceAdmin::GetNativeIamPolicy ( std::string const &  instance_id)

Gets the native policy for instance_id.

Parameters
instance_idthe instance to query.
Returns
google::iam::v1::Policy the full IAM policy for the instance.
Idempotency
This operation is read-only and therefore it is always idempotent.
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.
Example
namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::StatusOr;
[](cbta::BigtableInstanceAdminClient instance_admin,
std::string const& project_id, std::string const& instance_id) {
std::string instance_name = cbt::InstanceName(project_id, instance_id);
StatusOr<google::iam::v1::Policy> policy =
instance_admin.GetIamPolicy(instance_name);
if (!policy) throw std::runtime_error(policy.status().message());
std::cout << "The IAM Policy for " << instance_id << " is\n"
<< policy->DebugString() << "\n";
}

◆ InstanceName()

std::string google::cloud::bigtable::InstanceAdmin::InstanceName ( std::string const &  instance_id) const
inline

Return the fully qualified name of the given instance_id.

Definition at line 215 of file instance_admin.h.

◆ ListAppProfiles()

StatusOr<std::vector<google::bigtable::admin::v2::AppProfile> > google::cloud::bigtable::InstanceAdmin::ListAppProfiles ( std::string const &  instance_id)

List the application profiles in an instance.

Parameters
instance_idthe instance to list the profiles for.
Returns
a std::vector with the protos describing any profiles.
Idempotency
This operation is read-only and therefore it is always idempotent.
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.
Example
namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::StreamRange;
[](cbta::BigtableInstanceAdminClient instance_admin,
std::string const& project_id, std::string const& instance_id) {
std::string instance_name = cbt::InstanceName(project_id, instance_id);
StreamRange<google::bigtable::admin::v2::AppProfile> profiles =
instance_admin.ListAppProfiles(instance_name);
std::cout << "The " << instance_id << " instance has "
<< std::distance(profiles.begin(), profiles.end())
<< " application profiles\n";
for (auto const& profile : profiles) {
if (!profile) throw std::runtime_error(profile.status().message());
std::cout << profile->DebugString() << "\n";
}
}

◆ ListClusters() [1/2]

StatusOr<ClusterList> google::cloud::bigtable::InstanceAdmin::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.
Idempotency
This operation is read-only and therefore it is always idempotent.
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.
Example
namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::StatusOr;
[](cbta::BigtableInstanceAdminClient instance_admin,
std::string const& project_id, std::string const& instance_id) {
std::string instance_name = cbt::InstanceName(project_id, instance_id);
StatusOr<google::bigtable::admin::v2::ListClustersResponse> clusters =
instance_admin.ListClusters(instance_name);
if (!clusters) throw std::runtime_error(clusters.status().message());
std::cout << "Cluster Name List\n";
for (auto const& cluster : clusters->clusters()) {
std::cout << "Cluster Name:" << cluster.name() << "\n";
}
if (!clusters->failed_locations().empty()) {
std::cout << "The Cloud Bigtable service reports that the following "
"locations are temporarily unavailable and no information "
"about clusters in these locations can be obtained:\n";
for (auto const& failed_location : clusters->failed_locations()) {
std::cout << failed_location << "\n";
}
}
}

◆ ListClusters() [2/2]

StatusOr<ClusterList> google::cloud::bigtable::InstanceAdmin::ListClusters ( 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.
Idempotency
This operation is read-only and therefore it is always idempotent.
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.
Example
namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::StatusOr;
[](cbta::BigtableInstanceAdminClient instance_admin,
std::string const& project_id, std::string const& instance_id) {
std::string instance_name = cbt::InstanceName(project_id, instance_id);
StatusOr<google::bigtable::admin::v2::ListClustersResponse> clusters =
instance_admin.ListClusters(instance_name);
if (!clusters) throw std::runtime_error(clusters.status().message());
std::cout << "Cluster Name List\n";
for (auto const& cluster : clusters->clusters()) {
std::cout << "Cluster Name:" << cluster.name() << "\n";
}
if (!clusters->failed_locations().empty()) {
std::cout << "The Cloud Bigtable service reports that the following "
"locations are temporarily unavailable and no information "
"about clusters in these locations can be obtained:\n";
for (auto const& failed_location : clusters->failed_locations()) {
std::cout << failed_location << "\n";
}
}
}

◆ ListInstances()

StatusOr<InstanceList> google::cloud::bigtable::InstanceAdmin::ListInstances ( )

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.
Idempotency
This operation is read-only and therefore it is always idempotent.
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.
Example
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::Project;
using ::google::cloud::StatusOr;
[](cbta::BigtableInstanceAdminClient instance_admin,
std::string const& project_id) {
std::string project_name = Project(project_id).FullName();
StatusOr<google::bigtable::admin::v2::ListInstancesResponse> instances =
instance_admin.ListInstances(project_name);
if (!instances) throw std::runtime_error(instances.status().message());
for (auto const& instance : instances->instances()) {
std::cout << instance.name() << "\n";
}
if (!instances->failed_locations().empty()) {
std::cout << "The Cloud Bigtable service reports that the following "
"locations are temporarily unavailable and no information "
"about instances in these locations can be obtained:\n";
for (auto const& failed_location : instances->failed_locations()) {
std::cout << failed_location << "\n";
}
}
}

◆ project_id()

std::string const& google::cloud::bigtable::InstanceAdmin::project_id ( ) const
inline

The project id, i.e., project_name() without the projects/ prefix.

Definition at line 201 of file instance_admin.h.

◆ project_name()

std::string const& google::cloud::bigtable::InstanceAdmin::project_name ( ) const
inline

The full name (projects/<project_id>) of the project.

Definition at line 199 of file instance_admin.h.

◆ SetIamPolicy()

StatusOr<google::iam::v1::Policy> google::cloud::bigtable::InstanceAdmin::SetIamPolicy ( std::string const &  instance_id,
google::iam::v1::Policy const &  iam_policy 
)

Sets the IAM policy for an instance.

Parameters
instance_idwhich instance to set the IAM policy for.
iam_policygoogle::iam::v1::Policy object containing role and members.
Returns
google::iam::v1::Policy the current IAM policy for the instance.
Warning
ETags are currently not used by Cloud Bigtable.
Idempotency
This operation is always treated as non-idempotent.
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.
Example
namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::StatusOr;
[](cbta::BigtableInstanceAdminClient instance_admin,
std::string const& project_id, std::string const& instance_id,
std::string const& role, std::string const& member) {
std::string instance_name = cbt::InstanceName(project_id, instance_id);
StatusOr<google::iam::v1::Policy> current =
instance_admin.GetIamPolicy(instance_name);
if (!current) throw std::runtime_error(current.status().message());
// This example adds the member to all existing bindings for that role. If
// there are no such bindings, it adds a new one. This might not be what the
// user wants, e.g. in case of conditional bindings.
size_t num_added = 0;
for (auto& binding : *current->mutable_bindings()) {
if (binding.role() == role) {
binding.add_members(member);
++num_added;
}
}
if (num_added == 0) {
*current->add_bindings() = cbt::IamBinding(role, {member});
}
StatusOr<google::iam::v1::Policy> policy =
instance_admin.SetIamPolicy(instance_name, *current);
if (!policy) throw std::runtime_error(policy.status().message());
std::cout << "The IAM Policy for " << instance_id << " is\n"
<< policy->DebugString() << "\n";
}
google::iam::v1::Binding IamBinding(std::string role, InputIt begin, InputIt end)
Create a google::iam::v1::Binding.
Definition: iam_binding.h:160

◆ TestIamPermissions()

StatusOr<std::vector<std::string> > google::cloud::bigtable::InstanceAdmin::TestIamPermissions ( std::string const &  instance_id,
std::vector< std::string > const &  permissions 
)

Returns a permission set that the caller has on the specified instance.

Parameters
instance_idthe ID of the instance to query.
permissionsset of permissions to check for the resource.
Idempotency
This operation is read-only and therefore it is always idempotent.
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.
Example
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::StatusOr;
[](cbta::BigtableInstanceAdminClient instance_admin,
std::string const& resource_name,
std::vector<std::string> const& permissions) {
auto result = instance_admin.TestIamPermissions(resource_name, permissions);
if (!result) throw std::runtime_error(result.status().message());
std::cout << "The current user has the following permissions [";
std::cout << absl::StrJoin(result->permissions(), ", ");
std::cout << "]\n";
}
See also
https://cloud.google.com/bigtable/docs/access-control for a list of valid permissions on Google Cloud Bigtable.

◆ UpdateAppProfile()

future<StatusOr<google::bigtable::admin::v2::AppProfile> > google::cloud::bigtable::InstanceAdmin::UpdateAppProfile ( std::string const &  instance_id,
std::string const &  profile_id,
AppProfileUpdateConfig  config 
)

Updates an existing application profile.

Parameters
instance_idthe instance for the new application profile.
profile_idthe id (not the full name) of the profile to update.
configthe configuration for the new application profile.
Returns
The proto describing the new application profile.
Idempotency
This operation is always treated as non-idempotent.
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.
Change Description Example
namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::future;
using ::google::cloud::StatusOr;
[](cbta::BigtableInstanceAdminClient instance_admin,
std::string const& project_id, std::string const& instance_id,
std::string const& profile_id, std::string const& description) {
std::string profile_name =
cbt::AppProfileName(project_id, instance_id, profile_id);
google::bigtable::admin::v2::AppProfile profile;
profile.set_name(profile_name);
profile.set_description(description);
google::protobuf::FieldMask mask;
mask.add_paths("description");
future<StatusOr<google::bigtable::admin::v2::AppProfile>> profile_future =
instance_admin.UpdateAppProfile(std::move(profile), std::move(mask));
auto modified_profile = profile_future.get();
if (!modified_profile)
throw std::runtime_error(modified_profile.status().message());
std::cout << "Updated AppProfile: " << modified_profile->DebugString()
<< "\n";
}
Change Routing to Any Cluster Example
namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::future;
using ::google::cloud::StatusOr;
[](cbta::BigtableInstanceAdminClient instance_admin,
std::string const& project_id, std::string const& instance_id,
std::string const& profile_id) {
std::string profile_name =
cbt::AppProfileName(project_id, instance_id, profile_id);
google::bigtable::admin::v2::UpdateAppProfileRequest req;
req.mutable_app_profile()->set_name(profile_name);
req.mutable_app_profile()->mutable_multi_cluster_routing_use_any()->Clear();
req.mutable_update_mask()->add_paths("multi_cluster_routing_use_any");
req.set_ignore_warnings(true);
future<StatusOr<google::bigtable::admin::v2::AppProfile>> profile_future =
instance_admin.UpdateAppProfile(std::move(req));
auto modified_profile = profile_future.get();
if (!modified_profile)
throw std::runtime_error(modified_profile.status().message());
std::cout << "Updated AppProfile: " << modified_profile->DebugString()
<< "\n";
}
Change Routing to a Specific Cluster Example
namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::future;
using ::google::cloud::StatusOr;
[](cbta::BigtableInstanceAdminClient instance_admin,
std::string const& project_id, std::string const& instance_id,
std::string const& profile_id, std::string const& cluster_id) {
std::string profile_name =
cbt::AppProfileName(project_id, instance_id, profile_id);
google::bigtable::admin::v2::UpdateAppProfileRequest req;
req.mutable_app_profile()->set_name(profile_name);
req.mutable_app_profile()->mutable_single_cluster_routing()->set_cluster_id(
cluster_id);
req.mutable_update_mask()->add_paths("single_cluster_routing");
req.set_ignore_warnings(true);
future<StatusOr<google::bigtable::admin::v2::AppProfile>> profile_future =
instance_admin.UpdateAppProfile(std::move(req));
auto modified_profile = profile_future.get();
if (!modified_profile)
throw std::runtime_error(modified_profile.status().message());
std::cout << "Updated AppProfile: " << modified_profile->DebugString()
<< "\n";
}

◆ UpdateCluster()

future<StatusOr<google::bigtable::admin::v2::Cluster> > google::cloud::bigtable::InstanceAdmin::UpdateCluster ( ClusterConfig  cluster_config)

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.
Parameters
cluster_configcluster with updated values.
Returns
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.
Idempotency
This operation is always treated as non-idempotent.
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.
Example
namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::StatusOr;
[](cbta::BigtableInstanceAdminClient instance_admin,
std::string const& project_id, std::string const& instance_id,
std::string const& cluster_id) {
std::string cluster_name =
cbt::ClusterName(project_id, instance_id, cluster_id);
// GetCluster first and then modify it.
StatusOr<google::bigtable::admin::v2::Cluster> cluster =
instance_admin.GetCluster(cluster_name);
if (!cluster) throw std::runtime_error(cluster.status().message());
// The state cannot be sent on updates, so clear it first.
cluster->clear_state();
// Set the desired cluster configuration.
cluster->set_serve_nodes(4);
auto modified_cluster =
instance_admin.UpdateCluster(std::move(*cluster)).get();
if (!modified_cluster) {
throw std::runtime_error(modified_cluster.status().message());
}
std::cout << "cluster details : " << cluster->DebugString() << "\n";
}

◆ UpdateInstance()

future<StatusOr<google::bigtable::admin::v2::Instance> > google::cloud::bigtable::InstanceAdmin::UpdateInstance ( InstanceUpdateConfig  instance_update_config)

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.
Parameters
instance_update_configconfig with modified instance.
Returns
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.
Idempotency
This operation is always treated as non-idempotent.
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.
Example
namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::future;
using ::google::cloud::StatusOr;
[](cbta::BigtableInstanceAdminClient instance_admin,
std::string const& project_id, std::string const& instance_id) {
std::string instance_name = cbt::InstanceName(project_id, instance_id);
StatusOr<google::bigtable::admin::v2::Instance> instance =
instance_admin.GetInstance(instance_name);
if (!instance) throw std::runtime_error(instance.status().message());
// Modify the instance and prepare the mask with the modified field
instance->set_display_name("Modified Display Name");
google::protobuf::FieldMask mask;
mask.add_paths("display_name");
future<StatusOr<google::bigtable::admin::v2::Instance>> instance_future =
instance_admin.PartialUpdateInstance(std::move(*instance),
std::move(mask));
instance_future
.then([](future<StatusOr<google::bigtable::admin::v2::Instance>> f) {
auto updated_instance = f.get();
if (!updated_instance) {
throw std::runtime_error(updated_instance.status().message());
}
std::cout << "UpdateInstance details : "
<< updated_instance->DebugString() << "\n";
})
.get(); // block until done to simplify example
}

◆ WithNewTarget()

InstanceAdmin google::cloud::bigtable::InstanceAdmin::WithNewTarget ( std::string  project_id) const
inline

Returns an InstanceAdmin that reuses the connection and configuration of this InstanceAdmin, but with a different resource name.

Definition at line 207 of file instance_admin.h.