[alerter] 工程初始化与告警定义相关接口
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
package com.usthe.alert.service;
|
||||
|
||||
import com.usthe.alert.pojo.entity.AlertDefine;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 告警定义管理接口
|
||||
* @author tom
|
||||
* @date 2021/12/9 10:06
|
||||
*/
|
||||
public interface AlertDefineService {
|
||||
|
||||
/**
|
||||
* 校验请求数据参数正确性
|
||||
* @param alertDefine alertDefine
|
||||
* @param isModify 是否是修改配置
|
||||
* @throws IllegalArgumentException 校验参数错误抛出
|
||||
*/
|
||||
void validate(AlertDefine alertDefine, boolean isModify) throws IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* 新增告警定义
|
||||
* @param alertDefine 告警定义实体
|
||||
* @throws RuntimeException 新增过程异常抛出
|
||||
*/
|
||||
void addAlertDefine(AlertDefine alertDefine) throws RuntimeException;
|
||||
|
||||
/**
|
||||
* 修改告警定义
|
||||
* @param alertDefine 告警定义实体
|
||||
* @throws RuntimeException 修改过程中异常抛出
|
||||
*/
|
||||
void modifyAlertDefine(AlertDefine alertDefine) throws RuntimeException;
|
||||
|
||||
/**
|
||||
* 删除告警定义
|
||||
* @param alertId 告警定义ID
|
||||
* @throws RuntimeException 删除过程中异常抛出
|
||||
*/
|
||||
void deleteAlertDefine(long alertId) throws RuntimeException;
|
||||
|
||||
/**
|
||||
* 获取告警定义信息
|
||||
* @param alertId 监控ID
|
||||
* @return AlertDefine
|
||||
* @throws RuntimeException 查询过程中异常抛出
|
||||
*/
|
||||
AlertDefine getAlertDefine(long alertId) throws RuntimeException;
|
||||
|
||||
|
||||
/**
|
||||
* 批量删除告警定义
|
||||
* @param alertIds 告警定义IDs
|
||||
* @throws RuntimeException 删除过程中异常抛出
|
||||
*/
|
||||
void deleteAlertDefines(Set<Long> alertIds) throws RuntimeException;
|
||||
|
||||
/**
|
||||
* 动态条件查询
|
||||
* @param specification 查询条件
|
||||
* @param pageRequest 分页参数
|
||||
* @return 查询结果
|
||||
*/
|
||||
Page<AlertDefine> getAlertDefines(Specification<AlertDefine> specification, PageRequest pageRequest);
|
||||
|
||||
/**
|
||||
* 应用告警定于与监控关联关系
|
||||
* @param alertId 告警定义ID
|
||||
* @param monitorMap 监控ID-名称 MAP
|
||||
*/
|
||||
void applyBindAlertDefineMonitors(Long alertId, Map<Long, String> monitorMap);
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.usthe.alert.service.impl;
|
||||
|
||||
import com.usthe.alert.dao.AlertDefineBindDao;
|
||||
import com.usthe.alert.dao.AlertDefineDao;
|
||||
import com.usthe.alert.pojo.entity.AlertDefine;
|
||||
import com.usthe.alert.pojo.entity.AlertDefineBind;
|
||||
import com.usthe.alert.service.AlertDefineService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 告警定义管理接口实现
|
||||
* @author tom
|
||||
* @date 2021/12/9 10:17
|
||||
*/
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Slf4j
|
||||
public class AlertDefineServiceImpl implements AlertDefineService {
|
||||
|
||||
@Autowired
|
||||
private AlertDefineDao alertDefineDao;
|
||||
|
||||
@Autowired
|
||||
private AlertDefineBindDao alertDefineBindDao;
|
||||
|
||||
@Override
|
||||
public void validate(AlertDefine alertDefine, boolean isModify) throws IllegalArgumentException {
|
||||
// todo
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAlertDefine(AlertDefine alertDefine) throws RuntimeException {
|
||||
alertDefineDao.save(alertDefine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modifyAlertDefine(AlertDefine alertDefine) throws RuntimeException {
|
||||
alertDefineDao.save(alertDefine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAlertDefine(long alertId) throws RuntimeException {
|
||||
alertDefineDao.deleteById(alertId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlertDefine getAlertDefine(long alertId) throws RuntimeException {
|
||||
Optional<AlertDefine> optional = alertDefineDao.findById(alertId);
|
||||
return optional.orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAlertDefines(Set<Long> alertIds) throws RuntimeException {
|
||||
alertDefineDao.deleteAllByIdIn(alertIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<AlertDefine> getAlertDefines(Specification<AlertDefine> specification, PageRequest pageRequest) {
|
||||
return alertDefineDao.findAll(specification, pageRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyBindAlertDefineMonitors(Long alertId, Map<Long, String> monitorMap) {
|
||||
// todo 校验此告警定义和监控是否存在
|
||||
|
||||
// 先删除此告警的所有关联
|
||||
alertDefineBindDao.deleteAlertDefineBindsByAlertDefineIdEquals(alertId);
|
||||
// 保存关联
|
||||
List<AlertDefineBind> alertDefineBinds = monitorMap.entrySet().stream().map(entry ->
|
||||
AlertDefineBind.builder().alertDefineId(alertId).monitorId(entry.getKey())
|
||||
.monitorName(entry.getValue()).build())
|
||||
.collect(Collectors.toList());
|
||||
alertDefineBindDao.saveAll(alertDefineBinds);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user