diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertData.java b/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertData.java index f0c2f339b8..50b6c2cc7a 100644 --- a/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertData.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertData.java @@ -19,177 +19,46 @@ package org.apache.dolphinscheduler.alert.api; -import java.util.Objects; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; /** * alert data */ +@AllArgsConstructor +@Builder +@Data +@NoArgsConstructor public class AlertData { + + /** + * alert id + */ private int id; + + /** + * alert tile + */ private String title; + + /** + * alert content + */ private String content; + + /** + * alert log + */ private String log; + + /** + * 0 do not send warning; + * 1 send if process success; + * 2 send if process failed; + * 3 send if process ends, whatever the result; + */ private int warnType; - public AlertData(int id, String title, String content, String log, int warnType) { - this.id = id; - this.title = title; - this.content = content; - this.log = log; - this.warnType = warnType; - } - - public AlertData() { - } - - public static AlertDataBuilder builder() { - return new AlertDataBuilder(); - } - - public int getId() { - return this.id; - } - - public AlertData setId(int id) { - this.id = id; - return this; - } - - public String getTitle() { - return this.title; - } - - public AlertData setTitle(String title) { - this.title = title; - return this; - } - - public String getContent() { - return this.content; - } - - public AlertData setContent(String content) { - this.content = content; - return this; - } - - public String getLog() { - return this.log; - } - - public AlertData setLog(String log) { - this.log = log; - return this; - } - - public int getWarnType() { - return warnType; - } - - public void setWarnType(int warnType) { - this.warnType = warnType; - } - - @Override - public boolean equals(final Object o) { - if (o == this) { - return true; - } - if (!(o instanceof AlertData)) { - return false; - } - final AlertData other = (AlertData) o; - if (!other.canEqual(this)) { - return false; - } - if (this.getId() != other.getId()) { - return false; - } - if (this.getWarnType() != other.getWarnType()) { - return false; - } - final Object thisTitle = this.getTitle(); - final Object otherTitle = other.getTitle(); - if (!Objects.equals(thisTitle, otherTitle)) { - return false; - } - final Object thisContent = this.getContent(); - final Object otherContent = other.getContent(); - if (!Objects.equals(thisContent, otherContent)) { - return false; - } - final Object thisLog = this.getLog(); - final Object otherLog = other.getLog(); - return Objects.equals(thisLog, otherLog); - } - - protected boolean canEqual(final Object other) { - return other instanceof AlertData; - } - - @Override - public int hashCode() { - final int prime = 59; - int result = 1; - result = result * prime + this.getId(); - result = result * prime + this.getWarnType(); - final Object title = this.getTitle(); - result = result * prime + (title == null ? 43 : title.hashCode()); - final Object content = this.getContent(); - result = result * prime + (content == null ? 43 : content.hashCode()); - final Object log = this.getLog(); - result = result * prime + (log == null ? 43 : log.hashCode()); - return result; - } - - @Override - public String toString() { - return "AlertData(id=" + this.getId() + ", title=" + this.getTitle() + ", content=" + this.getContent() + ", log=" + this.getLog() + ", warnType=" + this.getWarnType() + ")"; - } - - public static class AlertDataBuilder { - private int id; - private String title; - private String content; - private String log; - private int warnType; - - AlertDataBuilder() { - } - - public AlertDataBuilder id(int id) { - this.id = id; - return this; - } - - public AlertDataBuilder title(String title) { - this.title = title; - return this; - } - - public AlertDataBuilder content(String content) { - this.content = content; - return this; - } - - public AlertDataBuilder log(String log) { - this.log = log; - return this; - } - - public AlertDataBuilder warnType(int warnType) { - this.warnType = warnType; - return this; - } - - public AlertData build() { - return new AlertData(id, title, content, log, warnType); - } - - @Override - public String toString() { - return "AlertData.AlertDataBuilder(id=" + this.id + ", title=" + this.title + ", content=" + this.content + ", log=" + this.log + ", warnType=" + this.warnType + ")"; - } - - } } 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 c3ff3d21c9..e7e8e86074 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 @@ -20,111 +20,23 @@ package org.apache.dolphinscheduler.alert.api; import java.util.Map; -import java.util.Objects; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; /** * The alarm information includes the parameters of the alert channel and the alarm data */ +@AllArgsConstructor +@Builder +@Data +@NoArgsConstructor public class AlertInfo { + private Map alertParams; + private AlertData alertData; - public AlertInfo(Map alertParams, AlertData alertData) { - this.alertParams = alertParams; - this.alertData = alertData; - } - - public AlertInfo() { - } - - public static AlertInfoBuilder builder() { - return new AlertInfoBuilder(); - } - - public Map getAlertParams() { - return this.alertParams; - } - - public AlertInfo setAlertParams(Map alertParams) { - this.alertParams = alertParams; - return this; - } - - public AlertData getAlertData() { - return this.alertData; - } - - public AlertInfo setAlertData(AlertData alertData) { - this.alertData = alertData; - return this; - } - - @Override - public boolean equals(final Object o) { - if (o == this) { - return true; - } - if (!(o instanceof AlertInfo)) { - return false; - } - final AlertInfo other = (AlertInfo) o; - if (!other.canEqual((Object) this)) { - return false; - } - final Object thisAlertParams = this.getAlertParams(); - final Object otherAlertParams = other.getAlertParams(); - if (!Objects.equals(thisAlertParams, otherAlertParams)) { - return false; - } - final Object thisAlertData = this.getAlertData(); - final Object otherAlertData = other.getAlertData(); - return Objects.equals(thisAlertData, otherAlertData); - } - - protected boolean canEqual(final Object other) { - return other instanceof AlertInfo; - } - - @Override - public int hashCode() { - final int prime = 59; - int result = 1; - final Object alertParams = this.getAlertParams(); - result = result * prime + (alertParams == null ? 43 : alertParams.hashCode()); - final Object alertData = this.getAlertData(); - result = result * prime + (alertData == null ? 43 : alertData.hashCode()); - return result; - } - - @Override - public String toString() { - return "AlertInfo(alertParams=" + this.getAlertParams() + ", alertData=" + this.getAlertData() + ")"; - } - - public static class AlertInfoBuilder { - private Map alertParams; - private AlertData alertData; - - AlertInfoBuilder() { - } - - public AlertInfoBuilder alertParams(Map alertParams) { - this.alertParams = alertParams; - return this; - } - - public AlertInfoBuilder alertData(AlertData alertData) { - this.alertData = alertData; - return this; - } - - public AlertInfo build() { - return new AlertInfo(alertParams, alertData); - } - - @Override - public String toString() { - return "AlertInfo.AlertInfoBuilder(alertParams=" + this.alertParams + ", alertData=" + this.alertData + ")"; - } - } } diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertResult.java b/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertResult.java index ede235c953..734d51779f 100644 --- a/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertResult.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertResult.java @@ -19,111 +19,26 @@ package org.apache.dolphinscheduler.alert.api; -import java.util.Objects; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; /** * alert result */ +@AllArgsConstructor +@Data +@NoArgsConstructor public class AlertResult { + + /** + * false or true + */ private String status; + + /** + * alert result message + */ private String message; - public AlertResult(String status, String message) { - this.status = status; - this.message = message; - } - - public AlertResult() { - } - - public static AlertResultBuilder builder() { - return new AlertResultBuilder(); - } - - public String getStatus() { - return this.status; - } - - public AlertResult setStatus(String status) { - this.status = status; - return this; - } - - public String getMessage() { - return this.message; - } - - public AlertResult setMessage(String message) { - this.message = message; - return this; - } - - @Override - public boolean equals(final Object o) { - if (o == this) { - return true; - } - if (!(o instanceof AlertResult)) { - return false; - } - final AlertResult other = (AlertResult) o; - if (!other.canEqual(this)) { - return false; - } - final Object thisStatus = this.getStatus(); - final Object otherStatus = other.getStatus(); - if (!Objects.equals(thisStatus, otherStatus)) { - return false; - } - final Object thisMessage = this.getMessage(); - final Object otherMessage = other.getMessage(); - return Objects.equals(thisMessage, otherMessage); - } - - protected boolean canEqual(final Object other) { - return other instanceof AlertResult; - } - - @Override - public int hashCode() { - final int prime = 59; - int result = 1; - final Object s = this.getStatus(); - result = result * prime + (s == null ? 43 : s.hashCode()); - final Object message = this.getMessage(); - result = result * prime + (message == null ? 43 : message.hashCode()); - return result; - } - - @Override - public String toString() { - return "AlertResult(status=" + this.getStatus() + ", message=" + this.getMessage() + ")"; - } - - public static class AlertResultBuilder { - private String status; - private String message; - - AlertResultBuilder() { - } - - public AlertResultBuilder status(String status) { - this.status = status; - return this; - } - - public AlertResultBuilder message(String message) { - this.message = message; - return this; - } - - public AlertResult build() { - return new AlertResult(status, message); - } - - @Override - public String toString() { - return "AlertResult.AlertResultBuilder(status=" + this.status + ", message=" + this.message + ")"; - } - } } diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/ShowType.java b/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/ShowType.java index 2f1b4f2b4b..95dccae7eb 100644 --- a/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/ShowType.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/ShowType.java @@ -19,6 +19,11 @@ package org.apache.dolphinscheduler.alert.api; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@AllArgsConstructor +@Getter public enum ShowType { /** * 0 TABLE; @@ -31,21 +36,11 @@ public enum ShowType { TEXT(1, "text"), ATTACHMENT(2, "attachment"), TABLE_ATTACHMENT(3, "table attachment"), - MARKDOWN(4, "markdown"),; + MARKDOWN(4, "markdown"), + ; private final int code; + private final String descp; - ShowType(int code, String descp) { - this.code = code; - this.descp = descp; - } - - public int getCode() { - return code; - } - - public String getDescp() { - return descp; - } } diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelTest.java index 8eb328114f..6a123eedcc 100644 --- a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelTest.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelTest.java @@ -43,7 +43,6 @@ public class EmailAlertChannelTest { @Test public void testProcess() { EmailAlertChannel emailAlertChannel = new EmailAlertChannel(); - AlertData alertData = new AlertData(); LinkedHashMap map1 = new LinkedHashMap<>(); map1.put("mysql service name", "mysql200"); map1.put("mysql address", "192.168.xx.xx"); @@ -54,10 +53,12 @@ public class EmailAlertChannelTest { maps.add(0, map1); String mapjson = JSONUtils.toJsonString(maps); - alertData.setId(10) - .setContent(mapjson) - .setLog("10") - .setTitle("test"); + AlertData alertData = AlertData.builder() + .id(10) + .content(mapjson) + .log("10") + .title("test") + .build(); AlertInfo alertInfo = new AlertInfo(); alertInfo.setAlertData(alertData); Map paramsMap = PluginParamsTransfer.getPluginParamsMap(getEmailAlertParams()); 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 ad92862ba9..2f91579322 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 @@ -92,13 +92,13 @@ public final class AlertSenderService extends Thread { alertDao.updateAlert(AlertStatus.EXECUTION_FAILURE, "no bind plugin instance", alertId); continue; } - AlertData alertData = new AlertData(); - alertData.setId(alertId) - .setContent(alert.getContent()) - .setLog(alert.getLog()) - .setTitle(alert.getTitle()) - .setTitle(alert.getTitle()) - .setWarnType(alert.getWarningType().getCode()); + AlertData alertData = AlertData.builder() + .id(alertId) + .content(alert.getContent()) + .log(alert.getLog()) + .title(alert.getTitle()) + .warnType(alert.getWarningType().getCode()) + .build(); int sendSuccessCount = 0; for (AlertPluginInstance instance : alertInstanceList) { @@ -131,10 +131,11 @@ public final class AlertSenderService extends Thread { */ public AlertSendResponseCommand syncHandler(int alertGroupId, String title, String content, int warnType) { List alertInstanceList = alertDao.listInstanceByAlertGroupId(alertGroupId); - AlertData alertData = new AlertData(); - alertData.setContent(content) - .setTitle(title) - .setWarnType(warnType); + AlertData alertData = AlertData.builder() + .content(content) + .title(title) + .warnType(warnType) + .build(); boolean sendResponseStatus = true; List sendResponseResults = new ArrayList<>(); @@ -222,9 +223,10 @@ public final class AlertSenderService extends Thread { return null; } - AlertInfo alertInfo = new AlertInfo(); - alertInfo.setAlertData(alertData); - alertInfo.setAlertParams(paramsMap); + AlertInfo alertInfo = AlertInfo.builder() + .alertData(alertData) + .alertParams(paramsMap) + .build(); int waitTimeout = alertConfig.getWaitTimeout(); AlertResult alertResult; try {