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



##########
File path: 
pulsar-broker/src/main/java/org/apache/pulsar/broker/web/PulsarWebResource.java
##########
@@ -972,15 +991,40 @@ public static ObjectMapper jsonMapper() {
         return ObjectMapperFactory.getThreadLocal();
     }
 
+    public CompletableFuture<Void> validatePoliciesReadOnlyAccessAsync() {
+        return pulsar().getPulsarResources()
+                .getNamespaceResources().getPoliciesReadOnlyAsync()
+                .thenAccept(arePoliciesReadOnly -> {
+                    if (arePoliciesReadOnly) {
+                        log.warn("Policies are read-only. Broker cannot do 
read-write operations");
+                        throw new RestException(Status.FORBIDDEN, "Broker is 
forbidden to do read-write operations");
+                    } else {
+                        if (log.isDebugEnabled()) {
+                            // Do nothing, just log the message.
+                            log.debug("Broker is allowed to make read-write 
operations");
+                        }
+                    }
+                });
+    }
+
+    /**
+     * Checks whether the broker is allowed to do read-write operations based 
on the existence of a node in
+     * configuration metadata-store.
+     *
+     * @throws WebApplicationException
+     *             if broker has a read only access if broker is not connected 
to the configuration metadata-store
+     */
     public void validatePoliciesReadOnlyAccess() {
         try {
-            if (namespaceResources().getPoliciesReadOnly()) {
-                log.debug("Policies are read-only. Broker cannot do read-write 
operations");
-                throw new RestException(Status.FORBIDDEN, "Broker is forbidden 
to do read-write operations");
+            validatePoliciesReadOnlyAccessAsync()
+                    .get(config().getZooKeeperOperationTimeoutSeconds(), 
TimeUnit.SECONDS);
+        } catch (InterruptedException | ExecutionException | TimeoutException 
ex) {
+            Throwable realCause = FutureUtil.unwrapCompletionException(ex);
+            if (realCause instanceof WebApplicationException) {
+                throw (WebApplicationException) realCause;

Review comment:
       This change will cause a compile error.

##########
File path: 
pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/NamespacesTest.java
##########
@@ -1748,4 +1738,26 @@ private void 
assertInvalidRetentionPolicyAsPartOfAllPolicies(Policies policies,
             assertTrue(e.getMessage().startsWith("Invalid retention policy"));
         }
     }
+
+    @Test
+    public void testNamespaceResourceGroup() {
+        String namespace = BrokerTestUtil.newUniqueName(this.testTenant + 
"/namespace");
+        ResourceGroup testResourceGroup = new ResourceGroup();
+        testResourceGroup.setDispatchRateInBytes(10000L);
+        testResourceGroup.setDispatchRateInMsgs(100);
+        testResourceGroup.setPublishRateInMsgs(100);
+        testResourceGroup.setPublishRateInBytes(10000L);
+        final String resourceGroupName = "test-resource-group";
+        try {

Review comment:
       This change will cause a compile error.




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