Skip to content

Commit

Permalink
Update to elasticsearch 2.0.0
Browse files Browse the repository at this point in the history
Tests fail see: #29 (comment)

Closes #73.
  • Loading branch information
dadoonet committed Oct 12, 2015
1 parent 2617dd5 commit af88902
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 93 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>spring-elasticsearch</artifactId>
<packaging>jar</packaging>
<name>spring-elasticsearch</name>
<version>1.4.3-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
<url>https://github.com/dadoonet/spring-elasticsearch</url>
<description>
Spring factories for Elasticsearch
Expand All @@ -28,8 +28,8 @@

<properties>
<spring.version>4.1.4.RELEASE</spring.version>
<elasticsearch.version>1.5.0</elasticsearch.version>
<beyonder.version>1.5.0</beyonder.version>
<elasticsearch.version>2.0.0-rc1</elasticsearch.version>
<beyonder.version>2.0.0-SNAPSHOT</beyonder.version>
<log4j.version>2.1</log4j.version>
<commons.io.version>2.4</commons.io.version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ private void initMappings() throws Exception {

// Let's initialize indexes and mappings if needed
for (String index : indexes.keySet()) {
createIndex(client, classpathRoot, index);
createIndex(client, classpathRoot, index, forceMapping);
if (mergeSettings) {
updateSettings(client, classpathRoot, index);
}
Expand All @@ -494,7 +494,7 @@ private void initMappings() throws Exception {
for (Iterator<String> iterator = mappings.iterator(); iterator
.hasNext();) {
String type = iterator.next();
createMapping(client, classpathRoot, index, type, mergeMapping, forceMapping);
createMapping(client, classpathRoot, index, type, mergeMapping);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import fr.pilato.spring.elasticsearch.proxy.GenericInvocationHandler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.node.Node;
import org.elasticsearch.node.NodeBuilder;
Expand Down Expand Up @@ -108,8 +107,8 @@ private Node initialize() {
}

if (null != settingsFile && null == properties) {
Settings settings = ImmutableSettings.settingsBuilder()
.loadFromClasspath(this.settingsFile)
Settings settings = Settings.builder()
.loadFromStream(settingsFile, ElasticsearchNodeFactoryBean.class.getResourceAsStream("/" + settingsFile))
.build();
nodeBuilder.getSettings().put(settings);
}
Expand All @@ -121,6 +120,7 @@ private Node initialize() {
if (logger.isDebugEnabled()) logger.debug("Starting ElasticSearch node...");
node = nodeBuilder.node();
logger.info("Node [" + node.settings().get("name") + "] for [" + node.settings().get("cluster.name") + "] cluster started...");
if (logger.isDebugEnabled()) logger.debug(" - home : " + node.settings().get("path.home"));
if (logger.isDebugEnabled()) logger.debug(" - data : " + node.settings().get("path.data"));
if (logger.isDebugEnabled()) logger.debug(" - logs : " + node.settings().get("path.logs"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@
import org.apache.commons.logging.LogFactory;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.springframework.beans.factory.FactoryBean;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
* An {@link FactoryBean} used to create an ElasticSearch Transport {@link Client}.
* <br>
Expand Down Expand Up @@ -88,22 +91,24 @@ public void setEsNodes(String[] esNodes) {

@Override
protected Client buildClient() throws Exception {
ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder();
Settings.Builder builder = Settings.builder();

if (null != this.settings && null == properties) {
builder.put(this.settings);
}

if (null != this.settingsFile && null == properties) {
logger.warn("settings has been deprecated in favor of properties. See issue #15: https://github.com/dadoonet/spring-elasticsearch/issues/15.");
builder.loadFromClasspath(this.settingsFile);
builder.loadFromStream(settingsFile, ElasticsearchTransportClientFactoryBean.class.getResourceAsStream("/" + settingsFile));
}

if (null != this.properties) {
builder.put(this.properties);
}

TransportClient client = new TransportClient(builder.build());
TransportClient client = TransportClient.builder()
.settings(builder.build())
.build();

for (int i = 0; i < esNodes.length; i++) {
client.addTransportAddress(toAddress(esNodes[i]));
Expand All @@ -117,7 +122,7 @@ protected Client buildClient() throws Exception {
* @param address Node address hostname:port (or hostname)
* @return
*/
private InetSocketTransportAddress toAddress(String address) {
private InetSocketTransportAddress toAddress(String address) throws UnknownHostException {
if (address == null) return null;

String[] splitted = address.split(":");
Expand All @@ -126,7 +131,7 @@ private InetSocketTransportAddress toAddress(String address) {
port = Integer.parseInt(splitted[1]);
}

return new InetSocketTransportAddress(splitted[0], port);
return new InetSocketTransportAddress(InetAddress.getByName(splitted[0]), port);
}

}
9 changes: 2 additions & 7 deletions src/test/java/fr/pilato/spring/elasticsearch/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,13 @@ public void createTempDir() throws IOException {
testDir = File.createTempFile("junit", "");
testDir.delete();
testDir.mkdir();
File dataDir = new File(testDir, "data");
File logsDir = new File(testDir, "logs");

System.setProperty("es.path.data", dataDir.getAbsolutePath());
System.setProperty("es.path.logs", logsDir.getAbsolutePath());
System.setProperty("es.path.home", testDir.getAbsolutePath());
}


@After
public void removeTempDir() {
recursiveDelete(testDir);
System.clearProperty("es.path.data");
System.clearProperty("es.path.logs");
System.clearProperty("es.path.home");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MappingMetaData;
import org.elasticsearch.indices.IndexMissingException;
import org.elasticsearch.node.Node;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -131,13 +130,8 @@ protected Node checkNode(String name, boolean async) {
}

protected boolean isMappingExist(Client client, String index, String type) {
IndexMetaData imd = null;
try {
ClusterState cs = client.admin().cluster().prepareState().setIndices(index).execute().actionGet().getState();
imd = cs.getMetaData().index(index);
} catch (IndexMissingException e) {
// If there is no index, there is no mapping either
}
ClusterState cs = client.admin().cluster().prepareState().setIndices(index).get().getState();
IndexMetaData imd = cs.getMetaData().index(index);

if (imd == null) return false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@

import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.collect.ImmutableList;
import org.elasticsearch.common.transport.TransportAddress;
import org.junit.Test;

import java.util.List;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.Matchers.emptyCollectionOf;
import static org.hamcrest.Matchers.is;
Expand All @@ -46,7 +47,7 @@ public void test_transport_client() {
assertThat(client, instanceOf(org.elasticsearch.client.transport.TransportClient.class));

TransportClient tClient = (TransportClient) client;
ImmutableList<TransportAddress> adresses = tClient.transportAddresses();
List<TransportAddress> adresses = tClient.transportAddresses();
assertThat(adresses, not(emptyCollectionOf(TransportAddress.class)));
assertThat(adresses.size(), is(2));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package fr.pilato.spring.elasticsearch.xml;

import fr.pilato.spring.elasticsearch.BaseTest;
import org.elasticsearch.ElasticsearchIllegalArgumentException;
import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.ConfigurableApplicationContext;
Expand All @@ -43,7 +42,7 @@ public void test_merge_settings_failure() {
try {
new ClassPathXmlApplicationContext("models/settings-failed/settings-failed-context.xml");
} catch (BeanCreationException e) {
assertEquals(ElasticsearchIllegalArgumentException.class, e.getCause().getClass());
assertEquals(IllegalArgumentException.class, e.getCause().getClass());
throw e;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.collect.ImmutableList;
import org.elasticsearch.common.transport.TransportAddress;
import org.junit.Test;

import java.util.List;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.Matchers.emptyCollectionOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;


public class TransportClientNamespaceTest extends AbstractXmlContextModel {
Expand All @@ -48,7 +47,7 @@ public void test_transport_client_namespace() {
assertThat(client, instanceOf(org.elasticsearch.client.transport.TransportClient.class));

TransportClient tClient = (TransportClient) client;
ImmutableList<TransportAddress> adresses = tClient.transportAddresses();
List<TransportAddress> adresses = tClient.transportAddresses();
assertThat("Nodes urls must not be empty...", adresses, not(emptyCollectionOf(TransportAddress.class)));

// Testing if we are really connected to a cluster node
Expand Down
11 changes: 1 addition & 10 deletions src/test/resources/es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,8 @@
cluster.name=junit.cluster
name=junit.node

# Disable network
discovery.zen.ping.multicast.enabled=false
node.local=true

# Using less filesystem as possible
index.store.type=memory
index.store.fs.memory.enabled=true
index.gateway.type=none
gateway.type=none

# If ES needs to write something, it's here
path.home=${project.build.directory}/es
path.data=${project.build.directory}/es/data

# Index are minimalists by default
Expand Down
10 changes: 0 additions & 10 deletions src/test/resources/esnode-transport.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@
cluster.name=junit.cluster.transport
name=junit.node.transport

# Disable network
discovery.zen.ping.multicast.enabled=false
node.local=false

# Using less filesystem as possible
index.store.type=memory
index.store.fs.memory.enabled=true
index.gateway.type=none
gateway.type=none

# If ES needs to write something, it's here
# path.data=${project.build.directory}/es/data

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,8 @@
cluster.name=junit.cluster.transport
name=junit.node1.xml

# Disable network
discovery.zen.ping.multicast.enabled=true
#node.local=false

# Using less filesystem as possible
index.store.type=memory
index.store.fs.memory.enabled=true
index.gateway.type=none
gateway.type=none

# If ES needs to write something, it's here
path.home=${project.build.directory}/es
path.data=${project.build.directory}/es/data

# Index are minimalists by default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,8 @@
cluster.name=junit.cluster.transport
name=junit.node2.xml

# Disable network
discovery.zen.ping.multicast.enabled=true
node.local=false

# Using less filesystem as possible
index.store.type=memory
index.store.fs.memory.enabled=true
index.gateway.type=none
gateway.type=none

# If ES needs to write something, it's here
path.home=${project.build.directory}/es
path.data=${project.build.directory}/es/data

# Index are minimalists by default
Expand Down
11 changes: 1 addition & 10 deletions src/test/resources/models/node-namespace/esnode.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,8 @@
cluster.name=junit.cluster.xml
name=junit.node.xml

# Disable network
discovery.zen.ping.multicast.enabled=false
node.local=true

# Using less filesystem as possible
index.store.type=memory
index.store.fs.memory.enabled=true
index.gateway.type=none
gateway.type=none

# If ES needs to write something, it's here
path.home=${project.build.directory}/es
# path.data=${project.build.directory}/es/data

# Index are minimalists by default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@

<util:map id="esProperties">
<entry key="cluster.name" value="newclustername"/>
<entry key="path.home" value="${project.build.directory}/es"/>
<entry key="path.data" value="${project.build.directory}/es/data"/>
<entry key="index.store.type" value="memory"/>
<entry key="index.store.fs.memory.enabled" value="true"/>
<entry key="index.gateway.type" value="none"/>
<entry key="gateway.type" value="none"/>
</util:map>

<elasticsearch:node id="esNode" properties="esProperties" />
Expand Down

0 comments on commit af88902

Please sign in to comment.