Class BigtableInstanceAdminClient

public final class BigtableInstanceAdminClient implements AutoCloseable

Client for creating, configuring and deleting Cloud Bigtable instances, app profiles, and clusters.

See the individual methods for example code.


 // One instance per application.
 BigtableInstanceAdminClient client =  BigtableInstanceAdminClient.create("my-project");
 CreateInstanceRequest request = CreateInstanceRequest.of("my-instance")
   .addCluster("my-cluster", "us-east1-c", 3, StorageType.SSD);

 Instance instance = client.createInstance(request);

 // Cleanup during application shutdown.
 client.close();
 

Creating a new client is a very expensive operation and should only be done once and shared in an application. However, close() needs to be called on the client object to clean up resources such as threads during application shutdown.

This class can be customized by passing in a custom instance of BigtableInstanceAdminSettings to create(). For example:

To customize credentials:


 BigtableInstanceAdminSettings settings = BigtableInstanceAdminSettings.newBuilder()
   .setProjectId("my-project")
   .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
   .build();

 BigtableInstanceAdminClient client = BigtableInstanceAdminClient.create(settings);
 

To customize the endpoint:


 BigtableInstanceAdminSettings.Builder settingsBuilder = BigtableInstanceAdminSettings.newBuilder()
   .setProjectId("my-project");

 settingsBuilder.stubSettings()
   .setEndpoint(myEndpoint);

 BigtableInstanceAdminClient client = BigtableInstanceAdminClient.create(settingsBuilder.build());
 

Inheritance

java.lang.Object > BigtableInstanceAdminClient

Implements

AutoCloseable

Methods

close()

public void close()

Closes the client and frees all resources associated with it (like thread pools).

create(BigtableInstanceAdminSettings settings)

public static BigtableInstanceAdminClient create(BigtableInstanceAdminSettings settings)

Constructs an instance of BigtableInstanceAdminClient with the given settings.

Parameter
NameDescription
settingsBigtableInstanceAdminSettings
Returns
TypeDescription
BigtableInstanceAdminClient
Exceptions
TypeDescription
IOException

create(String projectId)

public static BigtableInstanceAdminClient create(String projectId)

Constructs an instance of BigtableInstanceAdminClient with the given project ID.

Parameter
NameDescription
projectIdString
Returns
TypeDescription
BigtableInstanceAdminClient
Exceptions
TypeDescription
IOException

create(String projectId, BigtableInstanceAdminStub stub)

public static BigtableInstanceAdminClient create(String projectId, BigtableInstanceAdminStub stub)

Constructs an instance of BigtableInstanceAdminClient with the given project ID and stub.

Parameters
NameDescription
projectIdString
stubcom.google.cloud.bigtable.admin.v2.stub.BigtableInstanceAdminStub
Returns
TypeDescription
BigtableInstanceAdminClient

createAppProfile(CreateAppProfileRequest request)

public AppProfile createAppProfile(CreateAppProfileRequest request)

Creates a new app profile.

Sample code:


 AppProfile appProfile = client.createAppProfile(
   CreateAppProfileRequest.of("my-instance", "my-new-app-profile")
     .setRoutingPolicy(SingleClusterRoutingPolicy.of("my-cluster"))
 );
 
Parameter
NameDescription
requestCreateAppProfileRequest
Returns
TypeDescription
AppProfile

createAppProfileAsync(CreateAppProfileRequest request)

public ApiFuture<AppProfile> createAppProfileAsync(CreateAppProfileRequest request)

Asynchronously creates a new app profile.

Sample code:


 ApiFuture
Parameter
NameDescription
requestCreateAppProfileRequest
Returns
TypeDescription
ApiFuture<AppProfile>

createCluster(CreateClusterRequest request)

public Cluster createCluster(CreateClusterRequest request)

Creates a new cluster in the specified instance.

Sample code:


 Cluster cluster = client.createCluster(
   CreateClusterRequest.of("my-instance", "my-new-cluster")
     .setZone("us-east1-c")
     .setServeNodes(3)
     .setStorageType(StorageType.SSD)
 );
 
Parameter
NameDescription
requestCreateClusterRequest
Returns
TypeDescription
Cluster

createClusterAsync(CreateClusterRequest request)

public ApiFuture<Cluster> createClusterAsync(CreateClusterRequest request)

