Skip to content

Commit ad9a7aa

Browse files
committed
Core: Less settings to AbstractComponent (#35140)
Stop passing `Settings` to `AbstractComponent`'s ctor. This allows us to stop passing around `Settings` in a *ton* of places. While this change touches many files, it touches them all in fairly small, mechanical ways, doing a few things per file: 1. Drop the `super(settings);` line on everything that extends `AbstractComponent`. 2. Drop the `settings` argument to the ctor if it is no longer used. 3. If the file doesn't use `logger` then drop `extends AbstractComponent` from it. 4. Clean up all compilation failure caused by the `settings` removal and drop any now unused `settings` isntances and method arguments. I've intentionally *not* removed the `settings` argument from a few files: 1. TransportAction 2. AbstractLifecycleComponent 3. BaseRestHandler These files don't *need* `settings` either, but this change is large enough as is. Relates to #34488
1 parent bf09c6b commit ad9a7aa

File tree

382 files changed

+673
-1294
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

382 files changed

+673
-1294
lines changed

benchmarks/src/main/java/org/elasticsearch/benchmark/routing/allocation/Allocators.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ public final class Allocators {
4646
private static class NoopGatewayAllocator extends GatewayAllocator {
4747
public static final NoopGatewayAllocator INSTANCE = new NoopGatewayAllocator();
4848

49-
protected NoopGatewayAllocator() {
50-
super(Settings.EMPTY);
51-
}
52-
5349
@Override
5450
public void applyStartedShards(RoutingAllocation allocation, List<ShardRouting> startedShards) {
5551
// noop
@@ -79,7 +75,7 @@ public static AllocationService createAllocationService(Settings settings) throw
7975

8076
public static AllocationService createAllocationService(Settings settings, ClusterSettings clusterSettings) throws
8177
InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
82-
return new AllocationService(settings,
78+
return new AllocationService(
8379
defaultAllocationDeciders(settings, clusterSettings),
8480
NoopGatewayAllocator.INSTANCE, new BalancedShardsAllocator(settings), EmptyClusterInfoService.INSTANCE);
8581
}
@@ -88,7 +84,7 @@ public static AllocationDeciders defaultAllocationDeciders(Settings settings, Cl
8884
IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException {
8985
Collection<AllocationDecider> deciders =
9086
ClusterModule.createAllocationDeciders(settings, clusterSettings, Collections.emptyList());
91-
return new AllocationDeciders(settings, deciders);
87+
return new AllocationDeciders(deciders);
9288

9389
}
9490

modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ public class ExpressionPlugin extends Plugin implements ScriptPlugin {
3131

3232
@Override
3333
public ScriptEngine getScriptEngine(Settings settings, Collection<ScriptContext<?>> contexts) {
34-
return new ExpressionScriptEngine(settings);
34+
return new ExpressionScriptEngine();
3535
}
3636
}

modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionScriptEngine.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
import org.apache.lucene.search.SortField;
3131
import org.elasticsearch.SpecialPermission;
3232
import org.elasticsearch.common.Nullable;
33-
import org.elasticsearch.common.component.AbstractComponent;
34-
import org.elasticsearch.common.settings.Settings;
3533
import org.elasticsearch.index.fielddata.IndexFieldData;
3634
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
3735
import org.elasticsearch.index.mapper.DateFieldMapper;
@@ -63,14 +61,10 @@
6361
* Provides the infrastructure for Lucene expressions as a scripting language for Elasticsearch. Only
6462
* {@link SearchScript}s are supported.
6563
*/
66-
public class ExpressionScriptEngine extends AbstractComponent implements ScriptEngine {
64+
public class ExpressionScriptEngine implements ScriptEngine {
6765

6866
public static final String NAME = "expression";
6967

70-
public ExpressionScriptEngine(Settings settings) {
71-
super(settings);
72-
}
73-
7468
@Override
7569
public String getType() {
7670
return NAME;

modules/lang-expression/src/test/java/org/elasticsearch/script/expression/ExpressionTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
package org.elasticsearch.script.expression;
2121

22-
import org.elasticsearch.common.settings.Settings;
2322
import org.elasticsearch.index.fielddata.AtomicNumericFieldData;
2423
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
2524
import org.elasticsearch.index.fielddata.SortedNumericDoubleValues;
@@ -64,7 +63,7 @@ public void setUp() throws Exception {
6463
when(fieldData.getFieldName()).thenReturn("field");
6564
when(fieldData.load(anyObject())).thenReturn(atomicFieldData);
6665

67-
service = new ExpressionScriptEngine(Settings.EMPTY);
66+
service = new ExpressionScriptEngine();
6867
lookup = new SearchLookup(mapperService, ignored -> fieldData, null);
6968
}
7069

modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessScriptEngine.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import org.apache.lucene.index.LeafReaderContext;
2323
import org.elasticsearch.SpecialPermission;
24-
import org.elasticsearch.common.component.AbstractComponent;
2524
import org.elasticsearch.common.settings.Settings;
2625
import org.elasticsearch.painless.Compiler.Loader;
2726
import org.elasticsearch.painless.lookup.PainlessLookupBuilder;
@@ -57,7 +56,7 @@
5756
/**
5857
* Implementation of a ScriptEngine for the Painless language.
5958
*/
60-
public final class PainlessScriptEngine extends AbstractComponent implements ScriptEngine {
59+
public final class PainlessScriptEngine implements ScriptEngine {
6160

6261
/**
6362
* Standard name of the Painless language.
@@ -93,8 +92,6 @@ public final class PainlessScriptEngine extends AbstractComponent implements Scr
9392
* @param settings The settings to initialize the engine with.
9493
*/
9594
public PainlessScriptEngine(Settings settings, Map<ScriptContext<?>, List<Whitelist>> contexts) {
96-
super(settings);
97-
9895
defaultCompilerSettings.setRegexesEnabled(CompilerSettings.REGEX_ENABLED.get(settings));
9996

10097
Map<ScriptContext<?>, Compiler> contextsToCompilers = new HashMap<>();

modules/percolator/src/main/java/org/elasticsearch/percolator/PercolatorHighlightSubFetchPhase.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.elasticsearch.common.bytes.BytesReference;
3232
import org.elasticsearch.common.document.DocumentField;
3333
import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery;
34-
import org.elasticsearch.common.settings.Settings;
3534
import org.elasticsearch.common.text.Text;
3635
import org.elasticsearch.index.query.ParsedQuery;
3736
import org.elasticsearch.search.SearchHit;
@@ -56,8 +55,8 @@
5655
final class PercolatorHighlightSubFetchPhase implements FetchSubPhase {
5756
private final HighlightPhase highlightPhase;
5857

59-
PercolatorHighlightSubFetchPhase(Settings settings, Map<String, Highlighter> highlighters) {
60-
this.highlightPhase = new HighlightPhase(settings, highlighters);
58+
PercolatorHighlightSubFetchPhase(Map<String, Highlighter> highlighters) {
59+
this.highlightPhase = new HighlightPhase(highlighters);
6160
}
6261

6362
boolean hitsExecutionNeeded(SearchContext context) { // for testing

modules/percolator/src/main/java/org/elasticsearch/percolator/PercolatorPlugin.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package org.elasticsearch.percolator;
2121

2222
import org.elasticsearch.common.settings.Setting;
23-
import org.elasticsearch.common.settings.Settings;
2423
import org.elasticsearch.index.mapper.Mapper;
2524
import org.elasticsearch.plugins.MapperPlugin;
2625
import org.elasticsearch.plugins.Plugin;
@@ -35,13 +34,6 @@
3534
import static java.util.Collections.singletonMap;
3635

3736
public class PercolatorPlugin extends Plugin implements MapperPlugin, SearchPlugin {
38-
39-
private final Settings settings;
40-
41-
public PercolatorPlugin(Settings settings) {
42-
this.settings = settings;
43-
}
44-
4537
@Override
4638
public List<QuerySpec<?>> getQueries() {
4739
return singletonList(new QuerySpec<>(PercolateQueryBuilder.NAME, PercolateQueryBuilder::new, PercolateQueryBuilder::fromXContent));
@@ -51,7 +43,7 @@ public List<QuerySpec<?>> getQueries() {
5143
public List<FetchSubPhase> getFetchSubPhases(FetchPhaseConstructionContext context) {
5244
return Arrays.asList(
5345
new PercolatorMatchedSlotSubFetchPhase(),
54-
new PercolatorHighlightSubFetchPhase(settings, context.getHighlighters())
46+
new PercolatorHighlightSubFetchPhase(context.getHighlighters())
5547
);
5648
}
5749

modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorHighlightSubFetchPhaseTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.elasticsearch.common.bytes.BytesArray;
2929
import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery;
3030
import org.elasticsearch.common.lucene.search.function.RandomScoreFunction;
31-
import org.elasticsearch.common.settings.Settings;
3231
import org.elasticsearch.search.fetch.subphase.highlight.SearchContextHighlight;
3332
import org.elasticsearch.search.internal.SearchContext;
3433
import org.elasticsearch.test.ESTestCase;
@@ -47,8 +46,7 @@ public class PercolatorHighlightSubFetchPhaseTests extends ESTestCase {
4746
public void testHitsExecutionNeeded() {
4847
PercolateQuery percolateQuery = new PercolateQuery("_name", ctx -> null, Collections.singletonList(new BytesArray("{}")),
4948
new MatchAllDocsQuery(), Mockito.mock(IndexSearcher.class), new MatchAllDocsQuery());
50-
PercolatorHighlightSubFetchPhase subFetchPhase = new PercolatorHighlightSubFetchPhase(Settings.EMPTY,
51-
emptyMap());
49+
PercolatorHighlightSubFetchPhase subFetchPhase = new PercolatorHighlightSubFetchPhase(emptyMap());
5250
SearchContext searchContext = Mockito.mock(SearchContext.class);
5351
Mockito.when(searchContext.highlight()).thenReturn(new SearchContextHighlight(Collections.emptyList()));
5452
Mockito.when(searchContext.query()).thenReturn(new MatchAllDocsQuery());

modules/repository-url/src/main/java/org/elasticsearch/common/blobstore/url/URLBlobStore.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.elasticsearch.common.blobstore.BlobPath;
2424
import org.elasticsearch.common.blobstore.BlobStore;
2525
import org.elasticsearch.common.blobstore.BlobStoreException;
26-
import org.elasticsearch.common.component.AbstractComponent;
2726
import org.elasticsearch.common.settings.Settings;
2827
import org.elasticsearch.common.unit.ByteSizeUnit;
2928
import org.elasticsearch.common.unit.ByteSizeValue;
@@ -34,7 +33,7 @@
3433
/**
3534
* Read-only URL-based blob store
3635
*/
37-
public class URLBlobStore extends AbstractComponent implements BlobStore {
36+
public class URLBlobStore implements BlobStore {
3837

3938
private final URL path;
4039

@@ -53,7 +52,6 @@ public class URLBlobStore extends AbstractComponent implements BlobStore {
5352
* @param path base URL
5453
*/
5554
public URLBlobStore(Settings settings, URL path) {
56-
super(settings);
5755
this.path = path;
5856
this.bufferSizeInBytes = (int) settings.getAsBytesSize("repositories.uri.buffer_size",
5957
new ByteSizeValue(100, ByteSizeUnit.KB)).getBytes();

plugins/discovery-azure-classic/src/main/java/org/elasticsearch/discovery/azure/classic/AzureUnicastHostsProvider.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ public static Deployment fromString(String string) {
108108

109109
public AzureUnicastHostsProvider(Settings settings, AzureComputeService azureComputeService,
110110
TransportService transportService, NetworkService networkService) {
111-
super(settings);
112111
this.settings = settings;
113112
this.azureComputeService = azureComputeService;
114113
this.transportService = transportService;

plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2ServiceImpl.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import org.elasticsearch.common.Randomness;
3434
import org.elasticsearch.common.Strings;
3535
import org.elasticsearch.common.component.AbstractComponent;
36-
import org.elasticsearch.common.settings.Settings;
3736
import org.elasticsearch.common.util.LazyInitializable;
3837

3938
import java.util.Random;
@@ -46,10 +45,6 @@ class AwsEc2ServiceImpl extends AbstractComponent implements AwsEc2Service {
4645
private final AtomicReference<LazyInitializable<AmazonEc2Reference, ElasticsearchException>> lazyClientReference =
4746
new AtomicReference<>();
4847

49-
AwsEc2ServiceImpl(Settings settings) {
50-
super(settings);
51-
}
52-
5348
private AmazonEC2 buildClient(Ec2ClientSettings clientSettings) {
5449
final AWSCredentialsProvider credentials = buildCredentials(logger, clientSettings);
5550
final ClientConfiguration configuration = buildConfiguration(logger, clientSettings);

plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2UnicastHostsProvider.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ class AwsEc2UnicastHostsProvider extends AbstractComponent implements UnicastHos
6969
private final TransportAddressesCache dynamicHosts;
7070

7171
AwsEc2UnicastHostsProvider(Settings settings, TransportService transportService, AwsEc2Service awsEc2Service) {
72-
super(settings);
7372
this.transportService = transportService;
7473
this.awsEc2Service = awsEc2Service;
7574

plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryPlugin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public class Ec2DiscoveryPlugin extends Plugin implements DiscoveryPlugin, Reloa
7777
protected final AwsEc2Service ec2Service;
7878

7979
public Ec2DiscoveryPlugin(Settings settings) {
80-
this(settings, new AwsEc2ServiceImpl(settings));
80+
this(settings, new AwsEc2ServiceImpl());
8181
}
8282

8383
protected Ec2DiscoveryPlugin(Settings settings, AwsEc2ServiceImpl ec2Service) {
@@ -90,7 +90,7 @@ protected Ec2DiscoveryPlugin(Settings settings, AwsEc2ServiceImpl ec2Service) {
9090
@Override
9191
public NetworkService.CustomNameResolver getCustomNameResolver(Settings settings) {
9292
logger.debug("Register _ec2_, _ec2:xxx_ network names");
93-
return new Ec2NameResolver(settings);
93+
return new Ec2NameResolver();
9494
}
9595

9696
@Override

plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/Ec2NameResolver.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.elasticsearch.common.SuppressForbidden;
2424
import org.elasticsearch.common.component.AbstractComponent;
2525
import org.elasticsearch.common.network.NetworkService.CustomNameResolver;
26-
import org.elasticsearch.common.settings.Settings;
2726

2827
import java.io.BufferedReader;
2928
import java.io.IOException;
@@ -79,13 +78,6 @@ private enum Ec2HostnameType {
7978
}
8079
}
8180

82-
/**
83-
* Construct a {@link CustomNameResolver}.
84-
*/
85-
Ec2NameResolver(Settings settings) {
86-
super(settings);
87-
}
88-
8981
/**
9082
* @param type the ec2 hostname type to discover.
9183
* @return the appropriate host resolved from ec2 meta-data, or null if it cannot be obtained.

plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/AwsEc2ServiceMock.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,14 @@
2424
import com.amazonaws.services.ec2.AmazonEC2;
2525
import com.amazonaws.services.ec2.model.Tag;
2626

27-
import org.elasticsearch.common.settings.Settings;
28-
2927
import java.util.List;
3028

3129
public class AwsEc2ServiceMock extends AwsEc2ServiceImpl {
3230

3331
private final int nodes;
3432
private final List<List<Tag>> tagsList;
3533

36-
public AwsEc2ServiceMock(Settings settings, int nodes, List<List<Tag>> tagsList) {
37-
super(settings);
34+
public AwsEc2ServiceMock(int nodes, List<List<Tag>> tagsList) {
3835
this.nodes = nodes;
3936
this.tagsList = tagsList;
4037
}

plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryPluginMock.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class Ec2DiscoveryPluginMock extends Ec2DiscoveryPlugin {
3232
}
3333

3434
public Ec2DiscoveryPluginMock(Settings settings, int nodes, List<List<Tag>> tagsList) {
35-
super(settings, new AwsEc2ServiceMock(settings, nodes, tagsList));
35+
super(settings, new AwsEc2ServiceMock(nodes, tagsList));
3636
}
3737

3838
}

plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ abstract class DummyEc2HostProvider extends AwsEc2UnicastHostsProvider {
298298
}
299299

300300
public void testGetNodeListEmptyCache() throws Exception {
301-
AwsEc2Service awsEc2Service = new AwsEc2ServiceMock(Settings.EMPTY, 1, null);
301+
AwsEc2Service awsEc2Service = new AwsEc2ServiceMock(1, null);
302302
DummyEc2HostProvider provider = new DummyEc2HostProvider(Settings.EMPTY, transportService, awsEc2Service) {
303303
@Override
304304
protected List<TransportAddress> fetchDynamicNodes() {

0 commit comments

Comments
 (0)