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 2020/04/06 11:37:32 UTC

[GitHub] [pulsar] codelipenghui commented on a change in pull request #6637: [pulsar-broker] Implement AutoSubscriptionCreation by namespace override

codelipenghui commented on a change in pull request #6637: [pulsar-broker] Implement AutoSubscriptionCreation by namespace override
URL: https://github.com/apache/pulsar/pull/6637#discussion_r404022980
 
 

 ##########
 File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java
 ##########
 @@ -653,6 +654,101 @@ protected void internalRemoveAutoTopicCreation(AsyncResponse asyncResponse) {
         });
     }
 
+    protected void internalSetAutoSubscriptionCreation(AsyncResponse asyncResponse, AutoSubscriptionCreationOverride autoSubscriptionCreationOverride) {
+        validateAdminAccessForTenant(namespaceName.getTenant());
+        validatePoliciesReadOnlyAccess();
+
+        // Force to read the data s.t. the watch to the cache content is setup.
+        policiesCache().getWithStatAsync(path(POLICIES, namespaceName.toString())).thenApply(
+                policies -> {
+                    if (policies.isPresent()) {
+                        Entry<Policies, Stat> policiesNode = policies.get();
+                        policiesNode.getKey().autoSubscriptionCreationOverride = autoSubscriptionCreationOverride;
+                        try {
+                            // Write back the new policies into zookeeper
+                            globalZk().setData(path(POLICIES, namespaceName.toString()),
+                                    jsonMapper().writeValueAsBytes(policiesNode.getKey()), policiesNode.getValue().getVersion());
 
 Review comment:
   It's better to call `setData()` asynchronously.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services