diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ead8d9dea..8fb474d3c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,26 @@ # Changelog +## [1.9.0](https://www.github.com/googleapis/java-bigtable/compare/v1.8.0...v1.9.0) (2020-01-06) + + +### Features + +* add BigtableDataClientFactory to create lightweight data clients ([#112](https://www.github.com/googleapis/java-bigtable/issues/112)) ([d6bfd30](https://www.github.com/googleapis/java-bigtable/commit/d6bfd30ea9484b7433a048bdaad66153ffaa6a79)) +* introduce google-cloud-bigtable-deps-bom ([#130](https://www.github.com/googleapis/java-bigtable/issues/130)) ([9289a13](https://www.github.com/googleapis/java-bigtable/commit/9289a13203b009930507c858ed14326768174c28)) + + +### Dependencies + +* update core dependencies to v1.92.1 ([#132](https://www.github.com/googleapis/java-bigtable/issues/132)) ([da1e6c6](https://www.github.com/googleapis/java-bigtable/commit/da1e6c61770c934644588f8a9933f6f68bd35ad1)) +* update dependency com.google.guava:guava-bom to v28.2-android ([2905528](https://www.github.com/googleapis/java-bigtable/commit/2905528eac8f39e2aa39ca5bca13c6aba33f178b)) +* update dependency io.grpc:grpc-bom to v1.26.0 ([#121](https://www.github.com/googleapis/java-bigtable/issues/121)) ([82a5094](https://www.github.com/googleapis/java-bigtable/commit/82a50943e454a3e8a23f002128d842eb98458b51)) +* update dependency junit:junit to v4.13 ([#131](https://www.github.com/googleapis/java-bigtable/issues/131)) ([d4f46fd](https://www.github.com/googleapis/java-bigtable/commit/d4f46fd7118f2037a58bae2c467ff11449ee4dfc)) + + +### Documentation + +* update README to include CI Status ([#125](https://www.github.com/googleapis/java-bigtable/issues/125)) ([1e4987b](https://www.github.com/googleapis/java-bigtable/commit/1e4987b8baaa7e0dfd3905e6acf643788d5c722c)) + ## [1.8.0](https://www.github.com/googleapis/java-bigtable/compare/v1.7.1...v1.8.0) (2019-12-17) diff --git a/README.md b/README.md index ae32a554c0..637675ba4d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ Java idiomatic client for [Cloud Bigtable][cloud-bigtable]. -[![Kokoro CI](http://storage.googleapis.com/cloud-devrel-public/java/badges/google-cloud-java/master.svg)](http://storage.googleapis.com/cloud-devrel-public/java/badges/google-cloud-java/master.html) [![Maven](https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-bigtable.svg)](https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-bigtable.svg) [![Codacy Badge](https://api.codacy.com/project/badge/grade/9da006ad7c3a4fe1abd142e77c003917)](https://www.codacy.com/app/mziccard/google-cloud-java) @@ -17,16 +16,16 @@ If you are using Maven, add this to your pom.xml file com.google.cloud google-cloud-bigtable - 1.8.0 + 1.9.0 ``` If you are using Gradle, add this to your dependencies ```Groovy -compile 'com.google.cloud:google-cloud-bigtable:1.8.0' +compile 'com.google.cloud:google-cloud-bigtable:1.9.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-bigtable" % "1.8.0" +libraryDependencies += "com.google.cloud" % "google-cloud-bigtable" % "1.9.0" ``` [//]: # ({x-version-update-end}) @@ -338,7 +337,7 @@ Add the following to your project's pom.xml. io.grpc grpc-bom - 1.24.1 + 1.26.0 pom import @@ -374,6 +373,16 @@ codebase. Apache 2.0 - See [LICENSE] for more information. +## CI Status + +Java Version | Status +------------ | ------ +Java 7 | [![Kokoro CI][kokoro-badge-image-1]][kokoro-badge-link-1] +Java 8 | [![Kokoro CI][kokoro-badge-image-2]][kokoro-badge-link-2] +Java 8 OSX | [![Kokoro CI][kokoro-badge-image-3]][kokoro-badge-link-3] +Java 8 Windows | [![Kokoro CI][kokoro-badge-image-4]][kokoro-badge-link-4] +Java 11 | [![Kokoro CI][kokoro-badge-image-5]][kokoro-badge-link-5] + [CONTRIBUTING]:https://github.com/googleapis/google-cloud-java/blob/master/CONTRIBUTING.md [DEVELOPING]:DEVELOPING.md [LICENSE]: https://github.com/googleapis/google-cloud-java/blob/master/LICENSE @@ -381,3 +390,13 @@ Apache 2.0 - See [LICENSE] for more information. [cloud-bigtable]: https://cloud.google.com/bigtable/ [bigtable-product-docs]: https://cloud.google.com/bigtable/docs/ [bigtable-client-lib-docs]: https://googleapis.dev/java/google-cloud-clients/latest/index.html?com/google/cloud/bigtable/package-summary.html +[kokoro-badge-image-1]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-bigtable/java7.svg +[kokoro-badge-link-1]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-bigtable/java7.html +[kokoro-badge-image-2]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-bigtable/java8.svg +[kokoro-badge-link-2]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-bigtable/java8.html +[kokoro-badge-image-3]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-bigtable/java8-osx.svg +[kokoro-badge-link-3]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-bigtable/java8-osx.html +[kokoro-badge-image-4]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-bigtable/java8-win.svg +[kokoro-badge-link-4]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-bigtable/java8-win.html +[kokoro-badge-image-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-bigtable/java11.svg +[kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-bigtable/java11.html \ No newline at end of file diff --git a/google-cloud-bigtable-bom/pom.xml b/google-cloud-bigtable-bom/pom.xml index 4c3d25a57c..f1284474ac 100644 --- a/google-cloud-bigtable-bom/pom.xml +++ b/google-cloud-bigtable-bom/pom.xml @@ -3,12 +3,12 @@ 4.0.0 com.google.cloud google-cloud-bigtable-bom - 1.8.0 + 1.9.0 pom com.google.cloud google-cloud-shared-config - 0.3.0 + 0.3.1 Google Cloud Bigtable BOM @@ -72,32 +72,32 @@ com.google.cloud google-cloud-bigtable - 1.8.0 + 1.9.0 com.google.cloud google-cloud-bigtable-emulator - 0.117.0 + 0.118.0 com.google.api.grpc grpc-google-cloud-bigtable-admin-v2 - 1.8.0 + 1.9.0 com.google.api.grpc grpc-google-cloud-bigtable-v2 - 1.8.0 + 1.9.0 com.google.api.grpc proto-google-cloud-bigtable-admin-v2 - 1.8.0 + 1.9.0 com.google.api.grpc proto-google-cloud-bigtable-v2 - 1.8.0 + 1.9.0 diff --git a/google-cloud-bigtable-deps-bom/README.md b/google-cloud-bigtable-deps-bom/README.md new file mode 100644 index 0000000000..6889c82d15 --- /dev/null +++ b/google-cloud-bigtable-deps-bom/README.md @@ -0,0 +1,44 @@ +# Dependency BOM for Google Cloud Bigtable Client + +This module contains a BOM that lists all of Cloud Bigtable's dependency versions. Please note that +this BOM is complementary to google-cloud-bigtable-bom. This BOM only contains transitive dependencies, +while google-cloud-bigtable-bom contains versions for direct google-cloud-bigtable artifacts. + +This BOM is primarily intended to be used by java-bigtable-hbase to keep the dependencies in sync. + +Example usage: + +[//]: # ({x-version-update-start:google-cloud-bigtable:released}) +```xml + + + + + com.google.cloud + google-cloud-bigtable-bom + 1.8.0 + pom + import + + + + com.google.cloud + google-cloud-bigtable-deps-bom + 1.8.0 + pom + import + + + + + + + + com.google.cloud + google-cloud-bigtable + + + +``` +[//]: # ({x-version-update-end}) diff --git a/google-cloud-bigtable-deps-bom/pom.xml b/google-cloud-bigtable-deps-bom/pom.xml new file mode 100644 index 0000000000..7fd0932da1 --- /dev/null +++ b/google-cloud-bigtable-deps-bom/pom.xml @@ -0,0 +1,221 @@ + + + 4.0.0 + + + com.google.cloud + google-cloud-shared-config + 0.3.1 + + + com.google.cloud + google-cloud-bigtable-deps-bom + 1.9.0 + + pom + + A BOM that describes all of the dependencies used by google-cloud-bigtable. It's + mainly intended to be used by java-bigtable-hbase to align dependencies + + + + Google LLC + + + + + igorberstein + Igor Bernstein + igorbernstein@google.com + Google LLC + + Developer + + + + kolea2 + Kristen O'Leary + kaoleary@google.com + Google LLC + + Developer + + + + + + scm:git:https://github.com/googleapis/java-bigtable.git + scm:git:git@github.com:googleapis/java-bigtable.git + https://github.com/googleapis/java-bigtable + + + + + sonatype-nexus-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + + sonatype-nexus-staging + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + 1.7 + + 1.52.0 + 1.8.1 + 1.17.0 + 1.92.1 + 0.19.0 + + 1.26.0 + 28.2-android + 0.24.0 + 3.11.1 + 1.4.0 + + + + + + + com.google.api + gax-bom + ${gax.version} + pom + import + + + com.google.auth + google-auth-library-bom + ${google.auth.version} + pom + import + + + com.google.guava + guava-bom + ${guava.version} + pom + import + + + io.grpc + grpc-bom + ${grpc.version} + pom + import + + + + + com.google.api + api-common + ${google.api-common.version} + + + com.google.api.grpc + proto-google-common-protos + ${google.common-protos.version} + + + com.google.api.grpc + proto-google-iam-v1 + 0.13.0 + + + com.google.auto.value + auto-value + ${autovalue.version} + + + com.google.auto.value + auto-value-annotations + ${autovalue.version} + + + com.google.cloud + google-cloud-core + ${google.core.version} + + + com.google.cloud + google-cloud-core-grpc + ${google.core.version} + + + com.google.errorprone + error_prone_annotations + 2.3.4 + + + com.google.code.findbugs + jsr305 + 3.0.2 + + + com.google.protobuf + protobuf-java + ${protobuf.version} + + + com.google.protobuf + protobuf-java-util + ${protobuf.version} + + + io.opencensus + opencensus-api + ${opencensus.version} + + + javax.annotation + javax.annotation-api + 1.3.2 + + + org.codehaus.mojo + animal-sniffer-annotations + 1.18 + + + org.threeten + threetenbp + ${threeten.version} + + + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + true + + + + + + org.apache.maven.plugins + maven-site-plugin + + + false + + + + + diff --git a/google-cloud-bigtable-emulator/pom.xml b/google-cloud-bigtable-emulator/pom.xml index 0b35714cae..257ac82443 100644 --- a/google-cloud-bigtable-emulator/pom.xml +++ b/google-cloud-bigtable-emulator/pom.xml @@ -5,7 +5,7 @@ 4.0.0 google-cloud-bigtable-emulator - 0.117.0 + 0.118.0 Google Cloud Java - Bigtable Emulator https://github.com/googleapis/java-bigtable @@ -14,7 +14,7 @@ com.google.cloud google-cloud-bigtable-parent - 1.8.0 + 1.9.0 scm:git:git@github.com:googleapis/java-bigtable.git @@ -75,6 +75,25 @@ + + + + com.google.cloud + google-cloud-bigtable-deps-bom + 1.9.0 + pom + import + + + com.google.cloud + google-cloud-bigtable-bom + 1.9.0 + pom + import + + + + diff --git a/google-cloud-bigtable/pom.xml b/google-cloud-bigtable/pom.xml index a5382f3e5f..ece322e676 100644 --- a/google-cloud-bigtable/pom.xml +++ b/google-cloud-bigtable/pom.xml @@ -2,7 +2,7 @@ 4.0.0 google-cloud-bigtable - 1.8.0 + 1.9.0 jar Google Cloud Bigtable https://github.com/googleapis/java-bigtable @@ -12,7 +12,7 @@ com.google.cloud google-cloud-bigtable-parent - 1.8.0 + 1.9.0 google-cloud-bigtable @@ -29,6 +29,26 @@ + + + + + com.google.cloud + google-cloud-bigtable-deps-bom + 1.9.0 + pom + import + + + com.google.cloud + google-cloud-bigtable-bom + 1.9.0 + pom + import + + + + @@ -361,6 +381,7 @@ classes 2C + 1 true false diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClientFactory.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClientFactory.java new file mode 100644 index 0000000000..b08613cc69 --- /dev/null +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClientFactory.java @@ -0,0 +1,204 @@ +/* + * Copyright 2019 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable.data.v2; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.api.gax.core.FixedExecutorProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.FixedHeaderProvider; +import com.google.api.gax.rpc.FixedTransportChannelProvider; +import com.google.api.gax.rpc.FixedWatchdogProvider; +import com.google.api.gax.rpc.StubSettings; +import java.io.IOException; +import javax.annotation.Nonnull; + +/** + * A factory to create multiple {@link BigtableDataClient} instances that all share the same channel + * pool. + * + *