Asynchronously creates a new cluster in the specified instance.

Sample code:


 ApiFuture
Parameter
NameDescription
requestCreateClusterRequest
Returns
TypeDescription
ApiFuture<Cluster>

createInstance(CreateInstanceRequest request)

public Instance createInstance(CreateInstanceRequest request)

Creates a new instance and returns its representation.

Sample code:


 Instance instance = client.createInstance(
   CreateInstanceRequest.of("my-instance")
     .addCluster("my-cluster", "us-east1-c", 3, StorageType.SSD)
 );
 
Parameter
NameDescription
requestCreateInstanceRequest
Returns
TypeDescription
Instance

createInstanceAsync(CreateInstanceRequest request)

public ApiFuture<Instance> createInstanceAsync(CreateInstanceRequest request)

Asynchronously creates a new instance and returns its representation wrapped in a future.

Sample code:


 ApiFuture
Parameter
NameDescription
requestCreateInstanceRequest
Returns
TypeDescription
ApiFuture<Instance>

deleteAppProfile(String instanceId, String appProfileId)

public void deleteAppProfile(String instanceId, String appProfileId)

Deletes the specified app profile.

Sample code:


 client.deleteAppProfile("my-instance", "my-app-profile");
 
Parameters
NameDescription
instanceIdString
appProfileIdString

deleteAppProfile(String instanceId, String appProfileId, boolean forceDelete)

public void deleteAppProfile(String instanceId, String appProfileId, boolean forceDelete)

Deletes the specified app profile with an option to force deletion.

Sample code:


 client.deleteAppProfile("my-instance", "my-app-profile", true);
 
Parameters
NameDescription
instanceIdString
appProfileIdString
forceDeleteboolean

deleteAppProfileAsync(String instanceId, String appProfileId)

public ApiFuture<Void> deleteAppProfileAsync(String instanceId, String appProfileId)

Asynchronously deletes the specified app profile.

Sample code:


 ApiFuture
Parameters
NameDescription
instanceIdString
appProfileIdString
Returns
TypeDescription
ApiFuture<Void>

deleteAppProfileAsync(String instanceId, String appProfileId, boolean forceDelete)

public ApiFuture<Void> deleteAppProfileAsync(String instanceId, String appProfileId, boolean forceDelete)

Asynchronously deletes the specified app profile with an option to force deletion.

Sample code:


 ApiFuture
Parameters
NameDescription
instanceIdString
appProfileIdString
forceDeleteboolean
Returns
TypeDescription
ApiFuture<Void>

deleteCluster(String instanceId, String clusterId)

public void deleteCluster(String instanceId, String clusterId)

Deletes the specified cluster. Please note that an instance must have at least 1 cluster. To remove the last cluster, please use BigtableInstanceAdminClient#deleteInstance(String).

Sample code:


 client.deleteCluster("my-instance", "my-cluster");
 
Parameters
NameDescription
instanceIdString
clusterIdString

deleteClusterAsync(String instanceId, String clusterId)

public ApiFuture<Void> deleteClusterAsync(String instanceId, String clusterId)

Asynchronously deletes the specified cluster. Please note that an instance must have at least 1 cluster. To remove the last cluster, please use BigtableInstanceAdminClient#deleteInstanceAsync(String).

Sample code:


 ApiFuture
Parameters
NameDescription
instanceIdString
clusterIdString
Returns
TypeDescription
ApiFuture<Void>

deleteInstance(String instanceId)

public void deleteInstance(String instanceId)

Deletes the specified instance.

Sample code:


 client.deleteInstance("my-instance");
 
Parameter
NameDescription
instanceIdString

deleteInstanceAsync(String instanceId)

public ApiFuture<Void> deleteInstanceAsync(String instanceId)

Asynchronously deletes the specified instance.

Sample code:


 ApiFuture
Parameter
NameDescription
instanceIdString
Returns
TypeDescription
ApiFuture<Void>

disableClusterAutoscaling(String instanceId, String clusterId, int staticSize)

public Cluster disableClusterAutoscaling(String instanceId, String clusterId, int staticSize)

Disables autoscaling and enables manual scaling by setting a static node count for the cluster. Please note that only clusters that belong to a production instance can be resized.

Sample code:


 Cluster cluster = client.disableClusterAutoscaling("my-instance", "my-cluster", 3);
 
