Skip to content

Commit d442dec

Browse files
committed
Tests: Remove a couple test uses of onModule
There were still a couple test use cases and examples that were using onModule. This change cleans those cases up.
1 parent aec09a7 commit d442dec

File tree

12 files changed

+101
-84
lines changed

12 files changed

+101
-84
lines changed

core/src/main/java/org/elasticsearch/cluster/ClusterModule.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ public class ClusterModule extends AbstractModule {
8686
final Collection<AllocationDecider> allocationDeciders;
8787
final ShardsAllocator shardsAllocator;
8888

89-
// pkg private so tests can mock
90-
Class<? extends ClusterInfoService> clusterInfoServiceImpl = InternalClusterInfoService.class;
91-
9289
public ClusterModule(Settings settings, ClusterService clusterService, List<ClusterPlugin> clusterPlugins) {
9390
this.settings = settings;
9491
this.allocationDeciders = createAllocationDeciders(settings, clusterService.getClusterSettings(), clusterPlugins);
@@ -159,7 +156,6 @@ private static ShardsAllocator createShardsAllocator(Settings settings, ClusterS
159156

160157
@Override
161158
protected void configure() {
162-
bind(ClusterInfoService.class).to(clusterInfoServiceImpl).asEagerSingleton();
163159
bind(GatewayAllocator.class).asEagerSingleton();
164160
bind(AllocationService.class).asEagerSingleton();
165161
bind(ClusterService.class).toInstance(clusterService);

core/src/main/java/org/elasticsearch/cluster/InternalClusterInfoService.java

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,21 @@
1919

2020
package org.elasticsearch.cluster;
2121

22+
import java.util.List;
23+
import java.util.concurrent.CopyOnWriteArrayList;
24+
import java.util.concurrent.CountDownLatch;
25+
import java.util.concurrent.TimeUnit;
26+
2227
import org.apache.logging.log4j.Logger;
2328
import org.elasticsearch.action.ActionListener;
2429
import org.elasticsearch.action.LatchedActionListener;
2530
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
2631
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest;
2732
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse;
28-
import org.elasticsearch.action.admin.cluster.node.stats.TransportNodesStatsAction;
2933
import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest;
3034
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
3135
import org.elasticsearch.action.admin.indices.stats.ShardStats;
32-
import org.elasticsearch.action.admin.indices.stats.TransportIndicesStatsAction;
36+
import org.elasticsearch.client.node.NodeClient;
3337
import org.elasticsearch.cluster.block.ClusterBlockException;
3438
import org.elasticsearch.cluster.metadata.IndexMetaData;
3539
import org.elasticsearch.cluster.metadata.MetaData;
@@ -39,7 +43,6 @@
3943
import org.elasticsearch.cluster.service.ClusterService;
4044
import org.elasticsearch.common.collect.ImmutableOpenMap;
4145
import org.elasticsearch.common.component.AbstractComponent;
42-
import org.elasticsearch.common.inject.Inject;
4346
import org.elasticsearch.common.settings.ClusterSettings;
4447
import org.elasticsearch.common.settings.Setting;
4548
import org.elasticsearch.common.settings.Setting.Property;
@@ -50,11 +53,6 @@
5053
import org.elasticsearch.threadpool.ThreadPool;
5154
import org.elasticsearch.transport.ReceiveTimeoutTransportException;
5255

53-
import java.util.List;
54-
import java.util.concurrent.CopyOnWriteArrayList;
55-
import java.util.concurrent.CountDownLatch;
56-
import java.util.concurrent.TimeUnit;
57-
5856
/**
5957
* InternalClusterInfoService provides the ClusterInfoService interface,
6058
* routinely updated on a timer. The timer can be dynamically changed by
@@ -84,29 +82,24 @@ public class InternalClusterInfoService extends AbstractComponent implements Clu
8482
private volatile boolean isMaster = false;
8583
private volatile boolean enabled;
8684
private volatile TimeValue fetchTimeout;
87-
private final TransportNodesStatsAction transportNodesStatsAction;
88-
private final TransportIndicesStatsAction transportIndicesStatsAction;
8985
private final ClusterService clusterService;
9086
private final ThreadPool threadPool;
87+
private final NodeClient client;
9188
private final List<Listener> listeners = new CopyOnWriteArrayList<>();
9289

93-
@Inject
94-
public InternalClusterInfoService(Settings settings, ClusterSettings clusterSettings,
95-
TransportNodesStatsAction transportNodesStatsAction,
96-
TransportIndicesStatsAction transportIndicesStatsAction, ClusterService clusterService,
97-
ThreadPool threadPool) {
90+
public InternalClusterInfoService(Settings settings, ClusterService clusterService, ThreadPool threadPool, NodeClient client) {
9891
super(settings);
9992
this.leastAvailableSpaceUsages = ImmutableOpenMap.of();
10093
this.mostAvailableSpaceUsages = ImmutableOpenMap.of();
10194
this.shardRoutingToDataPath = ImmutableOpenMap.of();
10295
this.shardSizes = ImmutableOpenMap.of();
103-
this.transportNodesStatsAction = transportNodesStatsAction;
104-
this.transportIndicesStatsAction = transportIndicesStatsAction;
10596
this.clusterService = clusterService;
10697
this.threadPool = threadPool;
98+
this.client = client;
10799
this.updateFrequency = INTERNAL_CLUSTER_INFO_UPDATE_INTERVAL_SETTING.get(settings);
108100
this.fetchTimeout = INTERNAL_CLUSTER_INFO_TIMEOUT_SETTING.get(settings);
109101
this.enabled = DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED_SETTING.get(settings);
102+
ClusterSettings clusterSettings = clusterService.getClusterSettings();
110103
clusterSettings.addSettingsUpdateConsumer(INTERNAL_CLUSTER_INFO_TIMEOUT_SETTING, this::setFetchTimeout);
111104
clusterSettings.addSettingsUpdateConsumer(INTERNAL_CLUSTER_INFO_UPDATE_INTERVAL_SETTING, this::setUpdateFrequency);
112105
clusterSettings.addSettingsUpdateConsumer(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED_SETTING, this::setEnabled);
@@ -259,8 +252,7 @@ protected CountDownLatch updateNodeStats(final ActionListener<NodesStatsResponse
259252
nodesStatsRequest.clear();
260253
nodesStatsRequest.fs(true);
261254
nodesStatsRequest.timeout(fetchTimeout);
262-
263-
transportNodesStatsAction.execute(nodesStatsRequest, new LatchedActionListener<>(listener, latch));
255+
client.admin().cluster().nodesStats(nodesStatsRequest, new LatchedActionListener<>(listener, latch));
264256
return latch;
265257
}
266258

@@ -274,7 +266,7 @@ protected CountDownLatch updateIndicesStats(final ActionListener<IndicesStatsRes
274266
indicesStatsRequest.clear();
275267
indicesStatsRequest.store(true);
276268

277-
transportIndicesStatsAction.execute(indicesStatsRequest, new LatchedActionListener<>(listener, latch));
269+
client.admin().indices().stats(indicesStatsRequest, new LatchedActionListener<>(listener, latch));
278270
return latch;
279271
}
280272

core/src/main/java/org/elasticsearch/node/Node.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@
3535
import org.elasticsearch.action.update.UpdateHelper;
3636
import org.elasticsearch.client.Client;
3737
import org.elasticsearch.client.node.NodeClient;
38+
import org.elasticsearch.cluster.ClusterInfoService;
3839
import org.elasticsearch.cluster.ClusterModule;
3940
import org.elasticsearch.cluster.ClusterState;
4041
import org.elasticsearch.cluster.ClusterStateObserver;
42+
import org.elasticsearch.cluster.InternalClusterInfoService;
4143
import org.elasticsearch.cluster.MasterNodeChangePredicate;
4244
import org.elasticsearch.cluster.NodeConnectionsService;
4345
import org.elasticsearch.cluster.action.index.MappingUpdatedAction;
@@ -307,6 +309,7 @@ protected Node(final Environment environment, Collection<Class<? extends Plugin>
307309
for (final ExecutorBuilder<?> builder : threadPool.builders()) {
308310
additionalSettings.addAll(builder.getRegisteredSettings());
309311
}
312+
client = new NodeClient(settings, threadPool);
310313
final ResourceWatcherService resourceWatcherService = new ResourceWatcherService(settings, threadPool);
311314
final ScriptModule scriptModule = ScriptModule.create(settings, this.environment, resourceWatcherService,
312315
pluginsService.filterPlugins(ScriptPlugin.class));
@@ -327,6 +330,7 @@ protected Node(final Environment environment, Collection<Class<? extends Plugin>
327330
resourcesToClose.add(tribeService);
328331
final IngestService ingestService = new IngestService(settings, threadPool, this.environment,
329332
scriptModule.getScriptService(), analysisModule.getAnalysisRegistry(), pluginsService.filterPlugins(IngestPlugin.class));
333+
final ClusterInfoService clusterInfoService = newClusterInfoService(settings, clusterService, threadPool, client);
330334

331335
ModulesBuilder modules = new ModulesBuilder();
332336
// plugin modules must be added here, before others or we can get crazy injection errors...
@@ -362,7 +366,6 @@ protected Node(final Environment environment, Collection<Class<? extends Plugin>
362366
.flatMap(Function.identity()).collect(Collectors.toList());
363367
final NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(namedWriteables);
364368
final MetaStateService metaStateService = new MetaStateService(settings, nodeEnvironment);
365-
client = new NodeClient(settings, threadPool);
366369
final IndicesService indicesService = new IndicesService(settings, pluginsService, nodeEnvironment,
367370
settingsModule.getClusterSettings(), analysisModule.getAnalysisRegistry(), searchModule.getQueryParserRegistry(),
368371
clusterModule.getIndexNameExpressionResolver(), indicesModule.getMapperRegistry(), namedWriteableRegistry,
@@ -433,6 +436,7 @@ protected Node(final Environment environment, Collection<Class<? extends Plugin>
433436
b.bind(MetaDataIndexUpgradeService.class).toInstance(new MetaDataIndexUpgradeService(settings,
434437
indicesModule.getMapperRegistry(), settingsModule.getIndexScopedSettings()));
435438
b.bind(ZenPing.class).toInstance(zenPing);
439+
b.bind(ClusterInfoService.class).toInstance(clusterInfoService);
436440
{
437441
RecoverySettings recoverySettings = new RecoverySettings(settings, settingsModule.getClusterSettings());
438442
processRecoverySettings(settingsModule.getClusterSettings(), recoverySettings);
@@ -900,4 +904,10 @@ protected ZenPing newZenPing(Settings settings, ThreadPool threadPool, Transport
900904
protected Node newTribeClientNode(Settings settings, Collection<Class<? extends Plugin>> classpathPlugins) {
901905
return new Node(new Environment(settings), classpathPlugins);
902906
}
907+
908+
/** Constructs a ClusterInfoService which may be mocked for tests. */
909+
protected ClusterInfoService newClusterInfoService(Settings settings, ClusterService clusterService,
910+
ThreadPool threadPool, NodeClient client) {
911+
return new InternalClusterInfoService(settings, clusterService, threadPool, client);
912+
}
903913
}

core/src/main/java/org/elasticsearch/plugins/Plugin.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import org.elasticsearch.action.ActionModule;
2727
import org.elasticsearch.client.Client;
28+
import org.elasticsearch.cluster.ClusterModule;
2829
import org.elasticsearch.cluster.metadata.MetaData;
2930
import org.elasticsearch.cluster.service.ClusterService;
3031
import org.elasticsearch.common.component.LifecycleComponent;
@@ -37,6 +38,7 @@
3738
import org.elasticsearch.common.settings.SettingsModule;
3839
import org.elasticsearch.index.IndexModule;
3940
import org.elasticsearch.indices.analysis.AnalysisModule;
41+
import org.elasticsearch.repositories.RepositoriesModule;
4042
import org.elasticsearch.script.ScriptModule;
4143
import org.elasticsearch.script.ScriptService;
4244
import org.elasticsearch.search.SearchModule;
@@ -222,4 +224,23 @@ public final void onModule(SearchModule module) {}
222224
*/
223225
@Deprecated
224226
public final void onModule(NetworkModule module) {}
227+
228+
/**
229+
* Old-style snapshot/restore extension point. {@code @Deprecated} and {@code final} to act as a signpost for plugin authors upgrading
230+
* from 2.x.
231+
*
232+
* @deprecated implement {@link RepositoryPlugin} instead
233+
*/
234+
@Deprecated
235+
public final void onModule(RepositoriesModule module) {}
236+
237+
/**
238+
* Old-style cluster extension point. {@code @Deprecated} and {@code final} to act as a signpost for plugin authors upgrading
239+
* from 2.x.
240+
*
241+
* @deprecated implement {@link ClusterPlugin} instead
242+
*/
243+
@Deprecated
244+
public final void onModule(ClusterModule module) {}
245+
225246
}

core/src/test/java/org/elasticsearch/indices/memory/breaker/RandomExceptionCircuitBreakerIT.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.elasticsearch.indices.memory.breaker;
2121

2222
import org.apache.lucene.index.DirectoryReader;
23+
import org.apache.lucene.index.FilterDirectoryReader;
2324
import org.apache.lucene.index.LeafReader;
2425
import org.elasticsearch.ElasticsearchException;
2526
import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
@@ -39,12 +40,14 @@
3940
import org.elasticsearch.indices.IndicesService;
4041
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
4142
import org.elasticsearch.plugins.Plugin;
43+
import org.elasticsearch.search.basic.SearchWithRandomExceptionsIT;
4244
import org.elasticsearch.search.sort.SortOrder;
4345
import org.elasticsearch.test.ESIntegTestCase;
4446
import org.elasticsearch.test.engine.MockEngineSupport;
4547
import org.elasticsearch.test.engine.ThrowingLeafReaderWrapper;
4648

4749
import java.io.IOException;
50+
import java.util.ArrayList;
4851
import java.util.Arrays;
4952
import java.util.Collection;
5053
import java.util.List;
@@ -200,14 +203,19 @@ public static class RandomExceptionDirectoryReaderWrapper extends MockEngineSupp
200203
Setting.doubleSetting(EXCEPTION_TOP_LEVEL_RATIO_KEY, 0.1d, 0.0d, Property.IndexScope);
201204
public static final Setting<Double> EXCEPTION_LOW_LEVEL_RATIO_SETTING =
202205
Setting.doubleSetting(EXCEPTION_LOW_LEVEL_RATIO_KEY, 0.1d, 0.0d, Property.IndexScope);
203-
public static class TestPlugin extends Plugin {
206+
public static class TestPlugin extends MockEngineFactoryPlugin {
204207
@Override
205208
public List<Setting<?>> getSettings() {
206-
return Arrays.asList(EXCEPTION_TOP_LEVEL_RATIO_SETTING, EXCEPTION_LOW_LEVEL_RATIO_SETTING);
209+
List<Setting<?>> settings = new ArrayList<>();
210+
settings.addAll(super.getSettings());
211+
settings.add(EXCEPTION_TOP_LEVEL_RATIO_SETTING);
212+
settings.add(EXCEPTION_LOW_LEVEL_RATIO_SETTING);
213+
return settings;
207214
}
208215

209-
public void onModule(MockEngineFactoryPlugin.MockEngineReaderModule module) {
210-
module.setReaderClass(RandomExceptionDirectoryReaderWrapper.class);
216+
@Override
217+
protected Class<? extends FilterDirectoryReader> getReaderWrapperClass() {
218+
return RandomExceptionDirectoryReaderWrapper.class;
211219
}
212220
}
213221

core/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsIT.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.elasticsearch.test.engine.ThrowingLeafReaderWrapper;
4545

4646
import java.io.IOException;
47+
import java.util.ArrayList;
4748
import java.util.Arrays;
4849
import java.util.Collection;
4950
import java.util.List;
@@ -153,17 +154,22 @@ public void testRandomExceptions() throws IOException, InterruptedException, Exe
153154

154155
public static class RandomExceptionDirectoryReaderWrapper extends MockEngineSupport.DirectoryReaderWrapper {
155156

156-
public static class TestPlugin extends Plugin {
157+
public static class TestPlugin extends MockEngineFactoryPlugin {
157158
public static final Setting<Double> EXCEPTION_TOP_LEVEL_RATIO_SETTING =
158159
Setting.doubleSetting(EXCEPTION_TOP_LEVEL_RATIO_KEY, 0.1d, 0.0d, Property.IndexScope);
159160
public static final Setting<Double> EXCEPTION_LOW_LEVEL_RATIO_SETTING =
160161
Setting.doubleSetting(EXCEPTION_LOW_LEVEL_RATIO_KEY, 0.1d, 0.0d, Property.IndexScope);
161162
@Override
162163
public List<Setting<?>> getSettings() {
163-
return Arrays.asList(EXCEPTION_TOP_LEVEL_RATIO_SETTING, EXCEPTION_LOW_LEVEL_RATIO_SETTING);
164+
List<Setting<?>> settings = new ArrayList<>();
165+
settings.addAll(super.getSettings());
166+
settings.add(EXCEPTION_TOP_LEVEL_RATIO_SETTING);
167+
settings.add(EXCEPTION_LOW_LEVEL_RATIO_SETTING);
168+
return settings;
164169
}
165-
public void onModule(MockEngineFactoryPlugin.MockEngineReaderModule module) {
166-
module.setReaderClass(RandomExceptionDirectoryReaderWrapper.class);
170+
@Override
171+
protected Class<? extends FilterDirectoryReader> getReaderWrapperClass() {
172+
return RandomExceptionDirectoryReaderWrapper.class;
167173
}
168174
}
169175

docs/reference/modules/scripting/native.asciidoc

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,11 @@ If you squashed the whole thing into one class it'd look like:
2020

2121
[source,java]
2222
--------------------------------------------------
23-
public class MyNativeScriptPlugin extends Plugin {
24-
@Override
25-
public String name() {
26-
return "my-native-script";
27-
}
23+
public class MyNativeScriptPlugin extends Plugin implements ScriptPlugin {
24+
2825
@Override
29-
public String description() {
30-
return "my native script that does something great";
31-
}
32-
public void onModule(ScriptModule scriptModule) {
33-
scriptModule.registerScript("my_script", MyNativeScriptFactory.class);
26+
public List<NativeScriptFactory> getNativeScripts() {
27+
return Collections.singletonList(new MyNativeScriptFactory());
3428
}
3529
3630
public static class MyNativeScriptFactory implements NativeScriptFactory {

plugins/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/IngestGeoIpPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class IngestGeoIpPlugin extends Plugin implements IngestPlugin, Closeable
4646
@Override
4747
public Map<String, Processor.Factory> getProcessors(Processor.Parameters parameters) {
4848
if (databaseReaders != null) {
49-
throw new IllegalStateException("called onModule twice for geoip plugin!!");
49+
throw new IllegalStateException("getProcessors called twice for geoip plugin!!");
5050
}
5151
Path geoIpConfigDirectory = parameters.env.configFile().resolve("ingest-geoip");
5252
try {

plugins/jvm-example/src/main/java/org/elasticsearch/plugin/example/JvmExamplePlugin.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ public Settings additionalSettings() {
6060
return Settings.EMPTY;
6161
}
6262

63-
public void onModule(RepositoriesModule repositoriesModule) {
64-
}
65-
6663
/**
6764
* Module declaring some example configuration and a _cat action that uses
6865
* it.

0 commit comments

Comments
 (0)