Skip to content

Commit 4977d1b

Browse files
authored
[Improvement-18056][Alert] Remove the unused code in alert module (#18062)
1 parent dc38d34 commit 4977d1b

23 files changed

Lines changed: 68 additions & 390 deletions

File tree

dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-aliyunVoice/src/main/java/org/apache/dolphinscheduler/plugin/alert/voice/VoiceSender.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ public final class VoiceSender {
4040
* @return Client
4141
* @throws Exception
4242
*/
43-
public VoiceSender(VoiceParam voiceParam) {
43+
VoiceSender(VoiceParam voiceParam) {
4444
this.voiceParam = voiceParam;
4545
}
4646

47-
public AlertResult send() {
47+
AlertResult send() {
4848
AlertResult alertResult = new AlertResult();
4949
alertResult.setSuccess(false);
5050
try {
@@ -91,11 +91,4 @@ private com.aliyun.dyvmsapi20170525.Client createClient(VoiceParam.Connection co
9191
return new com.aliyun.dyvmsapi20170525.Client(config);
9292
}
9393

94-
public VoiceParam getVoidcePara() {
95-
return voiceParam;
96-
}
97-
98-
public void setVoidcePara(VoiceParam voidcePara) {
99-
this.voiceParam = voidcePara;
100-
}
10194
}

dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertInputTips.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
package org.apache.dolphinscheduler.alert.api;
1919

2020
import java.util.HashMap;
21-
import java.util.Locale;
2221
import java.util.Map;
2322

24-
import org.springframework.context.i18n.LocaleContextHolder;
23+
import lombok.Getter;
2524

25+
@Getter
2626
public enum AlertInputTips {
2727

2828
PASSWORD("if enable use authentication, you need input password", "如果开启鉴权校验,则需要输入密码"),
@@ -68,14 +68,6 @@ public enum AlertInputTips {
6868
this.zhMsg = zhMsg;
6969
}
7070

71-
public String getMsg() {
72-
if (Locale.SIMPLIFIED_CHINESE.getLanguage().equals(LocaleContextHolder.getLocale().getLanguage())) {
73-
return this.zhMsg;
74-
} else {
75-
return this.enMsg;
76-
}
77-
}
78-
7971
public static Map<String, String> getAllMsg(AlertInputTips alertInputTips) {
8072
Map<String, String> allMsgMap = new HashMap<>();
8173
allMsgMap.put("zhMsg", alertInputTips.zhMsg);

dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-dingtalk/src/main/java/org/apache/dolphinscheduler/plugin/alert/dingtalk/DingTalkSender.java

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@
4848
import javax.crypto.Mac;
4949
import javax.crypto.spec.SecretKeySpec;
5050

51-
import lombok.Getter;
52-
import lombok.Setter;
51+
import lombok.Data;
5352
import lombok.extern.slf4j.Slf4j;
5453

5554
/**
@@ -156,7 +155,7 @@ private AlertResult checkSendDingTalkSendMsgResult(String result) {
156155
* @param content content
157156
* @return
158157
*/
159-
public AlertResult sendDingTalkMsg(String title, String content) {
158+
AlertResult sendDingTalkMsg(String title, String content) {
160159
AlertResult alertResult;
161160
try {
162161
String resp = sendMsg(title, content);
@@ -328,53 +327,10 @@ private String generateSignedUrl() {
328327
return url + "&timestamp=" + timestamp + "&sign=" + sign;
329328
}
330329

331-
@Getter
332-
@Setter
330+
@Data
333331
static final class DingTalkSendMsgResponse {
334332

335333
private Integer errcode;
336334
private String errmsg;
337-
338-
public DingTalkSendMsgResponse() {
339-
}
340-
341-
@Override
342-
public boolean equals(final Object o) {
343-
if (o == this) {
344-
return true;
345-
}
346-
if (!(o instanceof DingTalkSendMsgResponse)) {
347-
return false;
348-
}
349-
final DingTalkSendMsgResponse other = (DingTalkSendMsgResponse) o;
350-
final Object this$errcode = this.getErrcode();
351-
final Object other$errcode = other.getErrcode();
352-
if (this$errcode == null ? other$errcode != null : !this$errcode.equals(other$errcode)) {
353-
return false;
354-
}
355-
final Object this$errmsg = this.getErrmsg();
356-
final Object other$errmsg = other.getErrmsg();
357-
if (this$errmsg == null ? other$errmsg != null : !this$errmsg.equals(other$errmsg)) {
358-
return false;
359-
}
360-
return true;
361-
}
362-
363-
@Override
364-
public int hashCode() {
365-
final int PRIME = 59;
366-
int result = 1;
367-
final Object $errcode = this.getErrcode();
368-
result = result * PRIME + ($errcode == null ? 43 : $errcode.hashCode());
369-
final Object $errmsg = this.getErrmsg();
370-
result = result * PRIME + ($errmsg == null ? 43 : $errmsg.hashCode());
371-
return result;
372-
}
373-
374-
@Override
375-
public String toString() {
376-
return "DingTalkSender.DingTalkSendMsgResponse(errcode=" + this.getErrcode() + ", errmsg="
377-
+ this.getErrmsg() + ")";
378-
}
379335
}
380336
}

dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/ExcelUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private ExcelUtils() {
5353
* @param title the title
5454
* @param xlsFilePath the xls path
5555
*/
56-
public static void genExcelFile(String content, String title, String xlsFilePath) {
56+
static void genExcelFile(String content, String title, String xlsFilePath) {
5757
File file = new File(xlsFilePath);
5858
if (!file.exists() && !file.mkdirs()) {
5959
log.error("Create xlsx directory error, path:{}", xlsFilePath);

dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/MailSender.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public final class MailSender {
8080
private final String mustNotNull = " must not be null";
8181
private String xlsFilePath;
8282

83-
public MailSender(Map<String, String> config) {
83+
MailSender(Map<String, String> config) {
8484
String receiversConfig = config.get(MailParamsConstants.NAME_PLUGIN_DEFAULT_EMAIL_RECEIVERS);
8585
if (receiversConfig == null || "".equals(receiversConfig)) {
8686
throw new AlertEmailException(MailParamsConstants.NAME_PLUGIN_DEFAULT_EMAIL_RECEIVERS + mustNotNull);
@@ -140,7 +140,7 @@ public MailSender(Map<String, String> config) {
140140
* @param title title
141141
* @param content content
142142
*/
143-
public AlertResult sendMails(String title, String content) {
143+
AlertResult sendMails(String title, String content) {
144144
return sendMails(this.receivers, this.receiverCcs, title, content);
145145
}
146146

@@ -152,7 +152,7 @@ public AlertResult sendMails(String title, String content) {
152152
* @param title title
153153
* @param content content
154154
*/
155-
public AlertResult sendMails(List<String> receivers, List<String> receiverCcs, String title, String content) {
155+
private AlertResult sendMails(List<String> receivers, List<String> receiverCcs, String title, String content) {
156156
AlertResult alertResult = new AlertResult();
157157
alertResult.setSuccess(false);
158158

@@ -390,7 +390,7 @@ private AlertResult getStringObjectMap(String title, String content, AlertResult
390390
*
391391
* @param file the file to delete
392392
*/
393-
public void deleteFile(File file) {
393+
private void deleteFile(File file) {
394394
if (file.exists()) {
395395
if (file.delete()) {
396396
log.info("delete success: {}", file.getAbsolutePath());

dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuSender.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private static String textToJsonString(AlertData alertData) {
8282
return JSONUtils.toJsonString(items);
8383
}
8484

85-
public static AlertResult checkSendFeiShuSendMsgResult(String result) {
85+
private static AlertResult checkSendFeiShuSendMsgResult(String result) {
8686
AlertResult alertResult = new AlertResult();
8787
alertResult.setSuccess(false);
8888

@@ -108,7 +108,7 @@ public static AlertResult checkSendFeiShuSendMsgResult(String result) {
108108
return alertResult;
109109
}
110110

111-
public static String formatContent(AlertData alertData) {
111+
private static String formatContent(AlertData alertData) {
112112
if (alertData.getContent() != null) {
113113

114114
List<Map> list = JSONUtils.toList(alertData.getContent(), Map.class);
@@ -131,7 +131,7 @@ public static String formatContent(AlertData alertData) {
131131
return null;
132132
}
133133

134-
public AlertResult sendFeiShuMsg(AlertData alertData) {
134+
AlertResult sendFeiShuMsg(AlertData alertData) {
135135
AlertResult alertResult;
136136
try {
137137
String resp = sendMsg(alertData);

dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/main/java/org/apache/dolphinscheduler/plugin/alert/feishu/HttpRequestUtil.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ private HttpRequestUtil() {
3636
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
3737
}
3838

39-
public static CloseableHttpClient getHttpClient(boolean enableProxy, String proxy, Integer port, String user,
40-
String password) {
39+
static CloseableHttpClient getHttpClient(boolean enableProxy, String proxy, Integer port, String user,
40+
String password) {
4141
if (enableProxy) {
4242
HttpHost httpProxy = new HttpHost(proxy, port);
4343
CredentialsProvider provider = new BasicCredentialsProvider();
@@ -49,7 +49,7 @@ public static CloseableHttpClient getHttpClient(boolean enableProxy, String prox
4949
}
5050
}
5151

52-
public static HttpPost constructHttpPost(String url, String msg) {
52+
static HttpPost constructHttpPost(String url, String msg) {
5353
HttpPost post = new HttpPost(url);
5454
StringEntity entity = new StringEntity(msg, ContentType.APPLICATION_JSON);
5555
post.setEntity(entity);

dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-feishu/src/test/java/org/apache/dolphinscheduler/plugin/alert/feishu/FeiShuSenderTest.java

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -46,52 +46,4 @@ public void testSend() {
4646
Assertions.assertFalse(alertResult.isSuccess());
4747
}
4848

49-
@Test
50-
public void testFormatContent() {
51-
String alertMsg = "[\n"
52-
+ " {\n"
53-
+ " \"owner\": \"dolphinscheduler\",\n"
54-
+ " \"processEndTime\": \"2021-01-29 19:01:11\",\n"
55-
+ " \"processHost\": \"10.81.129.4:5678\",\n"
56-
+ " \"processId\": 2926,\n"
57-
+ " \"processName\": \"3-20210129190038108\",\n"
58-
+ " \"processStartTime\": \"2021-01-29 19:00:38\",\n"
59-
+ " \"processState\": \"SUCCESS\",\n"
60-
+ " \"processType\": \"START_PROCESS\",\n"
61-
+ " \"projectId\": 2,\n"
62-
+ " \"projectName\": \"testdelproject\",\n"
63-
+ " \"recovery\": \"NO\",\n"
64-
+ " \"retryTimes\": 0,\n"
65-
+ " \"runTimes\": 1,\n"
66-
+ " \"taskId\": 0\n"
67-
+ " }\n"
68-
+ "]";
69-
AlertData alertData = new AlertData();
70-
alertData.setTitle("");
71-
alertData.setContent(alertMsg);
72-
Assertions.assertNotNull(FeiShuSender.formatContent(alertData));
73-
}
74-
75-
@Test
76-
public void testSendWithFormatException() {
77-
AlertData alertData = new AlertData();
78-
alertData.setTitle("feishu test title");
79-
alertData.setContent("[{\"content\":\"feishu test content\"}]");
80-
String alertResult = FeiShuSender.formatContent(alertData);
81-
Assertions.assertEquals(alertResult, "`feishu test title`\ncontent:feishu test content\n");
82-
}
83-
84-
@Test
85-
public void testCheckSendFeiShuSendMsgResult() {
86-
87-
AlertResult alertResult = FeiShuSender.checkSendFeiShuSendMsgResult("");
88-
Assertions.assertFalse(alertResult.isSuccess());
89-
AlertResult alertResult2 = FeiShuSender.checkSendFeiShuSendMsgResult("{\"code\":123}");
90-
Assertions.assertEquals("alert send feishu msg error: null",
91-
alertResult2.getMessage());
92-
93-
String response = "{\"code\":\"0\",\"data\":{},\"msg\":\"success\"}";
94-
AlertResult alertResult3 = FeiShuSender.checkSendFeiShuSendMsgResult(response);
95-
Assertions.assertTrue(alertResult3.isSuccess());
96-
}
9749
}

dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public final class HttpSender {
4949
private int timeout;
5050
private String url;
5151

52-
public HttpSender(Map<String, String> paramsMap) {
52+
HttpSender(Map<String, String> paramsMap) {
5353
paramsValidator(paramsMap);
5454
}
5555

@@ -96,7 +96,7 @@ private void paramsValidator(Map<String, String> paramsMap) {
9696
: HttpAlertConstants.DEFAULT_TIMEOUT) * 1000;
9797
}
9898

99-
public AlertResult send(String msg) {
99+
AlertResult send(String msg) {
100100

101101
AlertResult alertResult = new AlertResult();
102102
OkHttpResponse okHttpResponse;

dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-pagerduty/src/main/java/org/apache/dolphinscheduler/plugin/alert/pagerduty/PagerDutySender.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ public final class PagerDutySender {
4646

4747
private final String integrationKey;
4848

49-
public PagerDutySender(Map<String, String> config) {
49+
PagerDutySender(Map<String, String> config) {
5050
integrationKey = config.get(PagerDutyParamsConstants.NAME_PAGER_DUTY_INTEGRATION_KEY_NAME);
5151
Preconditions.checkArgument(!Objects.isNull(integrationKey), "PagerDuty integration key can not be null");
5252
}
5353

54-
public AlertResult sendPagerDutyAlter(String title, String content) {
54+
AlertResult sendPagerDutyAlter(String title, String content) {
5555
AlertResult alertResult = new AlertResult();
5656
alertResult.setSuccess(false);
5757
alertResult.setMessage("send pager duty alert fail.");
@@ -124,7 +124,7 @@ private static HttpPost constructHttpPost(String url, String requestBody) {
124124
return post;
125125
}
126126

127-
public static String formatContent(String content) {
127+
private static String formatContent(String content) {
128128
List<Map> list = JSONUtils.toList(content, Map.class);
129129
if (list.isEmpty()) {
130130
return content;

0 commit comments

Comments
 (0)