shibd commented on code in PR #15857:
URL: https://github.com/apache/pulsar/pull/15857#discussion_r887442701
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/NamespacesBase.java:
##########
@@ -2201,28 +2201,27 @@ protected Integer
internalGetMaxConsumersPerSubscription() {
return
getNamespacePolicies(namespaceName).max_consumers_per_subscription;
}
- protected void internalSetMaxConsumersPerSubscription(Integer
maxConsumersPerSubscription) {
- validateNamespacePolicyOperation(namespaceName,
PolicyName.MAX_CONSUMERS, PolicyOperation.WRITE);
- validatePoliciesReadOnlyAccess();
+ protected CompletableFuture<Void>
internalSetMaxConsumersPerSubscription(Integer maxConsumersPerSubscription) {
- try {
- if (maxConsumersPerSubscription != null &&
maxConsumersPerSubscription < 0) {
- throw new RestException(Status.PRECONDITION_FAILED,
- "maxConsumersPerSubscription must be 0 or more");
- }
- updatePolicies(namespaceName, policies -> {
- policies.max_consumers_per_subscription =
maxConsumersPerSubscription;
- return policies;
- });
- log.info("[{}] Successfully updated maxConsumersPerSubscription
configuration: namespace={}, value={}",
- clientAppId(), namespaceName, maxConsumersPerSubscription);
- } catch (RestException pfe) {
- throw pfe;
- } catch (Exception e) {
- log.error("[{}] Failed to update maxConsumersPerSubscription
configuration for namespace {}",
- clientAppId(), namespaceName, e);
- throw new RestException(e);
- }
+ CompletableFuture<Void> ret;
+ ret = validateNamespacePolicyOperationAsync(namespaceName,
PolicyName.MAX_CONSUMERS, PolicyOperation.WRITE)
+ .thenCompose(__ -> validatePoliciesReadOnlyAccessAsync())
+ .thenCompose(__ -> {
+ if (maxConsumersPerSubscription != null &&
maxConsumersPerSubscription < 0) {
+ throw new RestException(Status.PRECONDITION_FAILED,
+ "maxConsumersPerSubscription must be 0 or
more");
+ }
+ return updatePoliciesAsync(namespaceName, policies -> {
+ policies.max_consumers_per_subscription =
maxConsumersPerSubscription;
+ return policies;
+ });
+
+ }).exceptionally(ex -> {
+ Throwable realCause =
FutureUtil.unwrapCompletionException(ex);
Review Comment:
Exceptions can be handled in the rest layer
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v1/Namespaces.java:
##########
@@ -1251,11 +1251,21 @@ public Integer
getMaxConsumersPerSubscription(@PathParam("property") String prop
@ApiResponse(code = 409, message = "Concurrent modification"),
@ApiResponse(code = 412, message = "maxConsumersPerSubscription
value is not valid")})
public void setMaxConsumersPerSubscription(
+ @Suspended final AsyncResponse asyncResponse,
@PathParam("property") String property,
@PathParam("cluster") String cluster,
@PathParam("namespace") String namespace, int
maxConsumersPerSubscription) {
validateNamespaceName(property, cluster, namespace);
- internalSetMaxConsumersPerSubscription(maxConsumersPerSubscription);
+
internalSetMaxConsumersPerSubscription(maxConsumersPerSubscription).thenAccept(
+ __ ->
asyncResponse.resume(Response.noContent().build()))
+ .exceptionally(ex -> {
+ if (!isRedirectException(ex)) {
Review Comment:
The original logic does not have this judgment condition.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]