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/13 16:42:41 UTC

[incubator-pinot] branch master updated: [TE] Endpoint to migrate all the applications (#3824)

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 0df5f81  [TE] Endpoint to migrate all the applications (#3824)
0df5f81 is described below

commit 0df5f81d382c7da436b2541b09e3c5792b85edb4
Author: Akshay Rai <ak...@gmail.com>
AuthorDate: Wed Feb 13 08:42:36 2019 -0800

    [TE] Endpoint to migrate all the applications (#3824)
---
 .../dashboard/ThirdEyeDashboardApplication.java    |  7 ++--
 .../detection/DetectionMigrationResource.java      | 40 ++++++++++++++++++++--
 .../detection/DetectionMigrationResourceTest.java  |  2 +-
 3 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/dashboard/ThirdEyeDashboardApplication.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/dashboard/ThirdEyeDashboardApplication.java
index 5174f15..c641052 100644
--- a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/dashboard/ThirdEyeDashboardApplication.java
+++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/dashboard/ThirdEyeDashboardApplication.java
@@ -172,9 +172,10 @@ public class ThirdEyeDashboardApplication
     env.jersey().register(new DataResource(anomalyFunctionFactory, alertFilterFactory));
     env.jersey().register(new AnomaliesResource(anomalyFunctionFactory, alertFilterFactory));
     env.jersey().register(new DetectionMigrationResource(
-        DAO_REGISTRY.getAnomalyFunctionDAO(), DAO_REGISTRY.getAlertConfigDAO(), DAO_REGISTRY.getMetricConfigDAO(),
-        DAO_REGISTRY.getDetectionConfigManager(), DAO_REGISTRY.getDetectionAlertConfigManager(),
-        DAO_REGISTRY.getDatasetConfigDAO(), DAO_REGISTRY.getMergedAnomalyResultDAO()));
+        DAO_REGISTRY.getAnomalyFunctionDAO(), DAO_REGISTRY.getAlertConfigDAO(), DAO_REGISTRY.getApplicationDAO(),
+        DAO_REGISTRY.getMetricConfigDAO(), DAO_REGISTRY.getDetectionConfigManager(),
+        DAO_REGISTRY.getDetectionAlertConfigManager(), DAO_REGISTRY.getDatasetConfigDAO(),
+        DAO_REGISTRY.getMergedAnomalyResultDAO()));
     env.jersey().register(new OnboardResource(config));
     env.jersey().register(new EntityMappingResource());
     env.jersey().register(new OnboardDatasetMetricResource());
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 ebed49c..d7d728a 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
@@ -45,6 +45,7 @@ import org.apache.pinot.thirdeye.anomaly.detection.AnomalyDetectionInputContextB
 import org.apache.pinot.thirdeye.api.Constants;
 import org.apache.pinot.thirdeye.datalayer.bao.AlertConfigManager;
 import org.apache.pinot.thirdeye.datalayer.bao.AnomalyFunctionManager;
+import org.apache.pinot.thirdeye.datalayer.bao.ApplicationManager;
 import org.apache.pinot.thirdeye.datalayer.bao.DatasetConfigManager;
 import org.apache.pinot.thirdeye.datalayer.bao.DetectionAlertConfigManager;
 import org.apache.pinot.thirdeye.datalayer.bao.DetectionConfigManager;
@@ -52,6 +53,7 @@ import org.apache.pinot.thirdeye.datalayer.bao.MergedAnomalyResultManager;
 import org.apache.pinot.thirdeye.datalayer.bao.MetricConfigManager;
 import org.apache.pinot.thirdeye.datalayer.dto.AlertConfigDTO;
 import org.apache.pinot.thirdeye.datalayer.dto.AnomalyFunctionDTO;
+import org.apache.pinot.thirdeye.datalayer.dto.ApplicationDTO;
 import org.apache.pinot.thirdeye.datalayer.dto.DatasetConfigDTO;
 import org.apache.pinot.thirdeye.datalayer.dto.DetectionAlertConfigDTO;
 import org.apache.pinot.thirdeye.datalayer.dto.DetectionConfigDTO;
@@ -91,6 +93,7 @@ public class DetectionMigrationResource {
   private final DatasetConfigManager datasetConfigDAO;
   private final MergedAnomalyResultManager mergedAnomalyResultDAO;
   private final AlertConfigManager alertConfigDAO;
+  private final ApplicationManager appDAO;
   private final MetricConfigManager metricConfigDAO;
   private final Yaml yaml;
 
@@ -100,6 +103,7 @@ public class DetectionMigrationResource {
   public DetectionMigrationResource(
       AnomalyFunctionManager anomalyFunctionDAO,
       AlertConfigManager alertConfigDAO,
+      ApplicationManager appDAO,
       MetricConfigManager metricConfigDAO,
       DetectionConfigManager detectionConfigDAO,
       DetectionAlertConfigManager detectionAlertConfigDAO,
@@ -109,6 +113,7 @@ public class DetectionMigrationResource {
     this.detectionConfigDAO = detectionConfigDAO;
     this.detectionAlertConfigDAO = detectionAlertConfigDAO;
     this.alertConfigDAO = alertConfigDAO;
+    this.appDAO = appDAO;
     this.metricConfigDAO = metricConfigDAO;
     this.datasetConfigDAO = datasetConfigDAO;
     this.mergedAnomalyResultDAO = mergedAnomalyResultDAO;
@@ -559,13 +564,14 @@ public class DetectionMigrationResource {
             String.format("Failed to migrate alert ID %d with name %s due to %s", alertConfigDTO.getId(),
                 alertConfigDTO.getName(), e.getMessage()));
       }
-
     }
 
     if (responseMessage.isEmpty()) {
+      LOGGER.info("[MIG] Application " + application + " has been successfully migrated");
       return Response.ok("Application " + application + " has been successfully migrated").build();
     } else {
-      return Response.status(Response.Status.OK).entity(responseMessage).build();
+      LOGGER.error("[MIG] Found errors while migrating application " + application);
+      return Response.status(Response.Status.BAD_REQUEST).entity(responseMessage).build();
     }
   }
 
@@ -609,4 +615,34 @@ public class DetectionMigrationResource {
 
     return Response.ok(responseMessage).build();
   }
+
+  @POST
+  @ApiOperation("migrate all applications")
+  @Path("/applications")
+  public Response migrateApplication() {
+    List<ApplicationDTO> applicationDTOS = this.appDAO.findAll();
+    Map<String, String> responseMessage = new HashMap<>();
+
+    for (ApplicationDTO app : applicationDTOS) {
+      try {
+        Response response = migrateApplication(app.getApplication());
+        if (response.getStatusInfo() != Response.Status.OK) {
+          throw new RuntimeException("Found " + ConfigUtils.getMap(response.getEntity()).size() + " issues while migrating alerts.");
+        }
+      } catch (Exception e) {
+        // Skip migrating this application
+        LOGGER.error("[MIG] Failed to migrate application {}. Exception {}", app.getApplication(), e);
+        responseMessage.put("Status of application " + app.getApplication(),
+            String.format("Failed to migrate application %s due to %s", app.getApplication(), e.getMessage()));
+      }
+    }
+
+    if (responseMessage.isEmpty()) {
+      LOGGER.info("[MIG] Successfully migrated all the applications");
+      return Response.ok("All applications have been successfully migrated").build();
+    } else {
+      LOGGER.error("[MIG] Errors found while migrating application. Errors:\n" + responseMessage);
+      return Response.status(Response.Status.BAD_REQUEST).entity(responseMessage).build();
+    }
+  }
 }
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 238cff2..5a9c0b3 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
@@ -94,7 +94,7 @@ public class DetectionMigrationResourceTest {
     this.applicationDAO = DAORegistry.getInstance().getApplicationDAO();
 
     migrationResource = new DetectionMigrationResource(
-        anomalyFunctionDAO, alertConfigDAO, metricDAO, detectionConfigDAO, detectionAlertConfigDAO, datasetDAO, anomalyDAO);
+        anomalyFunctionDAO, alertConfigDAO, applicationDAO, metricDAO, detectionConfigDAO, detectionAlertConfigDAO, datasetDAO, anomalyDAO);
 
     DetectionRegistry.registerYamlConvertor(CompositePipelineConfigTranslator.class.getName(), "COMPOSITE");
     DetectionRegistry.registerComponent(PercentageChangeRuleDetector.class.getName(), "PERCENTAGE_RULE");


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