yuruguo opened a new issue #12822:
URL: https://github.com/apache/pulsar/issues/12822


   **Is your feature request related to a problem? Please describe.**
   CLI `bin/pulsar-admin` supports `set-clusters` and `get-clusters` command so 
that we can `set` / `get` replication clusters for a namespace. But it lacks 
corresponding `remove-clusters` command to restore to the unset state,  I think 
it is necessary to add this command to ensure the closed-loop operation of the 
replication cluster.
   
   **Describe the solution you'd like**
   #### In Client Side
   Add two methods `removeNamespaceReplicationClusters` and 
`removeNamespaceReplicationClustersAsync` in [Namespaces.java]( 
https://github.com/apache/pulsar/blob/master/pulsar-client-admin-api/src/main/java/org/apache/pulsar/client/admin/Namespaces.java)
   ```
       /**
        * Remove the replication clusters for a namespace.
        *
        * @param namespace
        * @throws PulsarAdminException
        */
       void removeNamespaceReplicationClusters(String namespace) throws 
PulsarAdminException;
   
       /**
        * Remove the replication clusters for a namespace asynchronously.
        *
        * @param namespace
        * @return
        */
       CompletableFuture<Void> removeNamespaceReplicationClustersAsync(String 
namespace);
   ```
   and implement them by calling an asynchronous delete request in 
[NamespacesImpl.java](https://github.com/apache/pulsar/blob/6ffd3602c0d144d012addcc47d1d2b1f38d1bb6c/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/NamespacesImpl.java)
   ```
       @Override
       public void removeNamespaceReplicationClusters(String namespace) throws 
PulsarAdminException {
           sync(() -> removeNamespaceReplicationClustersAsync(namespace));
       }
   
       @Override
       public CompletableFuture<Void> 
removeNamespaceReplicationClustersAsync(String namespace) {
           NamespaceName ns = NamespaceName.get(namespace);
           WebTarget path = namespacePath(ns, "replication");
           return asyncDeleteRequest(path);
       }
   ```
   #### In Server Side
   Add `removeNamespaceReplicationClusters` in  
[v1/Namespaces.java](https://github.com/apache/pulsar/blob/6ffd3602c0d144d012addcc47d1d2b1f38d1bb6c/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v1/Namespaces.java)
 and 
[v2/Namespaces.java](https://github.com/apache/pulsar/blob/6ffd3602c0d144d012addcc47d1d2b1f38d1bb6c/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/Namespaces.java)
   ```
       // for v1
       @DELETE
       @Path("/{property}/{cluster}/{namespace}/replication")
       @ApiOperation(value = "Remove the replication clusters for namespace")
       @ApiResponses(value = {@ApiResponse(code = 403, message = "Don't have 
admin permission"),
               @ApiResponse(code = 404, message = "Tenant or cluster or 
namespace doesn't exist"),
               @ApiResponse(code = 412, message = "Namespace is not global")})
       public void removeNamespaceReplicationClusters(@PathParam("property") 
String property,
                                                      @PathParam("cluster") 
String cluster,
                                                      @PathParam("namespace") 
String namespace) {
           validateNamespaceName(property, cluster, namespace);
           internalSetNamespaceReplicationClusters(Lists.newArrayList());
       }
   
       // for v2
       @DELETE
       @Path("/{tenant}/{namespace}/replication")
       @ApiOperation(value = "Remove the replication clusters for namespace")
       @ApiResponses(value = {@ApiResponse(code = 403, message = "Don't have 
admin permission"),
               @ApiResponse(code = 404, message = "Tenant or cluster or 
namespace doesn't exist"),
               @ApiResponse(code = 412, message = "Namespace is not global")})
       public void removeNamespaceReplicationClusters(@PathParam("tenant") 
String tenant,
                                                       @PathParam("namespace") 
String namespace) {
           validateNamespaceName(tenant, namespace);
           internalSetNamespaceReplicationClusters(Lists.newArrayList());
       }
   ```
   and they can reuse the `internalSetNamespaceReplicationClusters` method 
directly in 
[NamespacesBase.java](https://github.com/apache/pulsar/blob/6ffd3602c0d144d012addcc47d1d2b1f38d1bb6c/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java),
 just pass a `empty List`. The **important thing** is `replicationClusterSet` 
in method `internalSetNamespaceReplicationClusters` should be consistent with 
the initial value When creating replication clusters, its value is `empty 
hashSet` in v1/namespace
   
https://github.com/apache/pulsar/blob/3e6fedf9b69758c13d92c6ff75a7bd779038543a/pulsar-client-admin-api/src/main/java/org/apache/pulsar/common/policies/data/Policies.java#L38
   its value is `local cluster` in v2/namespace
   
https://github.com/apache/pulsar/blob/3e6fedf9b69758c13d92c6ff75a7bd779038543a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java#L2025-L2029
   So we modify the value of `replicationClusterSet` in method 
`internalSetNamespaceReplicationClusters` but this will not affect this method, 
as below:
   ```
       Set<String> replicationClusterSet = clusterIds.isEmpty()
                   ? Sets.newHashSet(namespaceName.isV2() ? 
config().getClusterName() : namespaceName.getCluster())
                   : Sets.newHashSet(clusterIds);
   ```
   


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