Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion google-cloud-clients/google-cloud-bigtable/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ at the top of your file:

```java
import com.google.cloud.bigtable.data.v2.BigtableDataClient;
import com.google.cloud.bigtable.data.v2.models.InstanceName;
import com.google.cloud.bigtable.data.v2.models.Query;
import com.google.cloud.bigtable.data.v2.models.Row;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.google.cloud.bigtable.admin.v2;

import com.google.api.gax.core.CredentialsProvider;
import com.google.bigtable.admin.v2.ProjectName;
import com.google.cloud.bigtable.admin.v2.stub.BigtableInstanceAdminStubSettings;
import com.google.common.base.Preconditions;
Expand All @@ -34,12 +35,6 @@
* BigtableInstanceAdminSettings.Builder settingsBuilder = BigtableInstanceAdminSettings.newBuilder()
* .setProjectId("my-project");
*
* settingsBuilder.stubSettings().createInstanceSettings()
* .setRetrySettings(
* RetrySettings.newBuilder()
* .setTotalTimeout(Duration.ofMinutes(15))
* .build());
*
* BigtableInstanceAdminSettings settings = settingsBuilder.build();
* }</pre>
*/
Expand All @@ -61,17 +56,6 @@ public String getProjectId() {
return projectId;
}

/**
* Gets the name of the project whose instances the client will manager.
*
* @deprecated Please use {@link #getProjectId()}.
*/
@Deprecated
@Nonnull
public com.google.bigtable.admin.v2.ProjectName getProjectName() {
return ProjectName.of(projectId);
}

/** Gets the underlying RPC settings. */
@Nonnull
public BigtableInstanceAdminStubSettings getStubSettings() {
Expand All @@ -88,6 +72,15 @@ public static Builder newBuilder() {
return new Builder();
}

// <editor-fold desc="Deprecated">
/** @deprecated Please use {@link #getProjectId()}. */
@Deprecated
@Nonnull
public com.google.bigtable.admin.v2.ProjectName getProjectName() {
return ProjectName.of(projectId);
}
// </editor-fold>

/** Builder for BigtableInstanceAdminSettings. */
public static final class Builder {
@Nullable private String projectId;
Expand Down Expand Up @@ -115,28 +108,16 @@ public String getProjectId() {
return projectId;
}

/**
* Sets the name of instance whose tables the client will manage.
*
* @deprecated Please use {@link #setProjectId(String)}.
*/
@Deprecated
public Builder setProjectName(@Nonnull com.google.bigtable.admin.v2.ProjectName projectName) {
return setProjectId(projectName.getProject());
/** Sets the CredentialsProvider to use for getting the credentials to make calls with. */
public Builder setCredentialsProvider(CredentialsProvider credentialsProvider) {
stubSettings.setCredentialsProvider(credentialsProvider);

return this;
}

/**
* Gets the name of the project whose instances the client will manage.
*
* @deprecated Please use {@link #getProjectId()}.
*/
@Deprecated
@Nullable
public ProjectName getProjectName() {
if (projectId != null) {
return ProjectName.of(projectId);
}
return null;
/** Gets the CredentialsProvider to use for getting the credentials to make calls with. */
public CredentialsProvider getCredentialsProvider() {
return stubSettings.getCredentialsProvider();
}

/**
Expand All @@ -153,5 +134,23 @@ public BigtableInstanceAdminStubSettings.Builder stubSettings() {
public BigtableInstanceAdminSettings build() throws IOException {
return new BigtableInstanceAdminSettings(this);
}

// <editor-fold desc="Deprecated">
/** @deprecated Please use {@link #setProjectId(String)}. */
@Deprecated
public Builder setProjectName(@Nonnull com.google.bigtable.admin.v2.ProjectName projectName) {
return setProjectId(projectName.getProject());
}

/** @deprecated Please use {@link #getProjectId()}. */
@Deprecated
@Nullable
public ProjectName getProjectName() {
if (projectId != null) {
return ProjectName.of(projectId);
}
return null;
}
// </editor-fold>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@
*/
package com.google.cloud.bigtable.admin.v2;

import com.google.api.core.ApiFunction;
import com.google.api.gax.core.CredentialsProvider;
import com.google.api.gax.core.NoCredentialsProvider;
import com.google.cloud.bigtable.admin.v2.stub.BigtableTableAdminStubSettings;
import com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings;
import com.google.common.base.Preconditions;
import com.google.common.base.Verify;
import io.grpc.ManagedChannelBuilder;
import java.io.IOException;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -34,12 +39,6 @@
* .setProjectId("my-project")
* .setInstanceId("my-instance");
*
* tableAdminSettingsBuilder.stubSettings().createTableSettings()
* .setRetrySettings(
* RetrySettings.newBuilder()
* .setTotalTimeout(Duration.ofMinutes(15))
* .build());
*
* BigtableTableAdminSettings tableAdminSettings = tableAdminSettingsBuilder.build();
* }</pre>
*/
Expand All @@ -65,17 +64,6 @@ public String getInstanceId() {
return instanceId;
}

/**
* Gets the name of instance whose tables the client will manage.
*
* @deprecated Please use {@link #getProjectId()} and {@link #getInstanceId()}.
*/
@Deprecated
@Nonnull
public com.google.bigtable.admin.v2.InstanceName getInstanceName() {
return com.google.bigtable.admin.v2.InstanceName.of(projectId, instanceId);
}

/** Gets the underlying RPC settings. */
public BigtableTableAdminStubSettings getStubSettings() {
return stubSettings;
Expand All @@ -91,6 +79,38 @@ public static Builder newBuilder() {
return new Builder();
}

/** Create a new builder preconfigured to connect to the Bigtable emulator. */
public static Builder newBuilderForEmulator(int port) {
Builder builder = newBuilder().setProjectId("fake-project").setInstanceId("fake-instance");

builder
.stubSettings()
.setCredentialsProvider(NoCredentialsProvider.create())
.setEndpoint("localhost:" + port)
.setTransportChannelProvider(
EnhancedBigtableStubSettings.defaultGrpcTransportProviderBuilder()
.setPoolSize(1)
.setChannelConfigurator(
new ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder>() {
@Override
public ManagedChannelBuilder apply(ManagedChannelBuilder input) {
return input.usePlaintext();
}
})
.build());

return builder;
}

// <editor-fold desc="Deprecated">
/** @deprecated Please use {@link #getProjectId()} and {@link #getInstanceId()}. */
@Deprecated
@Nonnull
public com.google.bigtable.admin.v2.InstanceName getInstanceName() {
return com.google.bigtable.admin.v2.InstanceName.of(projectId, instanceId);
}
// </editor-fold>

/** Builder for BigtableTableAdminSettings. */
public static final class Builder {
@Nullable private String projectId;
Expand Down Expand Up @@ -133,11 +153,34 @@ public String getInstanceId() {
return instanceId;
}

/** Sets the CredentialsProvider to use for getting the credentials to make calls with. */
public Builder setCredentialsProvider(CredentialsProvider credentialsProvider) {
stubSettings.setCredentialsProvider(credentialsProvider);
return this;
}

/** Gets the CredentialsProvider to use for getting the credentials to make calls with. */
public CredentialsProvider getCredentialsProvider() {
return stubSettings.getCredentialsProvider();
}

/**
* Sets the name of instance whose tables the client will manage.
* Returns the builder for the settings used for all RPCs.
*
* @deprecated Please use {@link #setProjectId(String)} and {@link #setInstanceId(String)}.
* <p>This is meant for advanced usage. The default RPC settings are set to their recommended
* values.
*/
public BigtableTableAdminStubSettings.Builder stubSettings() {
return stubSettings;
}

/** Builds an instance of the settings. */
public BigtableTableAdminSettings build() throws IOException {
return new BigtableTableAdminSettings(this);
}

// <editor-fold desc="Deprecated">
/** @deprecated Please use {@link #setProjectId(String)} and {@link #setInstanceId(String)}. */
@Deprecated
public Builder setInstanceName(
@Nonnull com.google.bigtable.admin.v2.InstanceName instanceName) {
Expand All @@ -147,11 +190,7 @@ public Builder setInstanceName(
return this;
}

/**
* Gets the name of instance whose tables the client will manage.
*
* @deprecated Please use {@link #getProjectId()} and {@link #getInstanceId()}.
*/
/** @deprecated Please use {@link #getProjectId()} and {@link #getInstanceId()}. */
@Deprecated
@Nullable
public com.google.bigtable.admin.v2.InstanceName getInstanceName() {
Expand All @@ -160,20 +199,6 @@ public com.google.bigtable.admin.v2.InstanceName getInstanceName() {
}
return null;
}

/**
* Returns the builder for the settings used for all RPCs.
*
* <p>This is meant for advanced usage. The default RPC settings are set to their recommended
* values.
*/
public BigtableTableAdminStubSettings.Builder stubSettings() {
return stubSettings;
}

/** Builds an instance of the settings. */
public BigtableTableAdminSettings build() throws IOException {
return new BigtableTableAdminSettings(this);
}
// </editor-fold>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,29 +127,24 @@ public static BigtableDataClient create(String projectId, String instanceId) thr
}

/**
* Constructs an instance of BigtableDataClient with default settings.
*
* @param instanceName The instance to connect to.
* @return A new client.
* @throws IOException If any.
* @deprecated Please use {@link #create(String, String)}.
* Constructs an instance of BigtableDataClient, using the given settings. The channels are
* created based on the settings passed in, or defaults for any settings that are not set.
*/
public static BigtableDataClient create(BigtableDataSettings settings) throws IOException {
EnhancedBigtableStub stub = EnhancedBigtableStub.create(settings.getStubSettings());
return new BigtableDataClient(stub);
}

// <editor-fold desc="Deprecated">
/** @deprecated Please use {@link #create(String, String)}. */
@Deprecated
public static BigtableDataClient create(
com.google.cloud.bigtable.data.v2.models.InstanceName instanceName) throws IOException {
BigtableDataSettings settings =
BigtableDataSettings.newBuilder().setInstanceName(instanceName).build();
return create(settings);
}

/**
* Constructs an instance of BigtableDataClient, using the given settings. The channels are
* created based on the settings passed in, or defaults for any settings that are not set.
*/
public static BigtableDataClient create(BigtableDataSettings settings) throws IOException {
EnhancedBigtableStub stub = EnhancedBigtableStub.create(settings.getTypedStubSettings());
return new BigtableDataClient(stub);
}
// </editor-fold>

@InternalApi("Visible for testing")
BigtableDataClient(EnhancedBigtableStub stub) {
Expand Down Expand Up @@ -260,8 +255,7 @@ public Row readRow(String tableId, String rowKey, @Nullable Filter filter) {
* <p>Sample code:
*
* <pre>{@code
* InstanceName instanceName = InstanceName.of("[PROJECT]", "[INSTANCE]");
* try (BigtableDataClient bigtableDataClient = BigtableDataClient.create(instanceName)) {
* try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
* String tableId = "[TABLE]";
*
* // Build the filter expression
Expand Down Expand Up @@ -400,8 +394,7 @@ public ApiFuture<Row> readRowAsync(String tableId, String rowKey, @Nullable Filt
* <p>Sample code:
*
* <pre>{@code
* InstanceName instanceName = InstanceName.of("[PROJECT]", "[INSTANCE]");
* try (BigtableDataClient bigtableDataClient = BigtableDataClient.create(instanceName)) {
* try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
* String tableId = "[TABLE]";
*
* // Build the filter expression
Expand Down Expand Up @@ -442,8 +435,7 @@ public ApiFuture<Row> readRowAsync(String tableId, ByteString rowKey, @Nullable
* <p>Sample code:
*
* <pre>{@code
* InstanceName instanceName = InstanceName.of("[PROJECT]", "[INSTANCE]");
* try (BigtableDataClient bigtableDataClient = BigtableDataClient.create(instanceName)) {
* try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
* String tableId = "[TABLE]";
*
* Query query = Query.create(tableId)
Expand Down Expand Up @@ -495,8 +487,7 @@ public UnaryCallable<Query, Row> readRowCallable() {
* <p>Sample code:
*
* <pre>{@code
* InstanceName instanceName = InstanceName.of("[PROJECT]", "[INSTANCE]");
* try (BigtableDataClient bigtableDataClient = BigtableDataClient.create(instanceName)) {
* try (BigtableDataClient bigtableDataClient = BigtableDataClient.create("[PROJECT]", "[INSTANCE]")) {
* String tableId = "[TABLE]";
*
* Query query = Query.create(tableId)
Expand Down
Loading