Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add detach subscription rpc #216

Merged
merged 3 commits into from Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
*
Expand All @@ -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:
*
Expand Down Expand Up @@ -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:
*
Expand All @@ -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:
*
Expand All @@ -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:
*
Expand Down Expand Up @@ -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();
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -478,6 +511,11 @@ public UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() {
return testIamPermissionsCallable;
}

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

@Override
public final void close() {
shutdown();
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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;
Expand All @@ -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)));
Expand Down Expand Up @@ -648,6 +663,8 @@ protected Builder(ClientContext clientContext) {

testIamPermissionsSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();

detachSubscriptionSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();

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

initDefaults(this);
}
Expand Down Expand Up @@ -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;
}

Expand All @@ -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(
Expand All @@ -773,7 +797,8 @@ protected Builder(PublisherStubSettings settings) {
deleteTopicSettings,
setIamPolicySettings,
getIamPolicySettings,
testIamPermissionsSettings);
testIamPermissionsSettings,
detachSubscriptionSettings);
}

// NEXT_MAJOR_VER: remove 'throws Exception'
Expand Down Expand Up @@ -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);
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
}
}
}