Skip to content

Commit 151c623

Browse files
committed
DATAES-9 : multiple elasticsearch cluster nodes not getting parsed if using property file
1 parent 7df712a commit 151c623

File tree

2 files changed

+61
-63
lines changed

2 files changed

+61
-63
lines changed

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

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -27,83 +27,83 @@
2727

2828
import java.util.Properties;
2929

30-
import static org.apache.commons.lang.StringUtils.substringAfter;
31-
import static org.apache.commons.lang.StringUtils.substringBefore;
30+
import static org.apache.commons.lang.StringUtils.*;
3231
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
3332

3433
/**
3534
* TransportClientFactoryBean
36-
*
35+
*
3736
* @author Rizwan Idrees
3837
* @author Mohsin Husen
3938
*/
4039

4140
public class TransportClientFactoryBean implements FactoryBean<TransportClient>, InitializingBean, DisposableBean {
4241

43-
private static final Logger logger = LoggerFactory.getLogger(TransportClientFactoryBean.class);
44-
private String[] clusterNodes;
45-
private TransportClient client;
46-
private Properties properties;
47-
static final String COLON = ":";
42+
private static final Logger logger = LoggerFactory.getLogger(TransportClientFactoryBean.class);
43+
private String clusterNodes;
44+
private TransportClient client;
45+
private Properties properties;
46+
static final String COLON = ":";
47+
static final String COMMA = ",";
4848

49-
@Override
50-
public void destroy() throws Exception {
51-
try {
52-
logger.info("Closing elasticSearch client");
53-
if (client != null) {
54-
client.close();
55-
}
56-
} catch (final Exception e) {
57-
logger.error("Error closing ElasticSearch client: ", e);
58-
}
59-
}
49+
@Override
50+
public void destroy() throws Exception {
51+
try {
52+
logger.info("Closing elasticSearch client");
53+
if (client != null) {
54+
client.close();
55+
}
56+
} catch (final Exception e) {
57+
logger.error("Error closing ElasticSearch client: ", e);
58+
}
59+
}
6060

61-
@Override
62-
public TransportClient getObject() throws Exception {
63-
return client;
64-
}
61+
@Override
62+
public TransportClient getObject() throws Exception {
63+
return client;
64+
}
6565

66-
@Override
67-
public Class<TransportClient> getObjectType() {
68-
return TransportClient.class;
69-
}
66+
@Override
67+
public Class<TransportClient> getObjectType() {
68+
return TransportClient.class;
69+
}
7070

71-
@Override
72-
public boolean isSingleton() {
73-
return false;
74-
}
71+
@Override
72+
public boolean isSingleton() {
73+
return false;
74+
}
7575

76-
@Override
77-
public void afterPropertiesSet() throws Exception {
78-
buildClient();
79-
}
76+
@Override
77+
public void afterPropertiesSet() throws Exception {
78+
buildClient();
79+
}
8080

81-
protected void buildClient() throws Exception {
82-
client = new TransportClient(settings());
83-
Assert.notEmpty(clusterNodes, "[Assertion failed] clusterNodes settings missing.");
84-
for (String clusterNode : clusterNodes) {
85-
String hostName = substringBefore(clusterNode, COLON);
86-
String port = substringAfter(clusterNode, COLON);
87-
Assert.hasText(hostName, "[Assertion failed] missing host name in 'clusterNodes'");
88-
Assert.hasText(port, "[Assertion failed] missing port in 'clusterNodes'");
89-
logger.info("adding transport node : " + clusterNode);
90-
client.addTransportAddress(new InetSocketTransportAddress(hostName, Integer.valueOf(port)));
91-
}
92-
client.connectedNodes();
93-
}
81+
protected void buildClient() throws Exception {
82+
client = new TransportClient(settings());
83+
Assert.hasText(clusterNodes, "[Assertion failed] clusterNodes settings missing.");
84+
for (String clusterNode : split(clusterNodes,COMMA)) {
85+
String hostName = substringBefore(clusterNode, COLON);
86+
String port = substringAfter(clusterNode, COLON);
87+
Assert.hasText(hostName, "[Assertion failed] missing host name in 'clusterNodes'");
88+
Assert.hasText(port, "[Assertion failed] missing port in 'clusterNodes'");
89+
logger.info("adding transport node : " + clusterNode);
90+
client.addTransportAddress(new InetSocketTransportAddress(hostName, Integer.valueOf(port)));
91+
}
92+
client.connectedNodes();
93+
}
9494

95-
private Settings settings() {
96-
if (properties != null) {
97-
return settingsBuilder().put(properties).build();
98-
}
99-
return settingsBuilder().put("client.transport.sniff", true).build();
100-
}
95+
private Settings settings() {
96+
if (properties != null) {
97+
return settingsBuilder().put(properties).build();
98+
}
99+
return settingsBuilder().put("client.transport.sniff", true).build();
100+
}
101101

102-
public void setClusterNodes(String[] clusterNodes) {
103-
this.clusterNodes = clusterNodes;
104-
}
102+
public void setClusterNodes(String clusterNodes) {
103+
this.clusterNodes = clusterNodes;
104+
}
105105

106-
public void setProperties(Properties properties) {
107-
this.properties = properties;
108-
}
106+
public void setProperties(Properties properties) {
107+
this.properties = properties;
108+
}
109109
}

src/main/java/org/springframework/data/elasticsearch/config/TransportClientBeanDefinitionParser.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333

3434
public class TransportClientBeanDefinitionParser extends AbstractBeanDefinitionParser {
3535

36-
private static final String SEPARATOR_CHARS = ",";
37-
3836
@Override
3937
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
4038
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(TransportClientFactoryBean.class);
@@ -43,7 +41,7 @@ protected AbstractBeanDefinition parseInternal(Element element, ParserContext pa
4341
}
4442

4543
private void setClusterNodes(Element element, BeanDefinitionBuilder builder) {
46-
builder.addPropertyValue("clusterNodes", split(element.getAttribute("cluster-nodes"), SEPARATOR_CHARS));
44+
builder.addPropertyValue("clusterNodes", element.getAttribute("cluster-nodes"));
4745
}
4846

4947
private AbstractBeanDefinition getSourcedBeanDefinition(BeanDefinitionBuilder builder, Element source,

0 commit comments

Comments
 (0)