Parameters
NameDescription
instanceIdString
clusterIdString
staticSizeint
Returns
TypeDescription
Cluster

disableClusterAutoscalingAsync(String instanceId, String clusterId, int staticSize)

public ApiFuture<Cluster> disableClusterAutoscalingAsync(String instanceId, String clusterId, int staticSize)

Asynchronously disables autoscaling and enables manual scaling by setting a static node count for the cluster. Please note that only clusters that belong to a production instance can be resized.

Sample code:


 ApiFuture
Parameters
NameDescription
instanceIdString
clusterIdString
staticSizeint
Returns
TypeDescription
ApiFuture<Cluster>

exists(String instanceId)

public boolean exists(String instanceId)

Checks if the instance specified by the instance ID exists.

Sample code:


 if(client.exists("my-instance")) {
   System.out.println("Instance exists");
 }
 
Parameter
NameDescription
instanceIdString
Returns
TypeDescription
boolean

existsAsync(String instanceId)

public ApiFuture<Boolean> existsAsync(String instanceId)

Asynchronously checks if the instance specified by the instance ID exists.

Sample code:


 ApiFuture
Parameter
NameDescription
instanceIdString
Returns
TypeDescription
ApiFuture<Boolean>

getAppProfile(String instanceId, String appProfileId)

public AppProfile getAppProfile(String instanceId, String appProfileId)

Gets the app profile by ID.

Sample code:


 AppProfile appProfile = client.getAppProfile("my-instance", "my-app-profile");
 
Parameters
NameDescription
instanceIdString
appProfileIdString
Returns
TypeDescription
AppProfile

getAppProfileAsync(String instanceId, String appProfileId)

public ApiFuture<AppProfile> getAppProfileAsync(String instanceId, String appProfileId)

Asynchronously gets the app profile by ID.

Sample code:


 ApiFuture
Parameters
NameDescription
instanceIdString
appProfileIdString
Returns
TypeDescription
ApiFuture<AppProfile>

getCluster(String instanceId, String clusterId)

public Cluster getCluster(String instanceId, String clusterId)

Gets the cluster representation by ID.

Sample code:


 Cluster cluster = client.getCluster("my-instance", "my-cluster");
 
Parameters
NameDescription
instanceIdString
clusterIdString
Returns
TypeDescription
Cluster

getClusterAsync(String instanceId, String clusterId)

public ApiFuture<Cluster> getClusterAsync(String instanceId, String clusterId)

Asynchronously gets the cluster representation by ID.

Sample code:


 ApiFuture
Parameters
NameDescription
instanceIdString
clusterIdString
Returns
TypeDescription
ApiFuture<Cluster>

getIamPolicy(String instanceId)

public Policy getIamPolicy(String instanceId)

Gets the IAM access control policy for the specified instance.

