You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2019/07/17 10:58:37 UTC

[camel] 01/02: CAMEL-13756 - Camel-Elasticsearch: Upgrade to 7.x

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit f3cc09202e23b8abad4549234a9c44a8340c1b7f
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Jul 17 12:53:42 2019 +0200

    CAMEL-13756 - Camel-Elasticsearch: Upgrade to 7.x
---
 .../elasticsearch/ElasticsearchProducer.java         |  6 +++---
 .../ElasticsearchRestComponentVerifierExtension.java |  3 ++-
 .../ElasticsearchActionRequestConverter.java         | 20 ++++++++++++++++----
 .../elasticsearch/ElasticsearchClusterBaseTest.java  |  8 +++-----
 .../elasticsearch/ElasticsearchClusterIndexTest.java | 15 +++++++++------
 ...ElasticsearchGetSearchDeleteExistsUpdateTest.java |  6 +++---
 .../elasticsearch/ElasticsearchIndexTest.java        |  6 ++++--
 parent/pom.xml                                       |  8 ++++----
 8 files changed, 44 insertions(+), 28 deletions(-)

diff --git a/components/camel-elasticsearch-rest/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchProducer.java b/components/camel-elasticsearch-rest/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchProducer.java
index 6146bc3..c845697 100644
--- a/components/camel-elasticsearch-rest/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchProducer.java
+++ b/components/camel-elasticsearch-rest/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchProducer.java
@@ -172,8 +172,8 @@ public class ElasticsearchProducer extends DefaultProducer {
             DeleteRequest deleteRequest = message.getBody(DeleteRequest.class);
             message.setBody(restHighLevelClient.delete(deleteRequest, RequestOptions.DEFAULT).getResult());
         } else if (operation == ElasticsearchOperation.DeleteIndex) {
-            DeleteRequest deleteRequest = message.getBody(DeleteRequest.class);
-            message.setBody(client.performRequest("Delete", deleteRequest.index()).getStatusLine().getStatusCode());
+            DeleteIndexRequest deleteIndexRequest = message.getBody(DeleteIndexRequest.class);
+            message.setBody(restHighLevelClient.indices().delete(deleteIndexRequest, RequestOptions.DEFAULT).isAcknowledged());
         } else if (operation == ElasticsearchOperation.Exists) {
             // ExistsRequest API is deprecated, using SearchRequest instead with size=0 and terminate_after=1
             SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
@@ -267,7 +267,7 @@ public class ElasticsearchProducer extends DefaultProducer {
 
     private RestClient createClient() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
         final RestClientBuilder builder = RestClient.builder(configuration.getHostAddressesList().toArray(new HttpHost[0]));
-        builder.setMaxRetryTimeoutMillis(configuration.getMaxRetryTimeout());
+
         builder.setRequestConfigCallback(requestConfigBuilder ->
             requestConfigBuilder.setConnectTimeout(configuration.getConnectionTimeout()).setSocketTimeout(configuration.getSocketTimeout()));
         if (configuration.getUser() != null && configuration.getPassword() != null) {
diff --git a/components/camel-elasticsearch-rest/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchRestComponentVerifierExtension.java b/components/camel-elasticsearch-rest/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchRestComponentVerifierExtension.java
index 4a64f3e..77d027f 100644
--- a/components/camel-elasticsearch-rest/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchRestComponentVerifierExtension.java
+++ b/components/camel-elasticsearch-rest/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchRestComponentVerifierExtension.java
@@ -24,6 +24,7 @@ import org.apache.camel.component.extension.verifier.ResultBuilder;
 import org.apache.camel.component.extension.verifier.ResultErrorBuilder;
 import org.apache.camel.component.extension.verifier.ResultErrorHelper;
 import org.apache.http.HttpHost;
+import org.elasticsearch.client.RequestOptions;
 import org.elasticsearch.client.RestClient;
 import org.elasticsearch.client.RestClientBuilder;
 import org.elasticsearch.client.RestHighLevelClient;
@@ -66,7 +67,7 @@ public class ElasticsearchRestComponentVerifierExtension extends DefaultComponen
             ElasticsearchConfiguration configuration = setProperties(new ElasticsearchConfiguration(), parameters);
             RestClientBuilder clientBuilder = RestClient.builder(configuration.getHostAddressesList().toArray(new HttpHost[0]));
             RestHighLevelClient restHighLevelClient = new RestHighLevelClient(clientBuilder);
-            restHighLevelClient.ping();
+            restHighLevelClient.ping(RequestOptions.DEFAULT);
         } catch (IOException e) {
             ResultErrorBuilder errorBuilder = ResultErrorBuilder.withCodeAndDescription(VerificationError.StandardCode.AUTHENTICATION, e.getMessage())
                 .detail("elasticsearch_rest_exception_message", e.getMessage()).detail(VerificationError.ExceptionAttribute.EXCEPTION_CLASS, e.getClass().getName())
diff --git a/components/camel-elasticsearch-rest/src/main/java/org/apache/camel/component/elasticsearch/converter/ElasticsearchActionRequestConverter.java b/components/camel-elasticsearch-rest/src/main/java/org/apache/camel/component/elasticsearch/converter/ElasticsearchActionRequestConverter.java
index 0262821..e78706e 100644
--- a/components/camel-elasticsearch-rest/src/main/java/org/apache/camel/component/elasticsearch/converter/ElasticsearchActionRequestConverter.java
+++ b/components/camel-elasticsearch-rest/src/main/java/org/apache/camel/component/elasticsearch/converter/ElasticsearchActionRequestConverter.java
@@ -25,6 +25,7 @@ import org.apache.camel.Converter;
 import org.apache.camel.Exchange;
 import org.apache.camel.component.elasticsearch.ElasticsearchConstants;
 import org.apache.camel.util.ObjectHelper;
+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;
@@ -72,8 +73,6 @@ public final class ElasticsearchActionRequestConverter {
         return updateRequest
             .waitForActiveShards(exchange.getIn().getHeader(
                 ElasticsearchConstants.PARAM_WAIT_FOR_ACTIVE_SHARDS, Integer.class))
-            .parent(exchange.getIn().getHeader(
-                PARENT, String.class))
             .index(exchange.getIn().getHeader(
                 ElasticsearchConstants.PARAM_INDEX_NAME, String.class))
             .type(exchange.getIn().getHeader(
@@ -103,8 +102,6 @@ public final class ElasticsearchActionRequestConverter {
         return indexRequest
             .waitForActiveShards(exchange.getIn().getHeader(
                 ElasticsearchConstants.PARAM_WAIT_FOR_ACTIVE_SHARDS, Integer.class))
-            .parent(exchange.getIn().getHeader(
-                PARENT, String.class))
             .index(exchange.getIn().getHeader(
                 ElasticsearchConstants.PARAM_INDEX_NAME, String.class))
             .type(exchange.getIn().getHeader(
@@ -152,6 +149,21 @@ public final class ElasticsearchActionRequestConverter {
             throw new IllegalArgumentException("Wrong body type. Only DeleteRequest or String is allowed as a type");
         }
     }
+    
+    @Converter
+    public static DeleteIndexRequest toDeleteIndexRequest(Object document, Exchange exchange) {
+        if (document instanceof DeleteIndexRequest) {
+            return (DeleteIndexRequest) document;
+        }
+        if (document instanceof String) {
+        	String index = exchange.getIn().getHeader(
+                    ElasticsearchConstants.PARAM_INDEX_NAME,
+                    String.class);
+            return new DeleteIndexRequest(index);
+        } else {
+            throw new IllegalArgumentException("Wrong body type. Only DeleteIndexRequest or String is allowed as a type");
+        }
+    }
 
     @Converter
     public static SearchRequest toSearchRequest(Object queryObject, Exchange exchange) throws IOException {
diff --git a/components/camel-elasticsearch-rest/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchClusterBaseTest.java b/components/camel-elasticsearch-rest/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchClusterBaseTest.java
index 5965c46b..73a9787 100644
--- a/components/camel-elasticsearch-rest/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchClusterBaseTest.java
+++ b/components/camel-elasticsearch-rest/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchClusterBaseTest.java
@@ -55,17 +55,15 @@ public class ElasticsearchClusterBaseTest extends CamelTestSupport {
         runner.onBuild((number, settingsBuilder) -> {
             settingsBuilder.put("http.cors.enabled", true);
             settingsBuilder.put("http.cors.allow-origin", "*");
-            settingsBuilder.put("discovery.zen.ping.unicast.hosts", "127.0.0.1:9301,127.0.0.1:9302,127.0.0.1:9303");
         }).build(newConfigs()
                  .clusterName(clusterName)
-                 .numOfNode(3)
+                 .numOfNode(1)
                  .baseHttpPort(ES_BASE_HTTP_PORT)
-                 .basePath("target/testcluster/")
-                 .disableESLogger());
+                 .basePath("target/testcluster/"));
 
         // wait for green status
         runner.ensureGreen();
-        restclientbuilder = RestClient.builder(new HttpHost(InetAddress.getByName("localhost"), ES_FIRST_NODE_TRANSPORT_PORT));
+        restclientbuilder = RestClient.builder(new HttpHost(InetAddress.getByName("127.0.0.1"), ES_FIRST_NODE_TRANSPORT_PORT));
         client = new RestHighLevelClient(restclientbuilder);
         restClient = client.getLowLevelClient();
     }
diff --git a/components/camel-elasticsearch-rest/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchClusterIndexTest.java b/components/camel-elasticsearch-rest/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchClusterIndexTest.java
index c001f77..2cc1867 100644
--- a/components/camel-elasticsearch-rest/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchClusterIndexTest.java
+++ b/components/camel-elasticsearch-rest/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchClusterIndexTest.java
@@ -22,6 +22,8 @@ import java.util.Map;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.http.impl.client.BasicResponseHandler;
 import org.elasticsearch.action.get.GetRequest;
+import org.elasticsearch.client.Request;
+import org.elasticsearch.client.RequestOptions;
 import org.junit.Test;
 
 public class ElasticsearchClusterIndexTest extends ElasticsearchClusterBaseTest {
@@ -42,8 +44,8 @@ public class ElasticsearchClusterIndexTest extends ElasticsearchClusterBaseTest
         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 1 must exists", true, client.get(new GetRequest("twitter", "tweet", "1")).isExists());
+        assertEquals("Cluster must be of one node", runner.getNodeSize(), 1);
+        assertEquals("Index id 1 must exists", true, client.get(new GetRequest("twitter").id("1"), RequestOptions.DEFAULT).isExists());
     }
 
     @Test
@@ -58,12 +60,13 @@ public class ElasticsearchClusterIndexTest extends ElasticsearchClusterBaseTest
         String indexId = template.requestBodyAndHeaders("direct:indexWithSniffer", 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.get(new GetRequest("facebook", "post", "4")).isExists());
+        assertEquals("Cluster must be of three nodes", runner.getNodeSize(), 1);
+        assertEquals("Index id 4 must exists", true, client.get(new GetRequest("facebook").id("4"), RequestOptions.DEFAULT).isExists());
 
         final BasicResponseHandler responseHandler = new BasicResponseHandler();
-        String body = responseHandler.handleEntity(restClient.performRequest("GET", "/_cluster/health?pretty").getEntity());
-        assertStringContains(body, "\"number_of_data_nodes\" : 3");
+        Request request = new Request("GET", "/_cluster/health?pretty");
+        String body = responseHandler.handleEntity(restClient.performRequest(request).getEntity());
+        assertStringContains(body, "\"number_of_data_nodes\" : 1");
     }
 
     @Override
diff --git a/components/camel-elasticsearch-rest/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchGetSearchDeleteExistsUpdateTest.java b/components/camel-elasticsearch-rest/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchGetSearchDeleteExistsUpdateTest.java
index defb013..e32d72e 100644
--- a/components/camel-elasticsearch-rest/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchGetSearchDeleteExistsUpdateTest.java
+++ b/components/camel-elasticsearch-rest/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchGetSearchDeleteExistsUpdateTest.java
@@ -94,7 +94,7 @@ public class ElasticsearchGetSearchDeleteExistsUpdateTest extends ElasticsearchB
         query.put("query", match);
         SearchHits response = template.requestBody("direct:search", query, SearchHits.class);
         assertNotNull("response should not be null", response);
-        assertEquals("response hits should be == 0", 0, response.totalHits);
+        assertEquals("response hits should be == 0", 0, response.getTotalHits().value);
     }
         
     @Test
@@ -114,13 +114,13 @@ public class ElasticsearchGetSearchDeleteExistsUpdateTest extends ElasticsearchB
                 + "}\n";
         SearchHits response = template.requestBody("direct:search", query, SearchHits.class);
         assertNotNull("response should not be null", response);
-        assertEquals("response hits should be == 0", 0, response.totalHits);
+        assertEquals("response hits should be == 0", 0, response.getTotalHits().value);
 
         // testing
 
         response = template.requestBody("direct:search-1", query, SearchHits.class);
         assertNotNull("response should not be null", response);
-        assertEquals("response hits should be == 0", 0, response.totalHits);
+        assertEquals("response hits should be == 0", 0, response.getTotalHits().value);
     }
     
     @Test
diff --git a/components/camel-elasticsearch-rest/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchIndexTest.java b/components/camel-elasticsearch-rest/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchIndexTest.java
index 8499f3a..078aae9 100644
--- a/components/camel-elasticsearch-rest/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchIndexTest.java
+++ b/components/camel-elasticsearch-rest/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchIndexTest.java
@@ -20,6 +20,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.camel.builder.RouteBuilder;
+import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
 import org.junit.Test;
 
 public class ElasticsearchIndexTest extends ElasticsearchBaseTest {
@@ -37,8 +38,9 @@ public class ElasticsearchIndexTest extends ElasticsearchBaseTest {
         String indexId = template.requestBody("direct:index", map, String.class);
         assertNotNull("indexId should be set", indexId);
 
-        int status = template.requestBody("direct:deleteIndex", "", Integer.class);
-        assertEquals("status should be 200", 200, status);
+        DeleteIndexRequest index = new DeleteIndexRequest("_all");
+        Boolean status = template.requestBody("direct:deleteIndex", index, Boolean.class);
+        assertEquals("status should be 200", true, status);
     }
 
     @Test
diff --git a/parent/pom.xml b/parent/pom.xml
index 40f14f5..1dbecbc 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -176,10 +176,10 @@
         <ehcache-version>2.10.6</ehcache-version>
         <ehcache3-version>3.7.0</ehcache3-version>
         <ekstazi-maven-plugin-version>5.3.0</ekstazi-maven-plugin-version>
-        <elasticsearch-rest-sniffer-version>6.6.2</elasticsearch-rest-sniffer-version>
-        <elasticsearch-rest-cluster-runner-version>6.6.2.0</elasticsearch-rest-cluster-runner-version>
-        <elasticsearch-rest-version>6.6.2</elasticsearch-rest-version>
-        <elasticsearch-rest-bundle-version>6.6.2_1</elasticsearch-rest-bundle-version>
+        <elasticsearch-rest-sniffer-version>7.1.1</elasticsearch-rest-sniffer-version>
+        <elasticsearch-rest-cluster-runner-version>7.1.1.0</elasticsearch-rest-cluster-runner-version>
+        <elasticsearch-rest-version>7.1.1</elasticsearch-rest-version>
+        <elasticsearch-rest-bundle-version>7.1.1_1</elasticsearch-rest-bundle-version>
         <elsql-version>1.3</elsql-version>
         <eddsa-version>0.3.0</eddsa-version>
         <embedmongo-version>2.1.1</embedmongo-version>