Skip to content

Commit

Permalink
refactor(告警历史): 修改初始化告警历史元数据的方式
Browse files Browse the repository at this point in the history
  • Loading branch information
PengyuDeng committed Nov 19, 2024
1 parent d2772e8 commit 483296e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public SceneTaskExecutorProvider sceneTaskExecutorProvider(EventBus eventBus,
@ConditionalOnClass(ElasticSearchService.class)
static class ElasticSearchAlarmHistoryConfiguration {

@Bean(initMethod = "init")
@Bean
public ElasticSearchAlarmHistoryService alarmHistoryService(ElasticSearchService elasticSearchService,
ElasticSearchIndexManager indexManager) {
return new ElasticSearchAlarmHistoryService(indexManager, elasticSearchService);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,60 @@
package org.jetlinks.community.rule.engine.service;

import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.hswebframework.ezorm.core.param.QueryParam;
import org.hswebframework.web.api.crud.entity.PagerResult;
import org.hswebframework.web.bean.FastBeanCopier;
import org.jetlinks.core.metadata.types.ArrayType;
import org.jetlinks.core.metadata.types.DateTimeType;
import org.jetlinks.core.metadata.types.IntType;
import org.jetlinks.core.metadata.types.StringType;
import org.jetlinks.community.PropertyConstants;
import org.jetlinks.community.elastic.search.index.DefaultElasticSearchIndexMetadata;
import org.jetlinks.community.elastic.search.index.ElasticSearchIndexManager;
import org.jetlinks.community.elastic.search.service.ElasticSearchService;
import org.jetlinks.community.rule.engine.entity.AlarmHistoryInfo;
import org.jetlinks.core.metadata.types.ArrayType;
import org.jetlinks.core.metadata.types.DateTimeType;
import org.jetlinks.core.metadata.types.IntType;
import org.jetlinks.core.metadata.types.StringType;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.Duration;
import java.util.HashMap;
import java.util.Map;

/**
* @author bestfeng
*/
@AllArgsConstructor
public class ElasticSearchAlarmHistoryService implements AlarmHistoryService {


public final static String ALARM_HISTORY_INDEX = "alarm_history";

private final ElasticSearchIndexManager indexManager;

private final ElasticSearchService elasticSearchService;

public ElasticSearchAlarmHistoryService(ElasticSearchIndexManager indexManager, ElasticSearchService elasticSearchService) {
this.elasticSearchService = elasticSearchService;
indexManager.putIndex(
new DefaultElasticSearchIndexMetadata(ALARM_HISTORY_INDEX)
.addProperty("id", StringType.GLOBAL)
.addProperty("alarmConfigId", StringType.GLOBAL)
.addProperty("alarmConfigName", StringType.GLOBAL)
.addProperty("alarmRecordId", StringType.GLOBAL)
.addProperty("level", IntType.GLOBAL)
.addProperty("description", StringType.GLOBAL)
.addProperty("alarmTime", DateTimeType.GLOBAL)
.addProperty("targetType", StringType.GLOBAL)
.addProperty("targetName", StringType.GLOBAL)
.addProperty("targetId", StringType.GLOBAL)
.addProperty("sourceType", StringType.GLOBAL)
.addProperty("sourceName", StringType.GLOBAL)
.addProperty("sourceId", StringType.GLOBAL)
.addProperty("alarmInfo", StringType.GLOBAL)
.addProperty("creatorId", StringType.GLOBAL)
.addProperty("termSpec", StringType.GLOBAL)
.addProperty("triggerDesc", StringType.GLOBAL)
.addProperty("actualDesc", StringType.GLOBAL)
.addProperty("alarmConfigSource", StringType.GLOBAL)
.addProperty("bindings", new ArrayType().elementType(StringType.GLOBAL))
).subscribe();
}


public Mono<PagerResult<AlarmHistoryInfo>> queryPager(QueryParam queryParam) {
return elasticSearchService.queryPager(ALARM_HISTORY_INDEX, queryParam, AlarmHistoryInfo.class);
Expand All @@ -60,31 +80,4 @@ private Map<String, Object> createData(AlarmHistoryInfo info) {
return data;
}

public void init() {
indexManager.putIndex(
new DefaultElasticSearchIndexMetadata(ALARM_HISTORY_INDEX)
.addProperty("id", StringType.GLOBAL)
.addProperty("alarmConfigId", StringType.GLOBAL)
.addProperty("alarmConfigName", StringType.GLOBAL)
.addProperty("alarmRecordId", StringType.GLOBAL)
.addProperty("level", IntType.GLOBAL)
.addProperty("description", StringType.GLOBAL)
.addProperty("alarmTime", DateTimeType.GLOBAL)
.addProperty("targetType", StringType.GLOBAL)
.addProperty("targetName", StringType.GLOBAL)
.addProperty("targetId", StringType.GLOBAL)

.addProperty("sourceType", StringType.GLOBAL)
.addProperty("sourceName", StringType.GLOBAL)
.addProperty("sourceId", StringType.GLOBAL)

.addProperty("alarmInfo", StringType.GLOBAL)
.addProperty("creatorId", StringType.GLOBAL)
.addProperty("termSpec", StringType.GLOBAL)
.addProperty("triggerDesc", StringType.GLOBAL)
.addProperty("actualDesc", StringType.GLOBAL)
.addProperty("alarmConfigSource", StringType.GLOBAL)
.addProperty("bindings", new ArrayType().elementType(StringType.GLOBAL))
).block(Duration.ofSeconds(10));
}
}

0 comments on commit 483296e

Please sign in to comment.