Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improve][broker] make some methods async in Namespaces #16784

Merged
merged 2 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1584,13 +1584,6 @@ private void doUpdatePersistence(PersistencePolicies persistence) {
}
}

protected PersistencePolicies internalGetPersistence() {
validateNamespacePolicyOperation(namespaceName, PolicyName.PERSISTENCE, PolicyOperation.READ);

Policies policies = getNamespacePolicies(namespaceName);
return policies.persistence;
}

protected void internalClearNamespaceBacklog(AsyncResponse asyncResponse, boolean authoritative) {
validateNamespaceOperation(namespaceName, NamespaceOperation.CLEAR_BACKLOG);

Expand Down Expand Up @@ -1808,12 +1801,6 @@ protected void internalSetSubscriptionAuthMode(SubscriptionAuthMode subscription
}
}

protected SubscriptionAuthMode internalGetSubscriptionAuthMode() {
validateNamespacePolicyOperation(namespaceName, PolicyName.SUBSCRIPTION_AUTH_MODE, PolicyOperation.READ);
Policies policies = getNamespacePolicies(namespaceName);
return policies.subscription_auth_mode;
}

protected void internalModifyEncryptionRequired(boolean encryptionRequired) {
validateNamespacePolicyOperation(namespaceName, PolicyName.ENCRYPTION, PolicyOperation.WRITE);
validatePoliciesReadOnlyAccess();
Expand Down Expand Up @@ -1843,13 +1830,6 @@ protected DelayedDeliveryPolicies internalGetDelayedDelivery() {
return getNamespacePolicies(namespaceName).delayed_delivery_policies;
}

protected InactiveTopicPolicies internalGetInactiveTopic() {
validateNamespacePolicyOperation(namespaceName, PolicyName.INACTIVE_TOPIC, PolicyOperation.READ);

Policies policies = getNamespacePolicies(namespaceName);
return policies.inactive_topic_policies;
}

protected void internalSetInactiveTopic(InactiveTopicPolicies inactiveTopicPolicies) {
validateSuperUserAccess();
validatePoliciesReadOnlyAccess();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1257,10 +1257,20 @@ public void deleteBookieAffinityGroup(@PathParam("property") String property, @P
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"),
@ApiResponse(code = 404, message = "Namespace does not exist"),
@ApiResponse(code = 409, message = "Concurrent modification") })
public PersistencePolicies getPersistence(@PathParam("property") String property,
public void getPersistence(
@Suspended final AsyncResponse asyncResponse,
@PathParam("property") String property,
@PathParam("cluster") String cluster, @PathParam("namespace") String namespace) {
validateNamespaceName(property, cluster, namespace);
return internalGetPersistence();
validateNamespacePolicyOperationAsync(namespaceName, PolicyName.PERSISTENCE, PolicyOperation.READ)
.thenCompose(__ -> getNamespacePoliciesAsync(namespaceName))
.thenAccept(policies -> asyncResponse.resume(policies.persistence))
.exceptionally(ex -> {
log.error("[{}] Failed to get persistence configuration for a namespace {}", clientAppId(),
namespaceName, ex);
resumeAsyncResponseExceptionally(asyncResponse, ex);
return null;
});
}

@POST
Expand Down Expand Up @@ -1384,11 +1394,20 @@ public void setSubscriptionAuthMode(@PathParam("property") String property, @Pat
@ApiOperation(value = "Get subscription auth mode in a namespace")
@ApiResponses(value = {@ApiResponse(code = 403, message = "Don't have admin permission"),
@ApiResponse(code = 404, message = "Property or cluster or namespace doesn't exist")})
public SubscriptionAuthMode getSubscriptionAuthMode(@PathParam("property") String property,
@PathParam("cluster") String cluster,
@PathParam("namespace") String namespace) {
public void getSubscriptionAuthMode(@Suspended final AsyncResponse asyncResponse,
@PathParam("property") String property,
@PathParam("cluster") String cluster,
@PathParam("namespace") String namespace) {
validateNamespaceName(property, cluster, namespace);
return internalGetSubscriptionAuthMode();
validateNamespacePolicyOperationAsync(namespaceName, PolicyName.SUBSCRIPTION_AUTH_MODE, PolicyOperation.READ)
.thenCompose(__ -> getNamespacePoliciesAsync(namespaceName))
.thenAccept(policies -> asyncResponse.resume(policies.subscription_auth_mode))
.exceptionally(ex -> {
log.error("[{}] Failed to get subscription auth mode in a namespace {}", clientAppId(),
namespaceName, ex);
resumeAsyncResponseExceptionally(asyncResponse, ex);
return null;
});
}

@POST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1298,10 +1298,20 @@ public void deleteBookieAffinityGroup(@PathParam("property") String property,
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"),
@ApiResponse(code = 404, message = "Namespace does not exist"),
@ApiResponse(code = 409, message = "Concurrent modification") })
public PersistencePolicies getPersistence(@PathParam("tenant") String tenant,
public void getPersistence(
@Suspended final AsyncResponse asyncResponse,
@PathParam("tenant") String tenant,
@PathParam("namespace") String namespace) {
validateNamespaceName(tenant, namespace);
return internalGetPersistence();
validateNamespacePolicyOperationAsync(namespaceName, PolicyName.PERSISTENCE, PolicyOperation.READ)
.thenCompose(__ -> getNamespacePoliciesAsync(namespaceName))
.thenAccept(policies -> asyncResponse.resume(policies.persistence))
.exceptionally(ex -> {
log.error("[{}] Failed to get persistence configuration for a namespace {}", clientAppId(),
namespaceName, ex);
resumeAsyncResponseExceptionally(asyncResponse, ex);
return null;
});
}

@POST
Expand Down Expand Up @@ -1425,10 +1435,20 @@ public void setSubscriptionAuthMode(@PathParam("tenant") String tenant,
@ApiOperation(value = "Get subscription auth mode in a namespace")
@ApiResponses(value = {@ApiResponse(code = 403, message = "Don't have admin permission"),
@ApiResponse(code = 404, message = "Tenant or namespace doesn't exist")})
public SubscriptionAuthMode getSubscriptionAuthMode(@PathParam("tenant") String tenant,
@PathParam("namespace") String namespace) {
public void getSubscriptionAuthMode(
@Suspended final AsyncResponse asyncResponse,
@PathParam("tenant") String tenant,
@PathParam("namespace") String namespace) {
validateNamespaceName(tenant, namespace);
return internalGetSubscriptionAuthMode();
validateNamespacePolicyOperationAsync(namespaceName, PolicyName.SUBSCRIPTION_AUTH_MODE, PolicyOperation.READ)
.thenCompose(__ -> getNamespacePoliciesAsync(namespaceName))
.thenAccept(policies -> asyncResponse.resume(policies.subscription_auth_mode))
.exceptionally(ex -> {
log.error("[{}] Failed to get subscription auth mode in a namespace {}", clientAppId(),
namespaceName, ex);
resumeAsyncResponseExceptionally(asyncResponse, ex);
return null;
});
}

@POST
Expand All @@ -1451,10 +1471,19 @@ public void modifyEncryptionRequired(
@ApiOperation(value = "Get message encryption required status in a namespace")
@ApiResponses(value = {@ApiResponse(code = 403, message = "Don't have admin permission"),
@ApiResponse(code = 404, message = "Tenant or namespace doesn't exist")})
public Boolean getEncryptionRequired(@PathParam("tenant") String tenant,
@PathParam("namespace") String namespace) {
public void getEncryptionRequired(@Suspended AsyncResponse asyncResponse,
@PathParam("tenant") String tenant,
@PathParam("namespace") String namespace) {
validateNamespaceName(tenant, namespace);
return internalGetEncryptionRequired();
validateNamespacePolicyOperationAsync(namespaceName, PolicyName.ENCRYPTION, PolicyOperation.READ)
.thenCompose(__ -> getNamespacePoliciesAsync(namespaceName))
.thenAccept(policies -> asyncResponse.resume(policies.encryption_required))
.exceptionally(ex -> {
log.error("[{}] Failed to get message encryption required status in a namespace {}", clientAppId(),
namespaceName, ex);
resumeAsyncResponseExceptionally(asyncResponse, ex);
return null;
});
}

@GET
Expand Down Expand Up @@ -1499,10 +1528,19 @@ public void removeDelayedDeliveryPolicies(@PathParam("tenant") String tenant,
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"),
@ApiResponse(code = 404, message = "Tenant or cluster or namespace doesn't exist"),
@ApiResponse(code = 409, message = "Concurrent modification"), })
public InactiveTopicPolicies getInactiveTopicPolicies(@PathParam("tenant") String tenant,
@PathParam("namespace") String namespace) {
public void getInactiveTopicPolicies(@Suspended final AsyncResponse asyncResponse,
@PathParam("tenant") String tenant,
@PathParam("namespace") String namespace) {
validateNamespaceName(tenant, namespace);
return internalGetInactiveTopic();
validateNamespacePolicyOperationAsync(namespaceName, PolicyName.INACTIVE_TOPIC, PolicyOperation.READ)
.thenCompose(__ -> getNamespacePoliciesAsync(namespaceName))
.thenAccept(policies -> asyncResponse.resume(policies.inactive_topic_policies))
.exceptionally(ex -> {
log.error("[{}] Failed to get inactive topic policies config on a namespace {}", clientAppId(),
namespaceName, ex);
resumeAsyncResponseExceptionally(asyncResponse, ex);
return null;
});
}

@DELETE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1062,8 +1062,11 @@ public void testPersistence() throws Exception {
NamespaceName testNs = this.testLocalNamespaces.get(0);
PersistencePolicies persistence1 = new PersistencePolicies(3, 2, 1, 0.0);
namespaces.setPersistence(testNs.getTenant(), testNs.getCluster(), testNs.getLocalName(), persistence1);
PersistencePolicies persistence2 = namespaces.getPersistence(testNs.getTenant(), testNs.getCluster(),
testNs.getLocalName());
AsyncResponse response = mock(AsyncResponse.class);
namespaces.getPersistence(response, testNs.getTenant(), testNs.getCluster(), testNs.getLocalName());
ArgumentCaptor<PersistencePolicies> captor = ArgumentCaptor.forClass(PersistencePolicies.class);
verify(response, timeout(5000).times(1)).resume(captor.capture());
PersistencePolicies persistence2 = captor.getValue();
assertEquals(persistence2, persistence1);
}

Expand Down