Technoboy- commented on code in PR #15518:
URL: https://github.com/apache/pulsar/pull/15518#discussion_r869372040


##########
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/resources/TenantResources.java:
##########
@@ -110,6 +110,40 @@ public List<String> getListOfNamespaces(String tenant) 
throws MetadataStoreExcep
         return namespaces;
     }
 
+    public CompletableFuture<List<String>> getListOfNamespacesAsync(String 
tenant) {
+        List<String> namespaces = new ArrayList<>();
+        // this will return a cluster in v1 and a namespace in v2
+        CompletableFuture<List<CompletableFuture<Void>>> result = 
getChildrenAsync(joinPath(BASE_POLICIES_PATH, tenant))
+                .thenApply(clusterOrNamespaces -> 
clusterOrNamespaces.stream().map(key ->
+                        getChildrenAsync(joinPath(BASE_POLICIES_PATH, tenant, 
key))
+                                .thenCompose(children -> {
+                                    CompletableFuture<Void> ret = 
CompletableFuture.completedFuture(null);
+                                    if (children == null || 
children.isEmpty()) {
+                                        String namespace = 
NamespaceName.get(tenant, key).toString();
+                                        // if the length is 0 then this is 
probably a leftover cluster from namespace
+                                        // created with the v1 admin format 
(prop/cluster/ns) and then deleted, so no
+                                        // need to add it to the list
+                                        ret = ret.thenCompose(__ -> 
getAsync(joinPath(BASE_POLICIES_PATH, namespace))
+                                                        .thenAccept(opt -> 
opt.map(k -> namespaces.add(namespace)))
+                                                        .exceptionally(ex -> {
+                                                            Throwable cause = 
FutureUtil.unwrapCompletionException(ex);
+                                                            if (cause 
instanceof MetadataStoreException
+                                                                    
.ContentDeserializationException) {
+                                                                return null;
+                                                            }
+                                                            throw 
FutureUtil.wrapToCompletionException(ex);
+                                                        }));
+                                    } else {
+                                        children.forEach(ns -> {

Review Comment:
   Fixed, but seems harder to read ... 



-- 
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