turboFei commented on code in PR #2730:
URL: https://github.com/apache/celeborn/pull/2730#discussion_r1752781899


##########
master/src/main/scala/org/apache/celeborn/service/deploy/master/http/api/v1/WorkerResource.scala:
##########
@@ -73,10 +73,16 @@ class WorkerResource extends ApiRequestContext {
   @POST
   @Path("/exclude")
   def excludeWorker(request: ExcludeWorkerRequest): HandleResponse = {
-    val (success, msg) = httpService.exclude(
-      request.getAdd.asScala.map(ApiUtils.toWorkerInfo).toSeq,
-      request.getRemove.asScala.map(ApiUtils.toWorkerInfo).toSeq)
-    new HandleResponse().success(success).message(msg)
+    if (master.isMasterActive == 1) {
+      val (success, msg) = httpService.exclude(
+        request.getAdd.asScala.map(ApiUtils.toWorkerInfo).toSeq,
+        request.getRemove.asScala.map(ApiUtils.toWorkerInfo).toSeq)
+      new HandleResponse().success(success).message(msg)
+    } else {
+      throw new BadRequestException(
+        s"This operation can only be done from a master that has the LEADER 
role." +

Review Comment:
   could you define a method for the exception thrown? likes:
   
   ```
   def ensureMasterActive(f: =>T): T = {
   if (master.isMasterActive != 1) {
    throw new BadRequestException(...)
   }
   f
   }
   
   ```



-- 
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