[2.0.1][Fix-7284] [api] Fix the missing project information in the process instance timeout alarm (#7309)
* cherry pick * Fix the missing project information in the process instance timeout alarm
This commit is contained in:
parent
79ab27299e
commit
b17fa26d61
|
|
@ -23,7 +23,14 @@ 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.utils.JSONUtils;
|
||||
import org.apache.dolphinscheduler.dao.entity.*;
|
||||
import org.apache.dolphinscheduler.dao.entity.Alert;
|
||||
import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance;
|
||||
import org.apache.dolphinscheduler.dao.entity.ProcessAlertContent;
|
||||
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
|
||||
import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
|
||||
import org.apache.dolphinscheduler.dao.entity.ServerAlertContent;
|
||||
import org.apache.dolphinscheduler.dao.entity.TaskDefinition;
|
||||
import org.apache.dolphinscheduler.dao.entity.TaskInstance;
|
||||
import org.apache.dolphinscheduler.dao.mapper.AlertGroupMapper;
|
||||
import org.apache.dolphinscheduler.dao.mapper.AlertMapper;
|
||||
import org.apache.dolphinscheduler.dao.mapper.AlertPluginInstanceMapper;
|
||||
|
|
@ -111,8 +118,14 @@ public class AlertDao {
|
|||
Alert alert = new Alert();
|
||||
List<ProcessAlertContent> processAlertContentList = new ArrayList<>(1);
|
||||
ProcessAlertContent processAlertContent = ProcessAlertContent.newBuilder()
|
||||
.projectCode(processDefinition.getProjectCode())
|
||||
.projectName(processDefinition.getProjectName())
|
||||
.owner(processDefinition.getUserName())
|
||||
.processId(processInstance.getId())
|
||||
.processDefinitionCode(processInstance.getProcessDefinitionCode())
|
||||
.processName(processInstance.getName())
|
||||
.processStartTime(processInstance.getStartTime())
|
||||
.processHost(processInstance.getHost())
|
||||
.event(AlertEvent.TIME_OUT)
|
||||
.warningLevel(AlertWarnLevel.MIDDLE)
|
||||
.build();
|
||||
|
|
@ -133,28 +146,32 @@ public class AlertDao {
|
|||
/**
|
||||
* task timeout warn
|
||||
*
|
||||
* @param alertGroupId alertGroupId
|
||||
* @param processInstanceId processInstanceId
|
||||
* @param processInstanceName processInstanceName
|
||||
* @param taskId taskId
|
||||
* @param taskName taskName
|
||||
* @param processInstance processInstanceId
|
||||
* @param taskInstance taskInstance
|
||||
* @param taskDefinition taskDefinition
|
||||
*/
|
||||
public void sendTaskTimeoutAlert(int alertGroupId, int processInstanceId,
|
||||
String processInstanceName, int taskId, String taskName) {
|
||||
public void sendTaskTimeoutAlert(ProcessInstance processInstance, TaskInstance taskInstance, TaskDefinition taskDefinition) {
|
||||
Alert alert = new Alert();
|
||||
List<ProcessAlertContent> processAlertContentList = new ArrayList<>(1);
|
||||
ProcessAlertContent processAlertContent = ProcessAlertContent.newBuilder()
|
||||
.processId(processInstanceId)
|
||||
.processName(processInstanceName)
|
||||
.taskId(taskId)
|
||||
.taskName(taskName)
|
||||
.projectCode(taskDefinition.getProjectCode())
|
||||
.projectName(taskDefinition.getProjectName())
|
||||
.owner(taskDefinition.getUserName())
|
||||
.processId(processInstance.getId())
|
||||
.processDefinitionCode(processInstance.getProcessDefinitionCode())
|
||||
.processName(processInstance.getName())
|
||||
.taskCode(taskInstance.getTaskCode())
|
||||
.taskName(taskInstance.getName())
|
||||
.taskType(taskInstance.getTaskType())
|
||||
.taskStartTime(taskInstance.getStartTime())
|
||||
.taskHost(taskInstance.getHost())
|
||||
.event(AlertEvent.TIME_OUT)
|
||||
.warningLevel(AlertWarnLevel.MIDDLE)
|
||||
.build();
|
||||
processAlertContentList.add(processAlertContent);
|
||||
String content = JSONUtils.toJsonString(processAlertContentList);
|
||||
alert.setTitle("Task Timeout Warn");
|
||||
saveTaskTimeoutAlert(alert, content, alertGroupId);
|
||||
saveTaskTimeoutAlert(alert, content, processInstance.getWarningGroupId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -33,14 +33,19 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
public class ProcessAlertContent implements Serializable {
|
||||
|
||||
@JsonProperty("projectId")
|
||||
private int projectId;
|
||||
private Integer projectId;
|
||||
@JsonProperty("projectCode")
|
||||
private Long projectCode;
|
||||
@JsonProperty("projectName")
|
||||
private String projectName;
|
||||
@JsonProperty("owner")
|
||||
private String owner;
|
||||
@JsonProperty("processId")
|
||||
private int processId;
|
||||
private Integer processId;
|
||||
@JsonProperty("processDefinitionCode")
|
||||
private Long processDefinitionCode;
|
||||
@JsonProperty("processName")
|
||||
private String processName;
|
||||
@JsonProperty("processType")
|
||||
|
|
@ -50,7 +55,7 @@ public class ProcessAlertContent implements Serializable {
|
|||
@JsonProperty("recovery")
|
||||
private Flag recovery;
|
||||
@JsonProperty("runTimes")
|
||||
private int runTimes;
|
||||
private Integer runTimes;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
@JsonProperty("processStartTime")
|
||||
private Date processStartTime;
|
||||
|
|
@ -59,8 +64,8 @@ public class ProcessAlertContent implements Serializable {
|
|||
private Date processEndTime;
|
||||
@JsonProperty("processHost")
|
||||
private String processHost;
|
||||
@JsonProperty("taskId")
|
||||
private int taskId;
|
||||
@JsonProperty("taskCode")
|
||||
private Long taskCode;
|
||||
@JsonProperty("taskName")
|
||||
private String taskName;
|
||||
@JsonProperty("event")
|
||||
|
|
@ -70,7 +75,7 @@ public class ProcessAlertContent implements Serializable {
|
|||
@JsonProperty("taskType")
|
||||
private String taskType;
|
||||
@JsonProperty("retryTimes")
|
||||
private int retryTimes;
|
||||
private Integer retryTimes;
|
||||
@JsonProperty("taskState")
|
||||
private ExecutionStatus taskState;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
|
|
@ -86,9 +91,11 @@ public class ProcessAlertContent implements Serializable {
|
|||
|
||||
private ProcessAlertContent(Builder builder) {
|
||||
this.projectId = builder.projectId;
|
||||
this.projectCode = builder.projectCode;
|
||||
this.projectName = builder.projectName;
|
||||
this.owner = builder.owner;
|
||||
this.processId = builder.processId;
|
||||
this.processDefinitionCode = builder.processDefinitionCode;
|
||||
this.processName = builder.processName;
|
||||
this.processType = builder.processType;
|
||||
this.recovery = builder.recovery;
|
||||
|
|
@ -97,7 +104,7 @@ public class ProcessAlertContent implements Serializable {
|
|||
this.processStartTime = builder.processStartTime;
|
||||
this.processEndTime = builder.processEndTime;
|
||||
this.processHost = builder.processHost;
|
||||
this.taskId = builder.taskId;
|
||||
this.taskCode = builder.taskCode;
|
||||
this.taskName = builder.taskName;
|
||||
this.event = builder.event;
|
||||
this.warnLevel = builder.warnLevel;
|
||||
|
|
@ -116,34 +123,40 @@ public class ProcessAlertContent implements Serializable {
|
|||
}
|
||||
|
||||
public static class Builder {
|
||||
private int projectId;
|
||||
private Integer projectId;
|
||||
private Long projectCode;
|
||||
private String projectName;
|
||||
private String owner;
|
||||
private int processId;
|
||||
private Integer processId;
|
||||
private Long processDefinitionCode;
|
||||
private String processName;
|
||||
private CommandType processType;
|
||||
private Flag recovery;
|
||||
private ExecutionStatus processState;
|
||||
private int runTimes;
|
||||
private Integer runTimes;
|
||||
private Date processStartTime;
|
||||
private Date processEndTime;
|
||||
private String processHost;
|
||||
private int taskId;
|
||||
private Long taskCode;
|
||||
private String taskName;
|
||||
private AlertEvent event;
|
||||
private AlertWarnLevel warnLevel;
|
||||
private String taskType;
|
||||
private int retryTimes;
|
||||
private Integer retryTimes;
|
||||
private ExecutionStatus taskState;
|
||||
private Date taskStartTime;
|
||||
private Date taskEndTime;
|
||||
private String taskHost;
|
||||
private String logPath;
|
||||
|
||||
public Builder projectId(int projectId) {
|
||||
public Builder projectId(Integer projectId) {
|
||||
this.projectId = projectId;
|
||||
return this;
|
||||
}
|
||||
public Builder projectCode(Long projectCode) {
|
||||
this.projectCode = projectCode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder projectName(String projectName) {
|
||||
this.projectName = projectName;
|
||||
|
|
@ -155,10 +168,14 @@ public class ProcessAlertContent implements Serializable {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder processId(int processId) {
|
||||
public Builder processId(Integer processId) {
|
||||
this.processId = processId;
|
||||
return this;
|
||||
}
|
||||
public Builder processDefinitionCode(Long processDefinitionCode) {
|
||||
this.processDefinitionCode = processDefinitionCode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder processName(String processName) {
|
||||
this.processName = processName;
|
||||
|
|
@ -180,7 +197,7 @@ public class ProcessAlertContent implements Serializable {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder runTimes(int runTimes) {
|
||||
public Builder runTimes(Integer runTimes) {
|
||||
this.runTimes = runTimes;
|
||||
return this;
|
||||
}
|
||||
|
|
@ -200,8 +217,8 @@ public class ProcessAlertContent implements Serializable {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder taskId(int taskId) {
|
||||
this.taskId = taskId;
|
||||
public Builder taskCode(Long taskCode) {
|
||||
this.taskCode = taskCode;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -225,7 +242,7 @@ public class ProcessAlertContent implements Serializable {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder retryTimes(int retryTimes) {
|
||||
public Builder retryTimes(Integer retryTimes) {
|
||||
this.retryTimes = retryTimes;
|
||||
return this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,6 +108,7 @@ public class ProcessAlertManager {
|
|||
.projectName(projectUser.getProjectName())
|
||||
.owner(projectUser.getUserName())
|
||||
.processId(processInstance.getId())
|
||||
.processDefinitionCode(processInstance.getProcessDefinitionCode())
|
||||
.processName(processInstance.getName())
|
||||
.processType(processInstance.getCommandType())
|
||||
.processState(processInstance.getState())
|
||||
|
|
@ -131,8 +132,9 @@ public class ProcessAlertManager {
|
|||
.projectName(projectUser.getProjectName())
|
||||
.owner(projectUser.getUserName())
|
||||
.processId(processInstance.getId())
|
||||
.processDefinitionCode(processInstance.getProcessDefinitionCode())
|
||||
.processName(processInstance.getName())
|
||||
.taskId(task.getId())
|
||||
.taskCode(task.getTaskCode())
|
||||
.taskName(task.getName())
|
||||
.taskType(task.getTaskType())
|
||||
.taskState(task.getState())
|
||||
|
|
@ -162,7 +164,10 @@ public class ProcessAlertManager {
|
|||
|
||||
for (TaskInstance taskInstance : toleranceTaskList) {
|
||||
ProcessAlertContent processAlertContent = ProcessAlertContent.newBuilder()
|
||||
.processId(processInstance.getId())
|
||||
.processDefinitionCode(processInstance.getProcessDefinitionCode())
|
||||
.processName(processInstance.getName())
|
||||
.taskCode(taskInstance.getTaskCode())
|
||||
.taskName(taskInstance.getName())
|
||||
.taskHost(taskInstance.getHost())
|
||||
.retryTimes(taskInstance.getRetryTimes())
|
||||
|
|
@ -255,7 +260,6 @@ public class ProcessAlertManager {
|
|||
}
|
||||
|
||||
public void sendTaskTimeoutAlert(ProcessInstance processInstance, TaskInstance taskInstance, TaskDefinition taskDefinition) {
|
||||
alertDao.sendTaskTimeoutAlert(processInstance.getWarningGroupId(), processInstance.getId(),processInstance.getName(),
|
||||
taskInstance.getId(), taskInstance.getName());
|
||||
alertDao.sendTaskTimeoutAlert(processInstance, taskInstance, taskDefinition);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue