Skip to content

Commit

Permalink
Merge pull request #1621 from tapdata/fix-v3.5.9-email
Browse files Browse the repository at this point in the history
Fix v3.5.9 email
  • Loading branch information
jackin-code committed Dec 27, 2023
2 parents 1bc6c8d + d34dc9b commit 7afe05a
Show file tree
Hide file tree
Showing 10 changed files with 461 additions and 13 deletions.
Expand Up @@ -13,8 +13,7 @@ public class AlarmMailTemplate {
public static final String TASK_STATUS_STOP_MANUAL_TITLE = "【Tapdata Notification:Task stopped】{0}";
public static final String TASK_STATUS_STOP_MANUAL = "Your task has been stopped. \n" +
" Task name: 【{0}】\n" +
" Stop time: {1}\n" +
" Stop reason: 被{2}手动停止";
" Stop time: {1}\n";

public static final String TASK_FULL_COMPLETE_TITLE = "【Tapdata Notification:Initial sync complete】{0}";
public static final String TASK_FULL_COMPLETE = "Your task initial sync has been completed. \n" +
Expand Down
Expand Up @@ -158,6 +158,14 @@ public boolean checkOpen(TaskDto taskDto, String nodeId, AlarmKeyEnum key, Notif
openTask = alarmSettingDtos.stream().anyMatch(t ->
key.equals(t.getKey()) && t.isOpen() && (type ==null || t.getNotify().contains(type)));
}
if (AlarmKeyEnum.TASK_STATUS_STOP.equals(key)){
List<AlarmSettingDto> settingDtos = alarmSettingService.findAllAlarmSetting(userDetail);
Map<AlarmKeyEnum, AlarmSettingDto> settingDtoMap = settingDtos.stream().collect(Collectors.toMap(AlarmSettingDto::getKey, Function.identity(), (e1, e2) -> e1));
List<AlarmSettingDto> alarmSettingDto = Lists.newArrayList();
alarmSettingDto.add(settingDtoMap.get(AlarmKeyEnum.TASK_STATUS_STOP));
openTask = alarmSettingDto.stream().anyMatch(t ->
key.equals(t.getKey()) && t.isOpen() && (type ==null || t.getNotify().contains(type)));
}
}

