Merge pull request #15035 from s1monw/simplify_monitoring_service

Simplify MonitorService construction and detach from guice
This commit is contained in:
Simon Willnauer 2015-11-26 14:05:32 +01:00
commit 59be738e40
25 changed files with 78 additions and 123 deletions

View File

@ -38,7 +38,9 @@ import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.inject.ModulesBuilder; import org.elasticsearch.common.inject.ModulesBuilder;
import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.network.NetworkService;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.common.settings.SettingsModule;
import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.env.Environment; import org.elasticsearch.env.Environment;
@ -46,6 +48,7 @@ import org.elasticsearch.env.EnvironmentModule;
import org.elasticsearch.indices.breaker.CircuitBreakerModule; import org.elasticsearch.indices.breaker.CircuitBreakerModule;
import org.elasticsearch.monitor.MonitorService; import org.elasticsearch.monitor.MonitorService;
import org.elasticsearch.node.internal.InternalSettingsPreparer; import org.elasticsearch.node.internal.InternalSettingsPreparer;
import org.elasticsearch.node.settings.NodeSettingsService;
import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.plugins.PluginsModule; import org.elasticsearch.plugins.PluginsModule;
import org.elasticsearch.plugins.PluginsService; import org.elasticsearch.plugins.PluginsService;
@ -128,7 +131,8 @@ public class TransportClient extends AbstractClient {
Version version = Version.CURRENT; Version version = Version.CURRENT;
final ThreadPool threadPool = new ThreadPool(settings); final ThreadPool threadPool = new ThreadPool(settings);
final NetworkService networkService = new NetworkService(settings);
final SettingsFilter settingsFilter = new SettingsFilter(settings);
boolean success = false; boolean success = false;
try { try {
ModulesBuilder modules = new ModulesBuilder(); ModulesBuilder modules = new ModulesBuilder();
@ -138,8 +142,8 @@ public class TransportClient extends AbstractClient {
modules.add(pluginModule); modules.add(pluginModule);
} }
modules.add(new PluginsModule(pluginsService)); modules.add(new PluginsModule(pluginsService));
modules.add(new SettingsModule(this.settings)); modules.add(new SettingsModule(this.settings, settingsFilter ));
modules.add(new NetworkModule()); modules.add(new NetworkModule(networkService));
modules.add(new ClusterNameModule(this.settings)); modules.add(new ClusterNameModule(this.settings));
modules.add(new ThreadPoolModule(threadPool)); modules.add(new ThreadPoolModule(threadPool));
modules.add(new TransportModule(this.settings)); modules.add(new TransportModule(this.settings));

View File

@ -26,8 +26,14 @@ import org.elasticsearch.common.inject.AbstractModule;
*/ */
public class NetworkModule extends AbstractModule { public class NetworkModule extends AbstractModule {
private final NetworkService networkService;
public NetworkModule(NetworkService networkService) {
this.networkService = networkService;
}
@Override @Override
protected void configure() { protected void configure() {
bind(NetworkService.class).asEagerSingleton(); bind(NetworkService.class).toInstance(networkService);
} }
} }

View File

@ -20,7 +20,6 @@
package org.elasticsearch.common.network; package org.elasticsearch.common.network;
import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
@ -37,7 +36,7 @@ import java.util.concurrent.TimeUnit;
/** /**
* *
*/ */
public class NetworkService extends AbstractComponent { public final class NetworkService extends AbstractComponent {
/** By default, we bind to loopback interfaces */ /** By default, we bind to loopback interfaces */
public static final String DEFAULT_NETWORK_HOST = "_local_"; public static final String DEFAULT_NETWORK_HOST = "_local_";
@ -80,7 +79,6 @@ public class NetworkService extends AbstractComponent {
private final List<CustomNameResolver> customNameResolvers = new CopyOnWriteArrayList<>(); private final List<CustomNameResolver> customNameResolvers = new CopyOnWriteArrayList<>();
@Inject
public NetworkService(Settings settings) { public NetworkService(Settings settings) {
super(settings); super(settings);
IfConfig.logIfNecessary(); IfConfig.logIfNecessary();

View File

@ -20,7 +20,6 @@ package org.elasticsearch.common.settings;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.xcontent.ToXContent.Params; import org.elasticsearch.common.xcontent.ToXContent.Params;
import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequest;
@ -35,7 +34,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
/** /**
* *
*/ */
public class SettingsFilter extends AbstractComponent { public final class SettingsFilter extends AbstractComponent {
/** /**
* Can be used to specify settings filter that will be used to filter out matching settings in toXContent method * Can be used to specify settings filter that will be used to filter out matching settings in toXContent method
*/ */
@ -43,7 +42,6 @@ public class SettingsFilter extends AbstractComponent {
private final CopyOnWriteArrayList<String> patterns = new CopyOnWriteArrayList<>(); private final CopyOnWriteArrayList<String> patterns = new CopyOnWriteArrayList<>();
@Inject
public SettingsFilter(Settings settings) { public SettingsFilter(Settings settings) {
super(settings); super(settings);
} }

View File

@ -29,14 +29,16 @@ import org.elasticsearch.common.inject.AbstractModule;
public class SettingsModule extends AbstractModule { public class SettingsModule extends AbstractModule {
private final Settings settings; private final Settings settings;
private final SettingsFilter settingsFilter;
public SettingsModule(Settings settings) { public SettingsModule(Settings settings, SettingsFilter settingsFilter) {
this.settings = settings; this.settings = settings;
this.settingsFilter = settingsFilter;
} }
@Override @Override
protected void configure() { protected void configure() {
bind(Settings.class).toInstance(settings); bind(Settings.class).toInstance(settings);
bind(SettingsFilter.class).asEagerSingleton(); bind(SettingsFilter.class).toInstance(settingsFilter);
} }
} }

View File

@ -1,63 +0,0 @@
/*
* 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.monitor;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.monitor.fs.FsProbe;
import org.elasticsearch.monitor.fs.FsService;
import org.elasticsearch.monitor.jvm.JvmMonitorService;
import org.elasticsearch.monitor.jvm.JvmService;
import org.elasticsearch.monitor.os.OsProbe;
import org.elasticsearch.monitor.os.OsService;
import org.elasticsearch.monitor.process.ProcessProbe;
import org.elasticsearch.monitor.process.ProcessService;
/**
*
*/
public class MonitorModule extends AbstractModule {
public static final class MonitorSettings {
public static final String MEMORY_MANAGER_TYPE = "monitor.memory.type";
}
private final Settings settings;
public MonitorModule(Settings settings) {
this.settings = settings;
}
@Override
protected void configure() {
// bind default implementations
bind(ProcessProbe.class).toInstance(ProcessProbe.getInstance());
bind(OsProbe.class).toInstance(OsProbe.getInstance());
bind(FsProbe.class).asEagerSingleton();
// bind other services
bind(ProcessService.class).asEagerSingleton();
bind(OsService.class).asEagerSingleton();
bind(JvmService.class).asEagerSingleton();
bind(FsService.class).asEagerSingleton();
bind(JvmMonitorService.class).asEagerSingleton();
}
}

View File

@ -20,13 +20,16 @@
package org.elasticsearch.monitor; package org.elasticsearch.monitor;
import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.component.AbstractLifecycleComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.monitor.fs.FsService; import org.elasticsearch.monitor.fs.FsService;
import org.elasticsearch.monitor.jvm.JvmMonitorService; import org.elasticsearch.monitor.jvm.JvmMonitorService;
import org.elasticsearch.monitor.jvm.JvmService; import org.elasticsearch.monitor.jvm.JvmService;
import org.elasticsearch.monitor.os.OsService; import org.elasticsearch.monitor.os.OsService;
import org.elasticsearch.monitor.process.ProcessService; import org.elasticsearch.monitor.process.ProcessService;
import org.elasticsearch.threadpool.ThreadPool;
import java.io.IOException;
/** /**
* *
@ -43,16 +46,13 @@ public class MonitorService extends AbstractLifecycleComponent<MonitorService> {
private final FsService fsService; private final FsService fsService;
@Inject public MonitorService(Settings settings, NodeEnvironment nodeEnvironment, ThreadPool threadPool) throws IOException {
public MonitorService(Settings settings, JvmMonitorService jvmMonitorService,
OsService osService, ProcessService processService, JvmService jvmService,
FsService fsService) {
super(settings); super(settings);
this.jvmMonitorService = jvmMonitorService; this.jvmMonitorService = new JvmMonitorService(settings, threadPool);
this.osService = osService; this.osService = new OsService(settings);
this.processService = processService; this.processService = new ProcessService(settings);
this.jvmService = jvmService; this.jvmService = new JvmService(settings);
this.fsService = fsService; this.fsService = new FsService(settings, nodeEnvironment);
} }
public OsService osService() { public OsService osService() {

View File

@ -20,7 +20,6 @@
package org.elasticsearch.monitor.fs; package org.elasticsearch.monitor.fs;
import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.env.NodeEnvironment.NodePath; import org.elasticsearch.env.NodeEnvironment.NodePath;
@ -31,7 +30,6 @@ public class FsProbe extends AbstractComponent {
private final NodeEnvironment nodeEnv; private final NodeEnvironment nodeEnv;
@Inject
public FsProbe(Settings settings, NodeEnvironment nodeEnv) { public FsProbe(Settings settings, NodeEnvironment nodeEnv) {
super(settings); super(settings);
this.nodeEnv = nodeEnv; this.nodeEnv = nodeEnv;

View File

@ -20,10 +20,10 @@
package org.elasticsearch.monitor.fs; package org.elasticsearch.monitor.fs;
import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.SingleObjectCache; import org.elasticsearch.common.util.SingleObjectCache;
import org.elasticsearch.env.NodeEnvironment;
import java.io.IOException; import java.io.IOException;
@ -35,10 +35,9 @@ public class FsService extends AbstractComponent {
private final SingleObjectCache<FsInfo> fsStatsCache; private final SingleObjectCache<FsInfo> fsStatsCache;
@Inject public FsService(Settings settings, NodeEnvironment nodeEnvironment) throws IOException {
public FsService(Settings settings, FsProbe probe) throws IOException {
super(settings); super(settings);
this.probe = probe; this.probe = new FsProbe(settings, nodeEnvironment);
TimeValue refreshInterval = settings.getAsTime("monitor.fs.refresh_interval", TimeValue.timeValueSeconds(1)); TimeValue refreshInterval = settings.getAsTime("monitor.fs.refresh_interval", TimeValue.timeValueSeconds(1));
fsStatsCache = new FsInfoCache(refreshInterval, probe.stats()); fsStatsCache = new FsInfoCache(refreshInterval, probe.stats());
logger.debug("Using probe [{}] with refresh_interval [{}]", probe, refreshInterval); logger.debug("Using probe [{}] with refresh_interval [{}]", probe, refreshInterval);

View File

@ -20,7 +20,6 @@
package org.elasticsearch.monitor.jvm; package org.elasticsearch.monitor.jvm;
import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.component.AbstractLifecycleComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.concurrent.FutureUtils; import org.elasticsearch.common.util.concurrent.FutureUtils;
@ -71,7 +70,6 @@ public class JvmMonitorService extends AbstractLifecycleComponent<JvmMonitorServ
} }
} }
@Inject
public JvmMonitorService(Settings settings, ThreadPool threadPool) { public JvmMonitorService(Settings settings, ThreadPool threadPool) {
super(settings); super(settings);
this.threadPool = threadPool; this.threadPool = threadPool;

View File

@ -20,7 +20,6 @@
package org.elasticsearch.monitor.jvm; package org.elasticsearch.monitor.jvm;
import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
@ -35,7 +34,6 @@ public class JvmService extends AbstractComponent {
private JvmStats jvmStats; private JvmStats jvmStats;
@Inject
public JvmService(Settings settings) { public JvmService(Settings settings) {
super(settings); super(settings);
this.jvmInfo = JvmInfo.jvmInfo(); this.jvmInfo = JvmInfo.jvmInfo();

View File

@ -20,7 +20,6 @@
package org.elasticsearch.monitor.os; package org.elasticsearch.monitor.os;
import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.SingleObjectCache; import org.elasticsearch.common.util.SingleObjectCache;
@ -37,10 +36,9 @@ public class OsService extends AbstractComponent {
private SingleObjectCache<OsStats> osStatsCache; private SingleObjectCache<OsStats> osStatsCache;
@Inject public OsService(Settings settings) {
public OsService(Settings settings, OsProbe probe) {
super(settings); super(settings);
this.probe = probe; this.probe = OsProbe.getInstance();
TimeValue refreshInterval = settings.getAsTime("monitor.os.refresh_interval", TimeValue.timeValueSeconds(1)); TimeValue refreshInterval = settings.getAsTime("monitor.os.refresh_interval", TimeValue.timeValueSeconds(1));

View File

@ -20,7 +20,6 @@
package org.elasticsearch.monitor.process; package org.elasticsearch.monitor.process;
import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.SingleObjectCache; import org.elasticsearch.common.util.SingleObjectCache;
@ -34,10 +33,9 @@ public final class ProcessService extends AbstractComponent {
private final ProcessInfo info; private final ProcessInfo info;
private final SingleObjectCache<ProcessStats> processStatsCache; private final SingleObjectCache<ProcessStats> processStatsCache;
@Inject public ProcessService(Settings settings) {
public ProcessService(Settings settings, ProcessProbe probe) {
super(settings); super(settings);
this.probe = probe; this.probe = ProcessProbe.getInstance();
final TimeValue refreshInterval = settings.getAsTime("monitor.process.refresh_interval", TimeValue.timeValueSeconds(1)); final TimeValue refreshInterval = settings.getAsTime("monitor.process.refresh_interval", TimeValue.timeValueSeconds(1));
processStatsCache = new ProcessStatsCache(refreshInterval, probe.processStats()); processStatsCache = new ProcessStatsCache(refreshInterval, probe.processStats());

View File

@ -20,8 +20,10 @@
package org.elasticsearch.node; package org.elasticsearch.node;
import org.elasticsearch.Build; import org.elasticsearch.Build;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.action.ActionModule; import org.elasticsearch.action.ActionModule;
import org.elasticsearch.bootstrap.Elasticsearch;
import org.elasticsearch.cache.recycler.PageCacheRecycler; import org.elasticsearch.cache.recycler.PageCacheRecycler;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.client.node.NodeClientModule; import org.elasticsearch.client.node.NodeClientModule;
@ -41,7 +43,9 @@ import org.elasticsearch.common.lease.Releasables;
import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.network.NetworkService;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.common.settings.SettingsModule;
import org.elasticsearch.discovery.Discovery; import org.elasticsearch.discovery.Discovery;
import org.elasticsearch.discovery.DiscoveryModule; import org.elasticsearch.discovery.DiscoveryModule;
@ -66,7 +70,6 @@ import org.elasticsearch.indices.memory.IndexingMemoryController;
import org.elasticsearch.indices.recovery.RecoverySettings; import org.elasticsearch.indices.recovery.RecoverySettings;
import org.elasticsearch.indices.store.IndicesStore; import org.elasticsearch.indices.store.IndicesStore;
import org.elasticsearch.indices.ttl.IndicesTTLService; import org.elasticsearch.indices.ttl.IndicesTTLService;
import org.elasticsearch.monitor.MonitorModule;
import org.elasticsearch.monitor.MonitorService; import org.elasticsearch.monitor.MonitorService;
import org.elasticsearch.monitor.jvm.JvmInfo; import org.elasticsearch.monitor.jvm.JvmInfo;
import org.elasticsearch.node.internal.InternalSettingsPreparer; import org.elasticsearch.node.internal.InternalSettingsPreparer;
@ -155,11 +158,13 @@ public class Node implements Releasable {
} catch (IOException ex) { } catch (IOException ex) {
throw new IllegalStateException("Failed to created node environment", ex); throw new IllegalStateException("Failed to created node environment", ex);
} }
final NetworkService networkService = new NetworkService(settings);
final NodeSettingsService nodeSettingsService = new NodeSettingsService(settings);
final SettingsFilter settingsFilter = new SettingsFilter(settings);
final ThreadPool threadPool = new ThreadPool(settings); final ThreadPool threadPool = new ThreadPool(settings);
boolean success = false; boolean success = false;
try { try {
final MonitorService monitorService = new MonitorService(settings, nodeEnvironment, threadPool);
ModulesBuilder modules = new ModulesBuilder(); ModulesBuilder modules = new ModulesBuilder();
modules.add(new Version.Module(version)); modules.add(new Version.Module(version));
modules.add(new CircuitBreakerModule(settings)); modules.add(new CircuitBreakerModule(settings));
@ -168,9 +173,9 @@ public class Node implements Releasable {
modules.add(pluginModule); modules.add(pluginModule);
} }
modules.add(new PluginsModule(pluginsService)); modules.add(new PluginsModule(pluginsService));
modules.add(new SettingsModule(this.settings)); modules.add(new SettingsModule(this.settings, settingsFilter));
modules.add(new NodeModule(this)); modules.add(new NodeModule(this, nodeSettingsService, monitorService));
modules.add(new NetworkModule()); modules.add(new NetworkModule(networkService));
modules.add(new ScriptModule(this.settings)); modules.add(new ScriptModule(this.settings));
modules.add(new EnvironmentModule(environment)); modules.add(new EnvironmentModule(environment));
modules.add(new NodeEnvironmentModule(nodeEnvironment)); modules.add(new NodeEnvironmentModule(nodeEnvironment));
@ -186,7 +191,6 @@ public class Node implements Releasable {
modules.add(new IndicesModule()); modules.add(new IndicesModule());
modules.add(new SearchModule()); modules.add(new SearchModule());
modules.add(new ActionModule(false)); modules.add(new ActionModule(false));
modules.add(new MonitorModule(settings));
modules.add(new GatewayModule(settings)); modules.add(new GatewayModule(settings));
modules.add(new NodeClientModule()); modules.add(new NodeClientModule());
modules.add(new PercolatorModule()); modules.add(new PercolatorModule());
@ -195,7 +199,6 @@ public class Node implements Releasable {
modules.add(new TribeModule()); modules.add(new TribeModule());
modules.add(new AnalysisModule(environment)); modules.add(new AnalysisModule(environment));
pluginsService.processModules(modules); pluginsService.processModules(modules);
injector = modules.createInjector(); injector = modules.createInjector();
@ -203,6 +206,8 @@ public class Node implements Releasable {
client = injector.getInstance(Client.class); client = injector.getInstance(Client.class);
threadPool.setNodeSettingsService(injector.getInstance(NodeSettingsService.class)); threadPool.setNodeSettingsService(injector.getInstance(NodeSettingsService.class));
success = true; success = true;
} catch (IOException ex) {
throw new ElasticsearchException("failed to bind service", ex);
} finally { } finally {
if (!success) { if (!success) {
nodeEnvironment.close(); nodeEnvironment.close();

View File

@ -22,6 +22,7 @@ package org.elasticsearch.node;
import org.elasticsearch.cache.recycler.PageCacheRecycler; import org.elasticsearch.cache.recycler.PageCacheRecycler;
import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.monitor.MonitorService;
import org.elasticsearch.node.Node; import org.elasticsearch.node.Node;
import org.elasticsearch.node.service.NodeService; import org.elasticsearch.node.service.NodeService;
import org.elasticsearch.node.settings.NodeSettingsService; import org.elasticsearch.node.settings.NodeSettingsService;
@ -32,13 +33,17 @@ import org.elasticsearch.node.settings.NodeSettingsService;
public class NodeModule extends AbstractModule { public class NodeModule extends AbstractModule {
private final Node node; private final Node node;
private final NodeSettingsService nodeSettingsService;
private final MonitorService monitorService;
// pkg private so tests can mock // pkg private so tests can mock
Class<? extends PageCacheRecycler> pageCacheRecyclerImpl = PageCacheRecycler.class; Class<? extends PageCacheRecycler> pageCacheRecyclerImpl = PageCacheRecycler.class;
Class<? extends BigArrays> bigArraysImpl = BigArrays.class; Class<? extends BigArrays> bigArraysImpl = BigArrays.class;
public NodeModule(Node node) { public NodeModule(Node node, NodeSettingsService nodeSettingsService, MonitorService monitorService) {
this.node = node; this.node = node;
this.nodeSettingsService = nodeSettingsService;
this.monitorService = monitorService;
} }
@Override @Override
@ -55,7 +60,8 @@ public class NodeModule extends AbstractModule {
} }
bind(Node.class).toInstance(node); bind(Node.class).toInstance(node);
bind(NodeSettingsService.class).asEagerSingleton(); bind(NodeSettingsService.class).toInstance(nodeSettingsService);
bind(MonitorService.class).toInstance(monitorService);
bind(NodeService.class).asEagerSingleton(); bind(NodeService.class).asEagerSingleton();
} }
} }

View File

@ -57,6 +57,7 @@ import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.common.settings.SettingsModule;
import org.elasticsearch.common.unit.Fuzziness; import org.elasticsearch.common.unit.Fuzziness;
import org.elasticsearch.common.xcontent.*; import org.elasticsearch.common.xcontent.*;
@ -183,7 +184,7 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
clientInvocationHandler); clientInvocationHandler);
injector = new ModulesBuilder().add( injector = new ModulesBuilder().add(
new EnvironmentModule(new Environment(settings)), new EnvironmentModule(new Environment(settings)),
new SettingsModule(settings), new SettingsModule(settings, new SettingsFilter(settings)),
new ThreadPoolModule(new ThreadPool(settings)), new ThreadPoolModule(new ThreadPool(settings)),
new IndicesModule() { new IndicesModule() {
@Override @Override

View File

@ -32,6 +32,7 @@ import org.elasticsearch.common.inject.ModulesBuilder;
import org.elasticsearch.common.inject.multibindings.Multibinder; import org.elasticsearch.common.inject.multibindings.Multibinder;
import org.elasticsearch.common.inject.util.Providers; import org.elasticsearch.common.inject.util.Providers;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.common.settings.SettingsModule;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -95,7 +96,7 @@ public class TemplateQueryParserTests extends ESTestCase {
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings(index, settings); IndexSettings idxSettings = IndexSettingsModule.newIndexSettings(index, settings);
injector = new ModulesBuilder().add( injector = new ModulesBuilder().add(
new EnvironmentModule(new Environment(settings)), new EnvironmentModule(new Environment(settings)),
new SettingsModule(settings), new SettingsModule(settings, new SettingsFilter(settings)),
new ThreadPoolModule(new ThreadPool(settings)), new ThreadPoolModule(new ThreadPool(settings)),
new IndicesModule() { new IndicesModule() {
@Override @Override

View File

@ -24,6 +24,7 @@ import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.inject.Injector; import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.inject.ModulesBuilder; import org.elasticsearch.common.inject.ModulesBuilder;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.common.settings.SettingsModule;
import org.elasticsearch.env.Environment; import org.elasticsearch.env.Environment;
import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.env.EnvironmentModule;
@ -55,7 +56,7 @@ public class NativeScriptTests extends ESTestCase {
Injector injector = new ModulesBuilder().add( Injector injector = new ModulesBuilder().add(
new EnvironmentModule(new Environment(settings)), new EnvironmentModule(new Environment(settings)),
new ThreadPoolModule(new ThreadPool(settings)), new ThreadPoolModule(new ThreadPool(settings)),
new SettingsModule(settings), new SettingsModule(settings, new SettingsFilter(settings)),
scriptModule).createInjector(); scriptModule).createInjector();
ScriptService scriptService = injector.getInstance(ScriptService.class); ScriptService scriptService = injector.getInstance(ScriptService.class);

View File

@ -31,6 +31,7 @@ import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.common.settings.SettingsModule;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.*; import org.elasticsearch.common.xcontent.*;
@ -79,7 +80,7 @@ public class SearchSourceBuilderTests extends ESTestCase {
.put("path.home", createTempDir()) .put("path.home", createTempDir())
.build(); .build();
injector = new ModulesBuilder().add( injector = new ModulesBuilder().add(
new SettingsModule(settings), new SettingsModule(settings, new SettingsFilter(settings)),
new ThreadPoolModule(new ThreadPool(settings)), new ThreadPoolModule(new ThreadPool(settings)),
new IndicesModule() { new IndicesModule() {
@Override @Override

View File

@ -24,6 +24,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.inject.Injector; import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.inject.ModulesBuilder; import org.elasticsearch.common.inject.ModulesBuilder;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.common.settings.SettingsModule;
import org.elasticsearch.env.Environment; import org.elasticsearch.env.Environment;
import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.env.EnvironmentModule;
@ -45,7 +46,7 @@ public class AnalysisTestUtils {
.build(); .build();
AnalysisModule analysisModule = new AnalysisModule(new Environment(settings)); AnalysisModule analysisModule = new AnalysisModule(new Environment(settings));
new AnalysisICUPlugin().onModule(analysisModule); new AnalysisICUPlugin().onModule(analysisModule);
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings, new SettingsFilter(settings)),
new EnvironmentModule(new Environment(settings)), analysisModule) new EnvironmentModule(new Environment(settings)), analysisModule)
.createInjector(); .createInjector();
final AnalysisService analysisService = parentInjector.getInstance(AnalysisRegistry.class).build(IndexSettingsModule.newIndexSettings(index, indexSettings)); final AnalysisService analysisService = parentInjector.getInstance(AnalysisRegistry.class).build(IndexSettingsModule.newIndexSettings(index, indexSettings));

View File

@ -29,6 +29,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.inject.Injector; import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.inject.ModulesBuilder; import org.elasticsearch.common.inject.ModulesBuilder;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.common.settings.SettingsModule;
import org.elasticsearch.env.Environment; import org.elasticsearch.env.Environment;
import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.env.EnvironmentModule;
@ -203,7 +204,7 @@ public class KuromojiAnalysisTests extends ESTestCase {
AnalysisModule analysisModule = new AnalysisModule(new Environment(settings)); AnalysisModule analysisModule = new AnalysisModule(new Environment(settings));
new AnalysisKuromojiPlugin().onModule(analysisModule); new AnalysisKuromojiPlugin().onModule(analysisModule);
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings, new SettingsFilter(settings)),
new EnvironmentModule(new Environment(settings)), analysisModule) new EnvironmentModule(new Environment(settings)), analysisModule)
.createInjector(); .createInjector();

View File

@ -24,6 +24,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.inject.Injector; import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.inject.ModulesBuilder; import org.elasticsearch.common.inject.ModulesBuilder;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.common.settings.SettingsModule;
import org.elasticsearch.env.Environment; import org.elasticsearch.env.Environment;
import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.env.EnvironmentModule;
@ -57,7 +58,7 @@ public class SimplePhoneticAnalysisTests extends ESTestCase {
Index index = new Index("test"); Index index = new Index("test");
AnalysisModule analysisModule = new AnalysisModule(new Environment(settings)); AnalysisModule analysisModule = new AnalysisModule(new Environment(settings));
new AnalysisPhoneticPlugin().onModule(analysisModule); new AnalysisPhoneticPlugin().onModule(analysisModule);
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings, new SettingsFilter(settings)),
new EnvironmentModule(new Environment(settings)), analysisModule) new EnvironmentModule(new Environment(settings)), analysisModule)
.createInjector(); .createInjector();
return parentInjector.getInstance(AnalysisRegistry.class).build(IndexSettingsModule.newIndexSettings(index, settings)); return parentInjector.getInstance(AnalysisRegistry.class).build(IndexSettingsModule.newIndexSettings(index, settings));

View File

@ -24,6 +24,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.inject.Injector; import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.inject.ModulesBuilder; import org.elasticsearch.common.inject.ModulesBuilder;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.common.settings.SettingsModule;
import org.elasticsearch.env.Environment; import org.elasticsearch.env.Environment;
import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.env.EnvironmentModule;
@ -50,7 +51,7 @@ public class SimpleSmartChineseAnalysisTests extends ESTestCase {
.build(); .build();
AnalysisModule analysisModule = new AnalysisModule(new Environment(settings)); AnalysisModule analysisModule = new AnalysisModule(new Environment(settings));
new AnalysisSmartChinesePlugin().onModule(analysisModule); new AnalysisSmartChinesePlugin().onModule(analysisModule);
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings, new SettingsFilter(settings)),
new EnvironmentModule(new Environment(settings)), analysisModule) new EnvironmentModule(new Environment(settings)), analysisModule)
.createInjector(); .createInjector();
final AnalysisService analysisService = parentInjector.getInstance(AnalysisRegistry.class).build(IndexSettingsModule.newIndexSettings(index, settings)); final AnalysisService analysisService = parentInjector.getInstance(AnalysisRegistry.class).build(IndexSettingsModule.newIndexSettings(index, settings));

View File

@ -26,6 +26,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.inject.Injector; import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.inject.ModulesBuilder; import org.elasticsearch.common.inject.ModulesBuilder;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.common.settings.SettingsModule;
import org.elasticsearch.env.Environment; import org.elasticsearch.env.Environment;
import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.env.EnvironmentModule;
@ -55,7 +56,7 @@ public class PolishAnalysisTests extends ESTestCase {
AnalysisModule analysisModule = new AnalysisModule(new Environment(settings)); AnalysisModule analysisModule = new AnalysisModule(new Environment(settings));
new AnalysisStempelPlugin().onModule(analysisModule); new AnalysisStempelPlugin().onModule(analysisModule);
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings, new SettingsFilter(settings)),
new EnvironmentModule(new Environment(settings)), analysisModule) new EnvironmentModule(new Environment(settings)), analysisModule)
.createInjector(); .createInjector();

View File

@ -29,6 +29,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.inject.Injector; import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.inject.ModulesBuilder; import org.elasticsearch.common.inject.ModulesBuilder;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.common.settings.SettingsModule;
import org.elasticsearch.env.Environment; import org.elasticsearch.env.Environment;
import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.env.EnvironmentModule;
@ -99,7 +100,7 @@ public class SimplePolishTokenFilterTests extends ESTestCase {
private AnalysisService createAnalysisService(Index index, Settings settings) throws IOException { private AnalysisService createAnalysisService(Index index, Settings settings) throws IOException {
AnalysisModule analysisModule = new AnalysisModule(new Environment(settings)); AnalysisModule analysisModule = new AnalysisModule(new Environment(settings));
new AnalysisStempelPlugin().onModule(analysisModule); new AnalysisStempelPlugin().onModule(analysisModule);
Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings), Injector parentInjector = new ModulesBuilder().add(new SettingsModule(settings, new SettingsFilter(settings)),
new EnvironmentModule(new Environment(settings)), analysisModule) new EnvironmentModule(new Environment(settings)), analysisModule)
.createInjector(); .createInjector();
return parentInjector.getInstance(AnalysisRegistry.class).build(IndexSettingsModule.newIndexSettings(index, settings)); return parentInjector.getInstance(AnalysisRegistry.class).build(IndexSettingsModule.newIndexSettings(index, settings));