Skip to content

Commit 14d887f

Browse files
feat: add detach subscription rpc (#216)
* changes without context autosynth cannot find the source of changes triggered by earlier changes in this repository, or by version upgrades to tools such as linters. * Add DetachSubscription RPC PiperOrigin-RevId: 313276022 Source-Author: Google APIs <[email protected]> Source-Date: Tue May 26 15:11:32 2020 -0700 Source-Repo: googleapis/googleapis Source-Sha: f5f268f5293e60143ac742a4eeb7dd6306ebf505 Source-Link: googleapis/googleapis@f5f268f
1 parent 6267a9e commit 14d887f

17 files changed

Lines changed: 1846 additions & 268 deletions

File tree

java-pubsub/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/TopicAdminClient.java

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import com.google.iam.v1.TestIamPermissionsResponse;
3838
import com.google.protobuf.Empty;
3939
import com.google.pubsub.v1.DeleteTopicRequest;
40+
import com.google.pubsub.v1.DetachSubscriptionRequest;
41+
import com.google.pubsub.v1.DetachSubscriptionResponse;
4042
import com.google.pubsub.v1.GetTopicRequest;
4143
import com.google.pubsub.v1.ListTopicSnapshotsRequest;
4244
import com.google.pubsub.v1.ListTopicSnapshotsResponse;
@@ -724,7 +726,7 @@ public final UnaryCallable<ListTopicsRequest, ListTopicsResponse> listTopicsCall
724726

725727
// AUTO-GENERATED DOCUMENTATION AND METHOD
726728
/**
727-
* Lists the names of the subscriptions on this topic.
729+
* Lists the names of the attached subscriptions on this topic.
728730
*
729731
* <p>Sample code:
730732
*
@@ -751,7 +753,7 @@ public final ListTopicSubscriptionsPagedResponse listTopicSubscriptions(TopicNam
751753

752754
// AUTO-GENERATED DOCUMENTATION AND METHOD
753755
/**
754-
* Lists the names of the subscriptions on this topic.
756+
* Lists the names of the attached subscriptions on this topic.
755757
*
756758
* <p>Sample code:
757759
*
@@ -804,7 +806,7 @@ public final ListTopicSubscriptionsPagedResponse listTopicSubscriptions(ProjectT
804806

805807
// AUTO-GENERATED DOCUMENTATION AND METHOD
806808
/**
807-
* Lists the names of the subscriptions on this topic.
809+
* Lists the names of the attached subscriptions on this topic.
808810
*
809811
* <p>Sample code:
810812
*
@@ -830,7 +832,7 @@ public final ListTopicSubscriptionsPagedResponse listTopicSubscriptions(
830832

831833
// AUTO-GENERATED DOCUMENTATION AND METHOD
832834
/**
833-
* Lists the names of the subscriptions on this topic.
835+
* Lists the names of the attached subscriptions on this topic.
834836
*
835837
* <p>Sample code:
836838
*
@@ -855,7 +857,7 @@ public final ListTopicSubscriptionsPagedResponse listTopicSubscriptions(
855857

856858
// AUTO-GENERATED DOCUMENTATION AND METHOD
857859
/**
858-
* Lists the names of the subscriptions on this topic.
860+
* Lists the names of the attached subscriptions on this topic.
859861
*
860862
* <p>Sample code:
861863
*
@@ -1416,6 +1418,56 @@ public final TestIamPermissionsResponse testIamPermissions(
14161418
return stub.testIamPermissionsCallable();
14171419
}
14181420

1421+
// AUTO-GENERATED DOCUMENTATION AND METHOD
1422+
/**
1423+
* Detaches a subscription from this topic. All messages retained in the subscription are dropped.
1424+
* Subsequent `Pull` and `StreamingPull` requests will return FAILED_PRECONDITION. If the
1425+
* subscription is a push subscription, pushes to the endpoint will stop.
1426+
*
1427+
* <p>Sample code:
1428+
*
1429+
* <pre><code>
1430+
* try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
1431+
* TopicName subscription = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
1432+
* DetachSubscriptionRequest request = DetachSubscriptionRequest.newBuilder()
1433+
* .setSubscription(subscription.toString())
1434+
* .build();
1435+
* DetachSubscriptionResponse response = topicAdminClient.detachSubscription(request);
1436+
* }
1437+
* </code></pre>
1438+
*
1439+
* @param request The request object containing all of the parameters for the API call.
1440+
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
1441+
*/
1442+
public final DetachSubscriptionResponse detachSubscription(DetachSubscriptionRequest request) {
1443+
return detachSubscriptionCallable().call(request);
1444+
}
1445+
1446+
// AUTO-GENERATED DOCUMENTATION AND METHOD
1447+
/**
1448+
* Detaches a subscription from this topic. All messages retained in the subscription are dropped.
1449+
* Subsequent `Pull` and `StreamingPull` requests will return FAILED_PRECONDITION. If the
1450+
* subscription is a push subscription, pushes to the endpoint will stop.
1451+
*
1452+
* <p>Sample code:
1453+
*
1454+
* <pre><code>
1455+
* try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
1456+
* TopicName subscription = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
1457+
* DetachSubscriptionRequest request = DetachSubscriptionRequest.newBuilder()
1458+
* .setSubscription(subscription.toString())
1459+
* .build();
1460+
* ApiFuture&lt;DetachSubscriptionResponse&gt; future = topicAdminClient.detachSubscriptionCallable().futureCall(request);
1461+
* // Do something
1462+
* DetachSubscriptionResponse response = future.get();
1463+
* }
1464+
* </code></pre>
1465+
*/
1466+
public final UnaryCallable<DetachSubscriptionRequest, DetachSubscriptionResponse>
1467+
detachSubscriptionCallable() {
1468+
return stub.detachSubscriptionCallable();
1469+
}
1470+
14191471
@Override
14201472
public final void close() {
14211473
stub.close();

java-pubsub/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/TopicAdminSettings.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import com.google.iam.v1.TestIamPermissionsResponse;
4040
import com.google.protobuf.Empty;
4141
import com.google.pubsub.v1.DeleteTopicRequest;
42+
import com.google.pubsub.v1.DetachSubscriptionRequest;
43+
import com.google.pubsub.v1.DetachSubscriptionResponse;
4244
import com.google.pubsub.v1.GetTopicRequest;
4345
import com.google.pubsub.v1.ListTopicSnapshotsRequest;
4446
import com.google.pubsub.v1.ListTopicSnapshotsResponse;
@@ -150,6 +152,12 @@ public UnaryCallSettings<GetIamPolicyRequest, Policy> getIamPolicySettings() {
150152
return ((PublisherStubSettings) getStubSettings()).testIamPermissionsSettings();
151153
}
152154

155+
/** Returns the object with the settings used for calls to detachSubscription. */
156+
public UnaryCallSettings<DetachSubscriptionRequest, DetachSubscriptionResponse>
157+
detachSubscriptionSettings() {
158+
return ((PublisherStubSettings) getStubSettings()).detachSubscriptionSettings();
159+
}
160+
153161
public static final TopicAdminSettings create(PublisherStubSettings stub) throws IOException {
154162
return new TopicAdminSettings.Builder(stub.toBuilder()).build();
155163
}
@@ -310,6 +318,12 @@ public UnaryCallSettings.Builder<GetIamPolicyRequest, Policy> getIamPolicySettin
310318
return getStubSettingsBuilder().testIamPermissionsSettings();
311319
}
312320

321+
/** Returns the builder for the settings used for calls to detachSubscription. */
322+
public UnaryCallSettings.Builder<DetachSubscriptionRequest, DetachSubscriptionResponse>
323+
detachSubscriptionSettings() {
324+
return getStubSettingsBuilder().detachSubscriptionSettings();
325+
}
326+
313327
@Override
314328
public TopicAdminSettings build() throws IOException {
315329
return new TopicAdminSettings(this);

java-pubsub/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/stub/GrpcPublisherStub.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import com.google.iam.v1.TestIamPermissionsResponse;
3636
import com.google.protobuf.Empty;
3737
import com.google.pubsub.v1.DeleteTopicRequest;
38+
import com.google.pubsub.v1.DetachSubscriptionRequest;
39+
import com.google.pubsub.v1.DetachSubscriptionResponse;
3840
import com.google.pubsub.v1.GetTopicRequest;
3941
import com.google.pubsub.v1.ListTopicSnapshotsRequest;
4042
import com.google.pubsub.v1.ListTopicSnapshotsResponse;
@@ -152,6 +154,16 @@ public class GrpcPublisherStub extends PublisherStub {
152154
.setResponseMarshaller(
153155
ProtoUtils.marshaller(TestIamPermissionsResponse.getDefaultInstance()))
154156
.build();
157+
private static final MethodDescriptor<DetachSubscriptionRequest, DetachSubscriptionResponse>
158+
detachSubscriptionMethodDescriptor =
159+
MethodDescriptor.<DetachSubscriptionRequest, DetachSubscriptionResponse>newBuilder()
160+
.setType(MethodDescriptor.MethodType.UNARY)
161+
.setFullMethodName("google.pubsub.v1.Publisher/DetachSubscription")
162+
.setRequestMarshaller(
163+
ProtoUtils.marshaller(DetachSubscriptionRequest.getDefaultInstance()))
164+
.setResponseMarshaller(
165+
ProtoUtils.marshaller(DetachSubscriptionResponse.getDefaultInstance()))
166+
.build();
155167

156168
private final BackgroundResource backgroundResources;
157169

@@ -174,6 +186,8 @@ public class GrpcPublisherStub extends PublisherStub {
174186
private final UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable;
175187
private final UnaryCallable<TestIamPermissionsRequest, TestIamPermissionsResponse>
176188
testIamPermissionsCallable;
189+
private final UnaryCallable<DetachSubscriptionRequest, DetachSubscriptionResponse>
190+
detachSubscriptionCallable;
177191

178192
private final GrpcStubCallableFactory callableFactory;
179193

@@ -360,6 +374,20 @@ public Map<String, String> extract(TestIamPermissionsRequest request) {
360374
}
361375
})
362376
.build();
377+
GrpcCallSettings<DetachSubscriptionRequest, DetachSubscriptionResponse>
378+
detachSubscriptionTransportSettings =
379+
GrpcCallSettings.<DetachSubscriptionRequest, DetachSubscriptionResponse>newBuilder()
380+
.setMethodDescriptor(detachSubscriptionMethodDescriptor)
381+
.setParamsExtractor(
382+
new RequestParamsExtractor<DetachSubscriptionRequest>() {
383+
@Override
384+
public Map<String, String> extract(DetachSubscriptionRequest request) {
385+
ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
386+
params.put("subscription", String.valueOf(request.getSubscription()));
387+
return params.build();
388+
}
389+
})
390+
.build();
363391

364392
this.createTopicCallable =
365393
callableFactory.createUnaryCallable(
@@ -413,6 +441,11 @@ public Map<String, String> extract(TestIamPermissionsRequest request) {
413441
testIamPermissionsTransportSettings,
414442
settings.testIamPermissionsSettings(),
415443
clientContext);
444+
this.detachSubscriptionCallable =
445+
callableFactory.createUnaryCallable(
446+
detachSubscriptionTransportSettings,
447+
settings.detachSubscriptionSettings(),
448+
clientContext);
416449

417450
backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources());
418451
}
@@ -478,6 +511,11 @@ public UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() {
478511
return testIamPermissionsCallable;
479512
}
480513

514+
public UnaryCallable<DetachSubscriptionRequest, DetachSubscriptionResponse>
515+
detachSubscriptionCallable() {
516+
return detachSubscriptionCallable;
517+
}
518+
481519
@Override
482520
public final void close() {
483521
shutdown();

java-pubsub/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/stub/PublisherStub.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import com.google.iam.v1.TestIamPermissionsResponse;
3030
import com.google.protobuf.Empty;
3131
import com.google.pubsub.v1.DeleteTopicRequest;
32+
import com.google.pubsub.v1.DetachSubscriptionRequest;
33+
import com.google.pubsub.v1.DetachSubscriptionResponse;
3234
import com.google.pubsub.v1.GetTopicRequest;
3335
import com.google.pubsub.v1.ListTopicSnapshotsRequest;
3436
import com.google.pubsub.v1.ListTopicSnapshotsResponse;
@@ -114,6 +116,11 @@ public UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() {
114116
throw new UnsupportedOperationException("Not implemented: testIamPermissionsCallable()");
115117
}
116118

119+
public UnaryCallable<DetachSubscriptionRequest, DetachSubscriptionResponse>
120+
detachSubscriptionCallable() {
121+
throw new UnsupportedOperationException("Not implemented: detachSubscriptionCallable()");
122+
}
123+
117124
@Override
118125
public abstract void close();
119126
}

java-pubsub/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/stub/PublisherStubSettings.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
import com.google.iam.v1.TestIamPermissionsResponse;
6161
import com.google.protobuf.Empty;
6262
import com.google.pubsub.v1.DeleteTopicRequest;
63+
import com.google.pubsub.v1.DetachSubscriptionRequest;
64+
import com.google.pubsub.v1.DetachSubscriptionResponse;
6365
import com.google.pubsub.v1.GetTopicRequest;
6466
import com.google.pubsub.v1.ListTopicSnapshotsRequest;
6567
import com.google.pubsub.v1.ListTopicSnapshotsResponse;
@@ -137,6 +139,8 @@ public class PublisherStubSettings extends StubSettings<PublisherStubSettings> {
137139
private final UnaryCallSettings<GetIamPolicyRequest, Policy> getIamPolicySettings;
138140
private final UnaryCallSettings<TestIamPermissionsRequest, TestIamPermissionsResponse>
139141
testIamPermissionsSettings;
142+
private final UnaryCallSettings<DetachSubscriptionRequest, DetachSubscriptionResponse>
143+
detachSubscriptionSettings;
140144

141145
/** Returns the object with the settings used for calls to createTopic. */
142146
public UnaryCallSettings<Topic, Topic> createTopicSettings() {
@@ -201,6 +205,12 @@ public UnaryCallSettings<GetIamPolicyRequest, Policy> getIamPolicySettings() {
201205
return testIamPermissionsSettings;
202206
}
203207

208+
/** Returns the object with the settings used for calls to detachSubscription. */
209+
public UnaryCallSettings<DetachSubscriptionRequest, DetachSubscriptionResponse>
210+
detachSubscriptionSettings() {
211+
return detachSubscriptionSettings;
212+
}
213+
204214
@BetaApi("A restructuring of stub classes is planned, so this may break in the future")
205215
public PublisherStub createStub() throws IOException {
206216
if (getTransportChannelProvider()
@@ -280,6 +290,7 @@ protected PublisherStubSettings(Builder settingsBuilder) throws IOException {
280290
setIamPolicySettings = settingsBuilder.setIamPolicySettings().build();
281291
getIamPolicySettings = settingsBuilder.getIamPolicySettings().build();
282292
testIamPermissionsSettings = settingsBuilder.testIamPermissionsSettings().build();
293+
detachSubscriptionSettings = settingsBuilder.detachSubscriptionSettings().build();
283294
}
284295

285296
private static final PagedListDescriptor<ListTopicsRequest, ListTopicsResponse, Topic>
@@ -551,6 +562,8 @@ public static class Builder extends StubSettings.Builder<PublisherStubSettings,
551562
private final UnaryCallSettings.Builder<GetIamPolicyRequest, Policy> getIamPolicySettings;
552563
private final UnaryCallSettings.Builder<TestIamPermissionsRequest, TestIamPermissionsResponse>
553564
testIamPermissionsSettings;
565+
private final UnaryCallSettings.Builder<DetachSubscriptionRequest, DetachSubscriptionResponse>
566+
detachSubscriptionSettings;
554567

555568
private static final ImmutableMap<String, ImmutableSet<StatusCode.Code>>
556569
RETRYABLE_CODE_DEFINITIONS;
@@ -563,6 +576,8 @@ public static class Builder extends StubSettings.Builder<PublisherStubSettings,
563576
ImmutableSet.copyOf(
564577
Lists.<StatusCode.Code>newArrayList(
565578
StatusCode.Code.ABORTED, StatusCode.Code.UNAVAILABLE, StatusCode.Code.UNKNOWN)));
579+
definitions.put(
580+
"non_idempotent2", ImmutableSet.copyOf(Lists.<StatusCode.Code>newArrayList()));
566581
definitions.put(
567582
"non_idempotent",
568583
ImmutableSet.copyOf(Lists.<StatusCode.Code>newArrayList(StatusCode.Code.UNAVAILABLE)));
@@ -648,6 +663,8 @@ protected Builder(ClientContext clientContext) {
648663

649664
testIamPermissionsSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
650665

666+
detachSubscriptionSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
667+
651668
unaryMethodSettingsBuilders =
652669
ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(
653670
createTopicSettings,
@@ -660,7 +677,8 @@ protected Builder(ClientContext clientContext) {
660677
deleteTopicSettings,
661678
setIamPolicySettings,
662679
getIamPolicySettings,
663-
testIamPermissionsSettings);
680+
testIamPermissionsSettings,
681+
detachSubscriptionSettings);
664682

665683
initDefaults(this);
666684
}
@@ -743,6 +761,11 @@ private static Builder initDefaults(Builder builder) {
743761
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent"))
744762
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));
745763

764+
builder
765+
.detachSubscriptionSettings()
766+
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent2"))
767+
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));
768+
746769
return builder;
747770
}
748771

