public class BigtableResourceManager
extends java.lang.Object
implements org.apache.beam.it.common.ResourceManager
The class supports one instance, and multiple tables per manager object. An instance is created when the first table is created if one has not been created already.
The instance id is formed using testId. The instance id will be "{testId}-{ISO8601 time, microsecond precision}", with additional formatting. Note: If testId is more than 30 characters, a new testId will be formed for naming: {first 21 chars of long testId} + “-” + {8 char hash of testId}.
The class is thread-safe.
Modifier and Type | Class and Description |
---|---|
static class |
BigtableResourceManager.Builder
Builder for
BigtableResourceManager . |
Modifier and Type | Method and Description |
---|---|
static BigtableResourceManager.Builder |
builder(java.lang.String testId,
java.lang.String projectId,
com.google.api.gax.core.CredentialsProvider credentialsProvider) |
void |
cleanupAll()
Deletes all created resources (instance and tables) and cleans up all Bigtable clients, making
the manager object unusable.
|
void |
createAppProfile(java.lang.String appProfileId,
boolean allowTransactionWrites,
java.util.List<java.lang.String> clusters)
Creates an application profile within the current instance
|
void |
createInstance(java.util.List<BigtableResourceManagerCluster> clusters)
Creates a Bigtable instance in which all clusters, nodes and tables will exist.
|
void |
createTable(java.lang.String tableId,
BigtableTableSpec bigtableTableSpec)
Creates a table within the current instance given a table ID and a collection of column family
names.
|
void |
createTable(java.lang.String tableId,
java.lang.Iterable<java.lang.String> columnFamilies)
Creates a table within the current instance given a table ID and a collection of column family
names.
|
void |
createTable(java.lang.String tableId,
java.lang.Iterable<java.lang.String> columnFamilies,
org.threeten.bp.Duration maxAge)
Creates a table within the current instance given a table ID and a collection of column family
names.
|
java.util.List<java.lang.String> |
getClusterNames()
Get all the cluster names of the current instance.
|
java.lang.String |
getInstanceId()
Return the instance ID this Resource Manager uses to create and manage tables in.
|
java.lang.String |
getProjectId()
Returns the project ID this Resource Manager is configured to operate on.
|
com.google.common.collect.ImmutableList<com.google.cloud.bigtable.data.v2.models.Row> |
readTable(java.lang.String tableId)
Reads all the rows in a table.
|
com.google.common.collect.ImmutableList<com.google.cloud.bigtable.data.v2.models.Row> |
readTable(java.lang.String tableId,
java.lang.Long limit)
Reads all the rows in a table.
|
void |
write(java.lang.Iterable<com.google.cloud.bigtable.data.v2.models.RowMutation> tableRows)
Writes a collection of table rows into one or more tables.
|
void |
write(com.google.cloud.bigtable.data.v2.models.RowMutation tableRow)
Writes a given row into a table.
|
public static BigtableResourceManager.Builder builder(java.lang.String testId, java.lang.String projectId, com.google.api.gax.core.CredentialsProvider credentialsProvider)
public java.lang.String getProjectId()
public java.lang.String getInstanceId()
public void createInstance(java.util.List<BigtableResourceManagerCluster> clusters) throws BigtableResourceManagerException
clusters
- List of BigtableResourceManagerCluster objects to associate with the given
Bigtable instance.BigtableResourceManagerException
- if there is an error creating the instance in
Bigtable.public void createTable(java.lang.String tableId, java.lang.Iterable<java.lang.String> columnFamilies) throws BigtableResourceManagerException
Bigtable has the capability to store multiple versions of data in a single cell, which are indexed using timestamp values. The timestamp can be set by Bigtable, with the default timestamp value being 1970-01-01, or can be set explicitly. The columns in the created table will be automatically garbage collected once they reach an age of 1-hour after the set timestamp.
Note: Implementations may do instance creation here, if one does not already exist.
tableId
- The id of the table.columnFamilies
- A collection of column family names for the table.BigtableResourceManagerException
- if there is an error creating the table in Bigtable.public void createTable(java.lang.String tableId, java.lang.Iterable<java.lang.String> columnFamilies, org.threeten.bp.Duration maxAge) throws BigtableResourceManagerException
Bigtable has the capability to store multiple versions of data in a single cell, which are
indexed using timestamp values. The timestamp can be set by Bigtable, with the default
timestamp value being 1970-01-01, or can be set explicitly. The columns in the created table
will be automatically garbage collected once they reach an age of maxAge
after the set
timestamp.
Note: Implementations may do instance creation here, if one does not already exist.
tableId
- The id of the table.columnFamilies
- A collection of column family names for the table.maxAge
- Sets the maximum age the columns can persist before being garbage collected.BigtableResourceManagerException
- if there is an error creating the table in Bigtable.public void createTable(java.lang.String tableId, BigtableTableSpec bigtableTableSpec) throws BigtableResourceManagerException
Bigtable has the capability to store multiple versions of data in a single cell, which are
indexed using timestamp values. The timestamp can be set by Bigtable, with the default
timestamp value being 1970-01-01, or can be set explicitly. The columns in the created table
will be automatically garbage collected once they reach an age of maxAge
after the set
timestamp.
Note: Implementations may do instance creation here, if one does not already exist.
tableId
- The id of the table.bigtableTableSpec
- Other table configurationsBigtableResourceManagerException
- if there is an error creating the table in Bigtable.public void createAppProfile(java.lang.String appProfileId, boolean allowTransactionWrites, java.util.List<java.lang.String> clusters) throws BigtableResourceManagerException
Note: Implementations may do instance creation here, if one does not already exist.
appProfileId
- The id of the app profile.allowTransactionWrites
- Allows transactional writes when single cluster routing is
enabledclusters
- Clusters where traffic is going to be routed. If more than one cluster is
specified, a multi-cluster routing is used. A single-cluster routing is used when a single
cluster is specified.BigtableResourceManagerException
- if there is an error creating the application profile
in Bigtable.public void write(com.google.cloud.bigtable.data.v2.models.RowMutation tableRow) throws BigtableResourceManagerException
createTable(String, Iterable)
to be called for the target table
beforehand.tableRow
- A mutation object representing the table row.BigtableResourceManagerException
- if method is called after resources have been cleaned
up, if the manager object has no instance, if the table does not exist or if there is an
IOException when attempting to retrieve the bigtable data client.public void write(java.lang.Iterable<com.google.cloud.bigtable.data.v2.models.RowMutation> tableRows) throws BigtableResourceManagerException
createTable(String, Iterable)
to be called for the target table
beforehand.tableRows
- A collection of mutation objects representing table rows.BigtableResourceManagerException
- if method is called after resources have been cleaned
up, if the manager object has no instance, if the table does not exist or if there is an
IOException when attempting to retrieve the bigtable data client.public com.google.common.collect.ImmutableList<com.google.cloud.bigtable.data.v2.models.Row> readTable(java.lang.String tableId) throws BigtableResourceManagerException
createTable(String, Iterable)
to be called for the target table
beforehand.tableId
- The id of table to read rows from.BigtableResourceManagerException
- if method is called after resources have been cleaned
up, if the manager object has no instance, if the table does not exist or if there is an
IOException when attempting to retrieve the bigtable data client.public com.google.common.collect.ImmutableList<com.google.cloud.bigtable.data.v2.models.Row> readTable(java.lang.String tableId, @Nullable java.lang.Long limit) throws BigtableResourceManagerException
createTable(String, Iterable)
to be called for the target table
beforehand.tableId
- The id of table to read rows from.limit
- Limits the number of rows that can be returnedBigtableResourceManagerException
- if method is called after resources have been cleaned
up, if the manager object has no instance, if the table does not exist or if there is an
IOException when attempting to retrieve the bigtable data client.public java.util.List<java.lang.String> getClusterNames()
public void cleanupAll() throws BigtableResourceManagerException
If this Resource Manager was configured to use a static instance, the instance will not be cleaned up, but any created tables will be deleted.
cleanupAll
in interface org.apache.beam.it.common.ResourceManager
BigtableResourceManagerException
- if there is an error deleting the instance or tables
in Bigtable.