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/05/03 21:04:26 UTC

[incubator-pulsar] branch master updated: Fixed clusters REST API to omit "global" cluster in response (#1725)

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 ea07ee1  Fixed clusters REST API to omit "global" cluster in response (#1725)
ea07ee1 is described below

commit ea07ee112d0e5803698dc16d752fa67846a8eab0
Author: Matteo Merli <mm...@apache.org>
AuthorDate: Thu May 3 14:04:23 2018 -0700

    Fixed clusters REST API to omit "global" cluster in response (#1725)
---
 .../pulsar/broker/admin/impl/ClustersBase.java     | 33 +++++++++++++---------
 .../apache/pulsar/broker/admin/AdminApiTest2.java  |  3 ++
 2 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/ClustersBase.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/ClustersBase.java
index 69b8a9b..3fcb7d6 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/ClustersBase.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/ClustersBase.java
@@ -19,6 +19,16 @@
 package org.apache.pulsar.broker.admin.impl;
 
 import static org.apache.pulsar.broker.cache.ConfigurationCacheService.POLICIES;
+import static org.apache.pulsar.broker.namespace.NamespaceService.NAMESPACE_ISOLATION_POLICIES;
+
+import com.fasterxml.jackson.core.JsonGenerationException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
 
 import java.io.IOException;
 import java.util.Collections;
@@ -40,8 +50,8 @@ import javax.ws.rs.core.Response.Status;
 import org.apache.bookkeeper.util.ZkUtils;
 import org.apache.pulsar.broker.admin.AdminResource;
 import org.apache.pulsar.broker.cache.ConfigurationCacheService;
-import static org.apache.pulsar.broker.namespace.NamespaceService.NAMESPACE_ISOLATION_POLICIES;
 import org.apache.pulsar.broker.web.RestException;
+import org.apache.pulsar.common.naming.Constants;
 import org.apache.pulsar.common.naming.NamedEntity;
 import org.apache.pulsar.common.policies.data.BrokerNamespaceIsolationData;
 import org.apache.pulsar.common.policies.data.ClusterData;
@@ -57,15 +67,6 @@ import org.apache.zookeeper.data.Stat;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.fasterxml.jackson.core.JsonGenerationException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiResponse;
-import io.swagger.annotations.ApiResponses;
-
 public class ClustersBase extends AdminResource {
 
     @GET
@@ -73,7 +74,11 @@ public class ClustersBase extends AdminResource {
     @ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission") })
     public Set<String> getClusters() throws Exception {
         try {
-            return clustersListCache().get();
+            Set<String> clusters = clustersListCache().get();
+
+            // Remove "global" cluster from returned list
+            clusters.remove(Constants.GLOBAL_CLUSTER);
+            return clusters;
         } catch (Exception e) {
             log.error("[{}] Failed to get clusters list", clientAppId(), e);
             throw new RestException(e);
@@ -238,7 +243,7 @@ public class ClustersBase extends AdminResource {
 			throw new RestException(e);
 		}
 	}
-    
+
     @DELETE
     @Path("/{cluster}")
     @ApiOperation(value = "Delete an existing cluster")
@@ -476,7 +481,7 @@ public class ClustersBase extends AdminResource {
         }
         return brokerIsolationData;
     }
-    
+
     @POST
     @Path("/{cluster}/namespaceIsolationPolicies/{policyName}")
     @ApiOperation(value = "Set namespace isolation policy")
@@ -537,7 +542,7 @@ public class ClustersBase extends AdminResource {
                 return true;
             } catch (KeeperException.NodeExistsException nee) {
                 if(log.isDebugEnabled()) {
-                    log.debug("Other broker preempted the full path [{}] already. Continue...", path);                    
+                    log.debug("Other broker preempted the full path [{}] already. Continue...", path);
                 }
             } catch (JsonGenerationException e) {
                 // ignore json error as it is empty hash
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest2.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest2.java
index 73dc79c..8df9348 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest2.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest2.java
@@ -873,6 +873,9 @@ public class AdminApiTest2 extends MockedPulsarServiceBaseTest {
     @Test
     public void clustersList() throws PulsarAdminException {
         final String cluster = pulsar.getConfiguration().getClusterName();
+        admin.clusters().createCluster("global", new ClusterData("http://localhost:6650"));
+
+        // Global cluster, if there, should be omitted from the results
         assertEquals(admin.clusters().getClusters(), Lists.newArrayList(cluster));
     }
 }

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