poorbarcode commented on code in PR #24390: URL: https://github.com/apache/pulsar/pull/24390#discussion_r2241978266
########## pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopicPolicies.java: ########## @@ -1993,6 +1998,67 @@ void run() throws PulsarAdminException { } } + @Command(description = "Set the replication clusters for a topic, global policy will be copied to the remote" + + " cluster if you enabled namespace level replication.") + private class SetReplicationClusters extends CliCommand { + @Parameters(description = "persistent://tenant/namespace/topic", arity = "1") + private String topicName; + + @Option(names = { "--clusters", + "-c" }, description = "Replication Cluster Ids list (comma separated values)", required = true) + private String clusterIds; + + @Option(names = { "--global", "-g" }, description = "Whether to set this policy globally. " + + "If set to true, the policy will be replicate to other clusters asynchronously") + private boolean isGlobal = false; + + @Override + void run() throws PulsarAdminException { + String persistentTopic = validatePersistentTopic(topicName); + List<String> clusters = Lists.newArrayList(clusterIds.split(",")); + getTopicPolicies(isGlobal).setReplicationClusters(persistentTopic, clusters); + } + } + + @Command(description = "Get the replication clusters for a topic") + private class GetReplicationClusters extends CliCommand { + @Parameters(description = "persistent://tenant/namespace/topic", arity = "1") + private String topicName; + + @Option(names = { "-ap", "--applied" }, description = "Get the applied policy of the topic. If set to true," + + " the param \"--global\" will be ignored. ") + private boolean applied = false; + + @Option(names = { "--global", "-g" }, description = "Whether to get this policy globally. " + + "If set to true, the policy will be replicate to other clusters asynchronously. " Review Comment: Thanks for mentioning this mistake, I have corrected it ########## pulsar-broker/src/main/java/org/apache/pulsar/broker/service/SystemTopicBasedTopicPoliciesService.java: ########## @@ -139,6 +139,17 @@ public SystemTopicBasedTopicPoliciesService(PulsarService pulsarService) { @Override public CompletableFuture<Void> deleteTopicPoliciesAsync(TopicName topicName) { + return deleteTopicPoliciesAsync(topicName, false); + } + + /** + * @param keepGlobalPoliciesAfterDeleting only be used when a topic was deleted because users removes current + * cluster from the policy "replicatedClusters". + * See also https://github.com/apache/pulsar/blob/master/pip/pip-422.md + */ + @Override + public CompletableFuture<Void> deleteTopicPoliciesAsync(TopicName topicName, + boolean keepGlobalPoliciesAfterDeleting) { Review Comment: Renamed ########## pulsar-broker/src/main/java/org/apache/pulsar/broker/service/TopicPoliciesService.java: ########## @@ -47,6 +51,16 @@ public interface TopicPoliciesService extends AutoCloseable { */ CompletableFuture<Void> deleteTopicPoliciesAsync(TopicName topicName); + default CompletableFuture<Void> deleteTopicPoliciesAsync(TopicName topicName, + boolean keepGlobalPoliciesAfterDeleting) { + if (keepGlobalPoliciesAfterDeleting) { + LOG.warn("The current implementation of TopicPoliciesService has not implemented the method" + + " deleteTopicPoliciesAsync(TopicName, boolean) yet, please implement it, see also" + + " https://github.com/apache/pulsar/blob/master/pip/pip-422.md"); Review Comment: Removed -- 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-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org