xiaohui-sun commented on a change in pull request #4763: [TE] endpoints - 
harleyjj/alert-activation - make endpoint for toggli…
URL: https://github.com/apache/incubator-pinot/pull/4763#discussion_r341318558
 
 

 ##########
 File path: 
thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/DetectionResource.java
 ##########
 @@ -540,6 +541,41 @@ public Response createUserAnomaly(
     return Response.ok(anomaly.getId()).build();
   }
 
+  /**
+   * Toggle active/inactive for given detection
+   *
+   * @param detectionId detection config id (must exist)
+   */
+  @PUT
+  @Path("/activation/{id}")
+  @ApiOperation("Make detection active or inactive, given id")
+  public Response toggleActivation(
+      @PathParam("id") long detectionId) throws Exception {
+    Map<String, String> responseMessage = new HashMap<>();
+    Boolean toggledTo = false;
+    try {
+      DetectionConfigDTO config = this.configDAO.findById(detectionId);
+      if (config == null) {
+        throw new IllegalArgumentException(String.format("Cannot find config 
%d", detectionId));
+      }
+
+      // grab for logs
+      toggledTo = !config.isActive();
+      // update state
+      config.setActive(!config.isActive());
 
 Review comment:
   config.setActive(toggledTo) is better.
   Let's avoid duplicating logic, although it is very small logic.

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