Skip to content

Commit

Permalink
Merge branch 'master' into build-release-2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zhou-hao authored Aug 21, 2024
2 parents 1a0cb60 + f754740 commit a6dd94d
Show file tree
Hide file tree
Showing 82 changed files with 3,774 additions and 718 deletions.
11 changes: 11 additions & 0 deletions jetlinks-components/common-component/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@
<artifactId>h2-mvstore</artifactId>
</dependency>

<dependency>
<groupId>org.jetlinks.sdk</groupId>
<artifactId>jetlinks-sdk-api</artifactId>
<version>${jetlinks.sdk.version}</version>
</dependency>

<dependency>
<groupId>org.hswebframework.web</groupId>
<artifactId>hsweb-system-dictionary</artifactId>
</dependency>

<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
Expand Down
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;
}
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;
}
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;
}
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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@
import com.alibaba.fastjson.JSON;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import lombok.Generated;
import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.beanutils.Converter;
import org.hswebframework.ezorm.rdb.mapping.ReactiveRepository;
import org.hswebframework.web.api.crud.entity.EntityFactory;
import org.hswebframework.web.bean.FastBeanCopier;
import org.hswebframework.web.cache.ReactiveCacheManager;
import org.hswebframework.web.dict.EnumDict;
import org.hswebframework.web.dict.defaults.DefaultItemDefine;
import org.jetlinks.community.Interval;
import org.jetlinks.community.JvmErrorException;
import org.jetlinks.community.config.ConfigManager;
import org.jetlinks.community.config.ConfigScopeCustomizer;
import org.jetlinks.community.config.ConfigScopeProperties;
import org.jetlinks.community.config.SimpleConfigManager;
import org.jetlinks.community.config.entity.ConfigEntity;
import org.jetlinks.community.dictionary.DictionaryJsonDeserializer;
import org.jetlinks.community.reference.DataReferenceManager;
import org.jetlinks.community.reference.DataReferenceProvider;
import org.jetlinks.community.reference.DefaultDataReferenceManager;
Expand All @@ -26,6 +31,7 @@
import org.jetlinks.community.service.DefaultUserBindService;
import org.jetlinks.community.utils.TimeUtils;
import org.jetlinks.core.event.EventBus;
import org.jetlinks.core.metadata.DataType;
import org.jetlinks.core.rpc.RpcManager;
import org.jetlinks.reactor.ql.feature.Feature;
import org.jetlinks.reactor.ql.supports.DefaultReactorQLMetadata;
Expand All @@ -47,6 +53,10 @@

import javax.annotation.Nonnull;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Date;

Expand Down Expand Up @@ -123,6 +133,22 @@ public <T> T convert(Class<T> type, Object value) {
}
}, Long.class);

BeanUtilsBean.getInstance().getConvertUtils().register(new Converter() {
@Override
@Generated
public <T> T convert(Class<T> type, Object value) {

if (value instanceof String) {
return (T) DefaultItemDefine.builder()
.value(String.valueOf(value))
.build();
}

return (T) FastBeanCopier.copy(value, new DefaultItemDefine());

}
}, EnumDict.class);

//捕获jvm错误,防止Flux被挂起
Hooks.onOperatorError((err, val) -> {
if (Exceptions.isJvmFatal(err)) {
Expand Down Expand Up @@ -155,6 +181,7 @@ public Object postProcessAfterInitialization(@Nonnull Object bean, @Nonnull Stri
public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer(){
return builder->{
builder.deserializerByType(Date.class,new SmartDateDeserializer());
builder.deserializerByType(EnumDict.class, new DictionaryJsonDeserializer());
};
}

Expand Down Expand Up @@ -196,7 +223,7 @@ public DataReferenceManager dataReferenceManager(ObjectProvider<DataReferencePro
return referenceManager;
}

@AutoConfiguration
@Configuration
@ConditionalOnClass(ReactiveRedisOperations.class)
static class DefaultUserBindServiceConfiguration {
@Bean
Expand Down
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();
}
}
Loading

0 comments on commit a6dd94d

Please sign in to comment.