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/17 02:48:55 UTC

[GitHub] [pulsar] gaoran10 commented on a diff in pull request #15605: Make some methods in ResourceQuotasBase async.

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


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/ResourceQuotasBase.java:
##########
@@ -18,110 +18,65 @@
  */
 package org.apache.pulsar.broker.admin.impl;
 
-import java.util.concurrent.TimeUnit;
+import java.util.concurrent.CompletableFuture;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.pulsar.broker.web.RestException;
 import org.apache.pulsar.common.naming.NamespaceBundle;
-import org.apache.pulsar.common.policies.data.Policies;
 import org.apache.pulsar.common.policies.data.ResourceQuota;
 
 @Slf4j
 public abstract class ResourceQuotasBase extends NamespacesBase {
 
-    public ResourceQuota getDefaultResourceQuota() throws Exception {
-        validateSuperUserAccess();
-        try {
-            return pulsar().getBrokerService().getBundlesQuotas().getDefaultResourceQuota()
-                    .get(config().getMetadataStoreOperationTimeoutSeconds(), TimeUnit.SECONDS);
-        } catch (Exception e) {
-            log.error("[{}] Failed to get default resource quota", clientAppId());
-            throw new RestException(e);
-        }
+    public ResourceQuota getDefaultResourceQuota() {
+        return sync(() -> getDefaultResourceQuotaAsync());
     }
 
-    public void setDefaultResourceQuota(ResourceQuota quota) throws Exception {
-        validateSuperUserAccess();
-        validatePoliciesReadOnlyAccess();
-        try {
-            pulsar().getBrokerService().getBundlesQuotas().setDefaultResourceQuota(quota)
-                    .get(config().getMetadataStoreOperationTimeoutSeconds(), TimeUnit.SECONDS);
-        } catch (Exception e) {
-            log.error("[{}] Failed to get default resource quota", clientAppId());
-            throw new RestException(e);
-        }
+    public CompletableFuture<ResourceQuota> getDefaultResourceQuotaAsync() {
+        return validateSuperUserAccessAsync()
+                .thenCompose(__ -> pulsar().getBrokerService().getBundlesQuotas().getDefaultResourceQuota());
     }
 
-    @SuppressWarnings("deprecation")
-    protected ResourceQuota internalGetNamespaceBundleResourceQuota(String bundleRange) {
-        validateSuperUserAccess();
-
-        Policies policies = getNamespacePolicies(namespaceName);
-
-        if (!namespaceName.isGlobal()) {
-            validateClusterOwnership(namespaceName.getCluster());
-            validateClusterForTenant(namespaceName.getTenant(), namespaceName.getCluster());
-        }
-
-        NamespaceBundle nsBundle = validateNamespaceBundleRange(namespaceName, policies.bundles, bundleRange);
-
-        try {
-            return pulsar().getBrokerService().getBundlesQuotas().getResourceQuota(nsBundle)
-                    .get(config().getMetadataStoreOperationTimeoutSeconds(), TimeUnit.SECONDS);
-        } catch (Exception e) {
-            log.error("[{}] Failed to get resource quota for namespace bundle {}", clientAppId(), nsBundle.toString());
-            throw new RestException(e);
-        }
+    public CompletableFuture<Void> setDefaultResourceQuota(ResourceQuota quota) {

Review Comment:
   ```suggestion
       public CompletableFuture<Void> setDefaultResourceQuotaAsync(ResourceQuota quota) {
   ```



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