You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by ak...@apache.org on 2019/02/08 19:09:23 UTC
[incubator-pinot] branch master updated: [TE] Remove duplicate
alert validation for update (#3806)
This is an automated email from the ASF dual-hosted git repository.
akshayrai09 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git
The following commit(s) were added to refs/heads/master by this push:
new fdd7102 [TE] Remove duplicate alert validation for update (#3806)
fdd7102 is described below
commit fdd71021bd6f41ad3da39840ca8c17ac1088253d
Author: Akshay Rai <ak...@gmail.com>
AuthorDate: Fri Feb 8 11:09:19 2019 -0800
[TE] Remove duplicate alert validation for update (#3806)
---
.../validators/DetectionAlertConfigValidator.java | 7 -----
.../thirdeye/detection/yaml/YamlResource.java | 31 ++++++++++++++++++++--
2 files changed, 29 insertions(+), 9 deletions(-)
diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/validators/DetectionAlertConfigValidator.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/validators/DetectionAlertConfigValidator.java
index bd145ad..8224671 100644
--- a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/validators/DetectionAlertConfigValidator.java
+++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/validators/DetectionAlertConfigValidator.java
@@ -87,13 +87,6 @@ public class DetectionAlertConfigValidator extends ConfigValidator {
+ " to ask_thirdeye if you wish to setup a new application.");
}
- // Check for duplicates
- List<DetectionAlertConfigDTO> alertConfigDTOS = DAORegistry.getInstance().getDetectionAlertConfigManager()
- .findByPredicate(Predicate.EQ("name", alertConfig.getName()));
- if (!alertConfigDTOS.isEmpty()) {
- throw new ValidationException("Subscription group name is already taken. Please use a different name.");
- }
-
// TODO add more checks like cron validity, email validity, alert type check, scheme type check etc.
}
diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/YamlResource.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/YamlResource.java
index cd7015b..441d79b 100644
--- a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/YamlResource.java
+++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/YamlResource.java
@@ -80,6 +80,7 @@ public class YamlResource {
private static ObjectMapper OBJECT_MAPPER = new ObjectMapper();
public static final String PROP_DETECTION_NAME = "detectionName";
+ public static final String PROP_SUBS_GROUP_NAME = "subscriptionGroupName";
private final DetectionConfigManager detectionConfigDAO;
private final DetectionAlertConfigManager detectionAlertConfigDAO;
@@ -217,7 +218,26 @@ public class YamlResource {
// Notification
String notificationYaml = yamls.get("notification");
- Response response = createDetectionAlertConfigApi(notificationYaml);
+
+ Map<String, Object> notificationYamlConfig;
+ try {
+ notificationYamlConfig = (Map<String, Object>) this.yaml.load(notificationYaml);
+ } catch (Exception e){
+ return Response.status(Response.Status.BAD_REQUEST)
+ .entity(ImmutableMap.of("message", "notification yaml parsing error, " + e.getMessage())).build();
+ }
+
+ // Check if existing or new subscription group
+ String groupName = MapUtils.getString(notificationYamlConfig, PROP_SUBS_GROUP_NAME);
+ List<DetectionAlertConfigDTO> alertConfigDTOS = detectionAlertConfigDAO
+ .findByPredicate(Predicate.EQ("name", groupName));
+ Response response;
+ if (!alertConfigDTOS.isEmpty()) {
+ response = updateDetectionAlertConfigApi(notificationYaml, alertConfigDTOS.get(0).getId());
+ } else {
+ response = createDetectionAlertConfigApi(notificationYaml);
+ }
+
if (response.getStatusInfo() != Response.Status.OK) {
// revert detection DTO
this.detectionConfigDAO.deleteById(detectionConfigId);
@@ -327,7 +347,14 @@ public class YamlResource {
DetectionAlertConfigDTO alertConfig = this.alertConfigTranslator.translate(newAlertConfigMap);
alertConfig.setYaml(yamlAlertConfig);
- // Validate the config before saving it
+ // Check for duplicates
+ List<DetectionAlertConfigDTO> alertConfigDTOS = detectionAlertConfigDAO
+ .findByPredicate(Predicate.EQ("name", alertConfig.getName()));
+ if (!alertConfigDTOS.isEmpty()) {
+ throw new ValidationException("Subscription group name is already taken. Please use a different name.");
+ }
+
+ // Validate the config
notificationValidator.validateConfig(alertConfig);
return alertConfig;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org