Skip to content

Commit

Permalink
Merge branch '1.2.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona committed Mar 18, 2015
2 parents 8d89f8f + 0a38b9b commit 9444a25
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.boot.autoconfigure.elasticsearch;

import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.elasticsearch.client.Client;
Expand Down Expand Up @@ -75,8 +77,9 @@ private Client createClient() throws Exception {
}

private Client createNodeClient() throws Exception {
ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder().put(
"http.enabled", String.valueOf(false));
ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder()
.put("http.enabled", String.valueOf(false))
.put(this.properties.getProperties());
Node node = new NodeBuilder().settings(settings)
.clusterName(this.properties.getClusterName()).local(true).node();
this.releasable = node;
Expand All @@ -85,15 +88,21 @@ private Client createNodeClient() throws Exception {

private Client createTransportClient() throws Exception {
TransportClientFactoryBean factory = new TransportClientFactoryBean();
factory.setClusterName(this.properties.getClusterName());
factory.setClusterNodes(this.properties.getClusterNodes());
factory.setClientTransportSniff(this.properties.getClientTransportSniff());
factory.setProperties(createProperties());
factory.afterPropertiesSet();
TransportClient client = factory.getObject();
this.releasable = client;
return client;
}

private Properties createProperties() {
Properties properties = new Properties();
properties.put("cluster.name", this.properties.getClusterName());
properties.putAll(this.properties.getProperties());
return properties;
}

@Override
public void destroy() throws Exception {
if (this.releasable != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package org.springframework.boot.autoconfigure.elasticsearch;

import java.util.HashMap;
import java.util.Map;

import org.springframework.boot.context.properties.ConfigurationProperties;

/**
Expand All @@ -40,9 +43,9 @@ public class ElasticsearchProperties {
private String clusterNodes;

/**
* Allow the client to sniff for other members of the cluster.
* Additional properties used to configure the client
*/
private boolean clientTransportSniff = true;
private Map<String, String> properties = new HashMap<String, String>();

public String getClusterName() {
return this.clusterName;
Expand All @@ -60,12 +63,12 @@ public void setClusterNodes(String clusterNodes) {
this.clusterNodes = clusterNodes;
}

public boolean getClientTransportSniff() {
return this.clientTransportSniff;
public Map<String, String> getProperties() {
return this.properties;
}

public void setClientTransportSniff(boolean clientTransportSniff) {
this.clientTransportSniff = clientTransportSniff;
public void setProperties(Map<String, String> properties) {
this.properties = properties;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import org.springframework.boot.test.EnvironmentTestUtils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;

Expand All @@ -52,11 +54,16 @@ public void close() {

@Test
public void createNodeClient() {
this.context = new AnnotationConfigApplicationContext(
PropertyPlaceholderAutoConfiguration.class,
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.data.elasticsearch.properties.foo.bar:baz");
this.context.register(PropertyPlaceholderAutoConfiguration.class,
ElasticsearchAutoConfiguration.class);
this.context.refresh();
assertEquals(1, this.context.getBeanNamesForType(Client.class).length);
assertThat(this.context.getBean(Client.class), instanceOf(NodeClient.class));
Client client = this.context.getBean(Client.class);
assertThat(client, instanceOf(NodeClient.class));
assertThat(((NodeClient) client).settings().get("foo.bar"), is(equalTo("baz")));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,9 @@ content into your application; rather pick only the properties that you need.
spring.data.solr.repositories.enabled=true # if spring data repository support is enabled
# ELASTICSEARCH ({sc-spring-boot-autoconfigure}/elasticsearch/ElasticsearchProperties.{sc-ext}[ElasticsearchProperties])
spring.data.elasticsearch.client-transport-sniff=true # Allow the client to sniff for other members of the cluster
spring.data.elasticsearch.cluster-name= # The cluster name (defaults to elasticsearch)
spring.data.elasticsearch.cluster-nodes= # The address(es) of the server node (comma-separated; if not specified starts a client node)
spring.data.elasticsearch.properties.*= # Additional properties used to configure the client
spring.data.elasticsearch.repositories.enabled=true # if spring data repository support is enabled
# DATA REST ({spring-data-rest-javadoc}/core/config/RepositoryRestConfiguration.{dc-ext}[RepositoryRestConfiguration])
Expand Down

0 comments on commit 9444a25

Please sign in to comment.