[Broker] Fix call sync method in async rest api for preValidation.
### Motivation
Avoid call sync method in async rest API for PersistentTopicsBase#preValidation.
@@ -3199,15 +3199,23 @@ public class PersistentTopicsBase extends AdminResource {
}
protected CompletableFuture<Void> preValidation(boolean authoritative) {
- checkTopicLevelPolicyEnable();
+ if (!config().isTopicLevelPoliciesEnabled()) {
+ return FutureUtil.failedFuture(new RestException(Status.METHOD_NOT_ALLOWED,
+ "Topic level policies is disabled, to enable the topic level policy and retry."));
+ }
if (topicName.isPartitioned()) {
return FutureUtil.failedFuture(new RestException(Status.PRECONDITION_FAILED,
"Not allowed to set/get topic policy for a partition"));
}
+ CompletableFuture<Void> ret;
if (topicName.isGlobal()) {
- validateGlobalNamespaceOwnership(namespaceName);
+ ret = validateGlobalNamespaceOwnershipAsync(namespaceName);
+ } else {
+ ret = CompletableFuture.completedFuture(null);
}
- return checkTopicExistsAsync(topicName).thenCompose(exist -> {
+ return ret
+ .thenCompose(__ -> checkTopicExistsAsync(topicName))
+ .thenCompose(exist -> {
if (!exist) {
throw new RestException(Status.NOT_FOUND, "Topic not found");
} else {
