Search in sources :

Example 6 with BigtableTableAdminSettings

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();
}
Also used : BigtableTableAdminSettings(com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings) BigtableTableAdminClient(com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient) Mutation(org.apache.hadoop.hbase.client.Mutation) Pipeline(org.apache.beam.sdk.Pipeline)

Example 7 with BigtableTableAdminSettings

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());
}
Also used : InstantiatingGrpcChannelProvider(com.google.api.gax.grpc.InstantiatingGrpcChannelProvider) BigtableTableAdminSettings(com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings) Test(org.junit.Test)

Example 8 with BigtableTableAdminSettings

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());
}
Also used : NoCredentialsProvider(com.google.api.gax.core.NoCredentialsProvider) BigtableTableAdminSettings(com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings) BigtableDataSettings(com.google.cloud.bigtable.data.v2.BigtableDataSettings) Test(org.junit.Test)

Example 9 with BigtableTableAdminSettings

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);
}
Also used : NoCredentialsProvider(com.google.api.gax.core.NoCredentialsProvider) BigtableTableAdminSettings(com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings) NoCredentialsProvider(com.google.api.gax.core.NoCredentialsProvider) CredentialsProvider(com.google.api.gax.core.CredentialsProvider) Test(org.junit.Test)

Example 10 with BigtableTableAdminSettings

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) {
    }
}
Also used : BigtableTableAdminSettings(com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings) Cluster(com.google.cloud.bigtable.admin.v2.models.Cluster) NotFoundException(com.google.api.gax.rpc.NotFoundException) BigtableTableAdminClient(com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)

Aggregations

BigtableTableAdminSettings (com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings)13 Test (org.junit.Test)6 BigtableTableAdminClient (com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)5 BigtableDataSettings (com.google.cloud.bigtable.data.v2.BigtableDataSettings)5 NoCredentialsProvider (com.google.api.gax.core.NoCredentialsProvider)2 BigtableInstanceAdminClient (com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient)2 BigtableInstanceAdminSettings (com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminSettings)2 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)2 ByteString (com.google.protobuf.ByteString)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PrintStream (java.io.PrintStream)2 BeforeClass (org.junit.BeforeClass)2 CreateBackupMessage (com.example.cloud.bigtable.scheduledbackups.resource.CreateBackupMessage)1 CredentialsProvider (com.google.api.gax.core.CredentialsProvider)1 InstantiatingGrpcChannelProvider (com.google.api.gax.grpc.InstantiatingGrpcChannelProvider)1 NotFoundException (com.google.api.gax.rpc.NotFoundException)1 Credentials (com.google.auth.Credentials)1 Backup (com.google.cloud.bigtable.admin.v2.models.Backup)1 Cluster (com.google.cloud.bigtable.admin.v2.models.Cluster)1 CreateBackupRequest (com.google.cloud.bigtable.admin.v2.models.CreateBackupRequest)1