Skip to content

Commit 313bfc6

Browse files
feat: All changes required to change library to use ApiException and gapic internals (#295)
* fix: merge * fix: clirr and samples * fix: deps * fix: deps again * fix: deflake * fix: Fix endpoints to add TLS port. * fix: Fix PublisherSettings * fix: Change PartitionPublisherFactory to only take a partition * fix: Fix ProducerSettings to compile * fix: Fix PublisherOptions to compile and reformat * fix: Reformat and document * fix: Compile issue * fix: Assorted changes * fix: rollback accidental gapic changes
1 parent 3f27c86 commit 313bfc6

File tree

166 files changed

+2427
-3154
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+2427
-3154
lines changed

google-cloud-pubsublite/clirr-ignored-differences.xml

+68
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,54 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!-- see http://www.mojohaus.org/clirr-maven-plugin/examples/ignored-differences.html -->
33
<differences>
4+
<!-- GAPIC conversion: remove on next release. -->
5+
<difference>
6+
<differenceType>6001</differenceType>
7+
<className>com/google/cloud/pubsublite/ErrorCodes</className>
8+
<field>*</field>
9+
</difference>
10+
<difference>
11+
<differenceType>7002</differenceType>
12+
<className>com/google/cloud/pubsublite/ErrorCodes</className>
13+
<method>*</method>
14+
</difference>
15+
<difference>
16+
<differenceType>7005</differenceType>
17+
<className>com/google/cloud/pubsublite/ErrorCodes</className>
18+
<method>*</method>
19+
<to>*</to>
20+
</difference>
21+
<difference>
22+
<differenceType>8001</differenceType>
23+
<className>com/google/cloud/pubsublite/Stubs</className>
24+
<method>*</method>
25+
</difference>
26+
<difference>
27+
<differenceType>7002</differenceType>
28+
<className>com/google/cloud/pubsublite/*Settings*</className>
29+
<method>*</method>
30+
</difference>
31+
<difference>
32+
<differenceType>7013</differenceType>
33+
<className>com/google/cloud/pubsublite/*Settings*</className>
34+
<method>*</method>
35+
</difference>
36+
<difference>
37+
<differenceType>7002</differenceType>
38+
<className>com/google/cloud/pubsublite/cloudpubsub/*Settings*</className>
39+
<method>*</method>
40+
</difference>
41+
<difference>
42+
<differenceType>7013</differenceType>
43+
<className>com/google/cloud/pubsublite/cloudpubsub/*Settings*</className>
44+
<method>*</method>
45+
</difference>
446
<!-- Blanket ignored files -->
47+
<difference>
48+
<differenceType>4001</differenceType>
49+
<className>com/google/cloud/pubsublite/internal/**</className>
50+
<to>**</to>
51+
</difference>
552
<difference>
653
<differenceType>5001</differenceType>
754
<className>com/google/cloud/pubsublite/internal/**</className>
@@ -27,6 +74,11 @@
2774
<className>com/google/cloud/pubsublite/internal/**</className>
2875
<method>*</method>
2976
</difference>
77+
<difference>
78+
<differenceType>7004</differenceType>
79+
<className>com/google/cloud/pubsublite/internal/**</className>
80+
<method>*</method>
81+
</difference>
3082
<difference>
3183
<differenceType>7005</differenceType>
3284
<className>com/google/cloud/pubsublite/internal/**</className>
@@ -39,6 +91,11 @@
3991
<method>*</method>
4092
<to>*</to>
4193
</difference>
94+
<difference>
95+
<differenceType>7009</differenceType>
96+
<className>com/google/cloud/pubsublite/internal/**</className>
97+
<method>*</method>
98+
</difference>
4299
<difference>
43100
<differenceType>7011</differenceType>
44101
<className>com/google/cloud/pubsublite/internal/*</className>
@@ -100,12 +157,23 @@
100157
<className>com/google/cloud/pubsublite/cloudpubsub/internal/**</className>
101158
<method>*</method>
102159
</difference>
160+
<difference>
161+
<differenceType>7005</differenceType>
162+
<className>com/google/cloud/pubsublite/cloudpubsub/internal/**</className>
163+
<method>*</method>
164+
<to>*</to>
165+
</difference>
103166
<difference>
104167
<differenceType>7006</differenceType>
105168
<className>com/google/cloud/pubsublite/cloudpubsub/internal/**</className>
106169
<method>*</method>
107170
<to>*</to>
108171
</difference>
172+
<difference>
173+
<differenceType>7009</differenceType>
174+
<className>com/google/cloud/pubsublite/cloudpubsub/internal/**</className>
175+
<method>*</method>
176+
</difference>
109177
<difference>
110178
<differenceType>7011</differenceType>
111179
<className>com/google/cloud/pubsublite/cloudpubsub/internal/**</className>

google-cloud-pubsublite/pom.xml

-17
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@
2323
<groupId>io.grpc</groupId>
2424
<artifactId>grpc-api</artifactId>
2525
</dependency>
26-
<dependency>
27-
<groupId>io.grpc</groupId>
28-
<artifactId>grpc-auth</artifactId>
29-
</dependency>
30-
<dependency>
31-
<groupId>io.grpc</groupId>
32-
<artifactId>grpc-core</artifactId>
33-
</dependency>
3426
<dependency>
3527
<groupId>io.grpc</groupId>
3628
<artifactId>grpc-stub</artifactId>
@@ -94,10 +86,6 @@
9486
<groupId>com.google.auto.value</groupId>
9587
<artifactId>auto-value-annotations</artifactId>
9688
</dependency>
97-
<dependency>
98-
<groupId>com.google.auth</groupId>
99-
<artifactId>google-auth-library-oauth2-http</artifactId>
100-
</dependency>
10189
<dependency>
10290
<groupId>com.google.api.grpc</groupId>
10391
<artifactId>proto-google-common-protos</artifactId>
@@ -135,11 +123,6 @@
135123
<artifactId>mockito-core</artifactId>
136124
<scope>test</scope>
137125
</dependency>
138-
<dependency>
139-
<groupId>io.grpc</groupId>
140-
<artifactId>grpc-testing</artifactId>
141-
<scope>test</scope>
142-
</dependency>
143126
<dependency>
144127
<groupId>junit</groupId>
145128
<artifactId>junit</artifactId>

google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/AdminClient.java

+31-30
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
package com.google.cloud.pubsublite;
1818

1919
import com.google.api.core.ApiFuture;
20+
import com.google.api.gax.rpc.ApiException;
2021
import com.google.cloud.pubsublite.internal.ApiBackgroundResource;
2122
import com.google.cloud.pubsublite.proto.Subscription;
2223
import com.google.cloud.pubsublite.proto.Topic;
2324
import com.google.protobuf.FieldMask;
24-
import io.grpc.StatusException;
2525
import java.util.List;
2626

2727
/** A client for performing Pub/Sub Lite admin operations. */
2828
public interface AdminClient extends ApiBackgroundResource {
29-
static AdminClient create(AdminClientSettings settings) throws StatusException {
29+
static AdminClient create(AdminClientSettings settings) throws ApiException {
3030
return settings.instantiate();
3131
}
3232

@@ -37,35 +37,35 @@ static AdminClient create(AdminClientSettings settings) throws StatusException {
3737
* Create the provided topic if it does not yet exist.
3838
*
3939
* @param topic The topic to create.
40-
* @return A future that will have either an error {@link io.grpc.StatusException} or the topic on
41-
* success.
40+
* @return A future that will have either an error {@link com.google.api.gax.rpc.ApiException} or
41+
* the topic on success.
4242
*/
4343
ApiFuture<Topic> createTopic(Topic topic);
4444

4545
/**
4646
* Get the topic with id {@code id} if it exists.
4747
*
4848
* @param path The path of the topic to retrieve.
49-
* @return A future that will have either an error {@link io.grpc.StatusException} or the topic on
50-
* success.
49+
* @return A future that will have either an error {@link com.google.api.gax.rpc.ApiException} or
50+
* the topic on success.
5151
*/
5252
ApiFuture<Topic> getTopic(TopicPath path);
5353

5454
/**
5555
* Get the partitioning info for the topic with id {@code id} if it exists.
5656
*
5757
* @param path The path of the topic to retrieve.
58-
* @return A future that will have either an error {@link io.grpc.StatusException} or the number
59-
* of topic partitions on success.
58+
* @return A future that will have either an error {@link com.google.api.gax.rpc.ApiException} or
59+
* the number of topic partitions on success.
6060
*/
6161
ApiFuture<Long> getTopicPartitionCount(TopicPath path);
6262

6363
/**
6464
* List all topics for the specified project.
6565
*
6666
* @param path The path of the project to list topics for.
67-
* @return A future that will have either an error {@link io.grpc.StatusException} or the list of
68-
* topic paths on success.
67+
* @return A future that will have either an error {@link com.google.api.gax.rpc.ApiException} or
68+
* the list of topic paths on success.
6969
*/
7070
ApiFuture<List<Topic>> listTopics(LocationPath path);
7171

@@ -74,55 +74,55 @@ static AdminClient create(AdminClientSettings settings) throws StatusException {
7474
*
7575
* @param topic The topic to update.
7676
* @param mask The mask indicating which fields should be updated.
77-
* @return A future that will have either an error {@link io.grpc.StatusException} or the
78-
* resulting topic on success. Updating nonexistent topics will cause the future to have an
79-
* exception with status {@link io.grpc.Status.Code#NOT_FOUND}
77+
* @return A future that will have either an error {@link com.google.api.gax.rpc.ApiException} or
78+
* the resulting topic on success. Updating nonexistent topics will cause the future to have
79+
* an exception with status {@link com.google.api.gax.rpc.StatusCode.Code#NOT_FOUND}
8080
*/
8181
ApiFuture<Topic> updateTopic(Topic topic, FieldMask mask);
8282

8383
/**
8484
* Delete the topic with id {@code id} if it exists.
8585
*
8686
* @param path The path of the topic to retrieve.
87-
* @return A future that will have either an error {@link io.grpc.StatusException} or void on
88-
* success. Deleting nonexistent topics will cause the future to have an exception with status
89-
* {@link io.grpc.Status.Code#NOT_FOUND}
87+
* @return A future that will have either an error {@link com.google.api.gax.rpc.ApiException} or
88+
* void on success. Deleting nonexistent topics will cause the future to have an exception
89+
* with status {@link com.google.api.gax.rpc.StatusCode.Code#NOT_FOUND}
9090
*/
9191
ApiFuture<Void> deleteTopic(TopicPath path);
9292

9393
/**
9494
* Get the list of subscriptions for the topic with id {@code id} if it exists.
9595
*
9696
* @param path The path of the topic to retrieve.
97-
* @return A future that will have either an error {@link io.grpc.StatusException} or the list of
98-
* subscriptions on success.
97+
* @return A future that will have either an error {@link com.google.api.gax.rpc.ApiException} or
98+
* the list of subscriptions on success.
9999
*/
100100
ApiFuture<List<SubscriptionPath>> listTopicSubscriptions(TopicPath path);
101101

102102
/**
103103
* Create the provided subscription if it does not yet exist.
104104
*
105105
* @param subscription The subscription to create.
106-
* @return A future that will have either an error {@link io.grpc.StatusException} or the
107-
* subscription on success.
106+
* @return A future that will have either an error {@link com.google.api.gax.rpc.ApiException} or
107+
* the subscription on success.
108108
*/
109109
ApiFuture<Subscription> createSubscription(Subscription subscription);
110110

111111
/**
112112
* Get the subscription with id {@code id} if it exists.
113113
*
114114
* @param path The path of the subscription to retrieve.
115-
* @return A future that will have either an error {@link io.grpc.StatusException} or the
116-
* subscription on success.
115+
* @return A future that will have either an error {@link com.google.api.gax.rpc.ApiException} or
116+
* the subscription on success.
117117
*/
118118
ApiFuture<Subscription> getSubscription(SubscriptionPath path);
119119

120120
/**
121121
* List all subscriptions for the specified project.
122122
*
123123
* @param path The path of the project to list subscriptions for.
124-
* @return A future that will have either an error {@link io.grpc.StatusException} or the list of
125-
* subscription paths on success.
124+
* @return A future that will have either an error {@link com.google.api.gax.rpc.ApiException} or
125+
* the list of subscription paths on success.
126126
*/
127127
ApiFuture<List<Subscription>> listSubscriptions(LocationPath path);
128128

@@ -131,19 +131,20 @@ static AdminClient create(AdminClientSettings settings) throws StatusException {
131131
*
132132
* @param subscription The subscription to update.
133133
* @param mask The mask indicating which fields should be updated.
134-
* @return A future that will have either an error {@link io.grpc.StatusException} or the
135-
* resulting subscription on success. Updating nonexistent subscriptions will cause the future
136-
* to have an exception with status {@link io.grpc.Status.Code#NOT_FOUND}
134+
* @return A future that will have either an error {@link com.google.api.gax.rpc.ApiException} or
135+
* the resulting subscription on success. Updating nonexistent subscriptions will cause the
136+
* future to have an exception with status {@link
137+
* com.google.api.gax.rpc.StatusCode.Code#NOT_FOUND}
137138
*/
138139
ApiFuture<Subscription> updateSubscription(Subscription subscription, FieldMask mask);
139140

140141
/**
141142
* Delete the subscription with id {@code id} if it exists.
142143
*
143144
* @param path The path of the subscription to retrieve.
144-
* @return A future that will have either an error {@link io.grpc.StatusException} or void on
145-
* success. Deleting nonexistent subscriptions will cause the future to have an exception with
146-
* status {@link io.grpc.Status.Code#NOT_FOUND}
145+
* @return A future that will have either an error {@link com.google.api.gax.rpc.ApiException} or
146+
* void on success. Deleting nonexistent subscriptions will cause the future to have an
147+
* exception with status {@link com.google.api.gax.rpc.StatusCode.Code#NOT_FOUND}
147148
*/
148149
ApiFuture<Void> deleteSubscription(SubscriptionPath path);
149150
}

google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/AdminClientSettings.java

+29-16
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,33 @@
1616

1717
package com.google.cloud.pubsublite;
1818

19+
import static com.google.cloud.pubsublite.internal.ServiceClients.addDefaultSettings;
20+
1921
import com.google.api.gax.retrying.RetrySettings;
22+
import com.google.api.gax.rpc.ApiException;
2023
import com.google.auto.value.AutoValue;
2124
import com.google.cloud.pubsublite.internal.AdminClientImpl;
22-
import com.google.cloud.pubsublite.proto.AdminServiceGrpc;
23-
import com.google.cloud.pubsublite.proto.AdminServiceGrpc.AdminServiceBlockingStub;
24-
import io.grpc.StatusException;
25+
import com.google.cloud.pubsublite.internal.ExtractStatus;
26+
import com.google.cloud.pubsublite.v1.AdminServiceClient;
27+
import com.google.cloud.pubsublite.v1.AdminServiceSettings;
2528
import java.util.Optional;
2629

2730
/** Settings for construction a Pub/Sub Lite AdminClient. */
2831
@AutoValue
2932
public abstract class AdminClientSettings {
30-
3133
// Required parameters.
32-
3334
/**
3435
* The <a href="https://cloud.google.com/pubsub/lite/docs/locations">cloud region</a> to perform
3536
* admin operations for.
3637
*/
3738
abstract CloudRegion region();
3839

3940
// Optional parameters.
40-
4141
/** The retry settings for this client. */
42-
abstract RetrySettings retrySettings();
42+
abstract Optional<RetrySettings> retrySettings();
4343

4444
/** A stub to use to connect. */
45-
abstract Optional<AdminServiceBlockingStub> stub();
45+
abstract Optional<AdminServiceClient> serviceClient();
4646

4747
public static Builder newBuilder() {
4848
return new AutoValue_AdminClientSettings.Builder()
@@ -61,20 +61,33 @@ public abstract static class Builder {
6161
/** The retry settings for this client. */
6262
public abstract Builder setRetrySettings(RetrySettings retrySettings);
6363

64-
/** A stub to use to connect. */
65-
public abstract Builder setStub(AdminServiceBlockingStub stub);
64+
/** A service client to use to connect. */
65+
public abstract Builder setServiceClient(AdminServiceClient serviceClient);
6666

6767
/** Build the settings object. */
6868
public abstract AdminClientSettings build();
6969
}
7070

71-
AdminClient instantiate() throws StatusException {
72-
AdminServiceBlockingStub stub;
73-
if (stub().isPresent()) {
74-
stub = stub().get();
71+
AdminClient instantiate() throws ApiException {
72+
AdminServiceClient serviceClient;
73+
if (serviceClient().isPresent()) {
74+
serviceClient = serviceClient().get();
7575
} else {
76-
stub = Stubs.defaultStub(region(), AdminServiceGrpc::newBlockingStub);
76+
try {
77+
AdminServiceSettings.Builder builder =
78+
addDefaultSettings(region(), AdminServiceSettings.newBuilder()).toBuilder();
79+
if (retrySettings().isPresent()) {
80+
builder.applyToAllUnaryMethods(
81+
callBuilder -> {
82+
callBuilder.setRetrySettings(retrySettings().get());
83+
return null;
84+
});
85+
}
86+
serviceClient = AdminServiceClient.create(builder.build());
87+
} catch (Throwable t) {
88+
throw ExtractStatus.toCanonical(t).underlying;
89+
}
7790
}
78-
return new AdminClientImpl(region(), stub, retrySettings());
91+
return new AdminClientImpl(region(), serviceClient);
7992
}
8093
}

0 commit comments

Comments
 (0)