/** * WARNING: Should be used only to specify additional parameters for connection to the Cloud * Bigtable, instanceId and projectId should be provided over {@link #withInstanceId} and {@link * #withProjectId} respectively. * * <p>Returns a new {@link BigtableIO.Read} that will read from the Cloud Bigtable instance * indicated by {@link #withProjectId}, and using any other specified customizations. * * <p>Does not modify this object. * * @deprecated will be replaced by bigtable options configurator. */ @Deprecated public Read withBigtableOptions(BigtableOptions options) { checkArgument(options != null, "options can not be null"); return withBigtableOptions(options.toBuilder()); }
/** * WARNING: Should be used only to specify additional parameters for connection to the Cloud * Bigtable, instanceId and projectId should be provided over {@link #withInstanceId} and {@link * #withProjectId} respectively. * * <p>Returns a new {@link BigtableIO.Write} that will write to the Cloud Bigtable instance * indicated by the given options, and using any other specified customizations. * * <p>Does not modify this object. * * @deprecated will be replaced by bigtable options configurator. */ @Deprecated public Write withBigtableOptions(BigtableOptions options) { checkArgument(options != null, "options can not be null"); return withBigtableOptions(options.toBuilder()); }
/** * WARNING: Should be used only to specify additional parameters for connection to the Cloud * Bigtable, instanceId and projectId should be provided over {@link #withInstanceId} and {@link * #withProjectId} respectively. * * <p>Returns a new {@link BigtableIO.Write} that will write to the Cloud Bigtable instance * indicated by the given options, and using any other specified customizations. * * <p>Clones the given {@link BigtableOptions} builder so that any further changes will have no * effect on the returned {@link BigtableIO.Write}. * * <p>Does not modify this object. * * @deprecated will be replaced by bigtable options configurator. */ @Deprecated public Write withBigtableOptions(BigtableOptions.Builder optionsBuilder) { BigtableConfig config = getBigtableConfig(); // TODO: is there a better way to clone a Builder? Want it to be immune from user changes. return toBuilder() .setBigtableConfig(config.withBigtableOptions(optionsBuilder.build().toBuilder().build())) .build(); }
/** * WARNING: Should be used only to specify additional parameters for connection to the Cloud * Bigtable, instanceId and projectId should be provided over {@link #withInstanceId} and {@link * #withProjectId} respectively. * * <p>Returns a new {@link BigtableIO.Read} that will read from the Cloud Bigtable instance * indicated by the given options, and using any other specified customizations. * * <p>Clones the given {@link BigtableOptions} builder so that any further changes will have no * effect on the returned {@link BigtableIO.Read}. * * <p>Does not modify this object. * * @deprecated will be replaced by bigtable options configurator. */ @Deprecated public Read withBigtableOptions(BigtableOptions.Builder optionsBuilder) { BigtableConfig config = getBigtableConfig(); // TODO: is there a better way to clone a Builder? Want it to be immune from user changes. return toBuilder() .setBigtableConfig(config.withBigtableOptions(optionsBuilder.build().toBuilder().build())) .build(); }
private BigtableOptions.Builder effectiveUserProvidedBigtableOptions() { BigtableOptions.Builder effectiveOptions = getBigtableOptions() != null ? getBigtableOptions().toBuilder() : new BigtableOptions.Builder(); if (getBigtableOptionsConfigurator() != null) { effectiveOptions = getBigtableOptionsConfigurator().apply(effectiveOptions); } if (getInstanceId() != null) { effectiveOptions.setInstanceId(getInstanceId().get()); } if (getProjectId() != null) { effectiveOptions.setProjectId(getProjectId().get()); } return effectiveOptions; }
@Test public void testReadWithBigTableOptionsSetsRetryOptions() { final int initialBackoffMillis = -1; BigtableOptions.Builder optionsBuilder = BIGTABLE_OPTIONS.toBuilder(); RetryOptions.Builder retryOptionsBuilder = new RetryOptions.Builder(); retryOptionsBuilder.setInitialBackoffMillis(initialBackoffMillis); optionsBuilder.setRetryOptions(retryOptionsBuilder.build()); BigtableIO.Read read = BigtableIO.read().withBigtableOptions(optionsBuilder.build()); BigtableOptions options = read.getBigtableOptions(); assertEquals(initialBackoffMillis, options.getRetryOptions().getInitialBackoffMillis()); assertThat(options.getRetryOptions(), Matchers.equalTo(retryOptionsBuilder.build())); }
@Test public void testWriteWithBigTableOptionsSetsBulkOptionsAndRetryOptions() { final int maxInflightRpcs = 1; final int initialBackoffMillis = -1; BigtableOptions.Builder optionsBuilder = BIGTABLE_OPTIONS.toBuilder(); BulkOptions.Builder bulkOptionsBuilder = new BulkOptions.Builder(); bulkOptionsBuilder.setMaxInflightRpcs(maxInflightRpcs); RetryOptions.Builder retryOptionsBuilder = new RetryOptions.Builder(); retryOptionsBuilder.setInitialBackoffMillis(initialBackoffMillis); optionsBuilder .setBulkOptions(bulkOptionsBuilder.build()) .setRetryOptions(retryOptionsBuilder.build()); BigtableIO.Write write = BigtableIO.write().withBigtableOptions(optionsBuilder.build()); BigtableOptions options = write.getBigtableOptions(); assertEquals(true, options.getBulkOptions().useBulkApi()); assertEquals(maxInflightRpcs, options.getBulkOptions().getMaxInflightRpcs()); assertEquals(initialBackoffMillis, options.getRetryOptions().getInitialBackoffMillis()); assertThat( options.getBulkOptions(), Matchers.equalTo(bulkOptionsBuilder.setUseBulkApi(true).build())); assertThat(options.getRetryOptions(), Matchers.equalTo(retryOptionsBuilder.build())); }
@Before public void setup() throws Exception { PipelineOptionsFactory.register(BigtableTestOptions.class); options = TestPipeline.testingPipelineOptions().as(BigtableTestOptions.class); project = options.as(GcpOptions.class).getProject(); bigtableOptions = new Builder() .setProjectId(project) .setInstanceId(options.getInstanceId()) .setUserAgent("apache-beam-test") .build(); session = new BigtableSession( bigtableOptions .toBuilder() .setCredentialOptions( CredentialOptions.credential(options.as(GcpOptions.class).getGcpCredential())) .build()); tableAdminClient = session.getTableAdminClient(); }
/** Tests that credentials are not used from PipelineOptions if supplied by BigtableOptions. */ @Test public void testDontUsePipelineOptionsCredentialsIfSpecifiedInBigtableOptions() throws Exception { BigtableOptions options = BIGTABLE_OPTIONS .toBuilder() .setCredentialOptions(CredentialOptions.nullCredential()) .build(); GcpOptions pipelineOptions = PipelineOptionsFactory.as(GcpOptions.class); pipelineOptions.setGcpCredential(new TestCredential()); BigtableService readService = BigtableIO.read() .withBigtableOptions(options) .withTableId("TEST-TABLE") .getBigtableConfig() .getBigtableService(pipelineOptions); BigtableService writeService = BigtableIO.write() .withBigtableOptions(options) .withTableId("TEST-TABLE") .getBigtableConfig() .getBigtableService(pipelineOptions); assertEquals( CredentialType.None, readService.getBigtableOptions().getCredentialOptions().getCredentialType()); assertEquals( CredentialType.None, writeService.getBigtableOptions().getCredentialOptions().getCredentialType()); }
/** Tests that credentials are used from PipelineOptions if not supplied by BigtableOptions. */ @Test public void testUsePipelineOptionsCredentialsIfNotSpecifiedInBigtableOptions() throws Exception { BigtableOptions options = BIGTABLE_OPTIONS .toBuilder() .setCredentialOptions(CredentialOptions.defaultCredentials()) .build(); GcpOptions pipelineOptions = PipelineOptionsFactory.as(GcpOptions.class); pipelineOptions.setGcpCredential(new TestCredential()); BigtableService readService = BigtableIO.read() .withBigtableOptions(options) .withTableId("TEST-TABLE") .getBigtableConfig() .getBigtableService(pipelineOptions); BigtableService writeService = BigtableIO.write() .withBigtableOptions(options) .withTableId("TEST-TABLE") .getBigtableConfig() .getBigtableService(pipelineOptions); assertEquals( CredentialType.SuppliedCredentials, readService.getBigtableOptions().getCredentialOptions().getCredentialType()); assertEquals( CredentialType.SuppliedCredentials, writeService.getBigtableOptions().getCredentialOptions().getCredentialType()); }