This is an automated email from the ASF dual-hosted git repository.
wenjun pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new caa6287d7f Add alertPluginInstanceId in AlertInfo (#11231)
caa6287d7f is described below
commit caa6287d7fb9d73e18cdad2850f1ec08e602ad38
Author: Wenjun Ruan <[email protected]>
AuthorDate: Mon Aug 1 17:32:26 2022 +0800
Add alertPluginInstanceId in AlertInfo (#11231)
---
.../dolphinscheduler/alert/api/AlertChannel.java | 4 ++-
.../dolphinscheduler/alert/api/AlertInfo.java | 2 ++
.../dolphinscheduler/alert/AlertSenderService.java | 35 +++++++---------------
3 files changed, 16 insertions(+), 25 deletions(-)
diff --git
a/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertChannel.java
b/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertChannel.java
index 56c45362dd..b461555a0e 100644
---
a/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertChannel.java
+++
b/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertChannel.java
@@ -19,6 +19,8 @@
package org.apache.dolphinscheduler.alert.api;
+import lombok.NonNull;
+
/**
* alert channel for sending alerts
*/
@@ -31,7 +33,7 @@ public interface AlertChannel {
*/
AlertResult process(AlertInfo info);
- default AlertResult closeAlert(AlertInfo info) {
+ default @NonNull AlertResult closeAlert(AlertInfo info) {
return new AlertResult("true", "no need to close alert");
}
}
diff --git
a/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertInfo.java
b/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertInfo.java
index e7e8e86074..8e60bdd07a 100644
---
a/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertInfo.java
+++
b/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertInfo.java
@@ -39,4 +39,6 @@ public class AlertInfo {
private AlertData alertData;
+ private int alertPluginInstanceId;
+
}
diff --git
a/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertSenderService.java
b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertSenderService.java
index fe2e1aaf4c..48dfaf3e3d 100644
---
a/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertSenderService.java
+++
b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertSenderService.java
@@ -233,12 +233,13 @@ public final class AlertSenderService extends Thread {
}
AlertInfo alertInfo = AlertInfo.builder()
- .alertData(alertData)
- .alertParams(paramsMap)
- .build();
+ .alertData(alertData)
+ .alertParams(paramsMap)
+ .alertPluginInstanceId(instance.getId())
+ .build();
int waitTimeout = alertConfig.getWaitTimeout();
- AlertResult alertResult;
try {
+ AlertResult alertResult;
if (waitTimeout <= 0) {
if (alertData.getAlertType() ==
AlertType.CLOSE_ALERT.getCode()) {
alertResult = alertChannel.closeAlert(alertInfo);
@@ -254,31 +255,17 @@ public final class AlertSenderService extends Thread {
}
alertResult = future.get(waitTimeout, TimeUnit.MILLISECONDS);
}
+ if (alertResult == null) {
+ throw new RuntimeException("Alert result cannot be null");
+ }
+ return alertResult;
} catch (InterruptedException e) {
- alertResult = new AlertResult("false", e.getMessage());
logger.error("send alert error alert data id :{},",
alertData.getId(), e);
Thread.currentThread().interrupt();
+ return new AlertResult("false", e.getMessage());
} catch (Exception e) {
- alertResult = new AlertResult("false", e.getMessage());
logger.error("send alert error alert data id :{},",
alertData.getId(), e);
+ return new AlertResult("false", e.getMessage());
}
-
- AlertResult alertResultExtend = new AlertResult();
- if (alertResult == null) {
- String message = String.format("Alert Plugin %s send error :
return alertResult value is null", pluginInstanceName);
- alertResultExtend.setStatus("false");
- alertResultExtend.setMessage(message);
- logger.info("Alert Plugin {} send error : return alertResult value
is null", pluginInstanceName);
- } else if
(!Boolean.parseBoolean(String.valueOf(alertResult.getStatus()))) {
- alertResultExtend.setStatus("false");
- alertResultExtend.setMessage(alertResult.getMessage());
- logger.info("Alert Plugin {} send error : {}", pluginInstanceName,
alertResult.getMessage());
- } else {
- String message = String.format("Alert Plugin %s send success",
pluginInstanceName);
- alertResultExtend.setStatus("true");
- alertResultExtend.setMessage(message);
- logger.info("Alert Plugin {} send success", pluginInstanceName);
- }
- return alertResultExtend;
}
}