Skip to content

Commit a03800a

Browse files
authored
[improve][broker][PIP-149]make getBacklogQuotaMap method async in Namespaces (#16504)
1 parent 147672f commit a03800a

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v1/Namespaces.java

+12-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import io.swagger.annotations.ApiResponse;
2727
import io.swagger.annotations.ApiResponses;
2828
import java.util.List;
29-
import java.util.Map;
3029
import java.util.Set;
3130
import java.util.concurrent.CompletableFuture;
3231
import javax.ws.rs.Consumes;
@@ -1076,14 +1075,20 @@ public void getReplicatorDispatchRate(
10761075
@ApiOperation(hidden = true, value = "Get backlog quota map on a namespace.")
10771076
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"),
10781077
@ApiResponse(code = 404, message = "Namespace does not exist") })
1079-
public Map<BacklogQuotaType, BacklogQuota> getBacklogQuotaMap(@PathParam("property") String property,
1078+
public void getBacklogQuotaMap(
1079+
@Suspended final AsyncResponse asyncResponse,
1080+
@PathParam("property") String property,
10801081
@PathParam("cluster") String cluster, @PathParam("namespace") String namespace) {
10811082
validateNamespaceName(property, cluster, namespace);
1082-
validateNamespacePolicyOperation(NamespaceName.get(property, namespace),
1083-
PolicyName.BACKLOG, PolicyOperation.READ);
1084-
1085-
Policies policies = getNamespacePolicies(namespaceName);
1086-
return policies.backlog_quota_map;
1083+
validateNamespacePolicyOperationAsync(namespaceName, PolicyName.BACKLOG,
1084+
PolicyOperation.READ)
1085+
.thenCompose(__ -> getNamespacePoliciesAsync(namespaceName))
1086+
.thenAccept(policies -> asyncResponse.resume(policies.backlog_quota_map))
1087+
.exceptionally(ex -> {
1088+
log.error("[{}] Failed to get backlog quota map on namespace {}", clientAppId(), namespaceName, ex);
1089+
resumeAsyncResponseExceptionally(asyncResponse, ex);
1090+
return null;
1091+
});
10871092
}
10881093

10891094
@POST

pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/Namespaces.java

+12-5
Original file line numberDiff line numberDiff line change
@@ -1121,13 +1121,20 @@ public void getReplicatorDispatchRate(
11211121
@ApiOperation(value = "Get backlog quota map on a namespace.")
11221122
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"),
11231123
@ApiResponse(code = 404, message = "Namespace does not exist") })
1124-
public Map<BacklogQuotaType, BacklogQuota> getBacklogQuotaMap(@PathParam("tenant") String tenant,
1124+
public void getBacklogQuotaMap(
1125+
@Suspended final AsyncResponse asyncResponse,
1126+
@PathParam("tenant") String tenant,
11251127
@PathParam("namespace") String namespace) {
11261128
validateNamespaceName(tenant, namespace);
1127-
validateNamespacePolicyOperation(
1128-
NamespaceName.get(tenant, namespace), PolicyName.BACKLOG, PolicyOperation.READ);
1129-
Policies policies = getNamespacePolicies(namespaceName);
1130-
return policies.backlog_quota_map;
1129+
validateNamespacePolicyOperationAsync(namespaceName, PolicyName.BACKLOG,
1130+
PolicyOperation.READ)
1131+
.thenCompose(__ -> getNamespacePoliciesAsync(namespaceName))
1132+
.thenAccept(policies -> asyncResponse.resume(policies.backlog_quota_map))
1133+
.exceptionally(ex -> {
1134+
log.error("[{}] Failed to get backlog quota map on namespace {}", clientAppId(), namespaceName, ex);
1135+
resumeAsyncResponseExceptionally(asyncResponse, ex);
1136+
return null;
1137+
});
11311138
}
11321139

11331140
@POST

0 commit comments

Comments
 (0)