From 6110dcc7104a12d62c407c13a3f808fb70b6949d Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Fri, 1 Jul 2016 12:45:43 -0700 Subject: [PATCH 1/2] Fix unit tests for http server that no longer need node service --- .../org/elasticsearch/http/HttpServerTests.java | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/http/HttpServerTests.java b/core/src/test/java/org/elasticsearch/http/HttpServerTests.java index 828336c1603..9ed680a6fbe 100644 --- a/core/src/test/java/org/elasticsearch/http/HttpServerTests.java +++ b/core/src/test/java/org/elasticsearch/http/HttpServerTests.java @@ -18,7 +18,8 @@ */ package org.elasticsearch.http; -import org.elasticsearch.cluster.service.ClusterService; +import java.util.Map; + import org.elasticsearch.common.breaker.CircuitBreaker; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; @@ -32,7 +33,6 @@ import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService; -import org.elasticsearch.node.service.NodeService; import org.elasticsearch.rest.AbstractRestChannel; import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.RestController; @@ -42,10 +42,6 @@ import org.elasticsearch.rest.RestStatus; import org.elasticsearch.test.ESTestCase; import org.junit.Before; -import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; -import java.util.Map; - public class HttpServerTests extends ESTestCase { private static final ByteSizeValue BREAKER_LIMIT = new ByteSizeValue(20); private HttpServer httpServer; @@ -71,11 +67,7 @@ public class HttpServerTests extends ESTestCase { throw new IllegalArgumentException("test error"); }); - ClusterService clusterService = new ClusterService(Settings.EMPTY, - new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), null); - NodeService nodeService = new NodeService(Settings.EMPTY, null, null, null, null, null, null, null, null, - clusterService, null); - httpServer = new HttpServer(settings, httpServerTransport, restController, nodeService, null, circuitBreakerService); + httpServer = new HttpServer(settings, httpServerTransport, restController, null, circuitBreakerService); httpServer.start(); } From 62397c0c3d662932f0069e0d56f258f0754cc8b8 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Fri, 1 Jul 2016 12:55:41 -0700 Subject: [PATCH 2/2] Fix node service to still work when http is disabled --- .../elasticsearch/common/network/NetworkModule.java | 3 +++ .../org/elasticsearch/node/service/NodeService.java | 13 ++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/network/NetworkModule.java b/core/src/main/java/org/elasticsearch/common/network/NetworkModule.java index 2b94f224b9c..b65f568af8a 100644 --- a/core/src/main/java/org/elasticsearch/common/network/NetworkModule.java +++ b/core/src/main/java/org/elasticsearch/common/network/NetworkModule.java @@ -32,6 +32,7 @@ import org.elasticsearch.cluster.routing.allocation.command.CancelAllocationComm import org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.common.inject.util.Providers; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.settings.Setting; @@ -166,6 +167,8 @@ public class NetworkModule extends AbstractModule { if (HTTP_ENABLED.get(settings)) { bind(HttpServer.class).asEagerSingleton(); httpTransportTypes.bindType(binder(), settings, HTTP_TYPE_SETTING.getKey(), NETTY_TRANSPORT); + } else { + bind(HttpServer.class).toProvider(Providers.of(null)); } // Bind the AllocationCommandRegistry so RestClusterRerouteAction can get it. bind(AllocationCommandRegistry.class).toInstance(allocationCommandRegistry); diff --git a/core/src/main/java/org/elasticsearch/node/service/NodeService.java b/core/src/main/java/org/elasticsearch/node/service/NodeService.java index f3743a46d1e..8f938bcb22d 100644 --- a/core/src/main/java/org/elasticsearch/node/service/NodeService.java +++ b/core/src/main/java/org/elasticsearch/node/service/NodeService.java @@ -28,6 +28,7 @@ import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; import org.elasticsearch.action.admin.indices.stats.CommonStatsFlags; import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.common.Nullable; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; @@ -58,14 +59,16 @@ public class NodeService extends AbstractComponent implements Closeable { private final SettingsFilter settingsFilter; private ClusterService clusterService; private ScriptService scriptService; - private final HttpServer httpServer; + + @Nullable + private HttpServer httpServer; private final Discovery discovery; @Inject public NodeService(Settings settings, ThreadPool threadPool, MonitorService monitorService, Discovery discovery, TransportService transportService, IndicesService indicesService, - PluginsService pluginService, CircuitBreakerService circuitBreakerService, HttpServer httpServer, + PluginsService pluginService, CircuitBreakerService circuitBreakerService, @Nullable HttpServer httpServer, ProcessorsRegistry.Builder processorsRegistryBuilder, ClusterService clusterService, SettingsFilter settingsFilter) { super(settings); this.threadPool = threadPool; @@ -98,7 +101,7 @@ public class NodeService extends AbstractComponent implements Closeable { monitorService.jvmService().info(), threadPool.info(), transportService.info(), - httpServer.info(), + httpServer == null ? null : httpServer.info(), pluginService == null ? null : pluginService.info(), ingestService == null ? null : ingestService.info(), indicesService.getTotalIndexingBufferBytes() @@ -114,7 +117,7 @@ public class NodeService extends AbstractComponent implements Closeable { jvm ? monitorService.jvmService().info() : null, threadPool ? this.threadPool.info() : null, transport ? transportService.info() : null, - http ? httpServer.info() : null, + http ? (httpServer == null ? null : httpServer.info()) : null, plugin ? (pluginService == null ? null : pluginService.info()) : null, ingest ? (ingestService == null ? null : ingestService.info()) : null, indices ? indicesService.getTotalIndexingBufferBytes() : null @@ -132,7 +135,7 @@ public class NodeService extends AbstractComponent implements Closeable { threadPool.stats(), monitorService.fsService().stats(), transportService.stats(), - httpServer.stats(), + httpServer == null ? null : httpServer.stats(), circuitBreakerService.stats(), scriptService.stats(), discovery.stats(),