You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by yo...@apache.org on 2021/12/23 14:41:09 UTC
[pulsar] 03/08: [Broker] Modify return result of NamespacesBase#internalGetPublishRate (#13237)
This is an automated email from the ASF dual-hosted git repository.
yong pushed a commit to branch branch-2.8
in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit a98c52bc6841cd48c8ec87f2982f0a89b547789f
Author: Ruguo Yu <ji...@163.com>
AuthorDate: Wed Dec 15 15:54:41 2021 +0800
[Broker] Modify return result of NamespacesBase#internalGetPublishRate (#13237)
### Motivation
It should return `null` instead of `RestException` in method `NamespacesBase#internalGetPublishRate`, because `null` means that the `publish-rate` is not configured.
It is the same as `internalGetSubscriptionDispatchRate` as below:
https://github.com/apache/pulsar/blob/6d9d24d50db5418ddbb845d2c7a2be2b9ac72893/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java#L1303-L1308
(cherry picked from commit 3e55b4f2c40ecd73bb38962cebc4a822bfe5f1ef)
---
.../apache/pulsar/broker/admin/impl/NamespacesBase.java | 8 +-------
.../org/apache/pulsar/broker/admin/v1/Namespaces.java | 15 ++++++++++-----
.../org/apache/pulsar/broker/admin/v2/Namespaces.java | 15 ++++++++++-----
.../client/api/AuthorizationProducerConsumerTest.java | 2 ++
4 files changed, 23 insertions(+), 17 deletions(-)
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java
index 5d78216..3d67008 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java
@@ -1198,13 +1198,7 @@ public abstract class NamespacesBase extends AdminResource {
validateNamespacePolicyOperation(namespaceName, PolicyName.RATE, PolicyOperation.READ);
Policies policies = getNamespacePolicies(namespaceName);
- PublishRate publishRate = policies.publishMaxMessageRate.get(pulsar().getConfiguration().getClusterName());
- if (publishRate != null) {
- return publishRate;
- } else {
- throw new RestException(Status.NOT_FOUND,
- "Publish-rate is not configured for cluster " + pulsar().getConfiguration().getClusterName());
- }
+ return policies.publishMaxMessageRate.get(pulsar().getConfiguration().getClusterName());
}
@SuppressWarnings("deprecation")
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v1/Namespaces.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v1/Namespaces.java
index 529b8ce..9fec59c 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v1/Namespaces.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v1/Namespaces.java
@@ -624,7 +624,8 @@ public class Namespaces extends NamespacesBase {
@GET
@Path("/{property}/{cluster}/{namespace}/publishRate")
@ApiOperation(hidden = true,
- value = "Get publish-rate configured for the namespace, -1 represents not configured yet")
+ value = "Get publish-rate configured for the namespace, null means publish-rate not configured, "
+ + "-1 means msg-publish-rate or byte-publish-rate not configured in publish-rate yet")
@ApiResponses(value = {@ApiResponse(code = 403, message = "Don't have admin permission"),
@ApiResponse(code = 404, message = "Namespace does not exist")})
public PublishRate getPublishRate(@PathParam("property") String property, @PathParam("cluster") String cluster,
@@ -646,7 +647,8 @@ public class Namespaces extends NamespacesBase {
@GET
@Path("/{property}/{cluster}/{namespace}/dispatchRate")
@ApiOperation(hidden = true,
- value = "Get dispatch-rate configured for the namespace, -1 represents not configured yet")
+ value = "Get dispatch-rate configured for the namespace, null means dispatch-rate not configured, "
+ + "-1 means msg-dispatch-rate or byte-dispatch-rate not configured in dispatch-rate yet")
@ApiResponses(value = {@ApiResponse(code = 403, message = "Don't have admin permission"),
@ApiResponse(code = 404, message = "Namespace does not exist")})
public DispatchRate getDispatchRate(@PathParam("property") String property, @PathParam("cluster") String cluster,
@@ -669,8 +671,9 @@ public class Namespaces extends NamespacesBase {
@GET
@Path("/{property}/{cluster}/{namespace}/subscriptionDispatchRate")
- @ApiOperation(value =
- "Get Subscription dispatch-rate configured for the namespace, -1 represents not configured yet")
+ @ApiOperation(value = "Get subscription dispatch-rate configured for the namespace, null means subscription "
+ + "dispatch-rate not configured, -1 means msg-dispatch-rate or byte-dispatch-rate not configured "
+ + "in dispatch-rate yet")
@ApiResponses(value = {@ApiResponse(code = 403, message = "Don't have admin permission"),
@ApiResponse(code = 404, message = "Namespace does not exist")})
public DispatchRate getSubscriptionDispatchRate(@PathParam("property") String property,
@@ -695,7 +698,9 @@ public class Namespaces extends NamespacesBase {
@GET
@Path("/{tenant}/{cluster}/{namespace}/replicatorDispatchRate")
- @ApiOperation(value = "Get replicator dispatch-rate configured for the namespace, -1 represents not configured yet")
+ @ApiOperation(value = "Get replicator dispatch-rate configured for the namespace, null means replicator "
+ + "dispatch-rate not configured, -1 means msg-dispatch-rate or byte-dispatch-rate not configured "
+ + "in dispatch-rate yet")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"),
@ApiResponse(code = 404, message = "Namespace does not exist") })
public DispatchRate getReplicatorDispatchRate(@PathParam("tenant") String tenant,
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/Namespaces.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/Namespaces.java
index f9515e3..ed5d9e1 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/Namespaces.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/Namespaces.java
@@ -565,7 +565,8 @@ public class Namespaces extends NamespacesBase {
@GET
@Path("/{property}/{namespace}/publishRate")
@ApiOperation(hidden = true,
- value = "Get publish-rate configured for the namespace, -1 represents not configured yet")
+ value = "Get publish-rate configured for the namespace, null means publish-rate not configured, "
+ + "-1 means msg-publish-rate or byte-publish-rate not configured in publish-rate yet")
@ApiResponses(value = {@ApiResponse(code = 403, message = "Don't have admin permission"),
@ApiResponse(code = 404, message = "Namespace does not exist")})
public PublishRate getPublishRate(
@@ -597,7 +598,8 @@ public class Namespaces extends NamespacesBase {
@GET
@Path("/{tenant}/{namespace}/dispatchRate")
- @ApiOperation(value = "Get dispatch-rate configured for the namespace, -1 represents not configured yet")
+ @ApiOperation(value = "Get dispatch-rate configured for the namespace, null means dispatch-rate not configured, "
+ + "-1 means msg-dispatch-rate or byte-dispatch-rate not configured in dispatch-rate yet")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"),
@ApiResponse(code = 404, message = "Namespace does not exist") })
public DispatchRate getDispatchRate(@PathParam("tenant") String tenant,
@@ -620,8 +622,9 @@ public class Namespaces extends NamespacesBase {
@GET
@Path("/{tenant}/{namespace}/subscriptionDispatchRate")
- @ApiOperation(
- value = "Get Subscription dispatch-rate configured for the namespace, -1 represents not configured yet")
+ @ApiOperation(value = "Get subscription dispatch-rate configured for the namespace, null means subscription "
+ + "dispatch-rate not configured, -1 means msg-dispatch-rate or byte-dispatch-rate not configured "
+ + "in dispatch-rate yet")
@ApiResponses(value = {@ApiResponse(code = 403, message = "Don't have admin permission"),
@ApiResponse(code = 404, message = "Namespace does not exist")})
public DispatchRate getSubscriptionDispatchRate(@PathParam("tenant") String tenant,
@@ -695,7 +698,9 @@ public class Namespaces extends NamespacesBase {
@GET
@Path("/{tenant}/{namespace}/replicatorDispatchRate")
- @ApiOperation(value = "Get replicator dispatch-rate configured for the namespace, -1 represents not configured yet")
+ @ApiOperation(value = "Get replicator dispatch-rate configured for the namespace, null means replicator "
+ + "dispatch-rate not configured, -1 means msg-dispatch-rate or byte-dispatch-rate not configured "
+ + "in dispatch-rate yet")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"),
@ApiResponse(code = 404, message = "Namespace does not exist") })
public DispatchRate getReplicatorDispatchRate(@PathParam("tenant") String tenant,
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/AuthorizationProducerConsumerTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/AuthorizationProducerConsumerTest.java
index 8807f11..475dc8d 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/client/api/AuthorizationProducerConsumerTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/client/api/AuthorizationProducerConsumerTest.java
@@ -22,6 +22,7 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.mockito.Mockito.spy;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import com.google.common.collect.Lists;
@@ -207,6 +208,7 @@ public class AuthorizationProducerConsumerTest extends ProducerConsumerBase {
superAdmin.tenants().createTenant("my-property",
new TenantInfoImpl(Sets.newHashSet(tenantRole), Sets.newHashSet("test")));
superAdmin.namespaces().createNamespace(namespace, Sets.newHashSet("test"));
+ assertNull(superAdmin.namespaces().getPublishRate(namespace));
// subscriptionRole doesn't have topic-level authorization, so it will fail to get topic stats-internal info
try {