From fb0139e959d66b7531ee8d075c44cc5d1bd36c85 Mon Sep 17 00:00:00 2001 From: Tq Date: Tue, 12 Apr 2022 14:31:38 +0800 Subject: [PATCH] [Feature] [ALERT-9406]enrich alert info when insert new row into DB (#9445) * enrich alert info when insert new row into DB * fix comments --- .../common/enums/AlertType.java | 14 +++++++++----- .../apache/dolphinscheduler/dao/AlertDao.java | 12 +++++++++++- .../dolphinscheduler/dao/entity/Alert.java | 9 +++++---- .../service/alert/ProcessAlertManager.java | 18 ++++++++++++++++++ 4 files changed, 43 insertions(+), 10 deletions(-) diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/AlertType.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/AlertType.java index 50ab51fe3e..8b97dbdf93 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/AlertType.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/AlertType.java @@ -24,13 +24,17 @@ import com.baomidou.mybatisplus.annotation.EnumValue; */ public enum AlertType { /** - * 0 process instance failure; 1 process instance success, 2 fault tolerance warning, 3 task failure, 4 task success - */ + * 0 process instance failure, 1 process instance success, 2 process instance blocked, 3 process instance timeout, 4 fault tolerance warning, + * 5 task failure, 6 task success, 7 task timeout + */ PROCESS_INSTANCE_FAILURE(0, "process instance failure"), PROCESS_INSTANCE_SUCCESS(1, "process instance success"), - FAULT_TOLERANCE_WARNING(2, "fault tolerance warning"), - TASK_FAILURE(3, "task failure"), - TASK_SUCCESS(4, "task success"); + PROCESS_INSTANCE_BLOCKED(2, "process instance blocked"), + PROCESS_INSTANCE_TIMEOUT(3, "process instance timeout"), + FAULT_TOLERANCE_WARNING(4, "fault tolerance warning"), + TASK_FAILURE(5, "task failure"), + TASK_SUCCESS(6, "task success"), + TASK_TIMEOUT(7, "task timeout"),; AlertType(int code, String descp) { this.code = code; diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/AlertDao.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/AlertDao.java index 00755e3b87..b2d5c60a67 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/AlertDao.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/AlertDao.java @@ -21,6 +21,7 @@ import org.apache.dolphinscheduler.common.enums.AlertEvent; import org.apache.dolphinscheduler.common.enums.AlertStatus; import org.apache.dolphinscheduler.common.enums.AlertWarnLevel; import org.apache.dolphinscheduler.common.enums.WarningType; +import org.apache.dolphinscheduler.common.enums.AlertType; import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.dao.entity.Alert; import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance; @@ -73,7 +74,7 @@ public class AlertDao { } /** - * update alert + * update alert sending(execution) status * * @param alertStatus alertStatus * @param log log @@ -131,6 +132,7 @@ public class AlertDao { alert.setAlertGroupId(alertGroupId); alert.setCreateTime(new Date()); alert.setUpdateTime(new Date()); + alert.setAlertType(AlertType.FAULT_TOLERANCE_WARNING); // we use this method to avoid insert duplicate alert(issue #5525) alertMapper.insertAlertWhenServerCrash(alert); } @@ -163,6 +165,10 @@ public class AlertDao { processAlertContentList.add(processAlertContent); String content = JSONUtils.toJsonString(processAlertContentList); alert.setTitle("Process Timeout Warn"); + alert.setProjectCode(projectUser.getProjectCode()); + alert.setProcessDefinitionCode(processInstance.getProcessDefinitionCode()); + alert.setProcessInstanceId(processInstance.getId()); + alert.setAlertType(AlertType.PROCESS_INSTANCE_TIMEOUT); saveTaskTimeoutAlert(alert, content, alertGroupId); } @@ -203,6 +209,10 @@ public class AlertDao { processAlertContentList.add(processAlertContent); String content = JSONUtils.toJsonString(processAlertContentList); alert.setTitle("Task Timeout Warn"); + alert.setProjectCode(projectUser.getProjectCode()); + alert.setProcessDefinitionCode(processInstance.getProcessDefinitionCode()); + alert.setProcessInstanceId(processInstance.getId()); + alert.setAlertType(AlertType.TASK_TIMEOUT); saveTaskTimeoutAlert(alert, content, processInstance.getWarningGroupId()); } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Alert.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Alert.java index c8a54cf651..388d294655 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Alert.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Alert.java @@ -18,6 +18,7 @@ package org.apache.dolphinscheduler.dao.entity; import org.apache.dolphinscheduler.common.enums.AlertStatus; +import org.apache.dolphinscheduler.common.enums.AlertType; import org.apache.dolphinscheduler.common.enums.WarningType; import java.util.Date; @@ -66,7 +67,7 @@ public class Alert { @TableField(value = "log") private String log; - /** + /**g * alertgroup_id */ @TableField("alertgroup_id") @@ -105,7 +106,7 @@ public class Alert { * alert_type */ @TableField("alert_type") - private int alertType; + private AlertType alertType; @TableField(exist = false) private Map info = new HashMap<>(); @@ -217,11 +218,11 @@ public class Alert { this.processInstanceId = processInstanceId; } - public int getAlertType() { + public AlertType getAlertType() { return alertType; } - public void setAlertType(int alertType) { + public void setAlertType(AlertType alertType) { this.alertType = alertType; } diff --git a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/alert/ProcessAlertManager.java b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/alert/ProcessAlertManager.java index 0765b48ce4..4fca7b47c6 100644 --- a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/alert/ProcessAlertManager.java +++ b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/alert/ProcessAlertManager.java @@ -17,6 +17,7 @@ package org.apache.dolphinscheduler.service.alert; +import org.apache.dolphinscheduler.common.enums.AlertType; import org.apache.dolphinscheduler.common.enums.CommandType; import org.apache.dolphinscheduler.common.enums.Flag; import org.apache.dolphinscheduler.common.enums.WarningType; @@ -194,6 +195,7 @@ public class ProcessAlertManager { alert.setWarningType(WarningType.FAILURE); alert.setCreateTime(new Date()); alert.setAlertGroupId(processInstance.getWarningGroupId() == null ? 1 : processInstance.getWarningGroupId()); + alert.setAlertType(AlertType.FAULT_TOLERANCE_WARNING); alertDao.addAlert(alert); logger.info("add alert to db , alert : {}", alert); @@ -227,6 +229,10 @@ public class ProcessAlertManager { alert.setContent(content); alert.setAlertGroupId(processInstance.getWarningGroupId()); alert.setCreateTime(new Date()); + alert.setProjectCode(projectUser.getProjectCode()); + alert.setProcessDefinitionCode(processInstance.getProcessDefinitionCode()); + alert.setProcessInstanceId(processInstance.getId()); + alert.setAlertType(processInstance.getState().typeIsSuccess() ? AlertType.PROCESS_INSTANCE_SUCCESS : AlertType.PROCESS_INSTANCE_FAILURE); alertDao.addAlert(alert); logger.info("add alert to db , alert: {}", alert); } @@ -285,6 +291,11 @@ public class ProcessAlertManager { alert.setContent(content); alert.setAlertGroupId(processInstance.getWarningGroupId()); alert.setCreateTime(new Date()); + alert.setProjectCode(result.getProjectCode()); + alert.setProcessDefinitionCode(processInstance.getProcessDefinitionCode()); + alert.setProcessInstanceId(processInstance.getId()); + //might need to change to data quality status + alert.setAlertType(processInstance.getState().typeIsSuccess() ? AlertType.PROCESS_INSTANCE_SUCCESS : AlertType.PROCESS_INSTANCE_FAILURE); alertDao.addAlert(alert); logger.info("add alert to db , alert: {}", alert); } @@ -299,6 +310,9 @@ public class ProcessAlertManager { alert.setContent(content); alert.setAlertGroupId(processInstance.getWarningGroupId()); alert.setCreateTime(new Date()); + alert.setProcessDefinitionCode(processInstance.getProcessDefinitionCode()); + alert.setProcessInstanceId(processInstance.getId()); + alert.setAlertType(AlertType.TASK_FAILURE); alertDao.addAlert(alert); logger.info("add alert to db , alert: {}", alert); } @@ -392,6 +406,10 @@ public class ProcessAlertManager { alert.setContent(content); alert.setAlertGroupId(processInstance.getWarningGroupId()); alert.setCreateTime(new Date()); + alert.setProjectCode(projectUser.getProjectCode()); + alert.setProcessDefinitionCode(processInstance.getProcessDefinitionCode()); + alert.setProcessInstanceId(processInstance.getId()); + alert.setAlertType(AlertType.PROCESS_INSTANCE_BLOCKED); alertDao.addAlert(alert); logger.info("add alert to db, alert: {}",alert); }