Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented Settings #76

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/com/o19s/es/explore/ExplorerQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.similarities.ClassicSimilarity;
import org.opensearch.ltr.settings.LTRSettings;

import java.io.IOException;
import java.util.HashSet;
Expand Down Expand Up @@ -91,6 +92,10 @@ public int hashCode() {
@Override
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost)
throws IOException {
if (!LTRSettings.isLTRPluginEnabled()) {
throw new IllegalStateException("LTR plugin is disabled. To enable, update ltr.plugin.enabled to true");
}

if (!scoreMode.needsScores()) {
return searcher.createWeight(query, scoreMode, boost);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Explanation;
import org.apache.lucene.search.DocIdSetIterator;
import org.opensearch.ltr.settings.LTRSettings;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -78,6 +79,10 @@ public int hashCode() {
@Override
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost)
throws IOException {
if (!LTRSettings.isLTRPluginEnabled()) {
throw new IllegalStateException("LTR plugin is disabled. To enable, update ltr.plugin.enabled to true");
}

assert scoreMode.needsScores() : "Should not be used in filtering mode";
return new PostingsExplorerWeight(this, this.term, TermStates.build(searcher, this.term,
scoreMode.needsScores()),
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/o19s/es/ltr/feature/PrebuiltFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.ScoreMode;
import org.opensearch.common.Nullable;
import org.opensearch.ltr.settings.LTRSettings;

import java.io.IOException;
import java.util.Map;
Expand Down Expand Up @@ -79,6 +80,10 @@ public String toString(String field) {

@Override
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException {
if (!LTRSettings.isLTRPluginEnabled()) {
throw new IllegalStateException("LTR plugin is disabled. To enable, update ltr.plugin.enabled to true");
}

return query.createWeight(searcher, scoreMode, boost);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.index.mapper.MappedFieldType;
import org.opensearch.ltr.settings.LTRSettings;
import org.opensearch.script.ScoreScript;
import org.opensearch.script.Script;

Expand Down Expand Up @@ -287,6 +288,10 @@ public String toString(String field) {

@Override
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException {
if (!LTRSettings.isLTRPluginEnabled()) {
throw new IllegalStateException("LTR plugin is disabled. To enable, update ltr.plugin.enabled to true");
}

if (!scoreMode.needsScores()) {
return new MatchAllDocsQuery().createWeight(searcher, scoreMode, 1F);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.lucene.search.ConstantScoreWeight;
import org.apache.lucene.search.ConstantScoreWeight;
import org.apache.lucene.search.ConstantScoreWeight;
import org.opensearch.ltr.settings.LTRSettings;


import java.io.IOException;
Expand Down Expand Up @@ -102,6 +103,10 @@ public String toString(String field) {

@Override
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException {
if (!LTRSettings.isLTRPluginEnabled()) {
throw new IllegalStateException("LTR plugin is disabled. To enable, update ltr.plugin.enabled to true");
}

if (!scoreMode.needsScores()) {
// If scores are not needed simply return a constant score on all docs
return new ConstantScoreWeight(this.query, boost) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/o19s/es/ltr/query/RankerQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.o19s.es.ltr.query;

import org.opensearch.ltr.settings.LTRSettings;
import com.o19s.es.ltr.LtrQueryContext;
import com.o19s.es.ltr.feature.Feature;
import com.o19s.es.ltr.feature.FeatureSet;
Expand Down Expand Up @@ -201,6 +202,10 @@ public FeatureSet featureSet() {

@Override
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException {
if (!LTRSettings.isLTRPluginEnabled()) {
throw new IllegalStateException("LTR plugin is disabled. To enable, update ltr.plugin.enabled to true");
}

if (!scoreMode.needsScores()) {
// If scores are not needed simply return a constant score on all docs
return new ConstantScoreWeight(this, boost) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/o19s/es/ltr/rest/RestAddFeatureToSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.o19s.es.ltr.rest;

import org.opensearch.ltr.settings.LTRSettings;
import com.o19s.es.ltr.action.AddFeaturesToSetAction.AddFeaturesToSetRequestBuilder;
import com.o19s.es.ltr.feature.FeatureValidation;
import com.o19s.es.ltr.feature.store.StoredFeature;
Expand Down Expand Up @@ -51,6 +52,10 @@ public List<Route> routes() {

@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
if (!LTRSettings.isLTRPluginEnabled()) {
throw new IllegalStateException("LTR plugin is disabled. To enable, update ltr.plugin.enabled to true");
}

String store = indexName(request);

String setName = request.param("name");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.o19s.es.ltr.rest;

import org.opensearch.ltr.settings.LTRSettings;
import com.o19s.es.ltr.action.CreateModelFromSetAction;
import com.o19s.es.ltr.action.CreateModelFromSetAction.CreateModelFromSetRequestBuilder;
import com.o19s.es.ltr.feature.FeatureValidation;
Expand Down Expand Up @@ -55,6 +56,10 @@ public List<Route> routes() {

@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
if (!LTRSettings.isLTRPluginEnabled()) {
throw new IllegalStateException("LTR plugin is disabled. To enable, update ltr.plugin.enabled to true");
}

String store = indexName(request);
Long expectedVersion = null;
if (request.hasParam("version")) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/o19s/es/ltr/rest/RestFeatureManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.opensearch.action.delete.DeleteResponse;
import org.opensearch.action.get.GetResponse;
import org.opensearch.client.node.NodeClient;
import org.opensearch.ltr.settings.LTRSettings;
import org.opensearch.rest.BytesRestResponse;
import org.opensearch.rest.RestRequest;
import org.opensearch.core.rest.RestStatus;
Expand Down Expand Up @@ -73,6 +74,10 @@ public List<Route> routes() {

@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
if (!LTRSettings.isLTRPluginEnabled()) {
throw new IllegalStateException("LTR plugin is disabled. To enable, update ltr.plugin.enabled to true");
}

String indexName = indexName(request);
if (request.method() == RestRequest.Method.DELETE) {
return delete(client, type, indexName, request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.o19s.es.ltr.rest;

import org.opensearch.ltr.settings.LTRSettings;
import com.o19s.es.ltr.action.CachesStatsAction;
import com.o19s.es.ltr.action.ClearCachesAction;
import com.o19s.es.ltr.action.ClearCachesAction.ClearCachesNodesResponse;
Expand Down Expand Up @@ -61,6 +62,10 @@ public List<Route> routes() {

@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) {
if (!LTRSettings.isLTRPluginEnabled()) {
throw new IllegalStateException("LTR plugin is disabled. To enable, update ltr.plugin.enabled to true");
}

if (request.method() == RestRequest.Method.POST) {
return clearCache(request, client);
} else {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/o19s/es/ltr/rest/RestLTRStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.o19s.es.ltr.action.LTRStatsAction.LTRStatsNodesRequest;
import com.o19s.es.ltr.stats.StatName;
import org.opensearch.client.node.NodeClient;
import org.opensearch.ltr.settings.LTRSettings;
import org.opensearch.rest.BaseRestHandler;
import org.opensearch.rest.RestRequest;
import org.opensearch.rest.action.RestActions;
Expand Down Expand Up @@ -62,6 +63,10 @@ public List<Route> routes() {
@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client)
throws IOException {
if (!LTRSettings.isLTRPluginEnabled()) {
throw new IllegalStateException("LTR plugin is disabled. To enable, update ltr.plugin.enabled to true");
}

LTRStatsNodesRequest ltrStatsRequest = getRequest(request);
return (channel) -> client.execute(LTRStatsAction.INSTANCE,
ltrStatsRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.o19s.es.ltr.feature.store.index.IndexFeatureStore;
import org.opensearch.client.node.NodeClient;
import org.opensearch.index.query.BoolQueryBuilder;
import org.opensearch.ltr.settings.LTRSettings;
import org.opensearch.rest.RestRequest;
import org.opensearch.rest.action.RestStatusToXContentListener;

Expand Down Expand Up @@ -51,6 +52,10 @@ public List<Route> routes() {

@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) {
if (!LTRSettings.isLTRPluginEnabled()) {
throw new IllegalStateException("LTR plugin is disabled. To enable, update ltr.plugin.enabled to true");
}

return search(client, type, indexName(request), request);
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/o19s/es/ltr/rest/RestStoreManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.opensearch.action.admin.indices.exists.indices.IndicesExistsResponse;
import org.opensearch.client.node.NodeClient;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.ltr.settings.LTRSettings;
import org.opensearch.rest.BytesRestResponse;
import org.opensearch.rest.RestRequest;
import org.opensearch.rest.RestResponse;
Expand Down Expand Up @@ -69,6 +70,10 @@ public List<Route> routes() {
*/
@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
if (!LTRSettings.isLTRPluginEnabled()) {
throw new IllegalStateException("LTR plugin is disabled. To enable, update ltr.plugin.enabled to true");
}

String indexName = indexName(request);

if (request.method() == RestRequest.Method.PUT) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/o19s/es/termstat/TermStatQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.lucene.search.Weight;
import org.apache.lucene.search.Explanation;
import org.apache.lucene.search.Scorer;
import org.opensearch.ltr.settings.LTRSettings;

import java.io.IOException;
import java.util.HashMap;
Expand Down Expand Up @@ -89,6 +90,10 @@ public String toString(String field) {
@Override
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost)
throws IOException {
if (!LTRSettings.isLTRPluginEnabled()) {
throw new IllegalStateException("LTR plugin is disabled. To enable, update ltr.plugin.enabled to true");
}

assert scoreMode.needsScores() : "Should not be used in filtering mode";

return new TermStatWeight(searcher, this, terms, scoreMode, aggr, posAggr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.opensearch.ltr.settings.LTRSettings;
import org.opensearch.monitor.jvm.JvmService;

import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -79,6 +80,10 @@ public LTRCircuitBreakerService init() {
}

public Boolean isOpen() {
if (!LTRSettings.isLTRBreakerEnabled()) {
return false;
}

for (CircuitBreaker breaker : breakers.values()) {
if (breaker.isOpen()) {
return true;
Expand Down
Loading
Loading