diff --git a/gradle.properties b/gradle.properties index 0ef54f56..af24e4c7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ ltrVersion = 1.5.8 -elasticsearchVersion = 8.9.2 -luceneVersion = 9.7.0 +elasticsearchVersion = 8.11.4 +luceneVersion = 9.8.0 ow2Version = 8.0.1 antlrVersion = 4.5.1-1 diff --git a/src/javaRestTest/java/com/o19s/es/ltr/action/ListStoresActionIT.java b/src/javaRestTest/java/com/o19s/es/ltr/action/ListStoresActionIT.java index db6feed5..de16e9e9 100644 --- a/src/javaRestTest/java/com/o19s/es/ltr/action/ListStoresActionIT.java +++ b/src/javaRestTest/java/com/o19s/es/ltr/action/ListStoresActionIT.java @@ -32,6 +32,10 @@ import static com.o19s.es.ltr.feature.store.index.IndexFeatureStore.indexName; public class ListStoresActionIT extends BaseIntegrationTest { + /* + Create two stores (test2, test2) in addition to the default store. + List the stores. + */ public void testListStore() throws Exception { createStore(indexName("test2")); createStore(indexName("test3")); @@ -54,6 +58,46 @@ public void testListStore() throws Exception { } } + /* + Create two stores (test2, test2) in addition to the default store. + List the stores. + Delete a store ("test2") and make sure the store is not listed any more. + */ + public void testListRemovedStore() throws Exception { + createStore(indexName("test2")); + createStore(indexName("test3")); + Map infos = new HashMap<>(); + String[] stores = new String[]{IndexFeatureStore.DEFAULT_STORE, indexName("test2"), indexName("test3")}; + for (String store : stores) { + infos.put(IndexFeatureStore.storeName(store), + new IndexStoreInfo(store, IndexFeatureStore.VERSION, addElements(store))); + } + ListStoresActionResponse resp = new ListStoresAction.ListStoresActionBuilder(client()).execute().get(); + assertEquals(infos.size(), resp.getStores().size()); + assertEquals(infos.keySet(), resp.getStores().keySet()); + for (String k : infos.keySet()) { + IndexStoreInfo expected = infos.get(k); + IndexStoreInfo actual = resp.getStores().get(k); + assertEquals(expected.getIndexName(), actual.getIndexName()); + assertEquals(expected.getStoreName(), actual.getStoreName()); + assertEquals(expected.getVersion(), actual.getVersion()); + assertEquals(expected.getCounts(), actual.getCounts()); + } + deleteStore(indexName("test2")); + infos.remove("test2"); + resp = new ListStoresAction.ListStoresActionBuilder(client()).execute().get(); + assertEquals(infos.size(), resp.getStores().size()); + assertEquals(infos.keySet(), resp.getStores().keySet()); + for (String k : infos.keySet()) { + IndexStoreInfo expected = infos.get(k); + IndexStoreInfo actual = resp.getStores().get(k); + assertEquals(expected.getIndexName(), actual.getIndexName()); + assertEquals(expected.getStoreName(), actual.getStoreName()); + assertEquals(expected.getVersion(), actual.getVersion()); + assertEquals(expected.getCounts(), actual.getCounts()); + } + } + private Map addElements(String store) throws Exception { Map counts = new HashMap<>(); int nFeats = randomInt(20) + 1; diff --git a/src/javaRestTest/java/com/o19s/es/ltr/logging/LoggingIT.java b/src/javaRestTest/java/com/o19s/es/ltr/logging/LoggingIT.java index 0ce24e30..76b61cb3 100644 --- a/src/javaRestTest/java/com/o19s/es/ltr/logging/LoggingIT.java +++ b/src/javaRestTest/java/com/o19s/es/ltr/logging/LoggingIT.java @@ -27,7 +27,7 @@ import org.apache.lucene.search.join.ScoreMode; import org.apache.lucene.tests.util.TestUtil; import org.elasticsearch.ExceptionsHelper; -import org.elasticsearch.action.index.IndexResponse; +import org.elasticsearch.action.DocWriteResponse; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction; import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery; @@ -715,7 +715,7 @@ public Map buildIndex() { } public void indexDoc(Doc d) { - IndexResponse resp = client().prepareIndex("test_index") + DocWriteResponse resp = client().prepareIndex("test_index") .setSource("field1", d.field1, "field2", d.field2, "scorefield1", d.scorefield1, "nesteddocs1", d.getNesteddocs1()) .get(); d.id = resp.getId(); diff --git a/src/main/java/com/o19s/es/explore/ExplorerQueryBuilder.java b/src/main/java/com/o19s/es/explore/ExplorerQueryBuilder.java index 5de09292..0d08550f 100644 --- a/src/main/java/com/o19s/es/explore/ExplorerQueryBuilder.java +++ b/src/main/java/com/o19s/es/explore/ExplorerQueryBuilder.java @@ -16,6 +16,7 @@ package com.o19s.es.explore; import org.apache.lucene.search.Query; +import org.elasticsearch.TransportVersions; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.TransportVersion; import org.elasticsearch.common.ParsingException; @@ -157,6 +158,6 @@ public ExplorerQueryBuilder statsType(String type) { @Override public TransportVersion getMinimalSupportedVersion() { - return TransportVersion.V_7_0_0; + return TransportVersions.V_7_0_0; } } diff --git a/src/main/java/com/o19s/es/ltr/LtrQueryParserPlugin.java b/src/main/java/com/o19s/es/ltr/LtrQueryParserPlugin.java index 8b1434a4..d499f323 100644 --- a/src/main/java/com/o19s/es/ltr/LtrQueryParserPlugin.java +++ b/src/main/java/com/o19s/es/ltr/LtrQueryParserPlugin.java @@ -77,6 +77,8 @@ import org.elasticsearch.cluster.routing.allocation.AllocationService; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.core.CheckedFunction; +import org.elasticsearch.indices.IndicesService; +import org.elasticsearch.telemetry.TelemetryProvider; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.NamedWriteableRegistry.Entry; @@ -105,7 +107,6 @@ import org.elasticsearch.script.ScriptService; import org.elasticsearch.search.fetch.FetchSubPhase; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.tracing.Tracer; import org.elasticsearch.watcher.ResourceWatcherService; import java.io.IOException; @@ -252,8 +253,9 @@ public Collection createComponents(Client client, NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver indexNameExpressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer, - AllocationService allocationService) { + TelemetryProvider telemetryProvider, + AllocationService allocationService, + IndicesService indicesService) { clusterService.addListener(event -> { for (Index i : event.indicesDeleted()) { if (IndexFeatureStore.isIndexStore(i.getName())) { diff --git a/src/main/java/com/o19s/es/ltr/action/AddFeaturesToSetAction.java b/src/main/java/com/o19s/es/ltr/action/AddFeaturesToSetAction.java index 6d3a7c22..4588b984 100644 --- a/src/main/java/com/o19s/es/ltr/action/AddFeaturesToSetAction.java +++ b/src/main/java/com/o19s/es/ltr/action/AddFeaturesToSetAction.java @@ -20,18 +20,19 @@ import com.o19s.es.ltr.feature.store.StoredFeature; import com.o19s.es.ltr.feature.FeatureValidation; import org.elasticsearch.action.ActionRequest; +import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.ActionRequestValidationException; -import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.ActionType; +import org.elasticsearch.action.DocWriteResponse; import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.client.internal.ElasticsearchClient; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable.Reader; -import org.elasticsearch.common.xcontent.StatusToXContentObject; -import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.rest.RestStatus; +import org.elasticsearch.xcontent.ToXContentObject; +import org.elasticsearch.xcontent.XContentBuilder; import java.io.IOException; import java.util.List; @@ -73,7 +74,7 @@ public AddFeaturesToSetRequest() { public AddFeaturesToSetRequest(StreamInput in) throws IOException { super(in); store = in.readString(); - features = in.readList(StoredFeature::new); + features = in.readCollectionAsList(StoredFeature::new); if (in.readBoolean()) { featureNameQuery = in.readOptionalString(); } @@ -107,7 +108,7 @@ public void writeTo(StreamOutput out) throws IOException { out.writeString(store); out.writeOptionalString(featureNameQuery); if (features != null) { - out.writeList(features); + out.writeCollection(features); } out.writeBoolean(merge); out.writeString(featureSet); @@ -172,15 +173,15 @@ public void setValidation(FeatureValidation validation) { } } - public static class AddFeaturesToSetResponse extends ActionResponse implements StatusToXContentObject { - private IndexResponse response; + public static class AddFeaturesToSetResponse extends ActionResponse implements ToXContentObject { + private DocWriteResponse response; public AddFeaturesToSetResponse(StreamInput in) throws IOException { super(in); response = new IndexResponse(in); } - public AddFeaturesToSetResponse(IndexResponse response) { + public AddFeaturesToSetResponse(DocWriteResponse response) { this.response = response; } @@ -189,20 +190,19 @@ public void writeTo(StreamOutput out) throws IOException { response.writeTo(out); } + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + return response.toXContent(builder, params); + } + /** * Returns the REST status to make sure it is returned correctly */ - @Override public RestStatus status() { return response.status(); } - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - return response.toXContent(builder, params); - } - - public IndexResponse getResponse() { + public DocWriteResponse getResponse() { return response; } } diff --git a/src/main/java/com/o19s/es/ltr/action/CachesStatsAction.java b/src/main/java/com/o19s/es/ltr/action/CachesStatsAction.java index 2cece093..6b8a7a56 100644 --- a/src/main/java/com/o19s/es/ltr/action/CachesStatsAction.java +++ b/src/main/java/com/o19s/es/ltr/action/CachesStatsAction.java @@ -78,12 +78,12 @@ public CachesStatsNodesResponse(ClusterName clusterName, List readNodesFrom(StreamInput in) throws IOException { - return in.readList(CachesStatsNodeResponse::new); + return in.readCollectionAsList(CachesStatsNodeResponse::new); } @Override protected void writeNodesTo(StreamOutput out, List nodes) throws IOException { - out.writeList(nodes); + out.writeCollection(nodes); } @Override diff --git a/src/main/java/com/o19s/es/ltr/action/ClearCachesAction.java b/src/main/java/com/o19s/es/ltr/action/ClearCachesAction.java index ef7533fd..71d7ea4f 100644 --- a/src/main/java/com/o19s/es/ltr/action/ClearCachesAction.java +++ b/src/main/java/com/o19s/es/ltr/action/ClearCachesAction.java @@ -153,12 +153,12 @@ public ClearCachesNodesResponse(ClusterName clusterName, List readNodesFrom(StreamInput in) throws IOException { - return in.readList(ClearCachesNodeResponse::new); + return in.readCollectionAsList(ClearCachesNodeResponse::new); } @Override protected void writeNodesTo(StreamOutput out, List nodes) throws IOException { - out.writeList(nodes); + out.writeCollection(nodes); } } diff --git a/src/main/java/com/o19s/es/ltr/action/CreateModelFromSetAction.java b/src/main/java/com/o19s/es/ltr/action/CreateModelFromSetAction.java index 00c50d21..d28dc7ac 100644 --- a/src/main/java/com/o19s/es/ltr/action/CreateModelFromSetAction.java +++ b/src/main/java/com/o19s/es/ltr/action/CreateModelFromSetAction.java @@ -20,17 +20,18 @@ import com.o19s.es.ltr.feature.FeatureValidation; import com.o19s.es.ltr.feature.store.StoredLtrModel; import org.elasticsearch.action.ActionRequest; +import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.ActionRequestValidationException; -import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.ActionType; +import org.elasticsearch.action.DocWriteResponse; import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.client.internal.ElasticsearchClient; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.StatusToXContentObject; -import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.rest.RestStatus; +import org.elasticsearch.xcontent.ToXContentObject; +import org.elasticsearch.xcontent.XContentBuilder; import java.io.IOException; @@ -46,7 +47,7 @@ protected CreateModelFromSetAction() { public static class CreateModelFromSetRequestBuilder extends ActionRequestBuilder { + CreateModelFromSetResponse> { public CreateModelFromSetRequestBuilder(ElasticsearchClient client) { super(client, INSTANCE, new CreateModelFromSetRequest()); @@ -115,7 +116,7 @@ public ActionRequestValidationException validate() { arve = addValidationError("modelName must be set", arve); } if (definition == null) { - arve = addValidationError("defition must be set", arve); + arve = addValidationError("definition must be set", arve); } return arve; } @@ -169,9 +170,9 @@ public void setValidation(FeatureValidation validation) { } } - public static class CreateModelFromSetResponse extends ActionResponse implements StatusToXContentObject { + public static class CreateModelFromSetResponse extends ActionResponse implements ToXContentObject { private static final int VERSION = 1; - private IndexResponse response; + private DocWriteResponse response; public CreateModelFromSetResponse(StreamInput in) throws IOException { super(in); @@ -180,7 +181,7 @@ public CreateModelFromSetResponse(StreamInput in) throws IOException { response = new IndexResponse(in); } - public CreateModelFromSetResponse(IndexResponse response) { + public CreateModelFromSetResponse(DocWriteResponse response) { this.response = response; } @@ -190,7 +191,7 @@ public void writeTo(StreamOutput out) throws IOException { response.writeTo(out); } - public IndexResponse getResponse() { + public DocWriteResponse getResponse() { return response; } @@ -199,9 +200,12 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws return response.toXContent(builder, params); } - @Override + /** + * Returns the REST status to make sure it is returned correctly + */ public RestStatus status() { return response.status(); } + } } diff --git a/src/main/java/com/o19s/es/ltr/action/FeatureStoreAction.java b/src/main/java/com/o19s/es/ltr/action/FeatureStoreAction.java index bef7ff67..19479038 100644 --- a/src/main/java/com/o19s/es/ltr/action/FeatureStoreAction.java +++ b/src/main/java/com/o19s/es/ltr/action/FeatureStoreAction.java @@ -21,18 +21,19 @@ import com.o19s.es.ltr.feature.store.StorableElement; import com.o19s.es.ltr.feature.store.index.IndexFeatureStore; import org.elasticsearch.action.ActionRequest; +import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.ActionRequestValidationException; -import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.ActionType; +import org.elasticsearch.action.DocWriteResponse; import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.client.internal.ElasticsearchClient; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable.Reader; -import org.elasticsearch.common.xcontent.StatusToXContentObject; -import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.rest.RestStatus; +import org.elasticsearch.xcontent.ToXContentObject; +import org.elasticsearch.xcontent.XContentBuilder; import java.io.IOException; import java.util.Objects; @@ -145,10 +146,6 @@ public void setRouting(String routing) { this.routing = routing; } - public Long getUpdatedVersion() { - return updatedVersion; - } - public FeatureValidation getValidation() { return validation; } @@ -173,19 +170,19 @@ public enum Action { } } - public static class FeatureStoreResponse extends ActionResponse implements StatusToXContentObject { - private IndexResponse response; + public static class FeatureStoreResponse extends ActionResponse implements ToXContentObject { + private DocWriteResponse response; public FeatureStoreResponse(StreamInput in) throws IOException { super(in); response = new IndexResponse(in); } - public FeatureStoreResponse(IndexResponse response) { + public FeatureStoreResponse(DocWriteResponse response) { this.response = response; } - public IndexResponse getResponse() { + public DocWriteResponse getResponse() { return response; } @@ -197,7 +194,6 @@ public void writeTo(StreamOutput out) throws IOException { /** * Returns the REST status to make sure it is returned correctly */ - @Override public RestStatus status() { return response.status(); } 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 c3386d41..5af8af63 100644 --- a/src/main/java/com/o19s/es/ltr/action/LTRStatsAction.java +++ b/src/main/java/com/o19s/es/ltr/action/LTRStatsAction.java @@ -103,7 +103,7 @@ public static class LTRStatsNodesRequest extends BaseNodesRequest getClusterStats() { @Override protected List readNodesFrom(StreamInput in) throws IOException { - return in.readList(LTRStatsNodeResponse::new); + return in.readCollectionAsList(LTRStatsNodeResponse::new); } @Override protected void writeNodesTo(StreamOutput out, List nodeResponses) throws IOException { - out.writeList(nodeResponses); + out.writeCollection(nodeResponses); } @Override 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 751a40d1..723a88ac 100644 --- a/src/main/java/com/o19s/es/ltr/action/TransportCacheStatsAction.java +++ b/src/main/java/com/o19s/es/ltr/action/TransportCacheStatsAction.java @@ -48,9 +48,11 @@ public TransportCacheStatsAction(Settings settings, ThreadPool threadPool, Caches caches) { super(CachesStatsAction.NAME, threadPool, clusterService, transportService, actionFilters, CachesStatsNodesRequest::new, CachesStatsNodeRequest::new, - ThreadPool.Names.MANAGEMENT, CachesStatsAction.CachesStatsNodeResponse.class); + threadPool.executor(ThreadPool.Names.MANAGEMENT)); this.caches = caches; } +//CachesStatsNodesRequest::new + @Override protected CachesStatsNodesResponse newResponse(CachesStatsNodesRequest request, List responses, 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 69705d39..ebee0014 100644 --- a/src/main/java/com/o19s/es/ltr/action/TransportClearCachesAction.java +++ b/src/main/java/com/o19s/es/ltr/action/TransportClearCachesAction.java @@ -48,7 +48,7 @@ public TransportClearCachesAction(Settings settings, ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, Caches caches) { super(ClearCachesAction.NAME, threadPool, clusterService, transportService, actionFilters, - ClearCachesNodesRequest::new, ClearCachesNodeRequest::new, ThreadPool.Names.MANAGEMENT, ClearCachesNodeResponse.class); + ClearCachesNodesRequest::new, ClearCachesNodeRequest::new, threadPool.executor(ThreadPool.Names.MANAGEMENT)); this.caches = caches; } diff --git a/src/main/java/com/o19s/es/ltr/action/TransportLTRStatsAction.java b/src/main/java/com/o19s/es/ltr/action/TransportLTRStatsAction.java index f7e78850..297ea671 100644 --- a/src/main/java/com/o19s/es/ltr/action/TransportLTRStatsAction.java +++ b/src/main/java/com/o19s/es/ltr/action/TransportLTRStatsAction.java @@ -35,7 +35,7 @@ public TransportLTRStatsAction(ThreadPool threadPool, LTRStats ltrStats) { super(LTRStatsAction.NAME, threadPool, clusterService, transportService, actionFilters, LTRStatsNodesRequest::new, LTRStatsNodeRequest::new, - ThreadPool.Names.MANAGEMENT, LTRStatsNodeResponse.class); + threadPool.executor(ThreadPool.Names.MANAGEMENT)); this.ltrStats = ltrStats; } diff --git a/src/main/java/com/o19s/es/ltr/action/TransportListStoresAction.java b/src/main/java/com/o19s/es/ltr/action/TransportListStoresAction.java index 657df618..11dac743 100644 --- a/src/main/java/com/o19s/es/ltr/action/TransportListStoresAction.java +++ b/src/main/java/com/o19s/es/ltr/action/TransportListStoresAction.java @@ -63,7 +63,8 @@ public TransportListStoresAction(TransportService transportService, ClusterService clusterService, ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, Client client) { super(ListStoresAction.NAME, transportService, clusterService, threadPool, - actionFilters, ListStoresActionRequest::new, indexNameExpressionResolver, ListStoresActionResponse::new, ThreadPool.Names.SAME); + actionFilters, ListStoresActionRequest::new, indexNameExpressionResolver, ListStoresActionResponse::new, + threadPool.executor(ThreadPool.Names.SAME)); this.client = client; } diff --git a/src/main/java/com/o19s/es/ltr/feature/store/StoredFeature.java b/src/main/java/com/o19s/es/ltr/feature/store/StoredFeature.java index a72f60a5..14253427 100644 --- a/src/main/java/com/o19s/es/ltr/feature/store/StoredFeature.java +++ b/src/main/java/com/o19s/es/ltr/feature/store/StoredFeature.java @@ -99,7 +99,7 @@ public StoredFeature(String name, List params, String templateLanguage, public StoredFeature(StreamInput input) throws IOException { name = input.readString(); - queryParams = input.readList(StreamInput::readString); + queryParams = input.readCollectionAsList(StreamInput::readString); templateLanguage = input.readString(); template = input.readString(); templateAsString = input.readBoolean(); diff --git a/src/main/java/com/o19s/es/ltr/feature/store/StoredFeatureSet.java b/src/main/java/com/o19s/es/ltr/feature/store/StoredFeatureSet.java index 71db4aa2..f78bd60b 100644 --- a/src/main/java/com/o19s/es/ltr/feature/store/StoredFeatureSet.java +++ b/src/main/java/com/o19s/es/ltr/feature/store/StoredFeatureSet.java @@ -123,13 +123,13 @@ public void validate() { } public StoredFeatureSet(StreamInput input) throws IOException { - this(input.readString(), input.readList(StoredFeature::new)); + this(input.readString(), input.readCollectionAsList(StoredFeature::new)); } @Override public void writeTo(StreamOutput out) throws IOException { out.writeString(name); - out.writeList(features); + out.writeCollection(features); } @Override diff --git a/src/main/java/com/o19s/es/ltr/feature/store/StoredLtrModel.java b/src/main/java/com/o19s/es/ltr/feature/store/StoredLtrModel.java index 75ffa448..2997b244 100644 --- a/src/main/java/com/o19s/es/ltr/feature/store/StoredLtrModel.java +++ b/src/main/java/com/o19s/es/ltr/feature/store/StoredLtrModel.java @@ -22,7 +22,7 @@ import com.o19s.es.ltr.ranker.normalizer.Normalizer; import com.o19s.es.ltr.ranker.parser.LtrRankerParser; import com.o19s.es.ltr.ranker.parser.LtrRankerParserFactory; -import org.elasticsearch.TransportVersion; +import org.elasticsearch.TransportVersions; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.Strings; @@ -85,7 +85,7 @@ public StoredLtrModel(StreamInput input) throws IOException { rankingModelType = input.readString(); rankingModel = input.readString(); modelAsString = input.readBoolean(); - if (input.getTransportVersion().onOrAfter(TransportVersion.V_7_7_0)) { + if (input.getTransportVersion().onOrAfter(TransportVersions.V_7_7_0)) { this.parsedFtrNorms = new StoredFeatureNormalizers(input); } else { this.parsedFtrNorms = new StoredFeatureNormalizers(); @@ -99,7 +99,7 @@ public void writeTo(StreamOutput out) throws IOException { out.writeString(rankingModelType); out.writeString(rankingModel); out.writeBoolean(modelAsString); - if (out.getTransportVersion().onOrAfter(TransportVersion.V_7_7_0)) { + if (out.getTransportVersion().onOrAfter(TransportVersions.V_7_7_0)) { parsedFtrNorms.writeTo(out); } } @@ -280,7 +280,7 @@ public LtrModelDefinition(StreamInput in) throws IOException { type = in.readString(); definition = in.readString(); modelAsString = in.readBoolean(); - if (in.getTransportVersion().onOrAfter(TransportVersion.V_7_7_0)) { + if (in.getTransportVersion().onOrAfter(TransportVersions.V_7_7_0)) { this.featureNormalizers = new StoredFeatureNormalizers(in); } else { this.featureNormalizers = new StoredFeatureNormalizers(); @@ -292,7 +292,7 @@ public void writeTo(StreamOutput out) throws IOException { out.writeString(type); out.writeString(definition); out.writeBoolean(modelAsString); - if (out.getTransportVersion().onOrAfter(TransportVersion.V_7_7_0)) { + if (out.getTransportVersion().onOrAfter(TransportVersions.V_7_7_0)) { this.featureNormalizers.writeTo(out); } } diff --git a/src/main/java/com/o19s/es/ltr/logging/LoggingSearchExtBuilder.java b/src/main/java/com/o19s/es/ltr/logging/LoggingSearchExtBuilder.java index b35d34db..4ae31e87 100644 --- a/src/main/java/com/o19s/es/ltr/logging/LoggingSearchExtBuilder.java +++ b/src/main/java/com/o19s/es/ltr/logging/LoggingSearchExtBuilder.java @@ -49,12 +49,12 @@ public class LoggingSearchExtBuilder extends SearchExtBuilder { public LoggingSearchExtBuilder() {} public LoggingSearchExtBuilder(StreamInput input) throws IOException { - logSpecs = input.readList(LogSpec::new); + logSpecs = input.readCollectionAsList(LogSpec::new); } @Override public void writeTo(StreamOutput out) throws IOException { - out.writeList(logSpecs); + out.writeCollection(logSpecs); } @Override diff --git a/src/main/java/com/o19s/es/ltr/query/LtrQueryBuilder.java b/src/main/java/com/o19s/es/ltr/query/LtrQueryBuilder.java index 3e63af0c..a2a38a72 100644 --- a/src/main/java/com/o19s/es/ltr/query/LtrQueryBuilder.java +++ b/src/main/java/com/o19s/es/ltr/query/LtrQueryBuilder.java @@ -24,6 +24,7 @@ import com.o19s.es.ltr.ranker.ranklib.RankLibScriptEngine; import com.o19s.es.ltr.utils.AbstractQueryBuilderUtils; import org.apache.lucene.search.Query; +import org.elasticsearch.TransportVersions; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.TransportVersion; import org.elasticsearch.common.ParsingException; @@ -206,6 +207,6 @@ public final LtrQueryBuilder features(List features) { @Override public TransportVersion getMinimalSupportedVersion() { - return TransportVersion.V_7_0_0; + return TransportVersions.V_7_0_0; } } diff --git a/src/main/java/com/o19s/es/ltr/query/RankerQuery.java b/src/main/java/com/o19s/es/ltr/query/RankerQuery.java index 957a0d84..866eda84 100644 --- a/src/main/java/com/o19s/es/ltr/query/RankerQuery.java +++ b/src/main/java/com/o19s/es/ltr/query/RankerQuery.java @@ -203,7 +203,7 @@ public boolean isCacheable(LeafReaderContext ctx) { // XXX: this is not thread safe and may run into extremely weird issues // if the searcher uses the parallel collector // Hopefully elastic never runs - MutableSupplier vectorSupplier = new Suppliers.FeatureVectorSupplier(); + MutableSupplier vectorSupplier = new Suppliers.MutableSupplier<>(); FVLtrRankerWrapper ltrRankerWrapper = new FVLtrRankerWrapper(ranker, vectorSupplier); LtrRewriteContext context = new LtrRewriteContext(ranker, vectorSupplier); for (Query q : queries) { 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 8e36d0de..f72176be 100644 --- a/src/main/java/com/o19s/es/ltr/query/StoredLtrQueryBuilder.java +++ b/src/main/java/com/o19s/es/ltr/query/StoredLtrQueryBuilder.java @@ -24,6 +24,7 @@ import com.o19s.es.ltr.ranker.linear.LinearRanker; import com.o19s.es.ltr.utils.FeatureStoreLoader; import org.elasticsearch.TransportVersion; +import org.elasticsearch.TransportVersions; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.io.stream.NamedWriteable; @@ -90,7 +91,7 @@ public StoredLtrQueryBuilder(FeatureStoreLoader storeLoader, StreamInput input) featureScoreCacheFlag = input.readOptionalBoolean(); featureSetName = input.readOptionalString(); params = input.readMap(); - if (input.getTransportVersion().onOrAfter(TransportVersion.V_7_0_0)) { + if (input.getTransportVersion().onOrAfter(TransportVersions.V_7_0_0)) { String[] activeFeat = input.readOptionalStringArray(); activeFeatures = activeFeat == null ? null : Arrays.asList(activeFeat); } @@ -121,7 +122,7 @@ protected void doWriteTo(StreamOutput out) throws IOException { out.writeOptionalBoolean(featureScoreCacheFlag); out.writeOptionalString(featureSetName); out.writeGenericMap(params); - if (out.getTransportVersion().onOrAfter(TransportVersion.V_7_0_0)) { + if (out.getTransportVersion().onOrAfter(TransportVersions.V_7_0_0)) { out.writeOptionalStringArray(activeFeatures != null ? activeFeatures.toArray(new String[0]) : null); } out.writeOptionalString(storeName); @@ -255,7 +256,7 @@ public StoredLtrQueryBuilder activeFeatures(List activeFeatures) { @Override public TransportVersion getMinimalSupportedVersion() { - return TransportVersion.V_7_0_0; + return TransportVersions.V_7_0_0; } } diff --git a/src/main/java/com/o19s/es/ltr/query/ValidatingLtrQueryBuilder.java b/src/main/java/com/o19s/es/ltr/query/ValidatingLtrQueryBuilder.java index a4d010b5..364c5d76 100644 --- a/src/main/java/com/o19s/es/ltr/query/ValidatingLtrQueryBuilder.java +++ b/src/main/java/com/o19s/es/ltr/query/ValidatingLtrQueryBuilder.java @@ -30,6 +30,7 @@ import com.o19s.es.ltr.ranker.parser.LtrRankerParserFactory; import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.Query; +import org.elasticsearch.TransportVersions; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.TransportVersion; import org.elasticsearch.common.ParsingException; @@ -209,6 +210,6 @@ public FeatureValidation getValidation() { @Override public TransportVersion getMinimalSupportedVersion() { - return TransportVersion.V_7_0_0; + return TransportVersions.V_7_0_0; } } diff --git a/src/main/java/com/o19s/es/ltr/rest/RestAddFeatureToSet.java b/src/main/java/com/o19s/es/ltr/rest/RestAddFeatureToSet.java index afcf6e0d..8865a751 100644 --- a/src/main/java/com/o19s/es/ltr/rest/RestAddFeatureToSet.java +++ b/src/main/java/com/o19s/es/ltr/rest/RestAddFeatureToSet.java @@ -24,7 +24,7 @@ import org.elasticsearch.xcontent.ObjectParser; import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.rest.RestRequest; -import org.elasticsearch.rest.action.RestStatusToXContentListener; +import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; import java.util.List; @@ -86,7 +86,7 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli builder.request().setFeatures(features); builder.request().setMerge(merge); builder.request().setValidation(validation); - return (channel) -> builder.execute(new RestStatusToXContentListener<>(channel, (r) -> r.getResponse().getLocation(routing))); + return (channel) -> builder.execute(new RestToXContentListener<>(channel)); } static class FeaturesParserState { diff --git a/src/main/java/com/o19s/es/ltr/rest/RestCreateModelFromSet.java b/src/main/java/com/o19s/es/ltr/rest/RestCreateModelFromSet.java index d8c15767..da4f25ff 100644 --- a/src/main/java/com/o19s/es/ltr/rest/RestCreateModelFromSet.java +++ b/src/main/java/com/o19s/es/ltr/rest/RestCreateModelFromSet.java @@ -31,7 +31,7 @@ import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestStatus; -import org.elasticsearch.rest.action.RestStatusToXContentListener; +import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; import java.util.List; @@ -78,8 +78,7 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli builder.request().setValidation(state.validation); builder.routing(routing); return (channel) -> builder.execute(ActionListener.wrap( - response -> new RestStatusToXContentListener(channel, - (r) -> r.getResponse().getLocation(routing)).onResponse(response), + response -> new RestToXContentListener(channel).onResponse(response), (e) -> { final Exception exc; final RestStatus status; diff --git a/src/main/java/com/o19s/es/ltr/rest/RestFeatureManager.java b/src/main/java/com/o19s/es/ltr/rest/RestFeatureManager.java index 0c725ec9..5c026d49 100644 --- a/src/main/java/com/o19s/es/ltr/rest/RestFeatureManager.java +++ b/src/main/java/com/o19s/es/ltr/rest/RestFeatureManager.java @@ -10,10 +10,9 @@ import org.elasticsearch.action.delete.DeleteResponse; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.client.internal.node.NodeClient; -import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; -import org.elasticsearch.rest.action.RestStatusToXContentListener; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; @@ -72,7 +71,8 @@ RestChannelConsumer delete(NodeClient client, String type, String indexName, Res String id = generateId(type, name); String routing = request.param("routing"); return (channel) -> { - RestStatusToXContentListener restR = new RestStatusToXContentListener<>(channel, (r) -> r.getLocation(routing)); + //RestToXContentListener restR = new RestToXContentListener<>(channel, (r) -> r.getLocation(routing)); + RestToXContentListener restR = (new RestToXContentListener<>(channel, (r) -> r.status())); client.prepareDelete(indexName, id) .setRouting(routing) .execute(ActionListener.wrap((deleteResponse) -> { @@ -109,12 +109,7 @@ RestChannelConsumer get(NodeClient client, String type, String indexName, RestRe String id = generateId(type, name); return (channel) -> client.prepareGet(indexName, id) .setRouting(routing) - .execute(new RestToXContentListener(channel) { - @Override - protected RestStatus getStatus(final GetResponse response) { - return response.isExists() ? OK : NOT_FOUND; - } - }); + .execute(new RestToXContentListener(channel, r -> r.isExists() ? OK : NOT_FOUND)); } RestChannelConsumer addOrUpdate(NodeClient client, String type, String indexName, RestRequest request) throws IOException { @@ -154,6 +149,7 @@ RestChannelConsumer addOrUpdate(NodeClient client, String type, String indexName builder.request().setRouting(routing); builder.request().setStore(indexName); builder.request().setValidation(parserState.getValidation()); - return (channel) -> builder.execute(new RestStatusToXContentListener<>(channel, (r) -> r.getResponse().getLocation(routing))); + return (channel) -> builder.execute(new RestToXContentListener<>(channel, (r) -> r.getResponse().status(), + (r) -> r.getResponse().getLocation(routing))); } } diff --git a/src/main/java/com/o19s/es/ltr/utils/Suppliers.java b/src/main/java/com/o19s/es/ltr/utils/Suppliers.java index 52baf725..e23e63e8 100644 --- a/src/main/java/com/o19s/es/ltr/utils/Suppliers.java +++ b/src/main/java/com/o19s/es/ltr/utils/Suppliers.java @@ -16,11 +16,10 @@ package com.o19s.es.ltr.utils; -import com.o19s.es.ltr.ranker.LtrRanker; -import org.elasticsearch.core.Assertions; import org.elasticsearch.common.CheckedSupplier; import java.util.Objects; +import java.util.concurrent.atomic.AtomicReference; import java.util.function.Supplier; public final class Suppliers { @@ -67,33 +66,15 @@ public E get() { * A mutable supplier */ public static class MutableSupplier implements Supplier { - T obj; + private final AtomicReference ref = new AtomicReference<>(); @Override public T get() { - return obj; + return ref.get(); } public void set(T obj) { - this.obj = obj; - } - } - - /** - * Simple wrapper to make sure we run on the same thread - */ - public static class FeatureVectorSupplier extends MutableSupplier { - private final long threadId = Assertions.ENABLED ? Thread.currentThread().getId() : 0; - - public LtrRanker.FeatureVector get() { - assert threadId == Thread.currentThread().getId(); - return super.get(); - } - - @Override - public void set(LtrRanker.FeatureVector obj) { - assert threadId == Thread.currentThread().getId(); - super.set(obj); + this.ref.set(obj); } } diff --git a/src/main/java/com/o19s/es/termstat/TermStatQueryBuilder.java b/src/main/java/com/o19s/es/termstat/TermStatQueryBuilder.java index ccdc9464..ca3365cc 100644 --- a/src/main/java/com/o19s/es/termstat/TermStatQueryBuilder.java +++ b/src/main/java/com/o19s/es/termstat/TermStatQueryBuilder.java @@ -8,6 +8,7 @@ import org.apache.lucene.analysis.tokenattributes.TermToBytesRefAttribute; import org.apache.lucene.index.Term; import org.apache.lucene.search.Query; +import org.elasticsearch.TransportVersions; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.TransportVersion; import org.elasticsearch.common.ParsingException; @@ -250,6 +251,6 @@ public TermStatQueryBuilder terms(List terms) { @Override public TransportVersion getMinimalSupportedVersion() { - return TransportVersion.V_7_0_0; + return TransportVersions.V_7_0_0; } } diff --git a/src/test/java/com/o19s/es/ltr/feature/store/StoredLtrModelParserTests.java b/src/test/java/com/o19s/es/ltr/feature/store/StoredLtrModelParserTests.java index 34df5094..95512e9a 100644 --- a/src/test/java/com/o19s/es/ltr/feature/store/StoredLtrModelParserTests.java +++ b/src/test/java/com/o19s/es/ltr/feature/store/StoredLtrModelParserTests.java @@ -24,7 +24,7 @@ import com.o19s.es.ltr.ranker.parser.LtrRankerParserFactory; import org.apache.lucene.util.BytesRef; import org.apache.lucene.tests.util.LuceneTestCase; -import org.elasticsearch.TransportVersion; +import org.elasticsearch.TransportVersions; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.Randomness; import org.elasticsearch.common.Strings; @@ -319,7 +319,7 @@ public void testSerializationUpgradeBinaryStream() throws IOException { String base64Encoded = "C21vZGVsL2R1bW15EmNvbXBsZXRlbHkgaWdub3JlZAE="; byte[] bytes = Base64.getDecoder().decode(base64Encoded); StreamInput input = ByteBufferStreamInput.wrap(bytes, 0, bytes.length); - input.setTransportVersion(TransportVersion.V_7_6_0); + input.setTransportVersion(TransportVersions.V_7_6_0); StoredLtrModel.LtrModelDefinition modelUnserialized = new StoredLtrModel.LtrModelDefinition(input); assertEquals(modelUnserialized.getDefinition(), "completely ignored");