Skip to content

Commit e7b93be

Browse files
rivergodakonczak
authored andcommitted
DATAES-421 - Update ES to 6.1.0
1 parent 9bc9c47 commit e7b93be

24 files changed

+271
-346
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
<properties>
2020
<commonscollections>3.2.1</commonscollections>
2121
<commonslang>2.6</commonslang>
22-
<elasticsearch>5.5.0</elasticsearch>
23-
<log4j>2.8.2</log4j>
22+
<elasticsearch>6.1.0</elasticsearch>
23+
<log4j>2.9.1</log4j>
2424
<springdata.commons>2.1.0.BUILD-SNAPSHOT</springdata.commons>
2525
<java-module-name>spring.data.elasticsearch</java-module-name>
2626
</properties>

src/main/java/org/springframework/data/elasticsearch/client/NodeClientFactoryBean.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
*
3939
* @author Rizwan Idrees
4040
* @author Mohsin Husen
41+
* @author Ilkang Na
4142
*/
4243

4344
public class NodeClientFactoryBean implements FactoryBean<Client>, InitializingBean, DisposableBean {
@@ -85,21 +86,19 @@ public void afterPropertiesSet() throws Exception {
8586
nodeClient = (NodeClient) new TestNode(
8687
Settings.builder().put(loadConfig())
8788
.put("transport.type", "netty4")
88-
.put("transport.type", "local")
8989
.put("http.type", "netty4")
9090
.put("path.home", this.pathHome)
9191
.put("path.data", this.pathData)
9292
.put("cluster.name", this.clusterName)
9393
.put("node.max_local_storage_nodes", 100)
94-
.put("script.inline", "true")
9594
.build(), asList(Netty4Plugin.class)).start().client();
9695
}
9796

9897
private Settings loadConfig() throws IOException {
9998
if (StringUtils.isNotBlank(pathConfiguration)) {
10099
InputStream stream = getClass().getClassLoader().getResourceAsStream(pathConfiguration);
101100
if (stream != null) {
102-
return Settings.builder().loadFromStream(pathConfiguration, getClass().getClassLoader().getResourceAsStream(pathConfiguration)).build();
101+
return Settings.builder().loadFromStream(pathConfiguration, getClass().getClassLoader().getResourceAsStream(pathConfiguration), false).build();
103102
}
104103
logger.error(String.format("Unable to read node configuration from file [%s]", pathConfiguration));
105104
}
Lines changed: 163 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -1,156 +1,163 @@
1-
/*
2-
* Copyright 2013 the original author or authors.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
package org.springframework.data.elasticsearch.client;
17-
18-
import static org.apache.commons.lang.StringUtils.*;
19-
20-
import java.net.InetAddress;
21-
import java.util.Properties;
22-
23-
import org.elasticsearch.client.transport.TransportClient;
24-
import org.elasticsearch.common.settings.Settings;
25-
import org.elasticsearch.common.transport.InetSocketTransportAddress;
26-
import org.elasticsearch.transport.client.PreBuiltTransportClient;
27-
import org.slf4j.Logger;
28-
import org.slf4j.LoggerFactory;
29-
import org.springframework.beans.factory.DisposableBean;
30-
import org.springframework.beans.factory.FactoryBean;
31-
import org.springframework.beans.factory.InitializingBean;
32-
import org.springframework.util.Assert;
33-
34-
/**
35-
* TransportClientFactoryBean
36-
*
37-
* @author Rizwan Idrees
38-
* @author Mohsin Husen
39-
* @author Jakub Vavrik
40-
* @author Piotr Betkier
41-
*/
42-
43-
public class TransportClientFactoryBean implements FactoryBean<TransportClient>, InitializingBean, DisposableBean {
44-
45-
private static final Logger logger = LoggerFactory.getLogger(TransportClientFactoryBean.class);
46-
private String clusterNodes = "127.0.0.1:9300";
47-
private String clusterName = "elasticsearch";
48-
private Boolean clientTransportSniff = true;
49-
private Boolean clientIgnoreClusterName = Boolean.FALSE;
50-
private String clientPingTimeout = "5s";
51-
private String clientNodesSamplerInterval = "5s";
52-
private TransportClient client;
53-
private Properties properties;
54-
static final String COLON = ":";
55-
static final String COMMA = ",";
56-
57-
@Override
58-
public void destroy() throws Exception {
59-
try {
60-
logger.info("Closing elasticSearch client");
61-
if (client != null) {
62-
client.close();
63-
}
64-
} catch (final Exception e) {
65-
logger.error("Error closing ElasticSearch client: ", e);
66-
}
67-
}
68-
69-
@Override
70-
public TransportClient getObject() throws Exception {
71-
return client;
72-
}
73-
74-
@Override
75-
public Class<TransportClient> getObjectType() {
76-
return TransportClient.class;
77-
}
78-
79-
@Override
80-
public boolean isSingleton() {
81-
return false;
82-
}
83-
84-
@Override
85-
public void afterPropertiesSet() throws Exception {
86-
buildClient();
87-
}
88-
89-
protected void buildClient() throws Exception {
90-
91-
client = new PreBuiltTransportClient(settings());
92-
Assert.hasText(clusterNodes, "[Assertion failed] clusterNodes settings missing.");
93-
for (String clusterNode : split(clusterNodes, COMMA)) {
94-
String hostName = substringBeforeLast(clusterNode, COLON);
95-
String port = substringAfterLast(clusterNode, COLON);
96-
Assert.hasText(hostName, "[Assertion failed] missing host name in 'clusterNodes'");
97-
Assert.hasText(port, "[Assertion failed] missing port in 'clusterNodes'");
98-
logger.info("adding transport node : " + clusterNode);
99-
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostName), Integer.valueOf(port)));
100-
}
101-
client.connectedNodes();
102-
}
103-
104-
private Settings settings() {
105-
if (properties != null) {
106-
return Settings.builder().put(properties).build();
107-
}
108-
return Settings.builder()
109-
.put("cluster.name", clusterName)
110-
.put("client.transport.sniff", clientTransportSniff)
111-
.put("client.transport.ignore_cluster_name", clientIgnoreClusterName)
112-
.put("client.transport.ping_timeout", clientPingTimeout)
113-
.put("client.transport.nodes_sampler_interval", clientNodesSamplerInterval)
114-
.build();
115-
}
116-
117-
public void setClusterNodes(String clusterNodes) {
118-
this.clusterNodes = clusterNodes;
119-
}
120-
121-
public void setClusterName(String clusterName) {
122-
this.clusterName = clusterName;
123-
}
124-
125-
public void setClientTransportSniff(Boolean clientTransportSniff) {
126-
this.clientTransportSniff = clientTransportSniff;
127-
}
128-
129-
public String getClientNodesSamplerInterval() {
130-
return clientNodesSamplerInterval;
131-
}
132-
133-
public void setClientNodesSamplerInterval(String clientNodesSamplerInterval) {
134-
this.clientNodesSamplerInterval = clientNodesSamplerInterval;
135-
}
136-
137-
public String getClientPingTimeout() {
138-
return clientPingTimeout;
139-
}
140-
141-
public void setClientPingTimeout(String clientPingTimeout) {
142-
this.clientPingTimeout = clientPingTimeout;
143-
}
144-
145-
public Boolean getClientIgnoreClusterName() {
146-
return clientIgnoreClusterName;
147-
}
148-
149-
public void setClientIgnoreClusterName(Boolean clientIgnoreClusterName) {
150-
this.clientIgnoreClusterName = clientIgnoreClusterName;
151-
}
152-
153-
public void setProperties(Properties properties) {
154-
this.properties = properties;
155-
}
156-
}
1+
/*
2+
* Copyright 2013 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.elasticsearch.client;
17+
18+
import static org.apache.commons.lang.StringUtils.*;
19+
20+
import java.net.InetAddress;
21+
import java.util.Properties;
22+
23+
import org.elasticsearch.client.transport.TransportClient;
24+
import org.elasticsearch.common.settings.Settings;
25+
import org.elasticsearch.common.transport.TransportAddress;
26+
import org.elasticsearch.transport.client.PreBuiltTransportClient;
27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
29+
import org.springframework.beans.factory.DisposableBean;
30+
import org.springframework.beans.factory.FactoryBean;
31+
import org.springframework.beans.factory.InitializingBean;
32+
import org.springframework.util.Assert;
33+
34+
/**
35+
* TransportClientFactoryBean
36+
*
37+
* @author Rizwan Idrees
38+
* @author Mohsin Husen
39+
* @author Jakub Vavrik
40+
* @author Piotr Betkier
41+
* @author Ilkang Na
42+
*/
43+
44+
public class TransportClientFactoryBean implements FactoryBean<TransportClient>, InitializingBean, DisposableBean {
45+
46+
private static final Logger logger = LoggerFactory.getLogger(TransportClientFactoryBean.class);
47+
private String clusterNodes = "127.0.0.1:9300";
48+
private String clusterName = "elasticsearch";
49+
private Boolean clientTransportSniff = true;
50+
private Boolean clientIgnoreClusterName = Boolean.FALSE;
51+
private String clientPingTimeout = "5s";
52+
private String clientNodesSamplerInterval = "5s";
53+
private TransportClient client;
54+
private Properties properties;
55+
static final String COLON = ":";
56+
static final String COMMA = ",";
57+
58+
@Override
59+
public void destroy() throws Exception {
60+
try {
61+
logger.info("Closing elasticSearch client");
62+
if (client != null) {
63+
client.close();
64+
}
65+
} catch (final Exception e) {
66+
logger.error("Error closing ElasticSearch client: ", e);
67+
}
68+
}
69+
70+
@Override
71+
public TransportClient getObject() throws Exception {
72+
return client;
73+
}
74+
75+
@Override
76+
public Class<TransportClient> getObjectType() {
77+
return TransportClient.class;
78+
}
79+
80+
@Override
81+
public boolean isSingleton() {
82+
return false;
83+
}
84+
85+
@Override
86+
public void afterPropertiesSet() throws Exception {
87+
buildClient();
88+
}
89+
90+
protected void buildClient() throws Exception {
91+
92+
client = new PreBuiltTransportClient(settings());
93+
Assert.hasText(clusterNodes, "[Assertion failed] clusterNodes settings missing.");
94+
for (String clusterNode : split(clusterNodes, COMMA)) {
95+
String hostName = substringBeforeLast(clusterNode, COLON);
96+
String port = substringAfterLast(clusterNode, COLON);
97+
Assert.hasText(hostName, "[Assertion failed] missing host name in 'clusterNodes'");
98+
Assert.hasText(port, "[Assertion failed] missing port in 'clusterNodes'");
99+
logger.info("adding transport node : " + clusterNode);
100+
client.addTransportAddress(new TransportAddress(InetAddress.getByName(hostName), Integer.valueOf(port)));
101+
}
102+
client.connectedNodes();
103+
}
104+
105+
private Settings settings() {
106+
if (properties != null) {
107+
Settings.Builder builder = Settings.builder();
108+
109+
properties.forEach((key, value) -> {
110+
builder.put(key.toString(), value.toString());
111+
});
112+
113+
return builder.build();
114+
}
115+
return Settings.builder()
116+
.put("cluster.name", clusterName)
117+
.put("client.transport.sniff", clientTransportSniff)
118+
.put("client.transport.ignore_cluster_name", clientIgnoreClusterName)
119+
.put("client.transport.ping_timeout", clientPingTimeout)
120+
.put("client.transport.nodes_sampler_interval", clientNodesSamplerInterval)
121+
.build();
122+
}
123+
124+
public void setClusterNodes(String clusterNodes) {
125+
this.clusterNodes = clusterNodes;
126+
}
127+
128+
public void setClusterName(String clusterName) {
129+
this.clusterName = clusterName;
130+
}
131+
132+
public void setClientTransportSniff(Boolean clientTransportSniff) {
133+
this.clientTransportSniff = clientTransportSniff;
134+
}
135+
136+
public String getClientNodesSamplerInterval() {
137+
return clientNodesSamplerInterval;
138+
}
139+
140+
public void setClientNodesSamplerInterval(String clientNodesSamplerInterval) {
141+
this.clientNodesSamplerInterval = clientNodesSamplerInterval;
142+
}
143+
144+
public String getClientPingTimeout() {
145+
return clientPingTimeout;
146+
}
147+
148+
public void setClientPingTimeout(String clientPingTimeout) {
149+
this.clientPingTimeout = clientPingTimeout;
150+
}
151+
152+
public Boolean getClientIgnoreClusterName() {
153+
return clientIgnoreClusterName;
154+
}
155+
156+
public void setClientIgnoreClusterName(Boolean clientIgnoreClusterName) {
157+
this.clientIgnoreClusterName = clientIgnoreClusterName;
158+
}
159+
160+
public void setProperties(Properties properties) {
161+
this.properties = properties;
162+
}
163+
}

0 commit comments

Comments
 (0)