Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Optimize] some optimize for alert module #2331

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -65,7 +64,7 @@ public void exportConfig(OutputStream os, List<Long> configList) {
var monitorList = configList.stream()
.map(it -> alertDefineService.getAlertDefine(it))
.map(this::convert)
.collect(Collectors.toUnmodifiableList());
.toList();
writeOs(monitorList, os);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
/**
* time expression deal util
*/
public class TimeExpressionUtil {
public final class TimeExpressionUtil {

private TimeExpressionUtil() {
}
Expand Down