diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecycleExecutionStateUtils.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecycleExecutionStateUtils.java deleted file mode 100644 index ab445ed279ea8..0000000000000 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecycleExecutionStateUtils.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.core.ilm; - -import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.metadata.LifecycleExecutionState; -import org.elasticsearch.cluster.metadata.Metadata; -import org.elasticsearch.index.Index; - -import java.util.Objects; - -/** - * A utility class used for index lifecycle execution states - */ -public class LifecycleExecutionStateUtils { - - private LifecycleExecutionStateUtils() {} - - /** - * Given a cluster state, index, and lifecycle state, returns a cluster state where - * the lifecycle state will be associated with the given index. - *
- * The passed-in index must already be present in the cluster state, this method cannot - * be used to add an index. - *
- * See also {@link Metadata#withLifecycleState}. - */ - public static ClusterState newClusterStateWithLifecycleState( - final ClusterState clusterState, - final Index index, - final LifecycleExecutionState lifecycleState - ) { - Objects.requireNonNull(clusterState, "clusterState must not be null"); - Objects.requireNonNull(index, "index must not be null"); - Objects.requireNonNull(lifecycleState, "lifecycleState must not be null"); - - final Metadata metadata = clusterState.metadata().withLifecycleState(index, lifecycleState); - if (metadata == clusterState.metadata()) { - return clusterState; - } else { - return ClusterState.builder(clusterState).metadata(metadata).build(); - } - } - -} diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/LifecycleExecutionStateUtilsTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/LifecycleExecutionStateUtilsTests.java deleted file mode 100644 index e7d112d6fc794..0000000000000 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/LifecycleExecutionStateUtilsTests.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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.core.ilm; - -import org.elasticsearch.cluster.ClusterName; -import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.metadata.IndexMetadata; -import org.elasticsearch.cluster.metadata.LifecycleExecutionState; -import org.elasticsearch.cluster.metadata.Metadata; -import org.elasticsearch.index.Index; -import org.elasticsearch.index.IndexVersion; -import org.elasticsearch.test.ESTestCase; - -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionStateUtils.newClusterStateWithLifecycleState; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.sameInstance; - -public class LifecycleExecutionStateUtilsTests extends ESTestCase { - - public void testNewClusterStateWithLifecycleState() { - String indexName = "my-index"; - String indexUUID = randomAlphaOfLength(10); - Index index = new Index(indexName, indexUUID); - - Metadata metadata = Metadata.builder() - .put( - IndexMetadata.builder(indexName) - .settings(settings(IndexVersion.current()).put(IndexMetadata.SETTING_INDEX_UUID, indexUUID)) - .creationDate(randomNonNegativeLong()) - .numberOfShards(1) - .numberOfReplicas(0) - - ) - .build(); - - ClusterState clusterState1 = ClusterState.builder(ClusterName.DEFAULT).metadata(metadata).build(); - IndexMetadata indexMetadata1 = clusterState1.metadata().getProject().index(indexName); - assertThat(indexMetadata1.getLifecycleExecutionState(), sameInstance(LifecycleExecutionState.EMPTY_STATE)); - - LifecycleExecutionState state = LifecycleExecutionState.builder().setPhase("phase").setAction("action").setStep("step").build(); - - // setting the state via newClusterStateWithLifecycleState will set the state - ClusterState clusterState2 = newClusterStateWithLifecycleState(clusterState1, index, state); - IndexMetadata indexMetadata2 = clusterState2.metadata().getProject().index(indexName); - assertThat(indexMetadata2.getLifecycleExecutionState().asMap(), is(state.asMap())); - - // but if the lifecycle state doesn't actually change, then you get the same cluster state back - LifecycleExecutionState copy = LifecycleExecutionState.fromCustomMetadata(state.asMap()); - ClusterState clusterState3 = newClusterStateWithLifecycleState(clusterState2, index, copy); - assertThat(clusterState3, sameInstance(clusterState2)); - } - -}