@@ -760,6 +783,7 @@ protected Builder(PublisherStubSettings settings) {
760783
setIamPolicySettings = settings.setIamPolicySettings.toBuilder();
761784
getIamPolicySettings = settings.getIamPolicySettings.toBuilder();
762785
testIamPermissionsSettings = settings.testIamPermissionsSettings.toBuilder();
786+
detachSubscriptionSettings = settings.detachSubscriptionSettings.toBuilder();
763787

764788
unaryMethodSettingsBuilders =
765789
ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(
@@ -773,7 +797,8 @@ protected Builder(PublisherStubSettings settings) {
773797
deleteTopicSettings,
774798
setIamPolicySettings,
775799
getIamPolicySettings,
776-
testIamPermissionsSettings);
800+
testIamPermissionsSettings,
801+
detachSubscriptionSettings);
777802
}
778803

779804
// NEXT_MAJOR_VER: remove 'throws Exception'
@@ -855,6 +880,12 @@ public UnaryCallSettings.Builder<GetIamPolicyRequest, Policy> getIamPolicySettin
855880
return testIamPermissionsSettings;
856881
}
857882

883+
/** Returns the builder for the settings used for calls to detachSubscription. */
884+
public UnaryCallSettings.Builder<DetachSubscriptionRequest, DetachSubscriptionResponse>
885+
detachSubscriptionSettings() {
886+
return detachSubscriptionSettings;
887+
}
888+
858889
@Override
859890
public PublisherStubSettings build() throws IOException {
860891
return new PublisherStubSettings(this);

java-pubsub/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/MockPublisherImpl.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import com.google.protobuf.AbstractMessage;
2020
import com.google.protobuf.Empty;
2121
import com.google.pubsub.v1.DeleteTopicRequest;
22+
import com.google.pubsub.v1.DetachSubscriptionRequest;
23+
import com.google.pubsub.v1.DetachSubscriptionResponse;
2224
import com.google.pubsub.v1.GetTopicRequest;
2325
import com.google.pubsub.v1.ListTopicSnapshotsRequest;
2426
import com.google.pubsub.v1.ListTopicSnapshotsResponse;
@@ -185,4 +187,20 @@ public void deleteTopic(DeleteTopicRequest request, StreamObserver<Empty> respon
185187
responseObserver.onError(new IllegalArgumentException("Unrecognized response type"));
186188
}
187189
}
190+
191+
@Override
192+
public void detachSubscription(
193+
DetachSubscriptionRequest request,
194+
StreamObserver<DetachSubscriptionResponse> responseObserver) {
195+
Object response = responses.remove();
196+
if (response instanceof DetachSubscriptionResponse) {
197+
requests.add(request);
198+
responseObserver.onNext((DetachSubscriptionResponse) response);
199+
responseObserver.onCompleted();
200+
} else if (response instanceof Exception) {
201+
responseObserver.onError((Exception) response);
202+
} else {
203+
responseObserver.onError(new IllegalArgumentException("Unrecognized response type"));
204+
}
205+
}
188206
}

0 commit comments

Comments
 (0)