Skip to content
Permalink
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 <noreply@google.com>
Source-Date: Tue May 26 15:11:32 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: f5f268f5293e60143ac742a4eeb7dd6306ebf505
Source-Link: googleapis/googleapis@f5f268f
  • Loading branch information
yoshi-automation committed Jun 5, 2020
1 parent 8414ee7 commit 09866b0d36e2dd1c994b4c91807d71552b65c8e1
Showing with 1,846 additions and 268 deletions.
  1. +57 −5 google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/TopicAdminClient.java
  2. +14 −0 google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/TopicAdminSettings.java
  3. +38 −0 google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/stub/GrpcPublisherStub.java
  4. +7 −0 google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/stub/PublisherStub.java
  5. +33 −2 google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/stub/PublisherStubSettings.java
  6. +18 −0 google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/MockPublisherImpl.java
  7. +44 −0 google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/TopicAdminClientTest.java
  8. +134 −4 grpc-google-cloud-pubsub-v1/src/main/java/com/google/pubsub/v1/PublisherGrpc.java
  9. +653 −0 proto-google-cloud-pubsub-v1/src/main/java/com/google/pubsub/v1/DetachSubscriptionRequest.java
  10. +56 −0 ...google-cloud-pubsub-v1/src/main/java/com/google/pubsub/v1/DetachSubscriptionRequestOrBuilder.java
  11. +457 −0 proto-google-cloud-pubsub-v1/src/main/java/com/google/pubsub/v1/DetachSubscriptionResponse.java
  12. +24 −0 ...oogle-cloud-pubsub-v1/src/main/java/com/google/pubsub/v1/DetachSubscriptionResponseOrBuilder.java
  13. +13 −13 proto-google-cloud-pubsub-v1/src/main/java/com/google/pubsub/v1/ListTopicSubscriptionsResponse.java
  14. +4 −4 ...e-cloud-pubsub-v1/src/main/java/com/google/pubsub/v1/ListTopicSubscriptionsResponseOrBuilder.java
  15. +264 −235 proto-google-cloud-pubsub-v1/src/main/java/com/google/pubsub/v1/PubsubProto.java
  16. +27 −2 proto-google-cloud-pubsub-v1/src/main/proto/google/pubsub/v1/pubsub.proto
  17. +3 −3 synth.metadata
