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 00:10:25 UTC
[incubator-pinot] branch master updated: [TE] Retain create owners
of anomaly functions and alerts (#3804)
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 521d551 [TE] Retain create owners of anomaly functions and alerts (#3804)
521d551 is described below
commit 521d551e9dda668ff7e3cb69bd0b78417ee19e0d
Author: Akshay Rai <ak...@gmail.com>
AuthorDate: Thu Feb 7 16:10:20 2019 -0800
[TE] Retain create owners of anomaly functions and alerts (#3804)
---
.../thirdeye/detection/DetectionMigrationResource.java | 16 +++++++++++++++-
.../detection/DetectionMigrationResourceTest.java | 7 ++++++-
2 files changed, 21 insertions(+), 2 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 811e594..f9e7c96 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
@@ -327,11 +327,18 @@ public class DetectionMigrationResource {
}
// Save the migrated anomaly function
- DAORegistry.getInstance().getDetectionConfigManager().save(detectionConfig);
+ detectionConfigDAO.save(detectionConfig);
if (detectionConfig.getId() == null) {
throw new RuntimeException("Error saving the new detection config.");
}
+ // Hack to retain Anomaly function owner
+ detectionConfig.setCreatedBy(anomalyFunctionDTO.getCreatedBy());
+ detectionConfigDAO.update(detectionConfig);
+ if (detectionConfig.getId() == null) {
+ throw new RuntimeException("Error saving the new detection config after updating the owner.");
+ }
+
// Point all the associated anomalies to the migrated anomaly function.
List<MergedAnomalyResultDTO> mergedAnomalyResultDTOS = mergedAnomalyResultDAO.findByPredicate(Predicate.EQ("functionId", anomalyFunctionDTO.getId()));
for (MergedAnomalyResultDTO anomaly : mergedAnomalyResultDTOS) {
@@ -407,6 +414,13 @@ public class DetectionMigrationResource {
if (alertConfig.getId() == null) {
throw new RuntimeException("Error while saving the migrated alert config for " + alertName);
}
+
+ // Hack to retain subscription group owner
+ alertConfig.setCreatedBy(alertConfigDTO.getCreatedBy());
+ detectionAlertConfigDAO.update(alertConfig);
+ if (alertConfig.getId() == null) {
+ throw new RuntimeException("Error saving the migrated alert config after updating the owner.");
+ }
}
// Update migration status and disable the old alert
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 85ea55e..238cff2 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
@@ -175,6 +175,10 @@ public class DetectionMigrationResourceTest {
AnomalyFunctionDTO actual = OBJECT_MAPPER.readValue(this.getClass().getResourceAsStream("legacy-anomaly-function-1.json"), AnomalyFunctionDTO.class);
long oldID = anomalyFunctionDAO.save(actual);
+ AnomalyFunctionDTO legacyAnomalyFunction = anomalyFunctionDAO.findById(oldID);
+ legacyAnomalyFunction.setCreatedBy("test_user");
+ anomalyFunctionDAO.update(legacyAnomalyFunction);
+
MergedAnomalyResultDTO mergedAnomalyResultDTO = new MergedAnomalyResultDTO();
mergedAnomalyResultDTO.setFunction(actual);
anomalyDAO.save(mergedAnomalyResultDTO);
@@ -182,9 +186,10 @@ public class DetectionMigrationResourceTest {
Response responseId = migrationResource.migrateAnomalyFunction(oldID);
long newID = (long) responseId.getEntity();
- AnomalyFunctionDTO legacyAnomalyFunction = anomalyFunctionDAO.findById(oldID);
DetectionConfigDTO migratedAnomalyFunction = detectionConfigDAO.findById(newID);
+ legacyAnomalyFunction = anomalyFunctionDAO.findById(oldID);
+
// Verify if the migration status is updated correctly and the old detection is disabled.
Assert.assertEquals(legacyAnomalyFunction.getFunctionName(), "test_function_thirdeye_migrated_" + newID);
Assert.assertFalse(legacyAnomalyFunction.getIsActive());
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org