boolean openSys = false;
Expand Down Expand Up @@ -532,6 +540,11 @@ public Map<String, String> getTaskTitleAndContent(AlarmInfo info) {
content = MessageFormat.format(AlarmMailTemplate.TASK_INCREMENT_DELAY_START, info.getName(), info.getParam().get("currentValue"));
SmsEvent = "增量延迟";
break;
case TASK_STATUS_STOP:
title = MessageFormat.format(AlarmMailTemplate.TASK_STATUS_STOP_MANUAL_TITLE, info.getName());
content = MessageFormat.format(AlarmMailTemplate.TASK_STATUS_STOP_MANUAL, info.getName(), dateTime);
SmsEvent = "任务停止";
break;
case DATANODE_AVERAGE_HANDLE_CONSUME:
title = MessageFormat.format(AlarmMailTemplate.AVERAGE_HANDLE_CONSUME_TITLE, info.getName());
content = MessageFormat.format(AlarmMailTemplate.AVERAGE_HANDLE_CONSUME, info.getName(), info.getNode(), info.getParam().get("currentValue"), info.getParam().get("threshold"), dateTime);
Expand Down
Expand Up @@ -58,7 +58,7 @@ public Boolean onEvent(Element<SyncTaskStatusDto> event, long sequence, boolean
return true;
}

private void taskAlarm(SyncTaskStatusDto data) {
protected void taskAlarm(SyncTaskStatusDto data) {
AlarmService alarmService = SpringUtil.getBean(AlarmService.class);

String taskId = data.getTaskId();
Expand Down Expand Up @@ -86,6 +86,22 @@ private void taskAlarm(SyncTaskStatusDto data) {
alarmService.save(errorInfo);
}
break;
case TaskDto.STATUS_STOP:
TaskDto stopTaskDto = taskService.findById(MongoUtils.toObjectId(taskId));
boolean checkOpenForStop = alarmService.checkOpen(stopTaskDto, null, AlarmKeyEnum.TASK_STATUS_STOP, null, data.getUserDetail());
if (checkOpenForStop) {
param.put("taskName", taskName);
param.put("stopTime", DateUtil.now());
param.put("alarmDate", alarmDate);
AlarmInfo errorInfo = AlarmInfo.builder().status(AlarmStatusEnum.ING).level(Level.NORMAL).component(AlarmComponentEnum.FE)
.type(AlarmTypeEnum.SYNCHRONIZATIONTASK_ALARM).agentId(data.getAgentId()).taskId(taskId)
.name(data.getTaskName()).summary("TASK_STATUS_STOP").metric(AlarmKeyEnum.TASK_STATUS_STOP)
.param(param)
.build();
errorInfo.setUserId(stopTaskDto.getUserId());
alarmService.save(errorInfo);
}
break;
}
}

Expand Down
Expand Up @@ -234,7 +234,6 @@ public void addMigration(String serverName, String sourceId, MsgTypeEnum msgType
log.info("任务恢复运行,只add message, 不用发邮件短信");
return;
}

NotificationDto notificationDto = needInform(SystemEnum.MIGRATION, msgTypeEnum);
Notification userNotification = userDetail.getNotification();
if (null != notificationDto) {
Expand All @@ -250,6 +249,10 @@ public void addMigration(String serverName, String sourceId, MsgTypeEnum msgType
if (userNotification.getStoppedByError().getEmail()) {
log.info("dataflow出错,email 通知");
MessageEntity finalSaveMessage = saveMessage;
if (MsgTypeEnum.DELETED.equals(msgTypeEnum) || MsgTypeEnum.PAUSED.equals(msgTypeEnum)) {
log.info("任务删除或停止,不用发邮件短信");
return;
}
FunctionUtils.isTureOrFalse(settingsService.isCloud()).trueOrFalseHandle(() -> {
informUserEmail(msgTypeEnum, SystemEnum.MIGRATION, serverName, sourceId, finalSaveMessage.getId().toString(), userDetail);
}, () -> {
Expand Down Expand Up @@ -360,7 +363,10 @@ public void addSync(String serverName, String sourceId, MsgTypeEnum msgTypeEnum,
if (notificationDto.getEmail()) {
FunctionUtils.isTureOrFalse(settingsService.isCloud()).trueOrFalseHandle(() -> {
if(checkSending(userDetail)){
SendStatus sendStatus = mailUtils.sendHtmlMail(userDetail.getEmail(), userDetail.getUsername(), serverName, SystemEnum.SYNC, msgTypeEnum, sourceId);
SendStatus sendStatus = new SendStatus("", "false");
if (!MsgTypeEnum.DELETED.equals(msgTypeEnum)) {
sendStatus = mailUtils.sendHtmlMail(userDetail.getEmail(), userDetail.getUsername(), serverName, SystemEnum.SYNC, msgTypeEnum, sourceId);
}
eventsService.recordEvents(MAIL_SUBJECT, MAIL_CONTENT, userDetail.getEmail(), saveMessage.getId().toString(), userDetail.getUserId(), sendStatus, 0, Type.NOTICE_MAIL);
update(Query.query(Criteria.where("_id").is(saveMessage.getId())),Update.update("isSend",true));
}
Expand Down Expand Up @@ -448,7 +454,7 @@ private MessageEntity addMessage(String serverName, String sourceId, SystemEnum
return messageEntity;
}

private MessageEntity addMessage(String serverName, String sourceId, SystemEnum systemEnum, MsgTypeEnum msgTypeEnum, String title, Level level, UserDetail userDetail, Boolean isNotify) {
protected MessageEntity addMessage(String serverName, String sourceId, SystemEnum systemEnum, MsgTypeEnum msgTypeEnum, String title, Level level, UserDetail userDetail, Boolean isNotify) {
MessageEntity messageEntity = new MessageEntity();
messageEntity.setLevel(level.getValue());
messageEntity.setServerName(serverName);
Expand Down
Expand Up @@ -27,4 +27,4 @@ INSPECT_TASK_ERROR =Your verification task [#{[inspectName]}] has stopped due to
INSPECT_COUNT_ERROR = Your verification task [#{[inspectName]}] quick count verification results are inconsistent, the current number of differences is: #{[count]}, please pay attention.
INSPECT_VALUE_ALL_ERROR = Your verification task [#{[inspectName]}] table full field value verification results are inconsistent, the current table data is poor: #{[count]}, please pay attention.
INSPECT_VALUE_JOIN_ERROR = Your verification task [#{[inspectName]}] associated field value verification results are inconsistent, the current table data is poor: #{[count]}, please pay attention.

TASK_STATUS_STOP = Task#{[taskName]} has stopped, stop time point: #{[stopTime]}, alarm time: #{[alarmDate]}
3 changes: 2 additions & 1 deletion manager/tm/src/main/resources/alarmTemplate_zh_CN.properties
Expand Up @@ -26,4 +26,5 @@ LESS=\u5C0F\u4E8E
INSPECT_TASK_ERROR = \u60A8\u7684\u6821\u9A8C\u4EFB\u52A1[#{[inspectName]}]\u5DF2\u51FA\u9519\u505C\u6B62\uFF0C\u65F6\u95F4\uFF1A#{[alarmDate]}\uFF0C\u8BF7\u5173\u6CE8\u3002
INSPECT_COUNT_ERROR = \u60A8\u7684\u6821\u9A8C\u4EFB\u52A1[#{[inspectName]}]\u5FEB\u901Fcount\u6821\u9A8C\u7ED3\u679C\u4E0D\u4E00\u81F4\uFF0C\u5F53\u524D\u5DEE\u5F02\u884C\u6570\u4E3A:#{[count]}\uFF0C\u8BF7\u5173\u6CE8\u3002
INSPECT_VALUE_ALL_ERROR = \u60A8\u7684\u6821\u9A8C\u4EFB\u52A1[#{[inspectName]}]\u8868\u5168\u5B57\u6BB5\u503C\u6821\u9A8C\u7ED3\u679C\u4E0D\u4E00\u81F4\uFF0C\u5F53\u524D\u8868\u6570\u636E\u5DEE:#{[count]}\uFF0C\u8BF7\u5173\u6CE8\u3002
INSPECT_VALUE_JOIN_ERROR = \u60A8\u7684\u6821\u9A8C\u4EFB\u52A1[#{[inspectName]}]\u5173\u8054\u5B57\u6BB5\u503C\u6821\u9A8C\u7ED3\u679C\u4E0D\u4E00\u81F4\uFF0C\u5F53\u524D\u8868\u6570\u636E\u5DEE:#{[count]}\uFF0C\u8BF7\u5173\u6CE8\u3002
INSPECT_VALUE_JOIN_ERROR = \u60A8\u7684\u6821\u9A8C\u4EFB\u52A1[#{[inspectName]}]\u5173\u8054\u5B57\u6BB5\u503C\u6821\u9A8C\u7ED3\u679C\u4E0D\u4E00\u81F4\uFF0C\u5F53\u524D\u8868\u6570\u636E\u5DEE:#{[count]}\uFF0C\u8BF7\u5173\u6CE8\u3002
TASK_STATUS_STOP = \u4efb\u52a1#{[taskName]}\u5df2\u505c\u6b62\uff0c\u505c\u6b62\u65f6\u95f4\u70b9\uff1a#{[stopTime]}, \u544a\u8b66\u65f6\u95f4\uff1a#{[alarmDate]}
Expand Up @@ -27,3 +27,4 @@ INSPECT_TASK_ERROR = \u60A8\u7684\u6821\u9A57\u4EFB\u52D9[#{[inspectName]}]\u5DF
INSPECT_COUNT_ERROR = \u60A8\u7684\u6821\u9A57\u4EFB\u52D9[#{[inspectName]}]\u5FEB\u901Fcount\u6821\u9A57\u7D50\u679C\u4E0D\u4E00\u81F4\uFF0C\u7576\u524D\u5DEE\u7570\u884C\u6578\u70BA:#{[count]}\uFF0C\u8BF7\u5173\u6CE8\u3002
INSPECT_VALUE_ALL_ERROR = \u60A8\u7684\u6821\u9A57\u4EFB\u52D9[#{[inspectName]}]\u8868\u5168\u5B57\u6BB5\u503C\u6821\u9A57\u7D50\u679C\u4E0D\u4E00\u81F4\uFF0C\u7576\u524D\u8868\u6578\u64DA\u5DEE:#{[count]}\uFF0C\u8ACB\u95DC\u6CE8\u3002
INSPECT_VALUE_JOIN_ERROR = \u60A8\u7684\u6821\u9A57\u4EFB\u52D9[#{[inspectName]}]\u95DC\u806F\u5B57\u6BB5\u503C\u6821\u9A57\u7D50\u679C\u4E0D\u4E00\u81F4\uFF0C\u7576\u524D\u8868\u6578\u64DA\u5DEE:#{[count]}\uFF0C\u8ACB\u95DC\u6CE8\u3002
TASK_STATUS_STOP = \u4efb\u52d9#{[taskName]}\u5df2\u505c\u6b62\uff0c\u505c\u6b62\u6642\u9593\u9ede\uff1a#{[stopTime]}, \u544a\u8b66\u6642\u9593\uff1a#{[alarmDate]}

0 comments on commit 7afe05a

Please sign in to comment.