Skip to content

Commit

Permalink
Pr allow circular references config add (DataLinkDC#754)
Browse files Browse the repository at this point in the history
* application.yml

* alert group : alert instance ids null
  • Loading branch information
mydq authored Jul 21, 2022
1 parent cab944c commit bc6def9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dlink.alert.*;
import com.dlink.assertion.Asserts;
import com.dlink.alert.Alert;
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.db.service.impl.SuperServiceImpl;
import com.dlink.mapper.AlertInstanceMapper;
Expand All @@ -32,7 +35,6 @@
import com.dlink.service.AlertGroupService;
import com.dlink.service.AlertInstanceService;
import com.dlink.utils.JSONUtil;

import com.fasterxml.jackson.databind.JsonNode;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
Expand All @@ -48,6 +50,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -131,25 +134,30 @@ private void writeBackGroupInformation(Map<Integer, Set<Integer>> alertGroupInfo
}
final Map<Integer, String> result = new HashMap<>(8);
for (Map.Entry<Integer, Set<Integer>> entry : alertGroupInformation.entrySet()) {
if (entry.getKey() == null){
continue;
}
final Set<Integer> groupIdSet = entry.getValue();
for (Integer groupId : groupIdSet) {
final String instanceIdString = result.get(groupId);
result.put(groupId, instanceIdString == null ? "" + 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 List<AlertGroup> list = result.entrySet().stream().map(entry -> {
final AlertGroup alertGroup = new AlertGroup();
alertGroup.setId(entry.getKey());
alertGroup.setAlertInstanceIds(entry.getValue());
alertGroup.setUpdateTime(now);
return alertGroup;
}).collect(Collectors.toList());
final List<AlertGroup> list = groupIdSet.stream().filter(Objects::nonNull)
.map(groupId -> {
final AlertGroup alertGroup = new AlertGroup();
alertGroup.setId(groupId);
final String groupIds = result.get(groupId);
alertGroup.setAlertInstanceIds(groupIds == null ? "" : groupIds);
alertGroup.setUpdateTime(now);
return alertGroup;
}).collect(Collectors.toList());
alertGroupService.updateBatchById(list);
}

Expand All @@ -162,9 +170,12 @@ private Map<Integer, Set<Integer>> getAlertGroupInformation(){
return new HashMap<>(0);
}
final Map<Integer, Set<Integer>> map = new HashMap<>(list.size());
final Set<Integer> groupIdSet = new HashSet<>();
for (AlertGroup alertGroup : list) {
buildGroup(map, alertGroup);
groupIdSet.add(alertGroup.getId());
}
map.put(null, groupIdSet);
return map;
}

Expand Down
2 changes: 2 additions & 0 deletions dlink-admin/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver
application:
name: dlink
main:
allow-circular-references: true
# flyway:
# enabled: false
# clean-disabled: true
Expand Down

0 comments on commit bc6def9

Please sign in to comment.