merlimat closed pull request #1584: On tenants cli tool, default tenant to all 
clusters if not specified
URL: https://github.com/apache/incubator-pulsar/pull/1584
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTenants.java 
b/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTenants.java
index 98da636b7..e1cf4bb85 100644
--- 
a/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTenants.java
+++ 
b/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTenants.java
@@ -18,14 +18,17 @@
  */
 package org.apache.pulsar.admin.cli;
 
-import org.apache.pulsar.client.admin.PulsarAdmin;
-import org.apache.pulsar.client.admin.PulsarAdminException;
-import org.apache.pulsar.common.policies.data.TenantInfo;
-
 import com.beust.jcommander.Parameter;
 import com.beust.jcommander.Parameters;
 import com.beust.jcommander.converters.CommaParameterSplitter;
-import com.google.common.collect.Sets;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+
+import org.apache.pulsar.client.admin.PulsarAdmin;
+import org.apache.pulsar.client.admin.PulsarAdminException;
+import org.apache.pulsar.common.policies.data.TenantInfo;
 
 @Parameters(commandDescription = "Operations about tenants")
 public class CmdTenants extends CmdBase {
@@ -55,38 +58,57 @@ void run() throws PulsarAdminException {
         private java.util.List<String> params;
 
         @Parameter(names = { "--admin-roles",
-                "-r" }, description = "Comma separated Admin roles", required 
= true, splitter = CommaParameterSplitter.class)
+                "-r" }, description = "Comma separated list of auth principal 
allowed to administrate the tenant", required = false, splitter = 
CommaParameterSplitter.class)
         private java.util.List<String> adminRoles;
 
         @Parameter(names = { "--allowed-clusters",
-                "-c" }, description = "Comma separated allowed clusters", 
required = true, splitter = CommaParameterSplitter.class)
+                "-c" }, description = "Comma separated allowed clusters. If 
empty, the tenant will have access to all clusters", required = false, splitter 
= CommaParameterSplitter.class)
         private java.util.List<String> allowedClusters;
 
         @Override
         void run() throws PulsarAdminException {
             String tenant = getOneArgument(params);
-            TenantInfo tenantInfo = new 
TenantInfo(Sets.newHashSet(adminRoles), Sets.newHashSet(allowedClusters));
+
+            if (adminRoles == null) {
+                adminRoles = Collections.emptyList();
+            }
+
+            if (allowedClusters == null || allowedClusters.isEmpty()) {
+                // Default to all available cluster
+                allowedClusters = admin.clusters().getClusters();
+            }
+
+            TenantInfo tenantInfo = new TenantInfo(new HashSet<>(adminRoles), 
new HashSet<>(allowedClusters));
             admin.tenants().createTenant(tenant, tenantInfo);
         }
     }
 
-    @Parameters(commandDescription = "Updates a tenant")
+    @Parameters(commandDescription = "Updates the configuration for a tenant")
     private class Update extends CliCommand {
         @Parameter(description = "tenant-name", required = true)
         private java.util.List<String> params;
 
         @Parameter(names = { "--admin-roles",
-                "-r" }, description = "Comma separated Admin roles", required 
= true, splitter = CommaParameterSplitter.class)
+                "-r" }, description = "Comma separated list of auth principal 
allowed to administrate the tenant. If empty the current set of roles won't be 
modified", required = false, splitter = CommaParameterSplitter.class)
         private java.util.List<String> adminRoles;
 
         @Parameter(names = { "--allowed-clusters",
-                "-c" }, description = "Comma separated allowed clusters", 
required = true, splitter = CommaParameterSplitter.class)
+                "-c" }, description = "Comma separated allowed clusters. If 
omitted, the current set of clusters will be preserved", required = false, 
splitter = CommaParameterSplitter.class)
         private java.util.List<String> allowedClusters;
 
         @Override
         void run() throws PulsarAdminException {
             String tenant = getOneArgument(params);
-            TenantInfo tenantInfo = new 
TenantInfo(Sets.newHashSet(adminRoles), Sets.newHashSet(allowedClusters));
+
+            if (adminRoles == null) {
+                adminRoles = new 
ArrayList<>(admin.tenants().getTenantInfo(tenant).getAdminRoles());
+            }
+
+            if (allowedClusters == null) {
+                allowedClusters = new 
ArrayList<>(admin.tenants().getTenantInfo(tenant).getAllowedClusters());
+            }
+
+            TenantInfo tenantInfo = new TenantInfo(new HashSet<>(adminRoles), 
new HashSet<>(allowedClusters));
             admin.tenants().updateTenant(tenant, tenantInfo);
         }
     }
diff --git 
a/pulsar-common/src/main/java/org/apache/pulsar/common/policies/data/TenantInfo.java
 
b/pulsar-common/src/main/java/org/apache/pulsar/common/policies/data/TenantInfo.java
index d65d94db5..c03eb911f 100644
--- 
a/pulsar-common/src/main/java/org/apache/pulsar/common/policies/data/TenantInfo.java
+++ 
b/pulsar-common/src/main/java/org/apache/pulsar/common/policies/data/TenantInfo.java
@@ -18,14 +18,16 @@
  */
 package org.apache.pulsar.common.policies.data;
 
-import java.util.Objects;
+import com.google.common.collect.Sets;
+
 import java.util.Set;
 
 import javax.xml.bind.annotation.XmlRootElement;
 
-import com.google.common.collect.Sets;
+import lombok.Data;
 
 @XmlRootElement
+@Data
 public class TenantInfo {
     /**
      * List of role enabled as admin for this tenant
@@ -62,16 +64,4 @@ public void setAdminRoles(Set<String> adminRoles) {
     public void setAllowedClusters(Set<String> allowedClusters) {
         this.allowedClusters = allowedClusters;
     }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (obj instanceof TenantInfo) {
-            TenantInfo other = (TenantInfo) obj;
-            return Objects.equals(adminRoles, other.adminRoles)
-                    && Objects.equals(allowedClusters, other.allowedClusters);
-        }
-
-        return false;
-    }
-
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to