This allows multiple client instances to share the same gRPC channel pool, which makes client + * creation very cheap. The intended use case is for applications that need to access multiple + * Bigtable Instances from the same process. + * + *

Example Usage: + * + *

{@code
+ * BigtableDataSettings defaultSettings = BigtableDataSettings.newBuilder()
+ *   .setProject("my-default-project")
+ *   .setInstance("my-default-instance")
+ *   .build();
+ *
+ * BigtableDataClientFactory clientFactory = BigtableDataClientFactory.create(defaultSettings);
+ *
+ * // Create a new client for "my-default-instance" in "my-default-project";
+ * BigtableDataClient defaultInstanceClient = clientFactory.createDefault();
+ *
+ * // Create a new client for a different application profile
+ * BigtableDataClient otherAppProfileClient = clientFactory.createForAppProfile("other-app-profile");
+ *
+ * // Create a new client for a completely different instance and application profile.
+ * BigtableDataClient otherInstanceClient = clientFactory
+ *   .createForInstance("my-other-project", "my-other-instance", "my-other-app-profile");
+ *
+ * // Clean up: make sure close the clients AND the factory.
+ * defaultInstanceClient.close();
+ * otherAppProfileClient.close();
+ * otherInstanceClient.close();
+ *
+ * clientFactory.close();
+ *
+ * 

Please note that this is an experimental feature and might be changed or removed in future. + * }

