QiuMM commented on a change in pull request #6272: Add suspend|resume|terminate 
all supervisors endpoints.
URL: https://github.com/apache/incubator-druid/pull/6272#discussion_r221417337
 
 

 ##########
 File path: 
indexing-service/src/main/java/org/apache/druid/indexing/overlord/supervisor/SupervisorResource.java
 ##########
 @@ -378,23 +407,31 @@ private Response specSuspendOrResume(final String id, 
boolean suspend)
   {
     return asLeaderWithSupervisorManager(
         manager -> {
-          Optional<SupervisorSpec> spec = manager.getSupervisorSpec(id);
-          if (!spec.isPresent()) {
-            return Response.status(Response.Status.NOT_FOUND)
-                           .entity(ImmutableMap.of("error", 
StringUtils.format("[%s] does not exist", id)))
-                           .build();
-          }
-
-          if (spec.get().isSuspended() == suspend) {
-            final String errMsg =
-                StringUtils.format("[%s] is already %s", id, suspend ? 
"suspended" : "running");
-            return Response.status(Response.Status.BAD_REQUEST)
+          if (manager.suspendOrResumeSupervisor(id, suspend)) {
+            Optional<SupervisorSpec> spec = manager.getSupervisorSpec(id);
+            return Response.ok(spec.get()).build();
+          } else {
+            Optional<SupervisorSpec> spec = manager.getSupervisorSpec(id);
+            final Response.Status status = spec.isPresent() ? 
Response.Status.BAD_REQUEST : Response.Status.NOT_FOUND;
+            final String errMsg = spec.isPresent() ? StringUtils.format(
+                "[%s] is already %s",
+                id,
+                suspend ? "suspended" : "running"
+            ) : StringUtils.format("[%s] does not exist", id);
+            return Response.status(status)
                            .entity(ImmutableMap.of("error", errMsg))
                            .build();
           }
-          manager.suspendOrResumeSupervisor(id, suspend);
-          spec = manager.getSupervisorSpec(id);
-          return Response.ok(spec.get()).build();
+        }
+    );
+  }
+
+  private Response suspendOrResumeAll(boolean suspend)
+  {
+    return asLeaderWithSupervisorManager(
+        manager -> {
+          manager.suspendOrResumeAllSupervisors(suspend);
+          return Response.ok(ImmutableMap.of("status", "success")).build();
 
 Review comment:
   I have stated the reason why I did not return these ids above. For your 
convenience, I paste here:
   > I think there is no need to return these ids since these all endpoints are 
idempotent operations. Just return OK would be fine. And I think users do not 
care about which supervisor has a state change, they just need to know they 
have changed all supervisors to suspened state or running state. Besides, 
return these ids would make the code a little complex and ugly ):
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to