Commit 906ffa09 authored by hgaol's avatar hgaol
Browse files

resolve code checks

parent 3c6d8136
Loading
Loading
Loading
Loading
+4 −10
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import org.apache.dolphinscheduler.dao.entity.Alert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.MalformedURLException;
import java.util.List;

/**
@@ -56,15 +55,10 @@ public class AlertServer {
    };

    public AlertServer() {
        try {
        alertPluginManager =
                new FilePluginManager(PropertyUtils.getString(Constants.PLUGIN_DIR), whitePrefixes, excludePrefixes);
        // add default alert plugins
        alertPluginManager.addPlugin(new EmailAlertPlugin());
        } catch (MalformedURLException e) {
            logger.error("Failed to start alert server", e);
            System.exit(1);
        }
    }

    public synchronized static AlertServer getInstance() {
+0 −1
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package org.apache.dolphinscheduler.alert.manager;

import org.apache.dolphinscheduler.alert.utils.MailUtils;
import org.apache.dolphinscheduler.common.enums.ShowType;

import java.util.List;
import java.util.Map;
+4 −16
Original line number Diff line number Diff line
@@ -54,9 +54,7 @@ public class AlertSender {
    }

    public void run() {

        List<User> users;

        Map<String, Object> retMaps = null;
        for (Alert alert : alertList) {
            users = alertDao.listUserByAlertgroupId(alert.getAlertGroupId());
@@ -85,7 +83,10 @@ public class AlertSender {
            AlertPlugin emailPlugin = pluginManager.findOne(Constants.PLUGIN_DEFAULT_EMAIL);
            retMaps = emailPlugin.process(alertInfo);

            if (retMaps == null || !Boolean.parseBoolean(String.valueOf(retMaps.get(Constants.STATUS)))) {
            if (retMaps == null) {
                alertDao.updateAlert(AlertStatus.EXECUTION_FAILURE, "alert send error", alert.getId());
                logger.info("alert send error : return value is null");
            } else if (!Boolean.parseBoolean(String.valueOf(retMaps.get(Constants.STATUS)))) {
                alertDao.updateAlert(AlertStatus.EXECUTION_FAILURE, String.valueOf(retMaps.get(Constants.MESSAGE)), alert.getId());
                logger.info("alert send error : {}", retMaps.get(Constants.MESSAGE));
            } else {
@@ -96,17 +97,4 @@ public class AlertSender {

    }

    /**
     * get a list of SMS users
     *
     * @param users
     * @return
     */
    private List<String> getReciversForSMS(List<User> users) {
        List<String> list = new ArrayList<>();
        for (User user : users) {
            list.add(user.getPhone());
        }
        return list;
    }
}
+5 −4
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package org.apache.dolphinscheduler.alert.utils;

import org.apache.dolphinscheduler.common.enums.ShowType;
import org.apache.dolphinscheduler.common.utils.StringUtils;
import org.apache.dolphinscheduler.dao.entity.Alert;
import com.alibaba.fastjson.JSON;

import com.google.common.reflect.TypeToken;
@@ -67,15 +66,17 @@ public class EnterpriseWeChatUtils {
     * get Enterprise WeChat is enable
     * @return isEnable
     */
    public static Boolean isEnable(){
        Boolean isEnable = false;
    public static boolean isEnable(){
        Boolean isEnable = null;
        try {
            isEnable = PropertyUtils.getBoolean(Constants.ENTERPRISE_WECHAT_ENABLE);
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
        }
        if (isEnable == null) {
            return false;
        }
        return isEnable;

    }

    /**
+6 −4
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.*;

@@ -65,14 +66,15 @@ public class EmailAlertPluginTest {
                .setContent("[\"alarm time:2018-02-05\", \"service name:MYSQL_ALTER\", \"alarm name:MYSQL_ALTER_DUMP\", " +
                        "\"get the alarm exception.!,interface error,exception information:timed out\", \"request address:http://blog.csdn.net/dreamInTheWorld/article/details/78539286\"]")
                .setLog("test log")
                .setReceivers("bitace@163.com")
                .setReceiversCc("bitace@163.com")
                .setReceivers("xx@xx.com")
                .setReceiversCc("xx@xx.com")
                .setShowType(ShowType.TEXT.getDescp())
                .setTitle("test title");

        alertInfo.setAlertData(alertData);
        List<String> list = new ArrayList<String>(){{ add("bitace@163.com"); }};
        List<String> list = new ArrayList<String>(){{ add("xx@xx.com"); }};
        alertInfo.addProp("receivers", list);
        plugin.process(alertInfo);
        Map<String, Object> ret = plugin.process(alertInfo);
        assertFalse(Boolean.parseBoolean(String.valueOf(ret.get(Constants.STATUS))));
    }
}
 No newline at end of file
Loading