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

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 34f6cc44cc88e8f28df22374a057bb8a87d82bbd
Author: Rene Cordier <rcord...@linagora.com>
AuthorDate: Wed Jun 22 11:10:51 2022 +0700

    JAMES-3771 Migrate rest of the code to opensearch new java client
---
 ...mesWithNonCompatibleElasticSearchServerTest.java |  2 +-
 .../modules/mailbox/OpenSearchStartUpCheck.java     | 21 +++++++++++----------
 .../distributed/DistributedThreadGetMethodTest.java | 17 ++++++++---------
 3 files changed, 20 insertions(+), 20 deletions(-)

diff --git 
a/server/apps/cassandra-app/src/test/java/org/apache/james/JamesWithNonCompatibleElasticSearchServerTest.java
 
b/server/apps/cassandra-app/src/test/java/org/apache/james/JamesWithNonCompatibleElasticSearchServerTest.java
index 078782885c..31699b491f 100644
--- 
a/server/apps/cassandra-app/src/test/java/org/apache/james/JamesWithNonCompatibleElasticSearchServerTest.java
+++ 
b/server/apps/cassandra-app/src/test/java/org/apache/james/JamesWithNonCompatibleElasticSearchServerTest.java
@@ -59,7 +59,7 @@ class JamesWithNonCompatibleElasticSearchServerTest {
                     .containsOnly(CheckResult.builder()
                         .checkName(OpenSearchStartUpCheck.CHECK_NAME)
                         .resultType(StartUpCheck.ResultType.BAD)
-                        .description("ES version(6.3.2) is not compatible with 
the recommendation(2.0.0)")
+                        .description("Error when checking ES version: Missing 
required property 'OpenSearchVersionInfo.distribution'")
                         .build()));
 
         assertThat(server.isStarted())
diff --git 
a/server/container/guice/opensearch/src/main/java/org/apache/james/modules/mailbox/OpenSearchStartUpCheck.java
 
b/server/container/guice/opensearch/src/main/java/org/apache/james/modules/mailbox/OpenSearchStartUpCheck.java
index dba5f904b1..4d1e6db11b 100644
--- 
a/server/container/guice/opensearch/src/main/java/org/apache/james/modules/mailbox/OpenSearchStartUpCheck.java
+++ 
b/server/container/guice/opensearch/src/main/java/org/apache/james/modules/mailbox/OpenSearchStartUpCheck.java
@@ -19,21 +19,18 @@
 
 package org.apache.james.modules.mailbox;
 
-import java.io.IOException;
-
 import javax.inject.Inject;
 
 import org.apache.james.backends.opensearch.ReactorOpenSearchClient;
 import org.apache.james.lifecycle.api.StartUpCheck;
-import org.opensearch.Version;
-import org.opensearch.client.RequestOptions;
+import org.opensearch.client.transport.Version;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class OpenSearchStartUpCheck implements StartUpCheck {
     private static final Logger LOGGER = 
LoggerFactory.getLogger(OpenSearchStartUpCheck.class);
 
-    private static final Version RECOMMENDED_ES_VERSION = Version.V_2_0_0;
+    private static final Version RECOMMENDED_OS_VERSION = 
Version.parse("2.0.0");
     private static final String VERSION_CHECKING_ERROR_MESSAGE = "Error when 
checking ES version";
 
     public static final String CHECK_NAME = "OpenSearchStartUpCheck";
@@ -48,10 +45,9 @@ public class OpenSearchStartUpCheck implements StartUpCheck {
     @Override
     public CheckResult check() {
         try {
+            Version esVersion = 
Version.parse(client.info().block().version().number());
 
-            Version esVersion = 
Version.fromString(client.info(RequestOptions.DEFAULT).getVersion().getNumber());
-
-            if (esVersion.isCompatible(RECOMMENDED_ES_VERSION)) {
+            if (isCompatible(esVersion)) {
                 return CheckResult.builder()
                     .checkName(checkName())
                     .resultType(ResultType.GOOD)
@@ -61,7 +57,7 @@ public class OpenSearchStartUpCheck implements StartUpCheck {
             String esVersionCompatibilityWarn = String.format(
                 "ES version(%s) is not compatible with the recommendation(%s)",
                 esVersion.toString(),
-                RECOMMENDED_ES_VERSION.toString());
+                RECOMMENDED_OS_VERSION.toString());
             LOGGER.warn(esVersionCompatibilityWarn);
 
             return CheckResult.builder()
@@ -69,7 +65,7 @@ public class OpenSearchStartUpCheck implements StartUpCheck {
                 .resultType(ResultType.BAD)
                 .description(esVersionCompatibilityWarn)
                 .build();
-        } catch (IOException e) {
+        } catch (Exception e) {
             LOGGER.error(VERSION_CHECKING_ERROR_MESSAGE, e);
             return CheckResult.builder()
                 .checkName(checkName())
@@ -83,4 +79,9 @@ public class OpenSearchStartUpCheck implements StartUpCheck {
     public String checkName() {
         return CHECK_NAME;
     }
+
+    private boolean isCompatible(Version usedVersion) {
+        return usedVersion.major() > RECOMMENDED_OS_VERSION.major()
+            || usedVersion.major() == RECOMMENDED_OS_VERSION.major() && 
usedVersion.minor() >= RECOMMENDED_OS_VERSION.minor();
+    }
 }
diff --git 
a/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedThreadGetMethodTest.java
 
b/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedThreadGetMethodTest.java
index cc507c9e4c..58e6e1476f 100644
--- 
a/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedThreadGetMethodTest.java
+++ 
b/server/protocols/jmap-rfc-8621-integration-tests/distributed-jmap-rfc-8621-integration-tests/src/test/java/org/apache/james/jmap/rfc8621/distributed/DistributedThreadGetMethodTest.java
@@ -49,10 +49,8 @@ import org.awaitility.Durations;
 import org.awaitility.core.ConditionFactory;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.extension.RegisterExtension;
-import org.opensearch.action.search.SearchRequest;
-import org.opensearch.client.RequestOptions;
-import org.opensearch.index.query.QueryBuilder;
-import org.opensearch.search.builder.SearchSourceBuilder;
+import org.opensearch.client.opensearch._types.query_dsl.Query;
+import org.opensearch.client.opensearch.core.SearchRequest;
 
 public class DistributedThreadGetMethodTest implements ThreadGetContract {
     private static final ConditionFactory CALMLY_AWAIT = Awaitility
@@ -103,13 +101,14 @@ public class DistributedThreadGetMethodTest implements 
ThreadGetContract {
             openSearch.getDockerOpenSearch().configuration());
     }
 
-    private void awaitForOpenSearch(QueryBuilder query, long totalHits) {
+    private void awaitForOpenSearch(Query query, long totalHits) {
         CALMLY_AWAIT.atMost(Durations.TEN_SECONDS)
             .untilAsserted(() -> assertThat(client.search(
-                new 
SearchRequest(MailboxOpenSearchConstants.DEFAULT_MAILBOX_INDEX.getValue())
-                    .source(new SearchSourceBuilder().query(query)),
-                RequestOptions.DEFAULT)
+                new SearchRequest.Builder()
+                    
.index(MailboxOpenSearchConstants.DEFAULT_MAILBOX_INDEX.getValue())
+                    .query(query)
+                    .build())
                 .block()
-                .getHits().getTotalHits().value).isEqualTo(totalHits));
+                .hits().total().value()).isEqualTo(totalHits));
     }
 }
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@james.apache.org
For additional commands, e-mail: notifications-h...@james.apache.org

Reply via email to