mirror of
https://gitee.com/dromara/easy-es.git
synced 2025-12-07 01:28:37 +08:00
feat: 索引策略迁移到core中实现,在容器中使用只需要注册bean即可
This commit is contained in:
parent
8176c53a78
commit
cf3faf0417
@ -1,24 +1,12 @@
|
|||||||
package org.dromara.easyes.starter;
|
package org.dromara.easyes.starter;
|
||||||
|
|
||||||
import org.apache.http.HttpHost;
|
|
||||||
import org.apache.http.auth.AuthScope;
|
|
||||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
|
||||||
import org.apache.http.client.CredentialsProvider;
|
|
||||||
import org.apache.http.conn.ssl.NoopHostnameVerifier;
|
|
||||||
import org.apache.http.conn.ssl.TrustStrategy;
|
|
||||||
import org.apache.http.impl.client.BasicCredentialsProvider;
|
|
||||||
import org.apache.http.nio.conn.ssl.SSLIOSessionStrategy;
|
|
||||||
import org.apache.http.ssl.SSLContextBuilder;
|
|
||||||
import org.dromara.easyes.common.enums.SchemaEnum;
|
|
||||||
import org.dromara.easyes.common.utils.*;
|
import org.dromara.easyes.common.utils.*;
|
||||||
import org.dromara.easyes.core.service.AutoProcessIndexService;
|
import org.dromara.easyes.common.strategy.AutoProcessIndexStrategy;
|
||||||
|
import org.dromara.easyes.core.index.AutoProcessIndexNotSmoothlyStrategy;
|
||||||
|
import org.dromara.easyes.core.index.AutoProcessIndexSmoothlyStrategy;
|
||||||
import org.dromara.easyes.spring.factory.IndexStrategyFactory;
|
import org.dromara.easyes.spring.factory.IndexStrategyFactory;
|
||||||
import org.dromara.easyes.spring.index.AutoProcessIndexNotSmoothlyServiceImpl;
|
|
||||||
import org.dromara.easyes.spring.index.AutoProcessIndexSmoothlyServiceImpl;
|
|
||||||
import org.dromara.easyes.common.property.EasyEsDynamicProperties;
|
import org.dromara.easyes.common.property.EasyEsDynamicProperties;
|
||||||
import org.dromara.easyes.common.property.EasyEsProperties;
|
import org.dromara.easyes.common.property.EasyEsProperties;
|
||||||
import org.elasticsearch.client.RestClient;
|
|
||||||
import org.elasticsearch.client.RestClientBuilder;
|
|
||||||
import org.elasticsearch.client.RestHighLevelClient;
|
import org.elasticsearch.client.RestHighLevelClient;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||||
@ -28,11 +16,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
|||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
import javax.net.ssl.SSLContext;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import static org.dromara.easyes.common.constants.BaseEsConstants.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* es自动配置
|
* es自动配置
|
||||||
* <p>
|
* <p>
|
||||||
@ -72,14 +55,19 @@ public class EsAutoConfiguration {
|
|||||||
return new IndexStrategyFactory();
|
return new IndexStrategyFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 索引
|
||||||
|
* @return {@link AutoProcessIndexStrategy}
|
||||||
|
* @author MoJie
|
||||||
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public AutoProcessIndexService autoProcessIndexSmoothlyServiceImpl() {
|
public AutoProcessIndexStrategy autoProcessIndexSmoothlyStrategy() {
|
||||||
return new AutoProcessIndexSmoothlyServiceImpl();
|
return new AutoProcessIndexSmoothlyStrategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public AutoProcessIndexService autoProcessIndexNotSmoothlyServiceImpl() {
|
public AutoProcessIndexStrategy autoProcessIndexNotSmoothlyStrategy() {
|
||||||
return new AutoProcessIndexNotSmoothlyServiceImpl();
|
return new AutoProcessIndexNotSmoothlyStrategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,74 +0,0 @@
|
|||||||
package org.dromara.easyes.starter.config;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import org.dromara.easyes.common.enums.SchemaEnum;
|
|
||||||
import org.dromara.easyes.common.property.GlobalConfig;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.boot.context.properties.NestedConfigurationProperty;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* easy-es基础配置项
|
|
||||||
* <p>
|
|
||||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
|
||||||
**/
|
|
||||||
@Data
|
|
||||||
@ConfigurationProperties(value = "easy-es")
|
|
||||||
@ConditionalOnExpression("'${easy-es.address:x}'!='x'")
|
|
||||||
@ConditionalOnProperty(prefix = "easy-es", name = {"enable"}, havingValue = "true", matchIfMissing = true)
|
|
||||||
public class EasyEsConfigProperties {
|
|
||||||
/**
|
|
||||||
* 是否开启easy-es 默认开启
|
|
||||||
*/
|
|
||||||
private boolean enable = true;
|
|
||||||
/**
|
|
||||||
* 是否开启easy-es LOGO BANNER的打印
|
|
||||||
*/
|
|
||||||
private boolean banner = true;
|
|
||||||
/**
|
|
||||||
* es client address es客户端地址
|
|
||||||
*/
|
|
||||||
private String address = "127.0.0.1:9200";
|
|
||||||
/**
|
|
||||||
* schema 模式
|
|
||||||
*/
|
|
||||||
private String schema = SchemaEnum.http.name();
|
|
||||||
/**
|
|
||||||
* username of es 用户名,可缺省
|
|
||||||
*/
|
|
||||||
private String username;
|
|
||||||
/**
|
|
||||||
* password of es 密码,可缺省
|
|
||||||
*/
|
|
||||||
private String password;
|
|
||||||
/**
|
|
||||||
* maxConnectTotal 最大连接数
|
|
||||||
*/
|
|
||||||
private Integer maxConnTotal;
|
|
||||||
/**
|
|
||||||
* maxConnectPerRoute 最大连接路由数
|
|
||||||
*/
|
|
||||||
private Integer maxConnPerRoute;
|
|
||||||
/**
|
|
||||||
* connectTimeout timeUnit:millis 连接超时时间 单位毫秒
|
|
||||||
*/
|
|
||||||
private Integer connectTimeout;
|
|
||||||
/**
|
|
||||||
* socketTimeout timeUnit:millis 通讯超时时间 单位毫秒 默认10分钟 以免小白踩坑平滑模式下数据量过大迁移超时失败
|
|
||||||
*/
|
|
||||||
private Integer socketTimeout = 600000;
|
|
||||||
/***
|
|
||||||
* 保持心跳时间 timeUnit:millis 单位毫秒 默认30秒 防止小白白出现服务首次调用不成时不知所措
|
|
||||||
*/
|
|
||||||
private Integer keepAliveMillis = 30000;
|
|
||||||
/**
|
|
||||||
* connectionRequestTimeout timeUnit:millis 连接请求超时时间 单位毫秒
|
|
||||||
*/
|
|
||||||
private Integer connectionRequestTimeout;
|
|
||||||
/**
|
|
||||||
* global config 全局配置
|
|
||||||
*/
|
|
||||||
@NestedConfigurationProperty
|
|
||||||
private GlobalConfig globalConfig = new GlobalConfig();
|
|
||||||
}
|
|
||||||
@ -0,0 +1,170 @@
|
|||||||
|
{
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"defaultValue": true,
|
||||||
|
"name": "easy-es.enable",
|
||||||
|
"description": "是否开启easy-es 默认开启.",
|
||||||
|
"type": "java.lang.Boolean"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"defaultValue": true,
|
||||||
|
"name": "easy-es.banner",
|
||||||
|
"description": "是否开启easy-es LOGO BANNER的打印.",
|
||||||
|
"type": "java.lang.Boolean"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"defaultValue": "127.0.0.1:9200",
|
||||||
|
"name": "easy-es.address",
|
||||||
|
"description": "es client address es客户端地址.",
|
||||||
|
"type": "java.lang.String"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"defaultValue": "http",
|
||||||
|
"name": "easy-es.schema",
|
||||||
|
"description": "schema 模式.",
|
||||||
|
"type": "java.lang.String"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "easy-es.username",
|
||||||
|
"description": "username of es 用户名,可缺省.",
|
||||||
|
"type": "java.lang.String"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "easy-es.password",
|
||||||
|
"description": "password of es 密码,可缺省.",
|
||||||
|
"type": "java.lang.String"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "easy-es.max-conn-total",
|
||||||
|
"description": "maxConnectTotal 最大连接数.",
|
||||||
|
"type": "java.lang.Integer"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "easy-es.connect-timeout",
|
||||||
|
"description": "connectTimeout timeUnit:millis 连接超时时间 单位毫秒.",
|
||||||
|
"type": "java.lang.Integer"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"defaultValue": 600000,
|
||||||
|
"name": "easy-es.socket-timeout",
|
||||||
|
"description": "socketTimeout timeUnit:millis 通讯超时时间 单位毫秒 默认10分钟 以免小白踩坑平滑模式下数据量过大迁移超时失败.",
|
||||||
|
"type": "java.lang.Integer"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"defaultValue": 30000,
|
||||||
|
"name": "easy-es.keep-alive-millis",
|
||||||
|
"description": "保持心跳时间 timeUnit:millis 单位毫秒 默认30秒 防止小白白出现服务首次调用不成时不知所措.",
|
||||||
|
"type": "java.lang.Integer"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "easy-es.connection-request-timeout",
|
||||||
|
"description": "connectionRequestTimeout timeUnit:millis 连接请求超时时间 单位毫秒.",
|
||||||
|
"type": "java.lang.Integer"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"defaultValue": true,
|
||||||
|
"name": "easy-es.global-config.print-dsl",
|
||||||
|
"description": "whether to print dsl log 是否打印执行的dsl语句.",
|
||||||
|
"type": "java.lang.Boolean"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "easy-es.global-config.i-kun-mode",
|
||||||
|
"description": "for fun, whether to print love chinese `kung fu` mode 是否开启爱坤(小黑子)模式 开启后日志将进入疯狂状态, 后期也会在此特殊模式下提供更多趣味化及傻瓜功能 让编码不仅简单,还有趣!.",
|
||||||
|
"type": "java.lang.Boolean"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"defaultValue": "MANUAL",
|
||||||
|
"name": "easy-es.global-config.process-index-mode",
|
||||||
|
"description": "process index mode Manual by default 索引处理模式 默认开启手动模式.",
|
||||||
|
"type": "org.dromara.easyes.common.enums.ProcessIndexStrategyEnum"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"defaultValue": 72,
|
||||||
|
"name": "easy-es.global-config.reindex-time-out-hours",
|
||||||
|
"description": "Rebuild index timeout unit: hour, default: 72 重建索引超时时间 单位小时,默认72.",
|
||||||
|
"type": "java.lang.Integer"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"defaultValue": 72,
|
||||||
|
"name": "easy-es.global-config.async-process-index-blocking",
|
||||||
|
"description": "process index blocking main thread true by default 异步处理索引是否阻塞主线程 默认阻塞.",
|
||||||
|
"type": "java.lang.Integer"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"defaultValue": true,
|
||||||
|
"name": "easy-es.global-config.distributed",
|
||||||
|
"description": "is distributed environment true by default 是否分布式环境 默认为是.",
|
||||||
|
"type": "java.lang.Boolean"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"defaultValue": 4320,
|
||||||
|
"name": "easy-es.global-config.active-release-index-max-retry",
|
||||||
|
"description": "Activate the current client's release index maximum number of retries 分布式环境下,平滑模式,当前客户端激活最新索引最大重试次数,若数据量过大,重建索引数据迁移时间超过4320/60=72H,可调大此参数值,此参数值决定最大重试次数,超出此次数后仍未成功,则终止重试并记录异常日志.",
|
||||||
|
"type": "java.lang.Integer"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"defaultValue": 60,
|
||||||
|
"name": "easy-es.global-config.active-release-index-fixed-delay",
|
||||||
|
"description": "Activate the current client's release index retry delay for a fixed time uint:second 分布式环境下,平滑模式,当前客户端激活最新索引重试时间间隔 若您期望最终一致性的时效性更高,可调小此值,但会牺牲一些性能.",
|
||||||
|
"type": "java.lang.Integer"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"defaultValue": "",
|
||||||
|
"name": "easy-es.global-config.db-config.index-prefix",
|
||||||
|
"description": "index prefix eg:daily_, 索引前缀 可缺省.",
|
||||||
|
"type": "java.lang.String"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "easy-es.global-config.db-config.map-underscore-to-camel-case",
|
||||||
|
"description": "enable underscore to camel case default false 是否开启下划线自动转驼峰 默认关闭.",
|
||||||
|
"type": "java.lang.Boolean"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"defaultValue": "none",
|
||||||
|
"name": "easy-es.global-config.db-config.id-type",
|
||||||
|
"description": "es id generate type. es id生成类型 默认由es自动生成.",
|
||||||
|
"type": "org.dromara.easyes.annotation.rely.IdType"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"defaultValue": "not_null",
|
||||||
|
"name": "easy-es.global-config.db-config.field-strategy",
|
||||||
|
"description": "Field update strategy default nonNull 字段更新策略,默认非null.",
|
||||||
|
"type": "org.dromara.easyes.annotation.rely.FieldStrategy"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"defaultValue": true,
|
||||||
|
"name": "easy-es.global-config.db-config.enable-track-total-hits",
|
||||||
|
"description": "enableTrackTotalHits default true,是否开启查询全部数据 默认开启.",
|
||||||
|
"type": "java.lang.Boolean"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"defaultValue": "none",
|
||||||
|
"name": "easy-es.global-config.db-config.refresh-policy",
|
||||||
|
"description": "data refresh policy 数据刷新策略,es默认的数据刷新策略为NONE.",
|
||||||
|
"type": "org.dromara.easyes.annotation.rely.RefreshPolicy"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"defaultValue": 10000,
|
||||||
|
"name": "easy-es.global-config.db-config.batchUpdate-threshold",
|
||||||
|
"description": "Batch update threshold 10000 by default 批量更新阈值 默认值为1万.",
|
||||||
|
"type": "java.lang.Integer"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"defaultValue": false,
|
||||||
|
"name": "easy-es.global-config.db-config.enable-agg-hits",
|
||||||
|
"description": "Batch update threshold 10000 by default 批量更新阈值 默认值为1万.",
|
||||||
|
"type": "java.lang.Boolean"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"defaultValue": true,
|
||||||
|
"name": "easy-es.global-config.db-config.smart-add-keyword-suffix",
|
||||||
|
"description": "Whether to intelligently add the. keyword suffix to the field. This configuration is enabled by default. The field type is KEYWORD only for annotation configuration_ The String field of TEXT or unconfigured type takes effect and only takes effect when the query requires that the field be of keyword type, so it is called smart! 是否智能为字段添加.keyword后缀 默认开启 此配置仅对注解配置字段类型为KEYWORD_TEXT或未配置类型的String字段生效,并且只会在查询要求该字段必须为keyword类型的查询中才生效,因此谓之智能!.",
|
||||||
|
"type": "java.lang.Boolean"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "easy-es.dynamic",
|
||||||
|
"description": "Whether to intelligently add the. keyword suffix to the field. This configuration is enabled by default. The field type is KEYWORD only for annotation configuration_ The String field of TEXT or unconfigured type takes effect and only takes effect when the query requires that the field be of keyword type, so it is called smart! 是否智能为字段添加.keyword后缀 默认开启 此配置仅对注解配置字段类型为KEYWORD_TEXT或未配置类型的String字段生效,并且只会在查询要求该字段必须为keyword类型的查询中才生效,因此谓之智能!.",
|
||||||
|
"type": "java.util.Map<java.lang.String, org.dromara.easyes.common.property.EasyEsProperties>"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -23,5 +23,5 @@ public enum ProcessIndexStrategyEnum {
|
|||||||
*/
|
*/
|
||||||
MANUAL(3);
|
MANUAL(3);
|
||||||
@Getter
|
@Getter
|
||||||
private Integer strategyType;
|
private final Integer strategyType;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
package org.dromara.easyes.core.service;
|
package org.dromara.easyes.common.strategy;
|
||||||
|
|
||||||
import org.elasticsearch.client.RestHighLevelClient;
|
import org.elasticsearch.client.RestHighLevelClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自动托管索引接口
|
* 自动托管索引策略接口
|
||||||
* <p>
|
* <p>
|
||||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||||
**/
|
**/
|
||||||
public interface AutoProcessIndexService {
|
public interface AutoProcessIndexStrategy {
|
||||||
/**
|
/**
|
||||||
* 获取当前策略类型
|
* 获取当前策略类型
|
||||||
*
|
*
|
||||||
@ -1,11 +1,11 @@
|
|||||||
package org.dromara.easyes.spring.index;
|
package org.dromara.easyes.core.index;
|
||||||
|
|
||||||
import org.dromara.easyes.common.enums.ProcessIndexStrategyEnum;
|
import org.dromara.easyes.common.enums.ProcessIndexStrategyEnum;
|
||||||
|
import org.dromara.easyes.common.strategy.AutoProcessIndexStrategy;
|
||||||
import org.dromara.easyes.common.utils.LogUtils;
|
import org.dromara.easyes.common.utils.LogUtils;
|
||||||
import org.dromara.easyes.core.biz.CreateIndexParam;
|
import org.dromara.easyes.core.biz.CreateIndexParam;
|
||||||
import org.dromara.easyes.core.biz.EntityInfo;
|
import org.dromara.easyes.core.biz.EntityInfo;
|
||||||
import org.dromara.easyes.core.biz.EsIndexInfo;
|
import org.dromara.easyes.core.biz.EsIndexInfo;
|
||||||
import org.dromara.easyes.core.service.AutoProcessIndexService;
|
|
||||||
import org.dromara.easyes.core.toolkit.EntityInfoHelper;
|
import org.dromara.easyes.core.toolkit.EntityInfoHelper;
|
||||||
import org.dromara.easyes.core.toolkit.IndexUtils;
|
import org.dromara.easyes.core.toolkit.IndexUtils;
|
||||||
import org.elasticsearch.client.RestHighLevelClient;
|
import org.elasticsearch.client.RestHighLevelClient;
|
||||||
@ -15,7 +15,7 @@ import org.elasticsearch.client.RestHighLevelClient;
|
|||||||
* <p>
|
* <p>
|
||||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||||
**/
|
**/
|
||||||
public class AutoProcessIndexNotSmoothlyServiceImpl implements AutoProcessIndexService {
|
public class AutoProcessIndexNotSmoothlyStrategy implements AutoProcessIndexStrategy {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer getStrategyType() {
|
public Integer getStrategyType() {
|
||||||
@ -1,11 +1,11 @@
|
|||||||
package org.dromara.easyes.spring.index;
|
package org.dromara.easyes.core.index;
|
||||||
|
|
||||||
import org.dromara.easyes.common.enums.ProcessIndexStrategyEnum;
|
import org.dromara.easyes.common.enums.ProcessIndexStrategyEnum;
|
||||||
|
import org.dromara.easyes.common.strategy.AutoProcessIndexStrategy;
|
||||||
import org.dromara.easyes.common.utils.LogUtils;
|
import org.dromara.easyes.common.utils.LogUtils;
|
||||||
import org.dromara.easyes.core.biz.CreateIndexParam;
|
import org.dromara.easyes.core.biz.CreateIndexParam;
|
||||||
import org.dromara.easyes.core.biz.EntityInfo;
|
import org.dromara.easyes.core.biz.EntityInfo;
|
||||||
import org.dromara.easyes.core.biz.EsIndexInfo;
|
import org.dromara.easyes.core.biz.EsIndexInfo;
|
||||||
import org.dromara.easyes.core.service.AutoProcessIndexService;
|
|
||||||
import org.dromara.easyes.core.toolkit.EntityInfoHelper;
|
import org.dromara.easyes.core.toolkit.EntityInfoHelper;
|
||||||
import org.dromara.easyes.core.toolkit.IndexUtils;
|
import org.dromara.easyes.core.toolkit.IndexUtils;
|
||||||
import org.elasticsearch.client.RestHighLevelClient;
|
import org.elasticsearch.client.RestHighLevelClient;
|
||||||
@ -18,7 +18,8 @@ import static org.dromara.easyes.common.constants.BaseEsConstants.SO_SUFFIX;
|
|||||||
* <p>
|
* <p>
|
||||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
* Copyright © 2022 xpc1024 All Rights Reserved
|
||||||
**/
|
**/
|
||||||
public class AutoProcessIndexSmoothlyServiceImpl implements AutoProcessIndexService {
|
public class AutoProcessIndexSmoothlyStrategy implements AutoProcessIndexStrategy {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer getStrategyType() {
|
public Integer getStrategyType() {
|
||||||
return ProcessIndexStrategyEnum.SMOOTHLY.getStrategyType();
|
return ProcessIndexStrategyEnum.SMOOTHLY.getStrategyType();
|
||||||
@ -2,15 +2,11 @@ package org.dromara.easyes.solon;
|
|||||||
|
|
||||||
import org.dromara.easyes.common.constants.BaseEsConstants;
|
import org.dromara.easyes.common.constants.BaseEsConstants;
|
||||||
import org.dromara.easyes.common.utils.LogUtils;
|
import org.dromara.easyes.common.utils.LogUtils;
|
||||||
import org.dromara.easyes.solon.config.DynamicEsProperties;
|
|
||||||
import org.dromara.easyes.solon.config.EasyEsConfigProperties;
|
|
||||||
import org.dromara.easyes.solon.config.EsAutoConfiguration;
|
import org.dromara.easyes.solon.config.EsAutoConfiguration;
|
||||||
import org.dromara.easyes.solon.config.GeneratorConfiguration;
|
import org.dromara.easyes.solon.config.GeneratorConfiguration;
|
||||||
import org.dromara.easyes.solon.factory.IndexStrategyFactory;
|
import org.dromara.easyes.solon.factory.IndexStrategyFactory;
|
||||||
import org.dromara.easyes.solon.register.EsMapperScan;
|
import org.dromara.easyes.solon.register.EsMapperScan;
|
||||||
import org.dromara.easyes.solon.register.MapperScannerRegister;
|
import org.dromara.easyes.solon.register.MapperScannerRegister;
|
||||||
import org.dromara.easyes.solon.service.impl.AutoProcessIndexNotSmoothlyServiceImpl;
|
|
||||||
import org.dromara.easyes.solon.service.impl.AutoProcessIndexSmoothlyServiceImpl;
|
|
||||||
import org.noear.solon.core.AppContext;
|
import org.noear.solon.core.AppContext;
|
||||||
import org.noear.solon.core.Plugin;
|
import org.noear.solon.core.Plugin;
|
||||||
|
|
||||||
@ -28,14 +24,9 @@ public class XPluginImp implements Plugin {
|
|||||||
LogUtils.info("===> Easy-Es is not enabled");
|
LogUtils.info("===> Easy-Es is not enabled");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Object dynamicEsProperties = context.cfg().getOrDefault("easy-es.dynamic", new DynamicEsProperties());
|
|
||||||
context.wrapAndPut(DynamicEsProperties.class, dynamicEsProperties);
|
|
||||||
context.beanMake(EasyEsConfigProperties.class);
|
|
||||||
context.beanMake(EsAutoConfiguration.class);
|
context.beanMake(EsAutoConfiguration.class);
|
||||||
context.beanMake(GeneratorConfiguration.class);
|
context.beanMake(GeneratorConfiguration.class);
|
||||||
context.beanMake(IndexStrategyFactory.class);
|
context.beanMake(IndexStrategyFactory.class);
|
||||||
context.beanMake(AutoProcessIndexSmoothlyServiceImpl.class);
|
|
||||||
context.beanMake(AutoProcessIndexNotSmoothlyServiceImpl.class);
|
|
||||||
// 扫描EsMapperScan的包并注册到容器
|
// 扫描EsMapperScan的包并注册到容器
|
||||||
context.beanBuilderAdd(EsMapperScan.class, new MapperScannerRegister(context));
|
context.beanBuilderAdd(EsMapperScan.class, new MapperScannerRegister(context));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,10 @@ package org.dromara.easyes.solon.config;
|
|||||||
|
|
||||||
import org.dromara.easyes.common.property.EasyEsDynamicProperties;
|
import org.dromara.easyes.common.property.EasyEsDynamicProperties;
|
||||||
import org.dromara.easyes.common.property.EasyEsProperties;
|
import org.dromara.easyes.common.property.EasyEsProperties;
|
||||||
|
import org.dromara.easyes.common.strategy.AutoProcessIndexStrategy;
|
||||||
import org.dromara.easyes.common.utils.*;
|
import org.dromara.easyes.common.utils.*;
|
||||||
|
import org.dromara.easyes.core.index.AutoProcessIndexNotSmoothlyStrategy;
|
||||||
|
import org.dromara.easyes.core.index.AutoProcessIndexSmoothlyStrategy;
|
||||||
import org.elasticsearch.client.RestHighLevelClient;
|
import org.elasticsearch.client.RestHighLevelClient;
|
||||||
import org.noear.solon.annotation.Bean;
|
import org.noear.solon.annotation.Bean;
|
||||||
import org.noear.solon.annotation.Condition;
|
import org.noear.solon.annotation.Condition;
|
||||||
@ -60,4 +63,14 @@ public class EsAutoConfiguration {
|
|||||||
return restHighLevelClientUtils;
|
return restHighLevelClientUtils;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public AutoProcessIndexStrategy autoProcessIndexSmoothlyStrategy() {
|
||||||
|
return new AutoProcessIndexSmoothlyStrategy();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public AutoProcessIndexStrategy autoProcessIndexNotSmoothlyStrategy() {
|
||||||
|
return new AutoProcessIndexNotSmoothlyStrategy();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@ package org.dromara.easyes.solon.factory;
|
|||||||
import org.dromara.easyes.common.enums.ProcessIndexStrategyEnum;
|
import org.dromara.easyes.common.enums.ProcessIndexStrategyEnum;
|
||||||
import org.dromara.easyes.common.property.EasyEsProperties;
|
import org.dromara.easyes.common.property.EasyEsProperties;
|
||||||
import org.dromara.easyes.common.utils.ExceptionUtils;
|
import org.dromara.easyes.common.utils.ExceptionUtils;
|
||||||
import org.dromara.easyes.solon.service.AutoProcessIndexService;
|
import org.dromara.easyes.common.strategy.AutoProcessIndexStrategy;
|
||||||
import org.elasticsearch.client.RestHighLevelClient;
|
import org.elasticsearch.client.RestHighLevelClient;
|
||||||
import org.noear.solon.Solon;
|
import org.noear.solon.Solon;
|
||||||
import org.noear.solon.annotation.Component;
|
import org.noear.solon.annotation.Component;
|
||||||
@ -36,7 +36,7 @@ public class IndexStrategyFactory implements LifecycleBean {
|
|||||||
/**
|
/**
|
||||||
* 策略容器
|
* 策略容器
|
||||||
*/
|
*/
|
||||||
private static final Map<Integer, AutoProcessIndexService> SERVICE_MAP = new HashMap<>(DEFAULT_SIZE);
|
private static final Map<Integer, AutoProcessIndexStrategy> SERVICE_MAP = new HashMap<>(DEFAULT_SIZE);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* bean初始化完成后执行
|
* bean初始化完成后执行
|
||||||
@ -47,13 +47,13 @@ public class IndexStrategyFactory implements LifecycleBean {
|
|||||||
// 是否开启自动托管模式,默认开启
|
// 是否开启自动托管模式,默认开启
|
||||||
if (!ProcessIndexStrategyEnum.MANUAL.equals(esConfigProperties.getGlobalConfig().getProcessIndexMode())) {
|
if (!ProcessIndexStrategyEnum.MANUAL.equals(esConfigProperties.getGlobalConfig().getProcessIndexMode())) {
|
||||||
// 将bean注册进工厂
|
// 将bean注册进工厂
|
||||||
Solon.context().getBeansMapOfType(AutoProcessIndexService.class)
|
Solon.context().getBeansMapOfType(AutoProcessIndexStrategy.class)
|
||||||
.values()
|
.values()
|
||||||
.forEach(v -> SERVICE_MAP.putIfAbsent(v.getStrategyType(), v));
|
.forEach(v -> SERVICE_MAP.putIfAbsent(v.getStrategyType(), v));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public AutoProcessIndexService getByStrategyType(Integer strategyType) {
|
public AutoProcessIndexStrategy getByStrategyType(Integer strategyType) {
|
||||||
return Optional.ofNullable(SERVICE_MAP.get(strategyType))
|
return Optional.ofNullable(SERVICE_MAP.get(strategyType))
|
||||||
.orElseThrow(() -> ExceptionUtils.eee("no such service strategyType:{}", strategyType));
|
.orElseThrow(() -> ExceptionUtils.eee("no such service strategyType:{}", strategyType));
|
||||||
|
|
||||||
|
|||||||
@ -14,12 +14,12 @@ import org.dromara.easyes.core.cache.GlobalConfigCache;
|
|||||||
import org.dromara.easyes.common.property.GlobalConfig;
|
import org.dromara.easyes.common.property.GlobalConfig;
|
||||||
import org.dromara.easyes.core.kernel.BaseEsMapper;
|
import org.dromara.easyes.core.kernel.BaseEsMapper;
|
||||||
import org.dromara.easyes.core.proxy.EsMapperProxy;
|
import org.dromara.easyes.core.proxy.EsMapperProxy;
|
||||||
|
import org.dromara.easyes.common.strategy.AutoProcessIndexStrategy;
|
||||||
import org.dromara.easyes.core.toolkit.EntityInfoHelper;
|
import org.dromara.easyes.core.toolkit.EntityInfoHelper;
|
||||||
import org.dromara.easyes.extension.context.Interceptor;
|
import org.dromara.easyes.extension.context.Interceptor;
|
||||||
import org.dromara.easyes.extension.context.InterceptorChain;
|
import org.dromara.easyes.extension.context.InterceptorChain;
|
||||||
import org.dromara.easyes.extension.context.InterceptorChainHolder;
|
import org.dromara.easyes.extension.context.InterceptorChainHolder;
|
||||||
import org.dromara.easyes.solon.factory.IndexStrategyFactory;
|
import org.dromara.easyes.solon.factory.IndexStrategyFactory;
|
||||||
import org.dromara.easyes.solon.service.AutoProcessIndexService;
|
|
||||||
import org.elasticsearch.client.RestHighLevelClient;
|
import org.elasticsearch.client.RestHighLevelClient;
|
||||||
import org.noear.solon.Solon;
|
import org.noear.solon.Solon;
|
||||||
import org.noear.solon.core.AppContext;
|
import org.noear.solon.core.AppContext;
|
||||||
@ -161,7 +161,7 @@ public class MapperScannerRegister implements BeanBuilder<EsMapperScan> {
|
|||||||
boolean isChild = entityInfo.isChild();
|
boolean isChild = entityInfo.isChild();
|
||||||
if (!isChild) {
|
if (!isChild) {
|
||||||
IndexStrategyFactory indexStrategyFactory = context.getBeanOrNew(IndexStrategyFactory.class);
|
IndexStrategyFactory indexStrategyFactory = context.getBeanOrNew(IndexStrategyFactory.class);
|
||||||
AutoProcessIndexService autoProcessIndexService = indexStrategyFactory
|
AutoProcessIndexStrategy autoProcessIndexService = indexStrategyFactory
|
||||||
.getByStrategyType(globalConfig.getProcessIndexMode().getStrategyType());
|
.getByStrategyType(globalConfig.getProcessIndexMode().getStrategyType());
|
||||||
autoProcessIndexService.processIndexAsync(entityClass, client);
|
autoProcessIndexService.processIndexAsync(entityClass, client);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,25 +0,0 @@
|
|||||||
package org.dromara.easyes.solon.service;
|
|
||||||
|
|
||||||
import org.elasticsearch.client.RestHighLevelClient;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自动托管索引接口
|
|
||||||
* <p>
|
|
||||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
|
||||||
**/
|
|
||||||
public interface AutoProcessIndexService {
|
|
||||||
/**
|
|
||||||
* 获取当前策略类型
|
|
||||||
*
|
|
||||||
* @return 策略类型
|
|
||||||
*/
|
|
||||||
Integer getStrategyType();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 异步处理索引
|
|
||||||
*
|
|
||||||
* @param entityClass 实体类
|
|
||||||
* @param client restHighLevelClient
|
|
||||||
*/
|
|
||||||
void processIndexAsync(Class<?> entityClass, RestHighLevelClient client);
|
|
||||||
}
|
|
||||||
@ -1,81 +0,0 @@
|
|||||||
package org.dromara.easyes.solon.service.impl;
|
|
||||||
|
|
||||||
import org.dromara.easyes.common.enums.ProcessIndexStrategyEnum;
|
|
||||||
import org.dromara.easyes.common.utils.LogUtils;
|
|
||||||
import org.dromara.easyes.core.biz.CreateIndexParam;
|
|
||||||
import org.dromara.easyes.core.biz.EntityInfo;
|
|
||||||
import org.dromara.easyes.core.biz.EsIndexInfo;
|
|
||||||
import org.dromara.easyes.core.toolkit.EntityInfoHelper;
|
|
||||||
import org.dromara.easyes.core.toolkit.IndexUtils;
|
|
||||||
import org.dromara.easyes.solon.service.AutoProcessIndexService;
|
|
||||||
import org.elasticsearch.client.RestHighLevelClient;
|
|
||||||
import org.noear.solon.annotation.Component;
|
|
||||||
import org.noear.solon.annotation.Condition;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自动非平滑托管索引实现类, 重建索引时原索引数据会被删除
|
|
||||||
* <p>
|
|
||||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
|
||||||
**/
|
|
||||||
@Component
|
|
||||||
@Condition(onBean = RestHighLevelClient.class, onProperty = "${easy-es.enable:true} = true && ${easy-es.address:x} != x")
|
|
||||||
public class AutoProcessIndexNotSmoothlyServiceImpl implements AutoProcessIndexService {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Integer getStrategyType() {
|
|
||||||
return ProcessIndexStrategyEnum.NOT_SMOOTHLY.getStrategyType();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void processIndexAsync(Class<?> entityClass, RestHighLevelClient client) {
|
|
||||||
LogUtils.info("===> Not smoothly process index mode activated");
|
|
||||||
IndexUtils.supplyAsync(this::process, entityClass, client);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean process(Class<?> entityClass, RestHighLevelClient client) {
|
|
||||||
EntityInfo entityInfo = EntityInfoHelper.getEntityInfo(entityClass);
|
|
||||||
// 是否存在索引
|
|
||||||
boolean existsIndex = IndexUtils.existsIndexWithRetry(entityInfo, client);
|
|
||||||
if (existsIndex) {
|
|
||||||
// 更新
|
|
||||||
LogUtils.info("===> Index exists, automatically updating index by easy-es...");
|
|
||||||
return doUpdateIndex(entityInfo, entityClass, client);
|
|
||||||
} else {
|
|
||||||
// 新建
|
|
||||||
LogUtils.info("===> Index not exists, automatically creating index by easy-es...");
|
|
||||||
return doCreateIndex(entityInfo, entityClass, client);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean doUpdateIndex(EntityInfo entityInfo, Class<?> clazz, RestHighLevelClient client) {
|
|
||||||
// 获取索引信息
|
|
||||||
EsIndexInfo esIndexInfo = IndexUtils.getIndexInfo(client, entityInfo.getRetrySuccessIndexName());
|
|
||||||
|
|
||||||
// 索引是否有变化 若有则直接删除旧索引,创建新索引 若无则直接返回托管成功
|
|
||||||
boolean isIndexNeedChange = IndexUtils.isIndexNeedChange(esIndexInfo, entityInfo, clazz);
|
|
||||||
if (!isIndexNeedChange) {
|
|
||||||
LogUtils.info("===> index has nothing changed");
|
|
||||||
entityInfo.setIndexName(entityInfo.getRetrySuccessIndexName());
|
|
||||||
return Boolean.TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 直接删除旧索引
|
|
||||||
IndexUtils.deleteIndex(client, entityInfo.getRetrySuccessIndexName());
|
|
||||||
|
|
||||||
// 初始化创建索引参数
|
|
||||||
CreateIndexParam createIndexParam = IndexUtils.getCreateIndexParam(entityInfo, clazz);
|
|
||||||
|
|
||||||
// 执行创建
|
|
||||||
return IndexUtils.createIndex(client, entityInfo, createIndexParam);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean doCreateIndex(EntityInfo entityInfo, Class<?> clazz, RestHighLevelClient client) {
|
|
||||||
// 初始化创建索引参数
|
|
||||||
CreateIndexParam createIndexParam = IndexUtils.getCreateIndexParam(entityInfo, clazz);
|
|
||||||
|
|
||||||
// 执行创建
|
|
||||||
return IndexUtils.createIndex(client, entityInfo, createIndexParam);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,132 +0,0 @@
|
|||||||
package org.dromara.easyes.solon.service.impl;
|
|
||||||
|
|
||||||
import org.dromara.easyes.common.enums.ProcessIndexStrategyEnum;
|
|
||||||
import org.dromara.easyes.common.utils.LogUtils;
|
|
||||||
import org.dromara.easyes.core.biz.CreateIndexParam;
|
|
||||||
import org.dromara.easyes.core.biz.EntityInfo;
|
|
||||||
import org.dromara.easyes.core.biz.EsIndexInfo;
|
|
||||||
import org.dromara.easyes.core.toolkit.EntityInfoHelper;
|
|
||||||
import org.dromara.easyes.core.toolkit.IndexUtils;
|
|
||||||
import org.dromara.easyes.solon.service.AutoProcessIndexService;
|
|
||||||
import org.elasticsearch.client.RestHighLevelClient;
|
|
||||||
import org.noear.solon.annotation.Component;
|
|
||||||
import org.noear.solon.annotation.Condition;
|
|
||||||
|
|
||||||
import static org.dromara.easyes.common.constants.BaseEsConstants.S1_SUFFIX;
|
|
||||||
import static org.dromara.easyes.common.constants.BaseEsConstants.SO_SUFFIX;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自动平滑托管索引实现类,本框架默认模式,过程零停机,数据会自动转移至新索引
|
|
||||||
* <p>
|
|
||||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
|
||||||
**/
|
|
||||||
@Component
|
|
||||||
@Condition(onBean = RestHighLevelClient.class, onProperty = "${easy-es.enable:true} = true && ${easy-es.address:x} != x")
|
|
||||||
public class AutoProcessIndexSmoothlyServiceImpl implements AutoProcessIndexService {
|
|
||||||
@Override
|
|
||||||
public Integer getStrategyType() {
|
|
||||||
return ProcessIndexStrategyEnum.SMOOTHLY.getStrategyType();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void processIndexAsync(Class<?> entityClass, RestHighLevelClient client) {
|
|
||||||
LogUtils.info("===> Smoothly process index mode activated");
|
|
||||||
IndexUtils.supplyAsync(this::process, entityClass, client);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private synchronized boolean process(Class<?> entityClass, RestHighLevelClient client) {
|
|
||||||
EntityInfo entityInfo = EntityInfoHelper.getEntityInfo(entityClass);
|
|
||||||
|
|
||||||
// 索引是否已存在
|
|
||||||
boolean existsIndex = IndexUtils.existsIndexWithRetryAndSetActiveIndex(entityInfo, client);
|
|
||||||
if (existsIndex) {
|
|
||||||
// 更新
|
|
||||||
LogUtils.info("===> Index exists, automatically updating index by easy-es...");
|
|
||||||
return doUpdateIndex(entityInfo, entityClass, client);
|
|
||||||
} else {
|
|
||||||
// 新建
|
|
||||||
LogUtils.info("===> Index not exists, automatically creating index by easy-es...");
|
|
||||||
return doCreateIndex(entityInfo, entityClass, client);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private boolean doUpdateIndex(EntityInfo entityInfo, Class<?> clazz, RestHighLevelClient client) {
|
|
||||||
// 获取索引信息
|
|
||||||
EsIndexInfo esIndexInfo = IndexUtils.getIndexInfo(client, entityInfo.getIndexName());
|
|
||||||
|
|
||||||
// 是否存在默认别名,若无则给添加
|
|
||||||
if (!esIndexInfo.getHasDefaultAlias()) {
|
|
||||||
IndexUtils.addDefaultAlias(client, entityInfo.getIndexName());
|
|
||||||
}
|
|
||||||
|
|
||||||
// 索引是否有变化 若有则创建新索引并无感迁移, 若无则直接返回托管成功
|
|
||||||
boolean isIndexNeedChange = IndexUtils.isIndexNeedChange(esIndexInfo, entityInfo, clazz);
|
|
||||||
if (!isIndexNeedChange) {
|
|
||||||
LogUtils.info("===> index has nothing changed");
|
|
||||||
return Boolean.TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建新索引
|
|
||||||
String releaseIndexName = generateReleaseIndexName(entityInfo.getIndexName());
|
|
||||||
entityInfo.setReleaseIndexName(releaseIndexName);
|
|
||||||
boolean isCreateIndexSuccess = doCreateIndex(entityInfo, clazz, client);
|
|
||||||
if (!isCreateIndexSuccess) {
|
|
||||||
LogUtils.error("create release index failed", "releaseIndex:" + releaseIndexName);
|
|
||||||
return Boolean.FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 迁移数据至新创建的索引
|
|
||||||
boolean isDataMigrationSuccess = doDataMigration(entityInfo.getIndexName(), releaseIndexName, entityInfo.getMaxResultWindow(), client);
|
|
||||||
if (!isDataMigrationSuccess) {
|
|
||||||
LogUtils.error("migrate data failed", "oldIndex:" + entityInfo.getIndexName(), "releaseIndex:" + releaseIndexName);
|
|
||||||
return Boolean.FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 原子操作 切换别名:将默认别名关联至新索引,并将旧索引的默认别名移除
|
|
||||||
boolean isChangeAliasSuccess = IndexUtils.changeAliasAtomic(client, entityInfo.getIndexName(), releaseIndexName);
|
|
||||||
if (!isChangeAliasSuccess) {
|
|
||||||
LogUtils.error("change alias atomically failed", "oldIndex:" + entityInfo.getIndexName(), "releaseIndex:" + releaseIndexName);
|
|
||||||
return Boolean.FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 删除旧索引
|
|
||||||
boolean isDeletedIndexSuccess = IndexUtils.deleteIndex(client, entityInfo.getIndexName());
|
|
||||||
if (!isDeletedIndexSuccess) {
|
|
||||||
LogUtils.error("delete old index failed", "oldIndex:" + entityInfo.getIndexName());
|
|
||||||
return Boolean.FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 用最新索引覆盖缓存中的老索引
|
|
||||||
entityInfo.setIndexName(releaseIndexName);
|
|
||||||
|
|
||||||
// 将新索引名称记录至ee-distribute-lock索引中,以便在分布式环境下其它机器能够感知到
|
|
||||||
IndexUtils.saveReleaseIndex(releaseIndexName, client);
|
|
||||||
|
|
||||||
// done.
|
|
||||||
return Boolean.TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String generateReleaseIndexName(String oldIndexName) {
|
|
||||||
if (oldIndexName.endsWith(SO_SUFFIX)) {
|
|
||||||
return oldIndexName.split(SO_SUFFIX)[0] + S1_SUFFIX;
|
|
||||||
} else if (oldIndexName.endsWith(S1_SUFFIX)) {
|
|
||||||
return oldIndexName.split(S1_SUFFIX)[0] + SO_SUFFIX;
|
|
||||||
} else {
|
|
||||||
return oldIndexName + SO_SUFFIX;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean doDataMigration(String oldIndexName, String releaseIndexName, Integer maxResultWindow, RestHighLevelClient client) {
|
|
||||||
return IndexUtils.reindex(client, oldIndexName, releaseIndexName, maxResultWindow);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean doCreateIndex(EntityInfo entityInfo, Class<?> clazz, RestHighLevelClient client) {
|
|
||||||
// 初始化创建索引参数
|
|
||||||
CreateIndexParam createIndexParam = IndexUtils.getCreateIndexParam(entityInfo, clazz);
|
|
||||||
// 执行创建
|
|
||||||
return IndexUtils.createIndex(client, entityInfo, createIndexParam);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -12,7 +12,7 @@ import org.dromara.easyes.core.cache.BaseCache;
|
|||||||
import org.dromara.easyes.core.cache.GlobalConfigCache;
|
import org.dromara.easyes.core.cache.GlobalConfigCache;
|
||||||
import org.dromara.easyes.common.property.GlobalConfig;
|
import org.dromara.easyes.common.property.GlobalConfig;
|
||||||
import org.dromara.easyes.core.proxy.EsMapperProxy;
|
import org.dromara.easyes.core.proxy.EsMapperProxy;
|
||||||
import org.dromara.easyes.core.service.AutoProcessIndexService;
|
import org.dromara.easyes.common.strategy.AutoProcessIndexStrategy;
|
||||||
import org.dromara.easyes.core.toolkit.EntityInfoHelper;
|
import org.dromara.easyes.core.toolkit.EntityInfoHelper;
|
||||||
import org.dromara.easyes.extension.context.Interceptor;
|
import org.dromara.easyes.extension.context.Interceptor;
|
||||||
import org.dromara.easyes.extension.context.InterceptorChain;
|
import org.dromara.easyes.extension.context.InterceptorChain;
|
||||||
@ -87,7 +87,7 @@ public class MapperFactoryBean<T> implements FactoryBean<T> {
|
|||||||
EntityInfo entityInfo = EntityInfoHelper.getEntityInfo(entityClass);
|
EntityInfo entityInfo = EntityInfoHelper.getEntityInfo(entityClass);
|
||||||
boolean isChild = entityInfo.isChild();
|
boolean isChild = entityInfo.isChild();
|
||||||
if (!isChild) {
|
if (!isChild) {
|
||||||
AutoProcessIndexService autoProcessIndexService = indexStrategyFactory
|
AutoProcessIndexStrategy autoProcessIndexService = indexStrategyFactory
|
||||||
.getByStrategyType(globalConfig.getProcessIndexMode().getStrategyType());
|
.getByStrategyType(globalConfig.getProcessIndexMode().getStrategyType());
|
||||||
autoProcessIndexService.processIndexAsync(entityClass, client);
|
autoProcessIndexService.processIndexAsync(entityClass, client);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,12 +3,11 @@ package org.dromara.easyes.spring.factory;
|
|||||||
import org.dromara.easyes.common.constants.BaseEsConstants;
|
import org.dromara.easyes.common.constants.BaseEsConstants;
|
||||||
import org.dromara.easyes.common.enums.ProcessIndexStrategyEnum;
|
import org.dromara.easyes.common.enums.ProcessIndexStrategyEnum;
|
||||||
import org.dromara.easyes.common.utils.ExceptionUtils;
|
import org.dromara.easyes.common.utils.ExceptionUtils;
|
||||||
import org.dromara.easyes.core.service.AutoProcessIndexService;
|
import org.dromara.easyes.common.strategy.AutoProcessIndexStrategy;
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ApplicationContextAware;
|
import org.springframework.context.ApplicationContextAware;
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -31,7 +30,7 @@ public class IndexStrategyFactory implements ApplicationContextAware, Initializi
|
|||||||
/**
|
/**
|
||||||
* 策略容器
|
* 策略容器
|
||||||
*/
|
*/
|
||||||
private static final Map<Integer, AutoProcessIndexService> SERVICE_MAP = new HashMap<>(DEFAULT_SIZE);
|
private static final Map<Integer, AutoProcessIndexStrategy> SERVICE_MAP = new HashMap<>(DEFAULT_SIZE);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||||
@ -40,8 +39,8 @@ public class IndexStrategyFactory implements ApplicationContextAware, Initializi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() {
|
public void afterPropertiesSet() {
|
||||||
Map<String, AutoProcessIndexService> beansOfType = this.applicationContext
|
Map<String, AutoProcessIndexStrategy> beansOfType = this.applicationContext
|
||||||
.getBeansOfType(AutoProcessIndexService.class);
|
.getBeansOfType(AutoProcessIndexStrategy.class);
|
||||||
if (beansOfType.isEmpty()) {
|
if (beansOfType.isEmpty()) {
|
||||||
throw ExceptionUtils.eee("AutoProcessIndexService must have implementation. " +
|
throw ExceptionUtils.eee("AutoProcessIndexService must have implementation. " +
|
||||||
"AutoProcessIndexService索引策略接口必须要有实现。");
|
"AutoProcessIndexService索引策略接口必须要有实现。");
|
||||||
@ -55,7 +54,7 @@ public class IndexStrategyFactory implements ApplicationContextAware, Initializi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public AutoProcessIndexService getByStrategyType(Integer strategyType) {
|
public AutoProcessIndexStrategy getByStrategyType(Integer strategyType) {
|
||||||
return Optional.ofNullable(SERVICE_MAP.get(strategyType))
|
return Optional.ofNullable(SERVICE_MAP.get(strategyType))
|
||||||
.orElseThrow(() -> ExceptionUtils.eee("no such service strategyType:{}", strategyType));
|
.orElseThrow(() -> ExceptionUtils.eee("no such service strategyType:{}", strategyType));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,138 +0,0 @@
|
|||||||
package org.dromara.easyes.spring.property;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import org.dromara.easyes.annotation.rely.FieldStrategy;
|
|
||||||
import org.dromara.easyes.annotation.rely.IdType;
|
|
||||||
import org.dromara.easyes.annotation.rely.RefreshPolicy;
|
|
||||||
import org.dromara.easyes.common.constants.BaseEsConstants;
|
|
||||||
import org.dromara.easyes.common.enums.ProcessIndexStrategyEnum;
|
|
||||||
import org.dromara.easyes.common.enums.SchemaEnum;
|
|
||||||
import org.dromara.easyes.common.property.GlobalConfig;
|
|
||||||
import org.dromara.easyes.common.utils.StringUtils;
|
|
||||||
import org.springframework.core.env.Environment;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static org.dromara.easyes.common.constants.BaseEsConstants.EMPTY_STR;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* easy-es基础配置项 考虑到spring的场景,有些参数不是必须配置
|
|
||||||
* 基本类型就会出现默认值的情况 所以为了要有null值出现,这里采用包装类型
|
|
||||||
* <p>
|
|
||||||
* Copyright © 2022 xpc1024 All Rights Reserved
|
|
||||||
**/
|
|
||||||
@Data
|
|
||||||
public class EasyEsProperty {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否开启easy-es 默认开启
|
|
||||||
*/
|
|
||||||
private Boolean enable;
|
|
||||||
/**
|
|
||||||
* 是否开启easy-es LOGO BANNER的打印
|
|
||||||
*/
|
|
||||||
private Boolean banner;
|
|
||||||
/**
|
|
||||||
* es client address es客户端地址
|
|
||||||
*/
|
|
||||||
private String address;
|
|
||||||
/**
|
|
||||||
* schema 模式
|
|
||||||
*/
|
|
||||||
private String schema;
|
|
||||||
/**
|
|
||||||
* username of es 用户名,可缺省
|
|
||||||
*/
|
|
||||||
private String username;
|
|
||||||
/**
|
|
||||||
* password of es 密码,可缺省
|
|
||||||
*/
|
|
||||||
private String password;
|
|
||||||
/**
|
|
||||||
* maxConnectTotal 最大连接数
|
|
||||||
*/
|
|
||||||
private Integer maxConnTotal;
|
|
||||||
/**
|
|
||||||
* maxConnectPerRoute 最大连接路由数
|
|
||||||
*/
|
|
||||||
private Integer maxConnPerRoute;
|
|
||||||
/**
|
|
||||||
* connectTimeout timeUnit:millis 连接超时时间 单位毫秒
|
|
||||||
*/
|
|
||||||
private Integer connectTimeout;
|
|
||||||
/**
|
|
||||||
* socketTimeout timeUnit:millis 通讯超时时间 单位毫秒 默认10分钟 以免小白踩坑平滑模式下数据量过大迁移超时失败
|
|
||||||
*/
|
|
||||||
private Integer socketTimeout;
|
|
||||||
/***
|
|
||||||
* 保持心跳时间 timeUnit:millis 单位毫秒 默认30秒 防止小白白出现服务首次调用不成时不知所措
|
|
||||||
*/
|
|
||||||
private Integer keepAliveMillis;
|
|
||||||
/**
|
|
||||||
* connectionRequestTimeout timeUnit:millis 连接请求超时时间 单位毫秒
|
|
||||||
*/
|
|
||||||
private Integer connectionRequestTimeout;
|
|
||||||
/**
|
|
||||||
* global config 全局配置
|
|
||||||
*/
|
|
||||||
private GlobalConfig globalConfig;
|
|
||||||
/**
|
|
||||||
* 配置多动态数据源key datasource id
|
|
||||||
*/
|
|
||||||
private Map<String, EasyEsProperty> datasource = new HashMap<>();
|
|
||||||
|
|
||||||
public EasyEsProperty(Environment environment) {
|
|
||||||
this.setEnable(environment.getProperty(BaseEsConstants.ENABLE_PREFIX, Boolean.class, true));
|
|
||||||
this.setBanner(environment.getProperty(BaseEsConstants.ENABLE_BANNER, Boolean.class, true));
|
|
||||||
this.setAddress(environment.getProperty("easy-es.address", "127.0.0.1:9200"));
|
|
||||||
this.setSchema(environment.getProperty("easy-es.schema", SchemaEnum.http.name()));
|
|
||||||
this.setUsername(environment.getProperty("easy-es.username"));
|
|
||||||
this.setPassword(environment.getProperty("easy-es.password"));
|
|
||||||
this.setMaxConnTotal(environment.getProperty("easy-es.max-conn-total", Integer.class));
|
|
||||||
this.setMaxConnPerRoute(environment.getProperty("easy-es.max-conn-per-route", Integer.class));
|
|
||||||
this.setConnectTimeout(environment.getProperty("easy-es.connect-timeout", Integer.class));
|
|
||||||
this.setSocketTimeout(environment.getProperty("easy-es.socket-timeout", Integer.class, 600000));
|
|
||||||
this.setKeepAliveMillis(environment.getProperty("easy-es.keep-alive-millis", Integer.class, 30000));
|
|
||||||
this.setConnectionRequestTimeout(environment.getProperty("easy-es.connection-request-timeout", Integer.class));
|
|
||||||
GlobalConfig globalConfig = new GlobalConfig();
|
|
||||||
globalConfig.setPrintDsl(environment.getProperty("easy-es.global-config.print-dsl", Boolean.class, true));
|
|
||||||
globalConfig.setIKunMode(environment.getProperty("easy-es.global-config.i-kun-mode", Boolean.class, false));
|
|
||||||
globalConfig.setProcessIndexMode(environment.getProperty("easy-es.global-config.process-index-mode",
|
|
||||||
ProcessIndexStrategyEnum.class, ProcessIndexStrategyEnum.MANUAL));
|
|
||||||
globalConfig.setDistributed(environment.getProperty("easy-es.global-config.distributed", Boolean.class, true));
|
|
||||||
globalConfig.setReindexTimeOutHours(environment.getProperty("easy-es.global-config.reindex-time-out-hours",
|
|
||||||
Integer.class, 72));
|
|
||||||
globalConfig.setAsyncProcessIndexBlocking(environment.getProperty("easy-es.global-config.async-process-index-blocking",
|
|
||||||
Boolean.class, true));
|
|
||||||
globalConfig.setActiveReleaseIndexMaxRetry(environment.getProperty("easy-es.global-config.active-release-index-max-retry",
|
|
||||||
Integer.class, 4320));
|
|
||||||
globalConfig.setActiveReleaseIndexFixedDelay(environment.getProperty("easy-es.global-config.active-release-index-fixed-delay",
|
|
||||||
Integer.class, 60));
|
|
||||||
GlobalConfig.DbConfig dbConfig = new GlobalConfig.DbConfig();
|
|
||||||
dbConfig.setIndexPrefix(environment.getProperty("easy-es.global-config.db-config.index-prefix", EMPTY_STR));
|
|
||||||
dbConfig.setMapUnderscoreToCamelCase(environment.getProperty("easy-es.global-config.db-config.map-underscore-to-camel-case",
|
|
||||||
Boolean.class, false));
|
|
||||||
dbConfig.setIdType(environment.getProperty("easy-es.global-config.db-config.id-type", IdType.class, IdType.NONE));
|
|
||||||
dbConfig.setFieldStrategy(environment.getProperty("easy-es.global-config.db-config.field-strategy",
|
|
||||||
FieldStrategy.class, FieldStrategy.NOT_NULL));
|
|
||||||
dbConfig.setEnableTrackTotalHits(environment.getProperty("easy-es.global-config.db-config.enable-track-total-hits",
|
|
||||||
Boolean.class, true));
|
|
||||||
dbConfig.setRefreshPolicy(environment.getProperty("easy-es.global-config.db-config.refresh-policy",
|
|
||||||
RefreshPolicy.class, RefreshPolicy.NONE));
|
|
||||||
dbConfig.setBatchUpdateThreshold(environment.getProperty("easy-es.global-config.db-config.batch-update-threshold",
|
|
||||||
Integer.class, 10000));
|
|
||||||
dbConfig.setSmartAddKeywordSuffix(environment.getProperty("easy-es.global-config.db-config.smart-add-keyword-suffix",
|
|
||||||
Boolean.class, true));
|
|
||||||
globalConfig.setDbConfig(dbConfig);
|
|
||||||
this.setGlobalConfig(globalConfig);
|
|
||||||
|
|
||||||
// 设置多数据源
|
|
||||||
}
|
|
||||||
|
|
||||||
public EasyEsProperty() {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user