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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improve][broker] Use validateTopicOperationAsync methods in all cases #19016

Merged
merged 1 commit into from
Dec 21, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,7 @@ private void internalUpdateSubscriptionPropertiesForNonPartitionedTopic(AsyncRes
String subName, Map<String, String> subscriptionProperties,
boolean authoritative) {
validateTopicOwnershipAsync(topicName, authoritative)
.thenRun(() -> validateTopicOperation(topicName, TopicOperation.CONSUME, subName))
.thenCompose(__ -> validateTopicOperationAsync(topicName, TopicOperation.CONSUME, subName))
.thenCompose(__ -> getTopicReferenceAsync(topicName))
.thenCompose(topic -> {
Subscription sub = topic.getSubscription(subName);
Expand All @@ -1684,7 +1684,7 @@ private void internalGetSubscriptionPropertiesForNonPartitionedTopic(AsyncRespon
String subName,
boolean authoritative) {
validateTopicOwnershipAsync(topicName, authoritative)
.thenRun(() -> validateTopicOperation(topicName, TopicOperation.CONSUME, subName))
.thenCompose(__ -> validateTopicOperationAsync(topicName, TopicOperation.CONSUME, subName))
.thenCompose(__ -> getTopicReferenceAsync(topicName))
.thenApply((Topic topic) -> {
Subscription sub = topic.getSubscription(subName);
Expand Down Expand Up @@ -1787,7 +1787,7 @@ protected void internalDeleteSubscriptionForcefully(AsyncResponse asyncResponse,
private void internalDeleteSubscriptionForNonPartitionedTopicForcefully(AsyncResponse asyncResponse,
String subName, boolean authoritative) {
validateTopicOwnershipAsync(topicName, authoritative)
.thenRun(() -> validateTopicOperation(topicName, TopicOperation.UNSUBSCRIBE, subName))
.thenCompose(__ -> validateTopicOperationAsync(topicName, TopicOperation.UNSUBSCRIBE, subName))
.thenCompose(__ -> getTopicReferenceAsync(topicName))
.thenCompose(topic -> {
Subscription sub = topic.getSubscription(subName);
Expand Down Expand Up @@ -2339,18 +2339,17 @@ private void internalCreateSubscriptionForNonPartitionedTopic(
Map<String, String> properties) {

validateTopicOwnershipAsync(topicName, authoritative)
.thenCompose(__ -> {
validateTopicOperation(topicName, TopicOperation.SUBSCRIBE, subscriptionName);
return pulsar().getBrokerService().isAllowAutoTopicCreationAsync(topicName)
.thenCompose(isAllowAutoTopicCreation -> pulsar().getBrokerService()
.getTopic(topicName.toString(), isAllowAutoTopicCreation));
}).thenApply(optTopic -> {
if (optTopic.isPresent()) {
return optTopic.get();
} else {
throw new RestException(Status.PRECONDITION_FAILED,
"Topic does not exist and cannot be auto-created");
}
.thenCompose(__ -> validateTopicOperationAsync(topicName, TopicOperation.SUBSCRIBE, subscriptionName))
.thenCompose(__ -> pulsar().getBrokerService().isAllowAutoTopicCreationAsync(topicName))
.thenCompose(isAllowAutoTopicCreation -> pulsar().getBrokerService()
.getTopic(topicName.toString(), isAllowAutoTopicCreation))
.thenApply(optTopic -> {
if (optTopic.isPresent()) {
return optTopic.get();
} else {
throw new RestException(Status.PRECONDITION_FAILED,
"Topic does not exist and cannot be auto-created");
}
}).thenCompose(topic -> {
if (topic.getSubscriptions().containsKey(subscriptionName)) {
throw new RestException(Status.CONFLICT, "Subscription already exists for topic");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,6 @@ protected CompletableFuture<LookupData> internalLookupTopicAsync(TopicName topic
});
}

private void validateAdminAndClientPermission(TopicName topic) throws RestException, Exception {
try {
validateTopicOperation(topic, TopicOperation.LOOKUP);
} catch (Exception e) {
// unknown error marked as internal server error
throw new RestException(e);
}
}

protected String internalGetNamespaceBundle(TopicName topicName) {
validateNamespaceOperation(topicName.getNamespaceObject(), NamespaceOperation.GET_BUNDLE);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1226,14 +1226,6 @@ && pulsar().getBrokerService().isAuthorizationEnabled()) {
return CompletableFuture.completedFuture(null);
}

public void validateTopicOperation(TopicName topicName, TopicOperation operation) {
validateTopicOperation(topicName, operation, null);
}

public void validateTopicOperation(TopicName topicName, TopicOperation operation, String subscription) {
sync(()-> validateTopicOperationAsync(topicName, operation, subscription));
}

public CompletableFuture<Void> validateTopicOperationAsync(TopicName topicName, TopicOperation operation) {
return validateTopicOperationAsync(topicName, operation, null);
}
Expand Down