Browse Source

add retMap null check for AlertSender (#1796)

* fix bug: zk hasTask method NPE

* add retMap null check for AlertSender
pull/2/head
Yelli 5 years ago committed by qiaozhanwei
parent
commit
1a86e7bae7
  1. 21
      dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/runner/AlertSender.java
  2. 3
      dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/ExcelUtils.java
  3. 8
      dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/MailUtils.java

21
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 org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -72,9 +73,7 @@ public class AlertSender{
String receivers = alert.getReceivers(); String receivers = alert.getReceivers();
if (StringUtils.isNotEmpty(receivers)){ if (StringUtils.isNotEmpty(receivers)){
String[] splits = receivers.split(","); String[] splits = receivers.split(",");
for (String receiver : splits){ receviersList.addAll(Arrays.asList(splits));
receviersList.add(receiver);
}
} }
// copy list // copy list
@ -86,9 +85,7 @@ public class AlertSender{
if (StringUtils.isNotEmpty(receiversCc)){ if (StringUtils.isNotEmpty(receiversCc)){
String[] splits = receiversCc.split(","); String[] splits = receiversCc.split(",");
for (String receiverCc : splits){ receviersCcList.addAll(Arrays.asList(splits));
receviersCcList.add(receiverCc);
}
} }
if (CollectionUtils.isEmpty(receviersList) && CollectionUtils.isEmpty(receviersCcList)) { if (CollectionUtils.isEmpty(receviersList) && CollectionUtils.isEmpty(receviersCcList)) {
@ -106,7 +103,13 @@ public class AlertSender{
alert.setInfo(retMaps); 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) { if (flag) {
alertDao.updateAlert(AlertStatus.EXECUTION_SUCCESS, "execution success", alert.getId()); alertDao.updateAlert(AlertStatus.EXECUTION_SUCCESS, "execution success", alert.getId());
logger.info("alert send success"); logger.info("alert send success");
@ -121,8 +124,10 @@ public class AlertSender{
} }
} else { } else {
if (null != retMaps) {
alertDao.updateAlert(AlertStatus.EXECUTION_FAILURE, String.valueOf(retMaps.get(Constants.MESSAGE)), alert.getId()); alertDao.updateAlert(AlertStatus.EXECUTION_FAILURE, String.valueOf(retMaps.get(Constants.MESSAGE)), alert.getId());
logger.info("alert send error : {}", String.valueOf(retMaps.get(Constants.MESSAGE))); logger.info("alert send error : {}", retMaps.get(Constants.MESSAGE));
}
} }
} }

3
dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/ExcelUtils.java

@ -16,6 +16,7 @@
*/ */
package org.apache.dolphinscheduler.alert.utils; 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.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFSheet;
@ -47,7 +48,7 @@ public class ExcelUtils {
//The JSONUtils.toList has been try catch ex //The JSONUtils.toList has been try catch ex
itemsList = JSONUtils.toList(content, LinkedHashMap.class); itemsList = JSONUtils.toList(content, LinkedHashMap.class);
if (itemsList == null || itemsList.size() == 0){ if (CollectionUtils.isEmpty(itemsList)){
logger.error("itemsList is null"); logger.error("itemsList is null");
throw new RuntimeException("itemsList is null"); throw new RuntimeException("itemsList is null");
} }

8
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.apache.dolphinscheduler.common.utils.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.util.ResourceUtils;
import javax.mail.*; import javax.mail.*;
import javax.mail.internet.*; import javax.mail.internet.*;
@ -33,7 +32,6 @@ import java.io.*;
import java.util.*; import java.util.*;
/** /**
* mail utils * mail utils
*/ */
@ -320,12 +318,12 @@ public class MailUtils {
public static void deleteFile(File file){ public static void deleteFile(File file){
if(file.exists()){ if(file.exists()){
if(file.delete()){ if(file.delete()){
logger.info("delete success:"+file.getAbsolutePath()+file.getName()); logger.info("delete success: {}",file.getAbsolutePath() + file.getName());
}else{ }else{
logger.info("delete fail"+file.getAbsolutePath()+file.getName()); logger.info("delete fail: {}", file.getAbsolutePath() + file.getName());
} }
}else{ }else{
logger.info("file not exists:"+file.getAbsolutePath()+file.getName()); logger.info("file not exists: {}", file.getAbsolutePath() + file.getName());
} }
} }

Loading…
Cancel
Save