use of com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings 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.BigtableTableAdminSettings in project java-bigtable-hbase by googleapis.
the class TestBigtableHBaseVeneerSettings method testAdminSettingsChannelPool.
@Test
public void testAdminSettingsChannelPool() throws IOException {
// should be ignored
configuration.setInt(BIGTABLE_DATA_CHANNEL_COUNT_KEY, 3);
BigtableHBaseVeneerSettings settings = (BigtableHBaseVeneerSettings) BigtableHBaseSettings.create(configuration);
BigtableTableAdminSettings adminSettings = settings.getTableAdminSettings();
InstantiatingGrpcChannelProvider transportChannelProvider = (InstantiatingGrpcChannelProvider) adminSettings.getStubSettings().getTransportChannelProvider();
assertEquals(1, transportChannelProvider.toBuilder().getPoolSize());
}
use of com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings in project java-bigtable-hbase by googleapis.
the class TestBigtableHBaseVeneerSettings method testWithNullCredentials.
@Test
public void testWithNullCredentials() throws IOException {
configuration.set(ADDITIONAL_RETRY_CODES, "UNAVAILABLE,ABORTED");
configuration.setBoolean(BIGTABLE_USE_SERVICE_ACCOUNTS_KEY, false);
configuration.setBoolean(BIGTABLE_NULL_CREDENTIAL_ENABLE_KEY, true);
BigtableDataSettings dataSettings = ((BigtableHBaseVeneerSettings) BigtableHBaseVeneerSettings.create(configuration)).getDataSettings();
assertTrue(dataSettings.getStubSettings().getCredentialsProvider() instanceof NoCredentialsProvider);
assertNull(dataSettings.getStubSettings().getCredentialsProvider().getCredentials());
BigtableTableAdminSettings adminSettings = ((BigtableHBaseVeneerSettings) BigtableHBaseVeneerSettings.create(configuration)).getTableAdminSettings();
assertTrue(adminSettings.getStubSettings().getCredentialsProvider() instanceof NoCredentialsProvider);
assertNull(adminSettings.getStubSettings().getCredentialsProvider().getCredentials());
}
use of com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings in project java-bigtable-hbase by googleapis.
the class TestBigtableHBaseVeneerSettings method testAdminSettingsWithEmulator.
@Test
public void testAdminSettingsWithEmulator() throws IOException {
// A real port isn't required for this test; only verifying the configs can be stored and
// retrieved.
final int availablePort = 987654321;
String emulatorHost = "localhost:" + availablePort;
configuration.set(BIGTABLE_EMULATOR_HOST_KEY, emulatorHost);
BigtableTableAdminSettings adminSettings = ((BigtableHBaseVeneerSettings) BigtableHBaseVeneerSettings.create(configuration)).getTableAdminSettings();
assertEquals(emulatorHost, adminSettings.getStubSettings().getEndpoint());
CredentialsProvider credProvider = adminSettings.getStubSettings().getCredentialsProvider();
assertTrue(credProvider instanceof NoCredentialsProvider);
}
use of com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings in project java-bigtable by googleapis.
the class TestEnvRule method deleteInstance.
/**
* Delete an instance with all of its resources.
*/
private void deleteInstance(String instanceId) throws IOException, ExecutionException, InterruptedException {
BigtableTableAdminSettings settings = env().getTableAdminSettings().toBuilder().setInstanceId(instanceId).build();
// Delete all child resources (backups & clusters) that wont be automatically deleted
try (BigtableTableAdminClient tableAdmin = BigtableTableAdminClient.create(settings)) {
List<Cluster> clusters = env().getInstanceAdminClient().listClusters(instanceId);
boolean isFirstCluster = true;
for (Cluster cluster : clusters) {
deleteBackups(tableAdmin, cluster.getId());
// without clusters)
if (!isFirstCluster) {
try {
env().getInstanceAdminClient().deleteCluster(instanceId, cluster.getId());
} catch (NotFoundException ignored) {
}
}
isFirstCluster = false;
}
}
// Delete everything else
try {
env().getInstanceAdminClient().deleteInstance(instanceId);
} catch (NotFoundException ignored) {
}
}
Aggregations