Search in sources :

Example 16 with TaskDTO

use of com.linkedin.thirdeye.datalayer.dto.TaskDTO in project pinot by linkedin.

the class AlertJobRunnerV2 method createTasks.

private List<Long> createTasks(DateTime monitoringWindowStartTime, DateTime monitoringWindowEndTime) {
    List<Long> taskIds = new ArrayList<>();
    try {
        List<AlertTaskInfo> tasks = taskGenerator.createAlertTasksV2(alertJobContext, monitoringWindowStartTime, monitoringWindowEndTime);
        for (AlertTaskInfo taskInfo : tasks) {
            String taskInfoJson = null;
            try {
                taskInfoJson = OBJECT_MAPPER.writeValueAsString(taskInfo);
            } catch (JsonProcessingException e) {
                LOG.error("Exception when converting AlertTaskInfo {} to jsonString", taskInfo, e);
            }
            TaskDTO taskSpec = new TaskDTO();
            taskSpec.setTaskType(TaskConstants.TaskType.ALERT2);
            taskSpec.setJobName(alertJobContext.getJobName());
            taskSpec.setStatus(TaskConstants.TaskStatus.WAITING);
            taskSpec.setStartTime(System.currentTimeMillis());
            taskSpec.setTaskInfo(taskInfoJson);
            taskSpec.setJobId(alertJobContext.getJobExecutionId());
            long taskId = taskDAO.save(taskSpec);
            taskIds.add(taskId);
            LOG.info("Created alert task {} with taskId {}", taskSpec, taskId);
        }
    } catch (Exception e) {
        LOG.error("Exception in creating alert tasks", e);
    }
    return taskIds;
}
Also used : AlertTaskInfo(com.linkedin.thirdeye.anomaly.alert.AlertTaskInfo) ArrayList(java.util.ArrayList) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TaskDTO(com.linkedin.thirdeye.datalayer.dto.TaskDTO) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JobExecutionException(org.quartz.JobExecutionException)

Example 17 with TaskDTO

use of com.linkedin.thirdeye.datalayer.dto.TaskDTO in project pinot by linkedin.

the class DetectionJobRunner method createTasks.

private List<Long> createTasks(DetectionJobContext detectionJobContext, List<DateTime> monitoringWindowStartTimes, List<DateTime> monitoringWindowEndTimes) {
    List<Long> taskIds = new ArrayList<>();
    try {
        List<DetectionTaskInfo> tasks = taskGenerator.createDetectionTasks(detectionJobContext, monitoringWindowStartTimes, monitoringWindowEndTimes);
        for (DetectionTaskInfo taskInfo : tasks) {
            String taskInfoJson = null;
            try {
                taskInfoJson = OBJECT_MAPPER.writeValueAsString(taskInfo);
            } catch (JsonProcessingException e) {
                LOG.error("Exception when converting DetectionTaskInfo {} to jsonString", taskInfo, e);
            }
            TaskDTO taskSpec = new TaskDTO();
            taskSpec.setTaskType(TaskType.ANOMALY_DETECTION);
            taskSpec.setJobName(detectionJobContext.getJobName());
            taskSpec.setStatus(TaskStatus.WAITING);
            taskSpec.setStartTime(System.currentTimeMillis());
            taskSpec.setTaskInfo(taskInfoJson);
            taskSpec.setJobId(detectionJobContext.getJobExecutionId());
            long taskId = DAO_REGISTRY.getTaskDAO().save(taskSpec);
            taskIds.add(taskId);
            LOG.info("Created anomalyTask {} with taskId {}", taskSpec, taskId);
        }
    } catch (Exception e) {
        LOG.error("Exception in creating detection tasks", e);
    }
    return taskIds;
}
Also used : ArrayList(java.util.ArrayList) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TaskDTO(com.linkedin.thirdeye.datalayer.dto.TaskDTO) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 18 with TaskDTO

use of com.linkedin.thirdeye.datalayer.dto.TaskDTO in project pinot by linkedin.

the class DataCompletenessJobRunner method createTasks.

