Skip to content

Commit b421cb5

Browse files
committed
Cluster Name config in Transport Client
1 parent af97fdb commit b421cb5

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public class TransportClientFactoryBean implements FactoryBean<TransportClient>,
4141

4242
private static final Logger logger = LoggerFactory.getLogger(TransportClientFactoryBean.class);
4343
private String clusterNodes;
44+
private String clusterName;
45+
private Boolean enableHttp;
46+
private Boolean clientTransportSniff;
4447
private TransportClient client;
4548
private Properties properties;
4649
static final String COLON = ":";
@@ -96,13 +99,29 @@ private Settings settings() {
9699
if (properties != null) {
97100
return settingsBuilder().put(properties).build();
98101
}
99-
return settingsBuilder().put("client.transport.sniff", true).build();
102+
return settingsBuilder()
103+
.put("cluster.name", clusterName)
104+
.put("client.transport.sniff", clientTransportSniff)
105+
.put("http.enabled", enableHttp)
106+
.build();
100107
}
101108

102109
public void setClusterNodes(String clusterNodes) {
103110
this.clusterNodes = clusterNodes;
104111
}
105112

113+
public void setClusterName(String clusterName) {
114+
this.clusterName = clusterName;
115+
}
116+
117+
public void setEnableHttp(Boolean enableHttp) {
118+
this.enableHttp = enableHttp;
119+
}
120+
121+
public void setClientTransportSniff(Boolean clientTransportSniff) {
122+
this.clientTransportSniff = clientTransportSniff;
123+
}
124+
106125
public void setProperties(Properties properties) {
107126
this.properties = properties;
108127
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ protected AbstractBeanDefinition parseInternal(Element element, ParserContext pa
4242

4343
private void setClusterNodes(Element element, BeanDefinitionBuilder builder) {
4444
builder.addPropertyValue("clusterNodes", element.getAttribute("cluster-nodes"));
45+
builder.addPropertyValue("clusterName", element.getAttribute("cluster-name"));
46+
builder.addPropertyValue("enableHttp", Boolean.valueOf(element.getAttribute("http-enabled")));
47+
builder.addPropertyValue("clientTransportSniff", Boolean.valueOf(element.getAttribute("client-transport-sniff")));
4548
}
4649

4750
private AbstractBeanDefinition getSourcedBeanDefinition(BeanDefinitionBuilder builder, Element source,

src/main/resources/org/springframework/data/elasticsearch/config/spring-elasticsearch-1.0.xsd

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,21 @@
4444
<xsd:complexType>
4545
<xsd:complexContent>
4646
<xsd:extension base="beans:identifiedType">
47-
<xsd:attribute name="local" type="xsd:boolean" default="false"/>
48-
<xsd:attribute name="cluster-name" type="xsd:string" default="elasticsearch"/>
49-
<xsd:attribute name="http-enabled" type="xsd:boolean" default="true"/>
47+
<xsd:attribute name="local" type="xsd:boolean" default="false">
48+
<xsd:annotation>
49+
<xsd:documentation><![CDATA[local here means local on the JVM (well, actually class loader) level, meaning that two local servers started within the same JVM will discover themselves and form a cluster]]></xsd:documentation>
50+
</xsd:annotation>
51+
</xsd:attribute>
52+
<xsd:attribute name="cluster-name" type="xsd:string" default="elasticsearch">
53+
<xsd:annotation>
54+
<xsd:documentation><![CDATA[Name of the cluster in which this instance of node client will connect to]]> </xsd:documentation>
55+
</xsd:annotation>
56+
</xsd:attribute>
57+
<xsd:attribute name="http-enabled" type="xsd:boolean" default="true">
58+
<xsd:annotation>
59+
<xsd:documentation><![CDATA[to enable or desable http port]]> </xsd:documentation>
60+
</xsd:annotation>
61+
</xsd:attribute>
5062
</xsd:extension>
5163
</xsd:complexContent>
5264
</xsd:complexType>
@@ -67,6 +79,21 @@
6779
<xsd:documentation><![CDATA[The comma delimited list of host:port entries to use for elasticsearch cluster.]]></xsd:documentation>
6880
</xsd:annotation>
6981
</xsd:attribute>
82+
<xsd:attribute name="cluster-name" type="xsd:string" default="elasticsearch">
83+
<xsd:annotation>
84+
<xsd:documentation><![CDATA[Name of the cluster in which this instance of node client will connect to]]> </xsd:documentation>
85+
</xsd:annotation>
86+
</xsd:attribute>
87+
<xsd:attribute name="http-enabled" type="xsd:boolean" default="true">
88+
<xsd:annotation>
89+
<xsd:documentation><![CDATA[to enable or desable http port]]> </xsd:documentation>
90+
</xsd:annotation>
91+
</xsd:attribute>
92+
<xsd:attribute name="client-transport-sniff" type="xsd:boolean" default="true">
93+
<xsd:annotation>
94+
<xsd:documentation><![CDATA[The client allows to sniff the rest of the cluster, and add those into its list of machines to use.]]> </xsd:documentation>
95+
</xsd:annotation>
96+
</xsd:attribute>
7097
</xsd:extension>
7198
</xsd:complexContent>
7299
</xsd:complexType>

0 commit comments

Comments
 (0)