xiaohui-sun 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_r292091451
##########
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);
+ } else {
+ detectionId = createDetectionPipeline(payload, 0, 0);
+ }
+
+ return detectionId;
+ }
+
+ /**
+ Set up a detection pipeline using a YAML config - create new or update
existing
+ @param payload YAML config string
+ @return a message contains the saved detection config id
+ */
+ @POST
+ @Produces(MediaType.APPLICATION_JSON)
+ @Consumes(MediaType.TEXT_PLAIN)
+ @ApiOperation("Create a new detection pipeline or update existing if one
already exists")
+ public Response createUpdateDetectionPipelineApi(@ApiParam("yaml config")
String payload) {
Review comment:
use "createOrUpdatePipelineApi"
----------------------------------------------------------------
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]