com.google.cloud.bigtable.grpc
Class BigtableClusterUtilities
- java.lang.Object
-
- com.google.cloud.bigtable.grpc.BigtableClusterUtilities
-
- All Implemented Interfaces:
- AutoCloseable
public class BigtableClusterUtilities extends Object implements AutoCloseable
This is a utility that can be used to resize a cluster. This is useful to use 20 minutes before a large job to increase Cloud Bigtable capacity and 20 minutes after a large batch job to reduce the size.
-
-
Constructor Summary
Constructors Constructor and Description BigtableClusterUtilities(BigtableOptions options)
Constructor for the utility.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method and Description void
close()
Shuts down the connection to the admin API.static BigtableClusterUtilities
forAllInstances(String projectId)
Creates aBigtableClusterUtilities
for all instances in a projectId.static BigtableClusterUtilities
forInstance(String projectId, String instanceId)
Creates aBigtableClusterUtilities
for a projectId and an instanceId.com.google.bigtable.admin.v2.Cluster
getCluster(String clusterId, String zoneId)
Gets the current configuration of the cluster as encapsulated by aCluster
object.int
getClusterNodeCount(String clusterId, String zoneId)
Gets the current number of nodes allocated to the cluster.com.google.bigtable.admin.v2.ListClustersResponse
getClusters()
Gets aListClustersResponse
that contains all of the clusters for the projectId/instanceId configuration.int
getClusterSize()
Gets the serve node count of an instance with a single cluster.int
getClusterSize(String clusterId, String zoneId)
Deprecated.UsegetCluster(String, String)
orgetSingleCluster()
and then callCluster.getServeNodes()
.com.google.bigtable.admin.v2.Cluster
getSingleCluster()
static String
getZoneId(com.google.bigtable.admin.v2.Cluster cluster)
static com.google.bigtable.admin.v2.Cluster
lookupCluster(String projectId, String instanceId)
static String
lookupInstanceId(String projectId, String clusterId, String zoneId)
void
setClusterSize(int newSize)
Sets a cluster size to a specific size in an instance with a single clustervoid
setClusterSize(String clusterId, String zoneId, int newSize)
Sets a cluster size to a specific size.void
waitForOperation(String operationName, int maxSeconds)
Waits for an operation like cluster resizing to complete.
-
-
-
Constructor Detail
-
BigtableClusterUtilities
public BigtableClusterUtilities(BigtableOptions options) throws IOException, GeneralSecurityException
Constructor for the utility. PreferforInstance(String, String)
orforAllInstances(String)
rather than this method.- Parameters:
options
- that specify projectId, instanceId, credentials and retry options.- Throws:
GeneralSecurityException
IOException
-
-
Method Detail
-
forInstance
public static BigtableClusterUtilities forInstance(String projectId, String instanceId) throws IOException, GeneralSecurityException
Creates aBigtableClusterUtilities
for a projectId and an instanceId.- Parameters:
projectId
-instanceId
-- Returns:
- a
BigtableClusterUtilities
for a specific projectId/instanceId. - Throws:
GeneralSecurityException
- if ssl configuration failsIOException
- if some aspect of the connection fails.
-
forAllInstances
public static BigtableClusterUtilities forAllInstances(String projectId) throws IOException, GeneralSecurityException
Creates aBigtableClusterUtilities
for all instances in a projectId.- Parameters:
projectId
-- Returns:
- a
BigtableClusterUtilities
for a all instances in a projectId. - Throws:
GeneralSecurityException
- if ssl configuration failsIOException
- if some aspect of the connection fails.
-
lookupInstanceId
public static String lookupInstanceId(String projectId, String clusterId, String zoneId) throws IOException
- Returns:
- The instance id associated with the given project, zone and cluster. We expect instance and cluster to have one-to-one relationship.
- Throws:
IllegalStateException
- if the cluster is not foundIOException
-
lookupCluster
public static com.google.bigtable.admin.v2.Cluster lookupCluster(String projectId, String instanceId) throws IOException
- Returns:
- The cluster associated with the given project and instance. We expect instance and cluster to have one-to-one relationship.
- Throws:
IllegalStateException
- if the cluster is not found or if there are many clusters in this instance.IOException
-
getZoneId
public static String getZoneId(com.google.bigtable.admin.v2.Cluster cluster)
-
getClusterSize
@Deprecated public int getClusterSize(String clusterId, String zoneId)
Deprecated. UsegetCluster(String, String)
orgetSingleCluster()
and then callCluster.getServeNodes()
.Gets the serve node count of the cluster.- Parameters:
clusterId
-zoneId
-- Returns:
- the
Cluster.getServeNodes()
of the clusterId.
-
getClusterSize
public int getClusterSize()
Gets the serve node count of an instance with a single cluster.- Returns:
- the
Cluster.getServeNodes()
of the clusterId.
-
getClusters
public com.google.bigtable.admin.v2.ListClustersResponse getClusters()
Gets aListClustersResponse
that contains all of the clusters for the projectId/instanceId configuration.- Returns:
- all clusters in the instance if the instance ID is provided; otherwise, all clusters in project are returned.
-
setClusterSize
public void setClusterSize(String clusterId, String zoneId, int newSize) throws InterruptedException
Sets a cluster size to a specific size.- Parameters:
clusterId
-zoneId
-newSize
-- Throws:
InterruptedException
- if the cluster is in the middle of updating, and an interrupt was received
-
setClusterSize
public void setClusterSize(int newSize) throws InterruptedException
Sets a cluster size to a specific size in an instance with a single cluster- Throws:
InterruptedException
- if the cluster is in the middle of updating, and an interrupt was received
-
getSingleCluster
public com.google.bigtable.admin.v2.Cluster getSingleCluster()
- Returns:
- a Single Cluster for the project and instance.
- Throws:
IllegalStateException
- for any project / instance combination that does not return exactly 1 cluster.
-
waitForOperation
public void waitForOperation(String operationName, int maxSeconds) throws InterruptedException
Waits for an operation like cluster resizing to complete.- Parameters:
operationName
- The fully qualified name of the operationmaxSeconds
- The maximum amount of seconds to wait for the operation to complete.- Throws:
InterruptedException
- if a user interrupts the process, usually with a ^C.
-
getClusterNodeCount
public int getClusterNodeCount(String clusterId, String zoneId)
Gets the current number of nodes allocated to the cluster.- Parameters:
clusterId
-zoneId
-- Returns:
- the serveNode count of the cluster.
-
getCluster
public com.google.bigtable.admin.v2.Cluster getCluster(String clusterId, String zoneId)
Gets the current configuration of the cluster as encapsulated by aCluster
object.- Parameters:
clusterId
-zoneId
-- Returns:
- the
Cluster
if it was set. If the cluster is not found, throw aNullPointerException
.
-
close
public void close()
Shuts down the connection to the admin API.- Specified by:
close
in interfaceAutoCloseable
-
-