mattisonchao commented on a change in pull request #13970:
URL: https://github.com/apache/pulsar/pull/13970#discussion_r794986028



##########
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java
##########
@@ -2720,25 +2746,55 @@ private void updatePolicies(NamespaceName ns, 
Function<Policies, Policies> updat
        }
    }
 
-    protected void internalSetNamespaceResourceGroup(String rgName) {
-        validateNamespacePolicyOperation(namespaceName, 
PolicyName.RESOURCEGROUP, PolicyOperation.WRITE);
-        validatePoliciesReadOnlyAccess();
-
-        if (rgName != null) {
-            // check resourcegroup exists.
-            try {
-                if (!resourceGroupResources().resourceGroupExists(rgName)) {
-                    throw new RestException(Status.PRECONDITION_FAILED, 
"ResourceGroup does not exist");
-                }
-            } catch (Exception e) {
-                log.error("[{}] Invalid ResourceGroup {}: {}", clientAppId(), 
rgName, e);
-                throw new RestException(e);
-            }
-        }
 
-        internalSetPolicies("resource_group_name", rgName);
+    protected void internalGetNamespaceResourceGroup(AsyncResponse 
asyncResponse, String tenant, String namespace) {
+        validateNamespacePolicyOperationAsync(NamespaceName.get(tenant, 
namespace),
+                PolicyName.RESOURCEGROUP, PolicyOperation.READ)
+                .thenCompose(__ -> getNamespacePoliciesAsync(namespaceName)
+                        .thenAccept(policies -> 
asyncResponse.resume(policies.resource_group_name)))
+                .exceptionally(ex -> {
+                    Throwable realCause = 
FutureUtil.unwrapCompletionException(ex);
+                    if (realCause instanceof WebApplicationException) {
+                        log.info("[{}] Successfully to get namespace resource 
group {}/{}",
+                                clientAppId(), tenant, namespace);
+                        asyncResponse.resume(realCause);
+                    } else {
+                        log.error("[{}] Fail to get namespace resource group 
{}/{}", clientAppId(), tenant, namespace);
+                        asyncResponse.resume(new RestException(realCause));
+                    }
+                    return null;
+                });
     }
 
-
-    private static final Logger log = 
LoggerFactory.getLogger(NamespacesBase.class);
+    protected void internalSetNamespaceResourceGroup(AsyncResponse 
asyncResponse, String rgName) {
+        validateNamespacePolicyOperationAsync(namespaceName, 
PolicyName.RESOURCEGROUP, PolicyOperation.WRITE)
+                .thenCompose(__ -> validatePoliciesReadOnlyAccessAsync())
+                .thenCompose(__ -> {
+                    if (rgName != null) {
+                        return 
resourceGroupResources().getResourceGroupAsync(rgName)
+                                .thenAccept(resourceGroup -> {
+                                    // check resource group exists.
+                                    if (!resourceGroup.isPresent()) {
+                                        throw new 
RestException(Status.PRECONDITION_FAILED,
+                                                "ResourceGroup does not 
exist");
+                                    }
+                                });
+                    } else {
+                        return CompletableFuture.completedFuture(null);
+                    }
+                }).thenCompose(__ -> 
internalSetPoliciesAsync("resource_group_name", rgName))
+                .thenAccept(__ -> {
+                    log.info("[{}] Successfully to set namespace resource 
group {}", clientAppId(), rgName);
+                    asyncResponse.resume(Response.noContent().build());
+                }).exceptionally(ex -> {
+                    Throwable realCause = 
FutureUtil.unwrapCompletionException(ex);
+                    if (realCause instanceof WebApplicationException) {

Review comment:
       I think the exception message is enough.




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