Browse Source

[11130] Refactor alert-api with lombok (#11133)

3.1.0-release
SongTao Zhuang 2 years ago committed by GitHub
parent
commit
a52d1b4acd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 191
      dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertData.java
  2. 108
      dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertInfo.java
  3. 111
      dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/AlertResult.java
  4. 21
      dolphinscheduler-alert/dolphinscheduler-alert-api/src/main/java/org/apache/dolphinscheduler/alert/api/ShowType.java
  5. 11
      dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/test/java/org/apache/dolphinscheduler/plugin/alert/email/EmailAlertChannelTest.java
  6. 30
      dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertSenderService.java

191
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 {
private int id;
private String title;
private String content;
private String log;
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 {
/**
* alert id
*/
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;
}
/**
* alert tile
*/
private String title;
public AlertDataBuilder warnType(int warnType) {
this.warnType = warnType;
return this;
}
/**
* alert content
*/
private String content;
public AlertData build() {
return new AlertData(id, title, content, log, warnType);
}
/**
* alert log
*/
private String log;
@Override
public String toString() {
return "AlertData.AlertDataBuilder(id=" + this.id + ", title=" + this.title + ", content=" + this.content + ", log=" + this.log + ", warnType=" + this.warnType + ")";
}
/**
* 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;
}
}

108
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<String, String> alertParams;
private AlertData alertData;
public AlertInfo(Map<String, String> alertParams, AlertData alertData) {
this.alertParams = alertParams;
this.alertData = alertData;
}
public AlertInfo() {
}
public static AlertInfoBuilder builder() {
return new AlertInfoBuilder();
}
public Map<String, String> getAlertParams() {
return this.alertParams;
}
public AlertInfo setAlertParams(Map<String, String> 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<String, String> alertParams;
private AlertData alertData;
AlertInfoBuilder() {
}
public AlertInfoBuilder alertParams(Map<String, String> alertParams) {
this.alertParams = alertParams;
return this;
}
public AlertInfoBuilder alertData(AlertData alertData) {
this.alertData = alertData;
return this;
}
public AlertInfo build() {
return new AlertInfo(alertParams, alertData);
}
private AlertData alertData;
@Override
public String toString() {
return "AlertInfo.AlertInfoBuilder(alertParams=" + this.alertParams + ", alertData=" + this.alertData + ")";
}
}
}

111
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 {
private String status;
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 {
/**
* false or true
*/
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);
}
/**
* alert result message
*/
private String message;
@Override
public String toString() {
return "AlertResult.AlertResultBuilder(status=" + this.status + ", message=" + this.message + ")";
}
}
}

21
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;
}
private final String descp;
public String getDescp() {
return descp;
}
}

11
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<String, Object> 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<String, String> paramsMap = PluginParamsTransfer.getPluginParamsMap(getEmailAlertParams());

30
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<AlertPluginInstance> 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<AlertSendResponseResult> 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 {

Loading…
Cancel
Save