-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rule-engine): 告警场景2.2相关功能更新 (#552)
- Loading branch information
Showing
79 changed files
with
3,726 additions
and
687 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...ts/common-component/src/main/java/org/jetlinks/community/command/rule/data/AlarmInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package org.jetlinks.community.command.rule.data; | ||
|
||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import org.jetlinks.community.terms.TermSpec; | ||
|
||
import java.io.Serializable; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* 触发告警参数 | ||
*/ | ||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class AlarmInfo implements Serializable { | ||
private static final long serialVersionUID = -2316376361116648370L; | ||
|
||
@Schema(description = "告警配置ID") | ||
private String alarmConfigId; | ||
|
||
@Schema(description = "告警名称") | ||
private String alarmName; | ||
|
||
@Schema(description = "告警说明") | ||
private String description; | ||
|
||
@Schema(description = "告警级别") | ||
private int level; | ||
|
||
@Schema(description = "告警目标类型") | ||
private String targetType; | ||
|
||
@Schema(description = "告警目标ID") | ||
private String targetId; | ||
|
||
@Schema(description = "告警目标名称") | ||
private String targetName; | ||
|
||
@Schema(description = "告警来源类型") | ||
private String sourceType; | ||
|
||
@Schema(description = "告警来源ID") | ||
private String sourceId; | ||
|
||
@Schema(description = "告警来源名称") | ||
private String sourceName; | ||
|
||
/** | ||
* 标识告警触发的配置来自什么业务功能 | ||
*/ | ||
@Schema(description = "告警配置源") | ||
private String alarmConfigSource; | ||
|
||
@Schema(description = "告警数据") | ||
private Map<String, Object> data; | ||
|
||
/** | ||
* 告警触发条件 | ||
*/ | ||
private TermSpec termSpec; | ||
} |
36 changes: 36 additions & 0 deletions
36
.../common-component/src/main/java/org/jetlinks/community/command/rule/data/AlarmResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.jetlinks.community.command.rule.data; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* 告警结果 | ||
*/ | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
@Setter | ||
public class AlarmResult implements Serializable { | ||
|
||
private static final long serialVersionUID = -1752497262936740164L; | ||
|
||
@Schema(description = "告警ID") | ||
private String recordId; | ||
|
||
@Schema(description = "是否重复告警") | ||
private boolean alarming; | ||
|
||
@Schema(description = "当前首次触发") | ||
private boolean firstAlarm; | ||
|
||
@Schema(description = "上一次告警时间") | ||
private long lastAlarmTime; | ||
|
||
@Schema(description = "首次告警或者解除告警后的再一次告警时间") | ||
private long alarmTime; | ||
} |
29 changes: 29 additions & 0 deletions
29
.../common-component/src/main/java/org/jetlinks/community/command/rule/data/RelieveInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.jetlinks.community.command.rule.data; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
/** | ||
* 解除告警参数 | ||
*/ | ||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class RelieveInfo extends AlarmInfo{ | ||
|
||
@Schema(description = "解除原因") | ||
private String relieveReason; | ||
|
||
@Schema(description = "解除说明") | ||
private String describe; | ||
|
||
/** | ||
* 告警解除类型,人工(user)、系统(system)等 | ||
*/ | ||
@Schema(description = "告警解除类型") | ||
private String alarmRelieveType; | ||
} |
32 changes: 32 additions & 0 deletions
32
...ommon-component/src/main/java/org/jetlinks/community/command/rule/data/RelieveResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.jetlinks.community.command.rule.data; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
/** | ||
* 解除警告结果 | ||
*/ | ||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class RelieveResult extends AlarmResult{ | ||
|
||
@Schema(description = "告警级别") | ||
private int level; | ||
|
||
@Schema(description = "告警原因描述") | ||
private String actualDesc; | ||
|
||
@Schema(description = "解除原因") | ||
private String relieveReason; | ||
|
||
@Schema(description = "解除时间") | ||
private long relieveTime; | ||
|
||
@Schema(description = "解除说明") | ||
private String describe; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...-component/src/main/java/org/jetlinks/community/dictionary/DatabaseDictionaryManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package org.jetlinks.community.dictionary; | ||
|
||
import lombok.AllArgsConstructor; | ||
import org.apache.commons.collections4.MapUtils; | ||
import org.hswebframework.web.dict.EnumDict; | ||
import org.hswebframework.web.dictionary.entity.DictionaryItemEntity; | ||
import org.hswebframework.web.dictionary.service.DefaultDictionaryItemService; | ||
import org.springframework.boot.CommandLineRunner; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.*; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** | ||
* @author bestfeng | ||
*/ | ||
@AllArgsConstructor | ||
public class DatabaseDictionaryManager implements DictionaryManager, CommandLineRunner{ | ||
|
||
private final DefaultDictionaryItemService dictionaryItemService; | ||
|
||
private final Map<String, Map<String, DictionaryItemEntity>> itemStore = new ConcurrentHashMap<>(); | ||
|
||
@Nonnull | ||
@Override | ||
public List<EnumDict<?>> getItems(@Nonnull String dictId) { | ||
Map<String, DictionaryItemEntity> itemEntityMap = itemStore.get(dictId); | ||
if (MapUtils.isEmpty(itemEntityMap)) { | ||
return Collections.emptyList(); | ||
} | ||
return new ArrayList<>(itemEntityMap.values()); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public Optional<EnumDict<?>> getItem(@Nonnull String dictId, @Nonnull String itemId) { | ||
Map<String, DictionaryItemEntity> itemEntityMap = itemStore.get(dictId); | ||
if (itemEntityMap == null) { | ||
return Optional.empty(); | ||
} | ||
return Optional.ofNullable(itemEntityMap.get(itemId)); | ||
} | ||
|
||
|
||
public void registerItems(List<DictionaryItemEntity> items) { | ||
items.forEach(this::registerItem); | ||
} | ||
|
||
|
||
public void removeItems(List<DictionaryItemEntity> items) { | ||
items.forEach(this::removeItem); | ||
} | ||
|
||
|
||
public void removeItem(DictionaryItemEntity item) { | ||
if (item == null || item.getDictId() == null || item.getId() == null) { | ||
return; | ||
} | ||
itemStore.compute(item.getDictId(), (k, v) -> { | ||
if (v != null) { | ||
v.remove(item.getId()); | ||
if (!v.isEmpty()) { | ||
return v; | ||
} | ||
} | ||
return null; | ||
}); | ||
} | ||
|
||
|
||
public void registerItem(DictionaryItemEntity item) { | ||
if (item == null || item.getDictId() == null) { | ||
return; | ||
} | ||
itemStore | ||
.computeIfAbsent(item.getDictId(), k -> new ConcurrentHashMap<>()) | ||
.put(item.getId(), item); | ||
} | ||
|
||
@Override | ||
public void run(String... args) throws Exception { | ||
dictionaryItemService | ||
.createQuery() | ||
.fetch() | ||
.doOnNext(this::registerItem) | ||
.subscribe(); | ||
} | ||
} |
Oops, something went wrong.