From 59a4debe08ac41e9e988bc23cc161798a90f658c Mon Sep 17 00:00:00 2001 From: Nikola Grcevski Date: Mon, 29 Aug 2022 16:30:51 -0400 Subject: [PATCH 01/12] Add reserved action for autoscaling --- .../cluster/service/ClusterService.java | 13 ++ .../java/org/elasticsearch/node/Node.java | 1 + .../xpack/autoscaling/Autoscaling.java | 14 ++- .../ReservedAutoscalingPolicyAction.java | 112 ++++++++++++++++++ ...ransportDeleteAutoscalingPolicyAction.java | 18 +++ .../TransportPutAutoscalingPolicyAction.java | 24 +++- 6 files changed, 176 insertions(+), 6 deletions(-) create mode 100644 x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyAction.java diff --git a/server/src/main/java/org/elasticsearch/cluster/service/ClusterService.java b/server/src/main/java/org/elasticsearch/cluster/service/ClusterService.java index 00f986ba4d54b..e7a4a52e6f177 100644 --- a/server/src/main/java/org/elasticsearch/cluster/service/ClusterService.java +++ b/server/src/main/java/org/elasticsearch/cluster/service/ClusterService.java @@ -21,6 +21,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.routing.OperationRouting; import org.elasticsearch.cluster.routing.RerouteService; +import org.elasticsearch.cluster.routing.allocation.AllocationService; import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Setting; @@ -56,6 +57,8 @@ public class ClusterService extends AbstractLifecycleComponent { private RerouteService rerouteService; + private AllocationService allocationService; + public ClusterService(Settings settings, ClusterSettings clusterSettings, ThreadPool threadPool, TaskManager taskManager) { this( settings, @@ -100,6 +103,16 @@ public RerouteService getRerouteService() { return rerouteService; } + public void setAllocationService(AllocationService allocationService) { + assert this.allocationService == null : "AllocationService is already set"; + this.allocationService = allocationService; + } + + public AllocationService getAllocationService() { + assert this.allocationService != null : "AllocationService not set"; + return allocationService; + } + @Override protected synchronized void doStart() { clusterApplierService.start(); diff --git a/server/src/main/java/org/elasticsearch/node/Node.java b/server/src/main/java/org/elasticsearch/node/Node.java index d1290aa4be6c3..343703924cc76 100644 --- a/server/src/main/java/org/elasticsearch/node/Node.java +++ b/server/src/main/java/org/elasticsearch/node/Node.java @@ -565,6 +565,7 @@ protected Node( systemIndices ); modules.add(clusterModule); + clusterService.setAllocationService(clusterModule.getAllocationService()); IndicesModule indicesModule = new IndicesModule(pluginsService.filterPlugins(MapperPlugin.class)); modules.add(indicesModule); diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/Autoscaling.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/Autoscaling.java index 6166a3751068b..fddcaee051078 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/Autoscaling.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/Autoscaling.java @@ -31,6 +31,7 @@ import org.elasticsearch.plugins.ExtensiblePlugin; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.repositories.RepositoriesService; +import org.elasticsearch.reservedstate.ReservedClusterStateHandler; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestHandler; import org.elasticsearch.script.ScriptService; @@ -43,6 +44,7 @@ import org.elasticsearch.xpack.autoscaling.action.GetAutoscalingCapacityAction; import org.elasticsearch.xpack.autoscaling.action.GetAutoscalingPolicyAction; import org.elasticsearch.xpack.autoscaling.action.PutAutoscalingPolicyAction; +import org.elasticsearch.xpack.autoscaling.action.ReservedAutoscalingPolicyAction; import org.elasticsearch.xpack.autoscaling.action.TransportDeleteAutoscalingPolicyAction; import org.elasticsearch.xpack.autoscaling.action.TransportGetAutoscalingCapacityAction; import org.elasticsearch.xpack.autoscaling.action.TransportGetAutoscalingPolicyAction; @@ -92,6 +94,7 @@ public class Autoscaling extends Plugin implements ActionPlugin, ExtensiblePlugi private final SetOnce clusterServiceHolder = new SetOnce<>(); private final SetOnce allocationDeciders = new SetOnce<>(); private final AutoscalingLicenseChecker autoscalingLicenseChecker; + private final SetOnce reservedAutoscalingPolicyAction = new SetOnce<>(); public Autoscaling() { this(new AutoscalingLicenseChecker()); @@ -118,11 +121,9 @@ public Collection createComponents( Tracer tracer ) { this.clusterServiceHolder.set(clusterService); - return List.of( - new AutoscalingCalculateCapacityService.Holder(this), - autoscalingLicenseChecker, - new AutoscalingNodeInfoService(clusterService, client) - ); + var capacityServiceHolder = new AutoscalingCalculateCapacityService.Holder(this); + reservedAutoscalingPolicyAction.set(new ReservedAutoscalingPolicyAction(clusterService, capacityServiceHolder)); + return List.of(capacityServiceHolder, autoscalingLicenseChecker, new AutoscalingNodeInfoService(clusterService, client)); } @Override @@ -227,4 +228,7 @@ public Set createDeciderServices(AllocationDeciders d return autoscalingExtensions.stream().flatMap(p -> p.deciders().stream()).collect(Collectors.toSet()); } + List> reservedClusterStateHandlers() { + return List.of(reservedAutoscalingPolicyAction.get()); + } } diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyAction.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyAction.java new file mode 100644 index 0000000000000..9bc4c34851ed8 --- /dev/null +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyAction.java @@ -0,0 +1,112 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.xpack.autoscaling.action; + +import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.reservedstate.ReservedClusterStateHandler; +import org.elasticsearch.reservedstate.TransformState; +import org.elasticsearch.xcontent.XContentParser; +import org.elasticsearch.xcontent.XContentParserConfiguration; +import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingCalculateCapacityService; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +import static org.elasticsearch.common.xcontent.XContentHelper.mapToXContentParser; + +/** + * This Action is the reserved state save version of RestPutAutoscalingPolicyHandler/RestDeleteAutoscalingPolicyHandler + *

+ * It is used by the ReservedClusterStateService to add/update or remove autoscaling policies. Typical usage + * for this action is in the context of file based settings. + */ +public class ReservedAutoscalingPolicyAction implements ReservedClusterStateHandler> { + public static final String NAME = "autoscaling"; + + private final ClusterService clusterService; + private final AutoscalingCalculateCapacityService.Holder policyValidatorHolder; + + /** + * Creates a ReservedAutoscalingPolicyAction + * + * @param policyValidatorHolder requires AutoscalingCalculateCapacityService.Holder for validation + */ + public ReservedAutoscalingPolicyAction( + final ClusterService clusterService, + final AutoscalingCalculateCapacityService.Holder policyValidatorHolder + ) { + this.clusterService = clusterService; + this.policyValidatorHolder = policyValidatorHolder; + } + + @Override + public String name() { + return NAME; + } + + @SuppressWarnings("unchecked") + public Collection prepare(Object input) { + List policies = (List) input; + + for (var policy : policies) { + validate(policy); + } + + return policies; + } + + @Override + public TransformState transform(Object source, TransformState prevState) throws Exception { + var requests = prepare(source); + ClusterState state = prevState.state(); + + for (var request : requests) { + state = TransportPutAutoscalingPolicyAction.putAutoscalingPolicy( + state, + request, + policyValidatorHolder.get(clusterService.getAllocationService().getAllocationDeciders()) + ); + } + + Set entities = requests.stream().map(r -> r.name()).collect(Collectors.toSet()); + + Set toDelete = new HashSet<>(prevState.keys()); + toDelete.removeAll(entities); + + for (var repositoryToDelete : toDelete) { + state = TransportDeleteAutoscalingPolicyAction.deleteAutoscalingPolicy(state, repositoryToDelete); + } + + return new TransformState(state, entities); + + } + + @Override + public List fromXContent(XContentParser parser) throws IOException { + List result = new ArrayList<>(); + + Map source = parser.map(); + + for (String name : source.keySet()) { + @SuppressWarnings("unchecked") + Map content = (Map) source.get(name); + try (XContentParser policyParser = mapToXContentParser(XContentParserConfiguration.EMPTY, content)) { + result.add(PutAutoscalingPolicyAction.Request.parse(policyParser, name)); + } + } + + return result; + } +} diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/TransportDeleteAutoscalingPolicyAction.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/TransportDeleteAutoscalingPolicyAction.java index 477e067ce4f2d..3dd3eda262607 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/TransportDeleteAutoscalingPolicyAction.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/TransportDeleteAutoscalingPolicyAction.java @@ -31,6 +31,8 @@ import org.elasticsearch.xpack.autoscaling.AutoscalingMetadata; import org.elasticsearch.xpack.autoscaling.policy.AutoscalingPolicyMetadata; +import java.util.Optional; +import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; @@ -85,6 +87,13 @@ protected ClusterBlockException checkBlock(final DeleteAutoscalingPolicyAction.R return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); } + /** + * Used by the reserved cluster state action handler for autoscaling policy + */ + static ClusterState deleteAutoscalingPolicy(final ClusterState currentState, final String name) { + return deleteAutoscalingPolicy(currentState, name, LOGGER); + } + static ClusterState deleteAutoscalingPolicy(final ClusterState currentState, final String name, final Logger logger) { final ClusterState.Builder builder = ClusterState.builder(currentState); final AutoscalingMetadata currentMetadata; @@ -113,4 +122,13 @@ static ClusterState deleteAutoscalingPolicy(final ClusterState currentState, fin return builder.build(); } + @Override + protected Optional reservedStateHandlerName() { + return Optional.of(ReservedAutoscalingPolicyAction.NAME); + } + + @Override + protected Set modifiedKeys(DeleteAutoscalingPolicyAction.Request request) { + return Set.of(request.name()); + } } diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/TransportPutAutoscalingPolicyAction.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/TransportPutAutoscalingPolicyAction.java index f31dd62babf03..e3ca39a8d3548 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/TransportPutAutoscalingPolicyAction.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/TransportPutAutoscalingPolicyAction.java @@ -36,11 +36,12 @@ import java.util.Collections; import java.util.Objects; +import java.util.Optional; +import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; public class TransportPutAutoscalingPolicyAction extends AcknowledgedTransportMasterNodeAction { - private static final Logger LOGGER = LogManager.getLogger(TransportPutAutoscalingPolicyAction.class); private final PolicyValidator policyValidator; @@ -121,6 +122,17 @@ protected ClusterBlockException checkBlock(final PutAutoscalingPolicyAction.Requ return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); } + /** + * Used by the reserved cluster state action handler for autoscaling policy + */ + static ClusterState putAutoscalingPolicy( + final ClusterState currentState, + final PutAutoscalingPolicyAction.Request request, + final PolicyValidator policyValidator + ) { + return putAutoscalingPolicy(currentState, request, policyValidator, LOGGER); + } + static ClusterState putAutoscalingPolicy( final ClusterState currentState, final PutAutoscalingPolicyAction.Request request, @@ -176,4 +188,14 @@ static ClusterState putAutoscalingPolicy( builder.metadata(Metadata.builder(currentState.getMetadata()).putCustom(AutoscalingMetadata.NAME, newMetadata).build()); return builder.build(); } + + @Override + protected Optional reservedStateHandlerName() { + return Optional.of(ReservedAutoscalingPolicyAction.NAME); + } + + @Override + protected Set modifiedKeys(PutAutoscalingPolicyAction.Request request) { + return Set.of(request.name()); + } } From c9032289feae475aad23e2ebfe5c040262eca718 Mon Sep 17 00:00:00 2001 From: Nikola Grcevski Date: Mon, 29 Aug 2022 16:31:35 -0400 Subject: [PATCH 02/12] Add SPI handler provider We can now load the handler when the plugin loads. --- ...servedAutoscalingStateHandlerProvider.java | 33 +++++++++++++++++++ ...dstate.ReservedClusterStateHandlerProvider | 8 +++++ 2 files changed, 41 insertions(+) create mode 100644 x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/ReservedAutoscalingStateHandlerProvider.java create mode 100644 x-pack/plugin/autoscaling/src/main/resources/META-INF/services/org.elasticsearch.reservedstate.ReservedClusterStateHandlerProvider diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/ReservedAutoscalingStateHandlerProvider.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/ReservedAutoscalingStateHandlerProvider.java new file mode 100644 index 0000000000000..c9f0f0196a987 --- /dev/null +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/ReservedAutoscalingStateHandlerProvider.java @@ -0,0 +1,33 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.xpack.autoscaling; + +import org.elasticsearch.reservedstate.ReservedClusterStateHandler; +import org.elasticsearch.reservedstate.ReservedClusterStateHandlerProvider; + +import java.util.Collection; + +/** + * Autoscaling provider implementation for the {@link ReservedClusterStateHandlerProvider} service interface + */ +public class ReservedAutoscalingStateHandlerProvider implements ReservedClusterStateHandlerProvider { + private final Autoscaling plugin; + + public ReservedAutoscalingStateHandlerProvider() { + throw new IllegalStateException("Provider must be constructed using PluginsService"); + } + + public ReservedAutoscalingStateHandlerProvider(Autoscaling plugin) { + this.plugin = plugin; + } + + @Override + public Collection> handlers() { + return plugin.reservedClusterStateHandlers(); + } +} diff --git a/x-pack/plugin/autoscaling/src/main/resources/META-INF/services/org.elasticsearch.reservedstate.ReservedClusterStateHandlerProvider b/x-pack/plugin/autoscaling/src/main/resources/META-INF/services/org.elasticsearch.reservedstate.ReservedClusterStateHandlerProvider new file mode 100644 index 0000000000000..c4b47a29f9ec3 --- /dev/null +++ b/x-pack/plugin/autoscaling/src/main/resources/META-INF/services/org.elasticsearch.reservedstate.ReservedClusterStateHandlerProvider @@ -0,0 +1,8 @@ +# +# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +# or more contributor license agreements. Licensed under the Elastic License +# 2.0; you may not use this file except in compliance with the Elastic License +# 2.0. +# + +org.elasticsearch.xpack.autoscaling.ReservedAutoscalingStateHandlerProvider From 0a87ab89365d37b3687c08b8bebcbbec1a27cae0 Mon Sep 17 00:00:00 2001 From: Nikola Grcevski Date: Mon, 29 Aug 2022 16:32:05 -0400 Subject: [PATCH 03/12] [TEST] Add SPI handler provider for test We can now load the handler when the plugin loads in tests --- ...servedAutoscalingStateHandlerProvider.java | 47 +++++++++++++++++++ ...dstate.ReservedClusterStateHandlerProvider | 8 ++++ 2 files changed, 55 insertions(+) create mode 100644 x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/LocalStateReservedAutoscalingStateHandlerProvider.java create mode 100644 x-pack/plugin/autoscaling/src/internalClusterTest/resources/META-INF/services/org.elasticsearch.reservedstate.ReservedClusterStateHandlerProvider diff --git a/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/LocalStateReservedAutoscalingStateHandlerProvider.java b/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/LocalStateReservedAutoscalingStateHandlerProvider.java new file mode 100644 index 0000000000000..e70fb08b6748c --- /dev/null +++ b/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/LocalStateReservedAutoscalingStateHandlerProvider.java @@ -0,0 +1,47 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.xpack.autoscaling; + +import org.elasticsearch.reservedstate.ReservedClusterStateHandler; +import org.elasticsearch.reservedstate.ReservedClusterStateHandlerProvider; + +import java.util.Collection; +import java.util.Objects; + +/** + * Autoscaling provider implementation for the {@link ReservedClusterStateHandlerProvider} service interface + */ +public class LocalStateReservedAutoscalingStateHandlerProvider implements ReservedClusterStateHandlerProvider { + private final LocalStateAutoscaling plugin; + + public LocalStateReservedAutoscalingStateHandlerProvider() { + throw new IllegalStateException("Provider must be constructed using PluginsService"); + } + + public LocalStateReservedAutoscalingStateHandlerProvider(LocalStateAutoscaling plugin) { + this.plugin = plugin; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + LocalStateReservedAutoscalingStateHandlerProvider that = (LocalStateReservedAutoscalingStateHandlerProvider) o; + return plugin.equals(that.plugin); + } + + @Override + public int hashCode() { + return Objects.hash(plugin); + } + + @Override + public Collection> handlers() { + return plugin.testPlugin().reservedClusterStateHandlers(); + } +} diff --git a/x-pack/plugin/autoscaling/src/internalClusterTest/resources/META-INF/services/org.elasticsearch.reservedstate.ReservedClusterStateHandlerProvider b/x-pack/plugin/autoscaling/src/internalClusterTest/resources/META-INF/services/org.elasticsearch.reservedstate.ReservedClusterStateHandlerProvider new file mode 100644 index 0000000000000..49cbe758eab1d --- /dev/null +++ b/x-pack/plugin/autoscaling/src/internalClusterTest/resources/META-INF/services/org.elasticsearch.reservedstate.ReservedClusterStateHandlerProvider @@ -0,0 +1,8 @@ +# +# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +# or more contributor license agreements. Licensed under the Elastic License +# 2.0; you may not use this file except in compliance with the Elastic License +# 2.0. +# + +org.elasticsearch.xpack.autoscaling.LocalStateReservedAutoscalingStateHandlerProvider From 25c0fa1c3b0869c8d541c3ccca1a258295479716 Mon Sep 17 00:00:00 2001 From: Nikola Grcevski Date: Mon, 29 Aug 2022 16:32:26 -0400 Subject: [PATCH 04/12] Make some methods public for testing --- .../reservedstate/service/FileSettingsService.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/reservedstate/service/FileSettingsService.java b/server/src/main/java/org/elasticsearch/reservedstate/service/FileSettingsService.java index 66ec590a1b773..bef04d0650884 100644 --- a/server/src/main/java/org/elasticsearch/reservedstate/service/FileSettingsService.java +++ b/server/src/main/java/org/elasticsearch/reservedstate/service/FileSettingsService.java @@ -82,13 +82,11 @@ public FileSettingsService(ClusterService clusterService, ReservedClusterStateSe this.operatorSettingsDir = environment.configFile().toAbsolutePath().resolve(OPERATOR_DIRECTORY); } - // package private for testing - Path operatorSettingsDir() { + public Path operatorSettingsDir() { return operatorSettingsDir; } - // package private for testing - Path operatorSettingsFile() { + public Path operatorSettingsFile() { return operatorSettingsDir().resolve(SETTINGS_FILE_NAME); } @@ -202,8 +200,7 @@ private void refreshExistingFileStateIfNeeded(ClusterState clusterState) { } } - // package private for testing - boolean watching() { + public boolean watching() { return this.watchService != null; } From 5f177cf7f37862273c0ea43c8dda8b415493d68e Mon Sep 17 00:00:00 2001 From: Nikola Grcevski Date: Mon, 29 Aug 2022 16:32:54 -0400 Subject: [PATCH 05/12] [TEST] Add autoscaling handler test --- .../ReservedAutoscalingPolicyTests.java | 146 ++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyTests.java diff --git a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyTests.java b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyTests.java new file mode 100644 index 0000000000000..b1d9c15cb881a --- /dev/null +++ b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyTests.java @@ -0,0 +1,146 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.xpack.autoscaling.action; + +import org.elasticsearch.cluster.ClusterName; +import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.routing.allocation.AllocationService; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; +import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.core.Tuple; +import org.elasticsearch.reservedstate.TransformState; +import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xcontent.XContentParser; +import org.elasticsearch.xcontent.XContentParserConfiguration; +import org.elasticsearch.xcontent.XContentType; +import org.elasticsearch.xpack.autoscaling.Autoscaling; +import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingCalculateCapacityService; +import org.elasticsearch.xpack.autoscaling.capacity.FixedAutoscalingDeciderService; +import org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider; + +import java.util.Collections; +import java.util.List; +import java.util.Set; + +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.empty; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; + +/** + * Tests that the ReservedAutoscalingPolicyAction does validation, can add and remove autoscaling polcies + */ +public class ReservedAutoscalingPolicyTests extends ESTestCase { + private TransformState processJSON(ReservedAutoscalingPolicyAction action, TransformState prevState, String json) throws Exception { + try (XContentParser parser = XContentType.JSON.xContent().createParser(XContentParserConfiguration.EMPTY, json)) { + return action.transform(action.fromXContent(parser), prevState); + } + } + + private static final AllocationDeciders DECIDERS = new AllocationDeciders(List.of(DataTierAllocationDecider.INSTANCE)); + + public void testValidation() { + var mocks = createMockServices(); + + ClusterState state = ClusterState.builder(new ClusterName("elasticsearch")).build(); + TransformState prevState = new TransformState(state, Collections.emptySet()); + ReservedAutoscalingPolicyAction action = new ReservedAutoscalingPolicyAction(mocks.v1(), mocks.v2()); + + String badPolicyJSON = """ + { + "my_autoscaling_policy": { + "roles" : [ "data_hot" ], + "deciders": { + "fixed": { + } + } + }, + "my_autoscaling_policy_1": { + "roles" : [ "data_hot" ], + "deciders": { + "random": { + } + } + } + }"""; + + assertEquals( + "unknown decider [random]", + expectThrows(IllegalArgumentException.class, () -> processJSON(action, prevState, badPolicyJSON)).getMessage() + ); + } + + public void testAddRemoveRoleMapping() throws Exception { + var mocks = createMockServices(); + + ClusterState state = ClusterState.builder(new ClusterName("elasticsearch")).build(); + TransformState prevState = new TransformState(state, Collections.emptySet()); + ReservedAutoscalingPolicyAction action = new ReservedAutoscalingPolicyAction(mocks.v1(), mocks.v2()); + + String emptyJSON = ""; + + TransformState updatedState = processJSON(action, prevState, emptyJSON); + assertEquals(0, updatedState.keys().size()); + assertEquals(prevState.state(), updatedState.state()); + + String json = """ + { + "my_autoscaling_policy": { + "roles" : [ "data_hot" ], + "deciders": { + "fixed": { + } + } + }, + "my_autoscaling_policy_1": { + "roles" : [ "data_warm" ], + "deciders": { + "fixed": { + } + } + } + }"""; + + prevState = updatedState; + updatedState = processJSON(action, prevState, json); + assertThat(updatedState.keys(), containsInAnyOrder("my_autoscaling_policy", "my_autoscaling_policy_1")); + + String halfJSON = """ + { + "my_autoscaling_policy_1": { + "roles" : [ "data_warm" ], + "deciders": { + "fixed": { + } + } + } + }"""; + + updatedState = processJSON(action, prevState, halfJSON); + assertThat(updatedState.keys(), containsInAnyOrder("my_autoscaling_policy_1")); + + updatedState = processJSON(action, prevState, emptyJSON); + assertThat(updatedState.keys(), empty()); + } + + private Tuple createMockServices() { + ClusterService clusterService = mock(ClusterService.class); + AllocationService allocationService = mock(AllocationService.class); + doReturn(allocationService).when(clusterService).getAllocationService(); + doReturn(DECIDERS).when(allocationService).getAllocationDeciders(); + AutoscalingCalculateCapacityService service = new AutoscalingCalculateCapacityService(Set.of(new FixedAutoscalingDeciderService())); + + Autoscaling autoscaling = mock(Autoscaling.class); + doReturn(Set.of(new FixedAutoscalingDeciderService())).when(autoscaling).createDeciderServices(any()); + + AutoscalingCalculateCapacityService.Holder holder = new AutoscalingCalculateCapacityService.Holder(autoscaling); + + return new Tuple<>(clusterService, holder); + } +} From 637d63fa1d32a4abd137e85bdd2dd282ee89c929 Mon Sep 17 00:00:00 2001 From: Nikola Grcevski Date: Mon, 29 Aug 2022 16:33:08 -0400 Subject: [PATCH 06/12] [TEST] Add autoscaling integration test --- .../AutoscalingFileSettingsIT.java | 229 ++++++++++++++++++ 1 file changed, 229 insertions(+) create mode 100644 x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/AutoscalingFileSettingsIT.java diff --git a/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/AutoscalingFileSettingsIT.java b/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/AutoscalingFileSettingsIT.java new file mode 100644 index 0000000000000..1ffa82e602b84 --- /dev/null +++ b/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/AutoscalingFileSettingsIT.java @@ -0,0 +1,229 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.xpack.autoscaling; + +import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest; +import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; +import org.elasticsearch.cluster.ClusterChangedEvent; +import org.elasticsearch.cluster.ClusterStateListener; +import org.elasticsearch.cluster.metadata.ReservedStateErrorMetadata; +import org.elasticsearch.cluster.metadata.ReservedStateHandlerMetadata; +import org.elasticsearch.cluster.metadata.ReservedStateMetadata; +import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.core.Strings; +import org.elasticsearch.core.Tuple; +import org.elasticsearch.reservedstate.service.FileSettingsService; +import org.elasticsearch.xcontent.XContentParserConfiguration; +import org.elasticsearch.xpack.autoscaling.action.PutAutoscalingPolicyAction; +import org.elasticsearch.xpack.autoscaling.action.ReservedAutoscalingPolicyAction; + +import java.io.ByteArrayInputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; + +import static org.elasticsearch.xcontent.XContentType.JSON; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.notNullValue; + +/** + * Tests that file settings service can properly add autoscaling policies and detect REST clashes + * with the reserved policies. + */ +public class AutoscalingFileSettingsIT extends AutoscalingIntegTestCase { + + private static AtomicLong versionCounter = new AtomicLong(1); + + private static String testJSON = """ + { + "metadata": { + "version": "%s", + "compatibility": "8.4.0" + }, + "state": { + "autoscaling": { + "my_autoscaling_policy": { + "roles" : [ "data_hot" ], + "deciders": { + "fixed": { + } + } + }, + "my_autoscaling_policy_1": { + "roles" : [ "data_warm" ], + "deciders": { + "fixed": { + } + } + } + } + } + }"""; + + private static String testErrorJSON = """ + { + "metadata": { + "version": "%s", + "compatibility": "8.4.0" + }, + "state": { + "autoscaling": { + "my_autoscaling_policy_bad": { + "roles" : [ "data_warm" ], + "deciders": { + "undecided": { + } + } + } + } + } + }"""; + + private void writeJSONFile(String node, String json) throws Exception { + long version = versionCounter.incrementAndGet(); + + FileSettingsService fileSettingsService = internalCluster().getInstance(FileSettingsService.class, node); + assertTrue(fileSettingsService.watching()); + + Files.deleteIfExists(fileSettingsService.operatorSettingsFile()); + + Files.createDirectories(fileSettingsService.operatorSettingsDir()); + Path tempFilePath = createTempFile(); + + logger.info("--> writing JSON config to node {} with path {}", node, tempFilePath); + Files.write(tempFilePath, Strings.format(json, version).getBytes(StandardCharsets.UTF_8)); + Files.move(tempFilePath, fileSettingsService.operatorSettingsFile(), StandardCopyOption.ATOMIC_MOVE); + } + + private Tuple setupClusterStateListener(String node) { + ClusterService clusterService = internalCluster().clusterService(node); + CountDownLatch savedClusterState = new CountDownLatch(1); + AtomicLong metadataVersion = new AtomicLong(-1); + clusterService.addListener(new ClusterStateListener() { + @Override + public void clusterChanged(ClusterChangedEvent event) { + ReservedStateMetadata reservedState = event.state().metadata().reservedStateMetadata().get(FileSettingsService.NAMESPACE); + if (reservedState != null) { + ReservedStateHandlerMetadata handlerMetadata = reservedState.handlers().get(ReservedAutoscalingPolicyAction.NAME); + if (handlerMetadata != null && handlerMetadata.keys().contains("my_autoscaling_policy")) { + clusterService.removeListener(this); + metadataVersion.set(event.state().metadata().version()); + savedClusterState.countDown(); + } + } + } + }); + + return new Tuple<>(savedClusterState, metadataVersion); + } + + private void assertPoliciesSaveOK(CountDownLatch savedClusterState, AtomicLong metadataVersion) throws Exception { + boolean awaitSuccessful = savedClusterState.await(20, TimeUnit.SECONDS); + assertTrue(awaitSuccessful); + + final ClusterStateResponse clusterStateResponse = client().admin() + .cluster() + .state(new ClusterStateRequest().waitForMetadataVersion(metadataVersion.get())) + .actionGet(); + + ReservedStateMetadata reservedState = clusterStateResponse.getState() + .metadata() + .reservedStateMetadata() + .get(FileSettingsService.NAMESPACE); + + ReservedStateHandlerMetadata handlerMetadata = reservedState.handlers().get(ReservedAutoscalingPolicyAction.NAME); + + assertThat(handlerMetadata.keys(), allOf(notNullValue(), containsInAnyOrder("my_autoscaling_policy", "my_autoscaling_policy_1"))); + + // Try using the REST API to update the my_autoscaling_policy policy + // This should fail, we have reserved certain autoscaling policies in operator mode + assertEquals( + "Failed to process request [org.elasticsearch.xpack.autoscaling.action.PutAutoscalingPolicyAction$Request/unset] " + + "with errors: [[my_autoscaling_policy] set as read-only by [file_settings]]", + expectThrows( + IllegalArgumentException.class, + () -> client().execute(PutAutoscalingPolicyAction.INSTANCE, sampleRestRequest("my_autoscaling_policy")).actionGet() + ).getMessage() + ); + } + + public void testPoliciesApplied() throws Exception { + ensureGreen(); + + var savedClusterState = setupClusterStateListener(internalCluster().getMasterName()); + writeJSONFile(internalCluster().getMasterName(), testJSON); + + assertPoliciesSaveOK(savedClusterState.v1(), savedClusterState.v2()); + } + + private Tuple setupClusterStateListenerForError(String node) { + ClusterService clusterService = internalCluster().clusterService(node); + CountDownLatch savedClusterState = new CountDownLatch(1); + AtomicLong metadataVersion = new AtomicLong(-1); + clusterService.addListener(new ClusterStateListener() { + @Override + public void clusterChanged(ClusterChangedEvent event) { + ReservedStateMetadata reservedState = event.state().metadata().reservedStateMetadata().get(FileSettingsService.NAMESPACE); + if (reservedState != null && reservedState.errorMetadata() != null) { + clusterService.removeListener(this); + metadataVersion.set(event.state().metadata().version()); + savedClusterState.countDown(); + assertEquals(ReservedStateErrorMetadata.ErrorKind.VALIDATION, reservedState.errorMetadata().errorKind()); + assertThat(reservedState.errorMetadata().errors(), allOf(notNullValue(), hasSize(1))); + assertThat( + reservedState.errorMetadata().errors().get(0), + containsString("java.lang.IllegalArgumentException: unknown decider [undecided]") + ); + } + } + }); + + return new Tuple<>(savedClusterState, metadataVersion); + } + + private void assertPoliciesNotSaved(CountDownLatch savedClusterState, AtomicLong metadataVersion) throws Exception { + boolean awaitSuccessful = savedClusterState.await(20, TimeUnit.SECONDS); + assertTrue(awaitSuccessful); + + // This should succeed, nothing was reserved + client().execute(PutAutoscalingPolicyAction.INSTANCE, sampleRestRequest("my_autoscaling_policy_bad")).actionGet(); + } + + public void testErrorSaved() throws Exception { + ensureGreen(); + var savedClusterState = setupClusterStateListenerForError(internalCluster().getMasterName()); + + writeJSONFile(internalCluster().getMasterName(), testErrorJSON); + assertPoliciesNotSaved(savedClusterState.v1(), savedClusterState.v2()); + } + + private PutAutoscalingPolicyAction.Request sampleRestRequest(String name) throws Exception { + var json = """ + { + "roles" : [ "data_cold" ], + "deciders": { + "fixed": { + } + } + }"""; + + try ( + var bis = new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8)); + var parser = JSON.xContent().createParser(XContentParserConfiguration.EMPTY, bis) + ) { + return PutAutoscalingPolicyAction.Request.parse(parser, name); + } + } +} From 6eb0fda4540beb418534a1988c6a5b7c629bb904 Mon Sep 17 00:00:00 2001 From: Nikola Grcevski <6207777+grcevski@users.noreply.github.com> Date: Mon, 29 Aug 2022 16:36:38 -0400 Subject: [PATCH 07/12] Update docs/changelog/89708.yaml --- docs/changelog/89708.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 docs/changelog/89708.yaml diff --git a/docs/changelog/89708.yaml b/docs/changelog/89708.yaml new file mode 100644 index 0000000000000..251baae98268a --- /dev/null +++ b/docs/changelog/89708.yaml @@ -0,0 +1,5 @@ +pr: 89708 +summary: Operator/autoscaling +area: Infra/Core +type: enhancement +issues: [] From ed30627cbc99fb0998f4ea03b12bfe9f0516dc4c Mon Sep 17 00:00:00 2001 From: Nikola Grcevski <6207777+grcevski@users.noreply.github.com> Date: Mon, 29 Aug 2022 16:42:37 -0400 Subject: [PATCH 08/12] Update 89708.yaml --- docs/changelog/89708.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog/89708.yaml b/docs/changelog/89708.yaml index 251baae98268a..9e6197880a24f 100644 --- a/docs/changelog/89708.yaml +++ b/docs/changelog/89708.yaml @@ -2,4 +2,4 @@ pr: 89708 summary: Operator/autoscaling area: Infra/Core type: enhancement -issues: [] +issues: [89183] From 12fdcea4ca01c9e892203e64d73c316ad5c381f3 Mon Sep 17 00:00:00 2001 From: Nikola Grcevski Date: Wed, 31 Aug 2022 19:26:49 -0400 Subject: [PATCH 09/12] Add allocation deciders supplier to createComponents --- .../analysis/common/CommonAnalysisPlugin.java | 4 +++- .../PredicateTokenScriptFilterTests.java | 2 +- .../ScriptedConditionTokenFilterTests.java | 2 +- .../org/elasticsearch/tracing/apm/APM.java | 4 +++- .../datastreams/DataStreamsPlugin.java | 4 +++- .../ingest/geoip/IngestGeoIpPlugin.java | 4 +++- .../painless/PainlessPlugin.java | 4 +++- .../elasticsearch/reindex/ReindexPlugin.java | 4 +++- .../ReindexFromRemoteWithAuthTests.java | 4 +++- .../azure/AzureRepositoryPlugin.java | 4 +++- .../azure/AzureStorageServiceTests.java | 2 +- .../repositories/s3/S3RepositoryPlugin.java | 4 +++- .../repository/url/URLRepositoryPlugin.java | 4 +++- .../RuntimeFieldsCommonPlugin.java | 4 +++- .../elasticsearch/systemd/SystemdPlugin.java | 4 +++- .../systemd/SystemdPluginTests.java | 10 +++++----- .../action/ingest/AsyncIngestProcessorIT.java | 4 +++- .../cluster/SimpleClusterStateIT.java | 4 +++- .../metadata/TemplateUpgradeServiceIT.java | 7 +++++-- .../health/GetHealthActionIT.java | 4 +++- .../elasticsearch/index/FinalPipelineIT.java | 4 +++- .../index/SettingsListenerIT.java | 4 +++- .../cluster/service/ClusterService.java | 13 ------------- .../java/org/elasticsearch/node/Node.java | 4 ++-- .../org/elasticsearch/plugins/Plugin.java | 4 +++- .../plugins/PluginIntrospectorTests.java | 4 +++- .../test/MockIndexEventListener.java | 4 +++- .../xpack/analytics/AnalyticsPlugin.java | 4 +++- .../xpack/async/AsyncResultsIndexPlugin.java | 4 +++- .../xpack/autoscaling/Autoscaling.java | 5 +++-- .../ReservedAutoscalingPolicyAction.java | 13 +++++++------ .../ReservedAutoscalingPolicyTests.java | 19 ++++--------------- .../java/org/elasticsearch/xpack/ccr/Ccr.java | 4 +++- .../elasticsearch/xpack/core/XPackPlugin.java | 4 +++- .../core/LocalStateCompositeXPackPlugin.java | 10 +++++++--- .../xpack/deprecation/Deprecation.java | 4 +++- .../xpack/enrich/EnrichPlugin.java | 4 +++- .../xpack/eql/plugin/EqlPlugin.java | 4 +++- .../org/elasticsearch/xpack/fleet/Fleet.java | 4 +++- .../xpack/idp/IdentityProviderPlugin.java | 4 +++- .../xpack/ilm/UpdateSettingsStepTests.java | 4 +++- .../xpack/ilm/IndexLifecycle.java | 4 +++- .../xpack/ml/MachineLearning.java | 4 +++- .../xpack/monitoring/Monitoring.java | 4 +++- .../xpack/lucene/bwc/OldLuceneVersions.java | 4 +++- .../elasticsearch/xpack/rollup/Rollup.java | 4 +++- .../SearchableSnapshots.java | 4 +++- .../xpack/security/Security.java | 4 +++- .../xpack/shutdown/NodeShutdownTasksIT.java | 4 +++- .../xpack/shutdown/ShutdownPlugin.java | 4 +++- .../xpack/sql/plugin/SqlPlugin.java | 4 +++- .../xpack/stack/StackPlugin.java | 4 +++- .../xpack/transform/Transform.java | 4 +++- .../votingonly/VotingOnlyNodePlugin.java | 4 +++- .../elasticsearch/xpack/watcher/Watcher.java | 4 +++- .../xpack/watcher/WatcherPluginTests.java | 5 ++++- 56 files changed, 172 insertions(+), 96 deletions(-) diff --git a/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/CommonAnalysisPlugin.java b/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/CommonAnalysisPlugin.java index 236af0ac3d64d..3de739b5ba335 100644 --- a/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/CommonAnalysisPlugin.java +++ b/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/CommonAnalysisPlugin.java @@ -102,6 +102,7 @@ import org.elasticsearch.Version; import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.logging.DeprecationCategory; @@ -164,7 +165,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver expressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { this.scriptServiceHolder.set(scriptService); return Collections.emptyList(); diff --git a/modules/analysis-common/src/test/java/org/elasticsearch/analysis/common/PredicateTokenScriptFilterTests.java b/modules/analysis-common/src/test/java/org/elasticsearch/analysis/common/PredicateTokenScriptFilterTests.java index 9155fd4167463..042659657b807 100644 --- a/modules/analysis-common/src/test/java/org/elasticsearch/analysis/common/PredicateTokenScriptFilterTests.java +++ b/modules/analysis-common/src/test/java/org/elasticsearch/analysis/common/PredicateTokenScriptFilterTests.java @@ -59,7 +59,7 @@ public FactoryType compile(Script script, ScriptContext FactoryType compile(Script script, ScriptContext createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver indexNameExpressionResolver, Supplier repositoriesServiceSupplier, - Tracer unused + Tracer unused, + Supplier allocationDecidersSupplier ) { final APMTracer apmTracer = tracer.get(); diff --git a/modules/data-streams/src/main/java/org/elasticsearch/datastreams/DataStreamsPlugin.java b/modules/data-streams/src/main/java/org/elasticsearch/datastreams/DataStreamsPlugin.java index bfe87bff3c794..4823b3c2d356d 100644 --- a/modules/data-streams/src/main/java/org/elasticsearch/datastreams/DataStreamsPlugin.java +++ b/modules/data-streams/src/main/java/org/elasticsearch/datastreams/DataStreamsPlugin.java @@ -20,6 +20,7 @@ import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.ClusterSettings; @@ -120,7 +121,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver indexNameExpressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { if (IndexSettings.isTimeSeriesModeEnabled() == false) { return List.of(); diff --git a/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/IngestGeoIpPlugin.java b/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/IngestGeoIpPlugin.java index ae4c2d9ae8abe..25b7a17ca5546 100644 --- a/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/IngestGeoIpPlugin.java +++ b/modules/ingest-geoip/src/main/java/org/elasticsearch/ingest/geoip/IngestGeoIpPlugin.java @@ -16,6 +16,7 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.ClusterSettings; @@ -114,7 +115,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver indexNameExpressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { try { String nodeId = nodeEnvironment.nodeId(); diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessPlugin.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessPlugin.java index ec07c37fe1747..75b972e7f77bf 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessPlugin.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessPlugin.java @@ -14,6 +14,7 @@ import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.ClusterSettings; @@ -144,7 +145,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver expressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { // this is a hack to bind the painless script engine in guice (all components are added to guice), so that // the painless context api. this is a temporary measure until transport actions do no require guice diff --git a/modules/reindex/src/main/java/org/elasticsearch/reindex/ReindexPlugin.java b/modules/reindex/src/main/java/org/elasticsearch/reindex/ReindexPlugin.java index f1a7f10c51d2c..5e3499274b66f 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/reindex/ReindexPlugin.java +++ b/modules/reindex/src/main/java/org/elasticsearch/reindex/ReindexPlugin.java @@ -13,6 +13,7 @@ import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.ClusterSettings; @@ -98,7 +99,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver expressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { return Collections.singletonList(new ReindexSslConfig(environment.settings(), environment, resourceWatcherService)); } diff --git a/modules/reindex/src/test/java/org/elasticsearch/reindex/ReindexFromRemoteWithAuthTests.java b/modules/reindex/src/test/java/org/elasticsearch/reindex/ReindexFromRemoteWithAuthTests.java index 89c275cccb69a..87ef3d7a9d37b 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/reindex/ReindexFromRemoteWithAuthTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/reindex/ReindexFromRemoteWithAuthTests.java @@ -21,6 +21,7 @@ import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; @@ -168,7 +169,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver expressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { testFilter.set(new ReindexFromRemoteWithAuthTests.TestFilter(threadPool)); return Collections.emptyList(); diff --git a/modules/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureRepositoryPlugin.java b/modules/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureRepositoryPlugin.java index b1603e23cbbed..3c9d5399d3b98 100644 --- a/modules/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureRepositoryPlugin.java +++ b/modules/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureRepositoryPlugin.java @@ -13,6 +13,7 @@ import org.apache.lucene.util.SetOnce; import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.Setting; @@ -95,7 +96,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver indexNameExpressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { AzureClientProvider azureClientProvider = AzureClientProvider.create(threadPool, settings); azureStoreService.set(createAzureStorageService(settings, azureClientProvider)); diff --git a/modules/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureStorageServiceTests.java b/modules/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureStorageServiceTests.java index ac54ec46be576..35b570e1c0b05 100644 --- a/modules/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureStorageServiceTests.java +++ b/modules/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureStorageServiceTests.java @@ -73,7 +73,7 @@ public void testReadSecuredSettings() { private AzureRepositoryPlugin pluginWithSettingsValidation(Settings settings) { final AzureRepositoryPlugin plugin = new AzureRepositoryPlugin(settings); new SettingsModule(settings, plugin.getSettings(), Collections.emptyList(), Collections.emptySet()); - plugin.createComponents(null, null, threadPool, null, null, null, null, null, null, null, null, Tracer.NOOP); + plugin.createComponents(null, null, threadPool, null, null, null, null, null, null, null, null, Tracer.NOOP, null); return plugin; } diff --git a/modules/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3RepositoryPlugin.java b/modules/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3RepositoryPlugin.java index 9a9312899e00e..a5d0088c59a2a 100644 --- a/modules/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3RepositoryPlugin.java +++ b/modules/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3RepositoryPlugin.java @@ -15,6 +15,7 @@ import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.RepositoryMetadata; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.Setting; @@ -100,7 +101,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver indexNameExpressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { service.set(s3Service(environment)); this.service.get().refreshAndClearCache(S3ClientSettings.load(settings)); diff --git a/modules/repository-url/src/main/java/org/elasticsearch/plugin/repository/url/URLRepositoryPlugin.java b/modules/repository-url/src/main/java/org/elasticsearch/plugin/repository/url/URLRepositoryPlugin.java index 79289de03fb65..98f55f3f90fb6 100644 --- a/modules/repository-url/src/main/java/org/elasticsearch/plugin/repository/url/URLRepositoryPlugin.java +++ b/modules/repository-url/src/main/java/org/elasticsearch/plugin/repository/url/URLRepositoryPlugin.java @@ -11,6 +11,7 @@ import org.apache.lucene.util.SetOnce; import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.blobstore.url.http.URLHttpClient; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; @@ -86,7 +87,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver indexNameExpressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { final URLHttpClient.Factory apacheURLHttpClientFactory = new URLHttpClient.Factory(); diff --git a/modules/runtime-fields-common/src/main/java/org/elasticsearch/runtimefields/RuntimeFieldsCommonPlugin.java b/modules/runtime-fields-common/src/main/java/org/elasticsearch/runtimefields/RuntimeFieldsCommonPlugin.java index 877d4e0f171d7..13a20422eefb3 100644 --- a/modules/runtime-fields-common/src/main/java/org/elasticsearch/runtimefields/RuntimeFieldsCommonPlugin.java +++ b/modules/runtime-fields-common/src/main/java/org/elasticsearch/runtimefields/RuntimeFieldsCommonPlugin.java @@ -10,6 +10,7 @@ import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.Setting; @@ -74,7 +75,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver indexNameExpressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { grokHelper.finishInitializing(threadPool); return List.of(); diff --git a/modules/systemd/src/main/java/org/elasticsearch/systemd/SystemdPlugin.java b/modules/systemd/src/main/java/org/elasticsearch/systemd/SystemdPlugin.java index 18792725652d7..7b7652c3c2d6a 100644 --- a/modules/systemd/src/main/java/org/elasticsearch/systemd/SystemdPlugin.java +++ b/modules/systemd/src/main/java/org/elasticsearch/systemd/SystemdPlugin.java @@ -14,6 +14,7 @@ import org.elasticsearch.Build; import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.core.TimeValue; @@ -89,7 +90,8 @@ public Collection createComponents( final NamedWriteableRegistry namedWriteableRegistry, final IndexNameExpressionResolver expressionResolver, final Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { if (enabled == false) { extender.set(null); diff --git a/modules/systemd/src/test/java/org/elasticsearch/systemd/SystemdPluginTests.java b/modules/systemd/src/test/java/org/elasticsearch/systemd/SystemdPluginTests.java index 8b15f5f7ab4dc..cb95f7d7e8482 100644 --- a/modules/systemd/src/test/java/org/elasticsearch/systemd/SystemdPluginTests.java +++ b/modules/systemd/src/test/java/org/elasticsearch/systemd/SystemdPluginTests.java @@ -53,28 +53,28 @@ public class SystemdPluginTests extends ESTestCase { public void testIsEnabled() { final SystemdPlugin plugin = new SystemdPlugin(false, randomPackageBuildType, Boolean.TRUE.toString()); - plugin.createComponents(null, null, threadPool, null, null, null, null, null, null, null, null, Tracer.NOOP); + plugin.createComponents(null, null, threadPool, null, null, null, null, null, null, null, null, Tracer.NOOP, null); assertTrue(plugin.isEnabled()); assertNotNull(plugin.extender()); } public void testIsNotPackageDistribution() { final SystemdPlugin plugin = new SystemdPlugin(false, randomNonPackageBuildType, Boolean.TRUE.toString()); - plugin.createComponents(null, null, threadPool, null, null, null, null, null, null, null, null, Tracer.NOOP); + plugin.createComponents(null, null, threadPool, null, null, null, null, null, null, null, null, Tracer.NOOP, null); assertFalse(plugin.isEnabled()); assertNull(plugin.extender()); } public void testIsImplicitlyNotEnabled() { final SystemdPlugin plugin = new SystemdPlugin(false, randomPackageBuildType, null); - plugin.createComponents(null, null, threadPool, null, null, null, null, null, null, null, null, Tracer.NOOP); + plugin.createComponents(null, null, threadPool, null, null, null, null, null, null, null, null, Tracer.NOOP, null); assertFalse(plugin.isEnabled()); assertNull(plugin.extender()); } public void testIsExplicitlyNotEnabled() { final SystemdPlugin plugin = new SystemdPlugin(false, randomPackageBuildType, Boolean.FALSE.toString()); - plugin.createComponents(null, null, threadPool, null, null, null, null, null, null, null, null, Tracer.NOOP); + plugin.createComponents(null, null, threadPool, null, null, null, null, null, null, null, null, Tracer.NOOP, null); assertFalse(plugin.isEnabled()); assertNull(plugin.extender()); } @@ -162,7 +162,7 @@ int sd_notify(final int unset_environment, final String state) { } }; - plugin.createComponents(null, null, threadPool, null, null, null, null, null, null, null, null, Tracer.NOOP); + plugin.createComponents(null, null, threadPool, null, null, null, null, null, null, null, null, Tracer.NOOP, null); if (Boolean.TRUE.toString().equals(esSDNotify)) { assertNotNull(plugin.extender()); } else { diff --git a/server/src/internalClusterTest/java/org/elasticsearch/action/ingest/AsyncIngestProcessorIT.java b/server/src/internalClusterTest/java/org/elasticsearch/action/ingest/AsyncIngestProcessorIT.java index 18b296f9bd7d3..4e6a928e19cc5 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/action/ingest/AsyncIngestProcessorIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/action/ingest/AsyncIngestProcessorIT.java @@ -14,6 +14,7 @@ import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; @@ -97,7 +98,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver expressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { this.threadPool = threadPool; return List.of(); diff --git a/server/src/internalClusterTest/java/org/elasticsearch/cluster/SimpleClusterStateIT.java b/server/src/internalClusterTest/java/org/elasticsearch/cluster/SimpleClusterStateIT.java index 062e3bc08ad39..f5657cc9265c1 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/cluster/SimpleClusterStateIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/cluster/SimpleClusterStateIT.java @@ -19,6 +19,7 @@ import org.elasticsearch.cluster.metadata.MappingMetadata; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.routing.RoutingTable; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Priority; import org.elasticsearch.common.Strings; @@ -441,7 +442,8 @@ public Collection createComponents( final NamedWriteableRegistry namedWriteableRegistry, final IndexNameExpressionResolver expressionResolver, final Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { clusterService.addListener(event -> { final ClusterState state = event.state(); diff --git a/server/src/internalClusterTest/java/org/elasticsearch/cluster/metadata/TemplateUpgradeServiceIT.java b/server/src/internalClusterTest/java/org/elasticsearch/cluster/metadata/TemplateUpgradeServiceIT.java index c8c813f445db6..2060f30cf3a1c 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/cluster/metadata/TemplateUpgradeServiceIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/cluster/metadata/TemplateUpgradeServiceIT.java @@ -11,6 +11,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.client.internal.Client; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.Setting; @@ -75,7 +76,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver expressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { clusterService.getClusterSettings() .addSettingsUpdateConsumer( @@ -94,7 +96,8 @@ public Collection createComponents( namedWriteableRegistry, expressionResolver, repositoriesServiceSupplier, - tracer + tracer, + allocationDecidersSupplier ); } diff --git a/server/src/internalClusterTest/java/org/elasticsearch/health/GetHealthActionIT.java b/server/src/internalClusterTest/java/org/elasticsearch/health/GetHealthActionIT.java index 52407a4d776f9..12a19a28e2251 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/health/GetHealthActionIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/health/GetHealthActionIT.java @@ -12,6 +12,7 @@ import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.Setting; @@ -101,7 +102,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver indexNameExpressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { healthIndicatorServices.add(new IlmHealthIndicatorService(clusterService)); healthIndicatorServices.add(new SlmHealthIndicatorService(clusterService)); diff --git a/server/src/internalClusterTest/java/org/elasticsearch/index/FinalPipelineIT.java b/server/src/internalClusterTest/java/org/elasticsearch/index/FinalPipelineIT.java index 3911ba6a6ab82..426602362ac4c 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/index/FinalPipelineIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/index/FinalPipelineIT.java @@ -20,6 +20,7 @@ import org.elasticsearch.action.support.WriteRequest; import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; @@ -348,7 +349,8 @@ public Collection createComponents( final NamedWriteableRegistry namedWriteableRegistry, final IndexNameExpressionResolver expressionResolver, final Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { return List.of(); } diff --git a/server/src/internalClusterTest/java/org/elasticsearch/index/SettingsListenerIT.java b/server/src/internalClusterTest/java/org/elasticsearch/index/SettingsListenerIT.java index 91f150401065b..cfd1ab5768ca4 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/index/SettingsListenerIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/index/SettingsListenerIT.java @@ -9,6 +9,7 @@ import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; @@ -73,7 +74,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver expressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { return Collections.singletonList(service); } diff --git a/server/src/main/java/org/elasticsearch/cluster/service/ClusterService.java b/server/src/main/java/org/elasticsearch/cluster/service/ClusterService.java index e7a4a52e6f177..00f986ba4d54b 100644 --- a/server/src/main/java/org/elasticsearch/cluster/service/ClusterService.java +++ b/server/src/main/java/org/elasticsearch/cluster/service/ClusterService.java @@ -21,7 +21,6 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.routing.OperationRouting; import org.elasticsearch.cluster.routing.RerouteService; -import org.elasticsearch.cluster.routing.allocation.AllocationService; import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Setting; @@ -57,8 +56,6 @@ public class ClusterService extends AbstractLifecycleComponent { private RerouteService rerouteService; - private AllocationService allocationService; - public ClusterService(Settings settings, ClusterSettings clusterSettings, ThreadPool threadPool, TaskManager taskManager) { this( settings, @@ -103,16 +100,6 @@ public RerouteService getRerouteService() { return rerouteService; } - public void setAllocationService(AllocationService allocationService) { - assert this.allocationService == null : "AllocationService is already set"; - this.allocationService = allocationService; - } - - public AllocationService getAllocationService() { - assert this.allocationService != null : "AllocationService not set"; - return allocationService; - } - @Override protected synchronized void doStart() { clusterApplierService.start(); diff --git a/server/src/main/java/org/elasticsearch/node/Node.java b/server/src/main/java/org/elasticsearch/node/Node.java index 343703924cc76..145769dc603c8 100644 --- a/server/src/main/java/org/elasticsearch/node/Node.java +++ b/server/src/main/java/org/elasticsearch/node/Node.java @@ -565,7 +565,6 @@ protected Node( systemIndices ); modules.add(clusterModule); - clusterService.setAllocationService(clusterModule.getAllocationService()); IndicesModule indicesModule = new IndicesModule(pluginsService.filterPlugins(MapperPlugin.class)); modules.add(indicesModule); @@ -711,7 +710,8 @@ protected Node( namedWriteableRegistry, clusterModule.getIndexNameExpressionResolver(), repositoriesServiceReference::get, - tracer + tracer, + clusterModule.getAllocationService()::getAllocationDeciders ) ).toList(); diff --git a/server/src/main/java/org/elasticsearch/plugins/Plugin.java b/server/src/main/java/org/elasticsearch/plugins/Plugin.java index f001535c3120c..9e68be6af69ea 100644 --- a/server/src/main/java/org/elasticsearch/plugins/Plugin.java +++ b/server/src/main/java/org/elasticsearch/plugins/Plugin.java @@ -12,6 +12,7 @@ import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.IndexTemplateMetadata; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.common.io.stream.NamedWriteable; @@ -94,7 +95,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver indexNameExpressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { return Collections.emptyList(); } diff --git a/server/src/test/java/org/elasticsearch/plugins/PluginIntrospectorTests.java b/server/src/test/java/org/elasticsearch/plugins/PluginIntrospectorTests.java index 30fe3c770efb6..9aae7ccf0979c 100644 --- a/server/src/test/java/org/elasticsearch/plugins/PluginIntrospectorTests.java +++ b/server/src/test/java/org/elasticsearch/plugins/PluginIntrospectorTests.java @@ -13,6 +13,7 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.SingleNodeShutdownMetadata; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.breaker.CircuitBreaker; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; @@ -270,7 +271,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver indexNameExpressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { return null; } diff --git a/test/framework/src/main/java/org/elasticsearch/test/MockIndexEventListener.java b/test/framework/src/main/java/org/elasticsearch/test/MockIndexEventListener.java index b67fa07d35228..363234a91c429 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/MockIndexEventListener.java +++ b/test/framework/src/main/java/org/elasticsearch/test/MockIndexEventListener.java @@ -10,6 +10,7 @@ import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.Setting; @@ -86,7 +87,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver expressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { return Collections.singletonList(listener); } diff --git a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/AnalyticsPlugin.java b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/AnalyticsPlugin.java index 6e2066a3b0453..134c24799090e 100644 --- a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/AnalyticsPlugin.java +++ b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/AnalyticsPlugin.java @@ -10,6 +10,7 @@ import org.elasticsearch.action.ActionResponse; import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.Setting; @@ -182,7 +183,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver indexNameExpressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { return singletonList(usage); } diff --git a/x-pack/plugin/async/src/main/java/org/elasticsearch/xpack/async/AsyncResultsIndexPlugin.java b/x-pack/plugin/async/src/main/java/org/elasticsearch/xpack/async/AsyncResultsIndexPlugin.java index 9dcee7af7d9a4..9d8d7275c8676 100644 --- a/x-pack/plugin/async/src/main/java/org/elasticsearch/xpack/async/AsyncResultsIndexPlugin.java +++ b/x-pack/plugin/async/src/main/java/org/elasticsearch/xpack/async/AsyncResultsIndexPlugin.java @@ -11,6 +11,7 @@ import org.elasticsearch.client.internal.OriginSettingClient; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.Settings; @@ -71,7 +72,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver indexNameExpressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { List components = new ArrayList<>(); if (DiscoveryNode.canContainData(environment.settings())) { diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/Autoscaling.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/Autoscaling.java index fddcaee051078..134248aed0527 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/Autoscaling.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/Autoscaling.java @@ -118,11 +118,12 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver indexNameExpressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { this.clusterServiceHolder.set(clusterService); var capacityServiceHolder = new AutoscalingCalculateCapacityService.Holder(this); - reservedAutoscalingPolicyAction.set(new ReservedAutoscalingPolicyAction(clusterService, capacityServiceHolder)); + reservedAutoscalingPolicyAction.set(new ReservedAutoscalingPolicyAction(capacityServiceHolder, allocationDecidersSupplier)); return List.of(capacityServiceHolder, autoscalingLicenseChecker, new AutoscalingNodeInfoService(clusterService, client)); } diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyAction.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyAction.java index 9bc4c34851ed8..95a2cc1e65fef 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyAction.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyAction.java @@ -8,7 +8,7 @@ package org.elasticsearch.xpack.autoscaling.action; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.reservedstate.ReservedClusterStateHandler; import org.elasticsearch.reservedstate.TransformState; import org.elasticsearch.xcontent.XContentParser; @@ -22,6 +22,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.function.Supplier; import java.util.stream.Collectors; import static org.elasticsearch.common.xcontent.XContentHelper.mapToXContentParser; @@ -35,7 +36,7 @@ public class ReservedAutoscalingPolicyAction implements ReservedClusterStateHandler> { public static final String NAME = "autoscaling"; - private final ClusterService clusterService; + private final Supplier allocationDecidersSupplier; private final AutoscalingCalculateCapacityService.Holder policyValidatorHolder; /** @@ -44,11 +45,11 @@ public class ReservedAutoscalingPolicyAction implements ReservedClusterStateHand * @param policyValidatorHolder requires AutoscalingCalculateCapacityService.Holder for validation */ public ReservedAutoscalingPolicyAction( - final ClusterService clusterService, - final AutoscalingCalculateCapacityService.Holder policyValidatorHolder + final AutoscalingCalculateCapacityService.Holder policyValidatorHolder, + final Supplier allocationDecidersSupplier ) { - this.clusterService = clusterService; this.policyValidatorHolder = policyValidatorHolder; + this.allocationDecidersSupplier = allocationDecidersSupplier; } @Override @@ -76,7 +77,7 @@ public TransformState transform(Object source, TransformState prevState) throws state = TransportPutAutoscalingPolicyAction.putAutoscalingPolicy( state, request, - policyValidatorHolder.get(clusterService.getAllocationService().getAllocationDeciders()) + policyValidatorHolder.get(allocationDecidersSupplier.get()) ); } diff --git a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyTests.java b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyTests.java index b1d9c15cb881a..6d907833d7825 100644 --- a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyTests.java +++ b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyTests.java @@ -9,10 +9,7 @@ import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.routing.allocation.AllocationService; import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; -import org.elasticsearch.cluster.service.ClusterService; -import org.elasticsearch.core.Tuple; import org.elasticsearch.reservedstate.TransformState; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xcontent.XContentParser; @@ -50,7 +47,7 @@ public void testValidation() { ClusterState state = ClusterState.builder(new ClusterName("elasticsearch")).build(); TransformState prevState = new TransformState(state, Collections.emptySet()); - ReservedAutoscalingPolicyAction action = new ReservedAutoscalingPolicyAction(mocks.v1(), mocks.v2()); + ReservedAutoscalingPolicyAction action = new ReservedAutoscalingPolicyAction(mocks, () -> DECIDERS); String badPolicyJSON = """ { @@ -81,7 +78,7 @@ public void testAddRemoveRoleMapping() throws Exception { ClusterState state = ClusterState.builder(new ClusterName("elasticsearch")).build(); TransformState prevState = new TransformState(state, Collections.emptySet()); - ReservedAutoscalingPolicyAction action = new ReservedAutoscalingPolicyAction(mocks.v1(), mocks.v2()); + ReservedAutoscalingPolicyAction action = new ReservedAutoscalingPolicyAction(mocks, () -> DECIDERS); String emptyJSON = ""; @@ -129,18 +126,10 @@ public void testAddRemoveRoleMapping() throws Exception { assertThat(updatedState.keys(), empty()); } - private Tuple createMockServices() { - ClusterService clusterService = mock(ClusterService.class); - AllocationService allocationService = mock(AllocationService.class); - doReturn(allocationService).when(clusterService).getAllocationService(); - doReturn(DECIDERS).when(allocationService).getAllocationDeciders(); - AutoscalingCalculateCapacityService service = new AutoscalingCalculateCapacityService(Set.of(new FixedAutoscalingDeciderService())); - + private AutoscalingCalculateCapacityService.Holder createMockServices() { Autoscaling autoscaling = mock(Autoscaling.class); doReturn(Set.of(new FixedAutoscalingDeciderService())).when(autoscaling).createDeciderServices(any()); - AutoscalingCalculateCapacityService.Holder holder = new AutoscalingCalculateCapacityService.Holder(autoscaling); - - return new Tuple<>(clusterService, holder); + return new AutoscalingCalculateCapacityService.Holder(autoscaling); } } diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/Ccr.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/Ccr.java index a8d3cdaeb108a..8a57f59c23067 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/Ccr.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/Ccr.java @@ -17,6 +17,7 @@ import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.ClusterSettings; @@ -185,7 +186,8 @@ public Collection createComponents( final NamedWriteableRegistry namedWriteableRegistry, final IndexNameExpressionResolver expressionResolver, final Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { this.client = client; if (enabled == false) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java index 8c845f57fc69d..1a052f83d1287 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java @@ -21,6 +21,7 @@ import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.allocation.DataTier; import org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.logging.DeprecationCategory; @@ -305,7 +306,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver expressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { List components = new ArrayList<>(); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/LocalStateCompositeXPackPlugin.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/LocalStateCompositeXPackPlugin.java index 0e0bb6b99c693..689ef9e3e702e 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/LocalStateCompositeXPackPlugin.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/LocalStateCompositeXPackPlugin.java @@ -28,6 +28,7 @@ import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.allocation.ExistingShardsAllocator; import org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.CheckedBiConsumer; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; @@ -199,7 +200,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver expressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { List components = new ArrayList<>(); components.addAll( @@ -215,7 +217,8 @@ public Collection createComponents( namedWriteableRegistry, expressionResolver, repositoriesServiceSupplier, - tracer + tracer, + allocationDecidersSupplier ) ); @@ -234,7 +237,8 @@ public Collection createComponents( namedWriteableRegistry, expressionResolver, repositoriesServiceSupplier, - tracer + tracer, + allocationDecidersSupplier ) ) ); diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/Deprecation.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/Deprecation.java index 90c3d5de993bc..5a7ed7d96e856 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/Deprecation.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/Deprecation.java @@ -11,6 +11,7 @@ import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.logging.RateLimitingFilter; @@ -98,7 +99,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver indexNameExpressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { final DeprecationIndexingTemplateRegistry templateRegistry = new DeprecationIndexingTemplateRegistry( environment.settings(), diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPlugin.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPlugin.java index e5ed0d83d2263..e6699a0c5ca74 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPlugin.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPlugin.java @@ -13,6 +13,7 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.ClusterSettings; @@ -199,7 +200,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver expressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { EnrichPolicyLocks enrichPolicyLocks = new EnrichPolicyLocks(); EnrichPolicyExecutor enrichPolicyExecutor = new EnrichPolicyExecutor( diff --git a/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/plugin/EqlPlugin.java b/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/plugin/EqlPlugin.java index 0924f128f7886..b7718f3ebce20 100644 --- a/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/plugin/EqlPlugin.java +++ b/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/plugin/EqlPlugin.java @@ -12,6 +12,7 @@ import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.breaker.CircuitBreaker; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; @@ -81,7 +82,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver expressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { return createComponents(client, environment.settings(), clusterService); } diff --git a/x-pack/plugin/fleet/src/main/java/org/elasticsearch/xpack/fleet/Fleet.java b/x-pack/plugin/fleet/src/main/java/org/elasticsearch/xpack/fleet/Fleet.java index d80b7b2c3a6f5..b853034b44a86 100644 --- a/x-pack/plugin/fleet/src/main/java/org/elasticsearch/xpack/fleet/Fleet.java +++ b/x-pack/plugin/fleet/src/main/java/org/elasticsearch/xpack/fleet/Fleet.java @@ -23,6 +23,7 @@ import org.elasticsearch.cluster.metadata.ComposableIndexTemplate; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; @@ -93,7 +94,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver expressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { FleetTemplateRegistry registry = new FleetTemplateRegistry( environment.settings(), diff --git a/x-pack/plugin/identity-provider/src/main/java/org/elasticsearch/xpack/idp/IdentityProviderPlugin.java b/x-pack/plugin/identity-provider/src/main/java/org/elasticsearch/xpack/idp/IdentityProviderPlugin.java index d3965a3ad9e21..f35ee4d8569ce 100644 --- a/x-pack/plugin/identity-provider/src/main/java/org/elasticsearch/xpack/idp/IdentityProviderPlugin.java +++ b/x-pack/plugin/identity-provider/src/main/java/org/elasticsearch/xpack/idp/IdentityProviderPlugin.java @@ -14,6 +14,7 @@ import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.ClusterSettings; @@ -96,7 +97,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver indexNameExpressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { settings = environment.settings(); enabled = ENABLED_SETTING.get(settings); diff --git a/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/UpdateSettingsStepTests.java b/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/UpdateSettingsStepTests.java index e5b681ae2b12a..828a101dc486b 100644 --- a/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/UpdateSettingsStepTests.java +++ b/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/UpdateSettingsStepTests.java @@ -12,6 +12,7 @@ import org.elasticsearch.cluster.ClusterStateObserver; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; @@ -72,7 +73,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver expressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { return List.of(service); } diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycle.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycle.java index 7b340986251c3..84c33b00e631d 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycle.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycle.java @@ -15,6 +15,7 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.NamedWriteableRegistry.Entry; @@ -210,7 +211,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver expressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { final List components = new ArrayList<>(); ILMHistoryTemplateRegistry ilmTemplateRegistry = new ILMHistoryTemplateRegistry( diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java index 67d1ea312b34d..5eeb903de0d81 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java @@ -29,6 +29,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.breaker.CircuitBreaker; import org.elasticsearch.common.collect.MapBuilder; @@ -825,7 +826,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver indexNameExpressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { if (enabled == false) { // special holder for @link(MachineLearningFeatureSetUsage) which needs access to job manager, empty if ML is disabled diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java index 30c45ae3e7f29..6425f33d83508 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java @@ -12,6 +12,7 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.IndexTemplateMetadata; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.ClusterSettings; @@ -128,7 +129,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver expressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { final ClusterSettings clusterSettings = clusterService.getClusterSettings(); final CleanerService cleanerService = new CleanerService(settings, clusterSettings, threadPool, getLicenseState()); diff --git a/x-pack/plugin/old-lucene-versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/OldLuceneVersions.java b/x-pack/plugin/old-lucene-versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/OldLuceneVersions.java index 25e74a68ae7c7..a21f51f3903ff 100644 --- a/x-pack/plugin/old-lucene-versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/OldLuceneVersions.java +++ b/x-pack/plugin/old-lucene-versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/OldLuceneVersions.java @@ -19,6 +19,7 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; @@ -97,7 +98,8 @@ public Collection createComponents( final NamedWriteableRegistry registry, final IndexNameExpressionResolver resolver, final Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { this.failShardsListener.set(new FailShardsOnInvalidLicenseClusterListener(getLicenseState(), clusterService.getRerouteService())); if (DiscoveryNode.isMasterNode(environment.settings())) { diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/Rollup.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/Rollup.java index 79890f6ece1f6..b6a10fc197169 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/Rollup.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/Rollup.java @@ -12,6 +12,7 @@ import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.ClusterSettings; @@ -114,7 +115,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver expressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { return emptyList(); } diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshots.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshots.java index 5df8d25b47d38..8030d205f0384 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshots.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshots.java @@ -25,6 +25,7 @@ import org.elasticsearch.cluster.routing.allocation.DataTier; import org.elasticsearch.cluster.routing.allocation.ExistingShardsAllocator; import org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Priority; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; @@ -329,7 +330,8 @@ public Collection createComponents( final NamedWriteableRegistry registry, final IndexNameExpressionResolver resolver, final Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { final List components = new ArrayList<>(); this.repositoriesServiceSupplier = repositoriesServiceSupplier; diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java index a977b7576ac40..9e0415899a6c3 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java @@ -22,6 +22,7 @@ import org.elasticsearch.cluster.metadata.IndexTemplateMetadata; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.CheckedBiConsumer; import org.elasticsearch.common.Strings; @@ -547,7 +548,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver expressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { try { return createComponents( diff --git a/x-pack/plugin/shutdown/src/internalClusterTest/java/org/elasticsearch/xpack/shutdown/NodeShutdownTasksIT.java b/x-pack/plugin/shutdown/src/internalClusterTest/java/org/elasticsearch/xpack/shutdown/NodeShutdownTasksIT.java index 4fba0a26f2d8c..b097e70169618 100644 --- a/x-pack/plugin/shutdown/src/internalClusterTest/java/org/elasticsearch/xpack/shutdown/NodeShutdownTasksIT.java +++ b/x-pack/plugin/shutdown/src/internalClusterTest/java/org/elasticsearch/xpack/shutdown/NodeShutdownTasksIT.java @@ -21,6 +21,7 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.SingleNodeShutdownMetadata; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.StreamInput; @@ -144,7 +145,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver indexNameExpressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { taskExecutor = new TaskExecutor(client, clusterService, threadPool); return Collections.singletonList(taskExecutor); diff --git a/x-pack/plugin/shutdown/src/main/java/org/elasticsearch/xpack/shutdown/ShutdownPlugin.java b/x-pack/plugin/shutdown/src/main/java/org/elasticsearch/xpack/shutdown/ShutdownPlugin.java index 542764706e2fd..63da5eafef745 100644 --- a/x-pack/plugin/shutdown/src/main/java/org/elasticsearch/xpack/shutdown/ShutdownPlugin.java +++ b/x-pack/plugin/shutdown/src/main/java/org/elasticsearch/xpack/shutdown/ShutdownPlugin.java @@ -12,6 +12,7 @@ import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.ClusterSettings; @@ -51,7 +52,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver indexNameExpressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { NodeSeenService nodeSeenService = new NodeSeenService(clusterService); diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlPlugin.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlPlugin.java index f1ce4efa85f5e..22b21f2fcaf9e 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlPlugin.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlPlugin.java @@ -11,6 +11,7 @@ import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.ClusterSettings; @@ -97,7 +98,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver expressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { return createComponents(client, environment.settings(), clusterService, namedWriteableRegistry); diff --git a/x-pack/plugin/stack/src/main/java/org/elasticsearch/xpack/stack/StackPlugin.java b/x-pack/plugin/stack/src/main/java/org/elasticsearch/xpack/stack/StackPlugin.java index 3e325b3ec6c0a..9847a183965b4 100644 --- a/x-pack/plugin/stack/src/main/java/org/elasticsearch/xpack/stack/StackPlugin.java +++ b/x-pack/plugin/stack/src/main/java/org/elasticsearch/xpack/stack/StackPlugin.java @@ -8,6 +8,7 @@ import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.Setting; @@ -53,7 +54,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver indexNameExpressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { StackTemplateRegistry templateRegistry = new StackTemplateRegistry(settings, clusterService, threadPool, client, xContentRegistry); templateRegistry.initialize(); diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/Transform.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/Transform.java index 626363452d174..b7ede0ccd874a 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/Transform.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/Transform.java @@ -24,6 +24,7 @@ import org.elasticsearch.cluster.metadata.IndexTemplateMetadata; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.settings.ClusterSettings; @@ -233,7 +234,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver expressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { TransformConfigManager configManager = new IndexBasedTransformConfigManager( clusterService, diff --git a/x-pack/plugin/voting-only-node/src/main/java/org/elasticsearch/cluster/coordination/votingonly/VotingOnlyNodePlugin.java b/x-pack/plugin/voting-only-node/src/main/java/org/elasticsearch/cluster/coordination/votingonly/VotingOnlyNodePlugin.java index 07c7b9bd296f4..c00809ef9babd 100644 --- a/x-pack/plugin/voting-only-node/src/main/java/org/elasticsearch/cluster/coordination/votingonly/VotingOnlyNodePlugin.java +++ b/x-pack/plugin/voting-only-node/src/main/java/org/elasticsearch/cluster/coordination/votingonly/VotingOnlyNodePlugin.java @@ -20,6 +20,7 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.StreamInput; @@ -93,7 +94,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver expressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { this.threadPool.set(threadPool); return Collections.emptyList(); diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java index 20ba37254af1a..c7aefc1509de2 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java @@ -24,6 +24,7 @@ import org.elasticsearch.cluster.metadata.IndexTemplateMetadata; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; @@ -304,7 +305,8 @@ public Collection createComponents( NamedWriteableRegistry namedWriteableRegistry, IndexNameExpressionResolver expressionResolver, Supplier repositoriesServiceSupplier, - Tracer tracer + Tracer tracer, + Supplier allocationDecidersSupplier ) { if (enabled == false) { return Collections.emptyList(); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherPluginTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherPluginTests.java index 23238b6a5012b..94cb554b6a5f8 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherPluginTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherPluginTests.java @@ -72,7 +72,10 @@ public void testWatcherDisabledTests() throws Exception { watcher.onIndexModule(indexModule); // also no component creation if not enabled - assertThat(watcher.createComponents(null, null, null, null, null, null, null, null, null, null, null, Tracer.NOOP), hasSize(0)); + assertThat( + watcher.createComponents(null, null, null, null, null, null, null, null, null, null, null, Tracer.NOOP, null), + hasSize(0) + ); watcher.close(); } From d93d71563c557c58ff19339a9fd9f749a5b7a641 Mon Sep 17 00:00:00 2001 From: Nikola Grcevski Date: Wed, 7 Sep 2022 13:52:44 -0400 Subject: [PATCH 10/12] Adjust code to match main --- .../xpack/autoscaling/Autoscaling.java | 8 ++++++++ .../action/ReservedAutoscalingPolicyAction.java | 15 ++------------- .../action/ReservedAutoscalingPolicyTests.java | 14 ++++---------- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/Autoscaling.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/Autoscaling.java index 49dfe3736f6b8..94f716966c37f 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/Autoscaling.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/Autoscaling.java @@ -31,6 +31,7 @@ import org.elasticsearch.plugins.ExtensiblePlugin; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.repositories.RepositoriesService; +import org.elasticsearch.reservedstate.ReservedClusterStateHandler; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestHandler; import org.elasticsearch.script.ScriptService; @@ -43,6 +44,7 @@ import org.elasticsearch.xpack.autoscaling.action.GetAutoscalingCapacityAction; import org.elasticsearch.xpack.autoscaling.action.GetAutoscalingPolicyAction; import org.elasticsearch.xpack.autoscaling.action.PutAutoscalingPolicyAction; +import org.elasticsearch.xpack.autoscaling.action.ReservedAutoscalingPolicyAction; import org.elasticsearch.xpack.autoscaling.action.TransportDeleteAutoscalingPolicyAction; import org.elasticsearch.xpack.autoscaling.action.TransportGetAutoscalingCapacityAction; import org.elasticsearch.xpack.autoscaling.action.TransportGetAutoscalingPolicyAction; @@ -92,6 +94,7 @@ public class Autoscaling extends Plugin implements ActionPlugin, ExtensiblePlugi private final SetOnce clusterServiceHolder = new SetOnce<>(); private final SetOnce allocationDeciders = new SetOnce<>(); private final AutoscalingLicenseChecker autoscalingLicenseChecker; + private final SetOnce reservedAutoscalingPolicyAction = new SetOnce<>(); public Autoscaling() { this(new AutoscalingLicenseChecker()); @@ -121,6 +124,7 @@ public Collection createComponents( this.clusterServiceHolder.set(clusterService); this.allocationDeciders.set(allocationDeciders); var capacityServiceHolder = new AutoscalingCalculateCapacityService.Holder(this); + this.reservedAutoscalingPolicyAction.set(new ReservedAutoscalingPolicyAction(capacityServiceHolder)); return List.of(capacityServiceHolder, autoscalingLicenseChecker, new AutoscalingNodeInfoService(clusterService, client)); } @@ -224,4 +228,8 @@ public Collection deciders() { public Set createDeciderServices() { return autoscalingExtensions.stream().flatMap(p -> p.deciders().stream()).collect(Collectors.toSet()); } + + public Collection> reservedClusterStateHandlers() { + return Set.of(reservedAutoscalingPolicyAction.get()); + } } diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyAction.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyAction.java index 95a2cc1e65fef..f4d5d495b758b 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyAction.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyAction.java @@ -8,7 +8,6 @@ package org.elasticsearch.xpack.autoscaling.action; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.reservedstate.ReservedClusterStateHandler; import org.elasticsearch.reservedstate.TransformState; import org.elasticsearch.xcontent.XContentParser; @@ -22,7 +21,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import java.util.function.Supplier; import java.util.stream.Collectors; import static org.elasticsearch.common.xcontent.XContentHelper.mapToXContentParser; @@ -36,7 +34,6 @@ public class ReservedAutoscalingPolicyAction implements ReservedClusterStateHandler> { public static final String NAME = "autoscaling"; - private final Supplier allocationDecidersSupplier; private final AutoscalingCalculateCapacityService.Holder policyValidatorHolder; /** @@ -44,12 +41,8 @@ public class ReservedAutoscalingPolicyAction implements ReservedClusterStateHand * * @param policyValidatorHolder requires AutoscalingCalculateCapacityService.Holder for validation */ - public ReservedAutoscalingPolicyAction( - final AutoscalingCalculateCapacityService.Holder policyValidatorHolder, - final Supplier allocationDecidersSupplier - ) { + public ReservedAutoscalingPolicyAction(final AutoscalingCalculateCapacityService.Holder policyValidatorHolder) { this.policyValidatorHolder = policyValidatorHolder; - this.allocationDecidersSupplier = allocationDecidersSupplier; } @Override @@ -74,11 +67,7 @@ public TransformState transform(Object source, TransformState prevState) throws ClusterState state = prevState.state(); for (var request : requests) { - state = TransportPutAutoscalingPolicyAction.putAutoscalingPolicy( - state, - request, - policyValidatorHolder.get(allocationDecidersSupplier.get()) - ); + state = TransportPutAutoscalingPolicyAction.putAutoscalingPolicy(state, request, policyValidatorHolder.get()); } Set entities = requests.stream().map(r -> r.name()).collect(Collectors.toSet()); diff --git a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyTests.java b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyTests.java index 6d907833d7825..e859426dbdef3 100644 --- a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyTests.java +++ b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyTests.java @@ -9,7 +9,6 @@ import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.reservedstate.TransformState; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xcontent.XContentParser; @@ -18,20 +17,17 @@ import org.elasticsearch.xpack.autoscaling.Autoscaling; import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingCalculateCapacityService; import org.elasticsearch.xpack.autoscaling.capacity.FixedAutoscalingDeciderService; -import org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider; import java.util.Collections; -import java.util.List; import java.util.Set; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.empty; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; /** - * Tests that the ReservedAutoscalingPolicyAction does validation, can add and remove autoscaling polcies + * Tests that the ReservedAutoscalingPolicyAction does validation, can add and remove autoscaling policies */ public class ReservedAutoscalingPolicyTests extends ESTestCase { private TransformState processJSON(ReservedAutoscalingPolicyAction action, TransformState prevState, String json) throws Exception { @@ -40,14 +36,12 @@ private TransformState processJSON(ReservedAutoscalingPolicyAction action, Trans } } - private static final AllocationDeciders DECIDERS = new AllocationDeciders(List.of(DataTierAllocationDecider.INSTANCE)); - public void testValidation() { var mocks = createMockServices(); ClusterState state = ClusterState.builder(new ClusterName("elasticsearch")).build(); TransformState prevState = new TransformState(state, Collections.emptySet()); - ReservedAutoscalingPolicyAction action = new ReservedAutoscalingPolicyAction(mocks, () -> DECIDERS); + ReservedAutoscalingPolicyAction action = new ReservedAutoscalingPolicyAction(mocks); String badPolicyJSON = """ { @@ -78,7 +72,7 @@ public void testAddRemoveRoleMapping() throws Exception { ClusterState state = ClusterState.builder(new ClusterName("elasticsearch")).build(); TransformState prevState = new TransformState(state, Collections.emptySet()); - ReservedAutoscalingPolicyAction action = new ReservedAutoscalingPolicyAction(mocks, () -> DECIDERS); + ReservedAutoscalingPolicyAction action = new ReservedAutoscalingPolicyAction(mocks); String emptyJSON = ""; @@ -128,7 +122,7 @@ public void testAddRemoveRoleMapping() throws Exception { private AutoscalingCalculateCapacityService.Holder createMockServices() { Autoscaling autoscaling = mock(Autoscaling.class); - doReturn(Set.of(new FixedAutoscalingDeciderService())).when(autoscaling).createDeciderServices(any()); + doReturn(Set.of(new FixedAutoscalingDeciderService())).when(autoscaling).createDeciderServices(); return new AutoscalingCalculateCapacityService.Holder(autoscaling); } From 0018f75e6e41c4a6679bfdd8ac36eba4f4671b2e Mon Sep 17 00:00:00 2001 From: Nikola Grcevski <6207777+grcevski@users.noreply.github.com> Date: Wed, 7 Sep 2022 13:57:40 -0400 Subject: [PATCH 11/12] Update docs/changelog/89708.yaml --- docs/changelog/89708.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog/89708.yaml b/docs/changelog/89708.yaml index 9e6197880a24f..251baae98268a 100644 --- a/docs/changelog/89708.yaml +++ b/docs/changelog/89708.yaml @@ -2,4 +2,4 @@ pr: 89708 summary: Operator/autoscaling area: Infra/Core type: enhancement -issues: [89183] +issues: [] From 700b5581cbd50f4ed5e2afc91b2e84c35e04be54 Mon Sep 17 00:00:00 2001 From: Nikola Grcevski Date: Mon, 12 Sep 2022 17:31:09 -0400 Subject: [PATCH 12/12] Address feedback --- ...servedAutoscalingStateHandlerProvider.java | 21 ++++++------------- .../ReservedAutoscalingPolicyAction.java | 8 +++---- .../ReservedAutoscalingPolicyTests.java | 7 +++++++ 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/LocalStateReservedAutoscalingStateHandlerProvider.java b/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/LocalStateReservedAutoscalingStateHandlerProvider.java index e70fb08b6748c..11583282ea800 100644 --- a/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/LocalStateReservedAutoscalingStateHandlerProvider.java +++ b/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/LocalStateReservedAutoscalingStateHandlerProvider.java @@ -11,10 +11,14 @@ import org.elasticsearch.reservedstate.ReservedClusterStateHandlerProvider; import java.util.Collection; -import java.util.Objects; /** - * Autoscaling provider implementation for the {@link ReservedClusterStateHandlerProvider} service interface + * Mock autoscaling provider implementation for the {@link ReservedClusterStateHandlerProvider} service interface + *

+ * This class is a test version of the {@link ReservedAutoscalingStateHandlerProvider}. When we load handler providers through + * our custom SPI interface, we must match the plugin type exactly. With MockNode, when we run + * {@link org.elasticsearch.test.ESIntegTestCase} test cases, the version of the {@link Autoscaling} plugin + * is {@link LocalStateAutoscaling}, therefore we need to provide a test version of this class. */ public class LocalStateReservedAutoscalingStateHandlerProvider implements ReservedClusterStateHandlerProvider { private final LocalStateAutoscaling plugin; @@ -27,19 +31,6 @@ public LocalStateReservedAutoscalingStateHandlerProvider(LocalStateAutoscaling p this.plugin = plugin; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - LocalStateReservedAutoscalingStateHandlerProvider that = (LocalStateReservedAutoscalingStateHandlerProvider) o; - return plugin.equals(that.plugin); - } - - @Override - public int hashCode() { - return Objects.hash(plugin); - } - @Override public Collection> handlers() { return plugin.testPlugin().reservedClusterStateHandlers(); diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyAction.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyAction.java index f4d5d495b758b..fe443183c87a2 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyAction.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyAction.java @@ -50,10 +50,7 @@ public String name() { return NAME; } - @SuppressWarnings("unchecked") - public Collection prepare(Object input) { - List policies = (List) input; - + private Collection prepare(List policies) { for (var policy : policies) { validate(policy); } @@ -63,7 +60,8 @@ public Collection prepare(Object input) { @Override public TransformState transform(Object source, TransformState prevState) throws Exception { - var requests = prepare(source); + @SuppressWarnings("unchecked") + var requests = prepare((List) source); ClusterState state = prevState.state(); for (var request : requests) { diff --git a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyTests.java b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyTests.java index e859426dbdef3..4f8cec0ee845d 100644 --- a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyTests.java +++ b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/action/ReservedAutoscalingPolicyTests.java @@ -15,6 +15,7 @@ import org.elasticsearch.xcontent.XContentParserConfiguration; import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xpack.autoscaling.Autoscaling; +import org.elasticsearch.xpack.autoscaling.AutoscalingMetadata; import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingCalculateCapacityService; import org.elasticsearch.xpack.autoscaling.capacity.FixedAutoscalingDeciderService; @@ -101,6 +102,12 @@ public void testAddRemoveRoleMapping() throws Exception { prevState = updatedState; updatedState = processJSON(action, prevState, json); assertThat(updatedState.keys(), containsInAnyOrder("my_autoscaling_policy", "my_autoscaling_policy_1")); + AutoscalingMetadata autoMetadata = updatedState.state().metadata().custom(AutoscalingMetadata.NAME); + assertThat(autoMetadata.policies().keySet(), containsInAnyOrder("my_autoscaling_policy", "my_autoscaling_policy_1")); + assertThat(autoMetadata.policies().get("my_autoscaling_policy").policy().roles(), containsInAnyOrder("data_hot")); + assertThat(autoMetadata.policies().get("my_autoscaling_policy").policy().deciders().keySet(), containsInAnyOrder("fixed")); + assertThat(autoMetadata.policies().get("my_autoscaling_policy_1").policy().roles(), containsInAnyOrder("data_warm")); + assertThat(autoMetadata.policies().get("my_autoscaling_policy_1").policy().deciders().keySet(), containsInAnyOrder("fixed")); String halfJSON = """ {