From 7a857e6e6cf1731dba6f36875b710c29eaa52af1 Mon Sep 17 00:00:00 2001 From: Johannes Peter Date: Thu, 7 Nov 2024 17:10:50 +0100 Subject: [PATCH] fix: Refactorings to build against opensearch version 3.0.0-SNAPSHOT Signed-off-by: Johannes Peter --- build.gradle | 8 ++++++-- gradle.properties | 2 +- .../java/com/o19s/es/ltr/action/LTRStatsAction.java | 4 ++-- .../o19s/es/ltr/action/TransportCacheStatsAction.java | 4 ++-- .../es/ltr/action/TransportClearCachesAction.java | 4 ++-- .../com/o19s/es/ltr/query/StoredLtrQueryBuilder.java | 11 +++-------- 6 files changed, 16 insertions(+), 17 deletions(-) diff --git a/build.gradle b/build.gradle index 73d93c9f..f179c8aa 100644 --- a/build.gradle +++ b/build.gradle @@ -2,8 +2,10 @@ import java.nio.file.Files buildscript { repositories { - mavenCentral() mavenLocal() + maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" } + mavenCentral() + maven { url "https://plugins.gradle.org/m2/" } } dependencies { @@ -56,8 +58,10 @@ opensearchplugin { // In this section you declare the dependencies for your production and test code // OpenSearch dependency is included due to the build-tools, test-framework as well repositories { - mavenCentral() mavenLocal() + maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" } + mavenCentral() + maven { url "https://plugins.gradle.org/m2/" } } dependencies { diff --git a/gradle.properties b/gradle.properties index 5912e714..4bb270b7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ ltrVersion = 2.17.1 -opensearchVersion = 2.17.1 +opensearchVersion = 3.0.0-SNAPSHOT luceneVersion = 9.7.0 ow2Version = 9.6 antlrVersion=4.11.1 diff --git a/src/main/java/com/o19s/es/ltr/action/LTRStatsAction.java b/src/main/java/com/o19s/es/ltr/action/LTRStatsAction.java index f571ea54..a9fdf5b4 100644 --- a/src/main/java/com/o19s/es/ltr/action/LTRStatsAction.java +++ b/src/main/java/com/o19s/es/ltr/action/LTRStatsAction.java @@ -19,7 +19,6 @@ import org.opensearch.action.ActionRequestBuilder; import org.opensearch.action.ActionType; import org.opensearch.action.FailedNodeException; -import org.opensearch.action.support.nodes.BaseNodeRequest; import org.opensearch.action.support.nodes.BaseNodeResponse; import org.opensearch.action.support.nodes.BaseNodesRequest; import org.opensearch.action.support.nodes.BaseNodesResponse; @@ -31,6 +30,7 @@ import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.ToXContentFragment; import org.opensearch.core.xcontent.XContentBuilder; +import org.opensearch.transport.TransportRequest; import java.io.IOException; import java.util.HashSet; @@ -55,7 +55,7 @@ public LTRStatsRequestBuilder(OpenSearchClient client) { } } - public static class LTRStatsNodeRequest extends BaseNodeRequest { + public static class LTRStatsNodeRequest extends TransportRequest { private final LTRStatsNodesRequest nodesRequest; public LTRStatsNodeRequest(LTRStatsNodesRequest nodesRequest) { diff --git a/src/main/java/com/o19s/es/ltr/action/TransportCacheStatsAction.java b/src/main/java/com/o19s/es/ltr/action/TransportCacheStatsAction.java index 9cea6057..ff5ba3fc 100644 --- a/src/main/java/com/o19s/es/ltr/action/TransportCacheStatsAction.java +++ b/src/main/java/com/o19s/es/ltr/action/TransportCacheStatsAction.java @@ -22,7 +22,6 @@ import com.o19s.es.ltr.feature.store.index.Caches; import org.opensearch.action.FailedNodeException; import org.opensearch.action.support.ActionFilters; -import org.opensearch.action.support.nodes.BaseNodeRequest; import org.opensearch.action.support.nodes.TransportNodesAction; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; import org.opensearch.cluster.service.ClusterService; @@ -30,6 +29,7 @@ import org.opensearch.core.common.io.stream.StreamInput; import org.opensearch.common.settings.Settings; import org.opensearch.threadpool.ThreadPool; +import org.opensearch.transport.TransportRequest; import org.opensearch.transport.TransportService; import java.io.IOException; @@ -71,7 +71,7 @@ protected CachesStatsNodeResponse nodeOperation(CachesStatsNodeRequest request) return new CachesStatsNodeResponse(clusterService.localNode()).initFromCaches(caches); } - public static class CachesStatsNodeRequest extends BaseNodeRequest { + public static class CachesStatsNodeRequest extends TransportRequest { public CachesStatsNodeRequest() {} public CachesStatsNodeRequest(StreamInput in) throws IOException { diff --git a/src/main/java/com/o19s/es/ltr/action/TransportClearCachesAction.java b/src/main/java/com/o19s/es/ltr/action/TransportClearCachesAction.java index 155ee1aa..eaa6b70c 100644 --- a/src/main/java/com/o19s/es/ltr/action/TransportClearCachesAction.java +++ b/src/main/java/com/o19s/es/ltr/action/TransportClearCachesAction.java @@ -22,7 +22,6 @@ import com.o19s.es.ltr.feature.store.index.Caches; import org.opensearch.action.FailedNodeException; import org.opensearch.action.support.ActionFilters; -import org.opensearch.action.support.nodes.BaseNodeRequest; import org.opensearch.action.support.nodes.TransportNodesAction; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; import org.opensearch.cluster.service.ClusterService; @@ -31,6 +30,7 @@ import org.opensearch.core.common.io.stream.StreamOutput; import org.opensearch.common.settings.Settings; import org.opensearch.threadpool.ThreadPool; +import org.opensearch.transport.TransportRequest; import org.opensearch.transport.TransportService; import java.io.IOException; @@ -88,7 +88,7 @@ protected ClearCachesNodeResponse nodeOperation(ClearCachesNodeRequest request) return new ClearCachesNodeResponse(clusterService.localNode()); } - public static class ClearCachesNodeRequest extends BaseNodeRequest { + public static class ClearCachesNodeRequest extends TransportRequest { private ClearCachesNodesRequest request; public ClearCachesNodeRequest() {} diff --git a/src/main/java/com/o19s/es/ltr/query/StoredLtrQueryBuilder.java b/src/main/java/com/o19s/es/ltr/query/StoredLtrQueryBuilder.java index d4423e32..e32cde5e 100644 --- a/src/main/java/com/o19s/es/ltr/query/StoredLtrQueryBuilder.java +++ b/src/main/java/com/o19s/es/ltr/query/StoredLtrQueryBuilder.java @@ -23,7 +23,6 @@ import com.o19s.es.ltr.feature.store.index.IndexFeatureStore; import com.o19s.es.ltr.ranker.linear.LinearRanker; import com.o19s.es.ltr.utils.FeatureStoreLoader; -import org.opensearch.Version; import org.opensearch.core.ParseField; import org.opensearch.core.common.ParsingException; import org.opensearch.core.common.io.stream.NamedWriteable; @@ -90,10 +89,8 @@ public StoredLtrQueryBuilder(FeatureStoreLoader storeLoader, StreamInput input) featureScoreCacheFlag = input.readOptionalBoolean(); featureSetName = input.readOptionalString(); params = input.readMap(); - if (input.getVersion().onOrAfter(Version.V_1_0_0)) {//TODO: check this. In the Elastic LTR plugin this is set to 7_0_0 - String[] activeFeat = input.readOptionalStringArray(); - activeFeatures = activeFeat == null ? null : Arrays.asList(activeFeat); - } + String[] activeFeat = input.readOptionalStringArray(); + activeFeatures = activeFeat == null ? null : Arrays.asList(activeFeat); storeName = input.readOptionalString(); } @@ -121,9 +118,7 @@ protected void doWriteTo(StreamOutput out) throws IOException { out.writeOptionalBoolean(featureScoreCacheFlag); out.writeOptionalString(featureSetName); out.writeMap(params); - if (out.getVersion().onOrAfter(Version.V_1_0_0)) { - out.writeOptionalStringArray(activeFeatures != null ? activeFeatures.toArray(new String[0]) : null); - } + out.writeOptionalStringArray(activeFeatures != null ? activeFeatures.toArray(new String[0]) : null); out.writeOptionalString(storeName); }