Skip to content

Commit d424878

Browse files
urandom2pongad
authored andcommitted
---
yaml --- r: 9789 b: refs/heads/mrschmidt-options c: 170f1e5 h: refs/heads/master i: 9787: a4f9450
1 parent 88738c0 commit d424878

4 files changed

Lines changed: 23 additions & 131 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ refs/tags/v0.45.0: 4b4eb52d0823f5335cb8acf54a88bae199e013ae
9595
refs/tags/v0.46.0: 40dfc83a11b2cf2c21bf0f5a7b1e47087cbf0259
9696
refs/tags/0.47.0: 2e8688416bcae6150c0fa59936103554dbbe3821
9797
refs/heads/mrschmidt-core-timestamps: 19c1eca95467e588c21378cae2b136d14973d532
98-
refs/heads/mrschmidt-options: 6668cd1240786fa052a9723324dfc0178ce33047
98+
refs/heads/mrschmidt-options: 170f1e52162053f5a567bae89be9db0e59974be8
9999
refs/heads/mrschmidt-timestamps: 1d1a2c248168fed01a3a03bd5907f40667f53ae0
100100
refs/tags/v0.48.0: 94a4b5648607953030555908d301c57e79c5afca
101101
refs/tags/v0.49.0: 6f75996bb3386bd4dac3d796497b10d24507ccd3

branches/mrschmidt-options/google-cloud-clients/google-cloud-core/src/main/java/com/google/cloud/MetadataConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static String getClusterName() {
5757
return getAttribute("instance/attributes/cluster-name");
5858
}
5959

