You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampark.apache.org by fa...@apache.org on 2022/11/17 16:01:46 UTC
[incubator-streampark] branch dev updated: [Bug] Fix the mapping between alarmType and implement class(#2046)
This is an automated email from the ASF dual-hosted git repository.
fanrui pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampark.git
The following commit(s) were added to refs/heads/dev by this push:
new 00acd9898 [Bug] Fix the mapping between alarmType and implement class(#2046)
00acd9898 is described below
commit 00acd9898e25180ef543913feecdb9af83f373fc
Author: benjobs <be...@apache.org>
AuthorDate: Fri Nov 18 00:01:40 2022 +0800
[Bug] Fix the mapping between alarmType and implement class(#2046)
---
.../streampark/console/core/enums/AlertType.java | 6 ++----
.../core/service/alert/impl/AlertServiceImpl.java | 25 +++++++++++++++++++---
2 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/enums/AlertType.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/enums/AlertType.java
index d3dd6f58d..7258d8811 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/enums/AlertType.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/enums/AlertType.java
@@ -33,6 +33,7 @@ public enum AlertType {
LARK(16);
private final Integer code;
+
private static Map<Integer, AlertType> cacheMap;
AlertType(Integer code) {
@@ -79,12 +80,9 @@ public enum AlertType {
return cacheMap.get(code);
}
- public String getServiceType() {
- return this.name() + "AlertNotifyServiceImpl";
- }
-
@JsonValue
public int getCode() {
return this.code;
}
+
}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/alert/impl/AlertServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/alert/impl/AlertServiceImpl.java
index 8a12c2c29..3334bb63f 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/alert/impl/AlertServiceImpl.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/alert/impl/AlertServiceImpl.java
@@ -17,6 +17,7 @@
package org.apache.streampark.console.core.service.alert.impl;
+import org.apache.streampark.common.util.AssertUtils;
import org.apache.streampark.console.base.exception.AlertException;
import org.apache.streampark.console.base.util.SpringContextUtils;
import org.apache.streampark.console.core.bean.AlertConfigWithParams;
@@ -78,9 +79,9 @@ public class AlertServiceImpl implements AlertService {
// No use thread pool, ensure that the alarm can be sent successfully
Tuple2<Boolean, AlertException> reduce = alertTypes.stream().map(alertType -> {
try {
- boolean alertRes = SpringContextUtils
- .getBean(alertType.getServiceType(), AlertNotifyService.class)
- .doAlert(params, alertTemplate);
+ Class<? extends AlertNotifyService> notifyServiceClass = getAlertServiceImpl(alertType);
+ AssertUtils.state(notifyServiceClass != null);
+ boolean alertRes = SpringContextUtils.getBean(notifyServiceClass).doAlert(params, alertTemplate);
return new Tuple2<Boolean, AlertException>(alertRes, null);
} catch (AlertException e) {
return new Tuple2<>(false, e);
@@ -103,4 +104,22 @@ public class AlertServiceImpl implements AlertService {
return reduce.f0;
}
+
+ private Class<? extends AlertNotifyService> getAlertServiceImpl(AlertType alertType) {
+ switch (alertType) {
+ case EMAIL:
+ return EmailAlertNotifyServiceImpl.class;
+ case DING_TALK:
+ return DingTalkAlertNotifyServiceImpl.class;
+ case WE_COM:
+ return WeComAlertNotifyServiceImpl.class;
+ case LARK:
+ return LarkAlertNotifyServiceImpl.class;
+ case HTTP_CALLBACK:
+ return HttpCallbackAlertNotifyServiceImpl.class;
+ default:
+ return null;
+ }
+ }
+
}