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/01/28 22:25:34 UTC

[incubator-pinot] branch master updated: [TE] Clean up and pretty print yaml (#3754)

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 6e10553  [TE] Clean up and pretty print yaml (#3754)
6e10553 is described below

commit 6e10553381a7284549a90cdc04b20c1be8ca3127
Author: Akshay Rai <ak...@gmail.com>
AuthorDate: Mon Jan 28 14:25:29 2019 -0800

    [TE] Clean up and pretty print yaml (#3754)
---
 .../thirdeye/detection/DetectionMigrationResource.java   | 16 ++++++++++++----
 .../yaml/YamlDetectionAlertConfigTranslator.java         |  3 ++-
 .../detection/DetectionMigrationResourceTest.java        |  8 ++++----
 3 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/DetectionMigrationResource.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/DetectionMigrationResource.java
index 267bcd7..5bd4d02 100644
--- a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/DetectionMigrationResource.java
+++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/DetectionMigrationResource.java
@@ -22,6 +22,7 @@ package org.apache.pinot.thirdeye.detection;
 import com.google.common.collect.ImmutableMap;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
@@ -30,11 +31,14 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
+import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import org.apache.commons.lang.exception.ExceptionUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -366,15 +370,15 @@ public class DetectionMigrationResource {
     yamlConfigs.put(PROP_CRON, alertConfigDTO.getCronExpression());
     yamlConfigs.put(PROP_ACTIVE, alertConfigDTO.isActive());
     yamlConfigs.put(PROP_APPLICATION, alertConfigDTO.getApplication());
-    yamlConfigs.put(PROP_EMAIL_SUBJECT_TYPE, alertConfigDTO.getSubjectType());
+    yamlConfigs.put(PROP_EMAIL_SUBJECT_TYPE, alertConfigDTO.getSubjectType().name());
     yamlConfigs.put(PROP_FROM, alertConfigDTO.getFromAddress());
 
     yamlConfigs.put(PROP_TYPE, "DEFAULT_ALERTER_PIPELINE");
 
     Map<String, Object> recipients = new LinkedHashMap<>();
-    recipients.put("to", alertConfigDTO.getReceiverAddresses().getTo());
-    recipients.put("cc", alertConfigDTO.getReceiverAddresses().getCc());
-    recipients.put("bcc", alertConfigDTO.getReceiverAddresses().getBcc());
+    recipients.put("to", new ArrayList<>(alertConfigDTO.getReceiverAddresses().getTo()));
+    recipients.put("cc", new ArrayList<>(alertConfigDTO.getReceiverAddresses().getCc()));
+    recipients.put("bcc", new ArrayList<>(alertConfigDTO.getReceiverAddresses().getBcc()));
     yamlConfigs.put(PROP_RECIPIENTS, recipients);
 
     List<Map<String, Object>> schemes = new ArrayList<>();
@@ -397,6 +401,8 @@ public class DetectionMigrationResource {
   }
 
   @GET
+  @Produces(MediaType.TEXT_PLAIN)
+  @Consumes(MediaType.APPLICATION_JSON)
   @Path("/legacy-anomaly-function-to-yaml/{id}")
   public Response getYamlFromLegacyAnomalyFunction(@PathParam("id") long anomalyFunctionID) throws Exception {
     AnomalyFunctionDTO anomalyFunctionDTO = this.anomalyFunctionDAO.findById(anomalyFunctionID);
@@ -409,6 +415,8 @@ public class DetectionMigrationResource {
   }
 
   @GET
+  @Produces(MediaType.TEXT_PLAIN)
+  @Consumes(MediaType.APPLICATION_JSON)
   @Path("/legacy-alert-to-yaml/{id}")
   public Response getYamlFromLegacyAlert(@PathParam("id") long alertId) throws Exception {
     AlertConfigDTO alertConfigDTO = this.alertConfigDAO.findById(alertId);
diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/YamlDetectionAlertConfigTranslator.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/YamlDetectionAlertConfigTranslator.java
index 0c34b51..b64b8ee 100644
--- a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/YamlDetectionAlertConfigTranslator.java
+++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/YamlDetectionAlertConfigTranslator.java
@@ -175,7 +175,8 @@ public class YamlDetectionAlertConfigTranslator {
     // TODO: Remove all references to onlyFetchLegacyAnomalies after migration
     alertConfigDTO.setOnlyFetchLegacyAnomalies(MapUtils.getBooleanValue(yamlAlertConfig, PROP_ONLY_FETCH_LEGACY_ANOMALIES, false));
 
-    alertConfigDTO.setSubjectType((AlertConfigBean.SubjectType) MapUtils.getObject(yamlAlertConfig, PROP_EMAIL_SUBJECT_TYPE, AlertConfigBean.SubjectType.METRICS));
+    alertConfigDTO.setSubjectType(AlertConfigBean.SubjectType.valueOf(
+        (String) MapUtils.getObject(yamlAlertConfig, PROP_EMAIL_SUBJECT_TYPE, AlertConfigBean.SubjectType.METRICS.name())));
 
     Map<String, String> refLinks = MapUtils.getMap(yamlAlertConfig, PROP_REFERENCE_LINKS);
     if (refLinks == null) {
diff --git a/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/detection/DetectionMigrationResourceTest.java b/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/detection/DetectionMigrationResourceTest.java
index 550c997..63327f9 100644
--- a/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/detection/DetectionMigrationResourceTest.java
+++ b/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/detection/DetectionMigrationResourceTest.java
@@ -157,7 +157,7 @@ public class DetectionMigrationResourceTest {
     Assert.assertEquals(yamlMap.get(PROP_SUBS_GROUP_NAME), "test_notification");
     Assert.assertEquals(yamlMap.get(PROP_CRON), "0 0 14 * * ? *");
     Assert.assertEquals(yamlMap.get(PROP_APPLICATION), "test_application");
-    Assert.assertEquals(yamlMap.get(PROP_EMAIL_SUBJECT_TYPE), AlertConfigBean.SubjectType.ALERT);
+    Assert.assertEquals(yamlMap.get(PROP_EMAIL_SUBJECT_TYPE), AlertConfigBean.SubjectType.ALERT.name());
     Assert.assertEquals(yamlMap.get(PROP_FROM), "test@thirdeye.com");
     Assert.assertEquals(yamlMap.get(PROP_TYPE), "DEFAULT_ALERTER_PIPELINE");
     Assert.assertEquals(ConfigUtils.getList(yamlMap.get(PROP_DETECTION_NAMES)).size(), 2);
@@ -165,9 +165,9 @@ public class DetectionMigrationResourceTest {
     Assert.assertEquals(ConfigUtils.getList(yamlMap.get(PROP_ALERT_SCHEMES)).size(), 1);
     Assert.assertEquals(ConfigUtils.getMap(ConfigUtils.getList(yamlMap.get(PROP_ALERT_SCHEMES)).get(0)).get(PROP_TYPE), "EMAIL");
     Assert.assertNotNull(yamlMap.get(PROP_RECIPIENTS));
-    Assert.assertEquals((ConfigUtils.getMap(yamlMap.get(PROP_RECIPIENTS)).get("to")), Collections.singleton("to@test"));
-    Assert.assertEquals((ConfigUtils.getMap(yamlMap.get(PROP_RECIPIENTS)).get("cc")), Collections.singleton("cc@test"));
-    Assert.assertEquals((ConfigUtils.getMap(yamlMap.get(PROP_RECIPIENTS)).get("bcc")), Collections.singleton("bcc@test"));
+    Assert.assertEquals((ConfigUtils.getMap(yamlMap.get(PROP_RECIPIENTS)).get("to")), Collections.singletonList("to@test"));
+    Assert.assertEquals((ConfigUtils.getMap(yamlMap.get(PROP_RECIPIENTS)).get("cc")), Collections.singletonList("cc@test"));
+    Assert.assertEquals((ConfigUtils.getMap(yamlMap.get(PROP_RECIPIENTS)).get("bcc")), Collections.singletonList("bcc@test"));
   }
 
   @Test


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