Skip to content

Correctly handle the asynchronous programming suggestions of api and base in the admin api of pulsar-broker. #7884

Closed as not planned

Description

@jianyun8023

Is your feature request related to a problem? Please describe.
I recently did topic level configuration. In the admin web module org.apache.pulsar.broker.admin, the asynchronous call between the api and the base made me feel very frustrated. The asyncResponse of the api layer was passed to the base layer, which made the handling of exceptions very complicated. . And this operation couples the api layer and the base layer together.

I understand that base is equivalent to the service layer, and api is the interface layer, and their responsibilities should be separated.

Describe the solution you'd like
For base layer methods that support asynchronous, it is recommended to use CompletableFuture return instead of passing in asyncResponse

For exceptions, normal throw is fine, no other operations are required.

Describe alternatives you've considered
no

Additional context

org.apache.pulsar.broker.admin.v2.Namespaces#deleteNamespace

@DELETE
    @Path("/{tenant}/{namespace}")
    @ApiOperation(value = "Delete a namespace and all the topics under it.")
    @ApiResponses(value = {
            @ApiResponse(code = 307, message = "Current broker doesn't serve the namespace"),
            @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 = "Namespace is not empty") })
    public void deleteNamespace(@Suspended final AsyncResponse asyncResponse, @PathParam("tenant") String tenant,
            @PathParam("namespace") String namespace,
            @QueryParam("authoritative") @DefaultValue("false") boolean authoritative) {
        try {
            validateNamespaceName(tenant, namespace);
            internalDeleteNamespace(asyncResponse, authoritative); 
        } catch (WebApplicationException wae) {
            asyncResponse.resume(wae);
        } catch (Exception e) {
            asyncResponse.resume(new RestException(e));
        }
    }

org.apache.pulsar.broker.admin.impl.NamespacesBase#internalDeleteNamespace
In NamespacesBase#internalDeleteNamespace, you can see that the exception handling becomes cumbersome

image

Activity

  1. added
    type/feature
    on Aug 23, 2020
  2. tisonkun commented on Dec 11, 2022

    @tisonkun
    Member

    Closed as stale. Please create a new issue if it's still relevant to the maintained versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/adminarea/brokerlifecycle/staletype/feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions