From af88902592c5d385216e31228887aa38639d43c6 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Mon, 12 Oct 2015 22:19:53 +0200 Subject: [PATCH] Update to elasticsearch 2.0.0 Tests fail see: https://github.com/dadoonet/spring-elasticsearch/issues/29#issuecomment-147445530 Closes #73. --- pom.xml | 6 +++--- .../ElasticsearchAbstractClientFactoryBean.java | 4 ++-- .../ElasticsearchNodeFactoryBean.java | 6 +++--- ...ElasticsearchTransportClientFactoryBean.java | 17 +++++++++++------ .../pilato/spring/elasticsearch/BaseTest.java | 9 ++------- .../xml/AbstractXmlContextModel.java | 10 ++-------- .../elasticsearch/xml/Settings13Test.java | 5 +++-- .../elasticsearch/xml/SettingsFailedTest.java | 3 +-- .../xml/TransportClientNamespaceTest.java | 11 +++++------ src/test/resources/es.properties | 11 +---------- src/test/resources/esnode-transport.properties | 10 ---------- .../multinodes-namespace/esnode1.properties | 11 +---------- .../multinodes-namespace/esnode2.properties | 11 +---------- .../models/node-namespace/esnode.properties | 11 +---------- .../models/settings-15/settings-15-context.xml | 5 +---- 15 files changed, 37 insertions(+), 93 deletions(-) diff --git a/pom.xml b/pom.xml index f2a3b89b..8b4556a5 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ spring-elasticsearch jar spring-elasticsearch - 1.4.3-SNAPSHOT + 2.0.0-SNAPSHOT https://github.com/dadoonet/spring-elasticsearch Spring factories for Elasticsearch @@ -28,8 +28,8 @@ 4.1.4.RELEASE - 1.5.0 - 1.5.0 + 2.0.0-rc1 + 2.0.0-SNAPSHOT 2.1 2.4 diff --git a/src/main/java/fr/pilato/spring/elasticsearch/ElasticsearchAbstractClientFactoryBean.java b/src/main/java/fr/pilato/spring/elasticsearch/ElasticsearchAbstractClientFactoryBean.java index 62dd8e0b..c1b2194d 100644 --- a/src/main/java/fr/pilato/spring/elasticsearch/ElasticsearchAbstractClientFactoryBean.java +++ b/src/main/java/fr/pilato/spring/elasticsearch/ElasticsearchAbstractClientFactoryBean.java @@ -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); } @@ -494,7 +494,7 @@ private void initMappings() throws Exception { for (Iterator iterator = mappings.iterator(); iterator .hasNext();) { String type = iterator.next(); - createMapping(client, classpathRoot, index, type, mergeMapping, forceMapping); + createMapping(client, classpathRoot, index, type, mergeMapping); } } } diff --git a/src/main/java/fr/pilato/spring/elasticsearch/ElasticsearchNodeFactoryBean.java b/src/main/java/fr/pilato/spring/elasticsearch/ElasticsearchNodeFactoryBean.java index 4747625c..c4269c3c 100644 --- a/src/main/java/fr/pilato/spring/elasticsearch/ElasticsearchNodeFactoryBean.java +++ b/src/main/java/fr/pilato/spring/elasticsearch/ElasticsearchNodeFactoryBean.java @@ -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; @@ -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); } @@ -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")); diff --git a/src/main/java/fr/pilato/spring/elasticsearch/ElasticsearchTransportClientFactoryBean.java b/src/main/java/fr/pilato/spring/elasticsearch/ElasticsearchTransportClientFactoryBean.java index e2954afd..5778c25f 100644 --- a/src/main/java/fr/pilato/spring/elasticsearch/ElasticsearchTransportClientFactoryBean.java +++ b/src/main/java/fr/pilato/spring/elasticsearch/ElasticsearchTransportClientFactoryBean.java @@ -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}. *
@@ -88,7 +91,7 @@ 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); @@ -96,14 +99,16 @@ protected Client buildClient() throws Exception { 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])); @@ -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(":"); @@ -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); } } diff --git a/src/test/java/fr/pilato/spring/elasticsearch/BaseTest.java b/src/test/java/fr/pilato/spring/elasticsearch/BaseTest.java index a318be94..39d4c4bb 100644 --- a/src/test/java/fr/pilato/spring/elasticsearch/BaseTest.java +++ b/src/test/java/fr/pilato/spring/elasticsearch/BaseTest.java @@ -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"); } } diff --git a/src/test/java/fr/pilato/spring/elasticsearch/xml/AbstractXmlContextModel.java b/src/test/java/fr/pilato/spring/elasticsearch/xml/AbstractXmlContextModel.java index 4889b1bc..74f1d6bf 100644 --- a/src/test/java/fr/pilato/spring/elasticsearch/xml/AbstractXmlContextModel.java +++ b/src/test/java/fr/pilato/spring/elasticsearch/xml/AbstractXmlContextModel.java @@ -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; @@ -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; diff --git a/src/test/java/fr/pilato/spring/elasticsearch/xml/Settings13Test.java b/src/test/java/fr/pilato/spring/elasticsearch/xml/Settings13Test.java index 4fed1f2f..6cf8356b 100644 --- a/src/test/java/fr/pilato/spring/elasticsearch/xml/Settings13Test.java +++ b/src/test/java/fr/pilato/spring/elasticsearch/xml/Settings13Test.java @@ -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; @@ -46,7 +47,7 @@ public void test_transport_client() { assertThat(client, instanceOf(org.elasticsearch.client.transport.TransportClient.class)); TransportClient tClient = (TransportClient) client; - ImmutableList adresses = tClient.transportAddresses(); + List adresses = tClient.transportAddresses(); assertThat(adresses, not(emptyCollectionOf(TransportAddress.class))); assertThat(adresses.size(), is(2)); } diff --git a/src/test/java/fr/pilato/spring/elasticsearch/xml/SettingsFailedTest.java b/src/test/java/fr/pilato/spring/elasticsearch/xml/SettingsFailedTest.java index 50354e14..c0c9447d 100644 --- a/src/test/java/fr/pilato/spring/elasticsearch/xml/SettingsFailedTest.java +++ b/src/test/java/fr/pilato/spring/elasticsearch/xml/SettingsFailedTest.java @@ -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; @@ -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; } } diff --git a/src/test/java/fr/pilato/spring/elasticsearch/xml/TransportClientNamespaceTest.java b/src/test/java/fr/pilato/spring/elasticsearch/xml/TransportClientNamespaceTest.java index c570c427..79e0224d 100644 --- a/src/test/java/fr/pilato/spring/elasticsearch/xml/TransportClientNamespaceTest.java +++ b/src/test/java/fr/pilato/spring/elasticsearch/xml/TransportClientNamespaceTest.java @@ -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 { @@ -48,7 +47,7 @@ public void test_transport_client_namespace() { assertThat(client, instanceOf(org.elasticsearch.client.transport.TransportClient.class)); TransportClient tClient = (TransportClient) client; - ImmutableList adresses = tClient.transportAddresses(); + List 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 diff --git a/src/test/resources/es.properties b/src/test/resources/es.properties index 872c456e..8c4c7685 100644 --- a/src/test/resources/es.properties +++ b/src/test/resources/es.properties @@ -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 diff --git a/src/test/resources/esnode-transport.properties b/src/test/resources/esnode-transport.properties index 265566de..75437e9f 100644 --- a/src/test/resources/esnode-transport.properties +++ b/src/test/resources/esnode-transport.properties @@ -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 diff --git a/src/test/resources/models/multinodes-namespace/esnode1.properties b/src/test/resources/models/multinodes-namespace/esnode1.properties index 300085a8..94576737 100644 --- a/src/test/resources/models/multinodes-namespace/esnode1.properties +++ b/src/test/resources/models/multinodes-namespace/esnode1.properties @@ -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 diff --git a/src/test/resources/models/multinodes-namespace/esnode2.properties b/src/test/resources/models/multinodes-namespace/esnode2.properties index e05389d3..e2480f14 100644 --- a/src/test/resources/models/multinodes-namespace/esnode2.properties +++ b/src/test/resources/models/multinodes-namespace/esnode2.properties @@ -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 diff --git a/src/test/resources/models/node-namespace/esnode.properties b/src/test/resources/models/node-namespace/esnode.properties index 5071eb49..040a14c3 100644 --- a/src/test/resources/models/node-namespace/esnode.properties +++ b/src/test/resources/models/node-namespace/esnode.properties @@ -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 diff --git a/src/test/resources/models/settings-15/settings-15-context.xml b/src/test/resources/models/settings-15/settings-15-context.xml index 81a0d3a2..644ea575 100644 --- a/src/test/resources/models/settings-15/settings-15-context.xml +++ b/src/test/resources/models/settings-15/settings-15-context.xml @@ -9,11 +9,8 @@ + - - - -