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

rdhabalia 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 7b07fce  Add get-peer clusters admin api (#1268)
7b07fce is described below

commit 7b07fce3ccf633f705b5bbe1de3248c5abdcac10
Author: Rajan Dhabalia <rdhaba...@apache.org>
AuthorDate: Thu Feb 22 11:06:19 2018 -0800

    Add get-peer clusters admin api (#1268)
---
 .../pulsar/broker/admin/impl/ClustersBase.java     | 22 +++++++++++++++++++++
 .../pulsar/broker/service/PeerReplicatorTest.java  | 19 ++++++++++++++++++
 .../org/apache/pulsar/client/admin/Clusters.java   | 23 ++++++++++++++++++++++
 .../pulsar/client/admin/internal/ClustersImpl.java | 10 ++++++++++
 .../org/apache/pulsar/admin/cli/CmdClusters.java   | 14 +++++++++++++
 .../pulsar/admin/cli/PulsarAdminToolTest.java      |  3 +++
 6 files changed, 91 insertions(+)

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 733105a..de670c1 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
@@ -213,6 +213,28 @@ public class ClustersBase extends AdminResource {
         }
     }
 
+       @GET
+       @Path("/{cluster}/peers")
+       @ApiOperation(value = "Get the peer-cluster data for the specified 
cluster.", response = Set.class)
+       @ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have 
admin permission"),
+                       @ApiResponse(code = 404, message = "Cluster doesn't 
exist") })
+       public Set<String> getPeerCluster(@PathParam("cluster") String cluster) 
{
+               validateSuperUserAccess();
+
+               try {
+                       String clusterPath = path("clusters", cluster);
+                       byte[] content = globalZk().getData(clusterPath, null, 
null);
+                       ClusterData clusterData = 
jsonMapper().readValue(content, ClusterData.class);
+                       return clusterData.getPeerClusterNames();
+               } catch (KeeperException.NoNodeException e) {
+                       log.warn("[{}] Failed to get cluster {}: Does not 
exist", clientAppId(), cluster);
+                       throw new RestException(Status.NOT_FOUND, "Cluster does 
not exist");
+               } catch (Exception e) {
+                       log.error("[{}] Failed to get cluster {}", 
clientAppId(), cluster, e);
+                       throw new RestException(e);
+               }
+       }
+    
     @DELETE
     @Path("/{cluster}")
     @ApiOperation(value = "Delete an existing cluster")
diff --git 
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PeerReplicatorTest.java
 
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PeerReplicatorTest.java
index c344af5..d5456fc 100644
--- 
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PeerReplicatorTest.java
+++ 
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PeerReplicatorTest.java
@@ -18,13 +18,16 @@
  */
 package org.apache.pulsar.broker.service;
 
+import static 
org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest.retryStrategically;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.fail;
 
+import java.util.LinkedHashSet;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.pulsar.broker.service.persistent.PersistentTopic;
+import org.apache.pulsar.client.admin.PulsarAdminException;
 import org.apache.pulsar.client.api.ClientConfiguration;
 import org.apache.pulsar.client.api.Producer;
 import org.apache.pulsar.client.api.PulsarClient;
@@ -151,6 +154,22 @@ public class PeerReplicatorTest extends ReplicatorTestBase 
{
 
     }
 
+       @Test
+       public void testGetPeerClusters() throws Exception {
+               final String mainClusterName = "r1";
+               
assertEquals(admin1.clusters().getPeerClusterNames(mainClusterName), null);
+               LinkedHashSet<String> peerClusters = 
Sets.newLinkedHashSet(Lists.newArrayList("r2", "r3"));
+               admin1.clusters().updatePeerClusterNames(mainClusterName, 
peerClusters);
+               retryStrategically((test) -> {
+                       try {
+                               return 
admin1.clusters().getPeerClusterNames(mainClusterName).size() == 1;
+                       } catch (PulsarAdminException e) {
+                               return false;
+                       }
+               }, 5, 100);
+               
assertEquals(admin1.clusters().getPeerClusterNames(mainClusterName), 
peerClusters);
+       }
+    
     private static final Logger log = 
LoggerFactory.getLogger(PeerReplicatorTest.class);
 
 }
diff --git 
a/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/Clusters.java
 
b/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/Clusters.java
index 779e7b1..4048367 100644
--- 
a/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/Clusters.java
+++ 
b/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/Clusters.java
@@ -21,6 +21,7 @@ package org.apache.pulsar.client.admin;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.pulsar.client.admin.PulsarAdminException.ConflictException;
 import 
org.apache.pulsar.client.admin.PulsarAdminException.NotAuthorizedException;
@@ -133,6 +134,28 @@ public interface Clusters {
      *             Unexpected error
      */
     void updatePeerClusterNames(String cluster, LinkedHashSet<String> 
peerClusterNames) throws PulsarAdminException;
+    
+    /**
+     * Get peer-cluster names
+     * <p>
+     *
+     * @param cluster
+     *            Cluster name
+     * @return
+     * @throws NotAuthorizedException
+     *             You don't have admin permission to create the cluster
+     *
+     * @throws NotFoundException
+     *             Domain doesn't exist
+     *
+     * @throws PreconditionFailedException
+     *             Cluster doesn't exist
+     *
+     * @throws PulsarAdminException
+     *             Unexpected error
+     */
+    Set<String> getPeerClusterNames(String cluster) throws 
PulsarAdminException;
+    
 
     /**
      * Delete an existing cluster
diff --git 
a/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/ClustersImpl.java
 
b/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/ClustersImpl.java
index 666a2e8..fcbf012 100644
--- 
a/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/ClustersImpl.java
+++ 
b/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/ClustersImpl.java
@@ -21,6 +21,7 @@ package org.apache.pulsar.client.admin.internal;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import javax.ws.rs.client.Entity;
 import javax.ws.rs.client.WebTarget;
@@ -94,6 +95,15 @@ public class ClustersImpl extends BaseResource implements 
Clusters {
         
     }
 
+       @Override
+       public Set<String> getPeerClusterNames(String cluster) throws 
PulsarAdminException {
+               try {
+                       return 
request(clusters.path(cluster).path("peers")).get(LinkedHashSet.class);
+               } catch (Exception e) {
+                       throw getApiException(e);
+               }
+       }
+    
     @Override
     public void deleteCluster(String cluster) throws PulsarAdminException {
         try {
diff --git 
a/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdClusters.java
 
b/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdClusters.java
index 5ba6c10..88f3b3f 100644
--- 
a/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdClusters.java
+++ 
b/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdClusters.java
@@ -127,6 +127,19 @@ public class CmdClusters extends CmdBase {
         }
     }
 
+    @Parameters(commandDescription = "Get list of peer-clusters")
+    private class GetPeerClusters extends CliCommand {
+        
+        @Parameter(description = "cluster-name\n", required = true)
+        private java.util.List<String> params;
+        
+        void run() throws PulsarAdminException {
+            String cluster = getOneArgument(params);
+            print(admin.clusters().getPeerClusterNames(cluster));
+        }
+    }
+    
+    
     @Parameters(commandDescription = "Create a new failure-domain for a 
cluster. updates it if already created.")
     private class CreateFailureDomain extends CliCommand {
         @Parameter(description = "cluster-name\n", required = true)
@@ -213,6 +226,7 @@ public class CmdClusters extends CmdBase {
         jcommander.addCommand("delete", new Delete());
         jcommander.addCommand("list", new List());
         jcommander.addCommand("update-peer-clusters", new 
UpdatePeerClusters());
+        jcommander.addCommand("get-peer-clusters", new GetPeerClusters());
         jcommander.addCommand("get-failure-domain", new GetFailureDomain());
         jcommander.addCommand("create-failure-domain", new 
CreateFailureDomain());
         jcommander.addCommand("update-failure-domain", new 
UpdateFailureDomain());
diff --git 
a/pulsar-client-tools/src/test/java/org/apache/pulsar/admin/cli/PulsarAdminToolTest.java
 
b/pulsar-client-tools/src/test/java/org/apache/pulsar/admin/cli/PulsarAdminToolTest.java
index 6328f41..16d0785 100644
--- 
a/pulsar-client-tools/src/test/java/org/apache/pulsar/admin/cli/PulsarAdminToolTest.java
+++ 
b/pulsar-client-tools/src/test/java/org/apache/pulsar/admin/cli/PulsarAdminToolTest.java
@@ -175,6 +175,9 @@ public class PulsarAdminToolTest {
 
         clusters.run(split("update-peer-clusters my-cluster --peer-clusters 
c1,c2"));
         verify(mockClusters).updatePeerClusterNames("my-cluster", 
Sets.newLinkedHashSet(Lists.newArrayList("c1", "c2")));
+        
+        clusters.run(split("get-peer-clusters my-cluster"));
+        verify(mockClusters).getPeerClusterNames("my-cluster");
     }
 
     @Test

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

Reply via email to