You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by jo...@apache.org on 2020/01/10 08:33:26 UTC
[incubator-dolphinscheduler] branch dev updated: add retMap null
check for AlertSender (#1796)
This is an automated email from the ASF dual-hosted git repository.
journey pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new 1a86e7b add retMap null check for AlertSender (#1796)
1a86e7b is described below
commit 1a86e7bae722aa00d9a6cca615c84a86b06593fd
Author: Yelli <51...@users.noreply.github.com>
AuthorDate: Fri Jan 10 16:33:20 2020 +0800
add retMap null check for AlertSender (#1796)
* fix bug: zk hasTask method NPE
* add retMap null check for AlertSender
---
.../dolphinscheduler/alert/runner/AlertSender.java | 23 +++++++++++++---------
.../dolphinscheduler/alert/utils/ExcelUtils.java | 3 ++-
.../dolphinscheduler/alert/utils/MailUtils.java | 8 +++-----
3 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/runner/AlertSender.java b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/runner/AlertSender.java
index 3703b5d..718ef50 100644
--- a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/runner/AlertSender.java
+++ b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/runner/AlertSender.java
@@ -31,6 +31,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.Map;
@@ -72,9 +73,7 @@ public class AlertSender{
String receivers = alert.getReceivers();
if (StringUtils.isNotEmpty(receivers)){
String[] splits = receivers.split(",");
- for (String receiver : splits){
- receviersList.add(receiver);
- }
+ receviersList.addAll(Arrays.asList(splits));
}
// copy list
@@ -86,9 +85,7 @@ public class AlertSender{
if (StringUtils.isNotEmpty(receiversCc)){
String[] splits = receiversCc.split(",");
- for (String receiverCc : splits){
- receviersCcList.add(receiverCc);
- }
+ receviersCcList.addAll(Arrays.asList(splits));
}
if (CollectionUtils.isEmpty(receviersList) && CollectionUtils.isEmpty(receviersCcList)) {
@@ -106,7 +103,13 @@ public class AlertSender{
alert.setInfo(retMaps);
}
- boolean flag = Boolean.parseBoolean(String.valueOf(retMaps.get(Constants.STATUS)));
+ //send flag
+ boolean flag = false;
+
+ if (null != retMaps) {
+ flag = Boolean.parseBoolean(String.valueOf(retMaps.get(Constants.STATUS)));
+ }
+
if (flag) {
alertDao.updateAlert(AlertStatus.EXECUTION_SUCCESS, "execution success", alert.getId());
logger.info("alert send success");
@@ -121,8 +124,10 @@ public class AlertSender{
}
} else {
- alertDao.updateAlert(AlertStatus.EXECUTION_FAILURE, String.valueOf(retMaps.get(Constants.MESSAGE)), alert.getId());
- logger.info("alert send error : {}", String.valueOf(retMaps.get(Constants.MESSAGE)));
+ if (null != retMaps) {
+ alertDao.updateAlert(AlertStatus.EXECUTION_FAILURE, String.valueOf(retMaps.get(Constants.MESSAGE)), alert.getId());
+ logger.info("alert send error : {}", retMaps.get(Constants.MESSAGE));
+ }
}
}
diff --git a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/ExcelUtils.java b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/ExcelUtils.java
index c051450..b2e71a8 100644
--- a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/ExcelUtils.java
+++ b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/ExcelUtils.java
@@ -16,6 +16,7 @@
*/
package org.apache.dolphinscheduler.alert.utils;
+import org.apache.dolphinscheduler.common.utils.CollectionUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
@@ -47,7 +48,7 @@ public class ExcelUtils {
//The JSONUtils.toList has been try catch ex
itemsList = JSONUtils.toList(content, LinkedHashMap.class);
- if (itemsList == null || itemsList.size() == 0){
+ if (CollectionUtils.isEmpty(itemsList)){
logger.error("itemsList is null");
throw new RuntimeException("itemsList is null");
}
diff --git a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/MailUtils.java b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/MailUtils.java
index 8bc8c35..e911817 100644
--- a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/MailUtils.java
+++ b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/MailUtils.java
@@ -25,7 +25,6 @@ import org.apache.dolphinscheduler.common.utils.CollectionUtils;
import org.apache.dolphinscheduler.common.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.util.ResourceUtils;
import javax.mail.*;
import javax.mail.internet.*;
@@ -33,7 +32,6 @@ import java.io.*;
import java.util.*;
-
/**
* mail utils
*/
@@ -320,12 +318,12 @@ public class MailUtils {
public static void deleteFile(File file){
if(file.exists()){
if(file.delete()){
- logger.info("delete success:"+file.getAbsolutePath()+file.getName());
+ logger.info("delete success: {}",file.getAbsolutePath() + file.getName());
}else{
- logger.info("delete fail"+file.getAbsolutePath()+file.getName());
+ logger.info("delete fail: {}", file.getAbsolutePath() + file.getName());
}
}else{
- logger.info("file not exists:"+file.getAbsolutePath()+file.getName());
+ logger.info("file not exists: {}", file.getAbsolutePath() + file.getName());
}
}