Sample code:


 Policy policy = client.getIamPolicy("my-instance");
 for(Map.Entry
Parameter
NameDescription
instanceIdString
Returns
TypeDescription
com.google.cloud.Policy

getIamPolicyAsync(String instanceId)

public ApiFuture<Policy> getIamPolicyAsync(String instanceId)

Asynchronously gets the IAM access control policy for the specified instance.

Sample code:


 ApiFuture
Parameter
NameDescription
instanceIdString
Returns
TypeDescription
ApiFuture<com.google.cloud.Policy>

getInstance(String id)

public Instance getInstance(String id)

Get the instance representation by ID.

Sample code:


 Instance instance = client.getInstance("my-instance");
 
Parameter
NameDescription
idString
Returns
TypeDescription
Instance

getInstanceAsync(String instanceId)

public ApiFuture<Instance> getInstanceAsync(String instanceId)

Asynchronously gets the instance representation by ID wrapped in a future.

Sample code:


 ApiFuture
Parameter
NameDescription
instanceIdString
Returns
TypeDescription
ApiFuture<Instance>

getProjectId()

public String getProjectId()

Gets the project ID this client is associated with.

Returns
TypeDescription
String

listAppProfiles(String instanceId)

public List<AppProfile> listAppProfiles(String instanceId)

Lists all app profiles of the specified instance.

Sample code:


 List
Parameter
NameDescription
instanceIdString
Returns
TypeDescription
List<AppProfile>

listAppProfilesAsync(String instanceId)

public ApiFuture<List<AppProfile>> listAppProfilesAsync(String instanceId)

Asynchronously lists all app profiles of the specified instance.

Sample code:


 ApiFuture<>
Parameter
NameDescription
instanceIdString
Returns
TypeDescription
ApiFuture<List<AppProfile>>

listClusters(String instanceId)

public List<Cluster> listClusters(String instanceId)

Lists all clusters in the specified instance.

This method will throw a PartialListClustersException when any zone is unavailable. If a partial list is OK, the exception can be caught and inspected.

Sample code:


 try {
   List
Parameter
NameDescription
instanceIdString
Returns
TypeDescription
List<Cluster>

listClustersAsync(String instanceId)

public ApiFuture<List<Cluster>> listClustersAsync(String instanceId)

Asynchronously lists all clusters in the specified instance.

This method will throw a PartialListClustersException when any zone is unavailable. If a partial list is OK, the exception can be caught and inspected.

Sample code:


 ApiFuture
Parameter
NameDescription
instanceIdString
Returns
TypeDescription
ApiFuture<List<Cluster>>

listInstances()

public List<Instance> listInstances()

Lists all of the instances in the current project.

This method will throw a PartialListInstancesException when any zone is unavailable. If a partial list is OK, the exception can be caught and inspected.

Sample code:


 try {
   List
Returns
TypeDescription
List<Instance>

listInstancesAsync()

public ApiFuture<List<Instance>> listInstancesAsync()

Asynchronously lists all of the instances in the current project.

This method will throw a PartialListInstancesException when any zone is unavailable. If a partial list is OK, the exception can be caught and inspected.

Sample code:


 ApiFuture
Returns
TypeDescription
ApiFuture<List<Instance>>

resizeCluster(String instanceId, String clusterId, int numServeNodes)

public Cluster resizeCluster(String instanceId, String clusterId, int numServeNodes)

Modifies the cluster's node count for manual scaling. If autoscaling is already enabled, manual scaling will be silently ignored. If you wish to disable autoscaling and enable manual scaling, please use BigtableInstanceAdminClient#disableClusterAutoscaling(String, String, int) instead. Please note that only clusters that belong to a production instance can be resized.

Sample code:


 Cluster cluster = client.resizeCluster("my-instance", "my-cluster", 30);
 
Parameters
NameDescription
instanceIdString
clusterIdString
numServeNodesint
Returns
TypeDescription
Cluster

resizeClusterAsync(String instanceId, String clusterId, int numServeNodes)

public ApiFuture<Cluster> resizeClusterAsync(String instanceId, String clusterId, int numServeNodes)

Asynchronously modifies the cluster's node count for manual scaling. If autoscaling is already enabled, manual scaling will be silently ignored. If you wish to disable autoscaling and enable manual scaling, please use BigtableInstanceAdminClient#disableClusterAutoscaling(String, String, int) instead. Please note that only clusters that belong to a production instance can be resized.


 ApiFuture
Parameters
NameDescription
instanceIdString
clusterIdString
numServeNodesint
Returns
TypeDescription
ApiFuture<Cluster>

setIamPolicy(String instanceId, Policy policy)

public Policy setIamPolicy(String instanceId, Policy policy)

Replaces the IAM policy associated with the specified instance.

Sample code:


 Policy newPolicy = client.setIamPolicy("my-instance",
   Policy.newBuilder()
     .addIdentity(Role.of("bigtable.user"), Identity.user("someone@example.com"))
     .addIdentity(Role.of("bigtable.admin"), Identity.group("admins@example.com"))
     .build());
 
Parameters
NameDescription
instanceIdString
policycom.google.cloud.Policy
Returns
TypeDescription
com.google.cloud.Policy

setIamPolicyAsync(String instanceId, Policy policy)

public ApiFuture<Policy> setIamPolicyAsync(String instanceId, Policy policy)

Asynchronously replaces the IAM policy associated with the specified instance.

Sample code:


 ApiFuture
Parameters
NameDescription
instanceIdString
policycom.google.cloud.Policy
Returns
TypeDescription
ApiFuture<com.google.cloud.Policy>

testIamPermission(String instanceId, String[] permissions)

public List<String> testIamPermission(String instanceId, String[] permissions)

Tests whether the caller has the given permissions for the specified instance. Returns a subset of the specified permissions that the caller has.

Sample code:


 List

System.out.println("Has read access: " + grantedPermissions.contains("bigtable.tables.readRows")); System.out.println("Has write access: " + grantedPermissions.contains("bigtable.tables.mutateRows"));

Parameters
NameDescription
instanceIdString
permissionsString[]
Returns
TypeDescription
List<String>

testIamPermissionAsync(String instanceId, String[] permissions)

public ApiFuture<List<String>> testIamPermissionAsync(String instanceId, String[] permissions)

Asynchronously tests whether the caller has the given permissions for the specified instance. Returns a subset of the specified permissions that the caller has.

Sample code:


 ApiFuture<>
Parameters
NameDescription
instanceIdString
permissionsString[]
Returns
TypeDescription
ApiFuture<List<String>>

updateAppProfile(UpdateAppProfileRequest request)

public AppProfile updateAppProfile(UpdateAppProfileRequest request)

Updates an existing app profile.

Sample code:


 AppProfile existingAppProfile = client.getAppProfile("my-instance", "my-app-profile");

 AppProfile updatedAppProfile = client.updateAppProfile(
   UpdateAppProfileRequest.of(existingAppProfile)
     .setRoutingPolicy(SingleClusterRoutingPolicy.of("my-cluster"))
 );
 
Parameter
NameDescription
requestUpdateAppProfileRequest
Returns
TypeDescription
AppProfile

updateAppProfileAsync(UpdateAppProfileRequest request)

public ApiFuture<AppProfile> updateAppProfileAsync(UpdateAppProfileRequest request)

Asynchronously updates an existing app profile.

Sample code:


 ApiFuture
Parameter
NameDescription
requestUpdateAppProfileRequest
Returns
TypeDescription
ApiFuture<AppProfile>

updateClusterAutoscalingConfig(ClusterAutoscalingConfig clusterAutoscalingConfig)

public Cluster updateClusterAutoscalingConfig(ClusterAutoscalingConfig clusterAutoscalingConfig)

Modifies the cluster's autoscaling config. This will enable autoscaling and disable manual scaling if the cluster is manually scaled. Please note that only clusters that belong to a production instance can enable autoscaling.

Sample code:


 ClusterAutoscalingConfig clusterAutoscalingConfig =
      ClusterAutoscalingConfig.of("my-instance", "my-cluster")
          .setMinNodes(1)
          .setMaxNodes(4)
          .setCpuUtilizationTargetPercent(40);
 Cluster cluster = client.updateClusterAutoscalingConfig(clusterAutoscalingConfig);
 
Parameter
NameDescription
clusterAutoscalingConfigClusterAutoscalingConfig
Returns
TypeDescription
Cluster

updateClusterAutoscalingConfigAsync(ClusterAutoscalingConfig clusterAutoscalingConfig)

public ApiFuture<Cluster> updateClusterAutoscalingConfigAsync(ClusterAutoscalingConfig clusterAutoscalingConfig)

Asynchronously modifies the cluster's autoscaling config. This will enable autoscaling and disable manual scaling if the cluster is manually scaled. Please note that only clusters that belong to a production instance can enable autoscaling.

Sample code:


 ClusterAutoscalingConfig clusterAutoscalingConfig =
      ClusterAutoscalingConfig.of(targetInstanceId, targetClusterId)
          .setMinNodes(1)
          .setMaxNodes(4)
          .setCpuUtilizationTargetPercent(40);

  ApiFuture
Parameter
NameDescription
clusterAutoscalingConfigClusterAutoscalingConfig
Returns
TypeDescription
ApiFuture<Cluster>

updateInstance(UpdateInstanceRequest request)

public Instance updateInstance(UpdateInstanceRequest request)

Updates a new instance and returns its representation.

Sample code:


 Instance instance = client.updateInstance(
   UpdateInstanceRequest.of("my-instance")
     .setProductionType()
 );
 
Parameter
NameDescription
requestUpdateInstanceRequest
Returns
TypeDescription
Instance

updateInstanceAsync(UpdateInstanceRequest request)

public ApiFuture<Instance> updateInstanceAsync(UpdateInstanceRequest request)

Asynchronously updates a new instance and returns its representation wrapped in a future.

Sample code:


 ApiFuture
Parameter
NameDescription
requestUpdateInstanceRequest
Returns
TypeDescription
ApiFuture<Instance>