Remove (again) test uses of onModule (#21414)
This change was reverted after it caused random test failures. This was due to a copy/paste error in the original PR which caused the mock version of ClusterInfoService to be used whenever the mock *ZenPing* was used, and the real ClusterInfoService to be used when MockZenPing was not used.
This commit is contained in:
parent
7ed195fe93
commit
48bfb142b9
|
@ -86,9 +86,6 @@ public class ClusterModule extends AbstractModule {
|
||||||
final Collection<AllocationDecider> allocationDeciders;
|
final Collection<AllocationDecider> allocationDeciders;
|
||||||
final ShardsAllocator shardsAllocator;
|
final ShardsAllocator shardsAllocator;
|
||||||
|
|
||||||
// pkg private so tests can mock
|
|
||||||
Class<? extends ClusterInfoService> clusterInfoServiceImpl = InternalClusterInfoService.class;
|
|
||||||
|
|
||||||
public ClusterModule(Settings settings, ClusterService clusterService, List<ClusterPlugin> clusterPlugins) {
|
public ClusterModule(Settings settings, ClusterService clusterService, List<ClusterPlugin> clusterPlugins) {
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
this.allocationDeciders = createAllocationDeciders(settings, clusterService.getClusterSettings(), clusterPlugins);
|
this.allocationDeciders = createAllocationDeciders(settings, clusterService.getClusterSettings(), clusterPlugins);
|
||||||
|
@ -159,7 +156,6 @@ public class ClusterModule extends AbstractModule {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(ClusterInfoService.class).to(clusterInfoServiceImpl).asEagerSingleton();
|
|
||||||
bind(GatewayAllocator.class).asEagerSingleton();
|
bind(GatewayAllocator.class).asEagerSingleton();
|
||||||
bind(AllocationService.class).asEagerSingleton();
|
bind(AllocationService.class).asEagerSingleton();
|
||||||
bind(ClusterService.class).toInstance(clusterService);
|
bind(ClusterService.class).toInstance(clusterService);
|
||||||
|
|
|
@ -19,17 +19,21 @@
|
||||||
|
|
||||||
package org.elasticsearch.cluster;
|
package org.elasticsearch.cluster;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.elasticsearch.action.ActionListener;
|
import org.elasticsearch.action.ActionListener;
|
||||||
import org.elasticsearch.action.LatchedActionListener;
|
import org.elasticsearch.action.LatchedActionListener;
|
||||||
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
|
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
|
||||||
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest;
|
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest;
|
||||||
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse;
|
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse;
|
||||||
import org.elasticsearch.action.admin.cluster.node.stats.TransportNodesStatsAction;
|
|
||||||
import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest;
|
import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest;
|
||||||
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
|
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
|
||||||
import org.elasticsearch.action.admin.indices.stats.ShardStats;
|
import org.elasticsearch.action.admin.indices.stats.ShardStats;
|
||||||
import org.elasticsearch.action.admin.indices.stats.TransportIndicesStatsAction;
|
import org.elasticsearch.client.node.NodeClient;
|
||||||
import org.elasticsearch.cluster.block.ClusterBlockException;
|
import org.elasticsearch.cluster.block.ClusterBlockException;
|
||||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||||
import org.elasticsearch.cluster.metadata.MetaData;
|
import org.elasticsearch.cluster.metadata.MetaData;
|
||||||
|
@ -39,7 +43,6 @@ import org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings;
|
||||||
import org.elasticsearch.cluster.service.ClusterService;
|
import org.elasticsearch.cluster.service.ClusterService;
|
||||||
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
||||||
import org.elasticsearch.common.component.AbstractComponent;
|
import org.elasticsearch.common.component.AbstractComponent;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
|
||||||
import org.elasticsearch.common.settings.ClusterSettings;
|
import org.elasticsearch.common.settings.ClusterSettings;
|
||||||
import org.elasticsearch.common.settings.Setting;
|
import org.elasticsearch.common.settings.Setting;
|
||||||
import org.elasticsearch.common.settings.Setting.Property;
|
import org.elasticsearch.common.settings.Setting.Property;
|
||||||
|
@ -50,11 +53,6 @@ import org.elasticsearch.monitor.fs.FsInfo;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
import org.elasticsearch.transport.ReceiveTimeoutTransportException;
|
import org.elasticsearch.transport.ReceiveTimeoutTransportException;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* InternalClusterInfoService provides the ClusterInfoService interface,
|
* InternalClusterInfoService provides the ClusterInfoService interface,
|
||||||
* routinely updated on a timer. The timer can be dynamically changed by
|
* routinely updated on a timer. The timer can be dynamically changed by
|
||||||
|
@ -84,29 +82,24 @@ public class InternalClusterInfoService extends AbstractComponent implements Clu
|
||||||
private volatile boolean isMaster = false;
|
private volatile boolean isMaster = false;
|
||||||
private volatile boolean enabled;
|
private volatile boolean enabled;
|
||||||
private volatile TimeValue fetchTimeout;
|
private volatile TimeValue fetchTimeout;
|
||||||
private final TransportNodesStatsAction transportNodesStatsAction;
|
|
||||||
private final TransportIndicesStatsAction transportIndicesStatsAction;
|
|
||||||
private final ClusterService clusterService;
|
private final ClusterService clusterService;
|
||||||
private final ThreadPool threadPool;
|
private final ThreadPool threadPool;
|
||||||
|
private final NodeClient client;
|
||||||
private final List<Listener> listeners = new CopyOnWriteArrayList<>();
|
private final List<Listener> listeners = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
@Inject
|
public InternalClusterInfoService(Settings settings, ClusterService clusterService, ThreadPool threadPool, NodeClient client) {
|
||||||
public InternalClusterInfoService(Settings settings, ClusterSettings clusterSettings,
|
|
||||||
TransportNodesStatsAction transportNodesStatsAction,
|
|
||||||
TransportIndicesStatsAction transportIndicesStatsAction, ClusterService clusterService,
|
|
||||||
ThreadPool threadPool) {
|
|
||||||
super(settings);
|
super(settings);
|
||||||
this.leastAvailableSpaceUsages = ImmutableOpenMap.of();
|
this.leastAvailableSpaceUsages = ImmutableOpenMap.of();
|
||||||
this.mostAvailableSpaceUsages = ImmutableOpenMap.of();
|
this.mostAvailableSpaceUsages = ImmutableOpenMap.of();
|
||||||
this.shardRoutingToDataPath = ImmutableOpenMap.of();
|
this.shardRoutingToDataPath = ImmutableOpenMap.of();
|
||||||
this.shardSizes = ImmutableOpenMap.of();
|
this.shardSizes = ImmutableOpenMap.of();
|
||||||
this.transportNodesStatsAction = transportNodesStatsAction;
|
|
||||||
this.transportIndicesStatsAction = transportIndicesStatsAction;
|
|
||||||
this.clusterService = clusterService;
|
this.clusterService = clusterService;
|
||||||
this.threadPool = threadPool;
|
this.threadPool = threadPool;
|
||||||
|
this.client = client;
|
||||||
this.updateFrequency = INTERNAL_CLUSTER_INFO_UPDATE_INTERVAL_SETTING.get(settings);
|
this.updateFrequency = INTERNAL_CLUSTER_INFO_UPDATE_INTERVAL_SETTING.get(settings);
|
||||||
this.fetchTimeout = INTERNAL_CLUSTER_INFO_TIMEOUT_SETTING.get(settings);
|
this.fetchTimeout = INTERNAL_CLUSTER_INFO_TIMEOUT_SETTING.get(settings);
|
||||||
this.enabled = DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED_SETTING.get(settings);
|
this.enabled = DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED_SETTING.get(settings);
|
||||||
|
ClusterSettings clusterSettings = clusterService.getClusterSettings();
|
||||||
clusterSettings.addSettingsUpdateConsumer(INTERNAL_CLUSTER_INFO_TIMEOUT_SETTING, this::setFetchTimeout);
|
clusterSettings.addSettingsUpdateConsumer(INTERNAL_CLUSTER_INFO_TIMEOUT_SETTING, this::setFetchTimeout);
|
||||||
clusterSettings.addSettingsUpdateConsumer(INTERNAL_CLUSTER_INFO_UPDATE_INTERVAL_SETTING, this::setUpdateFrequency);
|
clusterSettings.addSettingsUpdateConsumer(INTERNAL_CLUSTER_INFO_UPDATE_INTERVAL_SETTING, this::setUpdateFrequency);
|
||||||
clusterSettings.addSettingsUpdateConsumer(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED_SETTING, this::setEnabled);
|
clusterSettings.addSettingsUpdateConsumer(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED_SETTING, this::setEnabled);
|
||||||
|
@ -259,8 +252,7 @@ public class InternalClusterInfoService extends AbstractComponent implements Clu
|
||||||
nodesStatsRequest.clear();
|
nodesStatsRequest.clear();
|
||||||
nodesStatsRequest.fs(true);
|
nodesStatsRequest.fs(true);
|
||||||
nodesStatsRequest.timeout(fetchTimeout);
|
nodesStatsRequest.timeout(fetchTimeout);
|
||||||
|
client.admin().cluster().nodesStats(nodesStatsRequest, new LatchedActionListener<>(listener, latch));
|
||||||
transportNodesStatsAction.execute(nodesStatsRequest, new LatchedActionListener<>(listener, latch));
|
|
||||||
return latch;
|
return latch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,7 +266,7 @@ public class InternalClusterInfoService extends AbstractComponent implements Clu
|
||||||
indicesStatsRequest.clear();
|
indicesStatsRequest.clear();
|
||||||
indicesStatsRequest.store(true);
|
indicesStatsRequest.store(true);
|
||||||
|
|
||||||
transportIndicesStatsAction.execute(indicesStatsRequest, new LatchedActionListener<>(listener, latch));
|
client.admin().indices().stats(indicesStatsRequest, new LatchedActionListener<>(listener, latch));
|
||||||
return latch;
|
return latch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,9 +35,11 @@ import org.elasticsearch.action.support.TransportAction;
|
||||||
import org.elasticsearch.action.update.UpdateHelper;
|
import org.elasticsearch.action.update.UpdateHelper;
|
||||||
import org.elasticsearch.client.Client;
|
import org.elasticsearch.client.Client;
|
||||||
import org.elasticsearch.client.node.NodeClient;
|
import org.elasticsearch.client.node.NodeClient;
|
||||||
|
import org.elasticsearch.cluster.ClusterInfoService;
|
||||||
import org.elasticsearch.cluster.ClusterModule;
|
import org.elasticsearch.cluster.ClusterModule;
|
||||||
import org.elasticsearch.cluster.ClusterState;
|
import org.elasticsearch.cluster.ClusterState;
|
||||||
import org.elasticsearch.cluster.ClusterStateObserver;
|
import org.elasticsearch.cluster.ClusterStateObserver;
|
||||||
|
import org.elasticsearch.cluster.InternalClusterInfoService;
|
||||||
import org.elasticsearch.cluster.MasterNodeChangePredicate;
|
import org.elasticsearch.cluster.MasterNodeChangePredicate;
|
||||||
import org.elasticsearch.cluster.NodeConnectionsService;
|
import org.elasticsearch.cluster.NodeConnectionsService;
|
||||||
import org.elasticsearch.cluster.action.index.MappingUpdatedAction;
|
import org.elasticsearch.cluster.action.index.MappingUpdatedAction;
|
||||||
|
@ -315,6 +317,7 @@ public class Node implements Closeable {
|
||||||
for (final ExecutorBuilder<?> builder : threadPool.builders()) {
|
for (final ExecutorBuilder<?> builder : threadPool.builders()) {
|
||||||
additionalSettings.addAll(builder.getRegisteredSettings());
|
additionalSettings.addAll(builder.getRegisteredSettings());
|
||||||
}
|
}
|
||||||
|
client = new NodeClient(settings, threadPool);
|
||||||
final ResourceWatcherService resourceWatcherService = new ResourceWatcherService(settings, threadPool);
|
final ResourceWatcherService resourceWatcherService = new ResourceWatcherService(settings, threadPool);
|
||||||
final ScriptModule scriptModule = ScriptModule.create(settings, this.environment, resourceWatcherService,
|
final ScriptModule scriptModule = ScriptModule.create(settings, this.environment, resourceWatcherService,
|
||||||
pluginsService.filterPlugins(ScriptPlugin.class));
|
pluginsService.filterPlugins(ScriptPlugin.class));
|
||||||
|
@ -335,6 +338,7 @@ public class Node implements Closeable {
|
||||||
resourcesToClose.add(tribeService);
|
resourcesToClose.add(tribeService);
|
||||||
final IngestService ingestService = new IngestService(settings, threadPool, this.environment,
|
final IngestService ingestService = new IngestService(settings, threadPool, this.environment,
|
||||||
scriptModule.getScriptService(), analysisModule.getAnalysisRegistry(), pluginsService.filterPlugins(IngestPlugin.class));
|
scriptModule.getScriptService(), analysisModule.getAnalysisRegistry(), pluginsService.filterPlugins(IngestPlugin.class));
|
||||||
|
final ClusterInfoService clusterInfoService = newClusterInfoService(settings, clusterService, threadPool, client);
|
||||||
|
|
||||||
ModulesBuilder modules = new ModulesBuilder();
|
ModulesBuilder modules = new ModulesBuilder();
|
||||||
// plugin modules must be added here, before others or we can get crazy injection errors...
|
// plugin modules must be added here, before others or we can get crazy injection errors...
|
||||||
|
@ -370,7 +374,6 @@ public class Node implements Closeable {
|
||||||
.flatMap(Function.identity()).collect(Collectors.toList());
|
.flatMap(Function.identity()).collect(Collectors.toList());
|
||||||
final NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(namedWriteables);
|
final NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(namedWriteables);
|
||||||
final MetaStateService metaStateService = new MetaStateService(settings, nodeEnvironment);
|
final MetaStateService metaStateService = new MetaStateService(settings, nodeEnvironment);
|
||||||
client = new NodeClient(settings, threadPool);
|
|
||||||
final IndicesService indicesService = new IndicesService(settings, pluginsService, nodeEnvironment,
|
final IndicesService indicesService = new IndicesService(settings, pluginsService, nodeEnvironment,
|
||||||
settingsModule.getClusterSettings(), analysisModule.getAnalysisRegistry(), searchModule.getQueryParserRegistry(),
|
settingsModule.getClusterSettings(), analysisModule.getAnalysisRegistry(), searchModule.getQueryParserRegistry(),
|
||||||
clusterModule.getIndexNameExpressionResolver(), indicesModule.getMapperRegistry(), namedWriteableRegistry,
|
clusterModule.getIndexNameExpressionResolver(), indicesModule.getMapperRegistry(), namedWriteableRegistry,
|
||||||
|
@ -440,6 +443,7 @@ public class Node implements Closeable {
|
||||||
b.bind(UpdateHelper.class).toInstance(new UpdateHelper(settings, scriptModule.getScriptService()));
|
b.bind(UpdateHelper.class).toInstance(new UpdateHelper(settings, scriptModule.getScriptService()));
|
||||||
b.bind(MetaDataIndexUpgradeService.class).toInstance(new MetaDataIndexUpgradeService(settings,
|
b.bind(MetaDataIndexUpgradeService.class).toInstance(new MetaDataIndexUpgradeService(settings,
|
||||||
indicesModule.getMapperRegistry(), settingsModule.getIndexScopedSettings()));
|
indicesModule.getMapperRegistry(), settingsModule.getIndexScopedSettings()));
|
||||||
|
b.bind(ClusterInfoService.class).toInstance(clusterInfoService);
|
||||||
b.bind(Discovery.class).toInstance(discoveryModule.getDiscovery());
|
b.bind(Discovery.class).toInstance(discoveryModule.getDiscovery());
|
||||||
b.bind(ZenPing.class).toInstance(discoveryModule.getZenPing());
|
b.bind(ZenPing.class).toInstance(discoveryModule.getZenPing());
|
||||||
{
|
{
|
||||||
|
@ -909,4 +913,10 @@ public class Node implements Closeable {
|
||||||
protected Node newTribeClientNode(Settings settings, Collection<Class<? extends Plugin>> classpathPlugins) {
|
protected Node newTribeClientNode(Settings settings, Collection<Class<? extends Plugin>> classpathPlugins) {
|
||||||
return new Node(new Environment(settings), classpathPlugins);
|
return new Node(new Environment(settings), classpathPlugins);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Constructs a ClusterInfoService which may be mocked for tests. */
|
||||||
|
protected ClusterInfoService newClusterInfoService(Settings settings, ClusterService clusterService,
|
||||||
|
ThreadPool threadPool, NodeClient client) {
|
||||||
|
return new InternalClusterInfoService(settings, clusterService, threadPool, client);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import java.util.List;
|
||||||
|
|
||||||
import org.elasticsearch.action.ActionModule;
|
import org.elasticsearch.action.ActionModule;
|
||||||
import org.elasticsearch.client.Client;
|
import org.elasticsearch.client.Client;
|
||||||
|
import org.elasticsearch.cluster.ClusterModule;
|
||||||
import org.elasticsearch.cluster.metadata.MetaData;
|
import org.elasticsearch.cluster.metadata.MetaData;
|
||||||
import org.elasticsearch.cluster.service.ClusterService;
|
import org.elasticsearch.cluster.service.ClusterService;
|
||||||
import org.elasticsearch.common.component.LifecycleComponent;
|
import org.elasticsearch.common.component.LifecycleComponent;
|
||||||
|
@ -38,6 +39,7 @@ import org.elasticsearch.common.settings.SettingsModule;
|
||||||
import org.elasticsearch.discovery.DiscoveryModule;
|
import org.elasticsearch.discovery.DiscoveryModule;
|
||||||
import org.elasticsearch.index.IndexModule;
|
import org.elasticsearch.index.IndexModule;
|
||||||
import org.elasticsearch.indices.analysis.AnalysisModule;
|
import org.elasticsearch.indices.analysis.AnalysisModule;
|
||||||
|
import org.elasticsearch.repositories.RepositoriesModule;
|
||||||
import org.elasticsearch.script.ScriptModule;
|
import org.elasticsearch.script.ScriptModule;
|
||||||
import org.elasticsearch.script.ScriptService;
|
import org.elasticsearch.script.ScriptService;
|
||||||
import org.elasticsearch.search.SearchModule;
|
import org.elasticsearch.search.SearchModule;
|
||||||
|
@ -224,6 +226,24 @@ public abstract class Plugin {
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public final void onModule(NetworkModule module) {}
|
public final void onModule(NetworkModule module) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Old-style snapshot/restore extension point. {@code @Deprecated} and {@code final} to act as a signpost for plugin authors upgrading
|
||||||
|
* from 2.x.
|
||||||
|
*
|
||||||
|
* @deprecated implement {@link RepositoryPlugin} instead
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public final void onModule(RepositoriesModule module) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Old-style cluster extension point. {@code @Deprecated} and {@code final} to act as a signpost for plugin authors upgrading
|
||||||
|
* from 2.x.
|
||||||
|
*
|
||||||
|
* @deprecated implement {@link ClusterPlugin} instead
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public final void onModule(ClusterModule module) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Old-style discovery extension point. {@code @Deprecated} and {@code final} to act as a signpost for plugin authors upgrading
|
* Old-style discovery extension point. {@code @Deprecated} and {@code final} to act as a signpost for plugin authors upgrading
|
||||||
* from 2.x.
|
* from 2.x.
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
package org.elasticsearch.indices.memory.breaker;
|
package org.elasticsearch.indices.memory.breaker;
|
||||||
|
|
||||||
import org.apache.lucene.index.DirectoryReader;
|
import org.apache.lucene.index.DirectoryReader;
|
||||||
|
import org.apache.lucene.index.FilterDirectoryReader;
|
||||||
import org.apache.lucene.index.LeafReader;
|
import org.apache.lucene.index.LeafReader;
|
||||||
import org.elasticsearch.ElasticsearchException;
|
import org.elasticsearch.ElasticsearchException;
|
||||||
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
|
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
|
||||||
|
@ -39,16 +40,20 @@ import org.elasticsearch.index.query.QueryBuilders;
|
||||||
import org.elasticsearch.indices.IndicesService;
|
import org.elasticsearch.indices.IndicesService;
|
||||||
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
|
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
|
||||||
import org.elasticsearch.plugins.Plugin;
|
import org.elasticsearch.plugins.Plugin;
|
||||||
|
import org.elasticsearch.search.basic.SearchWithRandomExceptionsIT;
|
||||||
import org.elasticsearch.search.sort.SortOrder;
|
import org.elasticsearch.search.sort.SortOrder;
|
||||||
import org.elasticsearch.test.ESIntegTestCase;
|
import org.elasticsearch.test.ESIntegTestCase;
|
||||||
import org.elasticsearch.test.engine.MockEngineSupport;
|
import org.elasticsearch.test.engine.MockEngineSupport;
|
||||||
import org.elasticsearch.test.engine.ThrowingLeafReaderWrapper;
|
import org.elasticsearch.test.engine.ThrowingLeafReaderWrapper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAllSuccessful;
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAllSuccessful;
|
||||||
|
@ -60,7 +65,14 @@ import static org.hamcrest.Matchers.equalTo;
|
||||||
public class RandomExceptionCircuitBreakerIT extends ESIntegTestCase {
|
public class RandomExceptionCircuitBreakerIT extends ESIntegTestCase {
|
||||||
@Override
|
@Override
|
||||||
protected Collection<Class<? extends Plugin>> nodePlugins() {
|
protected Collection<Class<? extends Plugin>> nodePlugins() {
|
||||||
return Arrays.asList(RandomExceptionDirectoryReaderWrapper.TestPlugin.class, MockEngineFactoryPlugin.class);
|
return Arrays.asList(RandomExceptionDirectoryReaderWrapper.TestPlugin.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Collection<Class<? extends Plugin>> getMockPlugins() {
|
||||||
|
Set<Class<? extends Plugin>> mocks = new HashSet<>(super.getMockPlugins());
|
||||||
|
mocks.remove(MockEngineFactoryPlugin.class);
|
||||||
|
return mocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBreakerWithRandomExceptions() throws IOException, InterruptedException, ExecutionException {
|
public void testBreakerWithRandomExceptions() throws IOException, InterruptedException, ExecutionException {
|
||||||
|
@ -200,14 +212,19 @@ public class RandomExceptionCircuitBreakerIT extends ESIntegTestCase {
|
||||||
Setting.doubleSetting(EXCEPTION_TOP_LEVEL_RATIO_KEY, 0.1d, 0.0d, Property.IndexScope);
|
Setting.doubleSetting(EXCEPTION_TOP_LEVEL_RATIO_KEY, 0.1d, 0.0d, Property.IndexScope);
|
||||||
public static final Setting<Double> EXCEPTION_LOW_LEVEL_RATIO_SETTING =
|
public static final Setting<Double> EXCEPTION_LOW_LEVEL_RATIO_SETTING =
|
||||||
Setting.doubleSetting(EXCEPTION_LOW_LEVEL_RATIO_KEY, 0.1d, 0.0d, Property.IndexScope);
|
Setting.doubleSetting(EXCEPTION_LOW_LEVEL_RATIO_KEY, 0.1d, 0.0d, Property.IndexScope);
|
||||||
public static class TestPlugin extends Plugin {
|
public static class TestPlugin extends MockEngineFactoryPlugin {
|
||||||
@Override
|
@Override
|
||||||
public List<Setting<?>> getSettings() {
|
public List<Setting<?>> getSettings() {
|
||||||
return Arrays.asList(EXCEPTION_TOP_LEVEL_RATIO_SETTING, EXCEPTION_LOW_LEVEL_RATIO_SETTING);
|
List<Setting<?>> settings = new ArrayList<>();
|
||||||
|
settings.addAll(super.getSettings());
|
||||||
|
settings.add(EXCEPTION_TOP_LEVEL_RATIO_SETTING);
|
||||||
|
settings.add(EXCEPTION_LOW_LEVEL_RATIO_SETTING);
|
||||||
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onModule(MockEngineFactoryPlugin.MockEngineReaderModule module) {
|
@Override
|
||||||
module.setReaderClass(RandomExceptionDirectoryReaderWrapper.class);
|
protected Class<? extends FilterDirectoryReader> getReaderWrapperClass() {
|
||||||
|
return RandomExceptionDirectoryReaderWrapper.class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,10 +44,13 @@ import org.elasticsearch.test.engine.MockEngineSupport;
|
||||||
import org.elasticsearch.test.engine.ThrowingLeafReaderWrapper;
|
import org.elasticsearch.test.engine.ThrowingLeafReaderWrapper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||||
|
@ -56,7 +59,14 @@ public class SearchWithRandomExceptionsIT extends ESIntegTestCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Collection<Class<? extends Plugin>> nodePlugins() {
|
protected Collection<Class<? extends Plugin>> nodePlugins() {
|
||||||
return Arrays.asList(RandomExceptionDirectoryReaderWrapper.TestPlugin.class, MockEngineFactoryPlugin.class);
|
return Arrays.asList(RandomExceptionDirectoryReaderWrapper.TestPlugin.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Collection<Class<? extends Plugin>> getMockPlugins() {
|
||||||
|
Set<Class<? extends Plugin>> mocks = new HashSet<>(super.getMockPlugins());
|
||||||
|
mocks.remove(MockEngineFactoryPlugin.class);
|
||||||
|
return mocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRandomExceptions() throws IOException, InterruptedException, ExecutionException {
|
public void testRandomExceptions() throws IOException, InterruptedException, ExecutionException {
|
||||||
|
@ -153,17 +163,22 @@ public class SearchWithRandomExceptionsIT extends ESIntegTestCase {
|
||||||
|
|
||||||
public static class RandomExceptionDirectoryReaderWrapper extends MockEngineSupport.DirectoryReaderWrapper {
|
public static class RandomExceptionDirectoryReaderWrapper extends MockEngineSupport.DirectoryReaderWrapper {
|
||||||
|
|
||||||
public static class TestPlugin extends Plugin {
|
public static class TestPlugin extends MockEngineFactoryPlugin {
|
||||||
public static final Setting<Double> EXCEPTION_TOP_LEVEL_RATIO_SETTING =
|
public static final Setting<Double> EXCEPTION_TOP_LEVEL_RATIO_SETTING =
|
||||||
Setting.doubleSetting(EXCEPTION_TOP_LEVEL_RATIO_KEY, 0.1d, 0.0d, Property.IndexScope);
|
Setting.doubleSetting(EXCEPTION_TOP_LEVEL_RATIO_KEY, 0.1d, 0.0d, Property.IndexScope);
|
||||||
public static final Setting<Double> EXCEPTION_LOW_LEVEL_RATIO_SETTING =
|
public static final Setting<Double> EXCEPTION_LOW_LEVEL_RATIO_SETTING =
|
||||||
Setting.doubleSetting(EXCEPTION_LOW_LEVEL_RATIO_KEY, 0.1d, 0.0d, Property.IndexScope);
|
Setting.doubleSetting(EXCEPTION_LOW_LEVEL_RATIO_KEY, 0.1d, 0.0d, Property.IndexScope);
|
||||||
@Override
|
@Override
|
||||||
public List<Setting<?>> getSettings() {
|
public List<Setting<?>> getSettings() {
|
||||||
return Arrays.asList(EXCEPTION_TOP_LEVEL_RATIO_SETTING, EXCEPTION_LOW_LEVEL_RATIO_SETTING);
|
List<Setting<?>> settings = new ArrayList<>();
|
||||||
|
settings.addAll(super.getSettings());
|
||||||
|
settings.add(EXCEPTION_TOP_LEVEL_RATIO_SETTING);
|
||||||
|
settings.add(EXCEPTION_LOW_LEVEL_RATIO_SETTING);
|
||||||
|
return settings;
|
||||||
}
|
}
|
||||||
public void onModule(MockEngineFactoryPlugin.MockEngineReaderModule module) {
|
@Override
|
||||||
module.setReaderClass(RandomExceptionDirectoryReaderWrapper.class);
|
protected Class<? extends FilterDirectoryReader> getReaderWrapperClass() {
|
||||||
|
return RandomExceptionDirectoryReaderWrapper.class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,17 +20,11 @@ If you squashed the whole thing into one class it'd look like:
|
||||||
|
|
||||||
[source,java]
|
[source,java]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
public class MyNativeScriptPlugin extends Plugin {
|
public class MyNativeScriptPlugin extends Plugin implements ScriptPlugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String name() {
|
public List<NativeScriptFactory> getNativeScripts() {
|
||||||
return "my-native-script";
|
return Collections.singletonList(new MyNativeScriptFactory());
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public String description() {
|
|
||||||
return "my native script that does something great";
|
|
||||||
}
|
|
||||||
public void onModule(ScriptModule scriptModule) {
|
|
||||||
scriptModule.registerScript("my_script", MyNativeScriptFactory.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class MyNativeScriptFactory implements NativeScriptFactory {
|
public static class MyNativeScriptFactory implements NativeScriptFactory {
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class IngestGeoIpPlugin extends Plugin implements IngestPlugin, Closeable
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Processor.Factory> getProcessors(Processor.Parameters parameters) {
|
public Map<String, Processor.Factory> getProcessors(Processor.Parameters parameters) {
|
||||||
if (databaseReaders != null) {
|
if (databaseReaders != null) {
|
||||||
throw new IllegalStateException("called onModule twice for geoip plugin!!");
|
throw new IllegalStateException("getProcessors called twice for geoip plugin!!");
|
||||||
}
|
}
|
||||||
Path geoIpConfigDirectory = parameters.env.configFile().resolve("ingest-geoip");
|
Path geoIpConfigDirectory = parameters.env.configFile().resolve("ingest-geoip");
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -60,9 +60,6 @@ public class JvmExamplePlugin extends Plugin {
|
||||||
return Settings.EMPTY;
|
return Settings.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onModule(RepositoriesModule repositoriesModule) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Module declaring some example configuration and a _cat action that uses
|
* Module declaring some example configuration and a _cat action that uses
|
||||||
* it.
|
* it.
|
||||||
|
|
|
@ -18,19 +18,20 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.cluster;
|
package org.elasticsearch.cluster;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
import org.elasticsearch.Version;
|
import org.elasticsearch.Version;
|
||||||
import org.elasticsearch.action.ActionListener;
|
import org.elasticsearch.action.ActionListener;
|
||||||
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
|
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
|
||||||
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse;
|
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse;
|
||||||
import org.elasticsearch.action.admin.cluster.node.stats.TransportNodesStatsAction;
|
|
||||||
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
|
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
|
||||||
import org.elasticsearch.action.admin.indices.stats.TransportIndicesStatsAction;
|
import org.elasticsearch.client.node.NodeClient;
|
||||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||||
import org.elasticsearch.cluster.service.ClusterService;
|
import org.elasticsearch.cluster.service.ClusterService;
|
||||||
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
|
||||||
import org.elasticsearch.common.settings.ClusterSettings;
|
|
||||||
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.monitor.fs.FsInfo;
|
import org.elasticsearch.monitor.fs.FsInfo;
|
||||||
|
@ -38,10 +39,6 @@ import org.elasticsearch.plugins.Plugin;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
|
||||||
|
|
||||||
import static java.util.Collections.emptyMap;
|
import static java.util.Collections.emptyMap;
|
||||||
import static java.util.Collections.emptySet;
|
import static java.util.Collections.emptySet;
|
||||||
|
|
||||||
|
@ -51,11 +48,8 @@ import static java.util.Collections.emptySet;
|
||||||
*/
|
*/
|
||||||
public class MockInternalClusterInfoService extends InternalClusterInfoService {
|
public class MockInternalClusterInfoService extends InternalClusterInfoService {
|
||||||
|
|
||||||
public static class TestPlugin extends Plugin {
|
/** This is a marker plugin used to trigger MockNode to use this mock info service. */
|
||||||
public void onModule(ClusterModule module) {
|
public static class TestPlugin extends Plugin {}
|
||||||
module.clusterInfoServiceImpl = MockInternalClusterInfoService.class;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final ClusterName clusterName;
|
private final ClusterName clusterName;
|
||||||
private volatile NodeStats[] stats = new NodeStats[3];
|
private volatile NodeStats[] stats = new NodeStats[3];
|
||||||
|
@ -75,12 +69,8 @@ public class MockInternalClusterInfoService extends InternalClusterInfoService {
|
||||||
null, null, null);
|
null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
public MockInternalClusterInfoService(Settings settings, ClusterService clusterService, ThreadPool threadPool, NodeClient client) {
|
||||||
public MockInternalClusterInfoService(Settings settings, ClusterSettings clusterSettings,
|
super(settings, clusterService, threadPool, client);
|
||||||
TransportNodesStatsAction transportNodesStatsAction,
|
|
||||||
TransportIndicesStatsAction transportIndicesStatsAction,
|
|
||||||
ClusterService clusterService, ThreadPool threadPool) {
|
|
||||||
super(settings, clusterSettings, transportNodesStatsAction, transportIndicesStatsAction, clusterService, threadPool);
|
|
||||||
this.clusterName = ClusterName.CLUSTER_NAME_SETTING.get(settings);
|
this.clusterName = ClusterName.CLUSTER_NAME_SETTING.get(settings);
|
||||||
stats[0] = makeStats("node_t1", new DiskUsage("node_t1", "n1", "/dev/null", 100, 100));
|
stats[0] = makeStats("node_t1", new DiskUsage("node_t1", "n1", "/dev/null", 100, 100));
|
||||||
stats[1] = makeStats("node_t2", new DiskUsage("node_t2", "n2", "/dev/null", 100, 100));
|
stats[1] = makeStats("node_t2", new DiskUsage("node_t2", "n2", "/dev/null", 100, 100));
|
||||||
|
|
|
@ -33,11 +33,13 @@ import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
// this must exist in the same package as IndexModule to allow access to setting the impl
|
/**
|
||||||
|
* A plugin to use {@link MockEngineFactory}.
|
||||||
|
*
|
||||||
|
* Subclasses may override the reader wrapper used.
|
||||||
|
*/
|
||||||
public class MockEngineFactoryPlugin extends Plugin {
|
public class MockEngineFactoryPlugin extends Plugin {
|
||||||
|
|
||||||
private Class<? extends FilterDirectoryReader> readerWrapper = AssertingDirectoryReader.class;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Setting<?>> getSettings() {
|
public List<Setting<?>> getSettings() {
|
||||||
return Arrays.asList(MockEngineSupport.DISABLE_FLUSH_ON_CLOSE, MockEngineSupport.WRAP_READER_RATIO);
|
return Arrays.asList(MockEngineSupport.DISABLE_FLUSH_ON_CLOSE, MockEngineSupport.WRAP_READER_RATIO);
|
||||||
|
@ -45,22 +47,10 @@ public class MockEngineFactoryPlugin extends Plugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onIndexModule(IndexModule module) {
|
public void onIndexModule(IndexModule module) {
|
||||||
module.engineFactory.set(new MockEngineFactory(readerWrapper));
|
module.engineFactory.set(new MockEngineFactory(getReaderWrapperClass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
protected Class<? extends FilterDirectoryReader> getReaderWrapperClass() {
|
||||||
public Collection<Module> createGuiceModules() {
|
return AssertingDirectoryReader.class;
|
||||||
return Collections.singleton(new MockEngineReaderModule());
|
|
||||||
}
|
|
||||||
|
|
||||||
public class MockEngineReaderModule extends AbstractModule {
|
|
||||||
|
|
||||||
public void setReaderClass(Class<? extends FilterDirectoryReader> readerWrapper) {
|
|
||||||
MockEngineFactoryPlugin.this.readerWrapper = readerWrapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void configure() {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,9 @@
|
||||||
|
|
||||||
package org.elasticsearch.node;
|
package org.elasticsearch.node;
|
||||||
|
|
||||||
|
import org.elasticsearch.client.node.NodeClient;
|
||||||
|
import org.elasticsearch.cluster.ClusterInfoService;
|
||||||
|
import org.elasticsearch.cluster.MockInternalClusterInfoService;
|
||||||
import org.elasticsearch.cluster.service.ClusterService;
|
import org.elasticsearch.cluster.service.ClusterService;
|
||||||
import org.elasticsearch.common.settings.ClusterSettings;
|
import org.elasticsearch.common.settings.ClusterSettings;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
@ -120,5 +123,15 @@ public class MockNode extends Node {
|
||||||
clusterSettings.addSettingsUpdateConsumer(RecoverySettingsChunkSizePlugin.CHUNK_SIZE_SETTING, recoverySettings::setChunkSize);
|
clusterSettings.addSettingsUpdateConsumer(RecoverySettingsChunkSizePlugin.CHUNK_SIZE_SETTING, recoverySettings::setChunkSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ClusterInfoService newClusterInfoService(Settings settings, ClusterService clusterService,
|
||||||
|
ThreadPool threadPool, NodeClient client) {
|
||||||
|
if (getPluginsService().filterPlugins(MockInternalClusterInfoService.TestPlugin.class).isEmpty()) {
|
||||||
|
return super.newClusterInfoService(settings, clusterService, threadPool, client);
|
||||||
|
} else {
|
||||||
|
return new MockInternalClusterInfoService(settings, clusterService, threadPool, client);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue