Skip to content

Commit

Permalink
feat: auto close
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangwanpeng committed Oct 16, 2023
1 parent 4e7d68a commit 70c9d0a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class ProductCtlServiceImpl implements ProductCtlService {

@Scheduled(initialDelay = 10000L, fixedRate = 10000L)
private void refresh() {
List<MonitorInstance> monitorInstances = monitorInstanceService.queryByType("server");
List<MonitorInstance> monitorInstances = monitorInstanceService.list();
Map<String, Set<String>> dbProductClosed = new HashMap<>();
for (MonitorInstance monitorInstance : monitorInstances) {
MonitorInstanceCfg cfg =
Expand Down Expand Up @@ -105,14 +105,15 @@ public Map<String, Set<String>> productCtl(MonitorProductCode code, Map<String,
}
String uniqueId = buildResourceVal(rks, tags);

MonitorInstance instance = monitorInstanceService.queryByInstanceAndType(uniqueId, "server");
if (instance != null) {
List<MonitorInstance> instances = monitorInstanceService.queryByInstance(uniqueId);
if (CollectionUtils.isNotEmpty(instances)) {
MonitorInstance instance = instances.get(0);
MonitorInstanceCfg cfg = J.fromJson(instance.getConfig(), MonitorInstanceCfg.class);
control(action, uniqueId, code.getCode(), cfg.getClosed(), productClosed);
log.info("[product_ctl] uniqueId={}, instanceClosed={}, closed={}", uniqueId, cfg.getClosed(),
productClosed);
instance.setConfig(J.toJson(cfg));
monitorInstanceService.updateByInstanceAndType(instance);
monitorInstanceService.updateByInstance(instance);
}
return productClosed;
}
Expand All @@ -126,10 +127,14 @@ public Map<String, Boolean> productStatus(Map<String, String> tags) throws Excep
closed.put(code.getCode(), false);
} else {
String uniqueId = buildResourceVal(rks, tags);
MonitorInstance instance =
monitorInstanceService.queryByInstanceAndType(uniqueId, "server");
MonitorInstanceCfg cfg = J.fromJson(instance.getConfig(), MonitorInstanceCfg.class);
closed = cfg.getClosed();
List<MonitorInstance> instances = monitorInstanceService.queryByInstance(uniqueId);
if (CollectionUtils.isEmpty(instances)) {
closed.put(code.getCode(), false);
} else {
MonitorInstanceCfg cfg =
J.fromJson(instances.get(0).getConfig(), MonitorInstanceCfg.class);
closed = cfg.getClosed();
}
}
}
return closed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ public interface MonitorInstanceService extends IService<MonitorInstance> {

Boolean updateByInstanceAndType(MonitorInstance monitorInstance);

Boolean updateByInstance(MonitorInstance monitorInstance);

}
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,11 @@ public Boolean updateByInstanceAndType(MonitorInstance monitorInstance) {
return update(monitorInstance, updateWrapper);
}

@Override
public Boolean updateByInstance(MonitorInstance monitorInstance) {
UpdateWrapper<MonitorInstance> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("instance", monitorInstance.getInstance());
return update(monitorInstance, updateWrapper);
}

}

0 comments on commit 70c9d0a

Please sign in to comment.