Refactor RestMainAction into separate module (#95881)

we want to allow overriding info (GET /) api in serverless, therefore this commit moves the RestMainAction and is transport classes into a module that has a rest plugin

Main endpoint is often used in testing to verfiy that a cluster is ready, hence this commit also has to add a testing dependency on main to a lot of modules

relates #95422
This commit is contained in:
Przemyslaw Gomulka 2023-05-10 14:39:00 +02:00 committed by GitHub
parent f13b1a5648
commit dc03c47ada
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
41 changed files with 200 additions and 47 deletions

View file

@ -29,6 +29,7 @@ testClusters.configureEach {
// Modules who's integration is explicitly tested in integration tests // Modules who's integration is explicitly tested in integration tests
module ':modules:parent-join' module ':modules:parent-join'
module ':modules:lang-painless' module ':modules:lang-painless'
module ':modules:rest-root'
// Whitelist reindexing from the local node so we can test reindex-from-remote. // Whitelist reindexing from the local node so we can test reindex-from-remote.
setting 'reindex.remote.whitelist', '127.0.0.1:*' setting 'reindex.remote.whitelist', '127.0.0.1:*'
requiresFeature 'es.index_mode_feature_flag_registered', Version.fromString("8.0.0") requiresFeature 'es.index_mode_feature_flag_registered', Version.fromString("8.0.0")
@ -39,12 +40,13 @@ dependencies {
api project(":libs:elasticsearch-ssl-config") api project(":libs:elasticsearch-ssl-config")
// for parent/child testing // for parent/child testing
testImplementation project(':modules:parent-join') testImplementation project(':modules:parent-join')
testImplementation project(':modules:rest-root')
} }
restResources { restResources {
restApi { restApi {
include '_common', 'cluster', 'nodes', 'indices', 'index', 'get', 'search', 'mget', 'count', include '_common', 'cluster', 'nodes', 'indices', 'index', 'get', 'search', 'mget', 'count',
'update_by_query', 'delete_by_query', 'reindex_rethrottle', 'tasks', 'reindex', 'put_script', 'bulk' 'update_by_query', 'delete_by_query', 'reindex_rethrottle', 'tasks', 'reindex', 'put_script', 'bulk', 'info'
} }
} }

View file

@ -41,6 +41,7 @@ import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.repositories.RepositoriesService; import org.elasticsearch.repositories.RepositoriesService;
import org.elasticsearch.rest.RestHeaderDefinition; import org.elasticsearch.rest.RestHeaderDefinition;
import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.rest.root.MainRestPlugin;
import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.ScriptService;
import org.elasticsearch.tasks.Task; import org.elasticsearch.tasks.Task;
import org.elasticsearch.test.ESSingleNodeTestCase; import org.elasticsearch.test.ESSingleNodeTestCase;
@ -69,7 +70,12 @@ public class ReindexFromRemoteWithAuthTests extends ESSingleNodeTestCase {
@Override @Override
protected Collection<Class<? extends Plugin>> getPlugins() { protected Collection<Class<? extends Plugin>> getPlugins() {
return Arrays.asList(Netty4Plugin.class, ReindexFromRemoteWithAuthTests.TestPlugin.class, ReindexPlugin.class); return Arrays.asList(
Netty4Plugin.class,
ReindexFromRemoteWithAuthTests.TestPlugin.class,
ReindexPlugin.class,
MainRestPlugin.class
);
} }
@Override @Override

View file

@ -33,6 +33,7 @@ import org.elasticsearch.index.reindex.RemoteInfo;
import org.elasticsearch.index.reindex.UpdateByQueryAction; import org.elasticsearch.index.reindex.UpdateByQueryAction;
import org.elasticsearch.index.reindex.UpdateByQueryRequestBuilder; import org.elasticsearch.index.reindex.UpdateByQueryRequestBuilder;
import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.rest.root.MainRestPlugin;
import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.netty4.Netty4Plugin; import org.elasticsearch.transport.netty4.Netty4Plugin;
@ -70,7 +71,7 @@ public class RetryTests extends ESIntegTestCase {
@Override @Override
protected Collection<Class<? extends Plugin>> nodePlugins() { protected Collection<Class<? extends Plugin>> nodePlugins() {
return Arrays.asList(ReindexPlugin.class, Netty4Plugin.class); return Arrays.asList(ReindexPlugin.class, Netty4Plugin.class, MainRestPlugin.class);
} }
/** /**

View file

@ -0,0 +1,28 @@
import org.elasticsearch.gradle.internal.info.BuildParams
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
apply plugin: 'elasticsearch.internal-yaml-rest-test'
apply plugin: 'elasticsearch.yaml-rest-compat-test'
apply plugin: 'elasticsearch.internal-cluster-test'
esplugin {
description 'Adds HEAD and GET / endpoint to Elasticsearch'
classname 'org.elasticsearch.rest.root.MainRestPlugin'
}
restResources {
restApi {
include '_common','info', 'ping'
}
}
artifacts {
restTests(new File(projectDir, "src/yamlRestTest/resources/rest-api-spec/test"))
}

View file

@ -0,0 +1,15 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
module org.elasticsearch.rest.root {
requires org.elasticsearch.server;
requires org.elasticsearch.xcontent;
requires org.apache.lucene.core;
exports org.elasticsearch.rest.root;
}

View file

@ -6,7 +6,7 @@
* Side Public License, v 1. * Side Public License, v 1.
*/ */
package org.elasticsearch.action.main; package org.elasticsearch.rest.root;
import org.elasticsearch.action.ActionType; import org.elasticsearch.action.ActionType;

View file

@ -6,7 +6,7 @@
* Side Public License, v 1. * Side Public License, v 1.
*/ */
package org.elasticsearch.action.main; package org.elasticsearch.rest.root;
import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.ActionRequestValidationException;

View file

@ -6,7 +6,7 @@
* Side Public License, v 1. * Side Public License, v 1.
*/ */
package org.elasticsearch.action.main; package org.elasticsearch.rest.root;
import org.elasticsearch.Build; import org.elasticsearch.Build;
import org.elasticsearch.Version; import org.elasticsearch.Version;

View file

@ -0,0 +1,45 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.rest.root;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.IndexScopedSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.plugins.ActionPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestHandler;
import java.util.List;
import java.util.function.Supplier;
public class MainRestPlugin extends Plugin implements ActionPlugin {
@Override
public List<RestHandler> getRestHandlers(
Settings settings,
RestController restController,
ClusterSettings clusterSettings,
IndexScopedSettings indexScopedSettings,
SettingsFilter settingsFilter,
IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<DiscoveryNodes> nodesInCluster
) {
return List.of(new RestMainAction());
}
@Override
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
return List.of(new ActionHandler<>(MainAction.INSTANCE, TransportMainAction.class));
}
}

View file

@ -6,11 +6,8 @@
* Side Public License, v 1. * Side Public License, v 1.
*/ */
package org.elasticsearch.rest.action; package org.elasticsearch.rest.root;
import org.elasticsearch.action.main.MainAction;
import org.elasticsearch.action.main.MainRequest;
import org.elasticsearch.action.main.MainResponse;
import org.elasticsearch.client.internal.node.NodeClient; import org.elasticsearch.client.internal.node.NodeClient;
import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequest;
@ -18,6 +15,7 @@ import org.elasticsearch.rest.RestResponse;
import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.rest.Scope; import org.elasticsearch.rest.Scope;
import org.elasticsearch.rest.ServerlessScope; import org.elasticsearch.rest.ServerlessScope;
import org.elasticsearch.rest.action.RestBuilderListener;
import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;

View file

@ -6,7 +6,7 @@
* Side Public License, v 1. * Side Public License, v 1.
*/ */
package org.elasticsearch.action.main; package org.elasticsearch.rest.root;
import org.elasticsearch.Build; import org.elasticsearch.Build;
import org.elasticsearch.Version; import org.elasticsearch.Version;

View file

@ -6,7 +6,7 @@
* Side Public License, v 1. * Side Public License, v 1.
*/ */
package org.elasticsearch.action.main; package org.elasticsearch.rest.root;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.ActionFilters;
@ -86,7 +86,7 @@ public class MainActionTests extends ESTestCase {
); );
TransportMainAction action = new TransportMainAction(settings, transportService, mock(ActionFilters.class), clusterService); TransportMainAction action = new TransportMainAction(settings, transportService, mock(ActionFilters.class), clusterService);
AtomicReference<MainResponse> responseRef = new AtomicReference<>(); AtomicReference<MainResponse> responseRef = new AtomicReference<>();
action.doExecute(mock(Task.class), new MainRequest(), new ActionListener<MainResponse>() { action.doExecute(mock(Task.class), new MainRequest(), new ActionListener<>() {
@Override @Override
public void onResponse(MainResponse mainResponse) { public void onResponse(MainResponse mainResponse) {
responseRef.set(mainResponse); responseRef.set(mainResponse);

View file

@ -6,7 +6,7 @@
* Side Public License, v 1. * Side Public License, v 1.
*/ */
package org.elasticsearch.action.main; package org.elasticsearch.rest.root;
import org.elasticsearch.Build; import org.elasticsearch.Build;
import org.elasticsearch.Version; import org.elasticsearch.Version;

View file

@ -6,11 +6,10 @@
* Side Public License, v 1. * Side Public License, v 1.
*/ */
package org.elasticsearch.rest.action; package org.elasticsearch.rest.root;
import org.elasticsearch.Build; import org.elasticsearch.Build;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.action.main.MainResponse;
import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequest;

View file

@ -0,0 +1,37 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.rest.root;
import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;
import org.junit.ClassRule;
/** Runs yaml rest tests */
public class RestMainClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
@ClassRule
public static ElasticsearchCluster cluster = ElasticsearchCluster.local().module("rest-root").build();
public RestMainClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) {
super(testCandidate);
}
@ParametersFactory
public static Iterable<Object[]> parameters() throws Exception {
return ESClientYamlSuiteTestCase.createParameters();
}
@Override
protected String getTestRestCluster() {
return cluster.getHttpAddresses();
}
}

View file

@ -45,11 +45,13 @@ dependencies {
api "io.netty:netty-resolver:${versions.netty}" api "io.netty:netty-resolver:${versions.netty}"
api "io.netty:netty-transport:${versions.netty}" api "io.netty:netty-transport:${versions.netty}"
api "io.netty:netty-transport-native-unix-common:${versions.netty}" api "io.netty:netty-transport-native-unix-common:${versions.netty}"
testImplementation project(':modules:rest-root')
} }
restResources { restResources {
restApi { restApi {
include '_common', 'cluster', 'nodes' include '_common', 'cluster', 'nodes', 'ping'
} }
} }
@ -90,6 +92,10 @@ tasks.named("internalClusterTest").configure {
systemProperty 'es.insecure_network_trace_enabled', 'true' systemProperty 'es.insecure_network_trace_enabled', 'true'
} }
testClusters.configureEach {
module ':modules:rest-root'
}
tasks.named("check").configure { tasks.named("check").configure {
dependsOn(pooledTest, pooledJavaRestTest, pooledInternalClusterTest) dependsOn(pooledTest, pooledJavaRestTest, pooledInternalClusterTest)
} }

View file

@ -11,8 +11,10 @@ apply plugin: 'elasticsearch.legacy-java-rest-test'
dependencies { dependencies {
javaRestTestImplementation "com.fasterxml.jackson.core:jackson-databind:${versions.jackson}" javaRestTestImplementation "com.fasterxml.jackson.core:jackson-databind:${versions.jackson}"
javaRestTestImplementation project(':modules:rest-root')
} }
testClusters.configureEach { testClusters.configureEach {
module ':modules:rest-root'
setting 'xpack.security.enabled', 'false' setting 'xpack.security.enabled', 'false'
} }

View file

@ -10,6 +10,7 @@ package org.elasticsearch.http;
import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.rest.root.MainRestPlugin;
import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.transport.netty4.Netty4Plugin; import org.elasticsearch.transport.netty4.Netty4Plugin;
@ -34,7 +35,7 @@ public abstract class HttpSmokeTestCase extends ESIntegTestCase {
@Override @Override
protected Collection<Class<? extends Plugin>> nodePlugins() { protected Collection<Class<? extends Plugin>> nodePlugins() {
return List.of(getTestTransportPlugin()); return List.of(getTestTransportPlugin(), MainRestPlugin.class);
} }
@Override @Override

View file

@ -14,6 +14,10 @@ apply plugin: 'elasticsearch.internal-testclusters'
apply plugin: 'elasticsearch.standalone-rest-test' apply plugin: 'elasticsearch.standalone-rest-test'
apply plugin: 'elasticsearch.bwc-test' apply plugin: 'elasticsearch.bwc-test'
dependencies {
testImplementation project(':modules:rest-root')
}
BuildParams.bwcVersions.withIndexCompatible { bwcVersion, baseName -> BuildParams.bwcVersions.withIndexCompatible { bwcVersion, baseName ->
def baseCluster = testClusters.register(baseName) { def baseCluster = testClusters.register(baseName) {
version = bwcVersion.toString() version = bwcVersion.toString()

View file

@ -35,6 +35,7 @@ artifacts {
dependencies { dependencies {
clusterModules project(":modules:mapper-extras") clusterModules project(":modules:mapper-extras")
clusterModules project(":modules:rest-root")
} }
tasks.named("yamlRestTestV7CompatTransform").configure { task -> tasks.named("yamlRestTestV7CompatTransform").configure { task ->

View file

@ -28,6 +28,7 @@ public class ClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
@ClassRule @ClassRule
public static ElasticsearchCluster cluster = ElasticsearchCluster.local() public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
.module("mapper-extras") .module("mapper-extras")
.module("rest-root")
.feature(FeatureFlag.TIME_SERIES_MODE) .feature(FeatureFlag.TIME_SERIES_MODE)
.feature(FeatureFlag.DLM_ENABLED) .feature(FeatureFlag.DLM_ENABLED)
.build(); .build();

View file

@ -8,9 +8,9 @@
package org.elasticsearch.cluster.coordination; package org.elasticsearch.cluster.coordination;
import org.elasticsearch.action.main.MainAction; import org.elasticsearch.action.admin.cluster.stats.ClusterStatsAction;
import org.elasticsearch.action.main.MainRequest; import org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequest;
import org.elasticsearch.action.main.MainResponse; import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse;
import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.cluster.service.ClusterService;
@ -40,12 +40,12 @@ public class InitialClusterStateIT extends ESIntegTestCase {
assertEquals(expectCommitted, metadata.clusterUUIDCommitted()); assertEquals(expectCommitted, metadata.clusterUUIDCommitted());
assertEquals(expectedValue, metadata.clusterUUID()); assertEquals(expectedValue, metadata.clusterUUID());
final MainResponse mainResponse = PlainActionFuture.get( final ClusterStatsResponse response = PlainActionFuture.get(
fut -> client(nodeName).execute(MainAction.INSTANCE, new MainRequest(), fut), fut -> client(nodeName).execute(ClusterStatsAction.INSTANCE, new ClusterStatsRequest(), fut),
10, 10,
TimeUnit.SECONDS TimeUnit.SECONDS
); );
assertEquals(expectedValue, mainResponse.getClusterUuid()); assertEquals(expectedValue, response.getClusterUUID());
} }
} }

View file

@ -134,7 +134,6 @@ module org.elasticsearch.server {
exports org.elasticsearch.action.get; exports org.elasticsearch.action.get;
exports org.elasticsearch.action.index; exports org.elasticsearch.action.index;
exports org.elasticsearch.action.ingest; exports org.elasticsearch.action.ingest;
exports org.elasticsearch.action.main;
exports org.elasticsearch.action.resync; exports org.elasticsearch.action.resync;
exports org.elasticsearch.action.search; exports org.elasticsearch.action.search;
exports org.elasticsearch.action.support; exports org.elasticsearch.action.support;

View file

@ -229,8 +229,6 @@ import org.elasticsearch.action.ingest.PutPipelineAction;
import org.elasticsearch.action.ingest.PutPipelineTransportAction; import org.elasticsearch.action.ingest.PutPipelineTransportAction;
import org.elasticsearch.action.ingest.SimulatePipelineAction; import org.elasticsearch.action.ingest.SimulatePipelineAction;
import org.elasticsearch.action.ingest.SimulatePipelineTransportAction; import org.elasticsearch.action.ingest.SimulatePipelineTransportAction;
import org.elasticsearch.action.main.MainAction;
import org.elasticsearch.action.main.TransportMainAction;
import org.elasticsearch.action.search.ClearScrollAction; import org.elasticsearch.action.search.ClearScrollAction;
import org.elasticsearch.action.search.ClosePointInTimeAction; import org.elasticsearch.action.search.ClosePointInTimeAction;
import org.elasticsearch.action.search.MultiSearchAction; import org.elasticsearch.action.search.MultiSearchAction;
@ -299,7 +297,6 @@ import org.elasticsearch.rest.RestHandler;
import org.elasticsearch.rest.RestHeaderDefinition; import org.elasticsearch.rest.RestHeaderDefinition;
import org.elasticsearch.rest.RestUtils; import org.elasticsearch.rest.RestUtils;
import org.elasticsearch.rest.action.RestFieldCapabilitiesAction; import org.elasticsearch.rest.action.RestFieldCapabilitiesAction;
import org.elasticsearch.rest.action.RestMainAction;
import org.elasticsearch.rest.action.admin.cluster.RestAddVotingConfigExclusionAction; import org.elasticsearch.rest.action.admin.cluster.RestAddVotingConfigExclusionAction;
import org.elasticsearch.rest.action.admin.cluster.RestCancelTasksAction; import org.elasticsearch.rest.action.admin.cluster.RestCancelTasksAction;
import org.elasticsearch.rest.action.admin.cluster.RestCleanupRepositoryAction; import org.elasticsearch.rest.action.admin.cluster.RestCleanupRepositoryAction;
@ -608,7 +605,6 @@ public class ActionModule extends AbstractModule {
} }
ActionRegistry actions = new ActionRegistry(); ActionRegistry actions = new ActionRegistry();
actions.register(MainAction.INSTANCE, TransportMainAction.class);
actions.register(NodesInfoAction.INSTANCE, TransportNodesInfoAction.class); actions.register(NodesInfoAction.INSTANCE, TransportNodesInfoAction.class);
actions.register(RemoteInfoAction.INSTANCE, TransportRemoteInfoAction.class); actions.register(RemoteInfoAction.INSTANCE, TransportRemoteInfoAction.class);
actions.register(RemoteClusterNodesAction.INSTANCE, RemoteClusterNodesAction.TransportAction.class); actions.register(RemoteClusterNodesAction.INSTANCE, RemoteClusterNodesAction.TransportAction.class);
@ -798,7 +794,6 @@ public class ActionModule extends AbstractModule {
}; };
registerHandler.accept(new RestAddVotingConfigExclusionAction()); registerHandler.accept(new RestAddVotingConfigExclusionAction());
registerHandler.accept(new RestClearVotingConfigExclusionsAction()); registerHandler.accept(new RestClearVotingConfigExclusionsAction());
registerHandler.accept(new RestMainAction());
registerHandler.accept(new RestNodesInfoAction(settingsFilter)); registerHandler.accept(new RestNodesInfoAction(settingsFilter));
registerHandler.accept(new RestRemoteClusterInfoAction()); registerHandler.accept(new RestRemoteClusterInfoAction());
registerHandler.accept(new RestNodesStatsAction()); registerHandler.accept(new RestNodesStatsAction());

View file

@ -8,8 +8,8 @@
package org.elasticsearch.action; package org.elasticsearch.action;
import org.elasticsearch.action.main.MainAction; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoAction;
import org.elasticsearch.action.main.TransportMainAction; import org.elasticsearch.action.admin.cluster.node.info.TransportNodesInfoAction;
import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.TransportAction; import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.client.internal.node.NodeClient; import org.elasticsearch.client.internal.node.NodeClient;
@ -30,7 +30,7 @@ import org.elasticsearch.rest.RestChannel;
import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestHandler; import org.elasticsearch.rest.RestHandler;
import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestMainAction; import org.elasticsearch.rest.action.admin.cluster.RestNodesInfoAction;
import org.elasticsearch.tasks.Task; import org.elasticsearch.tasks.Task;
import org.elasticsearch.tasks.TaskManager; import org.elasticsearch.tasks.TaskManager;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
@ -56,7 +56,7 @@ public class ActionModuleTests extends ESTestCase {
public void testSetupActionsContainsKnownBuiltin() { public void testSetupActionsContainsKnownBuiltin() {
assertThat( assertThat(
ActionModule.setupActions(emptyList()), ActionModule.setupActions(emptyList()),
hasEntry(MainAction.INSTANCE.name(), new ActionHandler<>(MainAction.INSTANCE, TransportMainAction.class)) hasEntry(NodesInfoAction.INSTANCE.name(), new ActionHandler<>(NodesInfoAction.INSTANCE, TransportNodesInfoAction.class))
); );
} }
@ -64,11 +64,11 @@ public class ActionModuleTests extends ESTestCase {
ActionPlugin dupsMainAction = new ActionPlugin() { ActionPlugin dupsMainAction = new ActionPlugin() {
@Override @Override
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() { public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
return singletonList(new ActionHandler<>(MainAction.INSTANCE, TransportMainAction.class)); return singletonList(new ActionHandler<>(NodesInfoAction.INSTANCE, TransportNodesInfoAction.class));
} }
}; };
Exception e = expectThrows(IllegalArgumentException.class, () -> ActionModule.setupActions(singletonList(dupsMainAction))); Exception e = expectThrows(IllegalArgumentException.class, () -> ActionModule.setupActions(singletonList(dupsMainAction)));
assertEquals("action for name [" + MainAction.NAME + "] already registered", e.getMessage()); assertEquals("action for name [" + NodesInfoAction.NAME + "] already registered", e.getMessage());
} }
public void testPluginCanRegisterAction() { public void testPluginCanRegisterAction() {
@ -133,11 +133,11 @@ public class ActionModuleTests extends ESTestCase {
@Override @Override
public List<Route> routes() { public List<Route> routes() {
return List.of(new Route(GET, "/")); return List.of(new Route(GET, "/_nodes"));
} }
}) })
); );
assertThat(e.getMessage(), startsWith("Cannot replace existing handler for [/] for method: GET")); assertThat(e.getMessage(), startsWith("Cannot replace existing handler for [/_nodes] for method: GET"));
} }
public void testPluginCantOverwriteBuiltinRestHandler() throws IOException { public void testPluginCantOverwriteBuiltinRestHandler() throws IOException {
@ -152,7 +152,7 @@ public class ActionModuleTests extends ESTestCase {
IndexNameExpressionResolver indexNameExpressionResolver, IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<DiscoveryNodes> nodesInCluster Supplier<DiscoveryNodes> nodesInCluster
) { ) {
return singletonList(new RestMainAction() { return singletonList(new RestNodesInfoAction(new SettingsFilter(emptyList())) {
@Override @Override
public String getName() { public String getName() {
@ -183,7 +183,7 @@ public class ActionModuleTests extends ESTestCase {
List.of() List.of()
); );
Exception e = expectThrows(IllegalArgumentException.class, () -> actionModule.initRestHandlers(null)); Exception e = expectThrows(IllegalArgumentException.class, () -> actionModule.initRestHandlers(null));
assertThat(e.getMessage(), startsWith("Cannot replace existing handler for [/] for method: GET")); assertThat(e.getMessage(), startsWith("Cannot replace existing handler for [/_nodes] for method: GET"));
} finally { } finally {
threadPool.shutdown(); threadPool.shutdown();
} }

View file

@ -54,6 +54,7 @@ dependencies {
testImplementation project(path: ':modules:parent-join') testImplementation project(path: ':modules:parent-join')
testImplementation project(path: ':modules:lang-mustache') testImplementation project(path: ':modules:lang-mustache')
testImplementation project(path: ':modules:analysis-common') testImplementation project(path: ':modules:analysis-common')
testImplementation project(path: ':modules:rest-root')
testImplementation project(":client:rest-high-level") testImplementation project(":client:rest-high-level")
// Needed for Fips140ProviderVerificationTests // Needed for Fips140ProviderVerificationTests
testCompileOnly('org.bouncycastle:bc-fips:1.0.2') testCompileOnly('org.bouncycastle:bc-fips:1.0.2')

View file

@ -52,7 +52,6 @@ import org.elasticsearch.action.ingest.DeletePipelineAction;
import org.elasticsearch.action.ingest.GetPipelineAction; import org.elasticsearch.action.ingest.GetPipelineAction;
import org.elasticsearch.action.ingest.PutPipelineAction; import org.elasticsearch.action.ingest.PutPipelineAction;
import org.elasticsearch.action.ingest.SimulatePipelineAction; import org.elasticsearch.action.ingest.SimulatePipelineAction;
import org.elasticsearch.action.main.MainAction;
import org.elasticsearch.action.search.MultiSearchAction; import org.elasticsearch.action.search.MultiSearchAction;
import org.elasticsearch.action.search.SearchAction; import org.elasticsearch.action.search.SearchAction;
import org.elasticsearch.action.support.WriteRequest; import org.elasticsearch.action.support.WriteRequest;
@ -63,6 +62,7 @@ import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.common.util.set.Sets;
import org.elasticsearch.rest.root.MainAction;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.transport.TcpTransport; import org.elasticsearch.transport.TcpTransport;
import org.elasticsearch.transport.TransportRequest; import org.elasticsearch.transport.TransportRequest;

View file

@ -26,6 +26,7 @@ dependencies {
testImplementation project(path: ':modules:analysis-common') testImplementation project(path: ':modules:analysis-common')
testImplementation project(path: ':modules:reindex') testImplementation project(path: ':modules:reindex')
testImplementation project(':modules:data-streams') testImplementation project(':modules:data-streams')
testImplementation project(':modules:rest-root')
testImplementation project(":client:rest-high-level") testImplementation project(":client:rest-high-level")
testImplementation(testArtifact(project(xpackModule('core')))) testImplementation(testArtifact(project(xpackModule('core'))))

View file

@ -6,6 +6,7 @@ dependencies {
javaRestTestImplementation project(':client:rest-high-level') javaRestTestImplementation project(':client:rest-high-level')
javaRestTestImplementation project(':x-pack:plugin:security') javaRestTestImplementation project(':x-pack:plugin:security')
clusterModules(project(":modules:analysis-common")) clusterModules(project(":modules:analysis-common"))
clusterModules(project(":modules:rest-root"))
} }
testArtifacts { testArtifacts {

View file

@ -214,6 +214,7 @@ public class ServiceAccountIT extends ESRestTestCase {
public static ElasticsearchCluster cluster = ElasticsearchCluster.local() public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
.nodes(2) .nodes(2)
.module("analysis-common") .module("analysis-common")
.module("rest-root")
.setting("xpack.license.self_generated.type", "trial") .setting("xpack.license.self_generated.type", "trial")
.setting("xpack.security.enabled", "true") .setting("xpack.security.enabled", "true")
.setting("xpack.security.authc.token.enabled", "true") .setting("xpack.security.authc.token.enabled", "true")

View file

@ -11,6 +11,8 @@ import org.elasticsearch.ElasticsearchSecurityException;
import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthAction; import org.elasticsearch.action.admin.cluster.health.ClusterHealthAction;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoAction;
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexAction; import org.elasticsearch.action.admin.indices.create.CreateIndexAction;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.get.GetAction; import org.elasticsearch.action.get.GetAction;
@ -18,8 +20,6 @@ import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.ingest.GetPipelineAction; import org.elasticsearch.action.ingest.GetPipelineAction;
import org.elasticsearch.action.ingest.GetPipelineRequest; import org.elasticsearch.action.ingest.GetPipelineRequest;
import org.elasticsearch.action.main.MainAction;
import org.elasticsearch.action.main.MainRequest;
import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.internal.Client; import org.elasticsearch.client.internal.Client;
@ -174,7 +174,7 @@ public class ApiKeySingleNodeTests extends SecuritySingleNodeTestCase {
final ElasticsearchSecurityException e1 = expectThrows( final ElasticsearchSecurityException e1 = expectThrows(
ElasticsearchSecurityException.class, ElasticsearchSecurityException.class,
() -> client().filterWithHeader(Map.of("Authorization", "ApiKey " + base64ApiKeyKeyValue)) () -> client().filterWithHeader(Map.of("Authorization", "ApiKey " + base64ApiKeyKeyValue))
.execute(MainAction.INSTANCE, new MainRequest()) .execute(NodesInfoAction.INSTANCE, new NodesInfoRequest())
.actionGet() .actionGet()
); );
assertThat(e1.status().getStatus(), equalTo(403)); assertThat(e1.status().getStatus(), equalTo(403));

View file

@ -19,6 +19,7 @@ import org.elasticsearch.env.Environment;
import org.elasticsearch.index.mapper.extras.MapperExtrasPlugin; import org.elasticsearch.index.mapper.extras.MapperExtrasPlugin;
import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.reindex.ReindexPlugin; import org.elasticsearch.reindex.ReindexPlugin;
import org.elasticsearch.rest.root.MainRestPlugin;
import org.elasticsearch.test.ESIntegTestCase.Scope; import org.elasticsearch.test.ESIntegTestCase.Scope;
import org.elasticsearch.transport.netty4.Netty4Plugin; import org.elasticsearch.transport.netty4.Netty4Plugin;
import org.elasticsearch.xpack.core.XPackSettings; import org.elasticsearch.xpack.core.XPackSettings;
@ -186,7 +187,8 @@ public class SecuritySettingsSource extends NodeConfigurationSource {
ReindexPlugin.class, ReindexPlugin.class,
CommonAnalysisPlugin.class, CommonAnalysisPlugin.class,
InternalSettingsPlugin.class, InternalSettingsPlugin.class,
MapperExtrasPlugin.class MapperExtrasPlugin.class,
MainRestPlugin.class
); );
} }

View file

@ -14,6 +14,7 @@ dependencies {
api project(':x-pack:plugin:sql:sql-client') api project(':x-pack:plugin:sql:sql-client')
testImplementation project(":test:framework") testImplementation project(":test:framework")
testImplementation(testArtifact(project(xpackModule('core')))) testImplementation(testArtifact(project(xpackModule('core'))))
testImplementation project(':modules:rest-root')
} }
tasks.named("compileJava").configure { tasks.named("compileJava").configure {

View file

@ -8,8 +8,8 @@
package org.elasticsearch.xpack.sql.jdbc; package org.elasticsearch.xpack.sql.jdbc;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.action.main.MainResponse;
import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.rest.root.MainResponse;
import org.elasticsearch.test.VersionUtils; import org.elasticsearch.test.VersionUtils;
import org.elasticsearch.test.http.MockResponse; import org.elasticsearch.test.http.MockResponse;
import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xcontent.XContentType;

View file

@ -9,8 +9,8 @@ package org.elasticsearch.xpack.sql.jdbc;
import org.elasticsearch.Build; import org.elasticsearch.Build;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.action.main.MainResponse;
import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.rest.root.MainResponse;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.http.MockWebServer; import org.elasticsearch.test.http.MockWebServer;
import org.junit.After; import org.junit.After;

View file

@ -102,6 +102,8 @@ subprojects {
javaRestTestRuntimeOnly project(path: xpackModule('spatial')) javaRestTestRuntimeOnly project(path: xpackModule('spatial'))
javaRestTestRuntimeOnly project(path: ':modules:legacy-geo') javaRestTestRuntimeOnly project(path: ':modules:legacy-geo')
javaRestTestRuntimeOnly project(path: ':modules:rest-root')
javaRestTestRuntimeOnly "org.slf4j:slf4j-api:1.7.25" javaRestTestRuntimeOnly "org.slf4j:slf4j-api:1.7.25"
} }
} }

View file

@ -11,6 +11,8 @@ dependencies {
javaRestTestImplementation(testArtifact(project(xpackModule('core')))) javaRestTestImplementation(testArtifact(project(xpackModule('core'))))
javaRestTestImplementation(testArtifact(project(":qa:full-cluster-restart"), "javaRestTest")) javaRestTestImplementation(testArtifact(project(":qa:full-cluster-restart"), "javaRestTest"))
javaRestTestImplementation project(':x-pack:qa') javaRestTestImplementation project(':x-pack:qa')
javaRestTestImplementation project(':modules:rest-root')
} }
BuildParams.bwcVersions.withIndexCompatible { bwcVersion, baseName -> BuildParams.bwcVersions.withIndexCompatible { bwcVersion, baseName ->

View file

@ -15,6 +15,8 @@ dependencies {
javaRestTestImplementation project(':client:rest-high-level') javaRestTestImplementation project(':client:rest-high-level')
// let the javaRestTest see the classpath of main // let the javaRestTest see the classpath of main
javaRestTestImplementation project.sourceSets.main.runtimeClasspath javaRestTestImplementation project.sourceSets.main.runtimeClasspath
javaRestTestImplementation project(':modules:rest-root')
} }
testClusters.configureEach { testClusters.configureEach {