mirror of
https://gitee.com/dolphinscheduler/DolphinScheduler.git
synced 2024-12-01 03:37:46 +08:00
Merge branch 'dev' of https://github.com/apache/incubator-dolphinscheduler into dev
This commit is contained in:
commit
3ff0e5961b
@ -22,7 +22,7 @@ package org.apache.dolphinscheduler.plugin.alert.dingtalk;
|
||||
*/
|
||||
public class DingTalkParamsConstants {
|
||||
|
||||
public DingTalkParamsConstants() {
|
||||
private DingTalkParamsConstants() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,7 @@ public class DingTalkSender {
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
logger.info("Ding Talk send [ %s ], resp:{%s}", msg, resp);
|
||||
logger.info("Ding Talk send {}, resp: {}", msg, resp);
|
||||
return resp;
|
||||
} finally {
|
||||
httpClient.close();
|
||||
|
@ -19,6 +19,10 @@ package org.apache.dolphinscheduler.plugin.alert.email;
|
||||
|
||||
public class EmailConstants {
|
||||
|
||||
private EmailConstants() {
|
||||
throw new IllegalStateException(EmailConstants.class.getName());
|
||||
}
|
||||
|
||||
|
||||
public static final String XLS_FILE_PATH = "xls.file.path";
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
package org.apache.dolphinscheduler.plugin.alert.email;
|
||||
|
||||
import org.apache.dolphinscheduler.plugin.alert.email.exception.AlertEmailException;
|
||||
import org.apache.dolphinscheduler.spi.utils.JSONUtils;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
@ -31,7 +32,6 @@ import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -44,7 +44,7 @@ import org.slf4j.LoggerFactory;
|
||||
*/
|
||||
public class ExcelUtils {
|
||||
|
||||
public ExcelUtils() {
|
||||
private ExcelUtils() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
@ -65,16 +65,14 @@ public class ExcelUtils {
|
||||
|
||||
if (CollectionUtils.isEmpty(itemsList)) {
|
||||
logger.error("itemsList is null");
|
||||
throw new RuntimeException("itemsList is null");
|
||||
throw new AlertEmailException("itemsList is null");
|
||||
}
|
||||
|
||||
LinkedHashMap<String, Object> headerMap = itemsList.get(0);
|
||||
|
||||
List<String> headerList = new ArrayList<>();
|
||||
|
||||
Iterator<Map.Entry<String, Object>> iter = headerMap.entrySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
Map.Entry<String, Object> en = iter.next();
|
||||
for (Map.Entry<String, Object> en : headerMap.entrySet()) {
|
||||
headerList.add(en.getKey());
|
||||
}
|
||||
|
||||
@ -130,8 +128,7 @@ public class ExcelUtils {
|
||||
wb.write(fos);
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("generate excel error", e);
|
||||
throw new RuntimeException("generate excel error", e);
|
||||
throw new AlertEmailException("generate excel error", e);
|
||||
} finally {
|
||||
if (wb != null) {
|
||||
try {
|
||||
@ -150,4 +147,4 @@ public class ExcelUtils {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ package org.apache.dolphinscheduler.plugin.alert.email;
|
||||
*/
|
||||
public class MailParamsConstants {
|
||||
|
||||
public MailParamsConstants() {
|
||||
private MailParamsConstants() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.plugin.alert.email;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
import org.apache.dolphinscheduler.plugin.alert.email.exception.AlertEmailException;
|
||||
import org.apache.dolphinscheduler.plugin.alert.email.template.AlertTemplate;
|
||||
import org.apache.dolphinscheduler.plugin.alert.email.template.DefaultHTMLTemplate;
|
||||
import org.apache.dolphinscheduler.spi.alert.AlertConstants;
|
||||
@ -67,7 +68,7 @@ public class MailSender {
|
||||
private String mailProtocol = "SMTP";
|
||||
private String mailSmtpHost;
|
||||
private String mailSmtpPort;
|
||||
private String mailSender;
|
||||
private String mailSenderEmail;
|
||||
private String enableSmtpAuth;
|
||||
private String mailUser;
|
||||
private String mailPasswd;
|
||||
@ -77,12 +78,13 @@ public class MailSender {
|
||||
private String sslTrust;
|
||||
private String showType;
|
||||
private AlertTemplate alertTemplate;
|
||||
private String mustNotNull = "must not be null";
|
||||
|
||||
public MailSender(Map<String, String> config) {
|
||||
|
||||
String receiversConfig = config.get(MailParamsConstants.NAME_PLUGIN_DEFAULT_EMAIL_RECEIVERS);
|
||||
if (receiversConfig == null || "".equals(receiversConfig)) {
|
||||
throw new RuntimeException(MailParamsConstants.PLUGIN_DEFAULT_EMAIL_RECEIVERS + "must not be null");
|
||||
throw new AlertEmailException(MailParamsConstants.PLUGIN_DEFAULT_EMAIL_RECEIVERS + mustNotNull);
|
||||
}
|
||||
|
||||
receivers = Arrays.asList(receiversConfig.split(","));
|
||||
@ -95,33 +97,33 @@ public class MailSender {
|
||||
}
|
||||
|
||||
mailSmtpHost = config.get(MailParamsConstants.NAME_MAIL_SMTP_HOST);
|
||||
requireNonNull(mailSmtpHost, MailParamsConstants.MAIL_SMTP_HOST + " must not null");
|
||||
requireNonNull(mailSmtpHost, MailParamsConstants.MAIL_SMTP_HOST + mustNotNull);
|
||||
|
||||
mailSmtpPort = config.get(MailParamsConstants.NAME_MAIL_SMTP_PORT);
|
||||
requireNonNull(mailSmtpPort, MailParamsConstants.MAIL_SMTP_PORT + " must not null");
|
||||
requireNonNull(mailSmtpPort, MailParamsConstants.MAIL_SMTP_PORT + mustNotNull);
|
||||
|
||||
mailSender = config.get(MailParamsConstants.NAME_MAIL_SENDER);
|
||||
requireNonNull(mailSender, MailParamsConstants.MAIL_SENDER + " must not null");
|
||||
mailSenderEmail = config.get(MailParamsConstants.NAME_MAIL_SENDER);
|
||||
requireNonNull(mailSenderEmail, MailParamsConstants.MAIL_SENDER + mustNotNull);
|
||||
|
||||
enableSmtpAuth = config.get(MailParamsConstants.NAME_MAIL_SMTP_AUTH);
|
||||
|
||||
mailUser = config.get(MailParamsConstants.NAME_MAIL_USER);
|
||||
requireNonNull(mailUser, MailParamsConstants.MAIL_USER + " must not null");
|
||||
requireNonNull(mailUser, MailParamsConstants.MAIL_USER + mustNotNull);
|
||||
|
||||
mailPasswd = config.get(MailParamsConstants.NAME_MAIL_PASSWD);
|
||||
requireNonNull(mailPasswd, MailParamsConstants.MAIL_PASSWD + " must not null");
|
||||
requireNonNull(mailPasswd, MailParamsConstants.MAIL_PASSWD + mustNotNull);
|
||||
|
||||
mailUseStartTLS = config.get(MailParamsConstants.NAME_MAIL_SMTP_STARTTLS_ENABLE);
|
||||
requireNonNull(mailUseStartTLS, MailParamsConstants.MAIL_SMTP_STARTTLS_ENABLE + " must not null");
|
||||
requireNonNull(mailUseStartTLS, MailParamsConstants.MAIL_SMTP_STARTTLS_ENABLE + mustNotNull);
|
||||
|
||||
mailUseSSL = config.get(MailParamsConstants.NAME_MAIL_SMTP_SSL_ENABLE);
|
||||
requireNonNull(mailUseSSL, MailParamsConstants.MAIL_SMTP_SSL_ENABLE + " must not null");
|
||||
requireNonNull(mailUseSSL, MailParamsConstants.MAIL_SMTP_SSL_ENABLE + mustNotNull);
|
||||
|
||||
sslTrust = config.get(MailParamsConstants.NAME_MAIL_SMTP_SSL_TRUST);
|
||||
requireNonNull(sslTrust, MailParamsConstants.MAIL_SMTP_SSL_TRUST + " must not null");
|
||||
requireNonNull(sslTrust, MailParamsConstants.MAIL_SMTP_SSL_TRUST + mustNotNull);
|
||||
|
||||
showType = config.get(AlertConstants.SHOW_TYPE);
|
||||
requireNonNull(showType, AlertConstants.SHOW_TYPE + " must not null");
|
||||
requireNonNull(showType, AlertConstants.SHOW_TYPE + mustNotNull);
|
||||
|
||||
xlsFilePath = config.get(EmailConstants.XLS_FILE_PATH);
|
||||
if (StringUtils.isBlank(xlsFilePath)) {
|
||||
@ -134,9 +136,8 @@ public class MailSender {
|
||||
/**
|
||||
* send mail to receivers
|
||||
*
|
||||
* @param title title
|
||||
* @param title title
|
||||
* @param content content
|
||||
* @return
|
||||
*/
|
||||
public AlertResult sendMails(String title, String content) {
|
||||
return sendMails(this.receivers, this.receiverCcs, title, content);
|
||||
@ -145,9 +146,8 @@ public class MailSender {
|
||||
/**
|
||||
* send mail to receivers
|
||||
*
|
||||
* @param title email title
|
||||
* @param title email title
|
||||
* @param content email content
|
||||
* @return
|
||||
*/
|
||||
public AlertResult sendMailsToReceiverOnly(String title, String content) {
|
||||
return sendMails(this.receivers, null, title, content);
|
||||
@ -156,11 +156,10 @@ public class MailSender {
|
||||
/**
|
||||
* send mail
|
||||
*
|
||||
* @param receivers receivers
|
||||
* @param receivers receivers
|
||||
* @param receiverCcs receiverCcs
|
||||
* @param title title
|
||||
* @param content content
|
||||
* @return
|
||||
* @param title title
|
||||
* @param content content
|
||||
*/
|
||||
public AlertResult sendMails(List<String> receivers, List<String> receiverCcs, String title, String content) {
|
||||
AlertResult alertResult = new AlertResult();
|
||||
@ -180,7 +179,7 @@ public class MailSender {
|
||||
try {
|
||||
Session session = getSession();
|
||||
email.setMailSession(session);
|
||||
email.setFrom(mailSender);
|
||||
email.setFrom(mailSenderEmail);
|
||||
email.setCharset(EmailConstants.UTF_8);
|
||||
if (CollectionUtils.isNotEmpty(receivers)) {
|
||||
// receivers mail
|
||||
@ -251,11 +250,6 @@ public class MailSender {
|
||||
|
||||
/**
|
||||
* send mail as Excel attachment
|
||||
*
|
||||
* @param title
|
||||
* @param content
|
||||
* @param partContent
|
||||
* @throws Exception
|
||||
*/
|
||||
private void attachment(String title, String content, String partContent) throws Exception {
|
||||
MimeMessage msg = getMimeMessage();
|
||||
@ -265,9 +259,6 @@ public class MailSender {
|
||||
|
||||
/**
|
||||
* get MimeMessage
|
||||
*
|
||||
* @return
|
||||
* @throws MessagingException
|
||||
*/
|
||||
private MimeMessage getMimeMessage() throws MessagingException {
|
||||
|
||||
@ -279,7 +270,7 @@ public class MailSender {
|
||||
// 2. creating mail: Creating a MimeMessage
|
||||
MimeMessage msg = new MimeMessage(session);
|
||||
// 3. set sender
|
||||
msg.setFrom(new InternetAddress(mailSender));
|
||||
msg.setFrom(new InternetAddress(mailSenderEmail));
|
||||
// 4. set receivers
|
||||
for (String receiver : receivers) {
|
||||
msg.addRecipients(Message.RecipientType.TO, InternetAddress.parse(receiver));
|
||||
@ -317,16 +308,9 @@ public class MailSender {
|
||||
|
||||
/**
|
||||
* attach content
|
||||
*
|
||||
* @param title
|
||||
* @param content
|
||||
* @param partContent
|
||||
* @param msg
|
||||
* @throws MessagingException
|
||||
* @throws IOException
|
||||
*/
|
||||
private void attachContent(String title, String content, String partContent, MimeMessage msg) throws MessagingException, IOException {
|
||||
/**
|
||||
/*
|
||||
* set receiverCc
|
||||
*/
|
||||
if (CollectionUtils.isNotEmpty(receiverCcs)) {
|
||||
@ -365,21 +349,14 @@ public class MailSender {
|
||||
|
||||
/**
|
||||
* the string object map
|
||||
*
|
||||
* @param title
|
||||
* @param content
|
||||
* @param alertResult
|
||||
* @param email
|
||||
* @return
|
||||
* @throws EmailException
|
||||
*/
|
||||
private AlertResult getStringObjectMap(String title, String content, AlertResult alertResult, HtmlEmail email) throws EmailException {
|
||||
|
||||
/**
|
||||
/*
|
||||
* the subject of the message to be sent
|
||||
*/
|
||||
email.setSubject(title);
|
||||
/**
|
||||
/*
|
||||
* to send information, you can use HTML tags in mail content because of the use of HtmlEmail
|
||||
*/
|
||||
if (showType.equals(ShowType.TABLE.getDescp())) {
|
||||
@ -417,9 +394,6 @@ public class MailSender {
|
||||
|
||||
/**
|
||||
* handle exception
|
||||
*
|
||||
* @param alertResult
|
||||
* @param e
|
||||
*/
|
||||
private void handleException(AlertResult alertResult, Exception e) {
|
||||
logger.error("Send email to {} failed", receivers, e);
|
||||
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.plugin.alert.email.exception;
|
||||
|
||||
public class AlertEmailException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Create Runtime exception
|
||||
*
|
||||
* @param errMsg - Error message
|
||||
*/
|
||||
public AlertEmailException(String errMsg) {
|
||||
super(errMsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Runtime exception
|
||||
*
|
||||
* @param errMsg - Error message
|
||||
* @param cause - cause
|
||||
*/
|
||||
public AlertEmailException(String errMsg, Throwable cause) {
|
||||
super(errMsg, cause);
|
||||
}
|
||||
}
|
@ -50,7 +50,7 @@ public class DefaultHTMLTemplate implements AlertTemplate {
|
||||
case TABLE:
|
||||
return getTableTypeMessage(content, showAll);
|
||||
case TEXT:
|
||||
return getTextTypeMessage(content, showAll);
|
||||
return getTextTypeMessage(content);
|
||||
default:
|
||||
throw new IllegalArgumentException(String.format("not support showType: %s in DefaultHTMLTemplate", showType));
|
||||
}
|
||||
@ -77,7 +77,7 @@ public class DefaultHTMLTemplate implements AlertTemplate {
|
||||
boolean flag = true;
|
||||
|
||||
String title = "";
|
||||
for (LinkedHashMap mapItems : mapItemsList) {
|
||||
for (LinkedHashMap<String, Object> mapItems : mapItemsList) {
|
||||
|
||||
Set<Map.Entry<String, Object>> entries = mapItems.entrySet();
|
||||
|
||||
@ -111,10 +111,9 @@ public class DefaultHTMLTemplate implements AlertTemplate {
|
||||
* get alert message which type is TEXT
|
||||
*
|
||||
* @param content message content
|
||||
* @param showAll weather to show all
|
||||
* @return alert message
|
||||
*/
|
||||
private String getTextTypeMessage(String content, boolean showAll) {
|
||||
private String getTextTypeMessage(String content) {
|
||||
|
||||
if (StringUtils.isNotEmpty(content)) {
|
||||
ArrayNode list = JSONUtils.parseArray(content);
|
||||
@ -135,14 +134,14 @@ public class DefaultHTMLTemplate implements AlertTemplate {
|
||||
/**
|
||||
* get alert message from a html template
|
||||
*
|
||||
* @param title message title
|
||||
* @param title message title
|
||||
* @param content message content
|
||||
* @return alert message which use html template
|
||||
*/
|
||||
private String getMessageFromHtmlTemplate(String title, String content) {
|
||||
|
||||
requireNonNull(content, "content must not null");
|
||||
String htmlTableThead = StringUtils.isEmpty(title) ? "" : String.format("<thead>%s</thead>\n", title);
|
||||
String htmlTableThead = StringUtils.isEmpty(title) ? "" : String.format("<thead>%s</thead>%n", title);
|
||||
|
||||
return EmailConstants.HTML_HEADER_PREFIX + htmlTableThead + content + EmailConstants.TABLE_BODY_HTML_TAIL;
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ package org.apache.dolphinscheduler.plugin.alert.script;
|
||||
*/
|
||||
public class OSUtils {
|
||||
|
||||
public OSUtils() {
|
||||
private OSUtils() {
|
||||
throw new UnsupportedOperationException("Construct OSUtils");
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ package org.apache.dolphinscheduler.plugin.alert.script;
|
||||
*/
|
||||
public class ScriptParamsConstants {
|
||||
|
||||
public ScriptParamsConstants() {
|
||||
private ScriptParamsConstants() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
|
@ -51,11 +51,11 @@ public class StreamGobbler extends Thread {
|
||||
output.append(System.getProperty("line.separator"));
|
||||
}
|
||||
if (output.length() > 0) {
|
||||
logger.info("out put msg is{}",output.toString());
|
||||
logger.info("out put msg is{}", output);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error("I/O error occurs {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,10 @@ package org.apache.dolphinscheduler.plugin.alert.wechat;
|
||||
*/
|
||||
public class WeChatAlertConstants {
|
||||
|
||||
private WeChatAlertConstants() {
|
||||
throw new IllegalStateException(WeChatAlertConstants.class.getName());
|
||||
}
|
||||
|
||||
static final String MARKDOWN_QUOTE = ">";
|
||||
|
||||
static final String MARKDOWN_ENTER = "\n";
|
||||
|
@ -22,6 +22,9 @@ package org.apache.dolphinscheduler.plugin.alert.wechat;
|
||||
*/
|
||||
public class WeChatAlertParamsConstants {
|
||||
|
||||
private WeChatAlertParamsConstants() {
|
||||
throw new IllegalStateException(WeChatAlertParamsConstants.class.getName());
|
||||
}
|
||||
|
||||
static final String ENTERPRISE_WE_CHAT_CORP_ID = "corp.id";
|
||||
|
||||
|
@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.plugin.alert.wechat;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
import org.apache.dolphinscheduler.plugin.alert.wechat.exception.WeChatAlertException;
|
||||
import org.apache.dolphinscheduler.spi.alert.AlertConstants;
|
||||
import org.apache.dolphinscheduler.spi.alert.AlertResult;
|
||||
import org.apache.dolphinscheduler.spi.alert.ShowType;
|
||||
@ -59,8 +60,6 @@ public class WeChatSender {
|
||||
|
||||
private String weChatUsers;
|
||||
|
||||
private String weChatTeamSendMsg;
|
||||
|
||||
private String weChatUserSendMsg;
|
||||
|
||||
private String weChatTokenUrlReplace;
|
||||
@ -70,14 +69,14 @@ public class WeChatSender {
|
||||
private String showType;
|
||||
|
||||
|
||||
private static final String agentIdRegExp = "{agentId}";
|
||||
private static final String msgRegExp = "{msg}";
|
||||
private static final String userRegExp = "{toUser}";
|
||||
private static final String corpIdRegex = "{corpId}";
|
||||
private static final String secretRegex = "{secret}";
|
||||
private static final String toPartyRegex = "{toParty}";
|
||||
private static final String toUserRegex = "{toUser}";
|
||||
private static final String tokenRegex = "{token}";
|
||||
private static final String MUST_NOT_NULL = " must not null";
|
||||
private static final String ALERT_STATUS = "false";
|
||||
private static final String AGENT_ID_REG_EXP = "{agentId}";
|
||||
private static final String MSG_REG_EXP = "{msg}";
|
||||
private static final String USER_REG_EXP = "{toUser}";
|
||||
private static final String CORP_ID_REGEX = "{corpId}";
|
||||
private static final String SECRET_REGEX = "{secret}";
|
||||
private static final String TOKEN_REGEX = "{token}";
|
||||
|
||||
WeChatSender(Map<String, String> config) {
|
||||
weChatAgentId = config.get(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_AGENT_ID);
|
||||
@ -85,13 +84,12 @@ public class WeChatSender {
|
||||
String weChatCorpId = config.get(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_CORP_ID);
|
||||
String weChatSecret = config.get(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_SECRET);
|
||||
String weChatTokenUrl = WeChatAlertConstants.WE_CHAT_TOKEN_URL;
|
||||
weChatTeamSendMsg = config.get(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_TEAM_SEND_MSG);
|
||||
weChatUserSendMsg = config.get(WeChatAlertParamsConstants.NAME_ENTERPRISE_WE_CHAT_USER_SEND_MSG);
|
||||
showType = config.get(AlertConstants.SHOW_TYPE);
|
||||
requireNonNull(showType, AlertConstants.SHOW_TYPE + " must not null");
|
||||
requireNonNull(showType, AlertConstants.SHOW_TYPE + MUST_NOT_NULL);
|
||||
weChatTokenUrlReplace = weChatTokenUrl
|
||||
.replace(corpIdRegex, weChatCorpId)
|
||||
.replace(secretRegex, weChatSecret);
|
||||
.replace(CORP_ID_REGEX, weChatCorpId)
|
||||
.replace(SECRET_REGEX, weChatSecret);
|
||||
weChatToken = getToken();
|
||||
}
|
||||
|
||||
@ -105,16 +103,15 @@ public class WeChatSender {
|
||||
*/
|
||||
private String makeUserSendMsg(Collection<String> toUser, String agentId, String msg) {
|
||||
String listUser = mkString(toUser);
|
||||
return weChatUserSendMsg.replace(userRegExp, listUser)
|
||||
.replace(agentIdRegExp, agentId)
|
||||
.replace(msgRegExp, msg);
|
||||
return weChatUserSendMsg.replace(USER_REG_EXP, listUser)
|
||||
.replace(AGENT_ID_REG_EXP, agentId)
|
||||
.replace(MSG_REG_EXP, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* send Enterprise WeChat
|
||||
*
|
||||
* @return Enterprise WeChat resp, demo: {"errcode":0,"errmsg":"ok","invaliduser":""}
|
||||
* @throws Exception the Exception
|
||||
*/
|
||||
public AlertResult sendEnterpriseWeChat(String title, String content) {
|
||||
AlertResult alertResult;
|
||||
@ -124,10 +121,10 @@ public class WeChatSender {
|
||||
if (null == weChatToken) {
|
||||
alertResult = new AlertResult();
|
||||
alertResult.setMessage("send we chat alert fail,get weChat token error");
|
||||
alertResult.setStatus("false");
|
||||
alertResult.setStatus(ALERT_STATUS);
|
||||
return alertResult;
|
||||
}
|
||||
String enterpriseWeChatPushUrlReplace = WeChatAlertConstants.WE_CHAT_PUSH_URL.replace(tokenRegex, weChatToken);
|
||||
String enterpriseWeChatPushUrlReplace = WeChatAlertConstants.WE_CHAT_PUSH_URL.replace(TOKEN_REGEX, weChatToken);
|
||||
|
||||
try {
|
||||
return checkWeChatSendMsgResult(post(enterpriseWeChatPushUrlReplace, msg));
|
||||
@ -135,7 +132,7 @@ public class WeChatSender {
|
||||
logger.info("send we chat alert msg exception : {}", e.getMessage());
|
||||
alertResult = new AlertResult();
|
||||
alertResult.setMessage("send we chat alert fail");
|
||||
alertResult.setStatus("false");
|
||||
alertResult.setStatus(ALERT_STATUS);
|
||||
}
|
||||
return alertResult;
|
||||
}
|
||||
@ -170,7 +167,7 @@ public class WeChatSender {
|
||||
List<LinkedHashMap> mapItemsList = JSONUtils.toList(content, LinkedHashMap.class);
|
||||
if (null == mapItemsList || mapItemsList.isEmpty()) {
|
||||
logger.error("itemsList is null");
|
||||
throw new RuntimeException("itemsList is null");
|
||||
throw new WeChatAlertException("itemsList is null");
|
||||
}
|
||||
StringBuilder contents = new StringBuilder(200);
|
||||
for (LinkedHashMap mapItems : mapItemsList) {
|
||||
@ -259,7 +256,7 @@ public class WeChatSender {
|
||||
EntityUtils.consume(entity);
|
||||
}
|
||||
|
||||
HashMap map = JSONUtils.parseObject(resp, HashMap.class);
|
||||
HashMap<String, Object> map = JSONUtils.parseObject(resp, HashMap.class);
|
||||
if (map != null && null != map.get("access_token")) {
|
||||
return map.get("access_token").toString();
|
||||
} else {
|
||||
@ -310,7 +307,7 @@ public class WeChatSender {
|
||||
|
||||
private static AlertResult checkWeChatSendMsgResult(String result) {
|
||||
AlertResult alertResult = new AlertResult();
|
||||
alertResult.setStatus("false");
|
||||
alertResult.setStatus(ALERT_STATUS);
|
||||
|
||||
if (null == result) {
|
||||
alertResult.setMessage("we chat send fail");
|
||||
@ -328,7 +325,7 @@ public class WeChatSender {
|
||||
alertResult.setMessage("we chat alert send success");
|
||||
return alertResult;
|
||||
}
|
||||
alertResult.setStatus("false");
|
||||
alertResult.setStatus(ALERT_STATUS);
|
||||
alertResult.setMessage(sendMsgResponse.getErrmsg());
|
||||
return alertResult;
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.plugin.alert.wechat.exception;
|
||||
|
||||
public class WeChatAlertException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Create Runtime Exception
|
||||
*
|
||||
* @param errMsg - Error message
|
||||
*/
|
||||
public WeChatAlertException(String errMsg) {
|
||||
super(errMsg);
|
||||
}
|
||||
}
|
@ -263,13 +263,13 @@ public class CollectionUtils {
|
||||
}
|
||||
Map<String, Object> instanceMap;
|
||||
for (T instance : originList) {
|
||||
Map<String, Object> dataMap = new BeanMap(instance);
|
||||
BeanMap beanMap = new BeanMap(instance);
|
||||
instanceMap = new LinkedHashMap<>(16, 0.75f, true);
|
||||
for (Map.Entry<String, Object> entry : dataMap.entrySet()) {
|
||||
for (Map.Entry<Object, Object> entry : beanMap.entrySet()) {
|
||||
if (exclusionSet.contains(entry.getKey())) {
|
||||
continue;
|
||||
}
|
||||
instanceMap.put(entry.getKey(), entry.getValue());
|
||||
instanceMap.put((String) entry.getKey(), entry.getValue());
|
||||
}
|
||||
instanceList.add(instanceMap);
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ The text of each license is also included at licenses/LICENSE-[project].txt.
|
||||
byte-buddy 1.9.10: https://mvnrepository.com/artifact/net.bytebuddy/byte-buddy/1.9.10, Apache 2.0
|
||||
classmate 1.4.0: https://mvnrepository.com/artifact/com.fasterxml/classmate/1.4.0, Apache 2.0
|
||||
clickhouse-jdbc 0.1.52: https://mvnrepository.com/artifact/ru.yandex.clickhouse/clickhouse-jdbc/0.1.52, Apache 2.0
|
||||
commons-beanutils 1.7.0 https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils/1.7.0, Apache 2.0
|
||||
commons-beanutils 1.9.4 https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils/1.9.4, Apache 2.0
|
||||
commons-cli 1.2: https://mvnrepository.com/artifact/commons-cli/commons-cli/1.2, Apache 2.0
|
||||
commons-codec 1.11: https://mvnrepository.com/artifact/commons-codec/commons-codec/1.11, Apache 2.0
|
||||
commons-collections 3.2.2: https://mvnrepository.com/artifact/commons-collections/commons-collections/3.2.2, Apache 2.0
|
||||
|
@ -58,7 +58,7 @@ public class JSONUtils {
|
||||
/**
|
||||
* json representation of object
|
||||
*
|
||||
* @param object object
|
||||
* @param object object
|
||||
* @param feature feature
|
||||
* @return object to json string
|
||||
*/
|
||||
@ -81,9 +81,9 @@ public class JSONUtils {
|
||||
* the fields of the specified object are generics, just the object itself should not be a
|
||||
* generic type.
|
||||
*
|
||||
* @param json the string from which the object is to be deserialized
|
||||
* @param json the string from which the object is to be deserialized
|
||||
* @param clazz the class of T
|
||||
* @param <T> T
|
||||
* @param <T> T
|
||||
* @return an object of type T from the string
|
||||
* classOfT
|
||||
*/
|
||||
@ -103,9 +103,9 @@ public class JSONUtils {
|
||||
/**
|
||||
* json to list
|
||||
*
|
||||
* @param json json string
|
||||
* @param json json string
|
||||
* @param clazz class
|
||||
* @param <T> T
|
||||
* @param <T> T
|
||||
* @return list
|
||||
*/
|
||||
public static <T> List<T> toList(String json, Class<T> clazz) {
|
||||
@ -153,4 +153,4 @@ public class JSONUtils {
|
||||
throw new RuntimeException("Json deserialization exception.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +84,6 @@
|
||||
<el-button type="primary" size="mini" icon="el-icon-date" :disabled="scope.row.releaseState !== 'ONLINE'" @click="_timingManage(scope.row)" circle></el-button>
|
||||
</el-tooltip>
|
||||
<el-tooltip :content="$t('delete')" placement="top" :enterable="false">
|
||||
<el-button type="danger" size="mini" icon="el-icon-delete" circle></el-button>
|
||||
<el-popconfirm
|
||||
:confirmButtonText="$t('Confirm')"
|
||||
:cancelButtonText="$t('Cancel')"
|
||||
|
@ -84,7 +84,6 @@
|
||||
<span><el-button type="error" size="mini" :icon="scope.row.state === 'PAUSE' ? 'el-icon-video-play' : 'el-icon-video-pause'" :disabled="scope.row.state !== 'RUNNING_EXECUTION' && scope.row.state !== 'PAUSE'" @click="_suspend(scope.row,scope.$index)" circle></el-button></span>
|
||||
</el-tooltip>
|
||||
<el-tooltip :content="$t('delete')" placement="top" :enterable="false">
|
||||
<el-button type="danger" size="mini" icon="el-icon-delete" circle></el-button>
|
||||
<el-popconfirm
|
||||
:confirmButtonText="$t('Confirm')"
|
||||
:cancelButtonText="$t('Cancel')"
|
||||
@ -92,7 +91,7 @@
|
||||
iconColor="red"
|
||||
:title="$t('Delete?')"
|
||||
@onConfirm="_delete(scope.row,scope.row.id)">
|
||||
<el-button type="danger" size="mini" icon="el-icon-delete" :disabled="scope.row.releaseState === 'ONLINE'" circle slot="reference"></el-button>
|
||||
<el-button type="danger" size="mini" icon="el-icon-delete" :disabled="scope.row.state !== 'SUCCESS' && scope.row.state !== 'FAILURE' && scope.row.state !== 'STOP' && scope.row.state !== 'PAUSE'" circle slot="reference"></el-button>
|
||||
</el-popconfirm>
|
||||
</el-tooltip>
|
||||
<el-tooltip :content="$t('Gantt')" placement="top" :enterable="false">
|
||||
|
@ -81,18 +81,21 @@
|
||||
</el-table>
|
||||
</div>
|
||||
<el-dialog
|
||||
v-if="authProjectDialog"
|
||||
:visible.sync="authProjectDialog"
|
||||
width="auto">
|
||||
<m-transfer :transferData="transferData" @onUpdateAuthProject="onUpdateAuthProject" @closeAuthProject="closeAuthProject"></m-transfer>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog
|
||||
v-if="authDataSourceDialog"
|
||||
:visible.sync="authDataSourceDialog"
|
||||
width="auto">
|
||||
<m-transfer :transferData="transferData" @onUpdateAuthDataSource="onUpdateAuthDataSource" @closeAuthDataSource="closeAuthDataSource"></m-transfer>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog
|
||||
v-if="authUdfFuncDialog"
|
||||
:visible.sync="authUdfFuncDialog"
|
||||
width="auto">
|
||||
<m-transfer :transferData="transferData" @onUpdateAuthUdfFunc="onUpdateAuthUdfFunc" @closeAuthUdfFunc="closeAuthUdfFunc"></m-transfer>
|
||||
|
2
pom.xml
2
pom.xml
@ -81,7 +81,7 @@
|
||||
<slf4j.log4j12.version>1.7.5</slf4j.log4j12.version>
|
||||
<commons.collections.version>3.2.2</commons.collections.version>
|
||||
<commons.httpclient>3.0.1</commons.httpclient>
|
||||
<commons.beanutils.version>1.7.0</commons.beanutils.version>
|
||||
<commons.beanutils.version>1.9.4</commons.beanutils.version>
|
||||
<commons.configuration.version>1.10</commons.configuration.version>
|
||||
<commons.email.version>1.5</commons.email.version>
|
||||
<poi.version>3.17</poi.version>
|
||||
|
@ -24,7 +24,7 @@ commons-compress-1.4.1.jar
|
||||
commons-compiler-3.0.16.jar
|
||||
commons-configuration-1.10.jar
|
||||
commons-daemon-1.0.13.jar
|
||||
commons-beanutils-1.7.0.jar
|
||||
commons-beanutils-1.9.4.jar
|
||||
commons-dbcp-1.4.jar
|
||||
commons-httpclient-3.0.1.jar
|
||||
commons-io-2.4.jar
|
||||
|
Loading…
Reference in New Issue
Block a user