@@ -37,6 +37,8 @@
import com.google.iam.v1.TestIamPermissionsResponse;
import com.google.protobuf.Empty;
import com.google.pubsub.v1.DeleteTopicRequest;
import com.google.pubsub.v1.DetachSubscriptionRequest;
import com.google.pubsub.v1.DetachSubscriptionResponse;
import com.google.pubsub.v1.GetTopicRequest;
import com.google.pubsub.v1.ListTopicSnapshotsRequest;
import com.google.pubsub.v1.ListTopicSnapshotsResponse;
@@ -724,7 +726,7 @@ public final UnaryCallable<ListTopicsRequest, ListTopicsResponse> listTopicsCall

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

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

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

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

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

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Detaches a subscription from this topic. All messages retained in the subscription are dropped.
* Subsequent `Pull` and `StreamingPull` requests will return FAILED_PRECONDITION. If the
* subscription is a push subscription, pushes to the endpoint will stop.
*
* <p>Sample code:
*
* <pre><code>
* try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
* TopicName subscription = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
* DetachSubscriptionRequest request = DetachSubscriptionRequest.newBuilder()
* .setSubscription(subscription.toString())
* .build();
* DetachSubscriptionResponse response = topicAdminClient.detachSubscription(request);
* }
* </code></pre>
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final DetachSubscriptionResponse detachSubscription(DetachSubscriptionRequest request) {
return detachSubscriptionCallable().call(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Detaches a subscription from this topic. All messages retained in the subscription are dropped.
* Subsequent `Pull` and `StreamingPull` requests will return FAILED_PRECONDITION. If the
* subscription is a push subscription, pushes to the endpoint will stop.
*
* <p>Sample code:
*
* <pre><code>
* try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
* TopicName subscription = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
* DetachSubscriptionRequest request = DetachSubscriptionRequest.newBuilder()
* .setSubscription(subscription.toString())
* .build();
* ApiFuture&lt;DetachSubscriptionResponse&gt; future = topicAdminClient.detachSubscriptionCallable().futureCall(request);
* // Do something
* DetachSubscriptionResponse response = future.get();
* }
* </code></pre>
*/
public final UnaryCallable<DetachSubscriptionRequest, DetachSubscriptionResponse>
detachSubscriptionCallable() {
return stub.detachSubscriptionCallable();
}

@Override
public final void close() {
stub.close();
@@ -39,6 +39,8 @@
import com.google.iam.v1.TestIamPermissionsResponse;
import com.google.protobuf.Empty;
import com.google.pubsub.v1.DeleteTopicRequest;
import com.google.pubsub.v1.DetachSubscriptionRequest;
import com.google.pubsub.v1.DetachSubscriptionResponse;
import com.google.pubsub.v1.GetTopicRequest;
import com.google.pubsub.v1.ListTopicSnapshotsRequest;
import com.google.pubsub.v1.ListTopicSnapshotsResponse;
@@ -150,6 +152,12 @@ public UnaryCallSettings<GetIamPolicyRequest, Policy> getIamPolicySettings() {
return ((PublisherStubSettings) getStubSettings()).testIamPermissionsSettings();
}

/** Returns the object with the settings used for calls to detachSubscription. */
public UnaryCallSettings<DetachSubscriptionRequest, DetachSubscriptionResponse>
detachSubscriptionSettings() {
return ((PublisherStubSettings) getStubSettings()).detachSubscriptionSettings();
}

public static final TopicAdminSettings create(PublisherStubSettings stub) throws IOException {
return new TopicAdminSettings.Builder(stub.toBuilder()).build();
}
@@ -310,6 +318,12 @@ public UnaryCallSettings.Builder<GetIamPolicyRequest, Policy> getIamPolicySettin
return getStubSettingsBuilder().testIamPermissionsSettings();
}

/** Returns the builder for the settings used for calls to detachSubscription. */
public UnaryCallSettings.Builder<DetachSubscriptionRequest, DetachSubscriptionResponse>
detachSubscriptionSettings() {
return getStubSettingsBuilder().detachSubscriptionSettings();
}

@Override
public TopicAdminSettings build() throws IOException {
return new TopicAdminSettings(this);
@@ -35,6 +35,8 @@
import com.google.iam.v1.TestIamPermissionsResponse;
import com.google.protobuf.Empty;
import com.google.pubsub.v1.DeleteTopicRequest;
import com.google.pubsub.v1.DetachSubscriptionRequest;
import com.google.pubsub.v1.DetachSubscriptionResponse;
import com.google.pubsub.v1.GetTopicRequest;
import com.google.pubsub.v1.ListTopicSnapshotsRequest;
import com.google.pubsub.v1.ListTopicSnapshotsResponse;
@@ -152,6 +154,16 @@ public class GrpcPublisherStub extends PublisherStub {
.setResponseMarshaller(
ProtoUtils.marshaller(TestIamPermissionsResponse.getDefaultInstance()))
.build();
private static final MethodDescriptor<DetachSubscriptionRequest, DetachSubscriptionResponse>
detachSubscriptionMethodDescriptor =
MethodDescriptor.<DetachSubscriptionRequest, DetachSubscriptionResponse>newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName("google.pubsub.v1.Publisher/DetachSubscription")
.setRequestMarshaller(
ProtoUtils.marshaller(DetachSubscriptionRequest.getDefaultInstance()))
.setResponseMarshaller(
ProtoUtils.marshaller(DetachSubscriptionResponse.getDefaultInstance()))
.build();

private final BackgroundResource backgroundResources;

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

private final GrpcStubCallableFactory callableFactory;

@@ -360,6 +374,20 @@ public Map<String, String> extract(TestIamPermissionsRequest request) {
}
})
.build();
GrpcCallSettings<DetachSubscriptionRequest, DetachSubscriptionResponse>
detachSubscriptionTransportSettings =
GrpcCallSettings.<DetachSubscriptionRequest, DetachSubscriptionResponse>newBuilder()
.setMethodDescriptor(detachSubscriptionMethodDescriptor)
.setParamsExtractor(
new RequestParamsExtractor<DetachSubscriptionRequest>() {
@Override
public Map<String, String> extract(DetachSubscriptionRequest request) {
ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
params.put("subscription", String.valueOf(request.getSubscription()));
return params.build();
}
})
.build();

this.createTopicCallable =
callableFactory.createUnaryCallable(
@@ -413,6 +441,11 @@ public Map<String, String> extract(TestIamPermissionsRequest request) {
testIamPermissionsTransportSettings,
settings.testIamPermissionsSettings(),
clientContext);
this.detachSubscriptionCallable =
callableFactory.createUnaryCallable(
detachSubscriptionTransportSettings,
settings.detachSubscriptionSettings(),
clientContext);

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

public UnaryCallable<DetachSubscriptionRequest, DetachSubscriptionResponse>
detachSubscriptionCallable() {
return detachSubscriptionCallable;
}

@Override
public final void close() {
shutdown();
@@ -29,6 +29,8 @@
import com.google.iam.v1.TestIamPermissionsResponse;
import com.google.protobuf.Empty;
import com.google.pubsub.v1.DeleteTopicRequest;
import com.google.pubsub.v1.DetachSubscriptionRequest;
import com.google.pubsub.v1.DetachSubscriptionResponse;
import com.google.pubsub.v1.GetTopicRequest;
import com.google.pubsub.v1.ListTopicSnapshotsRequest;
import com.google.pubsub.v1.ListTopicSnapshotsResponse;
@@ -114,6 +116,11 @@ public UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() {
throw new UnsupportedOperationException("Not implemented: testIamPermissionsCallable()");
}

public UnaryCallable<DetachSubscriptionRequest, DetachSubscriptionResponse>
detachSubscriptionCallable() {
throw new UnsupportedOperationException("Not implemented: detachSubscriptionCallable()");
}

@Override
public abstract void close();
}
@@ -60,6 +60,8 @@
import com.google.iam.v1.TestIamPermissionsResponse;
import com.google.protobuf.Empty;
import com.google.pubsub.v1.DeleteTopicRequest;
import com.google.pubsub.v1.DetachSubscriptionRequest;
import com.google.pubsub.v1.DetachSubscriptionResponse;
import com.google.pubsub.v1.GetTopicRequest;
import com.google.pubsub.v1.ListTopicSnapshotsRequest;
import com.google.pubsub.v1.ListTopicSnapshotsResponse;
@@ -137,6 +139,8 @@ public class PublisherStubSettings extends StubSettings<PublisherStubSettings> {
private final UnaryCallSettings<GetIamPolicyRequest, Policy> getIamPolicySettings;
private final UnaryCallSettings<TestIamPermissionsRequest, TestIamPermissionsResponse>
testIamPermissionsSettings;
private final UnaryCallSettings<DetachSubscriptionRequest, DetachSubscriptionResponse>
detachSubscriptionSettings;

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

/** Returns the object with the settings used for calls to detachSubscription. */
public UnaryCallSettings<DetachSubscriptionRequest, DetachSubscriptionResponse>
detachSubscriptionSettings() {
return detachSubscriptionSettings;
}

@BetaApi("A restructuring of stub classes is planned, so this may break in the future")
public PublisherStub createStub() throws IOException {
if (getTransportChannelProvider()
@@ -280,6 +290,7 @@ protected PublisherStubSettings(Builder settingsBuilder) throws IOException {
setIamPolicySettings = settingsBuilder.setIamPolicySettings().build();
getIamPolicySettings = settingsBuilder.getIamPolicySettings().build();
testIamPermissionsSettings = settingsBuilder.testIamPermissionsSettings().build();
detachSubscriptionSettings = settingsBuilder.detachSubscriptionSettings().build();
}

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

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

testIamPermissionsSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();

detachSubscriptionSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();

unaryMethodSettingsBuilders =
ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(
createTopicSettings,
@@ -660,7 +677,8 @@ protected Builder(ClientContext clientContext) {
deleteTopicSettings,
setIamPolicySettings,
getIamPolicySettings,
testIamPermissionsSettings);
testIamPermissionsSettings,
detachSubscriptionSettings);

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

builder
.detachSubscriptionSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent2"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default"));

return builder;
}

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

unaryMethodSettingsBuilders =
ImmutableList.<UnaryCallSettings.Builder<?, ?>>of(
@@ -773,7 +797,8 @@ protected Builder(PublisherStubSettings settings) {
deleteTopicSettings,
setIamPolicySettings,
getIamPolicySettings,
testIamPermissionsSettings);
testIamPermissionsSettings,
detachSubscriptionSettings);
}

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

/** Returns the builder for the settings used for calls to detachSubscription. */
public UnaryCallSettings.Builder<DetachSubscriptionRequest, DetachSubscriptionResponse>
detachSubscriptionSettings() {
return detachSubscriptionSettings;
}

@Override
public PublisherStubSettings build() throws IOException {
return new PublisherStubSettings(this);
@@ -19,6 +19,8 @@
import com.google.protobuf.AbstractMessage;
import com.google.protobuf.Empty;
import com.google.pubsub.v1.DeleteTopicRequest;
import com.google.pubsub.v1.DetachSubscriptionRequest;
import com.google.pubsub.v1.DetachSubscriptionResponse;
import com.google.pubsub.v1.GetTopicRequest;
import com.google.pubsub.v1.ListTopicSnapshotsRequest;
import com.google.pubsub.v1.ListTopicSnapshotsResponse;
@@ -185,4 +187,20 @@ public void deleteTopic(DeleteTopicRequest request, StreamObserver<Empty> respon
responseObserver.onError(new IllegalArgumentException("Unrecognized response type"));
}
}

@Override
public void detachSubscription(
DetachSubscriptionRequest request,
StreamObserver<DetachSubscriptionResponse> responseObserver) {
Object response = responses.remove();
if (response instanceof DetachSubscriptionResponse) {
requests.add(request);
responseObserver.onNext((DetachSubscriptionResponse) response);
responseObserver.onCompleted();
} else if (response instanceof Exception) {
responseObserver.onError((Exception) response);
} else {
responseObserver.onError(new IllegalArgumentException("Unrecognized response type"));
}
}
}

0 comments on commit 09866b0

Please sign in to comment.