|
|
@ -14,15 +14,14 @@ |
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
* limitations under the License. |
|
|
|
* limitations under the License. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package org.apache.dolphinscheduler.dao; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package org.apache.dolphinscheduler.dao; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.common.utils.StringUtils; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.common.enums.AlertStatus; |
|
|
|
import org.apache.dolphinscheduler.common.enums.AlertStatus; |
|
|
|
import org.apache.dolphinscheduler.common.enums.AlertType; |
|
|
|
import org.apache.dolphinscheduler.common.enums.AlertType; |
|
|
|
import org.apache.dolphinscheduler.common.enums.ShowType; |
|
|
|
import org.apache.dolphinscheduler.common.enums.ShowType; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.common.utils.StringUtils; |
|
|
|
import org.apache.dolphinscheduler.dao.datasource.ConnectionFactory; |
|
|
|
import org.apache.dolphinscheduler.dao.datasource.ConnectionFactory; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.Alert; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.Alert; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
|
|
@ -30,13 +29,17 @@ import org.apache.dolphinscheduler.dao.entity.ProcessInstance; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.User; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.User; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.AlertMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.AlertMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.UserAlertGroupMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.UserAlertGroupMapper; |
|
|
|
import org.slf4j.Logger; |
|
|
|
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.Date; |
|
|
|
|
|
|
|
import java.util.LinkedHashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
|
|
|
@Component |
|
|
|
@Component |
|
|
|
public class AlertDao extends AbstractBaseDao { |
|
|
|
public class AlertDao extends AbstractBaseDao { |
|
|
|
|
|
|
|
|
|
|
@ -56,6 +59,7 @@ public class AlertDao extends AbstractBaseDao { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* insert alert |
|
|
|
* insert alert |
|
|
|
|
|
|
|
* |
|
|
|
* @param alert alert |
|
|
|
* @param alert alert |
|
|
|
* @return add alert result |
|
|
|
* @return add alert result |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -65,6 +69,7 @@ public class AlertDao extends AbstractBaseDao { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* update alert |
|
|
|
* update alert |
|
|
|
|
|
|
|
* |
|
|
|
* @param alertStatus alertStatus |
|
|
|
* @param alertStatus alertStatus |
|
|
|
* @param log log |
|
|
|
* @param log log |
|
|
|
* @param id id |
|
|
|
* @param id id |
|
|
@ -80,6 +85,7 @@ public class AlertDao extends AbstractBaseDao { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* query user list by alert group id |
|
|
|
* query user list by alert group id |
|
|
|
|
|
|
|
* |
|
|
|
* @param alerGroupId alerGroupId |
|
|
|
* @param alerGroupId alerGroupId |
|
|
|
* @return user list |
|
|
|
* @return user list |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -90,20 +96,28 @@ public class AlertDao extends AbstractBaseDao { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* MasterServer or WorkerServer stoped |
|
|
|
* MasterServer or WorkerServer stoped |
|
|
|
|
|
|
|
* |
|
|
|
* @param alertgroupId alertgroupId |
|
|
|
* @param alertgroupId alertgroupId |
|
|
|
* @param host host |
|
|
|
* @param host host |
|
|
|
* @param serverType serverType |
|
|
|
* @param serverType serverType |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void sendServerStopedAlert(int alertgroupId, String host, String serverType) { |
|
|
|
public void sendServerStopedAlert(int alertgroupId, String host, String serverType) { |
|
|
|
Alert alert = new Alert(); |
|
|
|
Alert alert = new Alert(); |
|
|
|
String content = String.format("[{'type':'%s','host':'%s','event':'server down','warning level':'serious'}]", |
|
|
|
List<LinkedHashMap> serverStopList = new ArrayList<>(1); |
|
|
|
serverType, host); |
|
|
|
LinkedHashMap<String, String> serverStopedMap = new LinkedHashMap(); |
|
|
|
|
|
|
|
serverStopedMap.put("type", serverType); |
|
|
|
|
|
|
|
serverStopedMap.put("host", host); |
|
|
|
|
|
|
|
serverStopedMap.put("event", "server down"); |
|
|
|
|
|
|
|
serverStopedMap.put("warning level", "serious"); |
|
|
|
|
|
|
|
serverStopList.add(serverStopedMap); |
|
|
|
|
|
|
|
String content = JSONUtils.toJsonString(serverStopList); |
|
|
|
alert.setTitle("Fault tolerance warning"); |
|
|
|
alert.setTitle("Fault tolerance warning"); |
|
|
|
saveTaskTimeoutAlert(alert, content, alertgroupId, null, null); |
|
|
|
saveTaskTimeoutAlert(alert, content, alertgroupId, null, null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* process time out alert |
|
|
|
* process time out alert |
|
|
|
|
|
|
|
* |
|
|
|
* @param processInstance processInstance |
|
|
|
* @param processInstance processInstance |
|
|
|
* @param processDefinition processDefinition |
|
|
|
* @param processDefinition processDefinition |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -112,8 +126,14 @@ public class AlertDao extends AbstractBaseDao { |
|
|
|
String receivers = processDefinition.getReceivers(); |
|
|
|
String receivers = processDefinition.getReceivers(); |
|
|
|
String receiversCc = processDefinition.getReceiversCc(); |
|
|
|
String receiversCc = processDefinition.getReceiversCc(); |
|
|
|
Alert alert = new Alert(); |
|
|
|
Alert alert = new Alert(); |
|
|
|
String content = String.format("[{'id':'%d','name':'%s','event':'timeout','warnLevel':'middle'}]", |
|
|
|
List<LinkedHashMap> processTimeoutList = new ArrayList<>(1); |
|
|
|
processInstance.getId(), processInstance.getName()); |
|
|
|
LinkedHashMap<String, String> processTimeoutMap = new LinkedHashMap(); |
|
|
|
|
|
|
|
processTimeoutMap.put("id", String.valueOf(processInstance.getId())); |
|
|
|
|
|
|
|
processTimeoutMap.put("name", processInstance.getName()); |
|
|
|
|
|
|
|
processTimeoutMap.put("event", "timeout"); |
|
|
|
|
|
|
|
processTimeoutMap.put("warnLevel", "middle"); |
|
|
|
|
|
|
|
processTimeoutList.add(processTimeoutMap); |
|
|
|
|
|
|
|
String content = JSONUtils.toJsonString(processTimeoutList); |
|
|
|
alert.setTitle("Process Timeout Warn"); |
|
|
|
alert.setTitle("Process Timeout Warn"); |
|
|
|
saveTaskTimeoutAlert(alert, content, alertgroupId, receivers, receiversCc); |
|
|
|
saveTaskTimeoutAlert(alert, content, alertgroupId, receivers, receiversCc); |
|
|
|
} |
|
|
|
} |
|
|
@ -135,9 +155,9 @@ public class AlertDao extends AbstractBaseDao { |
|
|
|
alertMapper.insert(alert); |
|
|
|
alertMapper.insert(alert); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* task timeout warn |
|
|
|
* task timeout warn |
|
|
|
|
|
|
|
* |
|
|
|
* @param alertgroupId alertgroupId |
|
|
|
* @param alertgroupId alertgroupId |
|
|
|
* @param receivers receivers |
|
|
|
* @param receivers receivers |
|
|
|
* @param receiversCc receiversCc |
|
|
|
* @param receiversCc receiversCc |
|
|
@ -149,14 +169,23 @@ public class AlertDao extends AbstractBaseDao { |
|
|
|
public void sendTaskTimeoutAlert(int alertgroupId, String receivers, String receiversCc, int processInstanceId, |
|
|
|
public void sendTaskTimeoutAlert(int alertgroupId, String receivers, String receiversCc, int processInstanceId, |
|
|
|
String processInstanceName, int taskId, String taskName) { |
|
|
|
String processInstanceName, int taskId, String taskName) { |
|
|
|
Alert alert = new Alert(); |
|
|
|
Alert alert = new Alert(); |
|
|
|
String content = String.format("[{'process instance id':'%d','task name':'%s','task id':'%d','task name':'%s'," + |
|
|
|
List<LinkedHashMap> taskTimeoutList = new ArrayList<>(1); |
|
|
|
"'event':'timeout','warnLevel':'middle'}]", processInstanceId, processInstanceName, taskId, taskName); |
|
|
|
LinkedHashMap<String, String> taskTimeoutMap = new LinkedHashMap(); |
|
|
|
|
|
|
|
taskTimeoutMap.put("process instance id", String.valueOf(processInstanceId)); |
|
|
|
|
|
|
|
taskTimeoutMap.put("process name", processInstanceName); |
|
|
|
|
|
|
|
taskTimeoutMap.put("task id", String.valueOf(taskId)); |
|
|
|
|
|
|
|
taskTimeoutMap.put("task name", taskName); |
|
|
|
|
|
|
|
taskTimeoutMap.put("event", "timeout"); |
|
|
|
|
|
|
|
taskTimeoutMap.put("warnLevel", "middle"); |
|
|
|
|
|
|
|
taskTimeoutList.add(taskTimeoutMap); |
|
|
|
|
|
|
|
String content = JSONUtils.toJsonString(taskTimeoutList); |
|
|
|
alert.setTitle("Task Timeout Warn"); |
|
|
|
alert.setTitle("Task Timeout Warn"); |
|
|
|
saveTaskTimeoutAlert(alert, content, alertgroupId, receivers, receiversCc); |
|
|
|
saveTaskTimeoutAlert(alert, content, alertgroupId, receivers, receiversCc); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* list the alert information of waiting to be executed |
|
|
|
* list the alert information of waiting to be executed |
|
|
|
|
|
|
|
* |
|
|
|
* @return alert list |
|
|
|
* @return alert list |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public List<Alert> listWaitExecutionAlert() { |
|
|
|
public List<Alert> listWaitExecutionAlert() { |
|
|
@ -165,6 +194,7 @@ public class AlertDao extends AbstractBaseDao { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* list user information by alert group id |
|
|
|
* list user information by alert group id |
|
|
|
|
|
|
|
* |
|
|
|
* @param alertgroupId alertgroupId |
|
|
|
* @param alertgroupId alertgroupId |
|
|
|
* @return user list |
|
|
|
* @return user list |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -174,6 +204,7 @@ public class AlertDao extends AbstractBaseDao { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* for test |
|
|
|
* for test |
|
|
|
|
|
|
|
* |
|
|
|
* @return AlertMapper |
|
|
|
* @return AlertMapper |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public AlertMapper getAlertMapper() { |
|
|
|
public AlertMapper getAlertMapper() { |
|
|
|