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 
   ```java
   getActiveBrokers(@Suspended final AsyncResponse asyncResponse, 
PathParam("cluster") String cluster)
   ``` 
   and 
   ```java
   getActiveBrokers(@Suspended final AsyncResponse asyncResponse)
   ` ``

##########
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 
   ```java
   getActiveBrokers(@Suspended final AsyncResponse asyncResponse, 
PathParam("cluster") String cluster)
   ``` 
   and 
   
   ```java
   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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to