You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2019/06/10 18:12:01 UTC

[GitHub] [incubator-pinot] akshayrai commented on a change in pull request #4295: [TE] Auto-Resolving Create-Update API for alerts

akshayrai commented on a change in pull request #4295: [TE] Auto-Resolving Create-Update API for alerts
URL: https://github.com/apache/incubator-pinot/pull/4295#discussion_r292125941
 
 

 ##########
 File path: thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/YamlResource.java
 ##########
 @@ -414,6 +416,70 @@ public Response updateDetectionPipelineApi(
     return Response.ok().entity(responseMessage).build();
   }
 
+  private DetectionConfigDTO fetchExistingDetection(String payload) {
+    DetectionConfigDTO existingDetectionConfig = null;
+
+    // Extract the detectionName from payload
+    Map<String, Object> detectionConfigMap = new HashMap<>();
+    detectionConfigMap.putAll(ConfigUtils.getMap(this.yaml.load(payload)));
+    String detectionName = MapUtils.getString(detectionConfigMap, PROP_DETECTION_NAME);
+    Preconditions.checkNotNull(detectionName, "Missing property detectionName in the detection config.");
+
+    // Check if detection already existing
+    Collection<DetectionConfigDTO> detectionConfigs = this.detectionConfigDAO
+        .findByPredicate(Predicate.EQ("name", detectionName));
+    if (detectionConfigs != null && !detectionConfigs.isEmpty()) {
+      existingDetectionConfig = detectionConfigs.iterator().next();
+    }
+
+    return existingDetectionConfig;
+  }
+
+  long createUpdateDetectionPipeline(String payload) {
+    Preconditions.checkArgument(StringUtils.isNotBlank(payload), "The Yaml Payload in the request is empty.");
+    long detectionId;
+    DetectionConfigDTO existingDetection = fetchExistingDetection(payload);
+    if (existingDetection != null) {
+      detectionId = existingDetection.getId();
+      updateDetectionPipeline(detectionId, payload, 0, 0);
 
 Review comment:
   Addressed

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org