60-
private static String getAttribute(String attributeName) {
60+
public static String getAttribute(String attributeName) {
6161
try {
6262
URL url = new URL(METADATA_URL + attributeName);
6363
HttpURLConnection connection = (HttpURLConnection) url.openConnection();

branches/mrschmidt-options/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreOptions.java

Lines changed: 15 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
package com.google.cloud.firestore;
1818

1919
import com.google.api.core.InternalApi;
20-
import com.google.api.gax.core.CredentialsProvider;
21-
import com.google.api.gax.core.GoogleCredentialsProvider;
22-
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
23-
import com.google.api.gax.rpc.TransportChannelProvider;
2420
import com.google.cloud.ServiceDefaults;
2521
import com.google.cloud.ServiceOptions;
2622
import com.google.cloud.TransportOptions;
@@ -30,7 +26,6 @@
3026
import com.google.cloud.grpc.GrpcTransportOptions;
3127
import com.google.common.collect.ImmutableSet;
3228
import java.io.IOException;
33-
import java.util.Objects;
3429
import java.util.Set;
3530
import javax.annotation.Nonnull;
3631

@@ -43,12 +38,11 @@ public final class FirestoreOptions extends ServiceOptions<Firestore, FirestoreO
4338
.add("https://www.googleapis.com/auth/cloud-platform")
4439
.add("https://www.googleapis.com/auth/datastore")
4540
.build();
46-
47-
private static final long serialVersionUID = -5853552236134770089L;
41+
private static final String DEFAULT_HOST = FirestoreSettings.getDefaultEndpoint();
42+
private static final String DEFAULT_DATABASE_ID = "(default)";
43+
private static final long serialVersionUID = -5853552236134770088L;
4844

4945
private final String databaseId;
50-
private final TransportChannelProvider channelProvider;
51-
private final CredentialsProvider credentialsProvider;
5246

5347
public static class DefaultFirestoreFactory implements FirestoreFactory {
5448

@@ -88,129 +82,53 @@ protected boolean projectIdRequired() {
8882

8983
@Override
9084
protected String getDefaultHost() {
91-
return FirestoreDefaults.INSTANCE.getHost();
85+
return DEFAULT_HOST;
9286
}
9387

9488
public String getDatabaseId() {
9589
return databaseId;
9690
}
9791

98-
public CredentialsProvider getCredentialsProvider() {
99-
return credentialsProvider;
100-
}
101-
102-
public TransportChannelProvider getTransportChannelProvider() {
103-
return channelProvider;
104-
}
105-
10692
public static class Builder extends ServiceOptions.Builder<Firestore, FirestoreOptions, Builder> {
10793

108-
private String databaseId = FirestoreDefaults.INSTANCE.getDatabaseId();
109-
private TransportChannelProvider channelProvider =
110-
FirestoreDefaults.INSTANCE.getDefaultTransportChannelProvider();
111-
private CredentialsProvider credentialsProvider =
112-
FirestoreDefaults.INSTANCE.getDefaultCredentialsProvider();
94+
private String databaseId = DEFAULT_DATABASE_ID;
11395

11496
private Builder() {}
11597

11698
private Builder(FirestoreOptions options) {
11799
super(options);
118-
this.databaseId = options.databaseId;
119-
this.channelProvider = options.channelProvider;
120-
this.credentialsProvider = options.credentialsProvider;
121100
}
122101

123-
/**
124-
* Sets the {@link TransportOptions} to use with this Firestore client.
125-
*
126-
* @param transportOptions A GrpcTransportOptions object that defines the transport options for
127-
* this client.
128-
*/
129102
@Nonnull
130103
@Override
131104
public Builder setTransportOptions(@Nonnull TransportOptions transportOptions) {
132105
if (!(transportOptions instanceof GrpcTransportOptions)) {
133106
throw new IllegalArgumentException(
134-
"Only GRPC transport is allowed for " + API_SHORT_NAME + ".");
107+
"Only grpc transport is allowed for " + API_SHORT_NAME + ".");
135108
}
136109
return super.setTransportOptions(transportOptions);
137110
}
138111

139-
/**
140-
* Sets the {@link TransportChannelProvider} to use with this Firestore client.
141-
*
142-
* @param channelProvider A InstantiatingGrpcChannelProvider object that defines the transport
143-
* provider for this client.
144-
*/
145-
@Nonnull
146-
public Builder setChannelProvider(@Nonnull TransportChannelProvider channelProvider) {
147-
if (!(channelProvider instanceof InstantiatingGrpcChannelProvider)) {
148-
throw new IllegalArgumentException(
149-
"Only GRPC channels are allowed for " + API_SHORT_NAME + ".");
150-
}
151-
this.channelProvider = channelProvider;
152-
return this;
153-
}
154-
155-
/**
156-
* Sets the {@link CredentialsProvider} to use with this Firestore client.
157-
*
158-
* @param credentialsProvider A CredentialsProvider object that defines the credential provider
159-
* for this client.
160-
*/
112+
@Override
161113
@Nonnull
162-
public Builder setCredentialsProvider(@Nonnull CredentialsProvider credentialsProvider) {
163-
this.credentialsProvider = credentialsProvider;
164-
return this;
114+
public FirestoreOptions build() {
115+
return new FirestoreOptions(this);
165116
}
166117

167-
/**
168-
* Sets the database ID to use with this Firestore client.
169-
*
170-
* @param databaseId The Firestore database ID to use with this client.
171-
*/
172118
public Builder setDatabaseId(String databaseId) {
173119
this.databaseId = databaseId;
174120
return this;
175121
}
176-
177-
@Override
178-
@Nonnull
179-
public FirestoreOptions build() {
180-
return new FirestoreOptions(this);
181-
}
182122
}
183123

184124
@InternalApi("This class should only be extended within google-cloud-java")
185125
protected FirestoreOptions(Builder builder) {
186126
super(FirestoreFactory.class, FirestoreRpcFactory.class, builder, new FirestoreDefaults());
187127

188128
this.databaseId = builder.databaseId;
189-
this.channelProvider = builder.channelProvider;
190-
this.credentialsProvider = builder.credentialsProvider;
191129
}
192130

193131
private static class FirestoreDefaults implements ServiceDefaults<Firestore, FirestoreOptions> {
194-
private static final FirestoreDefaults INSTANCE = new FirestoreDefaults();
195-
196-
private final String HOST = FirestoreSettings.getDefaultEndpoint();
197-
private final String DATABASE_ID = "(default)";
198-
private final TransportOptions TRANSPORT_OPTIONS =
199-
getDefaultTransportOptionsBuilder().build();
200-
private final TransportChannelProvider CHANNEL_PROVIDER =
201-
getDefaultTransportChannelProviderBuilder().build();
202-
private final CredentialsProvider CREDENTIALS_PROVIDER =
203-
getDefaultCredentialsProviderBuilder().build();
204-
205-
@Nonnull
206-
String getHost() {
207-
return HOST;
208-
}
209-
210-
@Nonnull
211-
String getDatabaseId() {
212-
return DATABASE_ID;
213-
}
214132

215133
@Nonnull
216134
@Override
@@ -227,34 +145,13 @@ public FirestoreRpcFactory getDefaultRpcFactory() {
227145
@Nonnull
228146
@Override
229147
public TransportOptions getDefaultTransportOptions() {
230-
return TRANSPORT_OPTIONS;
148+
return getDefaultGrpcTransportOptions();
231149
}
232-
233-
@Nonnull
234-
TransportChannelProvider getDefaultTransportChannelProvider() {
235-
return CHANNEL_PROVIDER;
236-
}
237-
238-
@Nonnull
239-
CredentialsProvider getDefaultCredentialsProvider() {
240-
return CREDENTIALS_PROVIDER;
241-
}
242-
}
243-
244-
@Nonnull
245-
public static GrpcTransportOptions.Builder getDefaultTransportOptionsBuilder() {
246-
return GrpcTransportOptions.newBuilder();
247150
}
248151

249152
@Nonnull
250-
public static InstantiatingGrpcChannelProvider.Builder
251-
getDefaultTransportChannelProviderBuilder() {
252-
return FirestoreSettings.defaultGrpcTransportProviderBuilder();
253-
}
254-
255-
@Nonnull
256-
public static GoogleCredentialsProvider.Builder getDefaultCredentialsProviderBuilder() {
257-
return FirestoreSettings.defaultCredentialsProviderBuilder();
153+
public static GrpcTransportOptions getDefaultGrpcTransportOptions() {
154+
return GrpcTransportOptions.newBuilder().build();
258155
}
259156

260157
@Override
@@ -267,22 +164,13 @@ FirestoreRpc getFirestoreRpc() {
267164
}
268165

269166
@Override
270-
public boolean equals(Object o) {
271-
if (this == o) {
272-
return true;
273-
}
274-
if (o == null || getClass() != o.getClass()) {
275-
return false;
276-
}
277-
FirestoreOptions that = (FirestoreOptions) o;
278-
return Objects.equals(databaseId, that.databaseId)
279-
&& Objects.equals(channelProvider, that.channelProvider)
280-
&& baseEquals(that);
167+
public boolean equals(Object obj) {
168+
return obj instanceof FirestoreOptions && baseEquals((FirestoreOptions) obj);
281169
}
282170

283171
@Override
284172
public int hashCode() {
285-
return Objects.hash(databaseId, channelProvider, baseHashCode());
173+
return baseHashCode();
286174
}
287175

288176
@Nonnull

branches/mrschmidt-options/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/spi/v1beta1/GrpcFirestoreRpc.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.google.api.gax.core.GaxProperties;
2222
import com.google.api.gax.grpc.GrpcCallContext;
2323
import com.google.api.gax.grpc.GrpcTransportChannel;
24+
import com.google.api.gax.rpc.ApiClientHeaderProvider;
2425
import com.google.api.gax.rpc.BidiStreamingCallable;
2526
import com.google.api.gax.rpc.ClientContext;
2627
import com.google.api.gax.rpc.HeaderProvider;
@@ -104,8 +105,11 @@ public GrpcFirestoreRpc(final FirestoreOptions options) throws IOException {
104105
DatabaseRootName databaseName =
105106
DatabaseRootName.of(options.getProjectId(), options.getDatabaseId());
106107

107-
settingsBuilder.setCredentialsProvider(options.getCredentialsProvider());
108-
settingsBuilder.setTransportChannelProvider(options.getTransportChannelProvider());
108+
settingsBuilder.setCredentialsProvider(
109+
GrpcTransportOptions.setUpCredentialsProvider(options));
110+
settingsBuilder.setTransportChannelProvider(
111+
GrpcTransportOptions.setUpChannelProvider(
112+
FirestoreSettings.defaultGrpcTransportProviderBuilder(), options));
109113

110114
HeaderProvider internalHeaderProvider =
111115
FirestoreSettings.defaultApiClientHeaderProviderBuilder()

0 commit comments

Comments
 (0)