public List<Long> createTasks() {
    List<Long> taskIds = new ArrayList<>();
    try {
        LOG.info("Creating data completeness checker tasks");
        List<DataCompletenessTaskInfo> dataCompletenessTasks = createDataCompletenessTasks(dataCompletenessJobContext);
        LOG.info("DataCompleteness tasks {}", dataCompletenessTasks);
        for (DataCompletenessTaskInfo taskInfo : dataCompletenessTasks) {
            String taskInfoJson = null;
            try {
                taskInfoJson = OBJECT_MAPPER.writeValueAsString(taskInfo);
            } catch (JsonProcessingException e) {
                LOG.error("Exception when converting DataCompletenessTaskInfo {} to jsonString", taskInfo, e);
            }
            TaskDTO taskSpec = new TaskDTO();
            taskSpec.setTaskType(TaskType.DATA_COMPLETENESS);
            taskSpec.setJobName(dataCompletenessJobContext.getJobName());
            taskSpec.setStatus(TaskStatus.WAITING);
            taskSpec.setStartTime(System.currentTimeMillis());
            taskSpec.setTaskInfo(taskInfoJson);
            taskSpec.setJobId(dataCompletenessJobContext.getJobExecutionId());
            long taskId = DAO_REGISTRY.getTaskDAO().save(taskSpec);
            taskIds.add(taskId);
            LOG.info("Created dataCompleteness task {} with taskId {}", taskSpec, taskId);
        }
    } catch (Exception e) {
        LOG.error("Exception in creating data completeness tasks", e);
    }
    return taskIds;
}
Also used : ArrayList(java.util.ArrayList) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TaskDTO(com.linkedin.thirdeye.datalayer.dto.TaskDTO) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 19 with TaskDTO

use of com.linkedin.thirdeye.datalayer.dto.TaskDTO in project pinot by linkedin.

the class TaskManagerImpl method updateStatusAndWorkerId.

@Override
public boolean updateStatusAndWorkerId(Long workerId, Long id, Set<TaskStatus> permittedOldStatus, TaskStatus newStatus, int expectedVersion) {
    TaskDTO task = findById(id);
    if (permittedOldStatus.contains(task.getStatus())) {
        task.setStatus(newStatus);
        task.setWorkerId(workerId);
        //increment the version
        task.setVersion(expectedVersion + 1);
        Predicate predicate = Predicate.AND(Predicate.EQ("id", id), Predicate.EQ("version", expectedVersion));
        int update = update(task, predicate);
        return update == 1;
    } else {
        return false;
    }
}
Also used : TaskDTO(com.linkedin.thirdeye.datalayer.dto.TaskDTO) Predicate(com.linkedin.thirdeye.datalayer.util.Predicate)

Example 20 with TaskDTO

use of com.linkedin.thirdeye.datalayer.dto.TaskDTO in project pinot by linkedin.

the class TaskManagerImpl method findByJobIdStatusNotIn.

@Override
public List<TaskDTO> findByJobIdStatusNotIn(Long jobId, TaskStatus status) {
    Predicate jobIdPredicate = Predicate.EQ("jobId", jobId);
    Predicate statusPredicate = Predicate.NEQ("status", status.toString());
    List<TaskBean> list = genericPojoDao.get(Predicate.AND(statusPredicate, jobIdPredicate), TaskBean.class);
    List<TaskDTO> result = new ArrayList<>();
    for (TaskBean bean : list) {
        result.add((TaskDTO) MODEL_MAPPER.map(bean, TaskDTO.class));
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) TaskBean(com.linkedin.thirdeye.datalayer.pojo.TaskBean) TaskDTO(com.linkedin.thirdeye.datalayer.dto.TaskDTO) Predicate(com.linkedin.thirdeye.datalayer.util.Predicate)

Aggregations

TaskDTO (com.linkedin.thirdeye.datalayer.dto.TaskDTO)22 ArrayList (java.util.ArrayList)10 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)5 Test (org.testng.annotations.Test)4 TaskStatus (com.linkedin.thirdeye.anomaly.task.TaskConstants.TaskStatus)3 TaskBean (com.linkedin.thirdeye.datalayer.pojo.TaskBean)3 Predicate (com.linkedin.thirdeye.datalayer.util.Predicate)3 HashMap (java.util.HashMap)3 JobDTO (com.linkedin.thirdeye.datalayer.dto.JobDTO)2 JobExecutionException (org.quartz.JobExecutionException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BiMap (com.google.common.collect.BiMap)1 Transactional (com.google.inject.persist.Transactional)1 AlertTaskInfo (com.linkedin.thirdeye.anomaly.alert.AlertTaskInfo)1 TaskType (com.linkedin.thirdeye.anomaly.task.TaskConstants.TaskType)1 DataCompletenessTaskInfo (com.linkedin.thirdeye.completeness.checker.DataCompletenessTaskInfo)1 JobManager (com.linkedin.thirdeye.datalayer.bao.JobManager)1 TaskManager (com.linkedin.thirdeye.datalayer.bao.TaskManager)1 MergedAnomalyResultDTO (com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO)1 RawAnomalyResultDTO (com.linkedin.thirdeye.datalayer.dto.RawAnomalyResultDTO)1