diff --git a/server/src/main/java/module-info.java b/server/src/main/java/module-info.java index 42e46ead48b1e..472707babf155 100644 --- a/server/src/main/java/module-info.java +++ b/server/src/main/java/module-info.java @@ -7,6 +7,7 @@ */ import org.elasticsearch.index.codec.tsdb.ES87TSDBDocValuesFormat; +import org.elasticsearch.plugins.internal.RestExtension; /** The Elasticsearch Server Module. */ module org.elasticsearch.server { @@ -393,7 +394,7 @@ uses org.elasticsearch.internal.VersionExtension; uses org.elasticsearch.internal.BuildExtension; uses org.elasticsearch.plugins.internal.SettingsExtension; - uses org.elasticsearch.plugins.internal.CatExtension; + uses RestExtension; provides org.apache.lucene.codecs.PostingsFormat with diff --git a/server/src/main/java/org/elasticsearch/action/ActionModule.java b/server/src/main/java/org/elasticsearch/action/ActionModule.java index 81dd81821a027..5683ace63ba3b 100644 --- a/server/src/main/java/org/elasticsearch/action/ActionModule.java +++ b/server/src/main/java/org/elasticsearch/action/ActionModule.java @@ -306,7 +306,7 @@ import org.elasticsearch.plugins.ActionPlugin; import org.elasticsearch.plugins.ActionPlugin.ActionHandler; import org.elasticsearch.plugins.interceptor.RestServerActionPlugin; -import org.elasticsearch.plugins.internal.CatExtension; +import org.elasticsearch.plugins.internal.RestExtension; import org.elasticsearch.reservedstate.ReservedClusterStateHandler; import org.elasticsearch.reservedstate.service.ReservedClusterStateService; import org.elasticsearch.rest.RestController; @@ -851,7 +851,13 @@ private static ActionFilters setupActionFilters(List actionPlugins public void initRestHandlers(Supplier nodesInCluster) { List catActions = new ArrayList<>(); - Predicate catActionsFilter = CatExtension.load(a -> true).getCatActionsFilter(); + var restExtension = RestExtension.load(() -> new RestExtension() { + @Override + public Predicate getCatActionsFilter() { + return action -> true; + } + }); + Predicate catActionsFilter = restExtension.getCatActionsFilter(); Consumer registerHandler = handler -> { if (shouldKeepRestHandler(handler)) { if (handler instanceof AbstractCatAction catAction && catActionsFilter.test(catAction)) { diff --git a/server/src/main/java/org/elasticsearch/plugins/internal/CatExtension.java b/server/src/main/java/org/elasticsearch/plugins/internal/RestExtension.java similarity index 74% rename from server/src/main/java/org/elasticsearch/plugins/internal/CatExtension.java rename to server/src/main/java/org/elasticsearch/plugins/internal/RestExtension.java index 7d43fdfd699bf..da5de4f784a22 100644 --- a/server/src/main/java/org/elasticsearch/plugins/internal/CatExtension.java +++ b/server/src/main/java/org/elasticsearch/plugins/internal/RestExtension.java @@ -12,8 +12,9 @@ import java.util.ServiceLoader; import java.util.function.Predicate; +import java.util.function.Supplier; -public interface CatExtension { +public interface RestExtension { /** * Returns a filter that determines which cat actions are exposed in /_cat. * @@ -22,16 +23,13 @@ public interface CatExtension { */ Predicate getCatActionsFilter(); - /** - * Loads a CatExtension. - */ - static CatExtension load(Predicate defaultFilter) { - var loader = ServiceLoader.load(CatExtension.class); + static RestExtension load(Supplier fallback) { + var loader = ServiceLoader.load(RestExtension.class); var extensions = loader.stream().toList(); if (extensions.size() > 1) { - throw new IllegalStateException("More than one cat extension found"); + throw new IllegalStateException("More than one rest extension found"); } else if (extensions.size() == 0) { - return () -> defaultFilter; + return fallback.get(); } return extensions.get(0).get(); }