Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(告警历史): 修改初始化告警历史元数据的方式 #585

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

失败后无法感知,可能会导致后续数据写入错误。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.doOnError()?

}


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));
}
}
Loading