Technoboy- commented on code in PR #15518:
URL: https://github.com/apache/pulsar/pull/15518#discussion_r872116745
##########
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/resources/TenantResources.java:
##########
@@ -110,6 +111,41 @@ public List<String> getListOfNamespaces(String tenant)
throws MetadataStoreExcep
return namespaces;
}
+ public CompletableFuture<List<String>> getListOfNamespacesAsync(String
tenant) {
+ // this will return a cluster in v1 and a namespace in v2
+ return getChildrenAsync(joinPath(BASE_POLICIES_PATH, tenant))
+ .thenCompose(clusterOrNamespaces ->
clusterOrNamespaces.stream().map(key ->
+ getChildrenAsync(joinPath(BASE_POLICIES_PATH, tenant,
key))
+ .thenCompose(children -> {
+ 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
+ return
getAsync(joinPath(BASE_POLICIES_PATH, namespace))
+ .thenApply(opt -> opt.isPresent() ?
Collections.singletonList(namespace)
+ : new ArrayList<String>())
+ .exceptionally(ex -> {
+ Throwable cause =
FutureUtil.unwrapCompletionException(ex);
+ if (cause instanceof
MetadataStoreException
+
.ContentDeserializationException) {
+ return new ArrayList<>();
+ }
+ throw
FutureUtil.wrapToCompletionException(ex);
+ });
+ } else {
+ CompletableFuture<List<String>> ret =
new CompletableFuture();
+ ret.complete(children.stream().map(ns
-> NamespaceName.get(tenant, key, ns)
+
.toString()).collect(Collectors.toList()));
+ return ret;
+ }
+
})).reduce(CompletableFuture.completedFuture(new ArrayList<>()),
+ (accumulator, n) ->
accumulator.thenCompose(namespaces -> n.thenCompose(m -> {
+ namespaces.addAll(m);
+ return
CompletableFuture.completedFuture(namespaces);
Review Comment:
fixed
##########
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/resources/TenantResources.java:
##########
@@ -110,6 +111,41 @@ public List<String> getListOfNamespaces(String tenant)
throws MetadataStoreExcep
return namespaces;
}
+ public CompletableFuture<List<String>> getListOfNamespacesAsync(String
tenant) {
+ // this will return a cluster in v1 and a namespace in v2
+ return getChildrenAsync(joinPath(BASE_POLICIES_PATH, tenant))
+ .thenCompose(clusterOrNamespaces ->
clusterOrNamespaces.stream().map(key ->
+ getChildrenAsync(joinPath(BASE_POLICIES_PATH, tenant,
key))
+ .thenCompose(children -> {
+ 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
+ return
getAsync(joinPath(BASE_POLICIES_PATH, namespace))
+ .thenApply(opt -> opt.isPresent() ?
Collections.singletonList(namespace)
+ : new ArrayList<String>())
+ .exceptionally(ex -> {
+ Throwable cause =
FutureUtil.unwrapCompletionException(ex);
+ if (cause instanceof
MetadataStoreException
+
.ContentDeserializationException) {
+ return new ArrayList<>();
+ }
+ throw
FutureUtil.wrapToCompletionException(ex);
+ });
+ } else {
+ CompletableFuture<List<String>> ret =
new CompletableFuture();
+ ret.complete(children.stream().map(ns
-> NamespaceName.get(tenant, key, ns)
+
.toString()).collect(Collectors.toList()));
+ return ret;
+ }
+
})).reduce(CompletableFuture.completedFuture(new ArrayList<>()),
+ (accumulator, n) ->
accumulator.thenCompose(namespaces -> n.thenCompose(m -> {
Review Comment:
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]