From db6e8c736d92582fe56024993450ce0a987b498d Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Thu, 2 Aug 2018 15:49:59 +0200 Subject: [PATCH] Remove cluster state initial customs (#32501) This infrastructure was introduced in #26144 and made obsolete in #30743 --- .../elasticsearch/cluster/ClusterModule.java | 17 ----- .../cluster/service/ClusterApplier.java | 5 -- .../service/ClusterApplierService.java | 9 +-- .../cluster/service/ClusterService.java | 19 +---- .../discovery/single/SingleNodeDiscovery.java | 3 +- .../discovery/zen/ZenDiscovery.java | 2 +- .../org/elasticsearch/gateway/Gateway.java | 3 +- .../java/org/elasticsearch/node/Node.java | 3 +- .../elasticsearch/plugins/ClusterPlugin.java | 9 --- .../cluster/ClusterModuleTests.java | 53 +------------- .../cluster/SimpleClusterStateIT.java | 73 ++++++++++++++++--- .../service/ClusterApplierServiceTests.java | 2 +- .../cluster/service/ClusterSerivceTests.java | 68 ----------------- .../single/SingleNodeDiscoveryTests.java | 6 -- .../discovery/zen/ZenDiscoveryUnitTests.java | 5 -- .../gateway/GatewayServiceTests.java | 3 +- .../node/ResponseCollectorServiceTests.java | 3 +- .../DedicatedClusterSnapshotRestoreIT.java | 21 ------ .../test/ClusterServiceUtils.java | 2 +- .../core/LocalStateCompositeXPackPlugin.java | 7 -- 20 files changed, 75 insertions(+), 238 deletions(-) delete mode 100644 server/src/test/java/org/elasticsearch/cluster/service/ClusterSerivceTests.java diff --git a/server/src/main/java/org/elasticsearch/cluster/ClusterModule.java b/server/src/main/java/org/elasticsearch/cluster/ClusterModule.java index 9c5c642df6b91..8362198a12c4b 100644 --- a/server/src/main/java/org/elasticsearch/cluster/ClusterModule.java +++ b/server/src/main/java/org/elasticsearch/cluster/ClusterModule.java @@ -116,23 +116,6 @@ public ClusterModule(Settings settings, ClusterService clusterService, List> getClusterStateCustomSuppliers(List clusterPlugins) { - final Map> customSupplier = new HashMap<>(); - customSupplier.put(SnapshotDeletionsInProgress.TYPE, SnapshotDeletionsInProgress::new); - customSupplier.put(RestoreInProgress.TYPE, RestoreInProgress::new); - customSupplier.put(SnapshotsInProgress.TYPE, SnapshotsInProgress::new); - for (ClusterPlugin plugin : clusterPlugins) { - Map> initialCustomSupplier = plugin.getInitialClusterStateCustomSupplier(); - for (String key : initialCustomSupplier.keySet()) { - if (customSupplier.containsKey(key)) { - throw new IllegalStateException("custom supplier key [" + key + "] is registered more than once"); - } - } - customSupplier.putAll(initialCustomSupplier); - } - return Collections.unmodifiableMap(customSupplier); - } - public static List getNamedWriteables() { List entries = new ArrayList<>(); // Cluster State diff --git a/server/src/main/java/org/elasticsearch/cluster/service/ClusterApplier.java b/server/src/main/java/org/elasticsearch/cluster/service/ClusterApplier.java index c587ab272e903..781adb3742a90 100644 --- a/server/src/main/java/org/elasticsearch/cluster/service/ClusterApplier.java +++ b/server/src/main/java/org/elasticsearch/cluster/service/ClusterApplier.java @@ -39,11 +39,6 @@ public interface ClusterApplier { */ void onNewClusterState(String source, Supplier clusterStateSupplier, ClusterApplyListener listener); - /** - * Creates a new cluster state builder that is initialized with the cluster name and all initial cluster state customs. - */ - ClusterState.Builder newClusterStateBuilder(); - /** * Listener for results of cluster state application */ diff --git a/server/src/main/java/org/elasticsearch/cluster/service/ClusterApplierService.java b/server/src/main/java/org/elasticsearch/cluster/service/ClusterApplierService.java index 2fb7c25671c88..5dd36b9b1bc20 100644 --- a/server/src/main/java/org/elasticsearch/cluster/service/ClusterApplierService.java +++ b/server/src/main/java/org/elasticsearch/cluster/service/ClusterApplierService.java @@ -96,17 +96,14 @@ public class ClusterApplierService extends AbstractLifecycleComponent implements private final AtomicReference state; // last applied state private NodeConnectionsService nodeConnectionsService; - private Supplier stateBuilderSupplier; - public ClusterApplierService(Settings settings, ClusterSettings clusterSettings, ThreadPool threadPool, Supplier stateBuilderSupplier) { + public ClusterApplierService(Settings settings, ClusterSettings clusterSettings, ThreadPool threadPool) { super(settings); this.clusterSettings = clusterSettings; this.threadPool = threadPool; this.state = new AtomicReference<>(); this.slowTaskLoggingThreshold = CLUSTER_SERVICE_SLOW_TASK_LOGGING_THRESHOLD_SETTING.get(settings); this.localNodeMasterListeners = new LocalNodeMasterListeners(threadPool); - this.stateBuilderSupplier = stateBuilderSupplier; } public void setSlowTaskLoggingThreshold(TimeValue slowTaskLoggingThreshold) { @@ -652,8 +649,4 @@ protected long currentTimeInNanos() { return System.nanoTime(); } - @Override - public ClusterState.Builder newClusterStateBuilder() { - return stateBuilderSupplier.get(); - } } 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 7610d75f677db..fc5dc678bd000 100644 --- a/server/src/main/java/org/elasticsearch/cluster/service/ClusterService.java +++ b/server/src/main/java/org/elasticsearch/cluster/service/ClusterService.java @@ -42,7 +42,6 @@ import java.util.Collections; import java.util.Map; -import java.util.function.Supplier; public class ClusterService extends AbstractLifecycleComponent { @@ -59,10 +58,8 @@ public class ClusterService extends AbstractLifecycleComponent { private final OperationRouting operationRouting; private final ClusterSettings clusterSettings; - private final Map> initialClusterStateCustoms; - public ClusterService(Settings settings, ClusterSettings clusterSettings, ThreadPool threadPool, - Map> initialClusterStateCustoms) { + public ClusterService(Settings settings, ClusterSettings clusterSettings, ThreadPool threadPool) { super(settings); this.masterService = new MasterService(settings, threadPool); this.operationRouting = new OperationRouting(settings, clusterSettings); @@ -70,19 +67,7 @@ public ClusterService(Settings settings, ClusterSettings clusterSettings, Thread this.clusterName = ClusterName.CLUSTER_NAME_SETTING.get(settings); this.clusterSettings.addSettingsUpdateConsumer(CLUSTER_SERVICE_SLOW_TASK_LOGGING_THRESHOLD_SETTING, this::setSlowTaskLoggingThreshold); - this.initialClusterStateCustoms = initialClusterStateCustoms; - this.clusterApplierService = new ClusterApplierService(settings, clusterSettings, threadPool, this::newClusterStateBuilder); - } - - /** - * Creates a new cluster state builder that is initialized with the cluster name and all initial cluster state customs. - */ - public ClusterState.Builder newClusterStateBuilder() { - ClusterState.Builder builder = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.get(settings)); - for (Map.Entry> entry : initialClusterStateCustoms.entrySet()) { - builder.putCustom(entry.getKey(), entry.getValue().get()); - } - return builder; + this.clusterApplierService = new ClusterApplierService(settings, clusterSettings, threadPool); } private void setSlowTaskLoggingThreshold(TimeValue slowTaskLoggingThreshold) { diff --git a/server/src/main/java/org/elasticsearch/discovery/single/SingleNodeDiscovery.java b/server/src/main/java/org/elasticsearch/discovery/single/SingleNodeDiscovery.java index d7c37febb5dd2..462136a22fe94 100644 --- a/server/src/main/java/org/elasticsearch/discovery/single/SingleNodeDiscovery.java +++ b/server/src/main/java/org/elasticsearch/discovery/single/SingleNodeDiscovery.java @@ -21,6 +21,7 @@ import org.apache.logging.log4j.message.ParameterizedMessage; import org.elasticsearch.cluster.ClusterChangedEvent; +import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlocks; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -113,7 +114,7 @@ protected synchronized void doStart() { } protected ClusterState createInitialState(DiscoveryNode localNode) { - ClusterState.Builder builder = clusterApplier.newClusterStateBuilder(); + ClusterState.Builder builder = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.get(settings)); return builder.nodes(DiscoveryNodes.builder().add(localNode) .localNodeId(localNode.getId()) .masterNodeId(localNode.getId()) diff --git a/server/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java b/server/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java index eb9a9f8d4885d..a68557adb9d03 100644 --- a/server/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java +++ b/server/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java @@ -252,7 +252,7 @@ protected void doStart() { // set initial state assert committedState.get() == null; assert localNode != null; - ClusterState.Builder builder = clusterApplier.newClusterStateBuilder(); + ClusterState.Builder builder = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.get(settings)); ClusterState initialState = builder .blocks(ClusterBlocks.builder() .addGlobalBlock(STATE_NOT_RECOVERED_BLOCK) diff --git a/server/src/main/java/org/elasticsearch/gateway/Gateway.java b/server/src/main/java/org/elasticsearch/gateway/Gateway.java index ae8f5a85def44..d2261e5d1b421 100644 --- a/server/src/main/java/org/elasticsearch/gateway/Gateway.java +++ b/server/src/main/java/org/elasticsearch/gateway/Gateway.java @@ -23,6 +23,7 @@ import com.carrotsearch.hppc.cursors.ObjectCursor; import org.apache.logging.log4j.message.ParameterizedMessage; import org.elasticsearch.action.FailedNodeException; +import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; @@ -147,7 +148,7 @@ public void performStateRecovery(final GatewayStateRecoveredListener listener) t metaDataBuilder.transientSettings(), e -> logUnknownSetting("transient", e), (e, ex) -> logInvalidSetting("transient", e, ex))); - ClusterState.Builder builder = clusterService.newClusterStateBuilder(); + ClusterState.Builder builder = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.get(settings)); builder.metaData(metaDataBuilder); listener.onSuccess(builder.build()); } diff --git a/server/src/main/java/org/elasticsearch/node/Node.java b/server/src/main/java/org/elasticsearch/node/Node.java index b5cc79640854f..c65488bd08eb7 100644 --- a/server/src/main/java/org/elasticsearch/node/Node.java +++ b/server/src/main/java/org/elasticsearch/node/Node.java @@ -349,8 +349,7 @@ protected Node(final Environment environment, Collection getCustomNameResolvers(pluginsService.filterPlugins(DiscoveryPlugin.class))); List clusterPlugins = pluginsService.filterPlugins(ClusterPlugin.class); - final ClusterService clusterService = new ClusterService(settings, settingsModule.getClusterSettings(), threadPool, - ClusterModule.getClusterStateCustomSuppliers(clusterPlugins)); + final ClusterService clusterService = new ClusterService(settings, settingsModule.getClusterSettings(), threadPool); clusterService.addStateApplier(scriptModule.getScriptService()); resourcesToClose.add(clusterService); final IngestService ingestService = new IngestService(settings, threadPool, this.environment, diff --git a/server/src/main/java/org/elasticsearch/plugins/ClusterPlugin.java b/server/src/main/java/org/elasticsearch/plugins/ClusterPlugin.java index 61145c7a1d7cf..a1274b9346cc8 100644 --- a/server/src/main/java/org/elasticsearch/plugins/ClusterPlugin.java +++ b/server/src/main/java/org/elasticsearch/plugins/ClusterPlugin.java @@ -24,7 +24,6 @@ import java.util.Map; import java.util.function.Supplier; -import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.routing.allocation.allocator.ShardsAllocator; import org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider; import org.elasticsearch.common.settings.ClusterSettings; @@ -66,12 +65,4 @@ default Map> getShardsAllocators(Settings sett default void onNodeStarted() { } - /** - * Returns a map of {@link ClusterState.Custom} supplier that should be invoked to initialize the initial clusterstate. - * This allows custom clusterstate extensions to be always present and prevents invariants where clusterstates are published - * but customs are not initialized. - * - * TODO: Remove this whole concept of InitialClusterStateCustomSupplier, it's not used anymore - */ - default Map> getInitialClusterStateCustomSupplier() { return Collections.emptyMap(); } } diff --git a/server/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java b/server/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java index 4c7a42de2ee95..af3807226a943 100644 --- a/server/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java @@ -63,7 +63,7 @@ public class ClusterModuleTests extends ModuleTestCase { private ClusterInfoService clusterInfoService = EmptyClusterInfoService.INSTANCE; private ClusterService clusterService = new ClusterService(Settings.EMPTY, - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), null, Collections.emptyMap()); + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), null); static class FakeAllocationDecider extends AllocationDecider { protected FakeAllocationDecider(Settings settings) { super(settings); @@ -202,57 +202,6 @@ public void testAllocationDeciderOrder() { } } - public void testCustomSuppliers() { - Map> customSuppliers = ClusterModule.getClusterStateCustomSuppliers(Collections.emptyList()); - assertEquals(3, customSuppliers.size()); - assertTrue(customSuppliers.containsKey(SnapshotsInProgress.TYPE)); - assertTrue(customSuppliers.containsKey(SnapshotDeletionsInProgress.TYPE)); - assertTrue(customSuppliers.containsKey(RestoreInProgress.TYPE)); - - customSuppliers = ClusterModule.getClusterStateCustomSuppliers(Collections.singletonList(new ClusterPlugin() { - @Override - public Map> getInitialClusterStateCustomSupplier() { - return Collections.singletonMap("foo", () -> null); - } - })); - assertEquals(4, customSuppliers.size()); - assertTrue(customSuppliers.containsKey(SnapshotsInProgress.TYPE)); - assertTrue(customSuppliers.containsKey(SnapshotDeletionsInProgress.TYPE)); - assertTrue(customSuppliers.containsKey(RestoreInProgress.TYPE)); - assertTrue(customSuppliers.containsKey("foo")); - - { - // Eclipse Neon 2 didn't compile the plugins definition inside the lambda expression, - // probably due to https://bugs.eclipse.org/bugs/show_bug.cgi?id=511750, which is - // fixed in Eclipse Oxygon. Pulled out the plugins definition to make it work in older versions - List plugins = Collections.singletonList(new ClusterPlugin() { - @Override - public Map> getInitialClusterStateCustomSupplier() { - return Collections.singletonMap(SnapshotsInProgress.TYPE, () -> null); - } - }); - IllegalStateException ise = expectThrows(IllegalStateException.class, - () -> ClusterModule.getClusterStateCustomSuppliers(plugins)); - assertEquals(ise.getMessage(), "custom supplier key [snapshots] is registered more than once"); - } - { - List plugins = Arrays.asList(new ClusterPlugin() { - @Override - public Map> getInitialClusterStateCustomSupplier() { - return Collections.singletonMap("foo", () -> null); - } - }, new ClusterPlugin() { - @Override - public Map> getInitialClusterStateCustomSupplier() { - return Collections.singletonMap("foo", () -> null); - } - }); - IllegalStateException ise = expectThrows(IllegalStateException.class, - () -> ClusterModule.getClusterStateCustomSuppliers(plugins)); - assertEquals(ise.getMessage(), "custom supplier key [foo] is registered more than once"); - } - } - public void testPre63CustomsFiltering() { final String whiteListedClusterCustom = randomFrom(ClusterModule.PRE_6_3_CLUSTER_CUSTOMS_WHITE_LIST); final String whiteListedMetaDataCustom = randomFrom(ClusterModule.PRE_6_3_METADATA_CUSTOMS_WHITE_LIST); diff --git a/server/src/test/java/org/elasticsearch/cluster/SimpleClusterStateIT.java b/server/src/test/java/org/elasticsearch/cluster/SimpleClusterStateIT.java index 0ba3de4381891..606e716d210b2 100644 --- a/server/src/test/java/org/elasticsearch/cluster/SimpleClusterStateIT.java +++ b/server/src/test/java/org/elasticsearch/cluster/SimpleClusterStateIT.java @@ -30,6 +30,7 @@ import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.common.Priority; import org.elasticsearch.common.Strings; import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.collect.ImmutableOpenMap; @@ -38,14 +39,20 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeValue; +import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.env.Environment; +import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.plugins.ClusterPlugin; import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.script.ScriptService; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.hamcrest.CollectionAssertions; +import org.elasticsearch.threadpool.ThreadPool; +import org.elasticsearch.watcher.ResourceWatcherService; import org.junit.Before; import java.io.IOException; @@ -53,9 +60,9 @@ import java.util.Collection; import java.util.Collections; import java.util.List; -import java.util.Map; -import java.util.function.Supplier; +import java.util.concurrent.atomic.AtomicBoolean; +import static org.elasticsearch.gateway.GatewayService.STATE_NOT_RECOVERED_BLOCK; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertIndexTemplateExists; import static org.hamcrest.Matchers.equalTo; @@ -279,13 +286,11 @@ public void testIndicesIgnoreUnavailableFalse() throws Exception { } } - public void testPrivateCustomsAreExcluded() { + public void testPrivateCustomsAreExcluded() throws Exception { + // ensure that the custom is injected into the cluster state + assertBusy(() -> assertTrue(clusterService().state().customs().containsKey("test"))); ClusterStateResponse clusterStateResponse = client().admin().cluster().prepareState().setCustoms(true).get(); assertFalse(clusterStateResponse.getState().customs().containsKey("test")); - // just to make sure there is something - assertTrue(clusterStateResponse.getState().customs().containsKey(SnapshotDeletionsInProgress.TYPE)); - ClusterState state = internalCluster().getInstance(ClusterService.class).state(); - assertTrue(state.customs().containsKey("test")); } private static class TestCustom extends AbstractNamedDiffable implements ClusterState.Custom { @@ -333,11 +338,6 @@ public static class PrivateCustomPlugin extends Plugin implements ClusterPlugin public PrivateCustomPlugin() {} - @Override - public Map> getInitialClusterStateCustomSupplier() { - return Collections.singletonMap("test", () -> new TestCustom(1)); - } - @Override public List getNamedWriteables() { List entries = new ArrayList<>(); @@ -345,5 +345,54 @@ public List getNamedWriteables() { entries.add(new NamedWriteableRegistry.Entry(NamedDiff.class, "test", TestCustom::readDiffFrom)); return entries; } + + private final AtomicBoolean installed = new AtomicBoolean(); + + @Override + public Collection createComponents( + final Client client, + final ClusterService clusterService, + final ThreadPool threadPool, + final ResourceWatcherService resourceWatcherService, + final ScriptService scriptService, + final NamedXContentRegistry xContentRegistry, + final Environment environment, + final NodeEnvironment nodeEnvironment, + final NamedWriteableRegistry namedWriteableRegistry) { + clusterService.addListener(event -> { + final ClusterState state = event.state(); + if (state.getBlocks().hasGlobalBlock(STATE_NOT_RECOVERED_BLOCK)) { + return; + } + + if (state.nodes().isLocalNodeElectedMaster()) { + if (state.custom("test") == null) { + if (installed.compareAndSet(false, true)) { + clusterService.submitStateUpdateTask("install-metadata-custom", new ClusterStateUpdateTask(Priority.URGENT) { + + @Override + public ClusterState execute(ClusterState currentState) { + if (currentState.custom("test") == null) { + final ClusterState.Builder builder = ClusterState.builder(currentState); + builder.putCustom("test", new TestCustom(42)); + return builder.build(); + } else { + return currentState; + } + } + + @Override + public void onFailure(String source, Exception e) { + throw new AssertionError(e); + } + + }); + } + } + } + + }); + return Collections.emptyList(); + } } } diff --git a/server/src/test/java/org/elasticsearch/cluster/service/ClusterApplierServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/service/ClusterApplierServiceTests.java index cbf8a7eda2b3e..0ca47377bdd0d 100644 --- a/server/src/test/java/org/elasticsearch/cluster/service/ClusterApplierServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/service/ClusterApplierServiceTests.java @@ -412,7 +412,7 @@ static class TimedClusterApplierService extends ClusterApplierService { public volatile Long currentTimeOverride = null; TimedClusterApplierService(Settings settings, ClusterSettings clusterSettings, ThreadPool threadPool) { - super(settings, clusterSettings, threadPool, () -> ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.get(settings))); + super(settings, clusterSettings, threadPool); } @Override diff --git a/server/src/test/java/org/elasticsearch/cluster/service/ClusterSerivceTests.java b/server/src/test/java/org/elasticsearch/cluster/service/ClusterSerivceTests.java deleted file mode 100644 index 2cebd41a52c43..0000000000000 --- a/server/src/test/java/org/elasticsearch/cluster/service/ClusterSerivceTests.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.elasticsearch.cluster.service; - -import org.elasticsearch.Version; -import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.Diff; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.settings.ClusterSettings; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.test.ESTestCase; - -import java.io.IOException; -import java.util.Collections; - -public class ClusterSerivceTests extends ESTestCase { - - public void testNewBuilderContainsCustoms() { - ClusterState.Custom custom = new ClusterState.Custom() { - @Override - public Diff diff(ClusterState.Custom previousState) { - return null; - } - - @Override - public String getWriteableName() { - return null; - } - - @Override - public Version getMinimalSupportedVersion() { - return Version.CURRENT; - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - return null; - } - }; - ClusterService service = new ClusterService(Settings.EMPTY, - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), null, Collections.singletonMap("foo", () -> - custom)); - ClusterState.Builder builder = service.newClusterStateBuilder(); - assertSame(builder.build().custom("foo"), custom); - } -} diff --git a/server/src/test/java/org/elasticsearch/discovery/single/SingleNodeDiscoveryTests.java b/server/src/test/java/org/elasticsearch/discovery/single/SingleNodeDiscoveryTests.java index d045adcaead21..57f7bfec6ef38 100644 --- a/server/src/test/java/org/elasticsearch/discovery/single/SingleNodeDiscoveryTests.java +++ b/server/src/test/java/org/elasticsearch/discovery/single/SingleNodeDiscoveryTests.java @@ -21,7 +21,6 @@ import org.elasticsearch.core.internal.io.IOUtils; import org.elasticsearch.Version; -import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; @@ -64,11 +63,6 @@ public void setInitialState(ClusterState initialState) { clusterState.set(initialState); } - @Override - public ClusterState.Builder newClusterStateBuilder() { - return ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.get(settings)); - } - @Override public void onNewClusterState(String source, Supplier clusterStateSupplier, ClusterApplyListener listener) { diff --git a/server/src/test/java/org/elasticsearch/discovery/zen/ZenDiscoveryUnitTests.java b/server/src/test/java/org/elasticsearch/discovery/zen/ZenDiscoveryUnitTests.java index 6dbf80d9be675..2c4fb0c7e8db2 100644 --- a/server/src/test/java/org/elasticsearch/discovery/zen/ZenDiscoveryUnitTests.java +++ b/server/src/test/java/org/elasticsearch/discovery/zen/ZenDiscoveryUnitTests.java @@ -306,11 +306,6 @@ public void setInitialState(ClusterState initialState) { } - @Override - public ClusterState.Builder newClusterStateBuilder() { - return ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.get(settings)); - } - @Override public void onNewClusterState(String source, Supplier clusterStateSupplier, ClusterApplyListener listener) { listener.onSuccess(source); diff --git a/server/src/test/java/org/elasticsearch/gateway/GatewayServiceTests.java b/server/src/test/java/org/elasticsearch/gateway/GatewayServiceTests.java index bd3d5beeaf5c0..3e4a3dce09153 100644 --- a/server/src/test/java/org/elasticsearch/gateway/GatewayServiceTests.java +++ b/server/src/test/java/org/elasticsearch/gateway/GatewayServiceTests.java @@ -27,14 +27,13 @@ import org.hamcrest.Matchers; import java.io.IOException; -import java.util.Collections; public class GatewayServiceTests extends ESTestCase { private GatewayService createService(Settings.Builder settings) { ClusterService clusterService = new ClusterService(Settings.builder().put("cluster.name", "GatewayServiceTests").build(), new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), - null, Collections.emptyMap()); + null); return new GatewayService(settings.build(), null, clusterService, null, null, null, null); } diff --git a/server/src/test/java/org/elasticsearch/node/ResponseCollectorServiceTests.java b/server/src/test/java/org/elasticsearch/node/ResponseCollectorServiceTests.java index d86d7b46cc7a1..8aa0f3ec5bad6 100644 --- a/server/src/test/java/org/elasticsearch/node/ResponseCollectorServiceTests.java +++ b/server/src/test/java/org/elasticsearch/node/ResponseCollectorServiceTests.java @@ -34,7 +34,6 @@ import org.junit.After; import org.junit.Before; -import java.util.Collections; import java.util.Map; import java.util.concurrent.CountDownLatch; @@ -53,7 +52,7 @@ public void setUp() throws Exception { threadpool = new TestThreadPool("response_collector_tests"); clusterService = new ClusterService(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), - threadpool, Collections.emptyMap()); + threadpool); collector = new ResponseCollectorService(Settings.EMPTY, clusterService); } diff --git a/server/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java b/server/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java index 5d2abdd149223..a008846e2d325 100644 --- a/server/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java +++ b/server/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java @@ -31,7 +31,6 @@ import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotStats; import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotStatus; import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse; -import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.support.ActiveShardCount; import org.elasticsearch.client.AdminClient; @@ -40,8 +39,6 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterStateUpdateTask; import org.elasticsearch.cluster.NamedDiff; -import org.elasticsearch.cluster.RestoreInProgress; -import org.elasticsearch.cluster.SnapshotDeletionsInProgress; import org.elasticsearch.cluster.SnapshotsInProgress; import org.elasticsearch.cluster.health.ClusterHealthStatus; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; @@ -165,24 +162,6 @@ protected Collection> nodePlugins() { return Arrays.asList(MockRepository.Plugin.class, TestCustomMetaDataPlugin.class); } - public void testClusterStateHasCustoms() throws Exception { - ClusterStateResponse clusterStateResponse = client().admin().cluster().prepareState().all().get(); - assertNotNull(clusterStateResponse.getState().custom(SnapshotsInProgress.TYPE)); - assertNotNull(clusterStateResponse.getState().custom(RestoreInProgress.TYPE)); - assertNotNull(clusterStateResponse.getState().custom(SnapshotDeletionsInProgress.TYPE)); - internalCluster().ensureAtLeastNumDataNodes(2); - if (randomBoolean()) { - internalCluster().fullRestart(); - } else { - internalCluster().rollingRestart(); - } - - clusterStateResponse = client().admin().cluster().prepareState().all().get(); - assertNotNull(clusterStateResponse.getState().custom(SnapshotsInProgress.TYPE)); - assertNotNull(clusterStateResponse.getState().custom(RestoreInProgress.TYPE)); - assertNotNull(clusterStateResponse.getState().custom(SnapshotDeletionsInProgress.TYPE)); - } - public void testRestorePersistentSettings() throws Exception { logger.info("--> start 2 nodes"); internalCluster().startNode(); diff --git a/test/framework/src/main/java/org/elasticsearch/test/ClusterServiceUtils.java b/test/framework/src/main/java/org/elasticsearch/test/ClusterServiceUtils.java index 8c4076e327d70..fff29dff3f680 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ClusterServiceUtils.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ClusterServiceUtils.java @@ -132,7 +132,7 @@ public static ClusterService createClusterService(ThreadPool threadPool, Discove public static ClusterService createClusterService(ThreadPool threadPool, DiscoveryNode localNode, ClusterSettings clusterSettings) { ClusterService clusterService = new ClusterService(Settings.builder().put("cluster.name", "ClusterServiceTests").build(), - clusterSettings, threadPool, Collections.emptyMap()); + clusterSettings, threadPool); clusterService.setNodeConnectionsService(new NodeConnectionsService(Settings.EMPTY, null, null) { @Override public void connectToNodes(DiscoveryNodes discoveryNodes) { 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 796cae375e3a6..e0029362003df 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 @@ -349,13 +349,6 @@ public void onIndexModule(IndexModule indexModule) { filterPlugins(Plugin.class).stream().forEach(p -> p.onIndexModule(indexModule)); } - @Override - public Map> getInitialClusterStateCustomSupplier() { - Map> suppliers = new HashMap<>(); - filterPlugins(ClusterPlugin.class).stream().forEach(p -> suppliers.putAll(p.getInitialClusterStateCustomSupplier())); - return suppliers; - } - @Override public Function> getFieldFilter() { List>> items = filterPlugins(MapperPlugin.class).stream().map(p ->