diff --git a/alerter/src/main/java/org/apache/hertzbeat/alert/service/AlertService.java b/alerter/src/main/java/org/apache/hertzbeat/alert/service/AlertService.java index 2bc6b182e64..34b16bcb02b 100644 --- a/alerter/src/main/java/org/apache/hertzbeat/alert/service/AlertService.java +++ b/alerter/src/main/java/org/apache/hertzbeat/alert/service/AlertService.java @@ -31,6 +31,14 @@ */ public interface AlertService { + /** + * Verify the correctness of the request data parameters + * @param alert AlertSilence + * @param isModify whether modify + * @throws IllegalArgumentException A checksum parameter error is thrown + */ + void validate(Alert alert, boolean isModify) throws IllegalArgumentException; + /** * Add alarm record * @param alert Alert entity diff --git a/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertConvergeServiceImpl.java b/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertConvergeServiceImpl.java index a4d05b47e56..36294cd4f9d 100644 --- a/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertConvergeServiceImpl.java +++ b/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertConvergeServiceImpl.java @@ -17,6 +17,7 @@ package org.apache.hertzbeat.alert.service.impl; +import java.util.Objects; import java.util.Set; import lombok.extern.slf4j.Slf4j; import org.apache.hertzbeat.alert.dao.AlertConvergeDao; @@ -45,7 +46,10 @@ public class AlertConvergeServiceImpl implements AlertConvergeService { @Override public void validate(AlertConverge alertConverge, boolean isModify) throws IllegalArgumentException { - // todo + // todo + if (Objects.isNull(alertConverge)) { + throw new IllegalArgumentException("alertConverge is null"); + } } @Override diff --git a/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertDefineAbstractImExportServiceImpl.java b/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertDefineAbstractImExportServiceImpl.java index 2900b0fe3af..e05592a1609 100644 --- a/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertDefineAbstractImExportServiceImpl.java +++ b/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertDefineAbstractImExportServiceImpl.java @@ -26,7 +26,6 @@ import java.io.OutputStream; import java.time.LocalDate; import java.util.List; -import java.util.stream.Collectors; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.apache.hertzbeat.alert.service.AlertDefineImExportService; @@ -51,7 +50,7 @@ public void importConfig(InputStream is) { var formList = parseImport(is) .stream() .map(this::convert) - .collect(Collectors.toUnmodifiableList()); + .toList(); if (!CollectionUtils.isEmpty(formList)) { formList.forEach(alertDefine -> { alertDefineService.validate(alertDefine, false); @@ -65,7 +64,7 @@ public void exportConfig(OutputStream os, List configList) { var monitorList = configList.stream() .map(it -> alertDefineService.getAlertDefine(it)) .map(this::convert) - .collect(Collectors.toUnmodifiableList()); + .toList(); writeOs(monitorList, os); } diff --git a/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertServiceImpl.java b/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertServiceImpl.java index ffdca29f9a9..715790a7325 100644 --- a/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertServiceImpl.java +++ b/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertServiceImpl.java @@ -25,6 +25,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import lombok.extern.slf4j.Slf4j; import org.apache.hertzbeat.alert.dao.AlertDao; import org.apache.hertzbeat.alert.dto.AlertPriorityNum; @@ -55,6 +56,14 @@ public class AlertServiceImpl implements AlertService { @Autowired private AlarmCommonReduce alarmCommonReduce; + @Override + public void validate(Alert alert, boolean isModify) throws IllegalArgumentException { + // todo + if (Objects.isNull(alert)) { + throw new IllegalArgumentException("Alarm priority cannot be empty"); + } + } + @Override public void addAlert(Alert alert) throws RuntimeException { alertDao.save(alert); diff --git a/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertSilenceServiceImpl.java b/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertSilenceServiceImpl.java index a8a347af5b4..931e8922508 100644 --- a/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertSilenceServiceImpl.java +++ b/alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertSilenceServiceImpl.java @@ -50,6 +50,8 @@ public void validate(AlertSilence alertSilence, boolean isModify) throws Illegal // if the alarm silent selection date set in periodic situations is empty, it will be deemed to be all checked. if (alertSilence.getType() == 1 && alertSilence.getDays() == null) { alertSilence.setDays(Arrays.asList((byte) 7, (byte) 1, (byte) 2, (byte) 3, (byte) 4, (byte) 5, (byte) 6)); + } else { + throw new IllegalArgumentException("periodic silence must set the alarm silent selection date"); } } diff --git a/collector/src/main/java/org/apache/hertzbeat/collector/util/TimeExpressionUtil.java b/collector/src/main/java/org/apache/hertzbeat/collector/util/TimeExpressionUtil.java index 69f16ca3c6c..a34d9afa24c 100644 --- a/collector/src/main/java/org/apache/hertzbeat/collector/util/TimeExpressionUtil.java +++ b/collector/src/main/java/org/apache/hertzbeat/collector/util/TimeExpressionUtil.java @@ -36,7 +36,7 @@ /** * time expression deal util */ -public class TimeExpressionUtil { +public final class TimeExpressionUtil { private TimeExpressionUtil() { }