Technoboy- commented on a change in pull request #14030:
URL: https://github.com/apache/pulsar/pull/14030#discussion_r795128733



##########
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java
##########
@@ -372,37 +372,42 @@ protected void internalRevokePermissionsOnTopic(String 
role) {
         revokePermissions(topicName.toString(), role);
     }
 
-    protected void internalCreateNonPartitionedTopic(boolean authoritative, 
Map<String, String> properties) {
-        validateNonPartitionTopicName(topicName.getLocalName());
+    protected void internalCreateNonPartitionedTopic(AsyncResponse 
asyncResponse, boolean authoritative,
+                                                     Map<String, String> 
properties) {
+        CompletableFuture<Void> ret = 
validateNonPartitionTopicNameAsync(topicName.getLocalName());
         if (topicName.isGlobal()) {
-            validateGlobalNamespaceOwnership(namespaceName);
-        }
-        validateTopicOwnership(topicName, authoritative);
-        validateNamespaceOperation(topicName.getNamespaceObject(), 
NamespaceOperation.CREATE_TOPIC);
-
-        PartitionedTopicMetadata partitionMetadata = 
getPartitionedTopicMetadata(topicName, authoritative, false);
-        if (partitionMetadata.partitions > 0) {
-            log.warn("[{}] Partitioned topic with the same name already exists 
{}", clientAppId(), topicName);
-            throw new RestException(Status.CONFLICT, "This topic already 
exists");
-        }
-
-        try {
-            Optional<Topic> existedTopic = 
pulsar().getBrokerService().getTopicIfExists(topicName.toString()).get();
-            if (existedTopic.isPresent()) {
-                log.error("[{}] Topic {} already exists", clientAppId(), 
topicName);
-                throw new RestException(Status.CONFLICT, "This topic already 
exists");
-            }
-
-            Topic createdTopic = getOrCreateTopic(topicName, properties);
-            log.info("[{}] Successfully created non-partitioned topic {}", 
clientAppId(), createdTopic);
-        } catch (Exception e) {
-            if (e instanceof RestException) {
-                throw (RestException) e;
-            } else {
-                log.error("[{}] Failed to create non-partitioned topic {}", 
clientAppId(), topicName, e);
-                throw new RestException(e);
-            }
-        }
+            ret.thenCompose(__ -> 
validateGlobalNamespaceOwnershipAsync(namespaceName));
+        }
+        ret.thenCompose(__ -> validateTopicOwnershipAsync(topicName, 
authoritative))
+           .thenCompose(__ -> 
validateNamespaceOperationAsync(topicName.getNamespaceObject(),
+                   NamespaceOperation.CREATE_TOPIC))
+           .thenCompose(__ -> getPartitionedTopicMetadataAsync(topicName, 
false, false))
+           .thenAccept(partitionMetadata -> {
+               if (partitionMetadata.partitions > 0) {
+                   log.warn("[{}] Partitioned topic with the same name already 
exists {}", clientAppId(), topicName);
+                   throw new RestException(Status.CONFLICT, "This topic 
already exists");
+               }
+           })
+           .thenCompose(__ -> 
pulsar().getBrokerService().getTopicIfExists(topicName.toString()))
+           .thenAccept(existedTopic -> {
+               if (existedTopic.isPresent()) {
+                   log.error("[{}] Topic {} already exists", clientAppId(), 
topicName);
+                   throw new RestException(Status.CONFLICT, "This topic 
already exists");
+               }
+           })
+           .thenAccept(__ ->
+               pulsar().getBrokerService().getTopic(topicName.toString(), 
true, properties)

Review comment:
       Yes, fixed. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to