From fd9c419525960cd9e4416814d81229659ef62139 Mon Sep 17 00:00:00 2001 From: pgomulka Date: Tue, 21 Jul 2020 18:28:53 +0200 Subject: [PATCH 1/2] refactor AbstractHttpServerTransport to use RestRequestFactory --- .../netty4/Netty4HttpServerTransport.java | 6 ++- .../elasticsearch/transport/Netty4Plugin.java | 6 ++- .../http/netty4/Netty4BadRequestTests.java | 2 +- .../Netty4HttpServerPipeliningTests.java | 3 +- .../Netty4HttpServerTransportTests.java | 12 +++--- .../http/nio/NioHttpServerTransport.java | 7 +++- .../transport/nio/NioTransportPlugin.java | 6 ++- .../http/nio/NioHttpServerTransportTests.java | 12 +++--- .../common/network/NetworkModule.java | 7 +++- .../http/AbstractHttpServerTransport.java | 8 +++- .../java/org/elasticsearch/node/Node.java | 22 ++++++++++- .../elasticsearch/plugins/NetworkPlugin.java | 3 +- .../plugins/RestRequestPlugin.java | 28 ++++++++++++++ .../org/elasticsearch/rest/RestRequest.java | 10 +++++ .../rest/RestRequestFactory.java | 28 ++++++++++++++ .../common/network/NetworkModuleTests.java | 10 +++-- .../AbstractHttpServerTransportTests.java | 4 +- .../plugin/compat-rest-request/build.gradle | 17 +++++++++ .../compat/CompatRestRequestPlugin.java | 37 +++++++++++++++++++ .../core/LocalStateCompositeXPackPlugin.java | 6 ++- .../xpack/security/Security.java | 8 ++-- .../SecurityNetty4HttpServerTransport.java | 7 +++- .../nio/SecurityNioHttpServerTransport.java | 6 ++- ...ecurityNetty4HttpServerTransportTests.java | 15 ++++---- .../SecurityNioHttpServerTransportTests.java | 15 ++++---- 25 files changed, 228 insertions(+), 57 deletions(-) create mode 100644 server/src/main/java/org/elasticsearch/plugins/RestRequestPlugin.java create mode 100644 server/src/main/java/org/elasticsearch/rest/RestRequestFactory.java create mode 100644 x-pack/plugin/compat-rest-request/build.gradle create mode 100644 x-pack/plugin/compat-rest-request/src/main/java/org/elasticsearch/compat/CompatRestRequestPlugin.java diff --git a/modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpServerTransport.java b/modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpServerTransport.java index 137ff735141d2..63a4e3b97f6e7 100644 --- a/modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpServerTransport.java +++ b/modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpServerTransport.java @@ -60,6 +60,8 @@ import org.elasticsearch.http.HttpReadTimeoutException; import org.elasticsearch.http.HttpServerChannel; import org.elasticsearch.http.netty4.cors.Netty4CorsHandler; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.RestRequestFactory; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.SharedGroupFactory; import org.elasticsearch.transport.NettyAllocator; @@ -147,8 +149,8 @@ public class Netty4HttpServerTransport extends AbstractHttpServerTransport { public Netty4HttpServerTransport(Settings settings, NetworkService networkService, BigArrays bigArrays, ThreadPool threadPool, NamedXContentRegistry xContentRegistry, Dispatcher dispatcher, ClusterSettings clusterSettings, - SharedGroupFactory sharedGroupFactory) { - super(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings); + SharedGroupFactory sharedGroupFactory, RestRequestFactory restRequestFactory) { + super(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings, restRequestFactory); Netty4Utils.setAvailableProcessors(EsExecutors.NODE_PROCESSORS_SETTING.get(settings)); this.sharedGroupFactory = sharedGroupFactory; diff --git a/modules/transport-netty4/src/main/java/org/elasticsearch/transport/Netty4Plugin.java b/modules/transport-netty4/src/main/java/org/elasticsearch/transport/Netty4Plugin.java index 1428eb7b17113..37b4c75ee3083 100644 --- a/modules/transport-netty4/src/main/java/org/elasticsearch/transport/Netty4Plugin.java +++ b/modules/transport-netty4/src/main/java/org/elasticsearch/transport/Netty4Plugin.java @@ -35,6 +35,8 @@ import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.plugins.NetworkPlugin; import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.RestRequestFactory; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.netty4.Netty4Transport; @@ -90,10 +92,10 @@ public Map> getHttpTransports(Settings set NamedXContentRegistry xContentRegistry, NetworkService networkService, HttpServerTransport.Dispatcher dispatcher, - ClusterSettings clusterSettings) { + ClusterSettings clusterSettings, RestRequestFactory restRequestFactory) { return Collections.singletonMap(NETTY_HTTP_TRANSPORT_NAME, () -> new Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, - clusterSettings, getSharedGroupFactory(settings))); + clusterSettings, getSharedGroupFactory(settings), restRequestFactory)); } private SharedGroupFactory getSharedGroupFactory(Settings settings) { diff --git a/modules/transport-netty4/src/test/java/org/elasticsearch/http/netty4/Netty4BadRequestTests.java b/modules/transport-netty4/src/test/java/org/elasticsearch/http/netty4/Netty4BadRequestTests.java index abd918f706bc7..10078d0d9c07e 100644 --- a/modules/transport-netty4/src/test/java/org/elasticsearch/http/netty4/Netty4BadRequestTests.java +++ b/modules/transport-netty4/src/test/java/org/elasticsearch/http/netty4/Netty4BadRequestTests.java @@ -91,7 +91,7 @@ public void dispatchBadRequest(RestChannel channel, ThreadContext threadContext, Settings settings = Settings.builder().put(HttpTransportSettings.SETTING_HTTP_PORT.getKey(), getPortRange()).build(); try (HttpServerTransport httpServerTransport = new Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry(), dispatcher, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), - new SharedGroupFactory(Settings.EMPTY))) { + new SharedGroupFactory(Settings.EMPTY), RestRequest::request)) { httpServerTransport.start(); final TransportAddress transportAddress = randomFrom(httpServerTransport.boundAddress().boundAddresses()); diff --git a/modules/transport-netty4/src/test/java/org/elasticsearch/http/netty4/Netty4HttpServerPipeliningTests.java b/modules/transport-netty4/src/test/java/org/elasticsearch/http/netty4/Netty4HttpServerPipeliningTests.java index a873293ab5b9f..032db84b90bc8 100644 --- a/modules/transport-netty4/src/test/java/org/elasticsearch/http/netty4/Netty4HttpServerPipeliningTests.java +++ b/modules/transport-netty4/src/test/java/org/elasticsearch/http/netty4/Netty4HttpServerPipeliningTests.java @@ -40,6 +40,7 @@ import org.elasticsearch.http.HttpServerTransport; import org.elasticsearch.http.NullDispatcher; import org.elasticsearch.indices.breaker.NoneCircuitBreakerService; +import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.TestThreadPool; @@ -120,7 +121,7 @@ class CustomNettyHttpServerTransport extends Netty4HttpServerTransport { Netty4HttpServerPipeliningTests.this.bigArrays, Netty4HttpServerPipeliningTests.this.threadPool, xContentRegistry(), new NullDispatcher(), new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), - new SharedGroupFactory(settings)); + new SharedGroupFactory(settings), RestRequest::request); } @Override diff --git a/modules/transport-netty4/src/test/java/org/elasticsearch/http/netty4/Netty4HttpServerTransportTests.java b/modules/transport-netty4/src/test/java/org/elasticsearch/http/netty4/Netty4HttpServerTransportTests.java index 8a4b5b9337b89..932be6e0ac925 100644 --- a/modules/transport-netty4/src/test/java/org/elasticsearch/http/netty4/Netty4HttpServerTransportTests.java +++ b/modules/transport-netty4/src/test/java/org/elasticsearch/http/netty4/Netty4HttpServerTransportTests.java @@ -170,7 +170,7 @@ public void dispatchBadRequest(RestChannel channel, ThreadContext threadContext, } }; try (Netty4HttpServerTransport transport = new Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, - xContentRegistry(), dispatcher, clusterSettings, new SharedGroupFactory(settings))) { + xContentRegistry(), dispatcher, clusterSettings, new SharedGroupFactory(settings), RestRequest::request)) { transport.start(); final TransportAddress remoteAddress = randomFrom(transport.boundAddress().boundAddresses()); try (Netty4HttpClient client = new Netty4HttpClient()) { @@ -204,7 +204,7 @@ public void dispatchBadRequest(RestChannel channel, ThreadContext threadContext, public void testBindUnavailableAddress() { Settings initialSettings = createSettings(); try (Netty4HttpServerTransport transport = new Netty4HttpServerTransport(initialSettings, networkService, bigArrays, threadPool, - xContentRegistry(), new NullDispatcher(), clusterSettings, new SharedGroupFactory(Settings.EMPTY))) { + xContentRegistry(), new NullDispatcher(), clusterSettings, new SharedGroupFactory(Settings.EMPTY), RestRequest::request)) { transport.start(); TransportAddress remoteAddress = randomFrom(transport.boundAddress().boundAddresses()); Settings settings = Settings.builder() @@ -212,7 +212,7 @@ public void testBindUnavailableAddress() { .put("network.host", remoteAddress.getAddress()) .build(); try (Netty4HttpServerTransport otherTransport = new Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, - xContentRegistry(), new NullDispatcher(), clusterSettings, new SharedGroupFactory(settings))) { + xContentRegistry(), new NullDispatcher(), clusterSettings, new SharedGroupFactory(settings), RestRequest::request)) { BindHttpException bindHttpException = expectThrows(BindHttpException.class, otherTransport::start); assertEquals( "Failed to bind to " + NetworkAddress.format(remoteAddress.address()), @@ -258,7 +258,7 @@ public void dispatchBadRequest(final RestChannel channel, final ThreadContext th try (Netty4HttpServerTransport transport = new Netty4HttpServerTransport( settings, networkService, bigArrays, threadPool, xContentRegistry(), dispatcher, clusterSettings, - new SharedGroupFactory(settings))) { + new SharedGroupFactory(settings), RestRequest::request)) { transport.start(); final TransportAddress remoteAddress = randomFrom(transport.boundAddress().boundAddresses()); @@ -308,7 +308,7 @@ public void dispatchBadRequest(final RestChannel channel, try (Netty4HttpServerTransport transport = new Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry(), dispatcher, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), - new SharedGroupFactory(settings))) { + new SharedGroupFactory(settings), RestRequest::request)) { transport.start(); final TransportAddress remoteAddress = randomFrom(transport.boundAddress().boundAddresses()); @@ -371,7 +371,7 @@ public void dispatchBadRequest(final RestChannel channel, NioEventLoopGroup group = new NioEventLoopGroup(); try (Netty4HttpServerTransport transport = new Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry(), dispatcher, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), - new SharedGroupFactory(settings))) { + new SharedGroupFactory(settings), RestRequest::request)) { transport.start(); final TransportAddress remoteAddress = randomFrom(transport.boundAddress().boundAddresses()); diff --git a/plugins/transport-nio/src/main/java/org/elasticsearch/http/nio/NioHttpServerTransport.java b/plugins/transport-nio/src/main/java/org/elasticsearch/http/nio/NioHttpServerTransport.java index 8594dae39f2a7..89f01b9118dee 100644 --- a/plugins/transport-nio/src/main/java/org/elasticsearch/http/nio/NioHttpServerTransport.java +++ b/plugins/transport-nio/src/main/java/org/elasticsearch/http/nio/NioHttpServerTransport.java @@ -43,6 +43,8 @@ import org.elasticsearch.nio.NioSocketChannel; import org.elasticsearch.nio.ServerChannelContext; import org.elasticsearch.nio.SocketChannelContext; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.RestRequestFactory; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.nio.NioGroupFactory; import org.elasticsearch.transport.nio.PageAllocator; @@ -86,8 +88,9 @@ public class NioHttpServerTransport extends AbstractHttpServerTransport { public NioHttpServerTransport(Settings settings, NetworkService networkService, BigArrays bigArrays, PageCacheRecycler pageCacheRecycler, ThreadPool threadPool, NamedXContentRegistry xContentRegistry, - Dispatcher dispatcher, NioGroupFactory nioGroupFactory, ClusterSettings clusterSettings) { - super(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings); + Dispatcher dispatcher, NioGroupFactory nioGroupFactory, ClusterSettings clusterSettings, + RestRequestFactory restRequestFactory) { + super(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings, restRequestFactory); this.pageAllocator = new PageAllocator(pageCacheRecycler); this.nioGroupFactory = nioGroupFactory; diff --git a/plugins/transport-nio/src/main/java/org/elasticsearch/transport/nio/NioTransportPlugin.java b/plugins/transport-nio/src/main/java/org/elasticsearch/transport/nio/NioTransportPlugin.java index 1da90e35ba7f4..1b1b8bcbe13c6 100644 --- a/plugins/transport-nio/src/main/java/org/elasticsearch/transport/nio/NioTransportPlugin.java +++ b/plugins/transport-nio/src/main/java/org/elasticsearch/transport/nio/NioTransportPlugin.java @@ -37,6 +37,8 @@ import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.plugins.NetworkPlugin; import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.RestRequestFactory; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.Transport; @@ -88,10 +90,10 @@ public Map> getHttpTransports(Settings set NamedXContentRegistry xContentRegistry, NetworkService networkService, HttpServerTransport.Dispatcher dispatcher, - ClusterSettings clusterSettings) { + ClusterSettings clusterSettings, RestRequestFactory restRequestFactory) { return Collections.singletonMap(NIO_HTTP_TRANSPORT_NAME, () -> new NioHttpServerTransport(settings, networkService, bigArrays, pageCacheRecycler, threadPool, xContentRegistry, - dispatcher, getNioGroupFactory(settings), clusterSettings)); + dispatcher, getNioGroupFactory(settings), clusterSettings, restRequestFactory)); } private synchronized NioGroupFactory getNioGroupFactory(Settings settings) { diff --git a/plugins/transport-nio/src/test/java/org/elasticsearch/http/nio/NioHttpServerTransportTests.java b/plugins/transport-nio/src/test/java/org/elasticsearch/http/nio/NioHttpServerTransportTests.java index b7b0cd7f0ed42..848cc4ea4dd68 100644 --- a/plugins/transport-nio/src/test/java/org/elasticsearch/http/nio/NioHttpServerTransportTests.java +++ b/plugins/transport-nio/src/test/java/org/elasticsearch/http/nio/NioHttpServerTransportTests.java @@ -162,7 +162,7 @@ public void dispatchBadRequest(RestChannel channel, ThreadContext threadContext, }; try (NioHttpServerTransport transport = new NioHttpServerTransport(settings, networkService, bigArrays, pageRecycler, threadPool, xContentRegistry(), dispatcher, new NioGroupFactory(settings, logger), - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS))) { + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), RestRequest::request)) { transport.start(); final TransportAddress remoteAddress = randomFrom(transport.boundAddress().boundAddresses()); try (NioHttpClient client = new NioHttpClient()) { @@ -197,7 +197,7 @@ public void testBindUnavailableAddress() { final Settings initialSettings = createSettings(); try (NioHttpServerTransport transport = new NioHttpServerTransport(initialSettings, networkService, bigArrays, pageRecycler, threadPool, xContentRegistry(), new NullDispatcher(), new NioGroupFactory(Settings.EMPTY, logger), - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS))) { + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), RestRequest::request)) { transport.start(); TransportAddress remoteAddress = randomFrom(transport.boundAddress().boundAddresses()); Settings settings = Settings.builder() @@ -206,7 +206,7 @@ threadPool, xContentRegistry(), new NullDispatcher(), new NioGroupFactory(Settin .build(); try (NioHttpServerTransport otherTransport = new NioHttpServerTransport(settings, networkService, bigArrays, pageRecycler, threadPool, xContentRegistry(), new NullDispatcher(), new NioGroupFactory(Settings.EMPTY, logger), - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS))) { + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), RestRequest::request)) { BindHttpException bindHttpException = expectThrows(BindHttpException.class, () -> otherTransport.start()); assertEquals( "Failed to bind to " + NetworkAddress.format(remoteAddress.address()), @@ -243,7 +243,7 @@ public void dispatchBadRequest(final RestChannel channel, try (NioHttpServerTransport transport = new NioHttpServerTransport(settings, networkService, bigArrays, pageRecycler, threadPool, xContentRegistry(), dispatcher, new NioGroupFactory(settings, logger), - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS))) { + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), RestRequest::request)) { transport.start(); final TransportAddress remoteAddress = randomFrom(transport.boundAddress().boundAddresses()); @@ -315,7 +315,7 @@ public void dispatchBadRequest(final RestChannel channel, final ThreadContext th try (NioHttpServerTransport transport = new NioHttpServerTransport(settings, networkService, bigArrays, pageRecycler, threadPool, xContentRegistry(), dispatcher, new NioGroupFactory(settings, logger), - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS))) { + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), RestRequest::request)) { transport.start(); final TransportAddress remoteAddress = randomFrom(transport.boundAddress().boundAddresses()); @@ -365,7 +365,7 @@ public void dispatchBadRequest(final RestChannel channel, try (NioHttpServerTransport transport = new NioHttpServerTransport(settings, networkService, bigArrays, pageRecycler, threadPool, xContentRegistry(), dispatcher, new NioGroupFactory(settings, logger), - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS))) { + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), RestRequest::request)) { transport.start(); final TransportAddress remoteAddress = randomFrom(transport.boundAddress().boundAddresses()); diff --git a/server/src/main/java/org/elasticsearch/common/network/NetworkModule.java b/server/src/main/java/org/elasticsearch/common/network/NetworkModule.java index 870d63ed5e57c..20792a0e25584 100644 --- a/server/src/main/java/org/elasticsearch/common/network/NetworkModule.java +++ b/server/src/main/java/org/elasticsearch/common/network/NetworkModule.java @@ -42,6 +42,8 @@ import org.elasticsearch.index.shard.PrimaryReplicaSyncer.ResyncTask; import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.plugins.NetworkPlugin; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.RestRequestFactory; import org.elasticsearch.tasks.RawTaskStatus; import org.elasticsearch.tasks.Task; import org.elasticsearch.threadpool.ThreadPool; @@ -106,6 +108,7 @@ public final class NetworkModule { /** * Creates a network module that custom networking classes can be plugged into. * @param settings The settings for the node + * @param restRequestFactory */ public NetworkModule(Settings settings, List plugins, ThreadPool threadPool, BigArrays bigArrays, @@ -114,11 +117,11 @@ public NetworkModule(Settings settings, List plugins, ThreadPool NamedWriteableRegistry namedWriteableRegistry, NamedXContentRegistry xContentRegistry, NetworkService networkService, HttpServerTransport.Dispatcher dispatcher, - ClusterSettings clusterSettings) { + ClusterSettings clusterSettings, RestRequestFactory restRequestFactory) { this.settings = settings; for (NetworkPlugin plugin : plugins) { Map> httpTransportFactory = plugin.getHttpTransports(settings, threadPool, bigArrays, - pageCacheRecycler, circuitBreakerService, xContentRegistry, networkService, dispatcher, clusterSettings); + pageCacheRecycler, circuitBreakerService, xContentRegistry, networkService, dispatcher, clusterSettings, restRequestFactory); for (Map.Entry> entry : httpTransportFactory.entrySet()) { registerHttpTransport(entry.getKey(), entry.getValue()); } diff --git a/server/src/main/java/org/elasticsearch/http/AbstractHttpServerTransport.java b/server/src/main/java/org/elasticsearch/http/AbstractHttpServerTransport.java index 204c9ad0365b6..8d2bdc5abf309 100644 --- a/server/src/main/java/org/elasticsearch/http/AbstractHttpServerTransport.java +++ b/server/src/main/java/org/elasticsearch/http/AbstractHttpServerTransport.java @@ -43,6 +43,7 @@ import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.rest.RestChannel; import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.RestRequestFactory; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.BindTransportException; @@ -75,6 +76,7 @@ public abstract class AbstractHttpServerTransport extends AbstractLifecycleCompo protected final ThreadPool threadPool; protected final Dispatcher dispatcher; protected final CorsHandler.Config corsConfig; + private RestRequestFactory restRequestFactory; private final NamedXContentRegistry xContentRegistry; protected final PortsRange port; @@ -90,7 +92,8 @@ public abstract class AbstractHttpServerTransport extends AbstractLifecycleCompo private final HttpTracer tracer; protected AbstractHttpServerTransport(Settings settings, NetworkService networkService, BigArrays bigArrays, ThreadPool threadPool, - NamedXContentRegistry xContentRegistry, Dispatcher dispatcher, ClusterSettings clusterSettings) { + NamedXContentRegistry xContentRegistry, Dispatcher dispatcher, ClusterSettings clusterSettings, + RestRequestFactory restRequestFactory) { this.settings = settings; this.networkService = networkService; this.bigArrays = bigArrays; @@ -99,6 +102,7 @@ protected AbstractHttpServerTransport(Settings settings, NetworkService networkS this.dispatcher = dispatcher; this.handlingSettings = HttpHandlingSettings.fromSettings(settings); this.corsConfig = CorsHandler.fromSettings(settings); + this.restRequestFactory = restRequestFactory; // we can't make the network.bind_host a fallback since we already fall back to http.host hence the extra conditional here List httpBindHost = SETTING_HTTP_BIND_HOST.get(settings); @@ -334,7 +338,7 @@ private void handleIncomingRequest(final HttpRequest httpRequest, final HttpChan { RestRequest innerRestRequest; try { - innerRestRequest = RestRequest.request(xContentRegistry, httpRequest, httpChannel); + innerRestRequest = restRequestFactory.createRestRequest(xContentRegistry, httpRequest, httpChannel); } catch (final RestRequest.ContentTypeHeaderException e) { badRequestCause = ExceptionsHelper.useOrSuppress(badRequestCause, e); innerRestRequest = requestWithoutContentTypeHeader(httpRequest, httpChannel, badRequestCause); diff --git a/server/src/main/java/org/elasticsearch/node/Node.java b/server/src/main/java/org/elasticsearch/node/Node.java index 0a0eb406405b1..8eca4703146e4 100644 --- a/server/src/main/java/org/elasticsearch/node/Node.java +++ b/server/src/main/java/org/elasticsearch/node/Node.java @@ -141,12 +141,15 @@ import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.PluginsService; import org.elasticsearch.plugins.RepositoryPlugin; +import org.elasticsearch.plugins.RestRequestPlugin; import org.elasticsearch.plugins.ScriptPlugin; import org.elasticsearch.plugins.SearchPlugin; import org.elasticsearch.plugins.SystemIndexPlugin; import org.elasticsearch.repositories.RepositoriesModule; import org.elasticsearch.repositories.RepositoriesService; import org.elasticsearch.rest.RestController; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.RestRequestFactory; import org.elasticsearch.script.ScriptContext; import org.elasticsearch.script.ScriptEngine; import org.elasticsearch.script.ScriptModule; @@ -515,9 +518,10 @@ protected Node(final Environment initialEnvironment, modules.add(actionModule); final RestController restController = actionModule.getRestController(); + RestRequestFactory restRequestFactory = getRestRequestFactory(pluginsService.filterPlugins(RestRequestPlugin.class)); final NetworkModule networkModule = new NetworkModule(settings, pluginsService.filterPlugins(NetworkPlugin.class), threadPool, bigArrays, pageCacheRecycler, circuitBreakerService, namedWriteableRegistry, xContentRegistry, - networkService, restController, clusterService.getClusterSettings()); + networkService, restController, clusterService.getClusterSettings(), restRequestFactory); Collection>> indexTemplateMetadataUpgraders = pluginsService.filterPlugins(Plugin.class).stream() .map(Plugin::getIndexTemplateMetadataUpgrader) @@ -680,6 +684,22 @@ protected Node(final Environment initialEnvironment, } } + private RestRequestFactory getRestRequestFactory(List restRequestPlugins) { + RestRequestFactory restRequestFactory = null; + for (RestRequestPlugin plugin : restRequestPlugins) { + RestRequestFactory newRestRequestFactory = plugin.getRestRequestFactory(); + if (newRestRequestFactory != null) { + logger.debug("Using REST request factory from plugin " + plugin.getClass().getName()); + if (restRequestFactory != null) { + //TODO maybe we could combine/chain them? + throw new IllegalArgumentException("Cannot have more than one plugin implementing a RestRequestPlugin"); + } + restRequestFactory = newRestRequestFactory; + } + } + return restRequestFactory != null ? restRequestFactory : RestRequest::request; + } + protected TransportService newTransportService(Settings settings, Transport transport, ThreadPool threadPool, TransportInterceptor interceptor, Function localNodeFactory, diff --git a/server/src/main/java/org/elasticsearch/plugins/NetworkPlugin.java b/server/src/main/java/org/elasticsearch/plugins/NetworkPlugin.java index a7c9e7bd842b7..6e987ff4d5cd7 100644 --- a/server/src/main/java/org/elasticsearch/plugins/NetworkPlugin.java +++ b/server/src/main/java/org/elasticsearch/plugins/NetworkPlugin.java @@ -33,6 +33,7 @@ import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.http.HttpServerTransport; import org.elasticsearch.indices.breaker.CircuitBreakerService; +import org.elasticsearch.rest.RestRequestFactory; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.Transport; import org.elasticsearch.transport.TransportInterceptor; @@ -75,7 +76,7 @@ default Map> getHttpTransports(Settings se NamedXContentRegistry xContentRegistry, NetworkService networkService, HttpServerTransport.Dispatcher dispatcher, - ClusterSettings clusterSettings) { + ClusterSettings clusterSettings, RestRequestFactory restRequestFactory) { return Collections.emptyMap(); } } diff --git a/server/src/main/java/org/elasticsearch/plugins/RestRequestPlugin.java b/server/src/main/java/org/elasticsearch/plugins/RestRequestPlugin.java new file mode 100644 index 0000000000000..9c84199d2af69 --- /dev/null +++ b/server/src/main/java/org/elasticsearch/plugins/RestRequestPlugin.java @@ -0,0 +1,28 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.plugins; + +import org.elasticsearch.rest.RestRequestFactory; + +public interface RestRequestPlugin { + default RestRequestFactory getRestRequestFactory() { + return null; + } +} diff --git a/server/src/main/java/org/elasticsearch/rest/RestRequest.java b/server/src/main/java/org/elasticsearch/rest/RestRequest.java index 512bf72e9c0d3..f0aeb6b63495a 100644 --- a/server/src/main/java/org/elasticsearch/rest/RestRequest.java +++ b/server/src/main/java/org/elasticsearch/rest/RestRequest.java @@ -21,6 +21,7 @@ import org.apache.lucene.util.SetOnce; import org.elasticsearch.ElasticsearchParseException; +import org.elasticsearch.Version; import org.elasticsearch.common.Booleans; import org.elasticsearch.common.CheckedConsumer; import org.elasticsearch.common.Nullable; @@ -135,6 +136,15 @@ public static RestRequest request(NamedXContentRegistry xContentRegistry, HttpRe requestIdGenerator.incrementAndGet()); } + /** + * An http request can be accompanied with a compatible version indicating with what version a client is using. + * Only a major Versions are supported. Internally we use Versions objects, but only use Version(major,0,0) + * @return a version with what a client is compatible with. + */ + public Version getCompatibleApiVersion() { + return Version.CURRENT; + } + private static Map params(final String uri) { final Map params = new HashMap<>(); int index = uri.indexOf('?'); diff --git a/server/src/main/java/org/elasticsearch/rest/RestRequestFactory.java b/server/src/main/java/org/elasticsearch/rest/RestRequestFactory.java new file mode 100644 index 0000000000000..b78ca4d40681f --- /dev/null +++ b/server/src/main/java/org/elasticsearch/rest/RestRequestFactory.java @@ -0,0 +1,28 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.rest; + +import org.elasticsearch.common.xcontent.NamedXContentRegistry; +import org.elasticsearch.http.HttpChannel; +import org.elasticsearch.http.HttpRequest; + +public interface RestRequestFactory { + RestRequest createRestRequest(NamedXContentRegistry xContentRegistry, HttpRequest httpRequest, HttpChannel httpChannel); +} diff --git a/server/src/test/java/org/elasticsearch/common/network/NetworkModuleTests.java b/server/src/test/java/org/elasticsearch/common/network/NetworkModuleTests.java index 43fd669f71da3..92252e4eb3891 100644 --- a/server/src/test/java/org/elasticsearch/common/network/NetworkModuleTests.java +++ b/server/src/test/java/org/elasticsearch/common/network/NetworkModuleTests.java @@ -34,6 +34,8 @@ import org.elasticsearch.http.NullDispatcher; import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.plugins.NetworkPlugin; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.RestRequestFactory; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.TestThreadPool; import org.elasticsearch.threadpool.ThreadPool; @@ -119,7 +121,7 @@ public Map> getHttpTransports(Settings set NamedXContentRegistry xContentRegistry, NetworkService networkService, HttpServerTransport.Dispatcher requestDispatcher, - ClusterSettings clusterSettings) { + ClusterSettings clusterSettings, RestRequestFactory restRequestFactory) { return Collections.singletonMap("custom", custom); } }); @@ -157,7 +159,7 @@ public Map> getHttpTransports(Settings set NamedXContentRegistry xContentRegistry, NetworkService networkService, HttpServerTransport.Dispatcher requestDispatcher, - ClusterSettings clusterSettings) { + ClusterSettings clusterSettings, RestRequestFactory restRequestFactory) { Map> supplierMap = new HashMap<>(); supplierMap.put("custom", custom); supplierMap.put("default_custom", def); @@ -193,7 +195,7 @@ public Map> getHttpTransports(Settings set NamedXContentRegistry xContentRegistry, NetworkService networkService, HttpServerTransport.Dispatcher requestDispatcher, - ClusterSettings clusterSettings) { + ClusterSettings clusterSettings, RestRequestFactory restRequestFactory) { Map> supplierMap = new HashMap<>(); supplierMap.put("custom", custom); supplierMap.put("default_custom", def); @@ -259,6 +261,6 @@ public List getTransportInterceptors(NamedWriteableRegistr private NetworkModule newNetworkModule(Settings settings, NetworkPlugin... plugins) { return new NetworkModule(settings, Arrays.asList(plugins), threadPool, null, null, null, null, xContentRegistry(), null, new NullDispatcher(), - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)); + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), RestRequest::request); } } diff --git a/server/src/test/java/org/elasticsearch/http/AbstractHttpServerTransportTests.java b/server/src/test/java/org/elasticsearch/http/AbstractHttpServerTransportTests.java index 348e8a83af731..42ebec8c91394 100644 --- a/server/src/test/java/org/elasticsearch/http/AbstractHttpServerTransportTests.java +++ b/server/src/test/java/org/elasticsearch/http/AbstractHttpServerTransportTests.java @@ -140,7 +140,7 @@ public void dispatchBadRequest(final RestChannel channel, try (AbstractHttpServerTransport transport = new AbstractHttpServerTransport(Settings.EMPTY, networkService, bigArrays, threadPool, xContentRegistry(), dispatcher, - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)) { + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), RestRequest::request) { @Override protected HttpServerChannel bind(InetSocketAddress hostAddress) { @@ -199,7 +199,7 @@ public void dispatchRequest(RestRequest request, RestChannel channel, ThreadCont public void dispatchBadRequest(RestChannel channel, ThreadContext threadContext, Throwable cause) { channel.sendResponse(emptyResponse(RestStatus.BAD_REQUEST)); } - }, clusterSettings) { + }, clusterSettings, RestRequest::request) { @Override protected HttpServerChannel bind(InetSocketAddress hostAddress) { return null; diff --git a/x-pack/plugin/compat-rest-request/build.gradle b/x-pack/plugin/compat-rest-request/build.gradle new file mode 100644 index 0000000000000..f16e5656fec29 --- /dev/null +++ b/x-pack/plugin/compat-rest-request/build.gradle @@ -0,0 +1,17 @@ +evaluationDependsOn(xpackModule('core')) + +apply plugin: 'elasticsearch.esplugin' + +esplugin { + name 'compat-rest-request' + description 'A plugin for Compatible Rest API' + classname 'org.elasticsearch.compat.CompatRestRequestPlugin' + extendedPlugins = ['x-pack-core'] +} + +dependencies { + compileOnly project(path: xpackModule('core'), configuration: 'default') + testImplementation project(path: xpackModule('core'), configuration: 'testArtifacts') +} + +integTest.enabled = false diff --git a/x-pack/plugin/compat-rest-request/src/main/java/org/elasticsearch/compat/CompatRestRequestPlugin.java b/x-pack/plugin/compat-rest-request/src/main/java/org/elasticsearch/compat/CompatRestRequestPlugin.java new file mode 100644 index 0000000000000..b1b158c3cc241 --- /dev/null +++ b/x-pack/plugin/compat-rest-request/src/main/java/org/elasticsearch/compat/CompatRestRequestPlugin.java @@ -0,0 +1,37 @@ +package org.elasticsearch.compat; + +import org.elasticsearch.Version; +import org.elasticsearch.common.xcontent.NamedXContentRegistry; +import org.elasticsearch.http.HttpChannel; +import org.elasticsearch.http.HttpRequest; +import org.elasticsearch.plugins.RestRequestPlugin; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.RestRequestFactory; + +public class CompatRestRequestPlugin implements RestRequestPlugin { + @Override + public RestRequestFactory getRestRequestFactory() { + return new RestRequestFactory() { + @Override + public RestRequest createRestRequest(NamedXContentRegistry xContentRegistry, HttpRequest httpRequest, HttpChannel httpChannel) { + RestRequest restRequest = RestRequest.request(xContentRegistry, httpRequest, httpChannel); + return new CompatibleRestRequest(restRequest); + } + }; + } + + public static class CompatibleRestRequest extends RestRequest { + + // TODO this requires copying the content of original rest request. Isn't this against why multiple rest wrappers were disallowed? + //https://github.com/elastic/elasticsearch/pull/21905/files#r90480951 + protected CompatibleRestRequest(RestRequest restRequest) { + super(restRequest); + } + + public Version getCompatibleApiVersion() { + return Version.CURRENT; + } + + + } +} diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/LocalStateCompositeXPackPlugin.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/LocalStateCompositeXPackPlugin.java index 1c0a61cf979f7..d2fc7cce40ea7 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/LocalStateCompositeXPackPlugin.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/LocalStateCompositeXPackPlugin.java @@ -66,6 +66,8 @@ import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestHandler; import org.elasticsearch.rest.RestHeaderDefinition; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.RestRequestFactory; import org.elasticsearch.script.ScriptContext; import org.elasticsearch.script.ScriptService; import org.elasticsearch.threadpool.ExecutorBuilder; @@ -309,10 +311,10 @@ public Map> getHttpTransports(Settings set NamedXContentRegistry xContentRegistry, NetworkService networkService, HttpServerTransport.Dispatcher dispatcher, - ClusterSettings clusterSettings) { + ClusterSettings clusterSettings, RestRequestFactory restRequestFactory) { Map> transports = new HashMap<>(); filterPlugins(NetworkPlugin.class).stream().forEach(p -> transports.putAll(p.getHttpTransports(settings, threadPool, bigArrays, - pageCacheRecycler, circuitBreakerService, xContentRegistry, networkService, dispatcher, clusterSettings))); + pageCacheRecycler, circuitBreakerService, xContentRegistry, networkService, dispatcher, clusterSettings, restRequestFactory))); return transports; } diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java index d48759439a7d2..c3b9531606775 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java @@ -62,6 +62,8 @@ import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestHandler; import org.elasticsearch.rest.RestHeaderDefinition; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.RestRequestFactory; import org.elasticsearch.script.ScriptService; import org.elasticsearch.threadpool.ExecutorBuilder; import org.elasticsearch.threadpool.FixedExecutorBuilder; @@ -977,7 +979,7 @@ public Map> getHttpTransports(Settings set NamedXContentRegistry xContentRegistry, NetworkService networkService, HttpServerTransport.Dispatcher dispatcher, - ClusterSettings clusterSettings) { + ClusterSettings clusterSettings, RestRequestFactory restRequestFactory) { if (enabled == false) { // don't register anything if we are not enabled return Collections.emptyMap(); } @@ -985,10 +987,10 @@ public Map> getHttpTransports(Settings set Map> httpTransports = new HashMap<>(); httpTransports.put(SecurityField.NAME4, () -> new SecurityNetty4HttpServerTransport(settings, networkService, bigArrays, ipFilter.get(), getSslService(), threadPool, xContentRegistry, dispatcher, clusterSettings, - getNettySharedGroupFactory(settings))); + getNettySharedGroupFactory(settings), restRequestFactory)); httpTransports.put(SecurityField.NIO, () -> new SecurityNioHttpServerTransport(settings, networkService, bigArrays, pageCacheRecycler, threadPool, xContentRegistry, dispatcher, ipFilter.get(), getSslService(), getNioGroupFactory(settings), - clusterSettings)); + clusterSettings, restRequestFactory)); return httpTransports; } diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransport.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransport.java index e3207605658f0..abce5d7caff81 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransport.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransport.java @@ -17,6 +17,8 @@ import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.http.HttpChannel; import org.elasticsearch.http.netty4.Netty4HttpServerTransport; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.RestRequestFactory; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.SharedGroupFactory; import org.elasticsearch.xpack.core.ssl.SSLConfiguration; @@ -39,8 +41,9 @@ public class SecurityNetty4HttpServerTransport extends Netty4HttpServerTransport public SecurityNetty4HttpServerTransport(Settings settings, NetworkService networkService, BigArrays bigArrays, IPFilter ipFilter, SSLService sslService, ThreadPool threadPool, NamedXContentRegistry xContentRegistry, Dispatcher dispatcher, ClusterSettings clusterSettings, - SharedGroupFactory sharedGroupFactory) { - super(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory); + SharedGroupFactory sharedGroupFactory, RestRequestFactory restRequestFactory) { + super(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings, sharedGroupFactory, + restRequestFactory); this.securityExceptionHandler = new SecurityHttpExceptionHandler(logger, lifecycle, (c, e) -> super.onException(c, e)); this.ipFilter = ipFilter; final boolean ssl = HTTP_SSL_ENABLED.get(settings); diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/nio/SecurityNioHttpServerTransport.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/nio/SecurityNioHttpServerTransport.java index d8f8b8036329a..3ee832ea42500 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/nio/SecurityNioHttpServerTransport.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/nio/SecurityNioHttpServerTransport.java @@ -26,6 +26,8 @@ import org.elasticsearch.nio.NioSocketChannel; import org.elasticsearch.nio.ServerChannelContext; import org.elasticsearch.nio.SocketChannelContext; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.RestRequestFactory; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.nio.NioGroupFactory; import org.elasticsearch.xpack.core.ssl.SSLConfiguration; @@ -55,9 +57,9 @@ public SecurityNioHttpServerTransport(Settings settings, NetworkService networkS PageCacheRecycler pageCacheRecycler, ThreadPool threadPool, NamedXContentRegistry xContentRegistry, Dispatcher dispatcher, IPFilter ipFilter, SSLService sslService, NioGroupFactory nioGroupFactory, - ClusterSettings clusterSettings) { + ClusterSettings clusterSettings, RestRequestFactory restRequestFactory) { super(settings, networkService, bigArrays, pageCacheRecycler, threadPool, xContentRegistry, dispatcher, nioGroupFactory, - clusterSettings); + clusterSettings, restRequestFactory); this.securityExceptionHandler = new SecurityHttpExceptionHandler(logger, lifecycle, (c, e) -> super.onException(c, e)); this.ipFilter = ipFilter; this.sslEnabled = HTTP_SSL_ENABLED.get(settings); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransportTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransportTests.java index 951c2d5fb4238..6c62f64fe50d6 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransportTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransportTests.java @@ -16,6 +16,7 @@ import org.elasticsearch.env.Environment; import org.elasticsearch.env.TestEnvironment; import org.elasticsearch.http.NullDispatcher; +import org.elasticsearch.rest.RestRequest; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.SharedGroupFactory; @@ -68,7 +69,7 @@ public void testDefaultClientAuth() throws Exception { SecurityNetty4HttpServerTransport transport = new SecurityNetty4HttpServerTransport(settings, new NetworkService(Collections.emptyList()), mock(BigArrays.class), mock(IPFilter.class), sslService, mock(ThreadPool.class), xContentRegistry(), new NullDispatcher(), - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), new SharedGroupFactory(settings)); + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), new SharedGroupFactory(settings), RestRequest::request); ChannelHandler handler = transport.configureServerChannelHandler(); final EmbeddedChannel ch = new EmbeddedChannel(handler); assertThat(ch.pipeline().get(SslHandler.class).engine().getNeedClientAuth(), is(false)); @@ -85,7 +86,7 @@ public void testOptionalClientAuth() throws Exception { SecurityNetty4HttpServerTransport transport = new SecurityNetty4HttpServerTransport(settings, new NetworkService(Collections.emptyList()), mock(BigArrays.class), mock(IPFilter.class), sslService, mock(ThreadPool.class), xContentRegistry(), new NullDispatcher(), - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), new SharedGroupFactory(settings)); + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), new SharedGroupFactory(settings), RestRequest::request); ChannelHandler handler = transport.configureServerChannelHandler(); final EmbeddedChannel ch = new EmbeddedChannel(handler); assertThat(ch.pipeline().get(SslHandler.class).engine().getNeedClientAuth(), is(false)); @@ -102,7 +103,7 @@ public void testRequiredClientAuth() throws Exception { SecurityNetty4HttpServerTransport transport = new SecurityNetty4HttpServerTransport(settings, new NetworkService(Collections.emptyList()), mock(BigArrays.class), mock(IPFilter.class), sslService, mock(ThreadPool.class), xContentRegistry(), new NullDispatcher(), - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), new SharedGroupFactory(settings)); + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), new SharedGroupFactory(settings), RestRequest::request); ChannelHandler handler = transport.configureServerChannelHandler(); final EmbeddedChannel ch = new EmbeddedChannel(handler); assertThat(ch.pipeline().get(SslHandler.class).engine().getNeedClientAuth(), is(true)); @@ -119,7 +120,7 @@ public void testNoClientAuth() throws Exception { SecurityNetty4HttpServerTransport transport = new SecurityNetty4HttpServerTransport(settings, new NetworkService(Collections.emptyList()), mock(BigArrays.class), mock(IPFilter.class), sslService, mock(ThreadPool.class), xContentRegistry(), new NullDispatcher(), - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), new SharedGroupFactory(settings)); + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), new SharedGroupFactory(settings), RestRequest::request); ChannelHandler handler = transport.configureServerChannelHandler(); final EmbeddedChannel ch = new EmbeddedChannel(handler); assertThat(ch.pipeline().get(SslHandler.class).engine().getNeedClientAuth(), is(false)); @@ -134,7 +135,7 @@ public void testCustomSSLConfiguration() throws Exception { SecurityNetty4HttpServerTransport transport = new SecurityNetty4HttpServerTransport(settings, new NetworkService(Collections.emptyList()), mock(BigArrays.class), mock(IPFilter.class), sslService, mock(ThreadPool.class), xContentRegistry(), new NullDispatcher(), - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), new SharedGroupFactory(settings)); + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), new SharedGroupFactory(settings), RestRequest::request); ChannelHandler handler = transport.configureServerChannelHandler(); EmbeddedChannel ch = new EmbeddedChannel(handler); SSLEngine defaultEngine = ch.pipeline().get(SslHandler.class).engine(); @@ -147,7 +148,7 @@ public void testCustomSSLConfiguration() throws Exception { sslService = new SSLService(TestEnvironment.newEnvironment(settings)); transport = new SecurityNetty4HttpServerTransport(settings, new NetworkService(Collections.emptyList()), mock(BigArrays.class), mock(IPFilter.class), sslService, mock(ThreadPool.class), xContentRegistry(), new NullDispatcher(), - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), new SharedGroupFactory(settings)); + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), new SharedGroupFactory(settings), RestRequest::request); handler = transport.configureServerChannelHandler(); ch = new EmbeddedChannel(handler); SSLEngine customEngine = ch.pipeline().get(SslHandler.class).engine(); @@ -170,7 +171,7 @@ public void testNoExceptionWhenConfiguredWithoutSslKeySSLDisabled() throws Excep SecurityNetty4HttpServerTransport transport = new SecurityNetty4HttpServerTransport(settings, new NetworkService(Collections.emptyList()), mock(BigArrays.class), mock(IPFilter.class), sslService, mock(ThreadPool.class), xContentRegistry(), new NullDispatcher(), - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), new SharedGroupFactory(settings)); + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), new SharedGroupFactory(settings), RestRequest::request); assertNotNull(transport.configureServerChannelHandler()); } } diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/nio/SecurityNioHttpServerTransportTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/nio/SecurityNioHttpServerTransportTests.java index 39d19578cec6f..d2792f41582f1 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/nio/SecurityNioHttpServerTransportTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/nio/SecurityNioHttpServerTransportTests.java @@ -17,6 +17,7 @@ import org.elasticsearch.http.nio.NioHttpChannel; import org.elasticsearch.nio.Config; import org.elasticsearch.nio.NioSelector; +import org.elasticsearch.rest.RestRequest; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.nio.NioGroupFactory; @@ -76,7 +77,7 @@ public void testDefaultClientAuth() throws IOException { SecurityNioHttpServerTransport transport = new SecurityNioHttpServerTransport(settings, new NetworkService(Collections.emptyList()), mock(BigArrays.class), mock(PageCacheRecycler.class), mock(ThreadPool.class), xContentRegistry(), new NullDispatcher(), mock(IPFilter.class), sslService, nioGroupFactory, - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)); + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), RestRequest::request); SecurityNioHttpServerTransport.SecurityHttpChannelFactory factory = transport.channelFactory(); SocketChannel socketChannel = mock(SocketChannel.class); when(socketChannel.getRemoteAddress()).thenReturn(address); @@ -98,7 +99,7 @@ public void testOptionalClientAuth() throws IOException { SecurityNioHttpServerTransport transport = new SecurityNioHttpServerTransport(settings, new NetworkService(Collections.emptyList()), mock(BigArrays.class), mock(PageCacheRecycler.class), mock(ThreadPool.class), xContentRegistry(), new NullDispatcher(), mock(IPFilter.class), sslService, nioGroupFactory, - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)); + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), RestRequest::request); SecurityNioHttpServerTransport.SecurityHttpChannelFactory factory = transport.channelFactory(); SocketChannel socketChannel = mock(SocketChannel.class); @@ -120,7 +121,7 @@ public void testRequiredClientAuth() throws IOException { SecurityNioHttpServerTransport transport = new SecurityNioHttpServerTransport(settings, new NetworkService(Collections.emptyList()), mock(BigArrays.class), mock(PageCacheRecycler.class), mock(ThreadPool.class), xContentRegistry(), new NullDispatcher(), mock(IPFilter.class), sslService, nioGroupFactory, - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)); + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), RestRequest::request); SecurityNioHttpServerTransport.SecurityHttpChannelFactory factory = transport.channelFactory(); SocketChannel socketChannel = mock(SocketChannel.class); @@ -142,7 +143,7 @@ public void testNoClientAuth() throws IOException { SecurityNioHttpServerTransport transport = new SecurityNioHttpServerTransport(settings, new NetworkService(Collections.emptyList()), mock(BigArrays.class), mock(PageCacheRecycler.class), mock(ThreadPool.class), xContentRegistry(), new NullDispatcher(), mock(IPFilter.class), sslService, nioGroupFactory, - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)); + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), RestRequest::request); SecurityNioHttpServerTransport.SecurityHttpChannelFactory factory = transport.channelFactory(); SocketChannel socketChannel = mock(SocketChannel.class); @@ -162,7 +163,7 @@ public void testCustomSSLConfiguration() throws IOException { SecurityNioHttpServerTransport transport = new SecurityNioHttpServerTransport(settings, new NetworkService(Collections.emptyList()), mock(BigArrays.class), mock(PageCacheRecycler.class), mock(ThreadPool.class), xContentRegistry(), new NullDispatcher(), mock(IPFilter.class), sslService, nioGroupFactory, - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)); + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), RestRequest::request); SecurityNioHttpServerTransport.SecurityHttpChannelFactory factory = transport.channelFactory(); SocketChannel socketChannel = mock(SocketChannel.class); when(socketChannel.getRemoteAddress()).thenReturn(address); @@ -179,7 +180,7 @@ public void testCustomSSLConfiguration() throws IOException { transport = new SecurityNioHttpServerTransport(settings, new NetworkService(Collections.emptyList()), mock(BigArrays.class), mock(PageCacheRecycler.class), mock(ThreadPool.class), xContentRegistry(), new NullDispatcher(), mock(IPFilter.class), sslService, nioGroupFactory, - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)); + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), RestRequest::request); factory = transport.channelFactory(); channel = factory.createChannel(mock(NioSelector.class), socketChannel, mock(Config.Socket.class)); SSLEngine customEngine = SSLEngineUtils.getSSLEngine(channel); @@ -203,6 +204,6 @@ public void testNoExceptionWhenConfiguredWithoutSslKeySSLDisabled() { SecurityNioHttpServerTransport transport = new SecurityNioHttpServerTransport(settings, new NetworkService(Collections.emptyList()), mock(BigArrays.class), mock(PageCacheRecycler.class), mock(ThreadPool.class), xContentRegistry(), new NullDispatcher(), mock(IPFilter.class), sslService, nioGroupFactory, - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)); + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), RestRequest::request); } } From 2e175ef21bb099ecd1ff16ec5a9281a8d524a23f Mon Sep 17 00:00:00 2001 From: pgomulka Date: Tue, 21 Jul 2020 19:21:53 +0200 Subject: [PATCH 2/2] precommit --- .../netty4/Netty4HttpServerTransport.java | 1 - .../elasticsearch/transport/Netty4Plugin.java | 4 ++-- .../http/nio/NioHttpServerTransport.java | 1 - .../transport/nio/NioTransportPlugin.java | 4 ++-- .../common/network/NetworkModule.java | 5 ++--- .../elasticsearch/plugins/NetworkPlugin.java | 3 ++- .../common/network/NetworkModuleTests.java | 9 +++++--- .../compat/CompatRestRequestPlugin.java | 8 +++++-- .../compat/CompatRestRequestPluginTests.java | 14 +++++++++++++ .../core/LocalStateCompositeXPackPlugin.java | 4 ++-- .../xpack/security/Security.java | 4 ++-- .../SecurityNetty4HttpServerTransport.java | 1 - .../nio/SecurityNioHttpServerTransport.java | 1 - ...ecurityNetty4HttpServerTransportTests.java | 21 ++++++++++++------- 14 files changed, 52 insertions(+), 28 deletions(-) create mode 100644 x-pack/plugin/compat-rest-request/src/test/java/org/elasticsearch/compat/CompatRestRequestPluginTests.java diff --git a/modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpServerTransport.java b/modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpServerTransport.java index 63a4e3b97f6e7..6a0eacf98ade5 100644 --- a/modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpServerTransport.java +++ b/modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpServerTransport.java @@ -60,7 +60,6 @@ import org.elasticsearch.http.HttpReadTimeoutException; import org.elasticsearch.http.HttpServerChannel; import org.elasticsearch.http.netty4.cors.Netty4CorsHandler; -import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequestFactory; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.SharedGroupFactory; diff --git a/modules/transport-netty4/src/main/java/org/elasticsearch/transport/Netty4Plugin.java b/modules/transport-netty4/src/main/java/org/elasticsearch/transport/Netty4Plugin.java index 37b4c75ee3083..d244cd2acecd6 100644 --- a/modules/transport-netty4/src/main/java/org/elasticsearch/transport/Netty4Plugin.java +++ b/modules/transport-netty4/src/main/java/org/elasticsearch/transport/Netty4Plugin.java @@ -35,7 +35,6 @@ import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.plugins.NetworkPlugin; import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequestFactory; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.netty4.Netty4Transport; @@ -92,7 +91,8 @@ public Map> getHttpTransports(Settings set NamedXContentRegistry xContentRegistry, NetworkService networkService, HttpServerTransport.Dispatcher dispatcher, - ClusterSettings clusterSettings, RestRequestFactory restRequestFactory) { + ClusterSettings clusterSettings, + RestRequestFactory restRequestFactory) { return Collections.singletonMap(NETTY_HTTP_TRANSPORT_NAME, () -> new Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher, clusterSettings, getSharedGroupFactory(settings), restRequestFactory)); diff --git a/plugins/transport-nio/src/main/java/org/elasticsearch/http/nio/NioHttpServerTransport.java b/plugins/transport-nio/src/main/java/org/elasticsearch/http/nio/NioHttpServerTransport.java index 89f01b9118dee..d6b7f54e9697a 100644 --- a/plugins/transport-nio/src/main/java/org/elasticsearch/http/nio/NioHttpServerTransport.java +++ b/plugins/transport-nio/src/main/java/org/elasticsearch/http/nio/NioHttpServerTransport.java @@ -43,7 +43,6 @@ import org.elasticsearch.nio.NioSocketChannel; import org.elasticsearch.nio.ServerChannelContext; import org.elasticsearch.nio.SocketChannelContext; -import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequestFactory; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.nio.NioGroupFactory; diff --git a/plugins/transport-nio/src/main/java/org/elasticsearch/transport/nio/NioTransportPlugin.java b/plugins/transport-nio/src/main/java/org/elasticsearch/transport/nio/NioTransportPlugin.java index 1b1b8bcbe13c6..3768f9a2d9376 100644 --- a/plugins/transport-nio/src/main/java/org/elasticsearch/transport/nio/NioTransportPlugin.java +++ b/plugins/transport-nio/src/main/java/org/elasticsearch/transport/nio/NioTransportPlugin.java @@ -37,7 +37,6 @@ import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.plugins.NetworkPlugin; import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequestFactory; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.Transport; @@ -90,7 +89,8 @@ public Map> getHttpTransports(Settings set NamedXContentRegistry xContentRegistry, NetworkService networkService, HttpServerTransport.Dispatcher dispatcher, - ClusterSettings clusterSettings, RestRequestFactory restRequestFactory) { + ClusterSettings clusterSettings, + RestRequestFactory restRequestFactory) { return Collections.singletonMap(NIO_HTTP_TRANSPORT_NAME, () -> new NioHttpServerTransport(settings, networkService, bigArrays, pageCacheRecycler, threadPool, xContentRegistry, dispatcher, getNioGroupFactory(settings), clusterSettings, restRequestFactory)); diff --git a/server/src/main/java/org/elasticsearch/common/network/NetworkModule.java b/server/src/main/java/org/elasticsearch/common/network/NetworkModule.java index 20792a0e25584..5fe59e2da4424 100644 --- a/server/src/main/java/org/elasticsearch/common/network/NetworkModule.java +++ b/server/src/main/java/org/elasticsearch/common/network/NetworkModule.java @@ -42,7 +42,6 @@ import org.elasticsearch.index.shard.PrimaryReplicaSyncer.ResyncTask; import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.plugins.NetworkPlugin; -import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequestFactory; import org.elasticsearch.tasks.RawTaskStatus; import org.elasticsearch.tasks.Task; @@ -108,7 +107,6 @@ public final class NetworkModule { /** * Creates a network module that custom networking classes can be plugged into. * @param settings The settings for the node - * @param restRequestFactory */ public NetworkModule(Settings settings, List plugins, ThreadPool threadPool, BigArrays bigArrays, @@ -121,7 +119,8 @@ public NetworkModule(Settings settings, List plugins, ThreadPool this.settings = settings; for (NetworkPlugin plugin : plugins) { Map> httpTransportFactory = plugin.getHttpTransports(settings, threadPool, bigArrays, - pageCacheRecycler, circuitBreakerService, xContentRegistry, networkService, dispatcher, clusterSettings, restRequestFactory); + pageCacheRecycler, circuitBreakerService, xContentRegistry, networkService, dispatcher, clusterSettings, + restRequestFactory); for (Map.Entry> entry : httpTransportFactory.entrySet()) { registerHttpTransport(entry.getKey(), entry.getValue()); } diff --git a/server/src/main/java/org/elasticsearch/plugins/NetworkPlugin.java b/server/src/main/java/org/elasticsearch/plugins/NetworkPlugin.java index 6e987ff4d5cd7..9dcc270fd62a0 100644 --- a/server/src/main/java/org/elasticsearch/plugins/NetworkPlugin.java +++ b/server/src/main/java/org/elasticsearch/plugins/NetworkPlugin.java @@ -76,7 +76,8 @@ default Map> getHttpTransports(Settings se NamedXContentRegistry xContentRegistry, NetworkService networkService, HttpServerTransport.Dispatcher dispatcher, - ClusterSettings clusterSettings, RestRequestFactory restRequestFactory) { + ClusterSettings clusterSettings, + RestRequestFactory restRequestFactory) { return Collections.emptyMap(); } } diff --git a/server/src/test/java/org/elasticsearch/common/network/NetworkModuleTests.java b/server/src/test/java/org/elasticsearch/common/network/NetworkModuleTests.java index 92252e4eb3891..18024eb282260 100644 --- a/server/src/test/java/org/elasticsearch/common/network/NetworkModuleTests.java +++ b/server/src/test/java/org/elasticsearch/common/network/NetworkModuleTests.java @@ -121,7 +121,8 @@ public Map> getHttpTransports(Settings set NamedXContentRegistry xContentRegistry, NetworkService networkService, HttpServerTransport.Dispatcher requestDispatcher, - ClusterSettings clusterSettings, RestRequestFactory restRequestFactory) { + ClusterSettings clusterSettings, + RestRequestFactory restRequestFactory) { return Collections.singletonMap("custom", custom); } }); @@ -159,7 +160,8 @@ public Map> getHttpTransports(Settings set NamedXContentRegistry xContentRegistry, NetworkService networkService, HttpServerTransport.Dispatcher requestDispatcher, - ClusterSettings clusterSettings, RestRequestFactory restRequestFactory) { + ClusterSettings clusterSettings, + RestRequestFactory restRequestFactory) { Map> supplierMap = new HashMap<>(); supplierMap.put("custom", custom); supplierMap.put("default_custom", def); @@ -195,7 +197,8 @@ public Map> getHttpTransports(Settings set NamedXContentRegistry xContentRegistry, NetworkService networkService, HttpServerTransport.Dispatcher requestDispatcher, - ClusterSettings clusterSettings, RestRequestFactory restRequestFactory) { + ClusterSettings clusterSettings, + RestRequestFactory restRequestFactory) { Map> supplierMap = new HashMap<>(); supplierMap.put("custom", custom); supplierMap.put("default_custom", def); diff --git a/x-pack/plugin/compat-rest-request/src/main/java/org/elasticsearch/compat/CompatRestRequestPlugin.java b/x-pack/plugin/compat-rest-request/src/main/java/org/elasticsearch/compat/CompatRestRequestPlugin.java index b1b158c3cc241..b8557f8662951 100644 --- a/x-pack/plugin/compat-rest-request/src/main/java/org/elasticsearch/compat/CompatRestRequestPlugin.java +++ b/x-pack/plugin/compat-rest-request/src/main/java/org/elasticsearch/compat/CompatRestRequestPlugin.java @@ -1,3 +1,8 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ package org.elasticsearch.compat; import org.elasticsearch.Version; @@ -23,7 +28,7 @@ public RestRequest createRestRequest(NamedXContentRegistry xContentRegistry, Htt public static class CompatibleRestRequest extends RestRequest { // TODO this requires copying the content of original rest request. Isn't this against why multiple rest wrappers were disallowed? - //https://github.com/elastic/elasticsearch/pull/21905/files#r90480951 + // https://github.com/elastic/elasticsearch/pull/21905/files#r90480951 protected CompatibleRestRequest(RestRequest restRequest) { super(restRequest); } @@ -32,6 +37,5 @@ public Version getCompatibleApiVersion() { return Version.CURRENT; } - } } diff --git a/x-pack/plugin/compat-rest-request/src/test/java/org/elasticsearch/compat/CompatRestRequestPluginTests.java b/x-pack/plugin/compat-rest-request/src/test/java/org/elasticsearch/compat/CompatRestRequestPluginTests.java new file mode 100644 index 0000000000000..70933b26be151 --- /dev/null +++ b/x-pack/plugin/compat-rest-request/src/test/java/org/elasticsearch/compat/CompatRestRequestPluginTests.java @@ -0,0 +1,14 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +package org.elasticsearch.compat; + +import org.elasticsearch.test.ESTestCase; + +public class CompatRestRequestPluginTests extends ESTestCase { + public void testEmpty() { + + } +} diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/LocalStateCompositeXPackPlugin.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/LocalStateCompositeXPackPlugin.java index d2fc7cce40ea7..72321f5561d16 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/LocalStateCompositeXPackPlugin.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/LocalStateCompositeXPackPlugin.java @@ -66,7 +66,6 @@ import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestHandler; import org.elasticsearch.rest.RestHeaderDefinition; -import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequestFactory; import org.elasticsearch.script.ScriptContext; import org.elasticsearch.script.ScriptService; @@ -311,7 +310,8 @@ public Map> getHttpTransports(Settings set NamedXContentRegistry xContentRegistry, NetworkService networkService, HttpServerTransport.Dispatcher dispatcher, - ClusterSettings clusterSettings, RestRequestFactory restRequestFactory) { + ClusterSettings clusterSettings, + RestRequestFactory restRequestFactory) { Map> transports = new HashMap<>(); filterPlugins(NetworkPlugin.class).stream().forEach(p -> transports.putAll(p.getHttpTransports(settings, threadPool, bigArrays, pageCacheRecycler, circuitBreakerService, xContentRegistry, networkService, dispatcher, clusterSettings, restRequestFactory))); diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java index c3b9531606775..ced5e27a40072 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java @@ -62,7 +62,6 @@ import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestHandler; import org.elasticsearch.rest.RestHeaderDefinition; -import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequestFactory; import org.elasticsearch.script.ScriptService; import org.elasticsearch.threadpool.ExecutorBuilder; @@ -979,7 +978,8 @@ public Map> getHttpTransports(Settings set NamedXContentRegistry xContentRegistry, NetworkService networkService, HttpServerTransport.Dispatcher dispatcher, - ClusterSettings clusterSettings, RestRequestFactory restRequestFactory) { + ClusterSettings clusterSettings, + RestRequestFactory restRequestFactory) { if (enabled == false) { // don't register anything if we are not enabled return Collections.emptyMap(); } diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransport.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransport.java index abce5d7caff81..b769b5647f753 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransport.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransport.java @@ -17,7 +17,6 @@ import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.http.HttpChannel; import org.elasticsearch.http.netty4.Netty4HttpServerTransport; -import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequestFactory; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.SharedGroupFactory; diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/nio/SecurityNioHttpServerTransport.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/nio/SecurityNioHttpServerTransport.java index 3ee832ea42500..bc14a2e80ef78 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/nio/SecurityNioHttpServerTransport.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/nio/SecurityNioHttpServerTransport.java @@ -26,7 +26,6 @@ import org.elasticsearch.nio.NioSocketChannel; import org.elasticsearch.nio.ServerChannelContext; import org.elasticsearch.nio.SocketChannelContext; -import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequestFactory; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.nio.NioGroupFactory; diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransportTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransportTests.java index 6c62f64fe50d6..8ea70e4d7918c 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransportTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransportTests.java @@ -69,7 +69,8 @@ public void testDefaultClientAuth() throws Exception { SecurityNetty4HttpServerTransport transport = new SecurityNetty4HttpServerTransport(settings, new NetworkService(Collections.emptyList()), mock(BigArrays.class), mock(IPFilter.class), sslService, mock(ThreadPool.class), xContentRegistry(), new NullDispatcher(), - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), new SharedGroupFactory(settings), RestRequest::request); + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), new SharedGroupFactory(settings), + RestRequest::request); ChannelHandler handler = transport.configureServerChannelHandler(); final EmbeddedChannel ch = new EmbeddedChannel(handler); assertThat(ch.pipeline().get(SslHandler.class).engine().getNeedClientAuth(), is(false)); @@ -86,7 +87,8 @@ public void testOptionalClientAuth() throws Exception { SecurityNetty4HttpServerTransport transport = new SecurityNetty4HttpServerTransport(settings, new NetworkService(Collections.emptyList()), mock(BigArrays.class), mock(IPFilter.class), sslService, mock(ThreadPool.class), xContentRegistry(), new NullDispatcher(), - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), new SharedGroupFactory(settings), RestRequest::request); + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), new SharedGroupFactory(settings), + RestRequest::request); ChannelHandler handler = transport.configureServerChannelHandler(); final EmbeddedChannel ch = new EmbeddedChannel(handler); assertThat(ch.pipeline().get(SslHandler.class).engine().getNeedClientAuth(), is(false)); @@ -103,7 +105,8 @@ public void testRequiredClientAuth() throws Exception { SecurityNetty4HttpServerTransport transport = new SecurityNetty4HttpServerTransport(settings, new NetworkService(Collections.emptyList()), mock(BigArrays.class), mock(IPFilter.class), sslService, mock(ThreadPool.class), xContentRegistry(), new NullDispatcher(), - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), new SharedGroupFactory(settings), RestRequest::request); + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), new SharedGroupFactory(settings), + RestRequest::request); ChannelHandler handler = transport.configureServerChannelHandler(); final EmbeddedChannel ch = new EmbeddedChannel(handler); assertThat(ch.pipeline().get(SslHandler.class).engine().getNeedClientAuth(), is(true)); @@ -120,7 +123,8 @@ public void testNoClientAuth() throws Exception { SecurityNetty4HttpServerTransport transport = new SecurityNetty4HttpServerTransport(settings, new NetworkService(Collections.emptyList()), mock(BigArrays.class), mock(IPFilter.class), sslService, mock(ThreadPool.class), xContentRegistry(), new NullDispatcher(), - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), new SharedGroupFactory(settings), RestRequest::request); + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), new SharedGroupFactory(settings), + RestRequest::request); ChannelHandler handler = transport.configureServerChannelHandler(); final EmbeddedChannel ch = new EmbeddedChannel(handler); assertThat(ch.pipeline().get(SslHandler.class).engine().getNeedClientAuth(), is(false)); @@ -135,7 +139,8 @@ public void testCustomSSLConfiguration() throws Exception { SecurityNetty4HttpServerTransport transport = new SecurityNetty4HttpServerTransport(settings, new NetworkService(Collections.emptyList()), mock(BigArrays.class), mock(IPFilter.class), sslService, mock(ThreadPool.class), xContentRegistry(), new NullDispatcher(), - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), new SharedGroupFactory(settings), RestRequest::request); + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), new SharedGroupFactory(settings), + RestRequest::request); ChannelHandler handler = transport.configureServerChannelHandler(); EmbeddedChannel ch = new EmbeddedChannel(handler); SSLEngine defaultEngine = ch.pipeline().get(SslHandler.class).engine(); @@ -148,7 +153,8 @@ public void testCustomSSLConfiguration() throws Exception { sslService = new SSLService(TestEnvironment.newEnvironment(settings)); transport = new SecurityNetty4HttpServerTransport(settings, new NetworkService(Collections.emptyList()), mock(BigArrays.class), mock(IPFilter.class), sslService, mock(ThreadPool.class), xContentRegistry(), new NullDispatcher(), - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), new SharedGroupFactory(settings), RestRequest::request); + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), new SharedGroupFactory(settings), + RestRequest::request); handler = transport.configureServerChannelHandler(); ch = new EmbeddedChannel(handler); SSLEngine customEngine = ch.pipeline().get(SslHandler.class).engine(); @@ -171,7 +177,8 @@ public void testNoExceptionWhenConfiguredWithoutSslKeySSLDisabled() throws Excep SecurityNetty4HttpServerTransport transport = new SecurityNetty4HttpServerTransport(settings, new NetworkService(Collections.emptyList()), mock(BigArrays.class), mock(IPFilter.class), sslService, mock(ThreadPool.class), xContentRegistry(), new NullDispatcher(), - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), new SharedGroupFactory(settings), RestRequest::request); + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), new SharedGroupFactory(settings), + RestRequest::request); assertNotNull(transport.configureServerChannelHandler()); } }