You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/03/17 00:06:47 UTC

[GitHub] [pulsar] aloyszhang commented on a change in pull request #14702: [PulsarAdmin] add get active brokers api without cluster name

aloyszhang commented on a change in pull request #14702:
URL: https://github.com/apache/pulsar/pull/14702#discussion_r828548262



##########
File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokersBase.java
##########
@@ -104,6 +104,30 @@ public void getActiveBrokers(@Suspended final AsyncResponse asyncResponse,
                 });
     }
 
+    @GET
+    @Path("/")
+    @ApiOperation(
+            value = "Get the list of active brokers (web service addresses) in the local cluster."
+                    + "If authorization is not enabled",
+            response = String.class,
+            responseContainer = "Set")
+    @ApiResponses(
+            value = {
+                    @ApiResponse(code = 401, message = "Authentication required"),
+                    @ApiResponse(code = 403, message = "This operation requires super-user access") })
+    public void getActiveBrokers(@Suspended final AsyncResponse asyncResponse) throws Exception {
+        validateSuperUserAccessAsync()
+                .thenCompose(__ -> pulsar().getLoadManager().get().getAvailableBrokersAsync())
+                .thenAccept(activeBrokers -> {
+                    LOG.info("[{}] Successfully to get active brokers", clientAppId());
+                    asyncResponse.resume(activeBrokers);
+                }).exceptionally(ex -> {
+                    LOG.error("[{}] Fail to get active brokers", clientAppId(), ex);
+                    resumeAsyncResponseExceptionally(asyncResponse, ex);
+                    return null;
+                });

Review comment:
       Most of the codes are duplicated to 
   ```java
   getActiveBrokers(@Suspended final AsyncResponse asyncResponse,
                                    @PathParam("cluster") String cluster)
   ```
   How about abstract a common method used by both the `getActiveBrokers(@Suspended final AsyncResponse asyncResponse, PathParam("cluster") String cluster)` and `getActiveBrokers(@Suspended final AsyncResponse asyncResponse)` ?




-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org