use of com.google.cloud.bigtable.admin.v2.models.Table in project java-bigtable by googleapis.
the class BigtableTableAdminClientIT method createTable.
@Test
public void createTable() {
assume().withMessage("Emulator doesn't return proper responses for CreateTable").that(testEnvRule.env()).isNotInstanceOf(EmulatorEnv.class);
CreateTableRequest createTableReq = CreateTableRequest.of(tableId).addFamily("cf1").addFamily("cf2", GCRULES.maxVersions(10)).addSplit(ByteString.copyFromUtf8("b")).addSplit(ByteString.copyFromUtf8("q"));
Table tableResponse = tableAdmin.createTable(createTableReq);
assertEquals(tableId, tableResponse.getId());
Map<String, ColumnFamily> columnFamilyById = Maps.newHashMap();
for (ColumnFamily columnFamily : tableResponse.getColumnFamilies()) {
columnFamilyById.put(columnFamily.getId(), columnFamily);
}
assertEquals(2, tableResponse.getColumnFamilies().size());
assertFalse(columnFamilyById.get("cf1").hasGCRule());
assertTrue(columnFamilyById.get("cf2").hasGCRule());
assertEquals(10, ((VersionRule) columnFamilyById.get("cf2").getGCRule()).getMaxVersions());
}
use of com.google.cloud.bigtable.admin.v2.models.Table in project java-bigtable by googleapis.
the class BigtableTableAdminClientIT method modifyFamilies.
@Test
public void modifyFamilies() {
tableAdmin.createTable(CreateTableRequest.of(tableId));
ModifyColumnFamiliesRequest modifyFamiliesReq = ModifyColumnFamiliesRequest.of(tableId).addFamily("mf1").addFamily("mf2", GCRULES.maxAge(Duration.ofSeconds(1000, 20000))).updateFamily("mf1", GCRULES.union().rule(GCRULES.maxAge(Duration.ofSeconds(100))).rule(GCRULES.maxVersions(1))).addFamily("mf3", GCRULES.intersection().rule(GCRULES.maxAge(Duration.ofSeconds(2000))).rule(GCRULES.maxVersions(10))).addFamily("mf4", GCRULES.intersection().rule(GCRULES.maxAge(Duration.ofSeconds(360)))).addFamily("mf5").addFamily("mf6").dropFamily("mf5").dropFamily("mf6").addFamily("mf7");
Table tableResponse = tableAdmin.modifyFamilies(modifyFamiliesReq);
Map<String, ColumnFamily> columnFamilyById = Maps.newHashMap();
for (ColumnFamily columnFamily : tableResponse.getColumnFamilies()) {
columnFamilyById.put(columnFamily.getId(), columnFamily);
}
assertEquals(5, columnFamilyById.size());
assertNotNull(columnFamilyById.get("mf1"));
assertNotNull(columnFamilyById.get("mf2"));
assertEquals(2, ((UnionRule) columnFamilyById.get("mf1").getGCRule()).getRulesList().size());
assertEquals(1000, ((DurationRule) columnFamilyById.get("mf2").getGCRule()).getMaxAge().getSeconds());
assertEquals(20000, ((DurationRule) columnFamilyById.get("mf2").getGCRule()).getMaxAge().getNano());
assertEquals(2, ((IntersectionRule) columnFamilyById.get("mf3").getGCRule()).getRulesList().size());
assertEquals(360, ((DurationRule) columnFamilyById.get("mf4").getGCRule()).getMaxAge().getSeconds());
assertNotNull(columnFamilyById.get("mf7"));
}
use of com.google.cloud.bigtable.admin.v2.models.Table in project java-docs-samples by GoogleCloudPlatform.
the class BulkWrite method bulkWrite.
static void bulkWrite(BigtableOptions options) throws IOException, GeneralSecurityException {
BigtableTableAdminSettings adminSettings = BigtableTableAdminSettings.newBuilder().setProjectId(options.getProject()).setInstanceId(options.getBigtableInstanceId()).build();
BigtableTableAdminClient adminClient = BigtableTableAdminClient.create(adminSettings);
int clusterNodeCount = getClusterNodeCount(options.getProject(), options.getBigtableInstanceId());
List<String> newTableIds = getNewTableIds(adminClient, options.getBigtableSize());
// If the specified size of Bigtable is already met, don't run the pipeline.
if (newTableIds.isEmpty()) {
return;
}
long numRows = (long) ((TB_PER_TABLE * ONE_TB) / (MB_PER_ROW * ONE_MB));
long rate = clusterNodeCount * MB_PER_SEC / newTableIds.size();
String generateLabel = String.format("Generate %d rows at %dMB per second for %d tables", numRows, rate, newTableIds.size());
String mutationLabel = String.format("Create mutations that write %d MB to each row", MB_PER_ROW);
System.out.println(generateLabel);
System.out.println(mutationLabel);
Pipeline p = Pipeline.create(options);
PCollection<Mutation> mutations = p.apply(generateLabel, GenerateSequence.from(0).to(numRows).withRate(rate, Duration.standardSeconds(1))).apply(mutationLabel, ParDo.of(new CreateMutationFn()));
for (String tableId : newTableIds) {
mutations.apply(String.format("Write data to table %s", tableId), CloudBigtableIO.writeToTable(new CloudBigtableTableConfiguration.Builder().withProjectId(options.getProject()).withInstanceId(options.getBigtableInstanceId()).withTableId(tableId).build()));
}
p.run();
}
use of com.google.cloud.bigtable.admin.v2.models.Table in project java-docs-samples by GoogleCloudPlatform.
the class BulkWrite method getNewTableIds.
// Increases or decreases the number of tables in the Bigtable instance based on the expected size
// and returns any newly created table ids.
private static List<String> getNewTableIds(BigtableTableAdminClient adminClient, double expectedSize) {
List<String> tableIds = adminClient.listTables();
List<String> newTableIds = new ArrayList<>();
double currentSize = tableIds.size() * TB_PER_TABLE;
if (currentSize >= expectedSize) {
int numTablesToDelete = (int) ((currentSize - expectedSize) / .5);
for (int i = 0; i < numTablesToDelete; i++) {
adminClient.deleteTable(tableIds.get(i));
}
System.out.printf("Deleted %d tables%n", numTablesToDelete);
} else {
int numTablesToCreate = (int) ((expectedSize - currentSize) / .5);
System.out.printf("Creating %d tables%n", numTablesToCreate);
for (int i = 0; i < numTablesToCreate; i++) {
String tableId = TABLE_PREFIX + UUID.randomUUID().toString().substring(0, 20);
CreateTableRequest createTableRequest = CreateTableRequest.of(tableId).addFamily(COLUMN_FAMILY);
adminClient.createTable(createTableRequest);
newTableIds.add(tableId);
System.out.println(tableId);
}
}
return newTableIds;
}
use of com.google.cloud.bigtable.admin.v2.models.Table in project java-bigtable-hbase by googleapis.
the class AbstractBigtableAdmin method modifyTable.
/**
* {@inheritDoc}
*/
@Override
public void modifyTable(TableName tableName, HTableDescriptor newDescriptor) throws IOException {
if (isTableAvailable(tableName)) {
try {
ModifyColumnFamiliesRequest request = buildModifications(newDescriptor, getTableDescriptor(tableName)).build();
FutureUtil.unwrap(adminClientWrapper.modifyFamiliesAsync(request));
} catch (Throwable throwable) {
throw new IOException(String.format("Failed to modify table '%s'", tableName.getNameAsString()), throwable);
}
} else {
throw new TableNotFoundException(tableName);
}
}
Aggregations