From 433a04c1229782085c467ef28f9a730074a13330 Mon Sep 17 00:00:00 2001 From: kolea2 Date: Wed, 24 Jan 2024 11:49:33 -0500 Subject: [PATCH 1/9] feat: allow setting channel and credential providers in DatastoreOptions --- .../cloud/datastore/DatastoreOptions.java | 69 ++++++++++++++++++- .../cloud/datastore/DatastoreUtils.java | 6 ++ .../datastore/spi/v1/GrpcDatastoreRpc.java | 17 +---- .../cloud/datastore/DatastoreOptionsTest.java | 32 +++++++++ 4 files changed, 108 insertions(+), 16 deletions(-) diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java index c94e9ff7a..5802289cb 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java @@ -18,6 +18,9 @@ import static com.google.cloud.datastore.Validator.validateNamespace; +import com.google.api.gax.core.CredentialsProvider; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.rpc.TransportChannelProvider; import com.google.cloud.ServiceDefaults; import com.google.cloud.ServiceOptions; import com.google.cloud.ServiceRpc; @@ -46,6 +49,9 @@ public class DatastoreOptions extends ServiceOptions { + private final TransportOptions TRANSPORT_OPTIONS = getDefaultTransportOptionsBuilder().build(); @Override public DatastoreFactory getDefaultServiceFactory() { @@ -147,7 +207,11 @@ public DatastoreRpcFactory getDefaultRpcFactory() { @Override public TransportOptions getDefaultTransportOptions() { - return getDefaultGrpcTransportOptions(); + return TRANSPORT_OPTIONS; + } + + public static GrpcTransportOptions.Builder getDefaultTransportOptionsBuilder() { + return GrpcTransportOptions.newBuilder(); } } @@ -202,7 +266,7 @@ public Builder toBuilder() { @Override public int hashCode() { - return Objects.hash(baseHashCode(), namespace, databaseId); + return Objects.hash(baseHashCode(), namespace, databaseId, channelProvider); } @Override @@ -213,6 +277,7 @@ public boolean equals(Object obj) { DatastoreOptions other = (DatastoreOptions) obj; return baseEquals(other) && Objects.equals(namespace, other.namespace) + && Objects.equals(channelProvider, other.channelProvider) && Objects.equals(databaseId, other.databaseId); } diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreUtils.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreUtils.java index ae1c7e07d..7ca92872f 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreUtils.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreUtils.java @@ -17,6 +17,7 @@ package com.google.cloud.datastore; import com.google.api.core.InternalApi; +import com.google.cloud.NoCredentials; import com.google.common.base.Strings; import java.net.InetAddress; import java.net.URL; @@ -24,6 +25,11 @@ @InternalApi public class DatastoreUtils { + public static boolean isEmulator(DatastoreOptions datastoreOptions) { + return isLocalHost(datastoreOptions.getHost()) + || NoCredentials.getInstance().equals(datastoreOptions.getCredentials()); + } + public static boolean isLocalHost(String host) { if (Strings.isNullOrEmpty(host)) { return false; diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/spi/v1/GrpcDatastoreRpc.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/spi/v1/GrpcDatastoreRpc.java index ffcab0560..3d9aebc68 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/spi/v1/GrpcDatastoreRpc.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/spi/v1/GrpcDatastoreRpc.java @@ -16,7 +16,7 @@ package com.google.cloud.datastore.spi.v1; -import static com.google.cloud.datastore.DatastoreUtils.isLocalHost; +import static com.google.cloud.datastore.DatastoreUtils.isEmulator; import static com.google.cloud.datastore.DatastoreUtils.removeScheme; import static com.google.cloud.datastore.spi.v1.RpcUtils.retrySettingSetter; import static java.util.concurrent.TimeUnit.SECONDS; @@ -30,14 +30,12 @@ import com.google.api.gax.rpc.HeaderProvider; import com.google.api.gax.rpc.NoHeaderProvider; import com.google.api.gax.rpc.TransportChannel; -import com.google.cloud.NoCredentials; import com.google.cloud.ServiceOptions; import com.google.cloud.datastore.DatastoreException; import com.google.cloud.datastore.DatastoreOptions; import com.google.cloud.datastore.v1.DatastoreSettings; import com.google.cloud.datastore.v1.stub.DatastoreStubSettings; import com.google.cloud.datastore.v1.stub.GrpcDatastoreStub; -import com.google.cloud.grpc.GrpcTransportOptions; import com.google.common.base.Strings; import com.google.datastore.v1.AllocateIdsRequest; import com.google.datastore.v1.AllocateIdsResponse; @@ -69,7 +67,6 @@ public class GrpcDatastoreRpc implements DatastoreRpc { private boolean closed; public GrpcDatastoreRpc(DatastoreOptions datastoreOptions) throws IOException { - try { clientContext = isEmulator(datastoreOptions) @@ -146,11 +143,6 @@ public boolean isClosed() { return closed && datastoreStub.isShutdown(); } - private boolean isEmulator(DatastoreOptions datastoreOptions) { - return isLocalHost(datastoreOptions.getHost()) - || NoCredentials.getInstance().equals(datastoreOptions.getCredentials()); - } - private ClientContext getClientContextForEmulator(DatastoreOptions datastoreOptions) throws IOException { ManagedChannel managedChannel = @@ -177,11 +169,8 @@ private ClientContext getClientContext(DatastoreOptions datastoreOptions) throws DatastoreSettingsBuilder settingsBuilder = new DatastoreSettingsBuilder(DatastoreSettings.newBuilder().build()); - settingsBuilder.setCredentialsProvider( - GrpcTransportOptions.setUpCredentialsProvider(datastoreOptions)); - settingsBuilder.setTransportChannelProvider( - GrpcTransportOptions.setUpChannelProvider( - DatastoreSettings.defaultGrpcTransportProviderBuilder(), datastoreOptions)); + settingsBuilder.setCredentialsProvider(datastoreOptions.getCredentialsProvider()); + settingsBuilder.setTransportChannelProvider(datastoreOptions.getTransportChannelProvider()); settingsBuilder.setInternalHeaderProvider(internalHeaderProvider); settingsBuilder.setHeaderProvider( datastoreOptions.getMergedHeaderProvider(new NoHeaderProvider())); diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreOptionsTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreOptionsTest.java index 6281befe6..ebabf8568 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreOptionsTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreOptionsTest.java @@ -22,8 +22,13 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.grpc.ChannelPoolSettings; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.cloud.NoCredentials; import com.google.cloud.datastore.spi.DatastoreRpcFactory; import com.google.cloud.datastore.spi.v1.DatastoreRpc; +import com.google.cloud.datastore.v1.DatastoreSettings; import com.google.cloud.grpc.GrpcTransportOptions; import com.google.cloud.http.HttpTransportOptions; import org.easymock.EasyMock; @@ -38,6 +43,16 @@ public class DatastoreOptionsTest { private DatastoreRpcFactory datastoreRpcFactory; private DatastoreRpc datastoreRpc; private DatastoreOptions.Builder options; + private DatastoreOptions.Builder options2; + private final InstantiatingGrpcChannelProvider channelProvider = + DatastoreSettings.defaultGrpcTransportProviderBuilder() + .setChannelPoolSettings( + ChannelPoolSettings.builder() + .setInitialChannelCount(10) + .setMaxChannelCount(20) + .build()) + .build(); + private final NoCredentialsProvider noCredentialsProvider = NoCredentialsProvider.create(); @Before public void setUp() { @@ -48,6 +63,16 @@ public void setUp() { .setServiceRpcFactory(datastoreRpcFactory) .setProjectId(PROJECT_ID) .setDatabaseId(DATABASE_ID) + .setCredentials(NoCredentials.getInstance()) + .setHost("http://localhost:" + PORT); + + options2 = + DatastoreOptions.newBuilder() + .setServiceRpcFactory(datastoreRpcFactory) + .setProjectId(PROJECT_ID) + .setDatabaseId(DATABASE_ID) + .setChannelProvider(channelProvider) + .setCredentialsProvider(noCredentialsProvider) .setHost("http://localhost:" + PORT); EasyMock.expect(datastoreRpcFactory.create(EasyMock.anyObject(DatastoreOptions.class))) .andReturn(datastoreRpc) @@ -81,6 +106,13 @@ public void testDatastore() { assertSame(datastoreRpc, options.build().getRpc()); } + @Test + public void testCustomChannelAndCredentials() { + DatastoreOptions datastoreOptions = options2.build(); + assertEquals(datastoreOptions.getTransportChannelProvider(), channelProvider); + assertEquals(datastoreOptions.getCredentialsProvider(), noCredentialsProvider); + } + @Test public void testTransport() { // default grpc transport From 0ebc7c8f51cf5e4d9ad1434f5271c8fe0a605688 Mon Sep 17 00:00:00 2001 From: kolea2 Date: Wed, 24 Jan 2024 12:04:00 -0500 Subject: [PATCH 2/9] add additional validation and test --- .../cloud/datastore/DatastoreOptions.java | 27 ++++++++++++------- .../cloud/datastore/DatastoreOptionsTest.java | 15 +++++++++++ 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java index 5802289cb..80157d8e2 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java @@ -160,16 +160,23 @@ private DatastoreOptions(Builder builder) { namespace = MoreObjects.firstNonNull(builder.namespace, defaultNamespace()); databaseId = MoreObjects.firstNonNull(builder.databaseId, DEFAULT_DATABASE_ID); - this.channelProvider = - builder.channelProvider != null - ? builder.channelProvider - : GrpcTransportOptions.setUpChannelProvider( - DatastoreSettings.defaultGrpcTransportProviderBuilder(), this); - - this.credentialsProvider = - builder.credentialsProvider != null - ? builder.credentialsProvider - : GrpcTransportOptions.setUpCredentialsProvider(this); + // todo see if we can update this + if (getTransportOptions() instanceof HttpTransportOptions + && (builder.channelProvider != null || builder.credentialsProvider != null)) { + throw new IllegalArgumentException( + "Only gRPC transport allows setting of channel provider or credentials provider"); + } else { + this.channelProvider = + builder.channelProvider != null + ? builder.channelProvider + : GrpcTransportOptions.setUpChannelProvider( + DatastoreSettings.defaultGrpcTransportProviderBuilder(), this); + + this.credentialsProvider = + builder.credentialsProvider != null + ? builder.credentialsProvider + : GrpcTransportOptions.setUpCredentialsProvider(this); + } } public CredentialsProvider getCredentialsProvider() { diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreOptionsTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreOptionsTest.java index ebabf8568..72e561c03 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreOptionsTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreOptionsTest.java @@ -32,6 +32,7 @@ import com.google.cloud.grpc.GrpcTransportOptions; import com.google.cloud.http.HttpTransportOptions; import org.easymock.EasyMock; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -113,6 +114,20 @@ public void testCustomChannelAndCredentials() { assertEquals(datastoreOptions.getCredentialsProvider(), noCredentialsProvider); } + @Test + public void testInvalidConfigForHttp() { + DatastoreOptions.Builder options = + DatastoreOptions.newBuilder() + .setServiceRpcFactory(datastoreRpcFactory) + .setProjectId(PROJECT_ID) + .setDatabaseId(DATABASE_ID) + .setTransportOptions(HttpTransportOptions.newBuilder().build()) + .setChannelProvider(channelProvider) + .setCredentialsProvider(noCredentialsProvider) + .setHost("http://localhost:" + PORT); + Assert.assertThrows(IllegalArgumentException.class, options::build); + } + @Test public void testTransport() { // default grpc transport From 5e9ce7dee50642635020a4908818f582de9a087d Mon Sep 17 00:00:00 2001 From: kolea2 Date: Tue, 30 Jan 2024 13:39:32 -0500 Subject: [PATCH 3/9] mark new fields as transient --- .../com/google/cloud/datastore/DatastoreOptions.java | 4 ++-- .../com/google/cloud/datastore/SerializationTest.java | 10 +--------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java index 80157d8e2..7ed0a55f0 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java @@ -49,8 +49,8 @@ public class DatastoreOptions extends ServiceOptions Date: Tue, 30 Jan 2024 18:46:59 +0000 Subject: [PATCH 4/9] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20po?= =?UTF-8?q?st-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 8 ++++---- .../com/google/cloud/datastore/SerializationTest.java | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 024f41511..04d343685 100644 --- a/README.md +++ b/README.md @@ -50,20 +50,20 @@ If you are using Maven without the BOM, add this to your dependencies: If you are using Gradle 5.x or later, add this to your dependencies: ```Groovy -implementation platform('com.google.cloud:libraries-bom:26.29.0') +implementation platform('com.google.cloud:libraries-bom:26.31.0') implementation 'com.google.cloud:google-cloud-datastore' ``` If you are using Gradle without BOM, add this to your dependencies: ```Groovy -implementation 'com.google.cloud:google-cloud-datastore:2.18.0' +implementation 'com.google.cloud:google-cloud-datastore:2.18.2' ``` If you are using SBT, add this to your dependencies: ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-datastore" % "2.18.0" +libraryDependencies += "com.google.cloud" % "google-cloud-datastore" % "2.18.2" ``` @@ -380,7 +380,7 @@ Java is a registered trademark of Oracle and/or its affiliates. [kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-datastore/java11.html [stability-image]: https://img.shields.io/badge/stability-stable-green [maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-datastore.svg -[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-datastore/2.18.0 +[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-datastore/2.18.2 [authentication]: https://github.com/googleapis/google-cloud-java#authentication [auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes [predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/SerializationTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/SerializationTest.java index 555fbf3f6..85d0d0bae 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/SerializationTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/SerializationTest.java @@ -19,7 +19,6 @@ import static java.nio.charset.StandardCharsets.UTF_8; import com.google.cloud.BaseSerializationTest; -import com.google.cloud.NoCredentials; import com.google.cloud.Restorable; import com.google.cloud.Timestamp; import com.google.cloud.datastore.StructuredQuery.CompositeFilter; From 8ead3931908876ecd0413a19335626906196c901 Mon Sep 17 00:00:00 2001 From: kolea2 Date: Thu, 1 Feb 2024 11:35:25 -0500 Subject: [PATCH 5/9] update test --- .../com/google/cloud/datastore/DatastoreOptions.java | 3 +-- .../com/google/cloud/datastore/SerializationTest.java | 11 ++++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java index 7ed0a55f0..c13484c05 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java @@ -273,7 +273,7 @@ public Builder toBuilder() { @Override public int hashCode() { - return Objects.hash(baseHashCode(), namespace, databaseId, channelProvider); + return Objects.hash(baseHashCode(), namespace, databaseId); } @Override @@ -284,7 +284,6 @@ public boolean equals(Object obj) { DatastoreOptions other = (DatastoreOptions) obj; return baseEquals(other) && Objects.equals(namespace, other.namespace) - && Objects.equals(channelProvider, other.channelProvider) && Objects.equals(databaseId, other.databaseId); } diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/SerializationTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/SerializationTest.java index 85d0d0bae..1b8186a54 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/SerializationTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/SerializationTest.java @@ -19,6 +19,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import com.google.cloud.BaseSerializationTest; +import com.google.cloud.NoCredentials; import com.google.cloud.Restorable; import com.google.cloud.Timestamp; import com.google.cloud.datastore.StructuredQuery.CompositeFilter; @@ -124,6 +125,12 @@ public class SerializationTest extends BaseSerializationTest { @Override protected java.io.Serializable[] serializableObjects() { + DatastoreOptions options = + DatastoreOptions.newBuilder() + .setCredentials(NoCredentials.getInstance()) + .setProjectId("ds1") + .build(); + DatastoreOptions otherOptions = options.toBuilder().setNamespace("ns1").build(); return new java.io.Serializable[] { KEY1, KEY2, @@ -157,7 +164,9 @@ protected java.io.Serializable[] serializableObjects() { BLOB_VALUE, RAW_VALUE, LAT_LNG_VALUE, - DATASTORE_EXCEPTION + DATASTORE_EXCEPTION, + options, + otherOptions }; } From f11f0bc7d53987ab644b89e3c5e7302813dafb95 Mon Sep 17 00:00:00 2001 From: kolea2 Date: Mon, 5 Feb 2024 13:39:54 -0500 Subject: [PATCH 6/9] review feedback --- .../cloud/datastore/DatastoreOptions.java | 10 ++-- .../cloud/datastore/DatastoreOptionsTest.java | 50 +++++++++++-------- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java index c13484c05..672a1ee0b 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java @@ -49,8 +49,8 @@ public class DatastoreOptions extends ServiceOptions Date: Tue, 6 Feb 2024 15:59:23 +0000 Subject: [PATCH 7/9] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20po?= =?UTF-8?q?st-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 04d343685..e4f708557 100644 --- a/README.md +++ b/README.md @@ -57,13 +57,13 @@ implementation 'com.google.cloud:google-cloud-datastore' If you are using Gradle without BOM, add this to your dependencies: ```Groovy -implementation 'com.google.cloud:google-cloud-datastore:2.18.2' +implementation 'com.google.cloud:google-cloud-datastore:2.18.3' ``` If you are using SBT, add this to your dependencies: ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-datastore" % "2.18.2" +libraryDependencies += "com.google.cloud" % "google-cloud-datastore" % "2.18.3" ``` @@ -380,7 +380,7 @@ Java is a registered trademark of Oracle and/or its affiliates. [kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-datastore/java11.html [stability-image]: https://img.shields.io/badge/stability-stable-green [maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-datastore.svg -[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-datastore/2.18.2 +[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-datastore/2.18.3 [authentication]: https://github.com/googleapis/google-cloud-java#authentication [auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes [predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles From cd6505a6f6b17d40998dacc41dfeb5da55dc85c3 Mon Sep 17 00:00:00 2001 From: kolea2 Date: Tue, 6 Feb 2024 13:18:28 -0500 Subject: [PATCH 8/9] review feedback --- .../google/cloud/datastore/DatastoreOptions.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java index 672a1ee0b..569defad6 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java @@ -103,7 +103,7 @@ private Builder(DatastoreOptions options) { super(options); this.namespace = options.namespace; this.databaseId = options.databaseId; - this.channelProvider = options.channelProvider; + this.channelProvider = validateChannelProvider(options.channelProvider); this.credentialsProvider = options.credentialsProvider; } @@ -119,11 +119,7 @@ public Builder setTransportOptions(TransportOptions transportOptions) { * provider for this client. */ public Builder setChannelProvider(TransportChannelProvider channelProvider) { - if (!(channelProvider instanceof InstantiatingGrpcChannelProvider)) { - throw new IllegalArgumentException( - "Only GRPC channels are allowed for " + API_SHORT_NAME + "."); - } - this.channelProvider = channelProvider; + this.channelProvider = validateChannelProvider(channelProvider); return this; } @@ -155,6 +151,14 @@ public Builder setDatabaseId(String databaseId) { } } + private static TransportChannelProvider validateChannelProvider(TransportChannelProvider channelProvider) { + if (!(channelProvider instanceof InstantiatingGrpcChannelProvider)) { + throw new IllegalArgumentException( + "Only GRPC channels are allowed for " + API_SHORT_NAME + "."); + } + return channelProvider; + } + private DatastoreOptions(Builder builder) { super(DatastoreFactory.class, DatastoreRpcFactory.class, builder, new DatastoreDefaults()); namespace = MoreObjects.firstNonNull(builder.namespace, defaultNamespace()); From b53cd72ba3de5c5fbcff2eeed649ea0fb2623628 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Tue, 6 Feb 2024 18:48:58 +0000 Subject: [PATCH 9/9] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20po?= =?UTF-8?q?st-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../main/java/com/google/cloud/datastore/DatastoreOptions.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java index 569defad6..c852fdb7f 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java @@ -151,7 +151,8 @@ public Builder setDatabaseId(String databaseId) { } } - private static TransportChannelProvider validateChannelProvider(TransportChannelProvider channelProvider) { + private static TransportChannelProvider validateChannelProvider( + TransportChannelProvider channelProvider) { if (!(channelProvider instanceof InstantiatingGrpcChannelProvider)) { throw new IllegalArgumentException( "Only GRPC channels are allowed for " + API_SHORT_NAME + ".");