Unverified Commit bc6def96 authored by mydq's avatar mydq Committed by GitHub

Pr allow circular references config add (#754)

* application.yml

* alert group : alert instance ids null
parent cab944cb
...@@ -22,8 +22,11 @@ package com.dlink.service.impl; ...@@ -22,8 +22,11 @@ package com.dlink.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dlink.alert.*; import com.dlink.alert.Alert;
import com.dlink.assertion.Asserts; import com.dlink.alert.AlertConfig;
import com.dlink.alert.AlertMsg;
import com.dlink.alert.AlertResult;
import com.dlink.alert.ShowType;
import com.dlink.common.result.Result; import com.dlink.common.result.Result;
import com.dlink.db.service.impl.SuperServiceImpl; import com.dlink.db.service.impl.SuperServiceImpl;
import com.dlink.mapper.AlertInstanceMapper; import com.dlink.mapper.AlertInstanceMapper;
...@@ -32,7 +35,6 @@ import com.dlink.model.AlertInstance; ...@@ -32,7 +35,6 @@ import com.dlink.model.AlertInstance;
import com.dlink.service.AlertGroupService; import com.dlink.service.AlertGroupService;
import com.dlink.service.AlertInstanceService; import com.dlink.service.AlertInstanceService;
import com.dlink.utils.JSONUtil; import com.dlink.utils.JSONUtil;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
...@@ -48,6 +50,7 @@ import java.util.HashMap; ...@@ -48,6 +50,7 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -131,6 +134,9 @@ public class AlertInstanceServiceImpl extends SuperServiceImpl<AlertInstanceMapp ...@@ -131,6 +134,9 @@ public class AlertInstanceServiceImpl extends SuperServiceImpl<AlertInstanceMapp
} }
final Map<Integer, String> result = new HashMap<>(8); final Map<Integer, String> result = new HashMap<>(8);
for (Map.Entry<Integer, Set<Integer>> entry : alertGroupInformation.entrySet()) { for (Map.Entry<Integer, Set<Integer>> entry : alertGroupInformation.entrySet()) {
if (entry.getKey() == null){
continue;
}
final Set<Integer> groupIdSet = entry.getValue(); final Set<Integer> groupIdSet = entry.getValue();
for (Integer groupId : groupIdSet) { for (Integer groupId : groupIdSet) {
final String instanceIdString = result.get(groupId); final String instanceIdString = result.get(groupId);
...@@ -138,15 +144,17 @@ public class AlertInstanceServiceImpl extends SuperServiceImpl<AlertInstanceMapp ...@@ -138,15 +144,17 @@ public class AlertInstanceServiceImpl extends SuperServiceImpl<AlertInstanceMapp
: instanceIdString + "," + entry.getKey()); : instanceIdString + "," + entry.getKey());
} }
} }
updateAlertGroupInformation(result); updateAlertGroupInformation(result, alertGroupInformation.get(null));
} }
private void updateAlertGroupInformation(Map<Integer, String> result) { private void updateAlertGroupInformation(Map<Integer, String> result, Set<Integer> groupIdSet) {
final LocalDateTime now = LocalDateTime.now(); final LocalDateTime now = LocalDateTime.now();
final List<AlertGroup> list = result.entrySet().stream().map(entry -> { final List<AlertGroup> list = groupIdSet.stream().filter(Objects::nonNull)
.map(groupId -> {
final AlertGroup alertGroup = new AlertGroup(); final AlertGroup alertGroup = new AlertGroup();
alertGroup.setId(entry.getKey()); alertGroup.setId(groupId);
alertGroup.setAlertInstanceIds(entry.getValue()); final String groupIds = result.get(groupId);
alertGroup.setAlertInstanceIds(groupIds == null ? "" : groupIds);
alertGroup.setUpdateTime(now); alertGroup.setUpdateTime(now);
return alertGroup; return alertGroup;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
...@@ -162,9 +170,12 @@ public class AlertInstanceServiceImpl extends SuperServiceImpl<AlertInstanceMapp ...@@ -162,9 +170,12 @@ public class AlertInstanceServiceImpl extends SuperServiceImpl<AlertInstanceMapp
return new HashMap<>(0); return new HashMap<>(0);
} }
final Map<Integer, Set<Integer>> map = new HashMap<>(list.size()); final Map<Integer, Set<Integer>> map = new HashMap<>(list.size());
final Set<Integer> groupIdSet = new HashSet<>();
for (AlertGroup alertGroup : list) { for (AlertGroup alertGroup : list) {
buildGroup(map, alertGroup); buildGroup(map, alertGroup);
groupIdSet.add(alertGroup.getId());
} }
map.put(null, groupIdSet);
return map; return map;
} }
......
...@@ -6,6 +6,8 @@ spring: ...@@ -6,6 +6,8 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
application: application:
name: dlink name: dlink
main:
allow-circular-references: true
# flyway: # flyway:
# enabled: false # enabled: false
# clean-disabled: true # clean-disabled: true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment