You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/02/02 09:04:52 UTC
[1/5] camel git commit: CAMEL-10766: Add to kit. This closes #1435
Repository: camel
Updated Branches:
refs/heads/master 43bf30298 -> 6d2b43154
CAMEL-10766: Add to kit. This closes #1435
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/6d2b4315
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6d2b4315
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6d2b4315
Branch: refs/heads/master
Commit: 6d2b43154babe4b1bc26a419ce1fe650333e36a6
Parents: 659255c
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Feb 2 10:03:52 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Feb 2 10:04:30 2017 +0100
----------------------------------------------------------------------
apache-camel/pom.xml | 4 ++++
apache-camel/src/main/descriptors/common-bin.xml | 1 +
2 files changed, 5 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/6d2b4315/apache-camel/pom.xml
----------------------------------------------------------------------
diff --git a/apache-camel/pom.xml b/apache-camel/pom.xml
index 74cfca9..f8ebbfb 100644
--- a/apache-camel/pom.xml
+++ b/apache-camel/pom.xml
@@ -259,6 +259,10 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-elasticsearch5</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-elsql</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/camel/blob/6d2b4315/apache-camel/src/main/descriptors/common-bin.xml
----------------------------------------------------------------------
diff --git a/apache-camel/src/main/descriptors/common-bin.xml b/apache-camel/src/main/descriptors/common-bin.xml
index 534cc39..2691281 100644
--- a/apache-camel/src/main/descriptors/common-bin.xml
+++ b/apache-camel/src/main/descriptors/common-bin.xml
@@ -75,6 +75,7 @@
<include>org.apache.camel:camel-ehcache</include>
<include>org.apache.camel:camel-ejb</include>
<include>org.apache.camel:camel-elasticsearch</include>
+ <include>org.apache.camel:camel-elasticsearch5</include>
<include>org.apache.camel:camel-elsql</include>
<include>org.apache.camel:camel-etcd</include>
<include>org.apache.camel:camel-eventadmin</include>
[4/5] camel git commit: CAMEL-10766: Create a new
camel-elasticsearch5 component for supporting ElasticSearch 5.x Java API
Posted by da...@apache.org.
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchClusterBaseTest.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchClusterBaseTest.java b/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchClusterBaseTest.java
new file mode 100644
index 0000000..a5dd5d3
--- /dev/null
+++ b/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchClusterBaseTest.java
@@ -0,0 +1,139 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.elasticsearch5;
+
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.codelibs.elasticsearch.runner.ElasticsearchClusterRunner;
+import org.elasticsearch.client.transport.TransportClient;
+import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.settings.Settings.Builder;
+import org.elasticsearch.common.transport.InetSocketTransportAddress;
+import org.elasticsearch.transport.client.PreBuiltTransportClient;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+import static org.codelibs.elasticsearch.runner.ElasticsearchClusterRunner.newConfigs;
+
+public class ElasticsearchClusterBaseTest extends CamelTestSupport {
+
+ public static ElasticsearchClusterRunner runner;
+ public static String clusterName;
+ public static TransportClient client;
+
+ @BeforeClass
+ public static void cleanUpOnce() throws Exception {
+ deleteDirectory("target/testcluster/");
+ clusterName = "es-cl-run-" + System.currentTimeMillis();
+ // create runner instance
+
+ runner = new ElasticsearchClusterRunner();
+ // create ES nodes
+ runner.onBuild(new ElasticsearchClusterRunner.Builder() {
+ @Override
+ public void build(final int number, final Builder settingsBuilder) {
+ settingsBuilder.put("http.cors.enabled", true);
+ settingsBuilder.put("http.cors.allow-origin", "*");
+ }
+ }).build(
+ newConfigs()
+ .clusterName(clusterName)
+ .numOfNode(3)
+ .basePath("target/testcluster/")
+ .useLogger());
+
+ // wait for green status
+ runner.ensureGreen();
+
+ client = new PreBuiltTransportClient(getSettings())
+ .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9301));
+ }
+
+ private static Settings getSettings() {
+ return Settings.builder()
+ .put("cluster.name", clusterName)
+ .put("client.transport.ignore_cluster_name", false)
+ .put("client.transport.sniff", true)
+ .build();
+ }
+
+ @AfterClass
+ public static void teardownOnce() throws Exception {
+ if (client != null) {
+ client.close();
+ }
+ if (runner != null) {
+ // close runner
+ runner.close();
+ // delete all files
+ runner.clean();
+ }
+ }
+
+ @Override
+ public boolean isCreateCamelContextPerClass() {
+ // let's speed up the tests using the same context
+ return true;
+ }
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+
+ // reuse existing client
+ ElasticsearchComponent es = context.getComponent("elasticsearch5", ElasticsearchComponent.class);
+ es.setClient(client);
+
+ return context;
+ }
+
+ /**
+ * As we don't delete the {@code target/data} folder for <b>each</b> test
+ * below (otherwise they would run much slower), we need to make sure
+ * there's no side effect of the same used data through creating unique
+ * indexes.
+ */
+ Map<String, String> createIndexedData(String... additionalPrefixes) {
+ String prefix = createPrefix();
+
+ // take over any potential prefixes we may have been asked for
+ if (additionalPrefixes.length > 0) {
+ StringBuilder sb = new StringBuilder(prefix);
+ for (String additionalPrefix : additionalPrefixes) {
+ sb.append(additionalPrefix).append("-");
+ }
+ prefix = sb.toString();
+ }
+
+ String key = prefix + "key";
+ String value = prefix + "value";
+ log.info("Creating indexed data using the key/value pair {} => {}", key, value);
+
+ Map<String, String> map = new HashMap<String, String>();
+ map.put(key, value);
+ return map;
+ }
+
+ String createPrefix() {
+ // make use of the test method name to avoid collision
+ return getTestMethodName().toLowerCase() + "-";
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchClusterIndexTest.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchClusterIndexTest.java b/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchClusterIndexTest.java
new file mode 100644
index 0000000..81ca789
--- /dev/null
+++ b/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchClusterIndexTest.java
@@ -0,0 +1,117 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.elasticsearch5;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class ElasticsearchClusterIndexTest extends ElasticsearchClusterBaseTest {
+
+ @Test
+ public void indexWithIp() throws Exception {
+ Map<String, String> map = createIndexedData();
+ Map<String, Object> headers = new HashMap<String, Object>();
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
+ headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter");
+ headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "tweet");
+ headers.put(ElasticsearchConstants.PARAM_INDEX_ID, "1");
+
+ String indexId = template.requestBodyAndHeaders("direct:indexWithIp", map, headers, String.class);
+ assertNotNull("indexId should be set", indexId);
+
+ headers.clear();
+
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
+ headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter");
+ headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "status");
+ headers.put(ElasticsearchConstants.PARAM_INDEX_ID, "2");
+
+
+ indexId = template.requestBodyAndHeaders("direct:indexWithIp", map, headers, String.class);
+ assertNotNull("indexId should be set", indexId);
+
+ assertEquals("Cluster must be of three nodes", runner.getNodeSize(), 3);
+ assertEquals("Index id 1 must exists", true, client.prepareGet("twitter", "tweet", "1").get().isExists());
+ assertEquals("Index id 2 must exists", true, client.prepareGet("twitter", "status", "2").get().isExists());
+ }
+
+ @Test
+ public void indexWithIpAndPort() throws Exception {
+ Map<String, String> map = createIndexedData();
+ Map<String, Object> headers = new HashMap<String, Object>();
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
+ headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "instagram");
+ headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "photo");
+ headers.put(ElasticsearchConstants.PARAM_INDEX_ID, "3");
+
+ String indexId = template.requestBodyAndHeaders("direct:indexWithIpAndPort", map, headers, String.class);
+ assertNotNull("indexId should be set", indexId);
+
+ assertEquals("Cluster must be of three nodes", runner.getNodeSize(), 3);
+ assertEquals("Index id 3 must exists", true, client.prepareGet("instagram", "photo", "3").get().isExists());
+ }
+
+ @Test
+ public void indexWithTransportAddresses() throws Exception {
+ Map<String, String> map = createIndexedData();
+ Map<String, Object> headers = new HashMap<String, Object>();
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
+ headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "facebook");
+ headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "post");
+ headers.put(ElasticsearchConstants.PARAM_INDEX_ID, "4");
+
+ String indexId = template.requestBodyAndHeaders("direct:indexWithTransportAddresses", map, headers, String.class);
+ assertNotNull("indexId should be set", indexId);
+
+ assertEquals("Cluster must be of three nodes", runner.getNodeSize(), 3);
+ assertEquals("Index id 4 must exists", true, client.prepareGet("facebook", "post", "4").get().isExists());
+ }
+
+ @Test
+ public void indexWithIpAndTransportAddresses() throws Exception {
+ Map<String, String> map = createIndexedData();
+ Map<String, Object> headers = new HashMap<String, Object>();
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
+ headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "ebay");
+ headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "search");
+ headers.put(ElasticsearchConstants.PARAM_INDEX_ID, "5");
+
+ //should ignore transport addresses configuration
+ String indexId = template.requestBodyAndHeaders("direct:indexWithIpAndTransportAddresses", map, headers, String.class);
+ assertNotNull("indexId should be set", indexId);
+
+ assertEquals("Cluster must be of three nodes", runner.getNodeSize(), 3);
+ assertEquals("Index id 5 must exists", true, client.prepareGet("ebay", "search", "5").get().isExists());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:indexWithIp").to("elasticsearch5://elasticsearch?operation=INDEX&indexName=twitter&indexType=tweet&port=9301");
+ from("direct:indexWithIpAndPort").to("elasticsearch5://elasticsearch?operation=INDEX&indexName=twitter&indexType=tweet&ip=localhost&port=9301");
+ from("direct:indexWithTransportAddresses").to("elasticsearch5://elasticsearch?operation=INDEX&indexName=twitter&indexType=tweet&transportAddresses=localhost:9301");
+ from("direct:indexWithIpAndTransportAddresses").
+ to("elasticsearch5://elasticsearch?operation=INDEX&indexName=twitter&indexType=tweet&ip=localhost&port=9301&transportAddresses=localhost:4444,localhost:5555");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchGetSearchDeleteExistsUpdateTest.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchGetSearchDeleteExistsUpdateTest.java b/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchGetSearchDeleteExistsUpdateTest.java
new file mode 100644
index 0000000..782929d
--- /dev/null
+++ b/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchGetSearchDeleteExistsUpdateTest.java
@@ -0,0 +1,355 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.elasticsearch5;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.elasticsearch.action.delete.DeleteRequest;
+import org.elasticsearch.action.delete.DeleteResponse;
+import org.elasticsearch.action.get.GetRequest;
+import org.elasticsearch.action.get.GetResponse;
+import org.elasticsearch.action.get.MultiGetItemResponse;
+import org.elasticsearch.action.get.MultiGetRequest.Item;
+import org.elasticsearch.action.get.MultiGetResponse;
+import org.elasticsearch.action.index.IndexRequest;
+import org.elasticsearch.action.search.MultiSearchResponse;
+import org.elasticsearch.action.search.SearchRequest;
+import org.elasticsearch.action.search.SearchRequestBuilder;
+import org.elasticsearch.action.search.SearchResponse;
+import org.elasticsearch.index.query.QueryBuilders;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.notNullValue;
+
+public class ElasticsearchGetSearchDeleteExistsUpdateTest extends ElasticsearchBaseTest {
+
+ @Test
+ public void testGet() throws Exception {
+ //first, INDEX a value
+ Map<String, String> map = createIndexedData();
+ sendBody("direct:index", map);
+ String indexId = template.requestBody("direct:index", map, String.class);
+ assertNotNull("indexId should be set", indexId);
+
+ //now, verify GET succeeded
+ GetResponse response = template.requestBody("direct:get", indexId, GetResponse.class);
+ assertNotNull("response should not be null", response);
+ assertNotNull("response source should not be null", response.getSource());
+ }
+
+ @Test
+ public void testDelete() throws Exception {
+ //first, INDEX a value
+ Map<String, String> map = createIndexedData();
+ sendBody("direct:index", map);
+ String indexId = template.requestBody("direct:index", map, String.class);
+ assertNotNull("indexId should be set", indexId);
+
+ //now, verify GET succeeded
+ GetResponse response = template.requestBody("direct:get", indexId, GetResponse.class);
+ assertNotNull("response should not be null", response);
+ assertNotNull("response source should not be null", response.getSource());
+
+ //now, perform DELETE
+ DeleteResponse deleteResponse = template.requestBody("direct:delete", indexId, DeleteResponse.class);
+ assertNotNull("response should not be null", deleteResponse);
+
+ //now, verify GET fails to find the indexed value
+ response = template.requestBody("direct:get", indexId, GetResponse.class);
+ assertNotNull("response should not be null", response);
+ assertNull("response source should be null", response.getSource());
+ }
+
+ @Test
+ public void testSearchWithMapQuery() throws Exception {
+ //first, INDEX a value
+ Map<String, String> map = createIndexedData();
+ sendBody("direct:index", map);
+
+ //now, verify GET succeeded
+ Map<String, Object> actualQuery = new HashMap<String, Object>();
+ actualQuery.put("content", "searchtest");
+ Map<String, Object> match = new HashMap<String, Object>();
+ match.put("match", actualQuery);
+ Map<String, Object> query = new HashMap<String, Object>();
+ query.put("query", match);
+ SearchResponse response = template.requestBody("direct:search", query, SearchResponse.class);
+ assertNotNull("response should not be null", response);
+ assertNotNull("response hits should be == 1", response.getHits().totalHits());
+ }
+
+ @Test
+ public void testSearchWithStringQuery() throws Exception {
+ //first, INDEX a value
+ Map<String, String> map = createIndexedData();
+ sendBody("direct:index", map);
+
+ //now, verify GET succeeded
+ String query = "{\"query\":{\"match\":{\"content\":\"searchtest\"}}}";
+ SearchResponse response = template.requestBody("direct:search", query, SearchResponse.class);
+ assertNotNull("response should not be null", response);
+ assertNotNull("response hits should be == 1", response.getHits().totalHits());
+ }
+
+ @Test
+ public void testUpdate() throws Exception {
+ Map<String, String> map = createIndexedData();
+ String indexId = template.requestBody("direct:index", map, String.class);
+ assertNotNull("indexId should be set", indexId);
+
+ Map<String, String> newMap = new HashMap<>();
+ newMap.put(createPrefix() + "key2", createPrefix() + "value2");
+ Map<String, Object> headers = new HashMap<>();
+ headers.put(ElasticsearchConstants.PARAM_INDEX_ID, indexId);
+ indexId = template.requestBodyAndHeaders("direct:update", newMap, headers, String.class);
+ assertNotNull("indexId should be set", indexId);
+ }
+
+ @Test
+ public void testGetWithHeaders() throws Exception {
+ //first, INDEX a value
+ Map<String, String> map = createIndexedData();
+ Map<String, Object> headers = new HashMap<String, Object>();
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
+ headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter");
+ headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "tweet");
+
+ String indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class);
+
+ //now, verify GET
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_GET_BY_ID);
+ GetResponse response = template.requestBodyAndHeaders("direct:start", indexId, headers, GetResponse.class);
+ assertNotNull("response should not be null", response);
+ assertNotNull("response source should not be null", response.getSource());
+ }
+
+ @Test
+ public void testExistsWithHeaders() throws Exception {
+ //first, INDEX a value
+ Map<String, String> map = createIndexedData();
+ Map<String, Object> headers = new HashMap<String, Object>();
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
+ headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter");
+ headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "tweet");
+
+ String indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class);
+
+ //now, verify GET
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_EXISTS);
+ headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter");
+ Boolean exists = template.requestBodyAndHeaders("direct:exists", "", headers, Boolean.class);
+ assertNotNull("response should not be null", exists);
+ assertTrue("Index should exists", exists);
+ }
+
+ @Test
+ public void testNotExistsWithHeaders() throws Exception {
+ //first, INDEX a value
+ Map<String, String> map = createIndexedData();
+ Map<String, Object> headers = new HashMap<String, Object>();
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
+ headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter");
+ headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "tweet");
+
+ String indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class);
+
+ //now, verify GET
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_EXISTS);
+ headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter-tweet");
+ Boolean exists = template.requestBodyAndHeaders("direct:exists", "", headers, Boolean.class);
+ assertNotNull("response should not be null", exists);
+ assertFalse("Index should not exists", exists);
+ }
+
+ @Test
+ public void testMultiGet() throws Exception {
+ //first, INDEX two values
+ Map<String, String> map = createIndexedData();
+ Map<String, Object> headers = new HashMap<String, Object>();
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
+ headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter");
+ headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "tweet");
+ headers.put(ElasticsearchConstants.PARAM_INDEX_ID, "1");
+
+ template.requestBodyAndHeaders("direct:start", map, headers, String.class);
+
+ headers.clear();
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
+ headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "facebook");
+ headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "status");
+ headers.put(ElasticsearchConstants.PARAM_INDEX_ID, "2");
+
+ template.requestBodyAndHeaders("direct:start", map, headers, String.class);
+ headers.clear();
+
+ //now, verify MULTIGET
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_MULTIGET);
+ Item item1 = new Item("twitter", "tweet", "1");
+ Item item2 = new Item("facebook", "status", "2");
+ Item item3 = new Item("instagram", "latest", "3");
+ List<Item> list = new ArrayList<Item>();
+ list.add(item1);
+ list.add(item2);
+ list.add(item3);
+ MultiGetResponse response = template.requestBodyAndHeaders("direct:start", list, headers, MultiGetResponse.class);
+ MultiGetItemResponse[] responses = response.getResponses();
+ assertNotNull("response should not be null", response);
+ assertEquals("response should contains three multiGetResponse object", 3, response.getResponses().length);
+ assertEquals("response 1 should contains tweet as type", "tweet", responses[0].getResponse().getType().toString());
+ assertEquals("response 2 should contains status as type", "status", responses[1].getResponse().getType().toString());
+ assertFalse("response 1 should be ok", responses[0].isFailed());
+ assertFalse("response 2 should be ok", responses[1].isFailed());
+ assertTrue("response 3 should be failed", responses[2].isFailed());
+ }
+
+ @Test
+ public void testMultiSearch() throws Exception {
+ //first, INDEX two values
+ Map<String, Object> headers = new HashMap<String, Object>();
+
+ node.client().prepareIndex("test", "type", "1").setSource("field", "xxx").execute().actionGet();
+ node.client().prepareIndex("test", "type", "2").setSource("field", "yyy").execute().actionGet();
+
+ //now, verify MULTISEARCH
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_MULTISEARCH);
+ SearchRequestBuilder srb1 = node.client().prepareSearch("test").setTypes("type").setQuery(QueryBuilders.termQuery("field", "xxx"));
+ SearchRequestBuilder srb2 = node.client().prepareSearch("test").setTypes("type").setQuery(QueryBuilders.termQuery("field", "yyy"));
+ SearchRequestBuilder srb3 = node.client().prepareSearch("instagram")
+ .setTypes("type").setQuery(QueryBuilders.termQuery("test-multisearchkey", "test-multisearchvalue"));
+ List<SearchRequest> list = new ArrayList<>();
+ list.add(srb1.request());
+ list.add(srb2.request());
+ list.add(srb3.request());
+ MultiSearchResponse response = template.requestBodyAndHeaders("direct:multisearch", list, headers, MultiSearchResponse.class);
+ MultiSearchResponse.Item[] responses = response.getResponses();
+ assertNotNull("response should not be null", response);
+ assertEquals("response should contains three multiSearchResponse object", 3, response.getResponses().length);
+ assertFalse("response 1 should be ok", responses[0].isFailure());
+ assertFalse("response 2 should be ok", responses[1].isFailure());
+ assertTrue("response 3 should be failed", responses[2].isFailure());
+ }
+
+ @Test
+ public void testDeleteWithHeaders() throws Exception {
+ //first, INDEX a value
+ Map<String, String> map = createIndexedData();
+ Map<String, Object> headers = new HashMap<String, Object>();
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
+ headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter");
+ headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "tweet");
+
+ String indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class);
+
+ //now, verify GET
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_GET_BY_ID);
+ GetResponse response = template.requestBodyAndHeaders("direct:start", indexId, headers, GetResponse.class);
+ assertNotNull("response should not be null", response);
+ assertNotNull("response source should not be null", response.getSource());
+
+ //now, perform DELETE
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_DELETE);
+ DeleteResponse deleteResponse = template.requestBodyAndHeaders("direct:start", indexId, headers, DeleteResponse.class);
+ assertNotNull("response should not be null", deleteResponse);
+
+ //now, verify GET fails to find the indexed value
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_GET_BY_ID);
+ response = template.requestBodyAndHeaders("direct:start", indexId, headers, GetResponse.class);
+ assertNotNull("response should not be null", response);
+ assertNull("response source should be null", response.getSource());
+ }
+
+ @Test
+ public void testUpdateWithIDInHeader() throws Exception {
+ Map<String, String> map = createIndexedData();
+ Map<String, Object> headers = new HashMap<String, Object>();
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
+ headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter");
+ headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "tweet");
+ headers.put(ElasticsearchConstants.PARAM_INDEX_ID, "123");
+
+ String indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class);
+ assertNotNull("indexId should be set", indexId);
+ assertEquals("indexId should be equals to the provided id", "123", indexId);
+
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_UPDATE);
+
+ indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class);
+ assertNotNull("indexId should be set", indexId);
+ assertEquals("indexId should be equals to the provided id", "123", indexId);
+ }
+
+ @Test
+ public void getRequestBody() throws Exception {
+ String prefix = createPrefix();
+
+ // given
+ GetRequest request = new GetRequest(prefix + "foo").type(prefix + "bar");
+
+ // when
+ String documentId = template.requestBody("direct:index",
+ new IndexRequest(prefix + "foo", prefix + "bar", prefix + "testId")
+ .source("{\"" + prefix + "content\": \"" + prefix + "hello\"}"), String.class);
+ GetResponse response = template.requestBody("direct:get",
+ request.id(documentId), GetResponse.class);
+
+ // then
+ assertThat(response, notNullValue());
+ assertThat(prefix + "hello", equalTo(response.getSourceAsMap().get(prefix + "content")));
+ }
+
+ @Test
+ public void deleteRequestBody() throws Exception {
+ String prefix = createPrefix();
+
+ // given
+ DeleteRequest request = new DeleteRequest(prefix + "foo").type(prefix + "bar");
+
+ // when
+ String documentId = template.requestBody("direct:index",
+ new IndexRequest("" + prefix + "foo", "" + prefix + "bar", "" + prefix + "testId")
+ .source("{\"" + prefix + "content\": \"" + prefix + "hello\"}"), String.class);
+ DeleteResponse response = template.requestBody("direct:delete",
+ request.id(documentId), DeleteResponse.class);
+
+ // then
+ assertThat(response, notNullValue());
+ assertThat(documentId, equalTo(response.getId()));
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:start").to("elasticsearch5://elasticsearch?operation=INDEX");
+ from("direct:index").to("elasticsearch5://elasticsearch?operation=INDEX&indexName=twitter&indexType=tweet");
+ from("direct:get").to("elasticsearch5://elasticsearch?operation=GET_BY_ID&indexName=twitter&indexType=tweet");
+ from("direct:multiget").to("elasticsearch5://elasticsearch?operation=MULTIGET&indexName=twitter&indexType=tweet");
+ from("direct:delete").to("elasticsearch5://elasticsearch?operation=DELETE&indexName=twitter&indexType=tweet");
+ from("direct:search").to("elasticsearch5://elasticsearch?operation=SEARCH&indexName=twitter&indexType=tweet");
+ from("direct:update").to("elasticsearch5://elasticsearch?operation=UPDATE&indexName=twitter&indexType=tweet");
+ from("direct:exists").to("elasticsearch5://elasticsearch?operation=EXISTS");
+ from("direct:multisearch").to("elasticsearch5://elasticsearch?operation=MULTISEARCH&indexName=test");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchIndexTest.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchIndexTest.java b/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchIndexTest.java
new file mode 100644
index 0000000..4ef3cb5
--- /dev/null
+++ b/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchIndexTest.java
@@ -0,0 +1,86 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.elasticsearch5;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class ElasticsearchIndexTest extends ElasticsearchBaseTest {
+
+ @Test
+ public void testIndex() throws Exception {
+ Map<String, String> map = createIndexedData();
+ String indexId = template.requestBody("direct:index", map, String.class);
+ assertNotNull("indexId should be set", indexId);
+ }
+
+ @Test
+ public void testIndexWithReplication() throws Exception {
+ Map<String, String> map = createIndexedData();
+ String indexId = template.requestBody("direct:indexWithReplication", map, String.class);
+ assertNotNull("indexId should be set", indexId);
+ }
+
+ @Test
+ public void testIndexWithWriteConsistency() throws Exception {
+ Map<String, String> map = createIndexedData();
+ String indexId = template.requestBody("direct:indexWithWriteConsistency", map, String.class);
+ assertNotNull("indexId should be set", indexId);
+ }
+
+ @Test
+ public void testIndexWithHeaders() throws Exception {
+ Map<String, String> map = createIndexedData();
+ Map<String, Object> headers = new HashMap<String, Object>();
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
+ headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter");
+ headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "tweet");
+
+ String indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class);
+ assertNotNull("indexId should be set", indexId);
+ }
+
+ @Test
+ public void testIndexWithIDInHeader() throws Exception {
+ Map<String, String> map = createIndexedData();
+ Map<String, Object> headers = new HashMap<String, Object>();
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
+ headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter");
+ headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "tweet");
+ headers.put(ElasticsearchConstants.PARAM_INDEX_ID, "123");
+
+ String indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class);
+ assertNotNull("indexId should be set", indexId);
+ assertEquals("indexId should be equals to the provided id", "123", indexId);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:start").to("elasticsearch5://elasticsearch");
+ from("direct:index").to("elasticsearch5://elasticsearch?operation=INDEX&indexName=twitter&indexType=tweet");
+ from("direct:indexWithReplication").to("elasticsearch5://elasticsearch?operation=INDEX&indexName=twitter&indexType=tweet");
+ from("direct:indexWithWriteConsistency").to("elasticsearch5://elasticsearch?operation=INDEX&indexName=twitter&indexType=tweet");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/components/camel-elasticsearch5/src/test/resources/log4j2.properties
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/test/resources/log4j2.properties b/components/camel-elasticsearch5/src/test/resources/log4j2.properties
new file mode 100644
index 0000000..1e56038
--- /dev/null
+++ b/components/camel-elasticsearch5/src/test/resources/log4j2.properties
@@ -0,0 +1,28 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+
+appender.file.type = File
+appender.file.name = file
+appender.file.fileName = target/camel-elasticsearch-test.log
+appender.file.layout.type = PatternLayout
+appender.file.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
+appender.stdout.type = Console
+appender.stdout.name = stdout
+appender.stdout.layout.type = PatternLayout
+appender.stdout.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
+rootLogger.level = INFO
+rootLogger.appenderRef.file.ref = file
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/components/camel-lucene/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-lucene/pom.xml b/components/camel-lucene/pom.xml
index 337cf04..e8a8b6b 100644
--- a/components/camel-lucene/pom.xml
+++ b/components/camel-lucene/pom.xml
@@ -51,14 +51,17 @@
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
+ <version>${lucene-version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-queryparser</artifactId>
+ <version>${lucene-version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-common</artifactId>
+ <version>${lucene-version}</version>
</dependency>
<!-- test dependencies -->
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/components/pom.xml
----------------------------------------------------------------------
diff --git a/components/pom.xml b/components/pom.xml
index 90b092e..def344c 100644
--- a/components/pom.xml
+++ b/components/pom.xml
@@ -108,6 +108,7 @@
<module>camel-ehcache</module>
<module>camel-ejb</module>
<module>camel-elasticsearch</module>
+ <module>camel-elasticsearch5</module>
<module>camel-elsql</module>
<module>camel-etcd</module>
<module>camel-eventadmin</module>
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/components/readme.adoc
----------------------------------------------------------------------
diff --git a/components/readme.adoc b/components/readme.adoc
index fccd05c..fd1534e 100644
--- a/components/readme.adoc
+++ b/components/readme.adoc
@@ -159,6 +159,9 @@ Components
| link:camel-elasticsearch/src/main/docs/elasticsearch-component.adoc[Elasticsearch] (camel-elasticsearch) +
`elasticsearch:clusterName` | The elasticsearch component is used for interfacing with ElasticSearch server.
+| link:camel-elasticsearch5/src/main/docs/elasticsearch5-component.adoc[Elasticsearch5] (camel-elasticsearch5) +
+`elasticsearch5:clusterName` | The elasticsearch component is used for interfacing with ElasticSearch server.
+
| link:camel-elsql/src/main/docs/elsql-component.adoc[ElSQL] (camel-elsql) +
`elsql:elsqlName:resourceUri` | The elsql component is an extension to the existing SQL Component that uses ElSql to define the SQL queries.
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/docs/user-manual/en/SUMMARY.md
----------------------------------------------------------------------
diff --git a/docs/user-manual/en/SUMMARY.md b/docs/user-manual/en/SUMMARY.md
index d93d575..46cbd3d 100644
--- a/docs/user-manual/en/SUMMARY.md
+++ b/docs/user-manual/en/SUMMARY.md
@@ -175,6 +175,7 @@
* [Ehcache](ehcache-component.adoc)
* [EJB](ejb-component.adoc)
* [Elasticsearch](elasticsearch-component.adoc)
+ * [Elasticsearch5](elasticsearch5-component.adoc)
* [ElSQL](elsql-component.adoc)
* [etcd](etcd-component.adoc)
* [Exec](exec-component.adoc)
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 5ddbcd5..09e2dfe 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -174,7 +174,9 @@
<elasticsearch-bundle-version>2.4.3_1</elasticsearch-bundle-version>
<elasticsearch-guava-version>18.0</elasticsearch-guava-version>
<elasticsearch-version>2.4.3</elasticsearch-version>
+ <elasticsearch5-version>5.1.2</elasticsearch5-version>
<elasticsearch-cluster-runner-version>2.4.0.0</elasticsearch-cluster-runner-version>
+ <elasticsearch5-cluster-runner-version>5.1.2.0</elasticsearch5-cluster-runner-version>
<elsql-version>1.2</elsql-version>
<el-api-1.0-version>1.0.1</el-api-1.0-version>
<!-- embedmongo 1.50.2 do not work -->
@@ -401,7 +403,7 @@
<lucene3-bundle-version>3.6.0_1</lucene3-bundle-version>
<lucene3-version>3.6.0</lucene3-version>
<lucene-bundle-version>5.5.2_1</lucene-bundle-version>
- <!-- lucene aligned with elastichsearch version of lucene in use -->
+ <!-- lucene aligned with elasticsearch version of lucene in use -->
<lucene-version>5.5.2</lucene-version>
<lucene-version-range>[5,6)</lucene-version-range>
<lightcouch-version>0.1.8</lightcouch-version>
@@ -1017,6 +1019,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-elasticsearch5</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-elsql</artifactId>
<version>${project.version}</version>
</dependency>
@@ -3808,73 +3815,6 @@
<version>${dropbox-version}</version>
</dependency>
- <!-- optional lucene dependencies -->
- <dependency>
- <groupId>org.apache.lucene</groupId>
- <artifactId>lucene-analyzers-common</artifactId>
- <version>${lucene-version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.lucene</groupId>
- <artifactId>lucene-backward-codecs</artifactId>
- <version>${lucene-version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.lucene</groupId>
- <artifactId>lucene-core</artifactId>
- <version>${lucene-version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.lucene</groupId>
- <artifactId>lucene-grouping</artifactId>
- <version>${lucene-version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.lucene</groupId>
- <artifactId>lucene-highlighter</artifactId>
- <version>${lucene-version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.lucene</groupId>
- <artifactId>lucene-join</artifactId>
- <version>${lucene-version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.lucene</groupId>
- <artifactId>lucene-memory</artifactId>
- <version>${lucene-version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.lucene</groupId>
- <artifactId>lucene-misc</artifactId>
- <version>${lucene-version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.lucene</groupId>
- <artifactId>lucene-queryparser</artifactId>
- <version>${lucene-version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.lucene</groupId>
- <artifactId>lucene-queries</artifactId>
- <version>${lucene-version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.lucene</groupId>
- <artifactId>lucene-spatial</artifactId>
- <version>${lucene-version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.lucene</groupId>
- <artifactId>lucene-spatial3d</artifactId>
- <version>${lucene-version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.lucene</groupId>
- <artifactId>lucene-suggest</artifactId>
- <version>${lucene-version}</version>
- </dependency>
-
<!-- optional mina dependencies -->
<dependency>
<groupId>org.apache.mina</groupId>
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/platforms/catalog-lucene/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/catalog-lucene/pom.xml b/platforms/catalog-lucene/pom.xml
index 026cba7..228e919 100644
--- a/platforms/catalog-lucene/pom.xml
+++ b/platforms/catalog-lucene/pom.xml
@@ -45,10 +45,12 @@
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
+ <version>${lucene-version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-suggest</artifactId>
+ <version>${lucene-version}</version>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/pom.xml b/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/pom.xml
new file mode 100644
index 0000000..907aa9b
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/pom.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>components-starter</artifactId>
+ <version>2.19.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>camel-elasticsearch5-starter</artifactId>
+ <packaging>jar</packaging>
+ <name>Spring-Boot Starter :: Camel :: ElasticSearch5</name>
+ <description>Spring-Boot Starter for Camel ElasticSearch 5.x support</description>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter</artifactId>
+ <version>${spring-boot-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-elasticsearch5</artifactId>
+ <version>${project.version}</version>
+ <!--START OF GENERATED CODE-->
+ <exclusions>
+ <exclusion>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </exclusion>
+ </exclusions>
+ <!--END OF GENERATED CODE-->
+ </dependency>
+ <!--START OF GENERATED CODE-->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core-starter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-spring-boot-starter</artifactId>
+ </dependency>
+ <!--END OF GENERATED CODE-->
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/java/org/apache/camel/component/elasticsearch5/springboot/ElasticsearchComponentAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/java/org/apache/camel/component/elasticsearch5/springboot/ElasticsearchComponentAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/java/org/apache/camel/component/elasticsearch5/springboot/ElasticsearchComponentAutoConfiguration.java
new file mode 100644
index 0000000..0edc75e
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/java/org/apache/camel/component/elasticsearch5/springboot/ElasticsearchComponentAutoConfiguration.java
@@ -0,0 +1,111 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.elasticsearch5.springboot;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.elasticsearch5.ElasticsearchComponent;
+import org.apache.camel.util.IntrospectionSupport;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionMessage;
+import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
+import org.springframework.boot.bind.RelaxedPropertyResolver;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ConditionContext;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.core.type.AnnotatedTypeMetadata;
+
+/**
+ * Generated by camel-package-maven-plugin - do not edit this file!
+ */
+@Configuration
+@ConditionalOnBean(type = "org.apache.camel.spring.boot.CamelAutoConfiguration")
+@Conditional(ElasticsearchComponentAutoConfiguration.Condition.class)
+@AutoConfigureAfter(name = "org.apache.camel.spring.boot.CamelAutoConfiguration")
+@EnableConfigurationProperties(ElasticsearchComponentConfiguration.class)
+public class ElasticsearchComponentAutoConfiguration {
+
+ @Lazy
+ @Bean(name = "elasticsearch5-component")
+ @ConditionalOnClass(CamelContext.class)
+ @ConditionalOnMissingBean(ElasticsearchComponent.class)
+ public ElasticsearchComponent configureElasticsearchComponent(
+ CamelContext camelContext,
+ ElasticsearchComponentConfiguration configuration) throws Exception {
+ ElasticsearchComponent component = new ElasticsearchComponent();
+ component.setCamelContext(camelContext);
+ Map<String, Object> parameters = new HashMap<>();
+ IntrospectionSupport.getProperties(configuration, parameters, null,
+ false);
+ for (Map.Entry<String, Object> entry : parameters.entrySet()) {
+ Object value = entry.getValue();
+ Class<?> paramClass = value.getClass();
+ if (paramClass.getName().endsWith("NestedConfiguration")) {
+ Class nestedClass = null;
+ try {
+ nestedClass = (Class) paramClass.getDeclaredField(
+ "CAMEL_NESTED_CLASS").get(null);
+ HashMap<String, Object> nestedParameters = new HashMap<>();
+ IntrospectionSupport.getProperties(value, nestedParameters,
+ null, false);
+ Object nestedProperty = nestedClass.newInstance();
+ IntrospectionSupport.setProperties(camelContext,
+ camelContext.getTypeConverter(), nestedProperty,
+ nestedParameters);
+ entry.setValue(nestedProperty);
+ } catch (NoSuchFieldException e) {
+ }
+ }
+ }
+ IntrospectionSupport.setProperties(camelContext,
+ camelContext.getTypeConverter(), component, parameters);
+ return component;
+ }
+
+ public static class Condition extends SpringBootCondition {
+ @Override
+ public ConditionOutcome getMatchOutcome(
+ ConditionContext conditionContext,
+ AnnotatedTypeMetadata annotatedTypeMetadata) {
+ boolean groupEnabled = isEnabled(conditionContext,
+ "camel.component.", true);
+ ConditionMessage.Builder message = ConditionMessage
+ .forCondition("camel.component.elasticsearch5");
+ if (isEnabled(conditionContext, "camel.component.elasticsearch5.",
+ groupEnabled)) {
+ return ConditionOutcome.match(message.because("enabled"));
+ }
+ return ConditionOutcome.noMatch(message.because("not enabled"));
+ }
+
+ private boolean isEnabled(
+ org.springframework.context.annotation.ConditionContext context,
+ java.lang.String prefix, boolean defaultValue) {
+ RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(
+ context.getEnvironment(), prefix);
+ return resolver.getProperty("enabled", Boolean.class, defaultValue);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/java/org/apache/camel/component/elasticsearch5/springboot/ElasticsearchComponentConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/java/org/apache/camel/component/elasticsearch5/springboot/ElasticsearchComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/java/org/apache/camel/component/elasticsearch5/springboot/ElasticsearchComponentConfiguration.java
new file mode 100644
index 0000000..7864d81
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/java/org/apache/camel/component/elasticsearch5/springboot/ElasticsearchComponentConfiguration.java
@@ -0,0 +1,46 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.elasticsearch5.springboot;
+
+import org.elasticsearch.client.transport.TransportClient;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.context.properties.NestedConfigurationProperty;
+
+/**
+ * The elasticsearch component is used for interfacing with ElasticSearch
+ * server.
+ *
+ * Generated by camel-package-maven-plugin - do not edit this file!
+ */
+@ConfigurationProperties(prefix = "camel.component.elasticsearch5")
+public class ElasticsearchComponentConfiguration {
+
+ /**
+ * To use an existing configured Elasticsearch client instead of creating a
+ * client per endpoint.
+ */
+ @NestedConfigurationProperty
+ private TransportClient client;
+
+ public TransportClient getClient() {
+ return client;
+ }
+
+ public void setClient(TransportClient client) {
+ this.client = client;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/resources/META-INF/LICENSE.txt
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/resources/META-INF/LICENSE.txt b/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/resources/META-INF/LICENSE.txt
new file mode 100644
index 0000000..6b0b127
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/resources/META-INF/LICENSE.txt
@@ -0,0 +1,203 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/resources/META-INF/NOTICE.txt
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/resources/META-INF/NOTICE.txt b/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/resources/META-INF/NOTICE.txt
new file mode 100644
index 0000000..2e215bf
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/resources/META-INF/NOTICE.txt
@@ -0,0 +1,11 @@
+ =========================================================================
+ == NOTICE file corresponding to the section 4 d of ==
+ == the Apache License, Version 2.0, ==
+ == in this case for the Apache Camel distribution. ==
+ =========================================================================
+
+ This product includes software developed by
+ The Apache Software Foundation (http://www.apache.org/).
+
+ Please read the different LICENSE files present in the licenses directory of
+ this distribution.
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json
new file mode 100644
index 0000000..32bee0b
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json
@@ -0,0 +1,10 @@
+{
+ "properties": [
+ {
+ "defaultValue": true,
+ "name": "camel.component.elasticsearch5.enabled",
+ "description": "Enable elasticsearch5 component",
+ "type": "java.lang.Boolean"
+ }
+ ]
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/resources/META-INF/spring.factories
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/resources/META-INF/spring.factories b/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/resources/META-INF/spring.factories
new file mode 100644
index 0000000..e3cf6b9
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/resources/META-INF/spring.factories
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+org.apache.camel.component.elasticsearch5.springboot.ElasticsearchComponentAutoConfiguration
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/resources/META-INF/spring.provides
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/resources/META-INF/spring.provides b/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/resources/META-INF/spring.provides
new file mode 100644
index 0000000..bf05784
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/resources/META-INF/spring.provides
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+provides: camel-elasticsearch5
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/platforms/spring-boot/components-starter/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/pom.xml b/platforms/spring-boot/components-starter/pom.xml
index c6dc0e0..052e3d8 100644
--- a/platforms/spring-boot/components-starter/pom.xml
+++ b/platforms/spring-boot/components-starter/pom.xml
@@ -122,6 +122,7 @@
<module>camel-eclipse-starter</module>
<module>camel-ehcache-starter</module>
<module>camel-elasticsearch-starter</module>
+ <module>camel-elasticsearch5-starter</module>
<module>camel-elsql-starter</module>
<module>camel-etcd-starter</module>
<module>camel-exec-starter</module>
[5/5] camel git commit: CAMEL-10766: Create a new
camel-elasticsearch5 component for supporting ElasticSearch 5.x Java API
Posted by da...@apache.org.
CAMEL-10766: Create a new camel-elasticsearch5 component for supporting
ElasticSearch 5.x Java API
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a5377007
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a5377007
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a5377007
Branch: refs/heads/master
Commit: a5377007b2b80ec83e559810b424263a82d3274c
Parents: 43bf302
Author: Dmitry Volodin <dm...@gmail.com>
Authored: Tue Jan 31 14:47:33 2017 +0300
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Feb 2 10:04:30 2017 +0100
----------------------------------------------------------------------
components/camel-elasticsearch5/pom.xml | 101 ++++++
.../src/main/docs/elasticsearch5-component.adoc | 154 ++++++++
.../src/main/java/META-INF/MANIFEST.MF | 3 +
.../elasticsearch5/ElasticsearchComponent.java | 90 +++++
.../ElasticsearchConfiguration.java | 158 +++++++++
.../elasticsearch5/ElasticsearchConstants.java | 49 +++
.../elasticsearch5/ElasticsearchEndpoint.java | 120 +++++++
.../elasticsearch5/ElasticsearchProducer.java | 206 +++++++++++
.../BulkRequestAggregationStrategy.java | 51 +++
.../ElasticsearchActionRequestConverter.java | 235 ++++++++++++
.../src/main/resources/META-INF/LICENSE.txt | 203 +++++++++++
.../src/main/resources/META-INF/NOTICE.txt | 11 +
.../services/org/apache/camel/TypeConverter | 17 +
.../org/apache/camel/component/elasticsearch5 | 18 +
.../elasticsearch5/ElasticsearchBaseTest.java | 122 +++++++
.../elasticsearch5/ElasticsearchBulkTest.java | 95 +++++
.../ElasticsearchClusterBaseTest.java | 139 ++++++++
.../ElasticsearchClusterIndexTest.java | 117 ++++++
...icsearchGetSearchDeleteExistsUpdateTest.java | 355 +++++++++++++++++++
.../elasticsearch5/ElasticsearchIndexTest.java | 86 +++++
.../src/test/resources/log4j2.properties | 28 ++
components/camel-lucene/pom.xml | 3 +
components/pom.xml | 1 +
components/readme.adoc | 3 +
docs/user-manual/en/SUMMARY.md | 1 +
parent/pom.xml | 76 +---
platforms/catalog-lucene/pom.xml | 2 +
.../camel-elasticsearch5-starter/pom.xml | 59 +++
...ElasticsearchComponentAutoConfiguration.java | 111 ++++++
.../ElasticsearchComponentConfiguration.java | 46 +++
.../src/main/resources/META-INF/LICENSE.txt | 203 +++++++++++
.../src/main/resources/META-INF/NOTICE.txt | 11 +
...dditional-spring-configuration-metadata.json | 10 +
.../main/resources/META-INF/spring.factories | 19 +
.../src/main/resources/META-INF/spring.provides | 18 +
.../spring-boot/components-starter/pom.xml | 1 +
36 files changed, 2854 insertions(+), 68 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/components/camel-elasticsearch5/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/pom.xml b/components/camel-elasticsearch5/pom.xml
new file mode 100644
index 0000000..e2e4612
--- /dev/null
+++ b/components/camel-elasticsearch5/pom.xml
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
+ license agreements. See the NOTICE file distributed with this work for additional
+ information regarding copyright ownership. The ASF licenses this file to
+ You under the Apache License, Version 2.0 (the "License"); you may not use
+ this file except in compliance with the License. You may obtain a copy of
+ the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
+ by applicable law or agreed to in writing, software distributed under the
+ License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ OF ANY KIND, either express or implied. See the License for the specific
+ language governing permissions and limitations under the License. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>components</artifactId>
+ <version>2.19.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-elasticsearch5</artifactId>
+ <packaging>jar</packaging>
+ <name>Camel :: ElasticSearch5</name>
+ <description>Camel ElasticSearch 5.x support</description>
+
+ <properties>
+ <elasticsearch.version>5.1.2</elasticsearch.version>
+ <camel.osgi.export.pkg>org.apache.camel.component.elasticsearch5.*;${camel.osgi.version}</camel.osgi.export.pkg>
+ <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=elasticsearch5</camel.osgi.export.service>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.elasticsearch.client</groupId>
+ <artifactId>transport</artifactId>
+ <version>${elasticsearch5-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>${jackson2-version}</version>
+ </dependency>
+
+ <!-- for testing -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.codelibs</groupId>
+ <artifactId>elasticsearch-cluster-runner</artifactId>
+ <version>${elasticsearch5-cluster-runner-version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- logging -->
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-1.2-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <systemPropertyVariables>
+ <es.path.data>target/data</es.path.data>
+ </systemPropertyVariables>
+ <forkCount>1</forkCount>
+ <reuseForks>false</reuseForks>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/components/camel-elasticsearch5/src/main/docs/elasticsearch5-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/main/docs/elasticsearch5-component.adoc b/components/camel-elasticsearch5/src/main/docs/elasticsearch5-component.adoc
new file mode 100644
index 0000000..1447dab
--- /dev/null
+++ b/components/camel-elasticsearch5/src/main/docs/elasticsearch5-component.adoc
@@ -0,0 +1,154 @@
+## Elasticsearch5 Component
+
+*Available as of Camel 2.19*
+
+The ElasticSearch component allows you to interface with an
+https://www.elastic.co/products/elasticsearch[ElasticSearch] 5.x API.
+
+Maven users will need to add the following dependency to their `pom.xml`
+for this component:
+
+[source,xml]
+------------------------------------------------------------
+<dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-elasticsearch5</artifactId>
+ <version>x.x.x</version>
+ <!-- use the same version as your Camel core version -->
+</dependency>
+------------------------------------------------------------
+
+### URI format
+
+[source,java]
+-------------------------------------
+elasticsearch5://clusterName[?options]
+-------------------------------------
+
+
+### Endpoint Options
+
+
+
+// component options: START
+The Elasticsearch5 component supports 1 options which are listed below.
+
+
+
+{% raw %}
+[width="100%",cols="2,1,1m,1m,5",options="header"]
+|=======================================================================
+| Name | Group | Default | Java Type | Description
+| client | advanced | | TransportClient | To use an existing configured Elasticsearch client instead of creating a client per endpoint.
+|=======================================================================
+{% endraw %}
+// component options: END
+
+
+
+
+
+// endpoint options: START
+The Elasticsearch5 component supports 10 endpoint options which are listed below:
+
+{% raw %}
+[width="100%",cols="2,1,1m,1m,5",options="header"]
+|=======================================================================
+| Name | Group | Default | Java Type | Description
+| clusterName | producer | | String | *Required* Name of the cluster
+| clientTransportSniff | producer | true | Boolean | Is the client allowed to sniff the rest of the cluster or not (default true). This setting map to the client.transport.sniff setting.
+| indexName | producer | | String | The name of the index to act against
+| indexType | producer | | String | The type of the index to act against
+| ip | producer | | String | The TransportClient remote host ip to use
+| operation | producer | | String | What operation to perform
+| port | producer | | int | The TransportClient remote port to use (defaults to 9300)
+| transportAddresses | producer | | String | Comma separated list with ip:port formatted remote transport addresses to use. The ip and port options must be left blank for transportAddresses to be considered instead.
+| waitForActiveShards | producer | | int | Index creation waits for the write consistency number of shards to be available
+| synchronous | advanced | false | boolean | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported).
+|=======================================================================
+{% endraw %}
+// endpoint options: END
+
+
+### Message Operations
+
+The following ElasticSearch operations are currently supported. Simply
+set an endpoint URI option or exchange header with a key of "operation"
+and a value set to one of the following. Some operations also require
+other parameters or the message body to be set.
+
+[width="100%",cols="10%,10%,80%",options="header",]
+|=======================================================================
+|operation |message body |description
+
+|INDEX |Map, String, byte[] or XContentBuilder content to index |adds content to an index and returns the content's indexId in the body.
+You can set the indexId by setting the message header with
+the key "indexId".
+
+|GET_BY_ID |index id of content to retrieve |retrieves the specified index and returns a GetResult object in the body
+
+|DELETE |index id of content to delete |deletes the specified indexId and returns a DeleteResult object in the
+body
+
+|BULK_INDEX | a�*List*�or *Collection* of any type that is already accepted
+(XContentBuilder, Map, byte[], String) |Adds content to an index and return a�List of the id�of the
+successfully indexed documents in the body
+
+|BULK |a�*List*�or *Collection* of any type that is already accepted
+(XContentBuilder, Map, byte[], String) |Adds content to an index and returns the BulkResponse
+object in the body
+
+|SEARCH |Map, String or SearchRequest Object |Search the content with the map of query string
+
+|MULTIGET |List of MultigetRequest.Item object |Retrieves the specified indexes, types etc. in
+MultigetRequest and returns a MultigetResponse object in the body
+
+|MULTISEARCH |List of SearchRequest object |Search for parameters specified in MultiSearchRequest and
+returns a MultiSearchResponse object in the body
+
+|EXISTS |Index name as header |Returns a Boolean object in the body
+
+|UPDATE |Map, String, byte[] or XContentBuilder content to update |Updates content to an index and returns the content's
+indexId in the body.
+|=======================================================================
+
+### Index Example
+
+Below is a simple INDEX example
+
+[source,java]
+-------------------------------------------------------------------------------
+from("direct:index")
+.to("elasticsearch5://elasticsearch?operation=INDEX&indexName=twitter&indexType=tweet");
+-------------------------------------------------------------------------------
+
+[source,xml]
+---------------------------------------------------------------------------------------
+<route>
+ <from uri="direct:index" />
+ <to uri="elasticsearch5://elasticsearch?operation=INDEX&indexName=twitter&indexType=tweet"/>
+</route>
+---------------------------------------------------------------------------------------
+
+A client would simply need to pass a body message containing a Map to
+the route. The result body contains the indexId created.
+
+[source,java]
+-------------------------------------------------------------------------
+Map<String, String> map = new HashMap<String, String>();
+map.put("content", "test");
+String indexId = template.requestBody("direct:index", map, String.class);
+-------------------------------------------------------------------------
+
+### For more information, see these resources
+
+http://www.elastic.co[Elastic Main Site]
+
+https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-api.html[ElasticSearch Java API]
+
+### See Also
+
+* link:configuring-camel.html[Configuring Camel]
+* link:component.html[Component]
+* link:endpoint.html[Endpoint]
+* link:getting-started.html[Getting Started]
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/components/camel-elasticsearch5/src/main/java/META-INF/MANIFEST.MF
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/main/java/META-INF/MANIFEST.MF b/components/camel-elasticsearch5/src/main/java/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..5e94951
--- /dev/null
+++ b/components/camel-elasticsearch5/src/main/java/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Class-Path:
+
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchComponent.java b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchComponent.java
new file mode 100644
index 0000000..1205519
--- /dev/null
+++ b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchComponent.java
@@ -0,0 +1,90 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.elasticsearch5;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.UriEndpointComponent;
+import org.apache.camel.spi.Metadata;
+import org.elasticsearch.client.transport.TransportClient;
+import org.elasticsearch.common.transport.InetSocketTransportAddress;
+
+/**
+ * Represents the component that manages {@link ElasticsearchEndpoint}.
+ */
+public class ElasticsearchComponent extends UriEndpointComponent {
+
+ @Metadata(label = "advanced")
+ private TransportClient client;
+
+ public ElasticsearchComponent() {
+ super(ElasticsearchEndpoint.class);
+ }
+
+ public ElasticsearchComponent(CamelContext context) {
+ super(context, ElasticsearchEndpoint.class);
+ }
+
+ protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+ ElasticsearchConfiguration config = new ElasticsearchConfiguration();
+ setProperties(config, parameters);
+ config.setClusterName(remaining);
+
+ config.setTransportAddressesList(parseTransportAddresses(config.getTransportAddresses(), config));
+
+ Endpoint endpoint = new ElasticsearchEndpoint(uri, this, config, client);
+ return endpoint;
+ }
+
+ private List<InetSocketTransportAddress> parseTransportAddresses(String ipsString, ElasticsearchConfiguration config) throws UnknownHostException {
+ if (ipsString == null || ipsString.isEmpty()) {
+ return null;
+ }
+ List<String> addressesStr = Arrays.asList(ipsString.split(ElasticsearchConstants.TRANSPORT_ADDRESSES_SEPARATOR_REGEX));
+ List<InetSocketTransportAddress> addressesTrAd = new ArrayList<InetSocketTransportAddress>(addressesStr.size());
+ for (String address : addressesStr) {
+ String[] split = address.split(ElasticsearchConstants.IP_PORT_SEPARATOR_REGEX);
+ String hostname;
+ if (split.length > 0) {
+ hostname = split[0];
+ } else {
+ throw new IllegalArgumentException();
+ }
+ Integer port = split.length > 1 ? Integer.parseInt(split[1]) : ElasticsearchConstants.DEFAULT_PORT;
+ addressesTrAd.add(new InetSocketTransportAddress(InetAddress.getByName(hostname), port));
+ }
+ return addressesTrAd;
+ }
+
+ public TransportClient getClient() {
+ return client;
+ }
+
+ /**
+ * To use an existing configured Elasticsearch client, instead of creating a client per endpoint.
+ */
+ public void setClient(TransportClient client) {
+ this.client = client;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchConfiguration.java b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchConfiguration.java
new file mode 100644
index 0000000..308ee83
--- /dev/null
+++ b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchConfiguration.java
@@ -0,0 +1,158 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.elasticsearch5;
+
+import java.util.List;
+
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriParams;
+import org.apache.camel.spi.UriPath;
+import org.elasticsearch.common.transport.InetSocketTransportAddress;
+
+@UriParams
+public class ElasticsearchConfiguration {
+
+ private List<InetSocketTransportAddress> transportAddressesList;
+
+ @UriPath @Metadata(required = "true")
+ private String clusterName;
+ @UriParam(enums = "INDEX, UPDATE, BULK, BULK_INDEX, GET_BY_ID, MULTIGET, DELETE, EXISTS, SEARCH, MULTISEARCH, DELETE_INDEX")
+ private String operation;
+ @UriParam
+ private String indexName;
+ @UriParam
+ private String indexType;
+ @UriParam
+ private int waitForActiveShards = ElasticsearchConstants.DEFAULT_FOR_WAIT_ACTIVE_SHARDS;
+ @UriParam
+ private String ip;
+ @UriParam
+ private String transportAddresses;
+ @UriParam
+ private int port = ElasticsearchConstants.DEFAULT_PORT;
+ @UriParam(defaultValue = "true")
+ private Boolean clientTransportSniff = true;
+
+ /**
+ * Name of the cluster
+ */
+ public String getClusterName() {
+ return clusterName;
+ }
+
+ public void setClusterName(String clusterName) {
+ this.clusterName = clusterName;
+ }
+
+ /**
+ * What operation to perform
+ */
+ public String getOperation() {
+ return operation;
+ }
+
+ public void setOperation(String operation) {
+ this.operation = operation;
+ }
+
+ /**
+ * The name of the index to act against
+ */
+ public String getIndexName() {
+ return indexName;
+ }
+
+ public void setIndexName(String indexName) {
+ this.indexName = indexName;
+ }
+
+ /**
+ * The type of the index to act against
+ */
+ public String getIndexType() {
+ return indexType;
+ }
+
+ public void setIndexType(String indexType) {
+ this.indexType = indexType;
+ }
+
+ /**
+ * The TransportClient remote host ip to use
+ */
+ public String getIp() {
+ return ip;
+ }
+
+ public void setIp(String ip) {
+ this.ip = ip;
+ }
+
+ /**
+ * Comma separated list with ip:port formatted remote transport addresses to use.
+ * The ip and port options must be left blank for transportAddresses to be considered instead.
+ */
+ public String getTransportAddresses() {
+ return transportAddresses;
+ }
+
+ public void setTransportAddresses(String transportAddresses) {
+ this.transportAddresses = transportAddresses;
+ }
+
+ /**
+ * The TransportClient remote port to use (defaults to 9300)
+ */
+ public int getPort() {
+ return port;
+ }
+
+ public void setPort(int port) {
+ this.port = port;
+ }
+
+ /**
+ * Index creation waits for the write consistency number of shards to be available
+ */
+ public int getWaitForActiveShards() {
+ return waitForActiveShards;
+ }
+
+ public void setWaitForActiveShards(int waitForActiveShards) {
+ this.waitForActiveShards = waitForActiveShards;
+ }
+
+ /**
+ * Is the client allowed to sniff the rest of the cluster or not (default true). This setting map to the <tt>client.transport.sniff</tt> setting.
+ */
+ public Boolean getClientTransportSniff() {
+ return clientTransportSniff;
+ }
+
+ public void setClientTransportSniff(Boolean clientTransportSniff) {
+ this.clientTransportSniff = clientTransportSniff;
+ }
+
+ public List<InetSocketTransportAddress> getTransportAddressesList() {
+ return transportAddressesList;
+ }
+
+ public void setTransportAddressesList(List<InetSocketTransportAddress> transportAddressesList) {
+ this.transportAddressesList = transportAddressesList;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchConstants.java b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchConstants.java
new file mode 100644
index 0000000..ab30a85
--- /dev/null
+++ b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchConstants.java
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.component.elasticsearch5;
+
+
+public interface ElasticsearchConstants {
+
+ String PARAM_OPERATION = "operation";
+ String OPERATION_INDEX = "INDEX";
+ String OPERATION_UPDATE = "UPDATE";
+ String OPERATION_BULK = "BULK";
+ String OPERATION_BULK_INDEX = "BULK_INDEX";
+ String OPERATION_GET_BY_ID = "GET_BY_ID";
+ String OPERATION_MULTIGET = "MULTIGET";
+ String OPERATION_DELETE = "DELETE";
+ String OPERATION_DELETE_INDEX = "DELETE_INDEX";
+ String OPERATION_SEARCH = "SEARCH";
+ String OPERATION_MULTISEARCH = "MULTISEARCH";
+ String OPERATION_EXISTS = "EXISTS";
+ String PARAM_INDEX_ID = "indexId";
+ String PARAM_INDEX_NAME = "indexName";
+ String PARAM_INDEX_TYPE = "indexType";
+ String PARAM_WAIT_FOR_ACTIVE_SHARDS = "waitForActiveShards";
+ String PARENT = "parent";
+ String TRANSPORT_ADDRESSES = "transportAddresses";
+ String PROTOCOL = "elasticsearch";
+ String IP = "ip";
+ String PORT = "port";
+ Integer DEFAULT_PORT = 9300;
+ Integer DEFAULT_FOR_WAIT_ACTIVE_SHARDS = 1; // Meaning only wait for the primary shard
+ String TRANSPORT_ADDRESSES_SEPARATOR_REGEX = ",";
+ String IP_PORT_SEPARATOR_REGEX = ":";
+ String ES_QUERY_DSL_PREFIX = "query";
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchEndpoint.java b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchEndpoint.java
new file mode 100644
index 0000000..f9aad84
--- /dev/null
+++ b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchEndpoint.java
@@ -0,0 +1,120 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.elasticsearch5;
+
+import java.net.InetAddress;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+import org.elasticsearch.client.transport.TransportClient;
+import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.transport.InetSocketTransportAddress;
+import org.elasticsearch.common.transport.TransportAddress;
+import org.elasticsearch.transport.client.PreBuiltTransportClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The elasticsearch component is used for interfacing with ElasticSearch server.
+ */
+@UriEndpoint(scheme = "elasticsearch5", title = "Elasticsearch5", syntax = "elasticsearch5:clusterName", producerOnly = true, label = "monitoring,search")
+public class ElasticsearchEndpoint extends DefaultEndpoint {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ElasticsearchEndpoint.class);
+
+ private TransportClient client;
+ @UriParam
+ private ElasticsearchConfiguration configuration;
+
+ public ElasticsearchEndpoint(String uri, ElasticsearchComponent component, ElasticsearchConfiguration config, TransportClient client) throws Exception {
+ super(uri, component);
+ this.configuration = config;
+ this.client = client;
+ }
+
+ public Producer createProducer() throws Exception {
+ return new ElasticsearchProducer(this);
+ }
+
+ public Consumer createConsumer(Processor processor) throws Exception {
+ throw new UnsupportedOperationException("Cannot consume from an ElasticsearchEndpoint: " + getEndpointUri());
+ }
+
+ public boolean isSingleton() {
+ return false;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected void doStart() throws Exception {
+ super.doStart();
+
+ if (client == null) {
+ LOG.info("Connecting to the ElasticSearch cluster: " + configuration.getClusterName());
+
+ if (configuration.getIp() != null) {
+ client = new PreBuiltTransportClient(getSettings())
+ .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(configuration.getIp()), configuration.getPort()));
+ } else if (configuration.getTransportAddressesList() != null
+ && !configuration.getTransportAddressesList().isEmpty()) {
+ List<TransportAddress> addresses = new ArrayList<TransportAddress>(configuration.getTransportAddressesList().size());
+ for (TransportAddress address : configuration.getTransportAddressesList()) {
+ addresses.add(address);
+ }
+ client = new PreBuiltTransportClient(getSettings()).addTransportAddresses(addresses.toArray(new TransportAddress[addresses.size()]));
+ } else {
+ LOG.info("Incorrect ip address and port parameters settings for ElasticSearch cluster");
+ }
+ }
+ }
+
+ private Settings getSettings() {
+ return Settings.builder()
+ .put("cluster.name", configuration.getClusterName())
+ .put("client.transport.ignore_cluster_name", false)
+ .put("client.transport.sniff", configuration.getClientTransportSniff())
+ .build();
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ if (client != null) {
+ LOG.info("Disconnecting from ElasticSearch cluster: " + configuration.getClusterName());
+ client.close();
+ client = null;
+ }
+ super.doStop();
+ }
+
+ public TransportClient getClient() {
+ return client;
+ }
+
+ public ElasticsearchConfiguration getConfig() {
+ return configuration;
+ }
+
+ public void setOperation(String operation) {
+ configuration.setOperation(operation);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchProducer.java b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchProducer.java
new file mode 100644
index 0000000..c63aebf
--- /dev/null
+++ b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchProducer.java
@@ -0,0 +1,206 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.elasticsearch5;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.impl.DefaultProducer;
+import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
+import org.elasticsearch.action.bulk.BulkItemResponse;
+import org.elasticsearch.action.bulk.BulkRequest;
+import org.elasticsearch.action.delete.DeleteRequest;
+import org.elasticsearch.action.get.GetRequest;
+import org.elasticsearch.action.get.MultiGetRequest;
+import org.elasticsearch.action.index.IndexRequest;
+import org.elasticsearch.action.search.MultiSearchRequest;
+import org.elasticsearch.action.search.SearchRequest;
+import org.elasticsearch.action.update.UpdateRequest;
+import org.elasticsearch.client.transport.TransportClient;
+import org.elasticsearch.index.IndexNotFoundException;
+
+/**
+ * Represents an Elasticsearch producer.
+ */
+public class ElasticsearchProducer extends DefaultProducer {
+
+ public ElasticsearchProducer(ElasticsearchEndpoint endpoint) {
+ super(endpoint);
+ }
+
+ @Override
+ public ElasticsearchEndpoint getEndpoint() {
+ return (ElasticsearchEndpoint) super.getEndpoint();
+ }
+
+ private String resolveOperation(Exchange exchange) {
+ // 1. Operation can be driven by either (in order of preference):
+ // a. If the body is an ActionRequest the operation is set by the type
+ // of request.
+ // b. If the body is not an ActionRequest, the operation is set by the
+ // header if it exists.
+ // c. If neither the operation can not be derived from the body or
+ // header, the configuration is used.
+ // In the event we can't discover the operation from a, b or c we throw
+ // an error.
+ Object request = exchange.getIn().getBody();
+ if (request instanceof IndexRequest) {
+ return ElasticsearchConstants.OPERATION_INDEX;
+ } else if (request instanceof GetRequest) {
+ return ElasticsearchConstants.OPERATION_GET_BY_ID;
+ } else if (request instanceof MultiGetRequest) {
+ return ElasticsearchConstants.OPERATION_MULTIGET;
+ } else if (request instanceof UpdateRequest) {
+ return ElasticsearchConstants.OPERATION_UPDATE;
+ } else if (request instanceof BulkRequest) {
+ // do we want bulk or bulk_index?
+ if (ElasticsearchConstants.OPERATION_BULK_INDEX.equals(getEndpoint().getConfig().getOperation())) {
+ return ElasticsearchConstants.OPERATION_BULK_INDEX;
+ } else {
+ return ElasticsearchConstants.OPERATION_BULK;
+ }
+ } else if (request instanceof DeleteRequest) {
+ return ElasticsearchConstants.OPERATION_DELETE;
+ } else if (request instanceof SearchRequest) {
+ return ElasticsearchConstants.OPERATION_EXISTS;
+ } else if (request instanceof SearchRequest) {
+ return ElasticsearchConstants.OPERATION_SEARCH;
+ } else if (request instanceof MultiSearchRequest) {
+ return ElasticsearchConstants.OPERATION_MULTISEARCH;
+ } else if (request instanceof DeleteIndexRequest) {
+ return ElasticsearchConstants.OPERATION_DELETE_INDEX;
+ }
+
+ String operationConfig = exchange.getIn().getHeader(ElasticsearchConstants.PARAM_OPERATION, String.class);
+ if (operationConfig == null) {
+ operationConfig = getEndpoint().getConfig().getOperation();
+ }
+ if (operationConfig == null) {
+ throw new IllegalArgumentException(ElasticsearchConstants.PARAM_OPERATION + " value '" + operationConfig + "' is not supported");
+ }
+ return operationConfig;
+ }
+
+ public void process(Exchange exchange) throws Exception {
+ // 2. Index and type will be set by:
+ // a. If the incoming body is already an action request
+ // b. If the body is not an action request we will use headers if they
+ // are set.
+ // c. If the body is not an action request and the headers aren't set we
+ // will use the configuration.
+ // No error is thrown by the component in the event none of the above
+ // conditions are met. The java es client
+ // will throw.
+
+ Message message = exchange.getIn();
+ final String operation = resolveOperation(exchange);
+
+ // Set the index/type headers on the exchange if necessary. This is used
+ // for type conversion.
+ boolean configIndexName = false;
+ String indexName = message.getHeader(ElasticsearchConstants.PARAM_INDEX_NAME, String.class);
+ if (indexName == null) {
+ message.setHeader(ElasticsearchConstants.PARAM_INDEX_NAME, getEndpoint().getConfig().getIndexName());
+ configIndexName = true;
+ }
+
+ boolean configIndexType = false;
+ String indexType = message.getHeader(ElasticsearchConstants.PARAM_INDEX_TYPE, String.class);
+ if (indexType == null) {
+ message.setHeader(ElasticsearchConstants.PARAM_INDEX_TYPE, getEndpoint().getConfig().getIndexType());
+ configIndexType = true;
+ }
+
+ boolean configWaitForActiveShards = false;
+ Integer waitForActiveShards = message.getHeader(ElasticsearchConstants.PARAM_WAIT_FOR_ACTIVE_SHARDS, Integer.class);
+ if (waitForActiveShards == null) {
+ message.setHeader(ElasticsearchConstants.PARAM_WAIT_FOR_ACTIVE_SHARDS, getEndpoint().getConfig().getWaitForActiveShards());
+ configWaitForActiveShards = true;
+ }
+
+ TransportClient client = getEndpoint().getClient();
+ if (ElasticsearchConstants.OPERATION_INDEX.equals(operation)) {
+ IndexRequest indexRequest = message.getBody(IndexRequest.class);
+ message.setBody(client.index(indexRequest).actionGet().getId());
+ } else if (ElasticsearchConstants.OPERATION_UPDATE.equals(operation)) {
+ UpdateRequest updateRequest = message.getBody(UpdateRequest.class);
+ message.setBody(client.update(updateRequest).actionGet().getId());
+ } else if (ElasticsearchConstants.OPERATION_GET_BY_ID.equals(operation)) {
+ GetRequest getRequest = message.getBody(GetRequest.class);
+ message.setBody(client.get(getRequest));
+ } else if (ElasticsearchConstants.OPERATION_MULTIGET.equals(operation)) {
+ MultiGetRequest multiGetRequest = message.getBody(MultiGetRequest.class);
+ message.setBody(client.multiGet(multiGetRequest));
+ } else if (ElasticsearchConstants.OPERATION_BULK.equals(operation)) {
+ BulkRequest bulkRequest = message.getBody(BulkRequest.class);
+ message.setBody(client.bulk(bulkRequest).actionGet());
+ } else if (ElasticsearchConstants.OPERATION_BULK_INDEX.equals(operation)) {
+ BulkRequest bulkRequest = message.getBody(BulkRequest.class);
+ List<String> indexedIds = new ArrayList<String>();
+ for (BulkItemResponse response : client.bulk(bulkRequest).actionGet().getItems()) {
+ indexedIds.add(response.getId());
+ }
+ message.setBody(indexedIds);
+ } else if (ElasticsearchConstants.OPERATION_DELETE.equals(operation)) {
+ DeleteRequest deleteRequest = message.getBody(DeleteRequest.class);
+ message.setBody(client.delete(deleteRequest).actionGet());
+ } else if (ElasticsearchConstants.OPERATION_EXISTS.equals(operation)) {
+ // ExistsRequest API is deprecated, using SearchRequest instead with size=0 and terminate_after=1
+ SearchRequest searchRequest = new SearchRequest(exchange.getIn().getHeader(ElasticsearchConstants.PARAM_INDEX_NAME, String.class));
+ try {
+ client.prepareSearch(searchRequest.indices()).setSize(0).setTerminateAfter(1).get();
+ message.setBody(true);
+ } catch (IndexNotFoundException e) {
+ message.setBody(false);
+ }
+ } else if (ElasticsearchConstants.OPERATION_SEARCH.equals(operation)) {
+ SearchRequest searchRequest = message.getBody(SearchRequest.class);
+ message.setBody(client.search(searchRequest).actionGet());
+ } else if (ElasticsearchConstants.OPERATION_MULTISEARCH.equals(operation)) {
+ MultiSearchRequest multiSearchRequest = message.getBody(MultiSearchRequest.class);
+ message.setBody(client.multiSearch(multiSearchRequest));
+ } else if (ElasticsearchConstants.OPERATION_DELETE_INDEX.equals(operation)) {
+ DeleteIndexRequest deleteIndexRequest = message.getBody(DeleteIndexRequest.class);
+ message.setBody(client.admin().indices().delete(deleteIndexRequest).actionGet());
+ } else {
+ throw new IllegalArgumentException(ElasticsearchConstants.PARAM_OPERATION + " value '" + operation + "' is not supported");
+ }
+
+ // If we set params via the configuration on this exchange, remove them
+ // now. This preserves legacy behavior for this component and enables a
+ // use case where one message can be sent to multiple elasticsearch
+ // endpoints where the user is relying on the endpoint configuration
+ // (index/type) rather than header values. If we do not clear this out
+ // sending the same message (index request, for example) to multiple
+ // elasticsearch endpoints would have the effect overriding any
+ // subsequent endpoint index/type with the first endpoint index/type.
+ if (configIndexName) {
+ message.removeHeader(ElasticsearchConstants.PARAM_INDEX_NAME);
+ }
+
+ if (configIndexType) {
+ message.removeHeader(ElasticsearchConstants.PARAM_INDEX_TYPE);
+ }
+
+ if (configWaitForActiveShards) {
+ message.removeHeader(ElasticsearchConstants.PARAM_WAIT_FOR_ACTIVE_SHARDS);
+ }
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/aggregation/BulkRequestAggregationStrategy.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/aggregation/BulkRequestAggregationStrategy.java b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/aggregation/BulkRequestAggregationStrategy.java
new file mode 100644
index 0000000..4fec8f6
--- /dev/null
+++ b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/aggregation/BulkRequestAggregationStrategy.java
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.elasticsearch5.aggregation;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.InvalidPayloadRuntimeException;
+import org.apache.camel.processor.aggregate.AggregationStrategy;
+import org.elasticsearch.action.ActionRequest;
+import org.elasticsearch.action.bulk.BulkRequest;
+
+/**
+ * Aggregates two {@link ActionRequest}s into a single {@link BulkRequest}.
+ */
+public class BulkRequestAggregationStrategy implements AggregationStrategy {
+
+ @Override
+ public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
+ // Don't use getBody(Class<T>) here as we don't want to coerce the body type using a type converter.
+ Object objBody = newExchange.getIn().getBody();
+ if (!(objBody instanceof ActionRequest)) {
+ throw new InvalidPayloadRuntimeException(newExchange, ActionRequest.class);
+ }
+
+ ActionRequest newBody = (ActionRequest) objBody;
+ BulkRequest request;
+ if (oldExchange == null) {
+ request = new BulkRequest();
+ request.add(newBody);
+ newExchange.getIn().setBody(request);
+ return newExchange;
+ } else {
+ request = oldExchange.getIn().getBody(BulkRequest.class);
+ request.add(newBody);
+ return oldExchange;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/converter/ElasticsearchActionRequestConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/converter/ElasticsearchActionRequestConverter.java b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/converter/ElasticsearchActionRequestConverter.java
new file mode 100644
index 0000000..febfdfd
--- /dev/null
+++ b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/converter/ElasticsearchActionRequestConverter.java
@@ -0,0 +1,235 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.elasticsearch5.converter;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import org.apache.camel.Converter;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.elasticsearch5.ElasticsearchConstants;
+import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
+import org.elasticsearch.action.bulk.BulkRequest;
+import org.elasticsearch.action.delete.DeleteRequest;
+import org.elasticsearch.action.get.GetRequest;
+import org.elasticsearch.action.get.MultiGetRequest;
+import org.elasticsearch.action.get.MultiGetRequest.Item;
+import org.elasticsearch.action.index.IndexRequest;
+import org.elasticsearch.action.search.MultiSearchRequest;
+import org.elasticsearch.action.search.SearchRequest;
+import org.elasticsearch.action.update.UpdateRequest;
+import org.elasticsearch.common.xcontent.XContentBuilder;
+import org.elasticsearch.common.xcontent.XContentFactory;
+import org.elasticsearch.common.xcontent.XContentType;
+import org.elasticsearch.index.query.QueryBuilders;
+import org.elasticsearch.search.builder.SearchSourceBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Converter
+public final class ElasticsearchActionRequestConverter {
+ private static final Logger LOG = LoggerFactory.getLogger(ElasticsearchActionRequestConverter.class);
+
+ private ElasticsearchActionRequestConverter() {
+ }
+
+ // Update requests
+ private static UpdateRequest createUpdateRequest(Object document, Exchange exchange) {
+ if (document instanceof UpdateRequest) {
+ return (UpdateRequest)document;
+ }
+ UpdateRequest updateRequest = new UpdateRequest();
+ if (document instanceof byte[]) {
+ updateRequest.doc((byte[]) document);
+ } else if (document instanceof Map) {
+ updateRequest.doc((Map<String, Object>) document);
+ } else if (document instanceof String) {
+ updateRequest.doc((String) document);
+ } else if (document instanceof XContentBuilder) {
+ updateRequest.doc((XContentBuilder) document);
+ } else {
+ return null;
+ }
+
+ return updateRequest
+ .waitForActiveShards(exchange.getIn().getHeader(
+ ElasticsearchConstants.PARAM_WAIT_FOR_ACTIVE_SHARDS, Integer.class))
+ .parent(exchange.getIn().getHeader(
+ ElasticsearchConstants.PARENT, String.class))
+ .index(exchange.getIn().getHeader(
+ ElasticsearchConstants.PARAM_INDEX_NAME, String.class))
+ .type(exchange.getIn().getHeader(
+ ElasticsearchConstants.PARAM_INDEX_TYPE, String.class))
+ .id(exchange.getIn().getHeader(
+ ElasticsearchConstants.PARAM_INDEX_ID, String.class));
+ }
+
+ // Index requests
+ @SuppressWarnings("unchecked")
+ private static IndexRequest createIndexRequest(Object document, Exchange exchange) {
+ if (document instanceof IndexRequest) {
+ return (IndexRequest)document;
+ }
+ IndexRequest indexRequest = new IndexRequest();
+ if (document instanceof byte[]) {
+ indexRequest.source((byte[]) document);
+ } else if (document instanceof Map) {
+ indexRequest.source((Map<String, Object>) document);
+ } else if (document instanceof String) {
+ indexRequest.source((String) document);
+ } else if (document instanceof XContentBuilder) {
+ indexRequest.source((XContentBuilder) document);
+ } else {
+ return null;
+ }
+
+ return indexRequest
+ .waitForActiveShards(exchange.getIn().getHeader(
+ ElasticsearchConstants.PARAM_WAIT_FOR_ACTIVE_SHARDS, Integer.class))
+ .parent(exchange.getIn().getHeader(
+ ElasticsearchConstants.PARENT, String.class))
+ .index(exchange.getIn().getHeader(
+ ElasticsearchConstants.PARAM_INDEX_NAME, String.class))
+ .type(exchange.getIn().getHeader(
+ ElasticsearchConstants.PARAM_INDEX_TYPE, String.class));
+ }
+
+ @Converter
+ public static IndexRequest toIndexRequest(Object document, Exchange exchange) {
+ return createIndexRequest(document, exchange)
+ .id(exchange.getIn().getHeader(ElasticsearchConstants.PARAM_INDEX_ID, String.class));
+ }
+
+ @Converter
+ public static UpdateRequest toUpdateRequest(Object document, Exchange exchange) {
+ return createUpdateRequest(document, exchange)
+ .id(exchange.getIn().getHeader(ElasticsearchConstants.PARAM_INDEX_ID, String.class));
+ }
+
+ @Converter
+ public static GetRequest toGetRequest(String id, Exchange exchange) {
+ return new GetRequest(exchange.getIn().getHeader(
+ ElasticsearchConstants.PARAM_INDEX_NAME, String.class))
+ .type(exchange.getIn().getHeader(
+ ElasticsearchConstants.PARAM_INDEX_TYPE,
+ String.class)).id(id);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Converter
+ public static MultiGetRequest toMultiGetRequest(Object document, Exchange exchange) {
+ List<Item> items = (List<Item>) document;
+ MultiGetRequest multiGetRequest = new MultiGetRequest();
+ Iterator<Item> it = items.iterator();
+ while (it.hasNext()) {
+ MultiGetRequest.Item item = it.next();
+ multiGetRequest.add(item);
+ }
+ return multiGetRequest;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Converter
+ public static MultiSearchRequest toMultiSearchRequest(Object document, Exchange exchange) {
+ List<SearchRequest> items = (List<SearchRequest>) document;
+ MultiSearchRequest multiSearchRequest = new MultiSearchRequest();
+ Iterator<SearchRequest> it = items.iterator();
+ while (it.hasNext()) {
+ SearchRequest item = it.next();
+ multiSearchRequest.add(item);
+ }
+ return multiSearchRequest;
+ }
+
+ @Converter
+ public static DeleteRequest toDeleteRequest(String id, Exchange exchange) {
+ return new DeleteRequest()
+ .index(exchange.getIn().getHeader(
+ ElasticsearchConstants.PARAM_INDEX_NAME,
+ String.class))
+ .type(exchange.getIn().getHeader(
+ ElasticsearchConstants.PARAM_INDEX_TYPE,
+ String.class)).id(id);
+ }
+
+ @Converter
+ public static DeleteIndexRequest toDeleteIndexRequest(String id, Exchange exchange) {
+ return new DeleteIndexRequest()
+ .indices(exchange.getIn().getHeader(
+ ElasticsearchConstants.PARAM_INDEX_NAME,
+ String.class));
+ }
+
+ @Converter
+ public static SearchRequest toSearchRequest(Object queryObject, Exchange exchange) {
+ SearchRequest searchRequest = new SearchRequest(exchange.getIn()
+ .getHeader(ElasticsearchConstants.PARAM_INDEX_NAME, String.class))
+ .types(exchange.getIn().getHeader(ElasticsearchConstants.PARAM_INDEX_TYPE, String.class));
+
+ SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
+ String queryText = null;
+
+ if (queryObject instanceof Map<?, ?>) {
+ Map<String, Object> mapQuery = (Map<String, Object>)queryObject;
+ // Remove 'query' prefix from the query object for backward compatibility
+ if (mapQuery.containsKey(ElasticsearchConstants.ES_QUERY_DSL_PREFIX)) {
+ mapQuery = (Map<String, Object>)mapQuery.get(ElasticsearchConstants.ES_QUERY_DSL_PREFIX);
+ }
+ try {
+ XContentBuilder contentBuilder = XContentFactory.contentBuilder(XContentType.JSON);
+ queryText = contentBuilder.map(mapQuery).string();
+ } catch (IOException e) {
+ LOG.error(e.getMessage());
+ }
+ } else if (queryObject instanceof String) {
+ queryText = (String)queryObject;
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ JsonNode jsonTextObject = mapper.readValue(queryText, JsonNode.class);
+ JsonNode parentJsonNode = jsonTextObject.get(ElasticsearchConstants.ES_QUERY_DSL_PREFIX);
+ if (parentJsonNode != null) {
+ queryText = parentJsonNode.toString();
+ }
+ } catch (IOException e) {
+ LOG.error(e.getMessage());
+ }
+ } else {
+ // Cannot convert the queryObject into SearchRequest
+ return null;
+ }
+
+ searchSourceBuilder.query(QueryBuilders.wrapperQuery(queryText));
+ searchRequest.source(searchSourceBuilder);
+
+ return searchRequest;
+ }
+
+ @Converter
+ public static BulkRequest toBulkRequest(List<Object> documents,
+ Exchange exchange) {
+ BulkRequest request = new BulkRequest();
+ for (Object document : documents) {
+ request.add(createIndexRequest(document, exchange));
+ }
+ return request;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/components/camel-elasticsearch5/src/main/resources/META-INF/LICENSE.txt
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/main/resources/META-INF/LICENSE.txt b/components/camel-elasticsearch5/src/main/resources/META-INF/LICENSE.txt
new file mode 100644
index 0000000..6b0b127
--- /dev/null
+++ b/components/camel-elasticsearch5/src/main/resources/META-INF/LICENSE.txt
@@ -0,0 +1,203 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/components/camel-elasticsearch5/src/main/resources/META-INF/NOTICE.txt
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/main/resources/META-INF/NOTICE.txt b/components/camel-elasticsearch5/src/main/resources/META-INF/NOTICE.txt
new file mode 100644
index 0000000..2e215bf
--- /dev/null
+++ b/components/camel-elasticsearch5/src/main/resources/META-INF/NOTICE.txt
@@ -0,0 +1,11 @@
+ =========================================================================
+ == NOTICE file corresponding to the section 4 d of ==
+ == the Apache License, Version 2.0, ==
+ == in this case for the Apache Camel distribution. ==
+ =========================================================================
+
+ This product includes software developed by
+ The Apache Software Foundation (http://www.apache.org/).
+
+ Please read the different LICENSE files present in the licenses directory of
+ this distribution.
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/components/camel-elasticsearch5/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/main/resources/META-INF/services/org/apache/camel/TypeConverter b/components/camel-elasticsearch5/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
new file mode 100644
index 0000000..dc9c4a5
--- /dev/null
+++ b/components/camel-elasticsearch5/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
@@ -0,0 +1,17 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+org.apache.camel.component.elasticsearch5.converter.ElasticsearchActionRequestConverter
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/components/camel-elasticsearch5/src/main/resources/META-INF/services/org/apache/camel/component/elasticsearch5
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/main/resources/META-INF/services/org/apache/camel/component/elasticsearch5 b/components/camel-elasticsearch5/src/main/resources/META-INF/services/org/apache/camel/component/elasticsearch5
new file mode 100644
index 0000000..f8320f8
--- /dev/null
+++ b/components/camel-elasticsearch5/src/main/resources/META-INF/services/org/apache/camel/component/elasticsearch5
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+class=org.apache.camel.component.elasticsearch5.ElasticsearchComponent
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchBaseTest.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchBaseTest.java b/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchBaseTest.java
new file mode 100644
index 0000000..a6e5ab9
--- /dev/null
+++ b/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchBaseTest.java
@@ -0,0 +1,122 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.elasticsearch5;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.elasticsearch.client.transport.TransportClient;
+import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.transport.InetSocketTransportAddress;
+import org.elasticsearch.node.Node;
+import org.elasticsearch.node.NodeValidationException;
+import org.elasticsearch.node.internal.InternalSettingsPreparer;
+import org.elasticsearch.plugins.Plugin;
+import org.elasticsearch.transport.Netty4Plugin;
+import org.elasticsearch.transport.client.PreBuiltTransportClient;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+public class ElasticsearchBaseTest extends CamelTestSupport {
+
+ public static Node node;
+ public static TransportClient client;
+
+ private static class PluginConfigurableNode extends Node {
+ PluginConfigurableNode(Settings settings, Collection<Class<? extends Plugin>> classpathPlugins) {
+ super(InternalSettingsPreparer.prepareEnvironment(settings, null), classpathPlugins);
+ }
+ }
+
+ @BeforeClass
+ public static void cleanupOnce() throws NodeValidationException {
+ deleteDirectory("target/data");
+
+ // create an embedded node to resume
+ node = new PluginConfigurableNode(Settings.builder().put("http.enabled", true).put("path.data", "target/data")
+ .put("path.home", "target/home").build(), Arrays.asList(Netty4Plugin.class)).start();
+ }
+
+ @AfterClass
+ public static void teardownOnce() throws IOException {
+ if (client != null) {
+ client.close();
+ }
+ if (node != null) {
+ node.close();
+ }
+ }
+
+ @Override
+ public boolean isCreateCamelContextPerClass() {
+ // let's speed up the tests using the same context
+ return true;
+ }
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+
+ // reuse existing client
+ ElasticsearchComponent es = context.getComponent("elasticsearch5", ElasticsearchComponent.class);
+
+ client = new PreBuiltTransportClient(Settings.EMPTY)
+ .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
+ es.setClient(client);
+
+ return context;
+ }
+
+ /**
+ * As we don't delete the {@code target/data} folder for <b>each</b> test
+ * below (otherwise they would run much slower), we need to make sure
+ * there's no side effect of the same used data through creating unique
+ * indexes.
+ */
+ Map<String, String> createIndexedData(String... additionalPrefixes) {
+ String prefix = createPrefix();
+
+ // take over any potential prefixes we may have been asked for
+ if (additionalPrefixes.length > 0) {
+ StringBuilder sb = new StringBuilder(prefix);
+ for (String additionalPrefix : additionalPrefixes) {
+ sb.append(additionalPrefix).append("-");
+ }
+ prefix = sb.toString();
+ }
+
+ String key = prefix + "key";
+ String value = prefix + "value";
+ log.info("Creating indexed data using the key/value pair {} => {}", key, value);
+
+ Map<String, String> map = new HashMap<String, String>();
+ map.put(key, value);
+ return map;
+ }
+
+ String createPrefix() {
+ // make use of the test method name to avoid collision
+ return getTestMethodName().toLowerCase() + "-";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a5377007/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchBulkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchBulkTest.java b/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchBulkTest.java
new file mode 100644
index 0000000..8c6c3f3
--- /dev/null
+++ b/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchBulkTest.java
@@ -0,0 +1,95 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.elasticsearch5;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.elasticsearch.action.bulk.BulkRequest;
+import org.elasticsearch.action.bulk.BulkResponse;
+import org.elasticsearch.action.index.IndexRequest;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.hasItem;
+import static org.hamcrest.CoreMatchers.notNullValue;
+
+public class ElasticsearchBulkTest extends ElasticsearchBaseTest {
+
+ @Test
+ public void testBulkIndex() throws Exception {
+ List<Map<String, String>> documents = new ArrayList<Map<String, String>>();
+ Map<String, String> document1 = createIndexedData("1");
+ Map<String, String> document2 = createIndexedData("2");
+
+ documents.add(document1);
+ documents.add(document2);
+
+ List<?> indexIds = template.requestBody("direct:bulk_index", documents, List.class);
+ assertNotNull("indexIds should be set", indexIds);
+ assertCollectionSize("Indexed documents should match the size of documents", indexIds, documents.size());
+ }
+
+ @Test
+ public void bulkIndexRequestBody() throws Exception {
+ String prefix = createPrefix();
+
+ // given
+ BulkRequest request = new BulkRequest();
+ request.add(new IndexRequest(prefix + "foo", prefix + "bar", prefix + "baz")
+ .source("{\"" + prefix + "content\": \"" + prefix + "hello\"}"));
+
+ // when
+ @SuppressWarnings("unchecked")
+ List<String> indexedDocumentIds = template.requestBody("direct:bulk_index", request, List.class);
+
+ // then
+ assertThat(indexedDocumentIds, notNullValue());
+ assertThat(indexedDocumentIds.size(), equalTo(1));
+ assertThat(indexedDocumentIds, hasItem(prefix + "baz"));
+ }
+
+ @Test
+ public void bulkRequestBody() throws Exception {
+ String prefix = createPrefix();
+
+ // given
+ BulkRequest request = new BulkRequest();
+ request.add(new IndexRequest(prefix + "foo", prefix + "bar", prefix + "baz")
+ .source("{\"" + prefix + "content\": \"" + prefix + "hello\"}"));
+
+ // when
+ BulkResponse response = template.requestBody("direct:bulk", request, BulkResponse.class);
+
+ // then
+ assertThat(response, notNullValue());
+ assertEquals(prefix + "baz", response.getItems()[0].getId());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:bulk_index").to("elasticsearch5://elasticsearch?operation=BULK_INDEX&indexName=twitter&indexType=tweet");
+ from("direct:bulk").to("elasticsearch5://elasticsearch?operation=BULK&indexName=twitter&indexType=tweet");
+ }
+ };
+ }
+}
[2/5] camel git commit: CAMEL-10766: Adding changes according to
Claus Ibsen comments
Posted by da...@apache.org.
http://git-wip-us.apache.org/repos/asf/camel/blob/659255cf/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml b/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml
index daf5298..d065f9a 100644
--- a/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml
+++ b/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml
@@ -789,6 +789,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-elasticsearch5</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-elsql</artifactId>
<version>${project.version}</version>
</dependency>
[3/5] camel git commit: CAMEL-10766: Adding changes according to
Claus Ibsen comments
Posted by da...@apache.org.
CAMEL-10766: Adding changes according to Claus Ibsen comments
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/659255cf
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/659255cf
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/659255cf
Branch: refs/heads/master
Commit: 659255cf05494fbf0835dccd065f1bc0f9c6bbaa
Parents: a537700
Author: Dmitry Volodin <dm...@gmail.com>
Authored: Wed Feb 1 21:27:08 2017 +0300
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Feb 2 10:04:30 2017 +0100
----------------------------------------------------------------------
components/camel-elasticsearch5/pom.xml | 186 ++++++++---------
.../src/main/docs/elasticsearch5-component.adoc | 29 +--
.../elasticsearch5/ElasticsearchComponent.java | 18 +-
.../ElasticsearchConfiguration.java | 12 +-
.../elasticsearch5/ElasticsearchConstants.java | 15 +-
.../elasticsearch5/ElasticsearchEndpoint.java | 73 +------
.../elasticsearch5/ElasticsearchOperation.java | 58 ++++++
.../elasticsearch5/ElasticsearchProducer.java | 125 ++++++++----
.../elasticsearch5/ElasticsearchBaseTest.java | 12 +-
.../elasticsearch5/ElasticsearchBulkTest.java | 4 +-
.../ElasticsearchClusterBaseTest.java | 11 -
.../ElasticsearchClusterIndexTest.java | 39 +---
...icsearchGetSearchDeleteExistsUpdateTest.java | 50 ++---
.../elasticsearch5/ElasticsearchIndexTest.java | 18 +-
.../src/test/resources/log4j2.properties | 2 +-
components/camel-lucene/pom.xml | 202 +++++++++----------
platforms/catalog-lucene/pom.xml | 39 ++--
...ElasticsearchComponentAutoConfiguration.java | 33 +--
.../ElasticsearchComponentConfiguration.java | 46 -----
.../camel-spring-boot-dependencies/pom.xml | 5 +
20 files changed, 437 insertions(+), 540 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/659255cf/components/camel-elasticsearch5/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/pom.xml b/components/camel-elasticsearch5/pom.xml
index e2e4612..ea372e2 100644
--- a/components/camel-elasticsearch5/pom.xml
+++ b/components/camel-elasticsearch5/pom.xml
@@ -1,101 +1,107 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
- license agreements. See the NOTICE file distributed with this work for additional
- information regarding copyright ownership. The ASF licenses this file to
- You under the Apache License, Version 2.0 (the "License"); you may not use
- this file except in compliance with the License. You may obtain a copy of
- the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
- by applicable law or agreed to in writing, software distributed under the
- License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
- OF ANY KIND, either express or implied. See the License for the specific
- language governing permissions and limitations under the License. -->
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.camel</groupId>
- <artifactId>components</artifactId>
- <version>2.19.0-SNAPSHOT</version>
- </parent>
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>components</artifactId>
+ <version>2.19.0-SNAPSHOT</version>
+ </parent>
- <artifactId>camel-elasticsearch5</artifactId>
- <packaging>jar</packaging>
- <name>Camel :: ElasticSearch5</name>
- <description>Camel ElasticSearch 5.x support</description>
+ <artifactId>camel-elasticsearch5</artifactId>
+ <packaging>jar</packaging>
+ <name>Camel :: ElasticSearch5</name>
+ <description>Camel ElasticSearch 5.x support</description>
- <properties>
- <elasticsearch.version>5.1.2</elasticsearch.version>
- <camel.osgi.export.pkg>org.apache.camel.component.elasticsearch5.*;${camel.osgi.version}</camel.osgi.export.pkg>
- <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=elasticsearch5</camel.osgi.export.service>
- </properties>
+ <properties>
+ <elasticsearch.version>5.1.2</elasticsearch.version>
+ <camel.osgi.export.pkg>org.apache.camel.component.elasticsearch5.*;${camel.osgi.version}</camel.osgi.export.pkg>
+ <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=elasticsearch5</camel.osgi.export.service>
+ </properties>
- <dependencies>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.elasticsearch.client</groupId>
- <artifactId>transport</artifactId>
- <version>${elasticsearch5-version}</version>
- </dependency>
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-databind</artifactId>
- <version>${jackson2-version}</version>
- </dependency>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.elasticsearch.client</groupId>
+ <artifactId>transport</artifactId>
+ <version>${elasticsearch5-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>${jackson2-version}</version>
+ </dependency>
- <!-- for testing -->
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.codelibs</groupId>
- <artifactId>elasticsearch-cluster-runner</artifactId>
- <version>${elasticsearch5-cluster-runner-version}</version>
- <scope>test</scope>
- </dependency>
+ <!-- for testing -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.codelibs</groupId>
+ <artifactId>elasticsearch-cluster-runner</artifactId>
+ <version>${elasticsearch5-cluster-runner-version}</version>
+ <scope>test</scope>
+ </dependency>
- <!-- logging -->
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-api</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-slf4j-impl</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-1.2-api</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
+ <!-- logging -->
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-1.2-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <systemPropertyVariables>
- <es.path.data>target/data</es.path.data>
- </systemPropertyVariables>
- <forkCount>1</forkCount>
- <reuseForks>false</reuseForks>
- </configuration>
- </plugin>
- </plugins>
- </build>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <systemPropertyVariables>
+ <es.path.data>target/data</es.path.data>
+ </systemPropertyVariables>
+ <forkCount>1</forkCount>
+ <reuseForks>false</reuseForks>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/659255cf/components/camel-elasticsearch5/src/main/docs/elasticsearch5-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/main/docs/elasticsearch5-component.adoc b/components/camel-elasticsearch5/src/main/docs/elasticsearch5-component.adoc
index 1447dab..e6e41bc 100644
--- a/components/camel-elasticsearch5/src/main/docs/elasticsearch5-component.adoc
+++ b/components/camel-elasticsearch5/src/main/docs/elasticsearch5-component.adoc
@@ -31,17 +31,7 @@ elasticsearch5://clusterName[?options]
// component options: START
-The Elasticsearch5 component supports 1 options which are listed below.
-
-
-
-{% raw %}
-[width="100%",cols="2,1,1m,1m,5",options="header"]
-|=======================================================================
-| Name | Group | Default | Java Type | Description
-| client | advanced | | TransportClient | To use an existing configured Elasticsearch client instead of creating a client per endpoint.
-|=======================================================================
-{% endraw %}
+The Elasticsearch5 component has no options.
// component options: END
@@ -60,10 +50,10 @@ The Elasticsearch5 component supports 10 endpoint options which are listed below
| indexName | producer | | String | The name of the index to act against
| indexType | producer | | String | The type of the index to act against
| ip | producer | | String | The TransportClient remote host ip to use
-| operation | producer | | String | What operation to perform
-| port | producer | | int | The TransportClient remote port to use (defaults to 9300)
+| operation | producer | | ElasticsearchOperation | What operation to perform
+| port | producer | 9300 | int | The TransportClient remote port to use (defaults to 9300)
| transportAddresses | producer | | String | Comma separated list with ip:port formatted remote transport addresses to use. The ip and port options must be left blank for transportAddresses to be considered instead.
-| waitForActiveShards | producer | | int | Index creation waits for the write consistency number of shards to be available
+| waitForActiveShards | producer | 1 | int | Index creation waits for the write consistency number of shards to be available
| synchronous | advanced | false | boolean | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported).
|=======================================================================
{% endraw %}
@@ -81,13 +71,16 @@ other parameters or the message body to be set.
|=======================================================================
|operation |message body |description
-|INDEX |Map, String, byte[] or XContentBuilder content to index |adds content to an index and returns the content's indexId in the body.
+|INDEX |Map, String, byte[] or XContentBuilder content to index |Adds content to an index and returns the content's indexId in the body.
You can set the indexId by setting the message header with
the key "indexId".
-|GET_BY_ID |index id of content to retrieve |retrieves the specified index and returns a GetResult object in the body
+|GET_BY_ID |index id of content to retrieve |Retrieves the specified index and returns a GetResult object in the body
+
+|DELETE |index name and type of content to delete |Deletes the specified indexName and indexType and returns a DeleteResponse object in the
+body
-|DELETE |index id of content to delete |deletes the specified indexId and returns a DeleteResult object in the
+|DELETE_INDEX |index name of content to delete |Deletes the specified indexName and returns a DeleteIndexResponse object in the
body
|BULK_INDEX | a�*List*�or *Collection* of any type that is already accepted
@@ -106,7 +99,7 @@ MultigetRequest and returns a MultigetResponse object in the body
|MULTISEARCH |List of SearchRequest object |Search for parameters specified in MultiSearchRequest and
returns a MultiSearchResponse object in the body
-|EXISTS |Index name as header |Returns a Boolean object in the body
+|EXISTS |Index name as header |Checks the index exists or not and returns a Boolean flag in the body
|UPDATE |Map, String, byte[] or XContentBuilder content to update |Updates content to an index and returns the content's
indexId in the body.
http://git-wip-us.apache.org/repos/asf/camel/blob/659255cf/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchComponent.java b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchComponent.java
index 1205519..cb3cd6c 100644
--- a/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchComponent.java
+++ b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchComponent.java
@@ -35,9 +35,6 @@ import org.elasticsearch.common.transport.InetSocketTransportAddress;
*/
public class ElasticsearchComponent extends UriEndpointComponent {
- @Metadata(label = "advanced")
- private TransportClient client;
-
public ElasticsearchComponent() {
super(ElasticsearchEndpoint.class);
}
@@ -53,7 +50,7 @@ public class ElasticsearchComponent extends UriEndpointComponent {
config.setTransportAddressesList(parseTransportAddresses(config.getTransportAddresses(), config));
- Endpoint endpoint = new ElasticsearchEndpoint(uri, this, config, client);
+ Endpoint endpoint = new ElasticsearchEndpoint(uri, this, config);
return endpoint;
}
@@ -76,15 +73,4 @@ public class ElasticsearchComponent extends UriEndpointComponent {
}
return addressesTrAd;
}
-
- public TransportClient getClient() {
- return client;
- }
-
- /**
- * To use an existing configured Elasticsearch client, instead of creating a client per endpoint.
- */
- public void setClient(TransportClient client) {
- this.client = client;
- }
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/659255cf/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchConfiguration.java b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchConfiguration.java
index 308ee83..ca09954 100644
--- a/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchConfiguration.java
+++ b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchConfiguration.java
@@ -31,19 +31,19 @@ public class ElasticsearchConfiguration {
@UriPath @Metadata(required = "true")
private String clusterName;
- @UriParam(enums = "INDEX, UPDATE, BULK, BULK_INDEX, GET_BY_ID, MULTIGET, DELETE, EXISTS, SEARCH, MULTISEARCH, DELETE_INDEX")
- private String operation;
+ @UriParam
+ private ElasticsearchOperation operation;
@UriParam
private String indexName;
@UriParam
private String indexType;
- @UriParam
+ @UriParam(defaultValue = "" + ElasticsearchConstants.DEFAULT_FOR_WAIT_ACTIVE_SHARDS)
private int waitForActiveShards = ElasticsearchConstants.DEFAULT_FOR_WAIT_ACTIVE_SHARDS;
@UriParam
private String ip;
@UriParam
private String transportAddresses;
- @UriParam
+ @UriParam(defaultValue = "" + ElasticsearchConstants.DEFAULT_PORT)
private int port = ElasticsearchConstants.DEFAULT_PORT;
@UriParam(defaultValue = "true")
private Boolean clientTransportSniff = true;
@@ -62,11 +62,11 @@ public class ElasticsearchConfiguration {
/**
* What operation to perform
*/
- public String getOperation() {
+ public ElasticsearchOperation getOperation() {
return operation;
}
- public void setOperation(String operation) {
+ public void setOperation(ElasticsearchOperation operation) {
this.operation = operation;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/659255cf/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchConstants.java b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchConstants.java
index ab30a85..6c31173 100644
--- a/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchConstants.java
+++ b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchConstants.java
@@ -21,17 +21,6 @@ package org.apache.camel.component.elasticsearch5;
public interface ElasticsearchConstants {
String PARAM_OPERATION = "operation";
- String OPERATION_INDEX = "INDEX";
- String OPERATION_UPDATE = "UPDATE";
- String OPERATION_BULK = "BULK";
- String OPERATION_BULK_INDEX = "BULK_INDEX";
- String OPERATION_GET_BY_ID = "GET_BY_ID";
- String OPERATION_MULTIGET = "MULTIGET";
- String OPERATION_DELETE = "DELETE";
- String OPERATION_DELETE_INDEX = "DELETE_INDEX";
- String OPERATION_SEARCH = "SEARCH";
- String OPERATION_MULTISEARCH = "MULTISEARCH";
- String OPERATION_EXISTS = "EXISTS";
String PARAM_INDEX_ID = "indexId";
String PARAM_INDEX_NAME = "indexName";
String PARAM_INDEX_TYPE = "indexType";
@@ -41,8 +30,8 @@ public interface ElasticsearchConstants {
String PROTOCOL = "elasticsearch";
String IP = "ip";
String PORT = "port";
- Integer DEFAULT_PORT = 9300;
- Integer DEFAULT_FOR_WAIT_ACTIVE_SHARDS = 1; // Meaning only wait for the primary shard
+ int DEFAULT_PORT = 9300;
+ int DEFAULT_FOR_WAIT_ACTIVE_SHARDS = 1; // Meaning only wait for the primary shard
String TRANSPORT_ADDRESSES_SEPARATOR_REGEX = ",";
String IP_PORT_SEPARATOR_REGEX = ":";
String ES_QUERY_DSL_PREFIX = "query";
http://git-wip-us.apache.org/repos/asf/camel/blob/659255cf/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchEndpoint.java b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchEndpoint.java
index f9aad84..f71bca2 100644
--- a/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchEndpoint.java
+++ b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchEndpoint.java
@@ -16,21 +16,12 @@
*/
package org.apache.camel.component.elasticsearch5;
-import java.net.InetAddress;
-import java.util.ArrayList;
-import java.util.List;
-
import org.apache.camel.Consumer;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
import org.apache.camel.impl.DefaultEndpoint;
import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.spi.UriParam;
-import org.elasticsearch.client.transport.TransportClient;
-import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.common.transport.InetSocketTransportAddress;
-import org.elasticsearch.common.transport.TransportAddress;
-import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -42,18 +33,16 @@ public class ElasticsearchEndpoint extends DefaultEndpoint {
private static final Logger LOG = LoggerFactory.getLogger(ElasticsearchEndpoint.class);
- private TransportClient client;
@UriParam
- private ElasticsearchConfiguration configuration;
+ protected final ElasticsearchConfiguration configuration;
- public ElasticsearchEndpoint(String uri, ElasticsearchComponent component, ElasticsearchConfiguration config, TransportClient client) throws Exception {
+ public ElasticsearchEndpoint(String uri, ElasticsearchComponent component, ElasticsearchConfiguration config) throws Exception {
super(uri, component);
this.configuration = config;
- this.client = client;
}
public Producer createProducer() throws Exception {
- return new ElasticsearchProducer(this);
+ return new ElasticsearchProducer(this, configuration);
}
public Consumer createConsumer(Processor processor) throws Exception {
@@ -61,60 +50,6 @@ public class ElasticsearchEndpoint extends DefaultEndpoint {
}
public boolean isSingleton() {
- return false;
- }
-
- @Override
- @SuppressWarnings("unchecked")
- protected void doStart() throws Exception {
- super.doStart();
-
- if (client == null) {
- LOG.info("Connecting to the ElasticSearch cluster: " + configuration.getClusterName());
-
- if (configuration.getIp() != null) {
- client = new PreBuiltTransportClient(getSettings())
- .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(configuration.getIp()), configuration.getPort()));
- } else if (configuration.getTransportAddressesList() != null
- && !configuration.getTransportAddressesList().isEmpty()) {
- List<TransportAddress> addresses = new ArrayList<TransportAddress>(configuration.getTransportAddressesList().size());
- for (TransportAddress address : configuration.getTransportAddressesList()) {
- addresses.add(address);
- }
- client = new PreBuiltTransportClient(getSettings()).addTransportAddresses(addresses.toArray(new TransportAddress[addresses.size()]));
- } else {
- LOG.info("Incorrect ip address and port parameters settings for ElasticSearch cluster");
- }
- }
- }
-
- private Settings getSettings() {
- return Settings.builder()
- .put("cluster.name", configuration.getClusterName())
- .put("client.transport.ignore_cluster_name", false)
- .put("client.transport.sniff", configuration.getClientTransportSniff())
- .build();
- }
-
- @Override
- protected void doStop() throws Exception {
- if (client != null) {
- LOG.info("Disconnecting from ElasticSearch cluster: " + configuration.getClusterName());
- client.close();
- client = null;
- }
- super.doStop();
- }
-
- public TransportClient getClient() {
- return client;
- }
-
- public ElasticsearchConfiguration getConfig() {
- return configuration;
- }
-
- public void setOperation(String operation) {
- configuration.setOperation(operation);
+ return true;
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/659255cf/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchOperation.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchOperation.java b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchOperation.java
new file mode 100644
index 0000000..509b30a
--- /dev/null
+++ b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchOperation.java
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.elasticsearch5;
+
+/**
+ * The ElasticSearch server operations list which are implemented
+ *
+ * INDEX - Index a document associated with a given index and type
+ * UPDATE - Updates a document based on a script
+ * BULK - Executes a bulk of index / delete operations
+ * BULK_INDEX - Executes a bulk of index / delete operations
+ * GET_BY_ID - Gets the document that was indexed from an index with a type and id
+ * MULTIGET - Multiple get documents
+ * DELETE - Deletes a document from the index based on the index, type and id
+ * DELETE_INDEX - Deletes an index based on the index name
+ * SEARCH - Search across one or more indices and one or more types with a query
+ * MULTISEARCH - Performs multiple search requests
+ * EXISTS - Checks the index exists or not (using search with size=0 and terminate_after=1 parameters)
+ *
+ */
+public enum ElasticsearchOperation {
+ INDEX("INDEX"),
+ UPDATE("UPDATE"),
+ BULK("BULK"),
+ BULK_INDEX("BULK_INDEX"),
+ GET_BY_ID("GET_BY_ID"),
+ MULTIGET("MULTIGET"),
+ DELETE("DELETE"),
+ DELETE_INDEX("DELETE_INDEX"),
+ SEARCH("SEARCH"),
+ MULTISEARCH("MULTISEARCH"),
+ EXISTS("EXISTS");
+
+ private final String text;
+
+ ElasticsearchOperation(final String text) {
+ this.text = text;
+ }
+
+ @Override
+ public String toString() {
+ return text;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/659255cf/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchProducer.java b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchProducer.java
index c63aebf..c0aaff9 100644
--- a/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchProducer.java
+++ b/components/camel-elasticsearch5/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchProducer.java
@@ -16,6 +16,7 @@
*/
package org.apache.camel.component.elasticsearch5;
+import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
@@ -33,23 +34,30 @@ import org.elasticsearch.action.search.MultiSearchRequest;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.client.transport.TransportClient;
+import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.transport.InetSocketTransportAddress;
+import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.index.IndexNotFoundException;
+import org.elasticsearch.transport.client.PreBuiltTransportClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Represents an Elasticsearch producer.
*/
public class ElasticsearchProducer extends DefaultProducer {
-
- public ElasticsearchProducer(ElasticsearchEndpoint endpoint) {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ElasticsearchProducer.class);
+
+ protected final ElasticsearchConfiguration configuration;
+ private TransportClient client;
+
+ public ElasticsearchProducer(ElasticsearchEndpoint endpoint, ElasticsearchConfiguration configuration) {
super(endpoint);
+ this.configuration = configuration;
}
- @Override
- public ElasticsearchEndpoint getEndpoint() {
- return (ElasticsearchEndpoint) super.getEndpoint();
- }
-
- private String resolveOperation(Exchange exchange) {
+ private ElasticsearchOperation resolveOperation(Exchange exchange) {
// 1. Operation can be driven by either (in order of preference):
// a. If the body is an ActionRequest the operation is set by the type
// of request.
@@ -61,35 +69,33 @@ public class ElasticsearchProducer extends DefaultProducer {
// an error.
Object request = exchange.getIn().getBody();
if (request instanceof IndexRequest) {
- return ElasticsearchConstants.OPERATION_INDEX;
+ return ElasticsearchOperation.INDEX;
} else if (request instanceof GetRequest) {
- return ElasticsearchConstants.OPERATION_GET_BY_ID;
+ return ElasticsearchOperation.GET_BY_ID;
} else if (request instanceof MultiGetRequest) {
- return ElasticsearchConstants.OPERATION_MULTIGET;
+ return ElasticsearchOperation.MULTIGET;
} else if (request instanceof UpdateRequest) {
- return ElasticsearchConstants.OPERATION_UPDATE;
+ return ElasticsearchOperation.UPDATE;
} else if (request instanceof BulkRequest) {
// do we want bulk or bulk_index?
- if (ElasticsearchConstants.OPERATION_BULK_INDEX.equals(getEndpoint().getConfig().getOperation())) {
- return ElasticsearchConstants.OPERATION_BULK_INDEX;
+ if (configuration.getOperation() == ElasticsearchOperation.BULK_INDEX) {
+ return configuration.getOperation().BULK_INDEX;
} else {
- return ElasticsearchConstants.OPERATION_BULK;
+ return configuration.getOperation().BULK;
}
} else if (request instanceof DeleteRequest) {
- return ElasticsearchConstants.OPERATION_DELETE;
+ return ElasticsearchOperation.DELETE;
} else if (request instanceof SearchRequest) {
- return ElasticsearchConstants.OPERATION_EXISTS;
- } else if (request instanceof SearchRequest) {
- return ElasticsearchConstants.OPERATION_SEARCH;
+ return ElasticsearchOperation.SEARCH;
} else if (request instanceof MultiSearchRequest) {
- return ElasticsearchConstants.OPERATION_MULTISEARCH;
+ return ElasticsearchOperation.MULTISEARCH;
} else if (request instanceof DeleteIndexRequest) {
- return ElasticsearchConstants.OPERATION_DELETE_INDEX;
+ return ElasticsearchOperation.DELETE_INDEX;
}
- String operationConfig = exchange.getIn().getHeader(ElasticsearchConstants.PARAM_OPERATION, String.class);
+ ElasticsearchOperation operationConfig = exchange.getIn().getHeader(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.class);
if (operationConfig == null) {
- operationConfig = getEndpoint().getConfig().getOperation();
+ operationConfig = configuration.getOperation();
}
if (operationConfig == null) {
throw new IllegalArgumentException(ElasticsearchConstants.PARAM_OPERATION + " value '" + operationConfig + "' is not supported");
@@ -109,58 +115,57 @@ public class ElasticsearchProducer extends DefaultProducer {
// will throw.
Message message = exchange.getIn();
- final String operation = resolveOperation(exchange);
+ final ElasticsearchOperation operation = resolveOperation(exchange);
// Set the index/type headers on the exchange if necessary. This is used
// for type conversion.
boolean configIndexName = false;
String indexName = message.getHeader(ElasticsearchConstants.PARAM_INDEX_NAME, String.class);
if (indexName == null) {
- message.setHeader(ElasticsearchConstants.PARAM_INDEX_NAME, getEndpoint().getConfig().getIndexName());
+ message.setHeader(ElasticsearchConstants.PARAM_INDEX_NAME, configuration.getIndexName());
configIndexName = true;
}
boolean configIndexType = false;
String indexType = message.getHeader(ElasticsearchConstants.PARAM_INDEX_TYPE, String.class);
if (indexType == null) {
- message.setHeader(ElasticsearchConstants.PARAM_INDEX_TYPE, getEndpoint().getConfig().getIndexType());
+ message.setHeader(ElasticsearchConstants.PARAM_INDEX_TYPE, configuration.getIndexType());
configIndexType = true;
}
boolean configWaitForActiveShards = false;
Integer waitForActiveShards = message.getHeader(ElasticsearchConstants.PARAM_WAIT_FOR_ACTIVE_SHARDS, Integer.class);
if (waitForActiveShards == null) {
- message.setHeader(ElasticsearchConstants.PARAM_WAIT_FOR_ACTIVE_SHARDS, getEndpoint().getConfig().getWaitForActiveShards());
+ message.setHeader(ElasticsearchConstants.PARAM_WAIT_FOR_ACTIVE_SHARDS, configuration.getWaitForActiveShards());
configWaitForActiveShards = true;
}
- TransportClient client = getEndpoint().getClient();
- if (ElasticsearchConstants.OPERATION_INDEX.equals(operation)) {
+ if (operation == ElasticsearchOperation.INDEX) {
IndexRequest indexRequest = message.getBody(IndexRequest.class);
message.setBody(client.index(indexRequest).actionGet().getId());
- } else if (ElasticsearchConstants.OPERATION_UPDATE.equals(operation)) {
+ } else if (operation == ElasticsearchOperation.UPDATE) {
UpdateRequest updateRequest = message.getBody(UpdateRequest.class);
message.setBody(client.update(updateRequest).actionGet().getId());
- } else if (ElasticsearchConstants.OPERATION_GET_BY_ID.equals(operation)) {
+ } else if (operation == ElasticsearchOperation.GET_BY_ID) {
GetRequest getRequest = message.getBody(GetRequest.class);
message.setBody(client.get(getRequest));
- } else if (ElasticsearchConstants.OPERATION_MULTIGET.equals(operation)) {
+ } else if (operation == ElasticsearchOperation.MULTIGET) {
MultiGetRequest multiGetRequest = message.getBody(MultiGetRequest.class);
message.setBody(client.multiGet(multiGetRequest));
- } else if (ElasticsearchConstants.OPERATION_BULK.equals(operation)) {
+ } else if (operation == ElasticsearchOperation.BULK) {
BulkRequest bulkRequest = message.getBody(BulkRequest.class);
message.setBody(client.bulk(bulkRequest).actionGet());
- } else if (ElasticsearchConstants.OPERATION_BULK_INDEX.equals(operation)) {
+ } else if (operation == ElasticsearchOperation.BULK_INDEX) {
BulkRequest bulkRequest = message.getBody(BulkRequest.class);
List<String> indexedIds = new ArrayList<String>();
for (BulkItemResponse response : client.bulk(bulkRequest).actionGet().getItems()) {
indexedIds.add(response.getId());
}
message.setBody(indexedIds);
- } else if (ElasticsearchConstants.OPERATION_DELETE.equals(operation)) {
+ } else if (operation == ElasticsearchOperation.DELETE) {
DeleteRequest deleteRequest = message.getBody(DeleteRequest.class);
message.setBody(client.delete(deleteRequest).actionGet());
- } else if (ElasticsearchConstants.OPERATION_EXISTS.equals(operation)) {
+ } else if (operation == ElasticsearchOperation.EXISTS) {
// ExistsRequest API is deprecated, using SearchRequest instead with size=0 and terminate_after=1
SearchRequest searchRequest = new SearchRequest(exchange.getIn().getHeader(ElasticsearchConstants.PARAM_INDEX_NAME, String.class));
try {
@@ -169,13 +174,13 @@ public class ElasticsearchProducer extends DefaultProducer {
} catch (IndexNotFoundException e) {
message.setBody(false);
}
- } else if (ElasticsearchConstants.OPERATION_SEARCH.equals(operation)) {
+ } else if (operation == ElasticsearchOperation.SEARCH) {
SearchRequest searchRequest = message.getBody(SearchRequest.class);
message.setBody(client.search(searchRequest).actionGet());
- } else if (ElasticsearchConstants.OPERATION_MULTISEARCH.equals(operation)) {
+ } else if (operation == ElasticsearchOperation.MULTISEARCH) {
MultiSearchRequest multiSearchRequest = message.getBody(MultiSearchRequest.class);
message.setBody(client.multiSearch(multiSearchRequest));
- } else if (ElasticsearchConstants.OPERATION_DELETE_INDEX.equals(operation)) {
+ } else if (operation == ElasticsearchOperation.DELETE_INDEX) {
DeleteIndexRequest deleteIndexRequest = message.getBody(DeleteIndexRequest.class);
message.setBody(client.admin().indices().delete(deleteIndexRequest).actionGet());
} else {
@@ -203,4 +208,46 @@ public class ElasticsearchProducer extends DefaultProducer {
}
}
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected void doStart() throws Exception {
+ super.doStart();
+
+ if (client == null) {
+ LOG.info("Connecting to the ElasticSearch cluster: " + configuration.getClusterName());
+
+ if (configuration.getIp() != null) {
+ client = new PreBuiltTransportClient(getSettings())
+ .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(configuration.getIp()), configuration.getPort()));
+ } else if (configuration.getTransportAddressesList() != null
+ && !configuration.getTransportAddressesList().isEmpty()) {
+ List<TransportAddress> addresses = new ArrayList<TransportAddress>(configuration.getTransportAddressesList().size());
+ for (TransportAddress address : configuration.getTransportAddressesList()) {
+ addresses.add(address);
+ }
+ client = new PreBuiltTransportClient(getSettings()).addTransportAddresses(addresses.toArray(new TransportAddress[addresses.size()]));
+ } else {
+ LOG.info("Incorrect ip address and port parameters settings for ElasticSearch cluster");
+ }
+ }
+ }
+
+ private Settings getSettings() {
+ return Settings.builder()
+ .put("cluster.name", configuration.getClusterName())
+ .put("client.transport.ignore_cluster_name", false)
+ .put("client.transport.sniff", configuration.getClientTransportSniff())
+ .build();
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ if (client != null) {
+ LOG.info("Disconnecting from ElasticSearch cluster: " + configuration.getClusterName());
+ client.close();
+ client = null;
+ }
+ super.doStop();
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/659255cf/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchBaseTest.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchBaseTest.java b/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchBaseTest.java
index a6e5ab9..e70b22b 100644
--- a/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchBaseTest.java
+++ b/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchBaseTest.java
@@ -49,12 +49,14 @@ public class ElasticsearchBaseTest extends CamelTestSupport {
}
@BeforeClass
- public static void cleanupOnce() throws NodeValidationException {
+ public static void cleanupOnce() throws Exception {
deleteDirectory("target/data");
// create an embedded node to resume
node = new PluginConfigurableNode(Settings.builder().put("http.enabled", true).put("path.data", "target/data")
.put("path.home", "target/home").build(), Arrays.asList(Netty4Plugin.class)).start();
+ client = new PreBuiltTransportClient(Settings.EMPTY)
+ .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
}
@AfterClass
@@ -76,14 +78,6 @@ public class ElasticsearchBaseTest extends CamelTestSupport {
@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext context = super.createCamelContext();
-
- // reuse existing client
- ElasticsearchComponent es = context.getComponent("elasticsearch5", ElasticsearchComponent.class);
-
- client = new PreBuiltTransportClient(Settings.EMPTY)
- .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
- es.setClient(client);
-
return context;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/659255cf/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchBulkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchBulkTest.java b/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchBulkTest.java
index 8c6c3f3..61a0984 100644
--- a/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchBulkTest.java
+++ b/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchBulkTest.java
@@ -87,8 +87,8 @@ public class ElasticsearchBulkTest extends ElasticsearchBaseTest {
return new RouteBuilder() {
@Override
public void configure() {
- from("direct:bulk_index").to("elasticsearch5://elasticsearch?operation=BULK_INDEX&indexName=twitter&indexType=tweet");
- from("direct:bulk").to("elasticsearch5://elasticsearch?operation=BULK&indexName=twitter&indexType=tweet");
+ from("direct:bulk_index").to("elasticsearch5://elasticsearch?operation=BULK_INDEX&indexName=twitter&indexType=tweet&ip=localhost&port=9300");
+ from("direct:bulk").to("elasticsearch5://elasticsearch?operation=BULK&indexName=twitter&indexType=tweet&ip=localhost&port=9300");
}
};
}
http://git-wip-us.apache.org/repos/asf/camel/blob/659255cf/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchClusterBaseTest.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchClusterBaseTest.java b/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchClusterBaseTest.java
index a5dd5d3..2f856ad 100644
--- a/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchClusterBaseTest.java
+++ b/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchClusterBaseTest.java
@@ -94,17 +94,6 @@ public class ElasticsearchClusterBaseTest extends CamelTestSupport {
return true;
}
- @Override
- protected CamelContext createCamelContext() throws Exception {
- CamelContext context = super.createCamelContext();
-
- // reuse existing client
- ElasticsearchComponent es = context.getComponent("elasticsearch5", ElasticsearchComponent.class);
- es.setClient(client);
-
- return context;
- }
-
/**
* As we don't delete the {@code target/data} folder for <b>each</b> test
* below (otherwise they would run much slower), we need to make sure
http://git-wip-us.apache.org/repos/asf/camel/blob/659255cf/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchClusterIndexTest.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchClusterIndexTest.java b/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchClusterIndexTest.java
index 81ca789..f7347d1 100644
--- a/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchClusterIndexTest.java
+++ b/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchClusterIndexTest.java
@@ -25,26 +25,26 @@ import org.junit.Test;
public class ElasticsearchClusterIndexTest extends ElasticsearchClusterBaseTest {
@Test
- public void indexWithIp() throws Exception {
+ public void indexWithIpAndPort() throws Exception {
Map<String, String> map = createIndexedData();
Map<String, Object> headers = new HashMap<String, Object>();
- headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.INDEX);
headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter");
headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "tweet");
headers.put(ElasticsearchConstants.PARAM_INDEX_ID, "1");
- String indexId = template.requestBodyAndHeaders("direct:indexWithIp", map, headers, String.class);
+ String indexId = template.requestBodyAndHeaders("direct:indexWithIpAndPort", map, headers, String.class);
assertNotNull("indexId should be set", indexId);
headers.clear();
- headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.INDEX);
headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter");
headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "status");
headers.put(ElasticsearchConstants.PARAM_INDEX_ID, "2");
- indexId = template.requestBodyAndHeaders("direct:indexWithIp", map, headers, String.class);
+ indexId = template.requestBodyAndHeaders("direct:indexWithIpAndPort", map, headers, String.class);
assertNotNull("indexId should be set", indexId);
assertEquals("Cluster must be of three nodes", runner.getNodeSize(), 3);
@@ -53,26 +53,10 @@ public class ElasticsearchClusterIndexTest extends ElasticsearchClusterBaseTest
}
@Test
- public void indexWithIpAndPort() throws Exception {
- Map<String, String> map = createIndexedData();
- Map<String, Object> headers = new HashMap<String, Object>();
- headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
- headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "instagram");
- headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "photo");
- headers.put(ElasticsearchConstants.PARAM_INDEX_ID, "3");
-
- String indexId = template.requestBodyAndHeaders("direct:indexWithIpAndPort", map, headers, String.class);
- assertNotNull("indexId should be set", indexId);
-
- assertEquals("Cluster must be of three nodes", runner.getNodeSize(), 3);
- assertEquals("Index id 3 must exists", true, client.prepareGet("instagram", "photo", "3").get().isExists());
- }
-
- @Test
public void indexWithTransportAddresses() throws Exception {
Map<String, String> map = createIndexedData();
Map<String, Object> headers = new HashMap<String, Object>();
- headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.INDEX);
headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "facebook");
headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "post");
headers.put(ElasticsearchConstants.PARAM_INDEX_ID, "4");
@@ -88,7 +72,7 @@ public class ElasticsearchClusterIndexTest extends ElasticsearchClusterBaseTest
public void indexWithIpAndTransportAddresses() throws Exception {
Map<String, String> map = createIndexedData();
Map<String, Object> headers = new HashMap<String, Object>();
- headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.INDEX);
headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "ebay");
headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "search");
headers.put(ElasticsearchConstants.PARAM_INDEX_ID, "5");
@@ -106,12 +90,11 @@ public class ElasticsearchClusterIndexTest extends ElasticsearchClusterBaseTest
return new RouteBuilder() {
@Override
public void configure() {
- from("direct:indexWithIp").to("elasticsearch5://elasticsearch?operation=INDEX&indexName=twitter&indexType=tweet&port=9301");
- from("direct:indexWithIpAndPort").to("elasticsearch5://elasticsearch?operation=INDEX&indexName=twitter&indexType=tweet&ip=localhost&port=9301");
- from("direct:indexWithTransportAddresses").to("elasticsearch5://elasticsearch?operation=INDEX&indexName=twitter&indexType=tweet&transportAddresses=localhost:9301");
+ from("direct:indexWithIpAndPort").to("elasticsearch5://" + clusterName + "?operation=INDEX&indexName=twitter&indexType=tweet&ip=localhost&port=9301");
+ from("direct:indexWithTransportAddresses").to("elasticsearch5://" + clusterName + "?operation=INDEX&indexName=twitter&indexType=tweet&transportAddresses=localhost:9301");
from("direct:indexWithIpAndTransportAddresses").
- to("elasticsearch5://elasticsearch?operation=INDEX&indexName=twitter&indexType=tweet&ip=localhost&port=9301&transportAddresses=localhost:4444,localhost:5555");
+ to("elasticsearch5://" + clusterName + "?operation=INDEX&indexName=twitter&indexType=tweet&ip=localhost&port=9301&transportAddresses=localhost:4444,localhost:5555");
}
};
}
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/659255cf/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchGetSearchDeleteExistsUpdateTest.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchGetSearchDeleteExistsUpdateTest.java b/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchGetSearchDeleteExistsUpdateTest.java
index 782929d..06e5df8 100644
--- a/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchGetSearchDeleteExistsUpdateTest.java
+++ b/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchGetSearchDeleteExistsUpdateTest.java
@@ -129,14 +129,14 @@ public class ElasticsearchGetSearchDeleteExistsUpdateTest extends ElasticsearchB
//first, INDEX a value
Map<String, String> map = createIndexedData();
Map<String, Object> headers = new HashMap<String, Object>();
- headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.INDEX);
headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter");
headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "tweet");
String indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class);
//now, verify GET
- headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_GET_BY_ID);
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.GET_BY_ID);
GetResponse response = template.requestBodyAndHeaders("direct:start", indexId, headers, GetResponse.class);
assertNotNull("response should not be null", response);
assertNotNull("response source should not be null", response.getSource());
@@ -147,14 +147,14 @@ public class ElasticsearchGetSearchDeleteExistsUpdateTest extends ElasticsearchB
//first, INDEX a value
Map<String, String> map = createIndexedData();
Map<String, Object> headers = new HashMap<String, Object>();
- headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.INDEX);
headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter");
headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "tweet");
String indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class);
//now, verify GET
- headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_EXISTS);
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.EXISTS);
headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter");
Boolean exists = template.requestBodyAndHeaders("direct:exists", "", headers, Boolean.class);
assertNotNull("response should not be null", exists);
@@ -166,14 +166,14 @@ public class ElasticsearchGetSearchDeleteExistsUpdateTest extends ElasticsearchB
//first, INDEX a value
Map<String, String> map = createIndexedData();
Map<String, Object> headers = new HashMap<String, Object>();
- headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.INDEX);
headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter");
headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "tweet");
String indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class);
//now, verify GET
- headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_EXISTS);
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.EXISTS);
headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter-tweet");
Boolean exists = template.requestBodyAndHeaders("direct:exists", "", headers, Boolean.class);
assertNotNull("response should not be null", exists);
@@ -185,7 +185,7 @@ public class ElasticsearchGetSearchDeleteExistsUpdateTest extends ElasticsearchB
//first, INDEX two values
Map<String, String> map = createIndexedData();
Map<String, Object> headers = new HashMap<String, Object>();
- headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.INDEX);
headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter");
headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "tweet");
headers.put(ElasticsearchConstants.PARAM_INDEX_ID, "1");
@@ -193,7 +193,7 @@ public class ElasticsearchGetSearchDeleteExistsUpdateTest extends ElasticsearchB
template.requestBodyAndHeaders("direct:start", map, headers, String.class);
headers.clear();
- headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.INDEX);
headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "facebook");
headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "status");
headers.put(ElasticsearchConstants.PARAM_INDEX_ID, "2");
@@ -202,7 +202,7 @@ public class ElasticsearchGetSearchDeleteExistsUpdateTest extends ElasticsearchB
headers.clear();
//now, verify MULTIGET
- headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_MULTIGET);
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.MULTIGET);
Item item1 = new Item("twitter", "tweet", "1");
Item item2 = new Item("facebook", "status", "2");
Item item3 = new Item("instagram", "latest", "3");
@@ -230,7 +230,7 @@ public class ElasticsearchGetSearchDeleteExistsUpdateTest extends ElasticsearchB
node.client().prepareIndex("test", "type", "2").setSource("field", "yyy").execute().actionGet();
//now, verify MULTISEARCH
- headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_MULTISEARCH);
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.MULTISEARCH);
SearchRequestBuilder srb1 = node.client().prepareSearch("test").setTypes("type").setQuery(QueryBuilders.termQuery("field", "xxx"));
SearchRequestBuilder srb2 = node.client().prepareSearch("test").setTypes("type").setQuery(QueryBuilders.termQuery("field", "yyy"));
SearchRequestBuilder srb3 = node.client().prepareSearch("instagram")
@@ -253,25 +253,25 @@ public class ElasticsearchGetSearchDeleteExistsUpdateTest extends ElasticsearchB
//first, INDEX a value
Map<String, String> map = createIndexedData();
Map<String, Object> headers = new HashMap<String, Object>();
- headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.INDEX);
headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter");
headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "tweet");
String indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class);
//now, verify GET
- headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_GET_BY_ID);
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.GET_BY_ID);
GetResponse response = template.requestBodyAndHeaders("direct:start", indexId, headers, GetResponse.class);
assertNotNull("response should not be null", response);
assertNotNull("response source should not be null", response.getSource());
//now, perform DELETE
- headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_DELETE);
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.DELETE);
DeleteResponse deleteResponse = template.requestBodyAndHeaders("direct:start", indexId, headers, DeleteResponse.class);
assertNotNull("response should not be null", deleteResponse);
//now, verify GET fails to find the indexed value
- headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_GET_BY_ID);
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.GET_BY_ID);
response = template.requestBodyAndHeaders("direct:start", indexId, headers, GetResponse.class);
assertNotNull("response should not be null", response);
assertNull("response source should be null", response.getSource());
@@ -281,7 +281,7 @@ public class ElasticsearchGetSearchDeleteExistsUpdateTest extends ElasticsearchB
public void testUpdateWithIDInHeader() throws Exception {
Map<String, String> map = createIndexedData();
Map<String, Object> headers = new HashMap<String, Object>();
- headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.INDEX);
headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter");
headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "tweet");
headers.put(ElasticsearchConstants.PARAM_INDEX_ID, "123");
@@ -290,7 +290,7 @@ public class ElasticsearchGetSearchDeleteExistsUpdateTest extends ElasticsearchB
assertNotNull("indexId should be set", indexId);
assertEquals("indexId should be equals to the provided id", "123", indexId);
- headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_UPDATE);
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.UPDATE);
indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class);
assertNotNull("indexId should be set", indexId);
@@ -340,15 +340,15 @@ public class ElasticsearchGetSearchDeleteExistsUpdateTest extends ElasticsearchB
return new RouteBuilder() {
@Override
public void configure() {
- from("direct:start").to("elasticsearch5://elasticsearch?operation=INDEX");
- from("direct:index").to("elasticsearch5://elasticsearch?operation=INDEX&indexName=twitter&indexType=tweet");
- from("direct:get").to("elasticsearch5://elasticsearch?operation=GET_BY_ID&indexName=twitter&indexType=tweet");
- from("direct:multiget").to("elasticsearch5://elasticsearch?operation=MULTIGET&indexName=twitter&indexType=tweet");
- from("direct:delete").to("elasticsearch5://elasticsearch?operation=DELETE&indexName=twitter&indexType=tweet");
- from("direct:search").to("elasticsearch5://elasticsearch?operation=SEARCH&indexName=twitter&indexType=tweet");
- from("direct:update").to("elasticsearch5://elasticsearch?operation=UPDATE&indexName=twitter&indexType=tweet");
- from("direct:exists").to("elasticsearch5://elasticsearch?operation=EXISTS");
- from("direct:multisearch").to("elasticsearch5://elasticsearch?operation=MULTISEARCH&indexName=test");
+ from("direct:start").to("elasticsearch5://elasticsearch?operation=INDEX&ip=localhost&port=9300");
+ from("direct:index").to("elasticsearch5://elasticsearch?operation=INDEX&indexName=twitter&indexType=tweet&ip=localhost&port=9300");
+ from("direct:get").to("elasticsearch5://elasticsearch?operation=GET_BY_ID&indexName=twitter&indexType=tweet&ip=localhost&port=9300");
+ from("direct:multiget").to("elasticsearch5://elasticsearch?operation=MULTIGET&indexName=twitter&indexType=tweet&ip=localhost&port=9300");
+ from("direct:delete").to("elasticsearch5://elasticsearch?operation=DELETE&indexName=twitter&indexType=tweet&ip=localhost&port=9300");
+ from("direct:search").to("elasticsearch5://elasticsearch?operation=SEARCH&indexName=twitter&indexType=tweet&ip=localhost&port=9300");
+ from("direct:update").to("elasticsearch5://elasticsearch?operation=UPDATE&indexName=twitter&indexType=tweet&ip=localhost&port=9300");
+ from("direct:exists").to("elasticsearch5://elasticsearch?operation=EXISTS&ip=localhost&port=9300");
+ from("direct:multisearch").to("elasticsearch5://elasticsearch?operation=MULTISEARCH&indexName=test&ip=localhost&port=9300");
}
};
}
http://git-wip-us.apache.org/repos/asf/camel/blob/659255cf/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchIndexTest.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchIndexTest.java b/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchIndexTest.java
index 4ef3cb5..c48c8e1 100644
--- a/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchIndexTest.java
+++ b/components/camel-elasticsearch5/src/test/java/org/apache/camel/component/elasticsearch5/ElasticsearchIndexTest.java
@@ -39,17 +39,10 @@ public class ElasticsearchIndexTest extends ElasticsearchBaseTest {
}
@Test
- public void testIndexWithWriteConsistency() throws Exception {
- Map<String, String> map = createIndexedData();
- String indexId = template.requestBody("direct:indexWithWriteConsistency", map, String.class);
- assertNotNull("indexId should be set", indexId);
- }
-
- @Test
public void testIndexWithHeaders() throws Exception {
Map<String, String> map = createIndexedData();
Map<String, Object> headers = new HashMap<String, Object>();
- headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.INDEX);
headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter");
headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "tweet");
@@ -61,7 +54,7 @@ public class ElasticsearchIndexTest extends ElasticsearchBaseTest {
public void testIndexWithIDInHeader() throws Exception {
Map<String, String> map = createIndexedData();
Map<String, Object> headers = new HashMap<String, Object>();
- headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
+ headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.INDEX);
headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter");
headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "tweet");
headers.put(ElasticsearchConstants.PARAM_INDEX_ID, "123");
@@ -76,10 +69,9 @@ public class ElasticsearchIndexTest extends ElasticsearchBaseTest {
return new RouteBuilder() {
@Override
public void configure() {
- from("direct:start").to("elasticsearch5://elasticsearch");
- from("direct:index").to("elasticsearch5://elasticsearch?operation=INDEX&indexName=twitter&indexType=tweet");
- from("direct:indexWithReplication").to("elasticsearch5://elasticsearch?operation=INDEX&indexName=twitter&indexType=tweet");
- from("direct:indexWithWriteConsistency").to("elasticsearch5://elasticsearch?operation=INDEX&indexName=twitter&indexType=tweet");
+ from("direct:start").to("elasticsearch5://elasticsearch?ip=localhost&port=9300");
+ from("direct:index").to("elasticsearch5://elasticsearch?operation=INDEX&indexName=twitter&indexType=tweet&ip=localhost&port=9300");
+ from("direct:indexWithReplication").to("elasticsearch5://elasticsearch?operation=INDEX&indexName=twitter&indexType=tweet&ip=localhost&port=9300");
}
};
}
http://git-wip-us.apache.org/repos/asf/camel/blob/659255cf/components/camel-elasticsearch5/src/test/resources/log4j2.properties
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5/src/test/resources/log4j2.properties b/components/camel-elasticsearch5/src/test/resources/log4j2.properties
index 1e56038..6ae1902 100644
--- a/components/camel-elasticsearch5/src/test/resources/log4j2.properties
+++ b/components/camel-elasticsearch5/src/test/resources/log4j2.properties
@@ -17,7 +17,7 @@
appender.file.type = File
appender.file.name = file
-appender.file.fileName = target/camel-elasticsearch-test.log
+appender.file.fileName = target/camel-elasticsearch5-test.log
appender.file.layout.type = PatternLayout
appender.file.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
appender.stdout.type = Console
http://git-wip-us.apache.org/repos/asf/camel/blob/659255cf/components/camel-lucene/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-lucene/pom.xml b/components/camel-lucene/pom.xml
index e8a8b6b..ae03ad4 100644
--- a/components/camel-lucene/pom.xml
+++ b/components/camel-lucene/pom.xml
@@ -1,111 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version
- 2.0 (the "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0 Unless required by
- applicable law or agreed to in writing, software distributed under the
- License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
- CONDITIONS OF ANY KIND, either express or implied. See the License for
- the specific language governing permissions and limitations under the
- License.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
+ http://www.apache.org/licenses/LICENSE-2.0
- <parent>
- <groupId>org.apache.camel</groupId>
- <artifactId>components</artifactId>
- <version>2.19.0-SNAPSHOT</version>
- </parent>
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
- <artifactId>camel-lucene</artifactId>
- <packaging>jar</packaging>
- <name>Camel :: Lucene</name>
- <description>Camel Lucene based search component</description>
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>components</artifactId>
+ <version>2.19.0-SNAPSHOT</version>
+ </parent>
- <properties>
- <camel.osgi.export.pkg>
- org.apache.camel.component.lucene.*;${camel.osgi.version},
- org.apache.camel.processor.lucene.*
- </camel.osgi.export.pkg>
- <camel.osgi.import.pkg>
- !org.apache.camel.component.lucene.*,
- !org.apache.camel.processor.lucene.*,
- ${camel.osgi.import.defaults},
- *
- </camel.osgi.import.pkg>
- <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=lucene</camel.osgi.export.service>
- </properties>
+ <artifactId>camel-lucene</artifactId>
+ <packaging>jar</packaging>
+ <name>Camel :: Lucene</name>
+ <description>Camel Lucene based search component</description>
- <dependencies>
-
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.lucene</groupId>
- <artifactId>lucene-core</artifactId>
- <version>${lucene-version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.lucene</groupId>
- <artifactId>lucene-queryparser</artifactId>
- <version>${lucene-version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.lucene</groupId>
- <artifactId>lucene-analyzers-common</artifactId>
- <version>${lucene-version}</version>
- </dependency>
+ <properties>
+ <camel.osgi.export.pkg>
+ org.apache.camel.component.lucene.*;${camel.osgi.version},
+ org.apache.camel.processor.lucene.*
+ </camel.osgi.export.pkg>
+ <camel.osgi.import.pkg>
+ !org.apache.camel.component.lucene.*,
+ !org.apache.camel.processor.lucene.*,
+ ${camel.osgi.import.defaults},
+ *
+ </camel.osgi.import.pkg>
+ <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=lucene</camel.osgi.export.service>
+ </properties>
- <!-- test dependencies -->
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-api</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-slf4j-impl</artifactId>
- <scope>test</scope>
- </dependency>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.lucene</groupId>
+ <artifactId>lucene-core</artifactId>
+ <version>${lucene-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.lucene</groupId>
+ <artifactId>lucene-queryparser</artifactId>
+ <version>${lucene-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.lucene</groupId>
+ <artifactId>lucene-analyzers-common</artifactId>
+ <version>${lucene-version}</version>
+ </dependency>
- </dependencies>
+ <!-- test dependencies -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-clean-plugin</artifactId>
- <configuration>
- <filesets>
- <fileset>
- <directory>${basedir}/res</directory>
- </fileset>
- </filesets>
- </configuration>
- </plugin>
- </plugins>
- </build>
-</project>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-clean-plugin</artifactId>
+ <configuration>
+ <filesets>
+ <fileset>
+ <directory>${basedir}/res</directory>
+ </fileset>
+ </filesets>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/659255cf/platforms/catalog-lucene/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/catalog-lucene/pom.xml b/platforms/catalog-lucene/pom.xml
index 228e919..3e653f9 100644
--- a/platforms/catalog-lucene/pom.xml
+++ b/platforms/catalog-lucene/pom.xml
@@ -1,21 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
+ http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@@ -36,7 +37,6 @@
</properties>
<dependencies>
-
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-catalog</artifactId>
@@ -58,7 +58,7 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
-
+
<!-- logging -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
@@ -75,19 +75,16 @@
<artifactId>log4j-slf4j-impl</artifactId>
<scope>test</scope>
</dependency>
-
</dependencies>
<build>
<plugins>
-
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
</plugin>
</plugins>
-
</build>
-</project>
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/659255cf/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/java/org/apache/camel/component/elasticsearch5/springboot/ElasticsearchComponentAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/java/org/apache/camel/component/elasticsearch5/springboot/ElasticsearchComponentAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/java/org/apache/camel/component/elasticsearch5/springboot/ElasticsearchComponentAutoConfiguration.java
index 0edc75e..3e9a70b 100644
--- a/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/java/org/apache/camel/component/elasticsearch5/springboot/ElasticsearchComponentAutoConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/java/org/apache/camel/component/elasticsearch5/springboot/ElasticsearchComponentAutoConfiguration.java
@@ -16,11 +16,8 @@
*/
package org.apache.camel.component.elasticsearch5.springboot;
-import java.util.HashMap;
-import java.util.Map;
import org.apache.camel.CamelContext;
import org.apache.camel.component.elasticsearch5.ElasticsearchComponent;
-import org.apache.camel.util.IntrospectionSupport;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
@@ -29,7 +26,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.boot.bind.RelaxedPropertyResolver;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.Conditional;
@@ -44,7 +40,6 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
@ConditionalOnBean(type = "org.apache.camel.spring.boot.CamelAutoConfiguration")
@Conditional(ElasticsearchComponentAutoConfiguration.Condition.class)
@AutoConfigureAfter(name = "org.apache.camel.spring.boot.CamelAutoConfiguration")
-@EnableConfigurationProperties(ElasticsearchComponentConfiguration.class)
public class ElasticsearchComponentAutoConfiguration {
@Lazy
@@ -52,35 +47,9 @@ public class ElasticsearchComponentAutoConfiguration {
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(ElasticsearchComponent.class)
public ElasticsearchComponent configureElasticsearchComponent(
- CamelContext camelContext,
- ElasticsearchComponentConfiguration configuration) throws Exception {
+ CamelContext camelContext) throws Exception {
ElasticsearchComponent component = new ElasticsearchComponent();
component.setCamelContext(camelContext);
- Map<String, Object> parameters = new HashMap<>();
- IntrospectionSupport.getProperties(configuration, parameters, null,
- false);
- for (Map.Entry<String, Object> entry : parameters.entrySet()) {
- Object value = entry.getValue();
- Class<?> paramClass = value.getClass();
- if (paramClass.getName().endsWith("NestedConfiguration")) {
- Class nestedClass = null;
- try {
- nestedClass = (Class) paramClass.getDeclaredField(
- "CAMEL_NESTED_CLASS").get(null);
- HashMap<String, Object> nestedParameters = new HashMap<>();
- IntrospectionSupport.getProperties(value, nestedParameters,
- null, false);
- Object nestedProperty = nestedClass.newInstance();
- IntrospectionSupport.setProperties(camelContext,
- camelContext.getTypeConverter(), nestedProperty,
- nestedParameters);
- entry.setValue(nestedProperty);
- } catch (NoSuchFieldException e) {
- }
- }
- }
- IntrospectionSupport.setProperties(camelContext,
- camelContext.getTypeConverter(), component, parameters);
return component;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/659255cf/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/java/org/apache/camel/component/elasticsearch5/springboot/ElasticsearchComponentConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/java/org/apache/camel/component/elasticsearch5/springboot/ElasticsearchComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/java/org/apache/camel/component/elasticsearch5/springboot/ElasticsearchComponentConfiguration.java
deleted file mode 100644
index 7864d81..0000000
--- a/platforms/spring-boot/components-starter/camel-elasticsearch5-starter/src/main/java/org/apache/camel/component/elasticsearch5/springboot/ElasticsearchComponentConfiguration.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.elasticsearch5.springboot;
-
-import org.elasticsearch.client.transport.TransportClient;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.boot.context.properties.NestedConfigurationProperty;
-
-/**
- * The elasticsearch component is used for interfacing with ElasticSearch
- * server.
- *
- * Generated by camel-package-maven-plugin - do not edit this file!
- */
-@ConfigurationProperties(prefix = "camel.component.elasticsearch5")
-public class ElasticsearchComponentConfiguration {
-
- /**
- * To use an existing configured Elasticsearch client instead of creating a
- * client per endpoint.
- */
- @NestedConfigurationProperty
- private TransportClient client;
-
- public TransportClient getClient() {
- return client;
- }
-
- public void setClient(TransportClient client) {
- this.client = client;
- }
-}
\ No newline at end of file