+ */ +@BetaApi("This feature is currently experimental and can change in the future") +public final class BigtableDataClientFactory implements AutoCloseable { + private final BigtableDataSettings defaultSettings; + private final ClientContext sharedClientContext; + + /** + * Create a instance of this factory. + * + *

The factory will be used to create clients using the provided settings as the base. Make + * sure to call {@link #close()} on the factory after closing all clients. + */ + public static BigtableDataClientFactory create(BigtableDataSettings defaultSettings) + throws IOException { + ClientContext sharedClientContext = ClientContext.create(defaultSettings.getStubSettings()); + return new BigtableDataClientFactory(sharedClientContext, defaultSettings); + } + + private BigtableDataClientFactory( + ClientContext sharedClientContext, BigtableDataSettings defaultSettings) { + this.sharedClientContext = sharedClientContext; + this.defaultSettings = defaultSettings; + } + + /** + * Release all of the resources associated with this factory. + * + *

This will close the underlying channel pooling, disconnecting all create clients. + */ + @Override + public void close() throws Exception { + for (BackgroundResource resource : sharedClientContext.getBackgroundResources()) { + resource.close(); + } + } + + /** + * Create a lightweight client using the default settings in this factory. This will use the + * factory default project, instance and application profile ids. The client will also share + * resources like the channel pool with other clients created using this factory. + * + *

The client should be closed when it is no longer needed. Closing the client will release + * client specific resources, but will leave shared resources like the channel pool open. To + * release all resources, first close all of the created clients and then this factory instance. + */ + public BigtableDataClient createDefault() { + BigtableDataSettings.Builder settingsBuilder = defaultSettings.toBuilder(); + patchStubSettings(settingsBuilder.stubSettings()); + BigtableDataSettings settings = settingsBuilder.build(); + + try { + return BigtableDataClient.create(settings); + } catch (IOException e) { + // Should never happen because the connection has been established already + throw new RuntimeException( + "Failed to create a new client using factory default settings and shared resources."); + } + } + + /** + * Create a lightweight client with an overriden application profile and the factory default + * project and instance ids. The client will also share resources like the channel pool with other + * clients created using this factory. + * + *

The client should be closed when it is no longer needed. Closing the client will release + * client specific resources, but will leave shared resources like the channel pool open. To + * release all resources, first close all of the created clients and then this factory instance. + */ + public BigtableDataClient createForAppProfile(@Nonnull String appProfileId) throws IOException { + BigtableDataSettings.Builder settingsBuilder = + defaultSettings.toBuilder().setAppProfileId(appProfileId); + + patchStubSettings(settingsBuilder.stubSettings()); + + return BigtableDataClient.create(settingsBuilder.build()); + } + + /** + * Create a lightweight client with the specified project and instance id. The resulting client + * will use the server default application profile. The client will also share resources like the + * channel pool with other clients created using this factory. + * + *

The client should be closed when it is no longer needed. Closing the client will release + * client specific resources, but will leave shared resources like the channel pool open. To + * release all resources, first close all of the created clients and then this factory instance. + */ + public BigtableDataClient createForInstance(@Nonnull String projectId, @Nonnull String instanceId) + throws IOException { + BigtableDataSettings.Builder settingsBuilder = + defaultSettings + .toBuilder() + .setProjectId(projectId) + .setInstanceId(instanceId) + .setDefaultAppProfileId(); + + patchStubSettings(settingsBuilder.stubSettings()); + + return BigtableDataClient.create(settingsBuilder.build()); + } + + /** + * Create a lightweight client to the specified project, instance and application profile id. The + * client will share resources like the channel pool with other clients created using this + * factory. + * + *

The client should be closed when it is no longer needed. Closing the client will release + * client specific resources, but will leave shared resources like the channel pool open. To + * release all resources, first close all of the created clients and then this factory instance. + */ + public BigtableDataClient createForInstance( + @Nonnull String projectId, @Nonnull String instanceId, @Nonnull String appProfileId) + throws IOException { + BigtableDataSettings.Builder settingsBuilder = + defaultSettings + .toBuilder() + .setProjectId(projectId) + .setInstanceId(instanceId) + .setAppProfileId(appProfileId); + + patchStubSettings(settingsBuilder.stubSettings()); + + return BigtableDataClient.create(settingsBuilder.build()); + } + + // Update stub settings to use shared resources in this factory + private void patchStubSettings(StubSettings.Builder stubSettings) { + stubSettings + .setTransportChannelProvider( + FixedTransportChannelProvider.create(sharedClientContext.getTransportChannel())) + .setCredentialsProvider( + FixedCredentialsProvider.create(sharedClientContext.getCredentials())) + .setExecutorProvider(FixedExecutorProvider.create(sharedClientContext.getExecutor())) + .setStreamWatchdogProvider( + FixedWatchdogProvider.create(sharedClientContext.getStreamWatchdog())) + .setHeaderProvider(FixedHeaderProvider.create(sharedClientContext.getHeaders())) + .setClock(sharedClientContext.getClock()); + } +} diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataSettings.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataSettings.java index ff97408809..437ebc653b 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataSettings.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataSettings.java @@ -255,16 +255,34 @@ public String getInstanceId() { } /** - * Sets the AppProfile to use. An application profile (sometimes also shortened to "app - * profile") is a group of configuration parameters for an individual use case. A client will - * identify itself with an application profile ID at connection time, and the requests will be - * handled according to that application profile. + * Sets the AppProfile to use. + * + *

An application profile (sometimes also shortened to "app profile") is a group of + * configuration parameters for an individual use case. A client will identify itself with an + * application profile ID at connection time, and the requests will be handled according to that + * application profile. */ public Builder setAppProfileId(@Nonnull String appProfileId) { stubSettings.setAppProfileId(appProfileId); return this; } + /** + * Resets the AppProfile id to the default for the instance. + * + *

An application profile (sometimes also shortened to "app profile") is a group of + * configuration parameters for an individual use case. A client will identify itself with an + * application profile ID at connection time, and the requests will be handled according to that + * application profile. + * + *

Every Bigtable Instance has a default application profile associated with it, this method + * configures the client to use it. + */ + public Builder setDefaultAppProfileId() { + stubSettings.setDefaultAppProfileId(); + return this; + } + /** Gets the app profile id that was previously set on this Builder. */ public String getAppProfileId() { return stubSettings.getAppProfileId(); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java index 11d4726080..4fc544061f 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java @@ -610,6 +610,22 @@ public Builder setAppProfileId(@Nonnull String appProfileId) { return this; } + /** + * Resets the AppProfile id to the default for the instance. + * + *

An application profile (sometimes also shortened to "app profile") is a group of + * configuration parameters for an individual use case. A client will identify itself with an + * application profile ID at connection time, and the requests will be handled according to that + * application profile. + * + *

Every Bigtable Instance has a default application profile associated with it, this method + * configures the client to use it. + */ + public Builder setDefaultAppProfileId() { + setAppProfileId(SERVER_DEFAULT_APP_PROFILE_ID); + return this; + } + /** Gets the app profile id that was previously set on this Builder. */ public String getAppProfileId() { return appProfileId; diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientFactoryTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientFactoryTest.java new file mode 100644 index 0000000000..612569fd2e --- /dev/null +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/BigtableDataClientFactoryTest.java @@ -0,0 +1,236 @@ +/* + * Copyright 2019 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable.data.v2; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.api.core.ApiClock; +import com.google.api.gax.core.CredentialsProvider; +import com.google.api.gax.core.ExecutorProvider; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.WatchdogProvider; +import com.google.bigtable.v2.BigtableGrpc; +import com.google.bigtable.v2.MutateRowRequest; +import com.google.bigtable.v2.MutateRowResponse; +import com.google.cloud.bigtable.data.v2.internal.NameUtil; +import com.google.cloud.bigtable.data.v2.models.RowMutation; +import io.grpc.Server; +import io.grpc.ServerBuilder; +import io.grpc.stub.StreamObserver; +import java.io.IOException; +import java.lang.reflect.Method; +import java.net.ServerSocket; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.mockito.Mockito; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; +import org.mockito.stubbing.Answer; + +@RunWith(JUnit4.class) +public class BigtableDataClientFactoryTest { + @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); + + private static final String DEFAULT_PROJECT_ID = "fake-project"; + private static final String DEFAULT_INSTANCE_ID = "fake-instance"; + private static final String DEFAULT_APP_PROFILE_ID = "fake-app-profile"; + + private Server fakeServer; + private FakeBigtableService service; + + private TransportChannelProvider transportChannelProvider; + private CredentialsProvider credentialsProvider; + private ExecutorProvider executorProvider; + private WatchdogProvider watchdogProvider; + private ApiClock apiClock; + private BigtableDataSettings defaultSettings; + + @Before + public void setUp() throws IOException { + service = new FakeBigtableService(); + + // Create a fake server for the client to connect to + final int port; + try (ServerSocket ss = new ServerSocket(0)) { + port = ss.getLocalPort(); + } + fakeServer = ServerBuilder.forPort(port).addService(service).build(); + fakeServer.start(); + + BigtableDataSettings.Builder builder = + BigtableDataSettings.newBuilderForEmulator(port) + .setProjectId(DEFAULT_PROJECT_ID) + .setInstanceId(DEFAULT_INSTANCE_ID) + .setAppProfileId(DEFAULT_APP_PROFILE_ID); + + transportChannelProvider = + Mockito.mock( + TransportChannelProvider.class, + new BuilderAnswer<>( + TransportChannelProvider.class, + builder.stubSettings().getTransportChannelProvider())); + + credentialsProvider = + Mockito.mock( + CredentialsProvider.class, + new BuilderAnswer<>( + CredentialsProvider.class, builder.stubSettings().getCredentialsProvider())); + + executorProvider = + Mockito.mock( + ExecutorProvider.class, + new BuilderAnswer<>( + ExecutorProvider.class, builder.stubSettings().getExecutorProvider())); + + watchdogProvider = + Mockito.mock( + WatchdogProvider.class, + new BuilderAnswer<>( + WatchdogProvider.class, builder.stubSettings().getStreamWatchdogProvider())); + + apiClock = builder.stubSettings().getClock(); + + builder + .stubSettings() + .setTransportChannelProvider(transportChannelProvider) + .setCredentialsProvider(credentialsProvider) + .setExecutorProvider(executorProvider) + .setStreamWatchdogProvider(watchdogProvider) + .setClock(apiClock); + + defaultSettings = builder.build(); + } + + @After + public void tearDown() { + if (fakeServer != null) { + fakeServer.shutdownNow(); + } + } + + @Test + public void testNewClientsShareTransportChannel() throws Exception { + BigtableDataClientFactory factory = BigtableDataClientFactory.create(defaultSettings); + + // Create 3 lightweight clients + BigtableDataClient client1 = factory.createForInstance("project1", "instance1"); + BigtableDataClient client2 = factory.createForInstance("project2", "instance2"); + BigtableDataClient client3 = factory.createForInstance("project3", "instance3"); + + // Make sure that only 1 instance is created by each provider + Mockito.verify(transportChannelProvider, Mockito.times(1)).getTransportChannel(); + Mockito.verify(credentialsProvider, Mockito.times(1)).getCredentials(); + Mockito.verify(executorProvider, Mockito.times(1)).getExecutor(); + Mockito.verify(watchdogProvider, Mockito.times(1)).getWatchdog(); + + // clean up + client1.close(); + client2.close(); + client3.close(); + factory.close(); + } + + @Test + public void testCreateDefaultKeepsSettings() throws Exception { + BigtableDataClientFactory factory = BigtableDataClientFactory.create(defaultSettings); + BigtableDataClient client = factory.createDefault(); + + client.mutateRow(RowMutation.create("some-table", "some-key").deleteRow()); + + assertThat(service.lastRequest.getTableName()) + .isEqualTo(NameUtil.formatTableName(DEFAULT_PROJECT_ID, DEFAULT_INSTANCE_ID, "some-table")); + assertThat(service.lastRequest.getAppProfileId()).isEqualTo(DEFAULT_APP_PROFILE_ID); + } + + @Test + public void testCreateForAppProfileHasCorrectSettings() throws Exception { + BigtableDataClientFactory factory = BigtableDataClientFactory.create(defaultSettings); + BigtableDataClient client = factory.createForAppProfile("other-app-profile"); + + client.mutateRow(RowMutation.create("some-table", "some-key").deleteRow()); + + assertThat(service.lastRequest.getTableName()) + .isEqualTo(NameUtil.formatTableName(DEFAULT_PROJECT_ID, DEFAULT_INSTANCE_ID, "some-table")); + assertThat(service.lastRequest.getAppProfileId()).isEqualTo("other-app-profile"); + } + + @Test + public void testCreateForInstanceHasCorrectSettings() throws Exception { + BigtableDataClientFactory factory = BigtableDataClientFactory.create(defaultSettings); + BigtableDataClient client = factory.createForInstance("other-project", "other-instance"); + + client.mutateRow(RowMutation.create("some-table", "some-key").deleteRow()); + + assertThat(service.lastRequest.getTableName()) + .isEqualTo(NameUtil.formatTableName("other-project", "other-instance", "some-table")); + // app profile should be reset to default + assertThat(service.lastRequest.getAppProfileId()).isEmpty(); + } + + @Test + public void testCreateForInstanceWithAppProfileHasCorrectSettings() throws Exception { + BigtableDataClientFactory factory = BigtableDataClientFactory.create(defaultSettings); + BigtableDataClient client = + factory.createForInstance("other-project", "other-instance", "other-app-profile"); + + client.mutateRow(RowMutation.create("some-table", "some-key").deleteRow()); + + assertThat(service.lastRequest.getTableName()) + .isEqualTo(NameUtil.formatTableName("other-project", "other-instance", "some-table")); + // app profile should be reset to default + assertThat(service.lastRequest.getAppProfileId()).isEqualTo("other-app-profile"); + } + + private static class FakeBigtableService extends BigtableGrpc.BigtableImplBase { + volatile MutateRowRequest lastRequest; + + @Override + public void mutateRow( + MutateRowRequest request, StreamObserver responseObserver) { + lastRequest = request; + responseObserver.onNext(MutateRowResponse.getDefaultInstance()); + responseObserver.onCompleted(); + } + } + + private static class BuilderAnswer implements Answer { + private final Class targetClass; + private T targetInstance; + + public BuilderAnswer(Class targetClass, T targetInstance) { + this.targetClass = targetClass; + this.targetInstance = targetInstance; + } + + @Override + public Object answer(InvocationOnMock invocation) throws Throwable { + Method method = invocation.getMethod(); + Object r = invocation.getMethod().invoke(targetInstance, invocation.getArguments()); + + if (method.getName().startsWith("with") + && targetClass.isAssignableFrom(method.getReturnType())) { + this.targetInstance = (T) r; + r = invocation.getMock(); + } + return r; + } + } +} diff --git a/grpc-google-cloud-bigtable-admin-v2/pom.xml b/grpc-google-cloud-bigtable-admin-v2/pom.xml index 0a04bff09d..b2f1e697a8 100644 --- a/grpc-google-cloud-bigtable-admin-v2/pom.xml +++ b/grpc-google-cloud-bigtable-admin-v2/pom.xml @@ -4,14 +4,34 @@ 4.0.0 com.google.api.grpc grpc-google-cloud-bigtable-admin-v2 - 1.8.0 + 1.9.0 grpc-google-cloud-bigtable-admin-v2 GRPC library for grpc-google-cloud-bigtable-admin-v2 com.google.cloud google-cloud-bigtable-parent - 1.8.0 + 1.9.0 + + + + + com.google.cloud + google-cloud-bigtable-deps-bom + 1.9.0 + pom + import + + + com.google.cloud + google-cloud-bigtable-bom + 1.9.0 + pom + import + + + + io.grpc diff --git a/grpc-google-cloud-bigtable-v2/pom.xml b/grpc-google-cloud-bigtable-v2/pom.xml index c61ef638d0..25d37e154d 100644 --- a/grpc-google-cloud-bigtable-v2/pom.xml +++ b/grpc-google-cloud-bigtable-v2/pom.xml @@ -4,14 +4,34 @@ 4.0.0 com.google.api.grpc grpc-google-cloud-bigtable-v2 - 1.8.0 + 1.9.0 grpc-google-cloud-bigtable-v2 GRPC library for grpc-google-cloud-bigtable-v2 com.google.cloud google-cloud-bigtable-parent - 1.8.0 + 1.9.0 + + + + + com.google.cloud + google-cloud-bigtable-deps-bom + 1.9.0 + pom + import + + + com.google.cloud + google-cloud-bigtable-bom + 1.9.0 + pom + import + + + + io.grpc diff --git a/pom.xml b/pom.xml index 74f523cd48..eb5bb47598 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ google-cloud-bigtable-parent pom - 1.8.0 + 1.9.0 Google Cloud Bigtable Parent https://github.com/googleapis/java-bigtable @@ -14,7 +14,7 @@ com.google.cloud google-cloud-shared-config - 0.3.0 + 0.3.1 @@ -152,160 +152,17 @@ github google-cloud-bigtable-parent https://googleapis.dev/java/google-api-grpc/latest - - 1.7 - 1.52.0 - 1.8.1 - 1.17.0 - 1.92.0 - - 1.25.0 - 28.1-android - 0.24.0 - 3.11.1 - 1.4.0 - - - com.google.api - gax-bom - ${gax.version} - pom - import - - - com.google.guava - guava-bom - ${guava.version} - pom - import - - - io.grpc - grpc-bom - ${grpc.version} - pom - import - - - - - com.google.cloud - google-cloud-bigtable-emulator - 0.117.0 - - - com.google.api.grpc - grpc-google-cloud-bigtable-admin-v2 - 1.8.0 - - - com.google.api.grpc - grpc-google-cloud-bigtable-v2 - 1.8.0 - - - com.google.api.grpc - proto-google-cloud-bigtable-admin-v2 - 1.8.0 - - - com.google.api.grpc - proto-google-cloud-bigtable-v2 - 1.8.0 - - - - - com.google.api - api-common - ${google.api-common.version} - - - com.google.api.grpc - proto-google-common-protos - ${google.common-protos.version} - - - com.google.api.grpc - proto-google-iam-v1 - 0.13.0 - - - com.google.auto.value - auto-value - ${autovalue.version} - - - com.google.auto.value - auto-value-annotations - ${autovalue.version} - - - com.google.cloud - google-cloud-core - ${google.core.version} - - - com.google.cloud - google-cloud-core-grpc - ${google.core.version} - - - com.google.errorprone - error_prone_annotations - 2.3.4 - - - com.google.code.findbugs - jsr305 - 3.0.2 - - - com.google.protobuf - protobuf-java - ${protobuf.version} - - - com.google.protobuf - protobuf-java-util - ${protobuf.version} - - - io.opencensus - opencensus-api - ${opencensus.version} - - - javax.annotation - javax.annotation-api - 1.3.2 - - - org.codehaus.mojo - animal-sniffer-annotations - 1.18 - - - org.threeten - threetenbp - ${threeten.version} - + - - com.google.api - gax-grpc - ${gax.version} - testlib - com.google.cloud google-cloud-conformance-tests - 0.0.2 + 0.0.3 + 1.9.0 proto-google-cloud-bigtable-admin-v2 PROTO library for proto-google-cloud-bigtable-admin-v2 com.google.cloud google-cloud-bigtable-parent - 1.8.0 + 1.9.0 + + + + + com.google.cloud + google-cloud-bigtable-deps-bom + 1.9.0 + pom + import + + + com.google.cloud + google-cloud-bigtable-bom + 1.9.0 + pom + import + + + + com.google.api diff --git a/proto-google-cloud-bigtable-v2/pom.xml b/proto-google-cloud-bigtable-v2/pom.xml index f90922a231..96e35de190 100644 --- a/proto-google-cloud-bigtable-v2/pom.xml +++ b/proto-google-cloud-bigtable-v2/pom.xml @@ -4,14 +4,34 @@ 4.0.0 com.google.api.grpc proto-google-cloud-bigtable-v2 - 1.8.0 + 1.9.0 proto-google-cloud-bigtable-v2 PROTO library for proto-google-cloud-bigtable-v2 com.google.cloud google-cloud-bigtable-parent - 1.8.0 + 1.9.0 + + + + + com.google.cloud + google-cloud-bigtable-deps-bom + 1.9.0 + pom + import + + + com.google.cloud + google-cloud-bigtable-bom + 1.9.0 + pom + import + + + + com.google.api diff --git a/renovate.json b/renovate.json index 9981047003..d014232c57 100644 --- a/renovate.json +++ b/renovate.json @@ -1,27 +1,58 @@ { "extends": [ - "config:base" + ":separateMajorReleases", + ":combinePatchMinorReleases", + ":ignoreUnstable", + ":prImmediately", + ":updateNotScheduled", + ":automergeDisabled", + ":ignoreModulesAndTests", + ":maintainLockFilesDisabled", + ":autodetectPinVersions" ], - "ignoreDeps": [], "packageRules": [ { - "managers": ["maven"], - "packageNames": ["com.google.guava:guava*"], + "packagePatterns": [ + "^com.google.guava:" + ], "versionScheme": "docker" }, { - "packagePatterns": ["^io.grpc:grpc-"], - "groupName": "gRPC packages" + "packagePatterns": [ + "^com.google.api:gax", + "^com.google.auth:", + "^com.google.cloud:google-cloud-core", + "^io.grpc:" + ], + "groupName": "core dependencies" }, { - "packagePatterns": ["^com.google.protobuf:protobuf-"], - "groupName": "Protobuf packages" + "packagePatterns": [ + "^com.google.http-client:", + "^com.google.oauth-client:", + "^com.google.api-client:" + ], + "groupName": "core transport dependencies" }, { - "packagePatterns": ["^io.opencensus:opencensus-"], - "groupName": "OpenCensus packages" + "packagePatterns": [ + "*" + ], + "semanticCommitType": "deps", + "semanticCommitScope": null + }, + { + "packagePatterns": [ + "^org.apache.maven", + "^org.jacoco:", + "^org.codehaus.mojo:", + "^org.sonatype.plugins:", + "^com.coveo:", + "^com.google.cloud:google-cloud-shared-config" + ], + "semanticCommitType": "build", + "semanticCommitScope": "deps" } ], - "semanticCommits": true, - "semanticCommitType": "deps" + "semanticCommits": true } diff --git a/versions.txt b/versions.txt index ea5b102db2..4f7ec7b94a 100644 --- a/versions.txt +++ b/versions.txt @@ -1,9 +1,9 @@ # Format: # module:released-version:current-version -google-cloud-bigtable:1.8.0:1.8.0 -grpc-google-cloud-bigtable-admin-v2:1.8.0:1.8.0 -grpc-google-cloud-bigtable-v2:1.8.0:1.8.0 -proto-google-cloud-bigtable-admin-v2:1.8.0:1.8.0 -proto-google-cloud-bigtable-v2:1.8.0:1.8.0 -google-cloud-bigtable-emulator:0.117.0:0.117.0 +google-cloud-bigtable:1.9.0:1.9.0 +grpc-google-cloud-bigtable-admin-v2:1.9.0:1.9.0 +grpc-google-cloud-bigtable-v2:1.9.0:1.9.0 +proto-google-cloud-bigtable-admin-v2:1.9.0:1.9.0 +proto-google-cloud-bigtable-v2:1.9.0:1.9.0 +google-cloud-bigtable-emulator:0.118.0:0.118.0