正在显示
9 个修改的文件
包含
837 行增加
和
17 行删除
@@ -102,10 +102,23 @@ management: | @@ -102,10 +102,23 @@ management: | ||
102 | shutdown: | 102 | shutdown: |
103 | enabled: true | 103 | enabled: true |
104 | 104 | ||
105 | -es: | ||
106 | - hostname: 192.168.37.139 | ||
107 | - port: 9200 | ||
108 | - scheme: http | 105 | +elasticsearch: |
106 | + # http连接超时时间 | ||
107 | + connectTimeout: 3000 | ||
108 | + # socket连接超时时间 | ||
109 | + socketTimeout: 60000 | ||
110 | + # 获取连接的超时时间, | ||
111 | + connectionRequestTimeout: 3000 | ||
112 | + # 最大连接数 | ||
113 | + maxConnTotal: 3000 | ||
114 | + # 最大路由连接数 | ||
115 | + maxConnPerRoute: 3000 | ||
116 | + # 任务最长可执行时间 (单位:小时) | ||
117 | + executeTimeout: 10 | ||
118 | + # 链接凭证:用户名 | ||
119 | + username: admin | ||
120 | + # 链接凭证:密码 | ||
121 | + password: 123456 | ||
109 | 122 | ||
110 | # 基础信息配置 | 123 | # 基础信息配置 |
111 | info: | 124 | info: |
@@ -60,6 +60,12 @@ | @@ -60,6 +60,12 @@ | ||
60 | <groupId>org.springframework.boot</groupId> | 60 | <groupId>org.springframework.boot</groupId> |
61 | <artifactId>spring-boot-starter-data-elasticsearch</artifactId> | 61 | <artifactId>spring-boot-starter-data-elasticsearch</artifactId> |
62 | </dependency> | 62 | </dependency> |
63 | + | ||
64 | + <dependency> | ||
65 | + <groupId>org.springframework.boot</groupId> | ||
66 | + <artifactId>spring-boot-configuration-processor</artifactId> | ||
67 | + <optional>true</optional> | ||
68 | + </dependency> | ||
63 | <!-- SpringBoot end --> | 69 | <!-- SpringBoot end --> |
64 | 70 | ||
65 | <!-- SpringCloud start --> | 71 | <!-- SpringCloud start --> |
1 | package com.sunyo.wlpt.message.bus.service.config; | 1 | package com.sunyo.wlpt.message.bus.service.config; |
2 | 2 | ||
3 | +import com.sunyo.wlpt.message.bus.service.domain.es.ElasticSearchInfo; | ||
4 | +import com.sunyo.wlpt.message.bus.service.domain.es.ElasticSearchProperties; | ||
5 | +import com.sunyo.wlpt.message.bus.service.service.ElasticSearchInfoService; | ||
6 | +import lombok.RequiredArgsConstructor; | ||
3 | import org.apache.http.HttpHost; | 7 | import org.apache.http.HttpHost; |
8 | +import org.apache.http.auth.AuthScope; | ||
9 | +import org.apache.http.auth.UsernamePasswordCredentials; | ||
10 | +import org.apache.http.client.CredentialsProvider; | ||
11 | +import org.apache.http.impl.client.BasicCredentialsProvider; | ||
4 | import org.elasticsearch.client.RestClient; | 12 | import org.elasticsearch.client.RestClient; |
13 | +import org.elasticsearch.client.RestClientBuilder; | ||
5 | import org.elasticsearch.client.RestHighLevelClient; | 14 | import org.elasticsearch.client.RestHighLevelClient; |
6 | -import org.springframework.beans.factory.annotation.Value; | 15 | +import org.springframework.beans.factory.annotation.Autowired; |
7 | import org.springframework.context.annotation.Bean; | 16 | import org.springframework.context.annotation.Bean; |
8 | import org.springframework.context.annotation.Configuration; | 17 | import org.springframework.context.annotation.Configuration; |
9 | import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration; | 18 | import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration; |
10 | import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; | 19 | import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; |
11 | 20 | ||
21 | +import javax.annotation.Resource; | ||
22 | +import java.util.List; | ||
23 | + | ||
12 | /** | 24 | /** |
13 | * @author 子诚 | 25 | * @author 子诚 |
14 | * Description:ES的配置文件 | 26 | * Description:ES的配置文件 |
15 | * 时间:2020/8/5 10:23 | 27 | * 时间:2020/8/5 10:23 |
16 | */ | 28 | */ |
29 | +@RequiredArgsConstructor(onConstructor_ = @Autowired) | ||
17 | @Configuration | 30 | @Configuration |
18 | public class ElasticSearchConfig extends AbstractElasticsearchConfiguration { | 31 | public class ElasticSearchConfig extends AbstractElasticsearchConfiguration { |
19 | 32 | ||
20 | - @Value("${es.hostname}") | ||
21 | - private String hostname; | 33 | + @Resource |
34 | + private ElasticSearchInfoService elasticSearchInfoService; | ||
22 | 35 | ||
23 | - @Value("${es.port}") | ||
24 | - private Integer port; | 36 | + private final ElasticSearchProperties elasticSearchProperties; |
25 | 37 | ||
26 | - @Value("${es.scheme}") | ||
27 | - private String scheme; | 38 | + /** |
39 | + * 获取ES集群信息 | ||
40 | + * | ||
41 | + * @return ES集群信息 | ||
42 | + */ | ||
43 | + public HttpHost[] getHttpHosts() | ||
44 | + { | ||
45 | + List<ElasticSearchInfo> elasticSearchInfos = elasticSearchInfoService.selectList(); | ||
46 | + int size = elasticSearchInfos.size(); | ||
47 | + HttpHost[] httpHosts = new HttpHost[size]; | ||
48 | + for (int i = 0; i < size; i++) { | ||
49 | + String hostname = elasticSearchInfos.get(i).getHostname(); | ||
50 | + Integer port = elasticSearchInfos.get(i).getPort(); | ||
51 | + String scheme = elasticSearchInfos.get(i).getScheme(); | ||
52 | + httpHosts[i] = new HttpHost(hostname, port, scheme); | ||
53 | + } | ||
54 | + return httpHosts; | ||
55 | + } | ||
28 | 56 | ||
29 | 57 | ||
30 | @Override | 58 | @Override |
31 | @Bean | 59 | @Bean |
32 | public RestHighLevelClient elasticsearchClient() | 60 | public RestHighLevelClient elasticsearchClient() |
33 | { | 61 | { |
34 | - RestHighLevelClient client = new RestHighLevelClient( | ||
35 | - RestClient.builder( | ||
36 | - // 天生契合集群,有几个es环境,就 new HttpHost 几个,用,相隔 | ||
37 | - new HttpHost(hostname, port, scheme) | ||
38 | - ) | ||
39 | - ); | 62 | + final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); |
63 | + credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials( | ||
64 | + elasticSearchProperties.getUsername(), elasticSearchProperties.getPassword() | ||
65 | + )); | ||
66 | + | ||
67 | + RestClientBuilder builder = RestClient.builder(getHttpHosts()); | ||
68 | + // 异步的请求配置 | ||
69 | + builder.setRequestConfigCallback(builder1 -> { | ||
70 | + // 连接超时时间 默认-1 | ||
71 | + builder1.setConnectTimeout(elasticSearchProperties.getConnectTimeout()); | ||
72 | + builder1.setSocketTimeout(elasticSearchProperties.getSocketTimeout()); | ||
73 | + // 获取连接的超时时间 默认-1 | ||
74 | + builder1.setConnectionRequestTimeout(elasticSearchProperties.getConnectionRequestTimeout()); | ||
75 | + return builder1; | ||
76 | + }); | ||
77 | + // 异步的httpclient连接数配置 | ||
78 | + builder.setHttpClientConfigCallback(httpAsyncClientBuilder -> { | ||
79 | + // 最大连接数 | ||
80 | + httpAsyncClientBuilder.setMaxConnTotal(elasticSearchProperties.getMaxConnTotal()); | ||
81 | + // 最大路由连接数 | ||
82 | + httpAsyncClientBuilder.setMaxConnPerRoute(elasticSearchProperties.getMaxConnPerRoute()); | ||
83 | + // 赋予连接凭证 | ||
84 | + httpAsyncClientBuilder.setDefaultCredentialsProvider(credentialsProvider); | ||
85 | + return httpAsyncClientBuilder; | ||
86 | + }); | ||
87 | + RestHighLevelClient client = new RestHighLevelClient(builder); | ||
40 | return client; | 88 | return client; |
41 | } | 89 | } |
42 | 90 |
1 | +package com.sunyo.wlpt.message.bus.service.domain.es; | ||
2 | + | ||
3 | +import lombok.AllArgsConstructor; | ||
4 | +import lombok.Builder; | ||
5 | +import lombok.Data; | ||
6 | +import lombok.NoArgsConstructor; | ||
7 | + | ||
8 | +import java.io.Serializable; | ||
9 | +import java.util.Date; | ||
10 | + | ||
11 | +/** | ||
12 | + * @author 子诚 | ||
13 | + * Description:ES服务器信息表,控制ES集群的详细信息 | ||
14 | + * 时间:2020/9/10 17:53 | ||
15 | + */ | ||
16 | + | ||
17 | +@Data | ||
18 | +@Builder | ||
19 | +@AllArgsConstructor | ||
20 | +@NoArgsConstructor | ||
21 | +public class ElasticSearchInfo implements Serializable { | ||
22 | + | ||
23 | + private static final long serialVersionUID = 379812159019579949L; | ||
24 | + | ||
25 | + /** | ||
26 | + * ES服务器ID | ||
27 | + */ | ||
28 | + private String id; | ||
29 | + | ||
30 | + /** | ||
31 | + * 集群名称 | ||
32 | + */ | ||
33 | + private String clusterName; | ||
34 | + | ||
35 | + /** | ||
36 | + * ES服务器名称 | ||
37 | + */ | ||
38 | + private String elasticsearchName; | ||
39 | + | ||
40 | + /** | ||
41 | + * ES服务器IP地址 | ||
42 | + */ | ||
43 | + private String hostname; | ||
44 | + | ||
45 | + /** | ||
46 | + * ES服务器端口号 | ||
47 | + */ | ||
48 | + private Integer port; | ||
49 | + | ||
50 | + /** | ||
51 | + * scheme协议,默认(必须是http) | ||
52 | + */ | ||
53 | + private String scheme; | ||
54 | + | ||
55 | + /** | ||
56 | + * 默认(即创建时),是否是主节点? | ||
57 | + */ | ||
58 | + private Boolean isMaster; | ||
59 | + | ||
60 | + /** | ||
61 | + * ES状态,运行,还是宕机? | ||
62 | + */ | ||
63 | + private Boolean elasticsearchState; | ||
64 | + | ||
65 | + /** | ||
66 | + * ES服务器相关描述 | ||
67 | + */ | ||
68 | + private String description; | ||
69 | + | ||
70 | + /** | ||
71 | + * ES服务器创建时间 | ||
72 | + */ | ||
73 | + private Date gmtCreate; | ||
74 | + | ||
75 | + /** | ||
76 | + * ES服务器修改时间 | ||
77 | + */ | ||
78 | + private Date gmtModified; | ||
79 | +} |
1 | +package com.sunyo.wlpt.message.bus.service.domain.es; | ||
2 | + | ||
3 | +import lombok.Data; | ||
4 | +import org.springframework.boot.context.properties.ConfigurationProperties; | ||
5 | +import org.springframework.context.annotation.Configuration; | ||
6 | + | ||
7 | +/** | ||
8 | + * @author 子诚 | ||
9 | + * Description:ES中使用的http连接的设置 | ||
10 | + * 时间:2020/9/9 17:42 | ||
11 | + */ | ||
12 | +@Data | ||
13 | +@ConfigurationProperties(prefix = "elasticsearch") | ||
14 | +@Configuration | ||
15 | +public class ElasticSearchProperties { | ||
16 | + /** | ||
17 | + * http连接超时时间 | ||
18 | + */ | ||
19 | + private Integer connectTimeout; | ||
20 | + /** | ||
21 | + * socket连接超时时间 | ||
22 | + */ | ||
23 | + private Integer socketTimeout; | ||
24 | + /** | ||
25 | + * 获取连接的超时时间 | ||
26 | + */ | ||
27 | + private Integer connectionRequestTimeout; | ||
28 | + /** | ||
29 | + * 最大连接数 | ||
30 | + */ | ||
31 | + private Integer maxConnTotal; | ||
32 | + /** | ||
33 | + * 最大路由连接数 | ||
34 | + */ | ||
35 | + private Integer maxConnPerRoute; | ||
36 | + /** | ||
37 | + * 任务最长可执行时间 (单位:小时) | ||
38 | + */ | ||
39 | + private Integer executeTimeout; | ||
40 | + /** | ||
41 | + * 链接凭证:用户名 | ||
42 | + */ | ||
43 | + private String username; | ||
44 | + /** | ||
45 | + * 链接凭证:密码 | ||
46 | + */ | ||
47 | + private String password; | ||
48 | +} |
1 | +package com.sunyo.wlpt.message.bus.service.mapper; | ||
2 | + | ||
3 | +import com.sunyo.wlpt.message.bus.service.domain.es.ElasticSearchInfo; | ||
4 | +import org.apache.ibatis.annotations.Mapper; | ||
5 | +import org.apache.ibatis.annotations.Param; | ||
6 | + | ||
7 | +import java.util.List; | ||
8 | + | ||
9 | +/** | ||
10 | + * @author 子诚 | ||
11 | + * Description: | ||
12 | + * 时间:2020/9/10 17:53 | ||
13 | + */ | ||
14 | +@Mapper | ||
15 | +public interface ElasticSearchInfoMapper { | ||
16 | + /** | ||
17 | + * delete by primary key | ||
18 | + * | ||
19 | + * @param id primaryKey | ||
20 | + * @return deleteCount | ||
21 | + */ | ||
22 | + int deleteByPrimaryKey(String id); | ||
23 | + | ||
24 | + /** | ||
25 | + * insert record to table | ||
26 | + * | ||
27 | + * @param record the record | ||
28 | + * @return insert count | ||
29 | + */ | ||
30 | + int insert(ElasticSearchInfo record); | ||
31 | + | ||
32 | + /** | ||
33 | + * insert record to table selective | ||
34 | + * | ||
35 | + * @param record the record | ||
36 | + * @return insert count | ||
37 | + */ | ||
38 | + int insertSelective(ElasticSearchInfo record); | ||
39 | + | ||
40 | + /** | ||
41 | + * select by primary key | ||
42 | + * | ||
43 | + * @param id primary key | ||
44 | + * @return object by primary key | ||
45 | + */ | ||
46 | + ElasticSearchInfo selectByPrimaryKey(String id); | ||
47 | + | ||
48 | + /** | ||
49 | + * update record selective | ||
50 | + * | ||
51 | + * @param record the updated record | ||
52 | + * @return update count | ||
53 | + */ | ||
54 | + int updateByPrimaryKeySelective(ElasticSearchInfo record); | ||
55 | + | ||
56 | + /** | ||
57 | + * update record | ||
58 | + * | ||
59 | + * @param record the updated record | ||
60 | + * @return update count | ||
61 | + */ | ||
62 | + int updateByPrimaryKey(ElasticSearchInfo record); | ||
63 | + | ||
64 | + /** | ||
65 | + * 查询所有ES信息,配置中使用 | ||
66 | + * | ||
67 | + * @return 所有ES信息 | ||
68 | + */ | ||
69 | + List<ElasticSearchInfo> selectList(); | ||
70 | + | ||
71 | + /** | ||
72 | + * 分页查询,ES列表 | ||
73 | + * | ||
74 | + * @param elasticSearchInfo {@link ElasticSearchInfo} | ||
75 | + * @return | ||
76 | + */ | ||
77 | + List<ElasticSearchInfo> selectListByPage(ElasticSearchInfo elasticSearchInfo); | ||
78 | + | ||
79 | + /** | ||
80 | + * 批量删除 | ||
81 | + * | ||
82 | + * @param idList id数组 | ||
83 | + * @return | ||
84 | + */ | ||
85 | + int batchRemoveByIds(String[] idList); | ||
86 | + | ||
87 | + /** | ||
88 | + * 根据ES名称(节点名称)查询ES信息 | ||
89 | + * | ||
90 | + * @return | ||
91 | + */ | ||
92 | + List<ElasticSearchInfo> selectListByElasticsearchName(@Param("elasticsearchName") String elasticsearchName); | ||
93 | + | ||
94 | + /** | ||
95 | + * 根据Url,校验 | ||
96 | + * | ||
97 | + * @param hostname ip地址 | ||
98 | + * @param port 端口号 | ||
99 | + * @param scheme 协议(http) | ||
100 | + * @return | ||
101 | + */ | ||
102 | + List<ElasticSearchInfo> selectByUrl(@Param("hostname") String hostname, @Param("port") Integer port, @Param("scheme") String scheme); | ||
103 | +} |
1 | +package com.sunyo.wlpt.message.bus.service.service; | ||
2 | + | ||
3 | +import com.sunyo.wlpt.message.bus.service.domain.es.ElasticSearchInfo; | ||
4 | +import com.sunyo.wlpt.message.bus.service.response.ResultJson; | ||
5 | + | ||
6 | +import java.util.List; | ||
7 | + | ||
8 | +/** | ||
9 | + * @author 子诚 | ||
10 | + * Description: | ||
11 | + * 时间:2020/9/8 15:49 | ||
12 | + */ | ||
13 | +public interface ElasticSearchInfoService { | ||
14 | + | ||
15 | + /** | ||
16 | + * delete by primary key | ||
17 | + * | ||
18 | + * @param id primaryKey | ||
19 | + * @return deleteCount | ||
20 | + */ | ||
21 | + ResultJson deleteByPrimaryKey(String id); | ||
22 | + | ||
23 | + /** | ||
24 | + * insert record to table | ||
25 | + * | ||
26 | + * @param record the record | ||
27 | + * @return insert count | ||
28 | + */ | ||
29 | + int insert(ElasticSearchInfo record); | ||
30 | + | ||
31 | + /** | ||
32 | + * insert record to table selective | ||
33 | + * | ||
34 | + * @param record the record | ||
35 | + * @return insert count | ||
36 | + */ | ||
37 | + ResultJson insertSelective(ElasticSearchInfo record); | ||
38 | + | ||
39 | + /** | ||
40 | + * select by primary key | ||
41 | + * | ||
42 | + * @param id primary key | ||
43 | + * @return object by primary key | ||
44 | + */ | ||
45 | + ElasticSearchInfo selectByPrimaryKey(String id); | ||
46 | + | ||
47 | + /** | ||
48 | + * update record selective | ||
49 | + * | ||
50 | + * @param record the updated record | ||
51 | + * @return update count | ||
52 | + */ | ||
53 | + ResultJson updateByPrimaryKeySelective(ElasticSearchInfo record); | ||
54 | + | ||
55 | + /** | ||
56 | + * update record | ||
57 | + * | ||
58 | + * @param record the updated record | ||
59 | + * @return update count | ||
60 | + */ | ||
61 | + int updateByPrimaryKey(ElasticSearchInfo record); | ||
62 | + | ||
63 | + /** | ||
64 | + * 查询所有ES信息 | ||
65 | + * | ||
66 | + * @return 所有ES信息 | ||
67 | + */ | ||
68 | + List<ElasticSearchInfo> selectList(); | ||
69 | + | ||
70 | + /** | ||
71 | + * 分页查询,ES列表 | ||
72 | + * | ||
73 | + * @param elasticSearchInfo {@link ElasticSearchInfo} | ||
74 | + * @param pageNum 当前页数 | ||
75 | + * @param pageSize 每页大小 | ||
76 | + * @return | ||
77 | + */ | ||
78 | + ResultJson selectListByPage(ElasticSearchInfo elasticSearchInfo, Integer pageNum, Integer pageSize); | ||
79 | + | ||
80 | + /** | ||
81 | + * 批量删除ES信息 | ||
82 | + * | ||
83 | + * @param ids id以,相连接的字符串 | ||
84 | + * @return | ||
85 | + */ | ||
86 | + ResultJson batchRemoveByIds(String ids); | ||
87 | +} | ||
88 | + | ||
89 | + | ||
90 | + |
src/main/java/com/sunyo/wlpt/message/bus/service/service/impl/ElasticSearchInfoServiceImpl.java
0 → 100644
1 | +package com.sunyo.wlpt.message.bus.service.service.impl; | ||
2 | + | ||
3 | +import com.github.pagehelper.PageHelper; | ||
4 | +import com.github.pagehelper.PageInfo; | ||
5 | +import com.sunyo.wlpt.message.bus.service.domain.es.ElasticSearchInfo; | ||
6 | +import com.sunyo.wlpt.message.bus.service.mapper.ElasticSearchInfoMapper; | ||
7 | +import com.sunyo.wlpt.message.bus.service.response.ResultJson; | ||
8 | +import com.sunyo.wlpt.message.bus.service.service.ElasticSearchInfoService; | ||
9 | +import com.sunyo.wlpt.message.bus.service.utils.IdUtils; | ||
10 | +import io.netty.util.internal.StringUtil; | ||
11 | +import org.springframework.stereotype.Service; | ||
12 | + | ||
13 | +import javax.annotation.Resource; | ||
14 | +import java.util.List; | ||
15 | + | ||
16 | +import static com.sunyo.wlpt.message.bus.service.common.Constant.RESULT_SUCCESS; | ||
17 | + | ||
18 | +/** | ||
19 | + * @author 子诚 | ||
20 | + * Description: | ||
21 | + * 时间:2020/9/8 15:49 | ||
22 | + */ | ||
23 | +@Service | ||
24 | +public class ElasticSearchInfoServiceImpl implements ElasticSearchInfoService { | ||
25 | + | ||
26 | + @Resource | ||
27 | + private ElasticSearchInfoMapper elasticSearchInfoMapper; | ||
28 | + | ||
29 | + @Override | ||
30 | + public ResultJson deleteByPrimaryKey(String id) | ||
31 | + { | ||
32 | + return elasticSearchInfoMapper.deleteByPrimaryKey(id) > 0 | ||
33 | + ? new ResultJson<>("200", "删除ES信息,成功") | ||
34 | + : new ResultJson<>("500", "删除ES信息,失败"); | ||
35 | + } | ||
36 | + | ||
37 | + @Override | ||
38 | + public ResultJson batchRemoveByIds(String ids) | ||
39 | + { | ||
40 | + String[] idList = ids.split(","); | ||
41 | + return elasticSearchInfoMapper.batchRemoveByIds(idList) > 0 | ||
42 | + ? new ResultJson<>("200", "批量删除ES信息,成功") | ||
43 | + : new ResultJson<>("500", "批量删除ES信息,失败"); | ||
44 | + } | ||
45 | + | ||
46 | + @Override | ||
47 | + public int insert(ElasticSearchInfo record) | ||
48 | + { | ||
49 | + return elasticSearchInfoMapper.insert(record); | ||
50 | + } | ||
51 | + | ||
52 | + @Override | ||
53 | + public ResultJson insertSelective(ElasticSearchInfo record) | ||
54 | + { | ||
55 | + ResultJson validate = validate(record); | ||
56 | + if (!RESULT_SUCCESS.equals(validate.getCode())) { | ||
57 | + return validate; | ||
58 | + } | ||
59 | + record.setId(IdUtils.generateId()); | ||
60 | + return elasticSearchInfoMapper.insertSelective(record) > 0 | ||
61 | + ? new ResultJson<>("200", "新增ES信息,成功") | ||
62 | + : new ResultJson<>("500", "新增ES信息,失败"); | ||
63 | + } | ||
64 | + | ||
65 | + @Override | ||
66 | + public ElasticSearchInfo selectByPrimaryKey(String id) | ||
67 | + { | ||
68 | + return elasticSearchInfoMapper.selectByPrimaryKey(id); | ||
69 | + } | ||
70 | + | ||
71 | + @Override | ||
72 | + public ResultJson updateByPrimaryKeySelective(ElasticSearchInfo record) | ||
73 | + { | ||
74 | + ResultJson validate = validate(record); | ||
75 | + if (!RESULT_SUCCESS.equals(validate.getCode())) { | ||
76 | + return validate; | ||
77 | + } | ||
78 | + return elasticSearchInfoMapper.updateByPrimaryKeySelective(record) > 0 | ||
79 | + ? new ResultJson<>("200", "编辑ES信息,成功") | ||
80 | + : new ResultJson<>("500", "编辑ES信息,失败"); | ||
81 | + } | ||
82 | + | ||
83 | + @Override | ||
84 | + public int updateByPrimaryKey(ElasticSearchInfo record) | ||
85 | + { | ||
86 | + return elasticSearchInfoMapper.updateByPrimaryKey(record); | ||
87 | + } | ||
88 | + | ||
89 | + @Override | ||
90 | + public List<ElasticSearchInfo> selectList() | ||
91 | + { | ||
92 | + return elasticSearchInfoMapper.selectList(); | ||
93 | + } | ||
94 | + | ||
95 | + /** | ||
96 | + * 分页查询 | ||
97 | + * | ||
98 | + * @param elasticSearchInfo {@link ElasticSearchInfo} | ||
99 | + * @param pageNum 当前页数 | ||
100 | + * @param pageSize 每页大小 | ||
101 | + * @return | ||
102 | + */ | ||
103 | + @Override | ||
104 | + public ResultJson selectListByPage(ElasticSearchInfo elasticSearchInfo, Integer pageNum, Integer pageSize) | ||
105 | + { | ||
106 | + PageHelper.startPage(pageNum, pageSize); | ||
107 | + List<ElasticSearchInfo> elasticSearchInfos = elasticSearchInfoMapper.selectListByPage(elasticSearchInfo); | ||
108 | + PageInfo<ElasticSearchInfo> pageInfo = new PageInfo<>(elasticSearchInfos); | ||
109 | + return pageInfo.getTotal() > 0 | ||
110 | + ? new ResultJson<>("200", "查询ES服务器列表,成功!", pageInfo) | ||
111 | + : new ResultJson<>("500", "查询ES服务器列表,失败!"); | ||
112 | + } | ||
113 | + | ||
114 | + /** | ||
115 | + * 校验规则,增加,修改时 | ||
116 | + * | ||
117 | + * @param elasticSearchInfo {@link ResultJson} ES信息实体类 | ||
118 | + * @return | ||
119 | + */ | ||
120 | + public ResultJson validate(ElasticSearchInfo elasticSearchInfo) | ||
121 | + { | ||
122 | + String clusterName = elasticSearchInfo.getClusterName(); | ||
123 | + String elasticsearchName = elasticSearchInfo.getElasticsearchName(); | ||
124 | + String hostname = elasticSearchInfo.getHostname(); | ||
125 | + Integer port = elasticSearchInfo.getPort(); | ||
126 | + String scheme = elasticSearchInfo.getScheme(); | ||
127 | + | ||
128 | + if (StringUtil.isNullOrEmpty(clusterName) | ||
129 | + || StringUtil.isNullOrEmpty(elasticsearchName) | ||
130 | + || StringUtil.isNullOrEmpty(hostname) | ||
131 | + || StringUtil.isNullOrEmpty(scheme) | ||
132 | + || port == null | ||
133 | + ) { | ||
134 | + return new ResultJson<>("400", "集群名称、节点名称、Ip地址、端口号或协议,不存在"); | ||
135 | + } | ||
136 | + String id = elasticSearchInfo.getId(); | ||
137 | + return StringUtil.isNullOrEmpty(id) | ||
138 | + // 新增ES信息 | ||
139 | + ? validateInsert(elasticsearchName, hostname, port, scheme) | ||
140 | + // 编辑ES信息 | ||
141 | + : validateEdit(id, elasticsearchName, hostname, port, scheme); | ||
142 | + } | ||
143 | + | ||
144 | + /** | ||
145 | + * 编辑ES信息方法的校验 | ||
146 | + * <p> | ||
147 | + * 判断Id,是否真实存在 | ||
148 | + * <p> | ||
149 | + * 判断ES名称,即节点名称,是否已存在 | ||
150 | + * <p> | ||
151 | + * 判断url信息是否已存在,即 scheme://hostname:port | ||
152 | + * | ||
153 | + * @param id id | ||
154 | + * @param elasticsearchName ES名称,即节点名称 | ||
155 | + * @param hostname IP地址 | ||
156 | + * @param port 端口号 | ||
157 | + * @param scheme 协议 | ||
158 | + * @return 校验通过与否 | ||
159 | + */ | ||
160 | + private ResultJson validateEdit(String id, String elasticsearchName, String hostname, Integer port, String scheme) | ||
161 | + { | ||
162 | + ElasticSearchInfo oldInfo = elasticSearchInfoMapper.selectByPrimaryKey(id); | ||
163 | + if (oldInfo == null) { | ||
164 | + return new ResultJson<>("400", "该ES信息不存在"); | ||
165 | + } | ||
166 | + if (!elasticsearchName.equals(oldInfo.getElasticsearchName())) { | ||
167 | + if (elasticSearchInfoMapper.selectListByElasticsearchName(elasticsearchName).size() > 0) { | ||
168 | + return new ResultJson<>("400", "节点名称(ES名称),已存在"); | ||
169 | + } | ||
170 | + } | ||
171 | + if (hostname.equals(oldInfo.getHostname()) && port.equals(oldInfo.getPort()) && scheme.equals(oldInfo.getScheme())) { | ||
172 | + return ResultJson.success("编辑ES信息,通过检验!"); | ||
173 | + } | ||
174 | + return elasticSearchInfoMapper.selectByUrl(hostname, port, scheme).size() > 0 | ||
175 | + ? new ResultJson<>("500", "该ES详细信息,已存在") | ||
176 | + : ResultJson.success("编辑ES信息,通过检验!"); | ||
177 | + } | ||
178 | + | ||
179 | + /** | ||
180 | + * 新增ES信息方法的校验 | ||
181 | + * <p> | ||
182 | + * 判断ES名称,即节点名称,是否已存在 | ||
183 | + * <p> | ||
184 | + * 判断url信息是否已存在,即 scheme://hostname:port | ||
185 | + * | ||
186 | + * @param elasticsearchName ES名称,即节点名称 | ||
187 | + * @param hostname IP地址 | ||
188 | + * @param port 端口号 | ||
189 | + * @param scheme 协议 | ||
190 | + * @return 校验通过与否 | ||
191 | + */ | ||
192 | + private ResultJson validateInsert(String elasticsearchName, String hostname, Integer port, String scheme) | ||
193 | + { | ||
194 | + if (elasticSearchInfoMapper.selectListByElasticsearchName(elasticsearchName).size() > 0) { | ||
195 | + return new ResultJson<>("400", "节点名称(ES名称),已存在"); | ||
196 | + } | ||
197 | + return elasticSearchInfoMapper.selectByUrl(hostname, port, scheme).size() > 0 | ||
198 | + ? new ResultJson<>("500", "该ES详细信息,已存在") | ||
199 | + : ResultJson.success("新增ES信息,通过检验!"); | ||
200 | + } | ||
201 | + | ||
202 | +} | ||
203 | + | ||
204 | + | ||
205 | + |
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
3 | +<mapper namespace="com.sunyo.wlpt.message.bus.service.mapper.ElasticSearchInfoMapper"> | ||
4 | + <resultMap id="BaseResultMap" type="com.sunyo.wlpt.message.bus.service.domain.es.ElasticSearchInfo"> | ||
5 | + <!--@mbg.generated--> | ||
6 | + <!--@Table elastic_search_info--> | ||
7 | + <id column="id" jdbcType="VARCHAR" property="id"/> | ||
8 | + <result column="cluster_name" jdbcType="VARCHAR" property="clusterName"/> | ||
9 | + <result column="elasticsearch_name" jdbcType="VARCHAR" property="elasticsearchName"/> | ||
10 | + <result column="hostname" jdbcType="VARCHAR" property="hostname"/> | ||
11 | + <result column="port" jdbcType="INTEGER" property="port"/> | ||
12 | + <result column="scheme" jdbcType="VARCHAR" property="scheme"/> | ||
13 | + <result column="is_master" jdbcType="BOOLEAN" property="isMaster"/> | ||
14 | + <result column="elasticsearch_state" jdbcType="BOOLEAN" property="elasticsearchState"/> | ||
15 | + <result column="description" jdbcType="VARCHAR" property="description"/> | ||
16 | + <result column="gmt_create" jdbcType="TIMESTAMP" property="gmtCreate"/> | ||
17 | + <result column="gmt_modified" jdbcType="TIMESTAMP" property="gmtModified"/> | ||
18 | + </resultMap> | ||
19 | + <sql id="Base_Column_List"> | ||
20 | + <!--@mbg.generated--> | ||
21 | + id, cluster_name, elasticsearch_name, hostname, port, scheme, is_master, elasticsearch_state, | ||
22 | + description, gmt_create, gmt_modified | ||
23 | + </sql> | ||
24 | + <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap"> | ||
25 | + <!--@mbg.generated--> | ||
26 | + select | ||
27 | + <include refid="Base_Column_List"/> | ||
28 | + from elastic_search_info | ||
29 | + where id = #{id,jdbcType=VARCHAR} | ||
30 | + </select> | ||
31 | + | ||
32 | + <!-- 分页查询, --> | ||
33 | + <select id="selectListByPage" parameterType="com.sunyo.wlpt.message.bus.service.domain.es.ElasticSearchInfo" | ||
34 | + resultMap="BaseResultMap"> | ||
35 | + <!--@mbg.generated--> | ||
36 | + select | ||
37 | + <include refid="Base_Column_List"/> | ||
38 | + from elastic_search_info | ||
39 | + <where> | ||
40 | + <if test="clusterName != null and clusterName != ''"> | ||
41 | + cluster_name = #{clusterName,jdbcType=VARCHAR} | ||
42 | + </if> | ||
43 | + <if test="elasticsearchName != null and elasticsearchName != ''"> | ||
44 | + and elasticsearch_name = #{elasticsearchName,jdbcType=VARCHAR} | ||
45 | + </if> | ||
46 | + <if test="elasticsearchState != null and elasticsearchState != ''"> | ||
47 | + and elasticsearch_state = #{elasticsearchState,jdbcType=BOOLEAN} | ||
48 | + </if> | ||
49 | + </where> | ||
50 | + </select> | ||
51 | + <!-- 查询ES的所有列表 --> | ||
52 | + <select id="selectList" resultMap="BaseResultMap"> | ||
53 | + <!--@mbg.generated--> | ||
54 | + select | ||
55 | + <include refid="Base_Column_List"/> | ||
56 | + from elastic_search_info | ||
57 | + </select> | ||
58 | + <!-- 根据ES名称(即节点名称)查询 --> | ||
59 | + <select id="selectListByElasticsearchName" parameterType="java.lang.String" resultMap="BaseResultMap"> | ||
60 | + select | ||
61 | + <include refid="Base_Column_List"/> | ||
62 | + from elastic_search_info | ||
63 | + where elasticsearch_name = #{elasticsearchName,jdbcType=VARCHAR} | ||
64 | + </select> | ||
65 | + <!-- 根据Url信息查询 --> | ||
66 | + <select id="selectByUrl" resultMap="BaseResultMap"> | ||
67 | + select | ||
68 | + <include refid="Base_Column_List"/> | ||
69 | + from elastic_search_info | ||
70 | + where hostname = #{hostname,jdbcType=VARCHAR} | ||
71 | + and scheme = #{scheme,jdbcType=VARCHAR} | ||
72 | + and port = #{port,jdbcType=INTEGER} | ||
73 | + </select> | ||
74 | + <delete id="deleteByPrimaryKey" parameterType="java.lang.String"> | ||
75 | + <!--@mbg.generated--> | ||
76 | + delete | ||
77 | + from elastic_search_info | ||
78 | + where id = #{id,jdbcType=VARCHAR} | ||
79 | + </delete> | ||
80 | + | ||
81 | + <delete id="batchRemoveByIds" parameterType="java.lang.String"> | ||
82 | + <!--@mbg.generated--> | ||
83 | + delete | ||
84 | + from elastic_search_info | ||
85 | + where id in | ||
86 | + <foreach collection="array" open="(" close=")" separator="," item="id"> | ||
87 | + #{id} | ||
88 | + </foreach> | ||
89 | + </delete> | ||
90 | + | ||
91 | + <insert id="insert" parameterType="com.sunyo.wlpt.message.bus.service.domain.es.ElasticSearchInfo"> | ||
92 | + <!--@mbg.generated--> | ||
93 | + insert into elastic_search_info (id, cluster_name, elasticsearch_name, | ||
94 | + hostname, port, scheme, | ||
95 | + is_master, elasticsearch_state, description, | ||
96 | + gmt_create, gmt_modified) | ||
97 | + values (#{id,jdbcType=VARCHAR}, #{clusterName,jdbcType=VARCHAR}, #{elasticsearchName,jdbcType=VARCHAR}, | ||
98 | + #{hostname,jdbcType=VARCHAR}, #{port,jdbcType=INTEGER}, #{scheme,jdbcType=VARCHAR}, | ||
99 | + #{isMaster,jdbcType=BOOLEAN}, #{elasticsearchState,jdbcType=BOOLEAN}, #{description,jdbcType=VARCHAR}, | ||
100 | + #{gmtCreate,jdbcType=TIMESTAMP}, #{gmtModified,jdbcType=TIMESTAMP}) | ||
101 | + </insert> | ||
102 | + <insert id="insertSelective" parameterType="com.sunyo.wlpt.message.bus.service.domain.es.ElasticSearchInfo"> | ||
103 | + <!--@mbg.generated--> | ||
104 | + insert into elastic_search_info | ||
105 | + <trim prefix="(" suffix=")" suffixOverrides=","> | ||
106 | + <if test="id != null"> | ||
107 | + id, | ||
108 | + </if> | ||
109 | + <if test="clusterName != null"> | ||
110 | + cluster_name, | ||
111 | + </if> | ||
112 | + <if test="elasticsearchName != null"> | ||
113 | + elasticsearch_name, | ||
114 | + </if> | ||
115 | + <if test="hostname != null"> | ||
116 | + hostname, | ||
117 | + </if> | ||
118 | + <if test="port != null"> | ||
119 | + port, | ||
120 | + </if> | ||
121 | + <if test="scheme != null"> | ||
122 | + scheme, | ||
123 | + </if> | ||
124 | + <if test="isMaster != null"> | ||
125 | + is_master, | ||
126 | + </if> | ||
127 | + <if test="elasticsearchState != null"> | ||
128 | + elasticsearch_state, | ||
129 | + </if> | ||
130 | + <if test="description != null"> | ||
131 | + description, | ||
132 | + </if> | ||
133 | + <if test="gmtCreate != null"> | ||
134 | + gmt_create, | ||
135 | + </if> | ||
136 | + <if test="gmtModified != null"> | ||
137 | + gmt_modified, | ||
138 | + </if> | ||
139 | + </trim> | ||
140 | + <trim prefix="values (" suffix=")" suffixOverrides=","> | ||
141 | + <if test="id != null"> | ||
142 | + #{id,jdbcType=VARCHAR}, | ||
143 | + </if> | ||
144 | + <if test="clusterName != null"> | ||
145 | + #{clusterName,jdbcType=VARCHAR}, | ||
146 | + </if> | ||
147 | + <if test="elasticsearchName != null"> | ||
148 | + #{elasticsearchName,jdbcType=VARCHAR}, | ||
149 | + </if> | ||
150 | + <if test="hostname != null"> | ||
151 | + #{hostname,jdbcType=VARCHAR}, | ||
152 | + </if> | ||
153 | + <if test="port != null"> | ||
154 | + #{port,jdbcType=INTEGER}, | ||
155 | + </if> | ||
156 | + <if test="scheme != null"> | ||
157 | + #{scheme,jdbcType=VARCHAR}, | ||
158 | + </if> | ||
159 | + <if test="isMaster != null"> | ||
160 | + #{isMaster,jdbcType=BOOLEAN}, | ||
161 | + </if> | ||
162 | + <if test="elasticsearchState != null"> | ||
163 | + #{elasticsearchState,jdbcType=BOOLEAN}, | ||
164 | + </if> | ||
165 | + <if test="description != null"> | ||
166 | + #{description,jdbcType=VARCHAR}, | ||
167 | + </if> | ||
168 | + <if test="gmtCreate != null"> | ||
169 | + #{gmtCreate,jdbcType=TIMESTAMP}, | ||
170 | + </if> | ||
171 | + <if test="gmtModified != null"> | ||
172 | + #{gmtModified,jdbcType=TIMESTAMP}, | ||
173 | + </if> | ||
174 | + </trim> | ||
175 | + </insert> | ||
176 | + <update id="updateByPrimaryKeySelective" parameterType="com.sunyo.wlpt.message.bus.service.domain.es.ElasticSearchInfo"> | ||
177 | + <!--@mbg.generated--> | ||
178 | + update elastic_search_info | ||
179 | + <set> | ||
180 | + <if test="clusterName != null"> | ||
181 | + cluster_name = #{clusterName,jdbcType=VARCHAR}, | ||
182 | + </if> | ||
183 | + <if test="elasticsearchName != null"> | ||
184 | + elasticsearch_name = #{elasticsearchName,jdbcType=VARCHAR}, | ||
185 | + </if> | ||
186 | + <if test="hostname != null"> | ||
187 | + hostname = #{hostname,jdbcType=VARCHAR}, | ||
188 | + </if> | ||
189 | + <if test="port != null"> | ||
190 | + port = #{port,jdbcType=INTEGER}, | ||
191 | + </if> | ||
192 | + <if test="scheme != null"> | ||
193 | + scheme = #{scheme,jdbcType=VARCHAR}, | ||
194 | + </if> | ||
195 | + <if test="isMaster != null"> | ||
196 | + is_master = #{isMaster,jdbcType=BOOLEAN}, | ||
197 | + </if> | ||
198 | + <if test="elasticsearchState != null"> | ||
199 | + elasticsearch_state = #{elasticsearchState,jdbcType=BOOLEAN}, | ||
200 | + </if> | ||
201 | + <if test="description != null"> | ||
202 | + description = #{description,jdbcType=VARCHAR}, | ||
203 | + </if> | ||
204 | + <if test="gmtCreate != null"> | ||
205 | + gmt_create = #{gmtCreate,jdbcType=TIMESTAMP}, | ||
206 | + </if> | ||
207 | + <if test="gmtModified != null"> | ||
208 | + gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}, | ||
209 | + </if> | ||
210 | + </set> | ||
211 | + where id = #{id,jdbcType=VARCHAR} | ||
212 | + </update> | ||
213 | + <update id="updateByPrimaryKey" parameterType="com.sunyo.wlpt.message.bus.service.domain.es.ElasticSearchInfo"> | ||
214 | + <!--@mbg.generated--> | ||
215 | + update elastic_search_info | ||
216 | + set cluster_name = #{clusterName,jdbcType=VARCHAR}, | ||
217 | + elasticsearch_name = #{elasticsearchName,jdbcType=VARCHAR}, | ||
218 | + hostname = #{hostname,jdbcType=VARCHAR}, | ||
219 | + port = #{port,jdbcType=INTEGER}, | ||
220 | + scheme = #{scheme,jdbcType=VARCHAR}, | ||
221 | + is_master = #{isMaster,jdbcType=BOOLEAN}, | ||
222 | + elasticsearch_state = #{elasticsearchState,jdbcType=BOOLEAN}, | ||
223 | + description = #{description,jdbcType=VARCHAR}, | ||
224 | + gmt_create = #{gmtCreate,jdbcType=TIMESTAMP}, | ||
225 | + gmt_modified = #{gmtModified,jdbcType=TIMESTAMP} | ||
226 | + where id = #{id,jdbcType=VARCHAR} | ||
227 | + </update> | ||
228 | +</mapper> |
-
请 注册 或 登录 后发表评论