akshayrai commented on a change in pull request #3790: [TE] yaml - onboarding 
tasks
URL: https://github.com/apache/incubator-pinot/pull/3790#discussion_r254363559
 
 

 ##########
 File path: 
thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/onboard/YamlOnboardingTaskRunner.java
 ##########
 @@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.pinot.thirdeye.detection.onboard;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.thirdeye.anomaly.task.TaskContext;
+import org.apache.pinot.thirdeye.anomaly.task.TaskInfo;
+import org.apache.pinot.thirdeye.anomaly.task.TaskResult;
+import org.apache.pinot.thirdeye.anomaly.task.TaskRunner;
+import org.apache.pinot.thirdeye.constant.AnomalyResultSource;
+import org.apache.pinot.thirdeye.datalayer.bao.DatasetConfigManager;
+import org.apache.pinot.thirdeye.datalayer.bao.DetectionConfigManager;
+import org.apache.pinot.thirdeye.datalayer.bao.EventManager;
+import org.apache.pinot.thirdeye.datalayer.bao.MergedAnomalyResultManager;
+import org.apache.pinot.thirdeye.datalayer.bao.MetricConfigManager;
+import org.apache.pinot.thirdeye.datalayer.dto.DetectionConfigDTO;
+import org.apache.pinot.thirdeye.datalayer.dto.MergedAnomalyResultDTO;
+import org.apache.pinot.thirdeye.datasource.DAORegistry;
+import org.apache.pinot.thirdeye.datasource.ThirdEyeCacheRegistry;
+import org.apache.pinot.thirdeye.datasource.loader.AggregationLoader;
+import org.apache.pinot.thirdeye.datasource.loader.DefaultAggregationLoader;
+import org.apache.pinot.thirdeye.datasource.loader.DefaultTimeSeriesLoader;
+import org.apache.pinot.thirdeye.datasource.loader.TimeSeriesLoader;
+import org.apache.pinot.thirdeye.detection.DataProvider;
+import org.apache.pinot.thirdeye.detection.DefaultDataProvider;
+import org.apache.pinot.thirdeye.detection.DetectionPipeline;
+import org.apache.pinot.thirdeye.detection.DetectionPipelineLoader;
+import org.apache.pinot.thirdeye.detection.DetectionPipelineResult;
+import org.apache.pinot.thirdeye.detection.yaml.YamlDetectionConfigTranslator;
+import org.apache.pinot.thirdeye.detection.yaml.YamlDetectionTranslatorLoader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.yaml.snakeyaml.Yaml;
+
+
+public class YamlOnboardingTaskRunner implements TaskRunner {
+  private static final Logger LOG = 
LoggerFactory.getLogger(YamlOnboardingTaskRunner.class);
+  private final DetectionConfigManager detectionDAO;
+  private final MergedAnomalyResultManager anomalyDAO;
+  private final DetectionPipelineLoader loader;
+  private final DataProvider provider;
+  private final YamlDetectionTranslatorLoader translatorLoader;
+  private final Yaml yaml;
+
+
+  public YamlOnboardingTaskRunner() {
+    this.loader = new DetectionPipelineLoader();
+    this.detectionDAO = DAORegistry.getInstance().getDetectionConfigManager();
+    this.anomalyDAO = DAORegistry.getInstance().getMergedAnomalyResultDAO();
+    this.translatorLoader = new YamlDetectionTranslatorLoader();
+    this.yaml = new Yaml();
+
+    MetricConfigManager metricDAO = 
DAORegistry.getInstance().getMetricConfigDAO();
+    DatasetConfigManager datasetDAO = 
DAORegistry.getInstance().getDatasetConfigDAO();
+    EventManager eventDAO = DAORegistry.getInstance().getEventDAO();
+
+    TimeSeriesLoader timeseriesLoader =
+        new DefaultTimeSeriesLoader(metricDAO, datasetDAO,
+            ThirdEyeCacheRegistry.getInstance().getQueryCache());
+
+    AggregationLoader aggregationLoader =
+        new DefaultAggregationLoader(metricDAO, datasetDAO,
+            ThirdEyeCacheRegistry.getInstance().getQueryCache(),
+            ThirdEyeCacheRegistry.getInstance().getDatasetMaxDataTimeCache());
+
+    this.provider = new DefaultDataProvider(metricDAO, datasetDAO, eventDAO, 
this.anomalyDAO,
+        timeseriesLoader, aggregationLoader, this.loader);
+  }
+
+  @Override
+  public List<TaskResult> execute(TaskInfo taskInfo, TaskContext taskContext) 
throws Exception {
+    YamlOnboardingTaskInfo info = (YamlOnboardingTaskInfo) taskInfo;
+    LOG.info("Running yaml detection onboarding task for id {}", 
info.getConfigId());
+
+    // replay the detection pipeline
+    DetectionConfigDTO config = this.detectionDAO.findById(info.getConfigId());
+    if (config == null) {
+      throw new IllegalArgumentException(String.format("Could not resolve 
config id %d", info.getConfigId()));
+    }
+
+    DetectionPipeline pipeline = this.loader.from(this.provider, config, 
info.getStart(), info.getEnd());
+    DetectionPipelineResult result = pipeline.run();
+
+    if (result.getLastTimestamp() < 0) {
+      return Collections.emptyList();
+    }
+
+    config.setLastTimestamp(result.getLastTimestamp());
+    this.detectionDAO.update(config);
+
+    for (MergedAnomalyResultDTO anomaly : result.getAnomalies()) {
+      anomaly.setAnomalyResultSource(AnomalyResultSource.ANOMALY_REPLAY);
+      this.anomalyDAO.save(anomaly);
+    }
+
+    for (MergedAnomalyResultDTO mergedAnomalyResultDTO : 
result.getAnomalies()) {
+      this.anomalyDAO.save(mergedAnomalyResultDTO);
 
 Review comment:
   Can this be merged with the above loop?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@pinot.apache.org
For additional commands, e-mail: dev-h...@pinot.apache.org

Reply via email to