Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
rjernst committed Sep 14, 2023
1 parent a499edc commit bd8d567
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
3 changes: 2 additions & 1 deletion server/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions server/src/main/java/org/elasticsearch/action/ActionModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -851,7 +851,13 @@ private static ActionFilters setupActionFilters(List<ActionPlugin> actionPlugins

public void initRestHandlers(Supplier<DiscoveryNodes> nodesInCluster) {
List<AbstractCatAction> catActions = new ArrayList<>();
Predicate<AbstractCatAction> catActionsFilter = CatExtension.load(a -> true).getCatActionsFilter();
var restExtension = RestExtension.load(() -> new RestExtension() {
@Override
public Predicate<AbstractCatAction> getCatActionsFilter() {
return action -> true;
}
});
Predicate<AbstractCatAction> catActionsFilter = restExtension.getCatActionsFilter();
Consumer<RestHandler> registerHandler = handler -> {
if (shouldKeepRestHandler(handler)) {
if (handler instanceof AbstractCatAction catAction && catActionsFilter.test(catAction)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -22,16 +23,13 @@ public interface CatExtension {
*/
Predicate<AbstractCatAction> getCatActionsFilter();

/**
* Loads a CatExtension.
*/
static CatExtension load(Predicate<AbstractCatAction> defaultFilter) {
var loader = ServiceLoader.load(CatExtension.class);
static RestExtension load(Supplier<RestExtension> 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();
}
Expand Down

0 comments on commit bd8d567

Please sign in to comment.