You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2018/03/29 21:10:13 UTC

[GitHub] merlimat closed pull request #1471: Add admin v2 support for clusters, brokers, and resources quotas.

merlimat closed pull request #1471: Add admin v2 support for clusters, brokers, and resources quotas.
URL: https://github.com/apache/incubator-pulsar/pull/1471
 
 
   

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-admin/src/main/java/org/apache/pulsar/client/admin/internal/BrokersImpl.java b/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/BrokersImpl.java
index f5c5b3d75..52270d3c2 100644
--- a/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/BrokersImpl.java
+++ b/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/BrokersImpl.java
@@ -37,7 +37,7 @@
 
     public BrokersImpl(WebTarget web, Authentication auth) {
         super(auth);
-        adminBrokers = web.path("/admin/brokers");
+        adminBrokers = web.path("/admin/v2/brokers");
     }
 
     @Override
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 9bf8e6bef..562fbee7f 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
@@ -39,11 +39,10 @@
 public class ClustersImpl extends BaseResource implements Clusters {
 
     private final WebTarget adminClusters;
-    //private final WebTarget clusters;
 
     public ClustersImpl(WebTarget web, Authentication auth) {
         super(auth);
-        adminClusters = web.path("/admin/clusters");
+        adminClusters = web.path("/admin/v2/clusters");
     }
 
     @Override
diff --git a/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/ResourceQuotasImpl.java b/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/ResourceQuotasImpl.java
index bd5369415..d96b643dd 100644
--- a/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/ResourceQuotasImpl.java
+++ b/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/ResourceQuotasImpl.java
@@ -32,15 +32,17 @@
 public class ResourceQuotasImpl extends BaseResource implements ResourceQuotas {
 
     private final WebTarget adminQuotas;
+    private final WebTarget adminV2Quotas;
 
     public ResourceQuotasImpl(WebTarget web, Authentication auth) {
         super(auth);
         adminQuotas = web.path("/admin/resource-quotas");
+        adminV2Quotas = web.path("/admin/v2/resource-quotas");
     }
 
     public ResourceQuota getDefaultResourceQuota() throws PulsarAdminException {
         try {
-            return request(adminQuotas).get(ResourceQuota.class);
+            return request(adminV2Quotas).get(ResourceQuota.class);
         } catch (Exception e) {
             throw getApiException(e);
         }
@@ -48,7 +50,7 @@ public ResourceQuota getDefaultResourceQuota() throws PulsarAdminException {
 
     public void setDefaultResourceQuota(ResourceQuota quota) throws PulsarAdminException {
         try {
-            request(adminQuotas).post(Entity.entity(quota, MediaType.APPLICATION_JSON), ErrorData.class);
+            request(adminV2Quotas).post(Entity.entity(quota, MediaType.APPLICATION_JSON), ErrorData.class);
         } catch (Exception e) {
             throw getApiException(e);
         }
@@ -57,9 +59,8 @@ public void setDefaultResourceQuota(ResourceQuota quota) throws PulsarAdminExcep
     public ResourceQuota getNamespaceBundleResourceQuota(String namespace, String bundle) throws PulsarAdminException {
         try {
             NamespaceName ns = NamespaceName.get(namespace);
-            return request(
-                    adminQuotas.path(ns.getProperty()).path(ns.getCluster()).path(ns.getLocalName()).path(bundle))
-                    .get(ResourceQuota.class);
+            WebTarget path = namespacePath(ns, bundle);
+            return request(path).get(ResourceQuota.class);
         } catch (Exception e) {
             throw getApiException(e);
         }
@@ -69,9 +70,8 @@ public void setNamespaceBundleResourceQuota(String namespace, String bundle, Res
             throws PulsarAdminException {
         try {
             NamespaceName ns = NamespaceName.get(namespace);
-            request(
-                    adminQuotas.path(ns.getProperty()).path(ns.getCluster()).path(ns.getLocalName()).path(bundle))
-                    .post(Entity.entity(quota, MediaType.APPLICATION_JSON), ErrorData.class);
+            WebTarget path = namespacePath(ns, bundle);
+            request(path).post(Entity.entity(quota, MediaType.APPLICATION_JSON), ErrorData.class);
         } catch (Exception e) {
             throw getApiException(e);
         }
@@ -80,12 +80,18 @@ public void setNamespaceBundleResourceQuota(String namespace, String bundle, Res
     public void resetNamespaceBundleResourceQuota(String namespace, String bundle) throws PulsarAdminException {
         try {
             NamespaceName ns = NamespaceName.get(namespace);
-            request(
-                    adminQuotas.path(ns.getProperty()).path(ns.getCluster()).path(ns.getLocalName()).path(bundle))
-                    .delete();
+            WebTarget path = namespacePath(ns, bundle);
+            request(path).delete();
         } catch (Exception e) {
             throw getApiException(e);
         }
     }
+
+    private WebTarget namespacePath(NamespaceName namespace, String... parts) {
+        final WebTarget base = namespace.isV2() ? adminV2Quotas : adminQuotas;
+        WebTarget namespacePath = base.path(namespace.toString());
+        namespacePath = WebTargets.addParts(namespacePath, parts);
+        return namespacePath;
+    }
 }
 


 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services