Search in sources :

Example 6 with Builder

use of com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder in project java-bigtable-hbase by googleapis.

the class SharedDataClientWrapperFactory method createDataClient.

synchronized DataClientWrapper createDataClient(BigtableHBaseVeneerSettings settings) throws IOException {
    Preconditions.checkArgument(!settings.getDataSettings().isRefreshingChannel(), "Channel refreshing is not compatible with cached channel pools");
    Key key = Key.createFromSettings(settings.getDataSettings());
    // Get or create ClientContext that will contained the shared resources
    ClientContext sharedCtx = cachedContexts.get(key);
    if (sharedCtx == null) {
        EnhancedBigtableStubSettings stubSettings = settings.getDataSettings().getStubSettings();
        sharedCtx = ClientContext.create(stubSettings);
        cachedContexts.put(key, sharedCtx);
        refCounts.put(key, 0);
        int channelPoolSize = BigtableVeneerApi.getChannelPoolSize(stubSettings);
        for (int i = 0; i < channelPoolSize; i++) {
            BigtableClientMetrics.counter(MetricLevel.Info, "grpc.channel.active").inc();
        }
        channelPoolSizes.put(key, channelPoolSize);
    }
    // Increment the count
    refCounts.put(key, refCounts.get(key) + 1);
    try {
        // Patch settings to use shared resources
        Builder builder = settings.getDataSettings().toBuilder();
        builder.stubSettings().setTransportChannelProvider(FixedTransportChannelProvider.create(sharedCtx.getTransportChannel())).setCredentialsProvider(FixedCredentialsProvider.create(sharedCtx.getCredentials())).setExecutorProvider(FixedExecutorProvider.create(sharedCtx.getExecutor())).setStreamWatchdogProvider(FixedWatchdogProvider.create(sharedCtx.getStreamWatchdog())).setHeaderProvider(FixedHeaderProvider.create(sharedCtx.getHeaders())).setClock(sharedCtx.getClock());
        BigtableDataSettings data = builder.build();
        // Create a reference counted client wrapper
        return new SharedDataClientWrapper(this, key, new DataClientVeneerApi(BigtableDataClient.create(data), settings.getClientTimeouts()));
    } catch (IOException | RuntimeException e) {
        release(key);
        throw e;
    }
}
Also used : EnhancedBigtableStubSettings(com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings) ClientContext(com.google.api.gax.rpc.ClientContext) Builder(com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder) IOException(java.io.IOException) BigtableDataSettings(com.google.cloud.bigtable.data.v2.BigtableDataSettings)

Example 7 with Builder

use of com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder in project java-bigtable-hbase by googleapis.

the class TestMultiRowRangeAdapter method testDisjoint.

@Test
public void testDisjoint() throws IOException {
    MultiRowRangeFilter filter = new MultiRowRangeFilter(Arrays.asList(new RowRange("bb", true, "cc", true), new RowRange("ss", true, "yy", true)));
    Filters.Filter adaptedFilter = adapter.adapt(context, filter);
    Assert.assertEquals(unaffectedRowFilter, adaptedFilter);
    RangeSet<RowKeyWrapper> indexScanHint = adapter.getIndexScanHint(filter);
    RangeSet<RowKeyWrapper> expected = ImmutableRangeSet.<RowKeyWrapper>builder().add(Range.closed(new RowKeyWrapper(ByteString.copyFromUtf8("bb")), new RowKeyWrapper(ByteString.copyFromUtf8("cc")))).add(Range.closed(new RowKeyWrapper(ByteString.copyFromUtf8("ss")), new RowKeyWrapper(ByteString.copyFromUtf8("yy")))).build();
    Assert.assertEquals(expected, indexScanHint);
}
Also used : Filters(com.google.cloud.bigtable.data.v2.models.Filters) RowRange(org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange) MultiRowRangeFilter(org.apache.hadoop.hbase.filter.MultiRowRangeFilter) RowKeyWrapper(com.google.cloud.bigtable.hbase.util.RowKeyWrapper) Test(org.junit.Test)

Example 8 with Builder

use of com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder in project java-bigtable by googleapis.

the class BigtableBulkReadRowsCallSettingsTest method testEmptyBuilder.

@Test
public void testEmptyBuilder() {
    BigtableBulkReadRowsCallSettings.Builder builder = BigtableBulkReadRowsCallSettings.newBuilder(new ReadRowsBatchingDescriptor());
    assertThat(builder.getBatchingSettings()).isNull();
    assertThat(builder.getRetryableCodes()).isEmpty();
    assertThat(builder.getRetrySettings()).isNotNull();
}
Also used : ReadRowsBatchingDescriptor(com.google.cloud.bigtable.data.v2.stub.readrows.ReadRowsBatchingDescriptor) Test(org.junit.Test)

