You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2018/04/18 21:32:15 UTC

[incubator-pulsar] branch master updated: On tenants cli tool, default tenant to all clusters if not specified (#1584)

This is an automated email from the ASF dual-hosted git repository.

mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 1334005  On tenants cli tool, default tenant to all clusters if not specified (#1584)
1334005 is described below

commit 1334005eda24564971343c42d0df3102fbe40039
Author: Matteo Merli <mm...@apache.org>
AuthorDate: Wed Apr 18 14:32:13 2018 -0700

    On tenants cli tool, default tenant to all clusters if not specified (#1584)
    
    * On tenants cli tool, default tenant to all clusters if not specified
    
    * Fixed handling of tenant info args in cli
---
 .../org/apache/pulsar/admin/cli/CmdTenants.java    | 46 ++++++++++++++++------
 .../pulsar/common/policies/data/TenantInfo.java    | 18 ++-------
 2 files changed, 38 insertions(+), 26 deletions(-)

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 98da636..e1cf4bb 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 @@ public class CmdTenants extends CmdBase {
         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 d65d94d..c03eb91 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 class TenantInfo {
     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;
-    }
-
 }

-- 
To stop receiving notification emails like this one, please contact
mmerli@apache.org.