Skip to content

Commit

Permalink
[improve][broker][PIP-149]make getBacklogQuotaMap method async in Nam…
Browse files Browse the repository at this point in the history
…espaces (apache#16504)
  • Loading branch information
HQebupt authored and weimob-wuxuanqi committed Jul 14, 2022
1 parent b55a8fa commit 03c6dc4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import javax.ws.rs.Consumes;
Expand Down Expand Up @@ -1076,14 +1075,20 @@ public void getReplicatorDispatchRate(
@ApiOperation(hidden = true, value = "Get backlog quota map on a namespace.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"),
@ApiResponse(code = 404, message = "Namespace does not exist") })
public Map<BacklogQuotaType, BacklogQuota> getBacklogQuotaMap(@PathParam("property") String property,
public void getBacklogQuotaMap(
@Suspended final AsyncResponse asyncResponse,
@PathParam("property") String property,
@PathParam("cluster") String cluster, @PathParam("namespace") String namespace) {
validateNamespaceName(property, cluster, namespace);
validateNamespacePolicyOperation(NamespaceName.get(property, namespace),
PolicyName.BACKLOG, PolicyOperation.READ);

Policies policies = getNamespacePolicies(namespaceName);
return policies.backlog_quota_map;
validateNamespacePolicyOperationAsync(namespaceName, PolicyName.BACKLOG,
PolicyOperation.READ)
.thenCompose(__ -> getNamespacePoliciesAsync(namespaceName))
.thenAccept(policies -> asyncResponse.resume(policies.backlog_quota_map))
.exceptionally(ex -> {
log.error("[{}] Failed to get backlog quota map on namespace {}", clientAppId(), namespaceName, ex);
resumeAsyncResponseExceptionally(asyncResponse, ex);
return null;
});
}

@POST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1121,13 +1121,20 @@ public void getReplicatorDispatchRate(
@ApiOperation(value = "Get backlog quota map on a namespace.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"),
@ApiResponse(code = 404, message = "Namespace does not exist") })
public Map<BacklogQuotaType, BacklogQuota> getBacklogQuotaMap(@PathParam("tenant") String tenant,
public void getBacklogQuotaMap(
@Suspended final AsyncResponse asyncResponse,
@PathParam("tenant") String tenant,
@PathParam("namespace") String namespace) {
validateNamespaceName(tenant, namespace);
validateNamespacePolicyOperation(
NamespaceName.get(tenant, namespace), PolicyName.BACKLOG, PolicyOperation.READ);
Policies policies = getNamespacePolicies(namespaceName);
return policies.backlog_quota_map;
validateNamespacePolicyOperationAsync(namespaceName, PolicyName.BACKLOG,
PolicyOperation.READ)
.thenCompose(__ -> getNamespacePoliciesAsync(namespaceName))
.thenAccept(policies -> asyncResponse.resume(policies.backlog_quota_map))
.exceptionally(ex -> {
log.error("[{}] Failed to get backlog quota map on namespace {}", clientAppId(), namespaceName, ex);
resumeAsyncResponseExceptionally(asyncResponse, ex);
return null;
});
}

@POST
Expand Down

0 comments on commit 03c6dc4

Please sign in to comment.