Example 9 with Builder

use of com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder in project java-bigtable by googleapis.

the class BigtableBulkReadRowsCallSettingsTest method testBuilder.

@Test
public void testBuilder() {
    BigtableBulkReadRowsCallSettings.Builder builder = BigtableBulkReadRowsCallSettings.newBuilder(new ReadRowsBatchingDescriptor());
    Set<StatusCode.Code> retryCodes = ImmutableSet.of(StatusCode.Code.UNAVAILABLE);
    RetrySettings retrySettings = RetrySettings.newBuilder().build();
    builder.setBatchingSettings(BATCHING_SETTINGS).setRetryableCodes(retryCodes).setRetrySettings(retrySettings);
    BigtableBulkReadRowsCallSettings settings = builder.build();
    assertThat(settings.getBatchingSettings()).isEqualTo(BATCHING_SETTINGS);
    assertThat(settings.getRetryableCodes()).isEqualTo(retryCodes);
    assertThat(settings.getRetrySettings()).isEqualTo(retrySettings);
}
Also used : RetrySettings(com.google.api.gax.retrying.RetrySettings) ReadRowsBatchingDescriptor(com.google.cloud.bigtable.data.v2.stub.readrows.ReadRowsBatchingDescriptor) StatusCode(com.google.api.gax.rpc.StatusCode) Test(org.junit.Test)

Example 10 with Builder

use of com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder in project java-bigtable by googleapis.

the class BigtableBulkReadRowsCallSettingsTest method testBuilderFromSettings.

@Test
public void testBuilderFromSettings() {
    BigtableBulkReadRowsCallSettings.Builder builder = BigtableBulkReadRowsCallSettings.newBuilder(new ReadRowsBatchingDescriptor());
    RetrySettings retrySettings = RetrySettings.newBuilder().setTotalTimeout(Duration.ofMinutes(1)).build();
    builder.setBatchingSettings(BATCHING_SETTINGS).setRetryableCodes(StatusCode.Code.UNAVAILABLE, StatusCode.Code.UNAUTHENTICATED).setRetrySettings(retrySettings);
    BigtableBulkReadRowsCallSettings settings = builder.build();
    BigtableBulkReadRowsCallSettings.Builder newBuilder = settings.toBuilder();
    assertThat(newBuilder.getBatchingSettings()).isEqualTo(BATCHING_SETTINGS);
    assertThat(newBuilder.getRetryableCodes()).containsExactly(StatusCode.Code.UNAVAILABLE, StatusCode.Code.UNAUTHENTICATED);
    assertThat(newBuilder.getRetrySettings()).isEqualTo(retrySettings);
}
Also used : RetrySettings(com.google.api.gax.retrying.RetrySettings) ReadRowsBatchingDescriptor(com.google.cloud.bigtable.data.v2.stub.readrows.ReadRowsBatchingDescriptor) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 RetrySettings (com.google.api.gax.retrying.RetrySettings)4 BigtableDataSettings (com.google.cloud.bigtable.data.v2.BigtableDataSettings)3 MutateRowsBatchingDescriptor (com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsBatchingDescriptor)3 ReadRowsBatchingDescriptor (com.google.cloud.bigtable.data.v2.stub.readrows.ReadRowsBatchingDescriptor)3 InstantiatingGrpcChannelProvider (com.google.api.gax.grpc.InstantiatingGrpcChannelProvider)2 StatusCode (com.google.api.gax.rpc.StatusCode)2 MutateRowsRequest (com.google.bigtable.v2.MutateRowsRequest)2 Builder (com.google.bigtable.v2.MutateRowsRequest.Builder)2 Filters (com.google.cloud.bigtable.data.v2.models.Filters)2 MutateRowsException (com.google.cloud.bigtable.data.v2.models.MutateRowsException)2 FailedMutation (com.google.cloud.bigtable.data.v2.models.MutateRowsException.FailedMutation)2 ApiFunction (com.google.api.core.ApiFunction)1 BatcherImpl (com.google.api.gax.batching.BatcherImpl)1 FlowControlEventStats (com.google.api.gax.batching.FlowControlEventStats)1 ApiException (com.google.api.gax.rpc.ApiException)1 ClientContext (com.google.api.gax.rpc.ClientContext)1 OpencensusTracerFactory (com.google.api.gax.tracing.OpencensusTracerFactory)1 Credentials (com.google.auth.Credentials)1 ServiceAccountJwtAccessCredentials (com.google.auth.oauth2.ServiceAccountJwtAccessCredentials)1