You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/05/04 03:20:18 UTC

[GitHub] [pulsar] gaoran10 commented on a diff in pull request #15318: [improve][broker] Make some methods of `ClusterBase` pure async.

gaoran10 commented on code in PR #15318:
URL: https://github.com/apache/pulsar/pull/15318#discussion_r864431950


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/ClustersBase.java:
##########
@@ -158,27 +152,31 @@ public void createCluster(
                         + "}"
                 )
             )
-        )
-                ClusterDataImpl clusterData
-    ) {
-        validateSuperUserAccess();
-        validatePoliciesReadOnlyAccess();
-
-        try {
-            NamedEntity.checkName(cluster);
-            if (clusterResources().getCluster(cluster).isPresent()) {
-                log.warn("[{}] Failed to create already existing cluster {}", clientAppId(), cluster);
-                throw new RestException(Status.CONFLICT, "Cluster already exists");
-            }
-            clusterResources().createCluster(cluster, clusterData);
-            log.info("[{}] Created cluster {}", clientAppId(), cluster);
-        } catch (IllegalArgumentException e) {
-            log.warn("[{}] Failed to create cluster with invalid name {}", clientAppId(), cluster, e);
-            throw new RestException(Status.PRECONDITION_FAILED, "Cluster name is not valid");
-        } catch (Exception e) {
-            log.error("[{}] Failed to create cluster {}", clientAppId(), cluster, e);
-            throw new RestException(e);
-        }
+        ) ClusterDataImpl clusterData) {
+        validateSuperUserAccessAsync()
+                .thenCompose(__ -> validatePoliciesReadOnlyAccessAsync())
+                .thenCompose(__ -> {
+                    NamedEntity.checkName(cluster);
+                    return clusterResources().getClusterAsync(cluster);
+                }).thenCompose(clusterOpt -> {
+                    if (clusterOpt.isPresent()) {
+                        throw new RestException(Status.CONFLICT, "Cluster already exists");

Review Comment:
   Ok



-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org