diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/allocation/TransportClusterAllocationExplainAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/allocation/TransportClusterAllocationExplainAction.java index b67b9f91e63ee..1ee2954e0ec3f 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/allocation/TransportClusterAllocationExplainAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/allocation/TransportClusterAllocationExplainAction.java @@ -20,7 +20,6 @@ import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.cluster.routing.RoutingNodes; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.allocation.AllocationService; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; @@ -72,9 +71,8 @@ protected ClusterBlockException checkBlock(ClusterAllocationExplainRequest reque @Override protected void masterOperation(final ClusterAllocationExplainRequest request, final ClusterState state, final ActionListener listener) { - final RoutingNodes routingNodes = state.getRoutingNodes(); final ClusterInfo clusterInfo = clusterInfoService.getClusterInfo(); - final RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, routingNodes, state, + final RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state::getRoutingNodes, state, clusterInfo, snapshotsInfoService.snapshotShardSizes(), System.nanoTime()); ShardRouting shardRouting = findShardToExplain(request, allocation); diff --git a/server/src/main/java/org/elasticsearch/cluster/ClusterState.java b/server/src/main/java/org/elasticsearch/cluster/ClusterState.java index e549ecca185a4..7406cfe85f939 100644 --- a/server/src/main/java/org/elasticsearch/cluster/ClusterState.java +++ b/server/src/main/java/org/elasticsearch/cluster/ClusterState.java @@ -172,12 +172,12 @@ default boolean isPrivate() { public ClusterState(long version, String stateUUID, ClusterState state) { this(state.clusterName, version, stateUUID, state.metadata(), state.routingTable(), state.nodes(), state.blocks(), - state.customs(), -1, false); + state.customs(), -1, false, state.routingNodes); } - public ClusterState(ClusterName clusterName, long version, String stateUUID, Metadata metadata, RoutingTable routingTable, + private ClusterState(ClusterName clusterName, long version, String stateUUID, Metadata metadata, RoutingTable routingTable, DiscoveryNodes nodes, ClusterBlocks blocks, ImmutableOpenMap customs, - int minimumMasterNodesOnPublishingMaster, boolean wasReadFromDiff) { + int minimumMasterNodesOnPublishingMaster, boolean wasReadFromDiff, RoutingNodes routingNodes) { this.version = version; this.stateUUID = stateUUID; this.clusterName = clusterName; @@ -187,6 +187,7 @@ public ClusterState(ClusterName clusterName, long version, String stateUUID, Met this.blocks = blocks; this.customs = customs; this.minimumMasterNodesOnPublishingMaster = minimumMasterNodesOnPublishingMaster; + this.routingNodes = routingNodes; this.wasReadFromDiff = wasReadFromDiff; } @@ -302,15 +303,35 @@ public boolean wasReadFromDiff() { return wasReadFromDiff; } + public RoutingNodes mutableRoutingNodes() { + final RoutingNodes nodes = this.routingNodes; + if (nodes != null) { + return nodes.mutableCopy(); + } + return new RoutingNodes(routingTable, this.nodes, false); + } + /** * Returns a built (on demand) routing nodes view of the routing table. */ public RoutingNodes getRoutingNodes() { - if (routingNodes != null) { + final RoutingNodes nodes = this.routingNodes; + if (nodes != null) { + return nodes; + } + return buildRoutingNodes(); + } + + private RoutingNodes buildRoutingNodes() { + synchronized (this) { + RoutingNodes routingNodes = this.routingNodes; + if (routingNodes != null) { + return routingNodes; + } + routingNodes = new RoutingNodes(routingTable, this.nodes); + this.routingNodes = routingNodes; return routingNodes; } - routingNodes = new RoutingNodes(this); - return routingNodes; } @Override @@ -550,11 +571,14 @@ public static Builder builder(ClusterState state) { public static class Builder { + private ClusterState previous; + private final ClusterName clusterName; private long version = 0; private String uuid = UNKNOWN_UUID; private Metadata metadata = Metadata.EMPTY_METADATA; private RoutingTable routingTable = RoutingTable.EMPTY_ROUTING_TABLE; + private RoutingNodes routingNodes = null; private DiscoveryNodes nodes = DiscoveryNodes.EMPTY_NODES; private ClusterBlocks blocks = ClusterBlocks.EMPTY_CLUSTER_BLOCK; private final ImmutableOpenMap.Builder customs; @@ -562,6 +586,7 @@ public static class Builder { private int minimumMasterNodesOnPublishingMaster = -1; public Builder(ClusterState state) { + this.previous = state; this.clusterName = state.clusterName; this.version = state.version(); this.uuid = state.stateUUID(); @@ -592,6 +617,11 @@ public DiscoveryNodes nodes() { return nodes; } + public Builder routingNodes(RoutingNodes routingNodes) { + this.routingNodes = routingNodes; + return this; + } + public Builder routingTable(RoutingTable routingTable) { this.routingTable = routingTable; return this; @@ -661,8 +691,11 @@ public ClusterState build() { if (UNKNOWN_UUID.equals(uuid)) { uuid = UUIDs.randomBase64UUID(); } + if (previous != null && routingTable.indicesRouting() == previous.routingTable.indicesRouting() && nodes == previous.nodes) { + routingNodes = previous.routingNodes; + } return new ClusterState(clusterName, version, uuid, metadata, routingTable, nodes, blocks, customs.build(), - minimumMasterNodesOnPublishingMaster, fromDiff); + minimumMasterNodesOnPublishingMaster, fromDiff, routingNodes); } public static byte[] toBytes(ClusterState state) throws IOException { @@ -818,6 +851,9 @@ public ClusterState apply(ClusterState state) { builder.blocks(blocks.apply(state.blocks)); builder.customs(customs.apply(state.customs)); builder.minimumMasterNodesOnPublishingMaster(minimumMasterNodesOnPublishingMaster); + if (builder.routingTable == state.routingTable && builder.nodes == state.nodes) { + builder.routingNodes(state.routingNodes); + } builder.fromDiff(true); return builder.build(); } diff --git a/server/src/main/java/org/elasticsearch/cluster/health/ClusterIndexHealth.java b/server/src/main/java/org/elasticsearch/cluster/health/ClusterIndexHealth.java index a129879149af9..06d5007f48bbd 100644 --- a/server/src/main/java/org/elasticsearch/cluster/health/ClusterIndexHealth.java +++ b/server/src/main/java/org/elasticsearch/cluster/health/ClusterIndexHealth.java @@ -104,12 +104,7 @@ public ClusterIndexHealth(final IndexMetadata indexMetadata, final IndexRoutingT this.numberOfShards = indexMetadata.getNumberOfShards(); this.numberOfReplicas = indexMetadata.getNumberOfReplicas(); - shards = new HashMap<>(); - for (IndexShardRoutingTable shardRoutingTable : indexRoutingTable) { - int shardId = shardRoutingTable.shardId().id(); - shards.put(shardId, new ClusterShardHealth(shardId, shardRoutingTable)); - } - + shards = new HashMap<>(this.numberOfShards); // update the index status ClusterHealthStatus computeStatus = ClusterHealthStatus.GREEN; int computeActivePrimaryShards = 0; @@ -117,7 +112,10 @@ public ClusterIndexHealth(final IndexMetadata indexMetadata, final IndexRoutingT int computeRelocatingShards = 0; int computeInitializingShards = 0; int computeUnassignedShards = 0; - for (ClusterShardHealth shardHealth : shards.values()) { + for (IndexShardRoutingTable shardRoutingTable : indexRoutingTable) { + int shardId = shardRoutingTable.shardId().id(); + final ClusterShardHealth shardHealth = new ClusterShardHealth(shardId, shardRoutingTable); + shards.put(shardId, shardHealth); if (shardHealth.isPrimaryActive()) { computeActivePrimaryShards++; } @@ -133,6 +131,7 @@ public ClusterIndexHealth(final IndexMetadata indexMetadata, final IndexRoutingT computeStatus = ClusterHealthStatus.YELLOW; } } + if (shards.isEmpty()) { // might be since none has been created yet (two phase index creation) computeStatus = ClusterHealthStatus.RED; } diff --git a/server/src/main/java/org/elasticsearch/cluster/health/ClusterStateHealth.java b/server/src/main/java/org/elasticsearch/cluster/health/ClusterStateHealth.java index 1d8fa46f30769..528ea3e9122ba 100644 --- a/server/src/main/java/org/elasticsearch/cluster/health/ClusterStateHealth.java +++ b/server/src/main/java/org/elasticsearch/cluster/health/ClusterStateHealth.java @@ -56,6 +56,12 @@ public ClusterStateHealth(final ClusterState clusterState, final String[] concre numberOfNodes = clusterState.nodes().getSize(); numberOfDataNodes = clusterState.nodes().getDataNodes().size(); indices = new HashMap<>(); + ClusterHealthStatus computeStatus = ClusterHealthStatus.GREEN; + int computeActivePrimaryShards = 0; + int computeActiveShards = 0; + int computeRelocatingShards = 0; + int computeInitializingShards = 0; + int computeUnassignedShards = 0; for (String index : concreteIndices) { IndexRoutingTable indexRoutingTable = clusterState.routingTable().index(index); IndexMetadata indexMetadata = clusterState.metadata().index(index); @@ -66,16 +72,6 @@ public ClusterStateHealth(final ClusterState clusterState, final String[] concre ClusterIndexHealth indexHealth = new ClusterIndexHealth(indexMetadata, indexRoutingTable); indices.put(indexHealth.getIndex(), indexHealth); - } - - ClusterHealthStatus computeStatus = ClusterHealthStatus.GREEN; - int computeActivePrimaryShards = 0; - int computeActiveShards = 0; - int computeRelocatingShards = 0; - int computeInitializingShards = 0; - int computeUnassignedShards = 0; - - for (ClusterIndexHealth indexHealth : indices.values()) { computeActivePrimaryShards += indexHealth.getActivePrimaryShards(); computeActiveShards += indexHealth.getActiveShards(); computeRelocatingShards += indexHealth.getRelocatingShards(); diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/AutoExpandReplicas.java b/server/src/main/java/org/elasticsearch/cluster/metadata/AutoExpandReplicas.java index 0d96d4061b9a5..9397be74c8c52 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/AutoExpandReplicas.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/AutoExpandReplicas.java @@ -142,7 +142,7 @@ public static Map> getAutoExpandReplicaChanges(Metadata me for (final IndexMetadata indexMetadata : metadata) { if (indexMetadata.getState() == IndexMetadata.State.OPEN || isIndexVerifiedBeforeClosed(indexMetadata)) { - AutoExpandReplicas autoExpandReplicas = SETTING.get(indexMetadata.getSettings()); + AutoExpandReplicas autoExpandReplicas = indexMetadata.getAutoExpandReplicas(); autoExpandReplicas.getDesiredNumberOfReplicas(indexMetadata, allocation).ifPresent(numberOfReplicas -> { if (numberOfReplicas != indexMetadata.getNumberOfReplicas()) { nrReplicasChanged.computeIfAbsent(numberOfReplicas, ArrayList::new).add(indexMetadata.getIndex().getName()); diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/ComposableIndexTemplateMetadata.java b/server/src/main/java/org/elasticsearch/cluster/metadata/ComposableIndexTemplateMetadata.java index 1fe3f3ab8d8c2..9ff08d33ea4f3 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/ComposableIndexTemplateMetadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/ComposableIndexTemplateMetadata.java @@ -32,6 +32,9 @@ */ public class ComposableIndexTemplateMetadata implements Metadata.Custom { public static final String TYPE = "index_template"; + + public static final ComposableIndexTemplateMetadata EMPTY = new ComposableIndexTemplateMetadata(org.elasticsearch.core.Map.of()); + private static final ParseField INDEX_TEMPLATE = new ParseField("index_template"); @SuppressWarnings("unchecked") private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>(TYPE, diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexAbstraction.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexAbstraction.java index 37048035fe476..7bb08ba877e95 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexAbstraction.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexAbstraction.java @@ -182,6 +182,23 @@ public boolean isSystem() { public List getAliases() { return aliases; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ConcreteIndex that = (ConcreteIndex) o; + return isHidden == that.isHidden && + isSystem == that.isSystem && + concreteIndexName.equals(that.concreteIndexName) && + Objects.equals(aliases, that.aliases) && + Objects.equals(dataStream, that.dataStream); + } + + @Override + public int hashCode() { + return Objects.hash(concreteIndexName, isHidden, isSystem, aliases, dataStream); + } } /** @@ -302,6 +319,24 @@ private void validateAliasProperties(List referenceIndexMetadatas private boolean isNonEmpty(List idxMetas) { return (Objects.isNull(idxMetas) || idxMetas.isEmpty()) == false; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Alias alias = (Alias) o; + return isHidden == alias.isHidden && + isSystem == alias.isSystem && + dataStreamAlias == alias.dataStreamAlias && + aliasName.equals(alias.aliasName) && + referenceIndexMetadatas.equals(alias.referenceIndexMetadatas) && + Objects.equals(writeIndex, alias.writeIndex); + } + + @Override + public int hashCode() { + return Objects.hash(aliasName, referenceIndexMetadatas, writeIndex, isHidden, isSystem, dataStreamAlias); + } } class DataStream implements IndexAbstraction { @@ -363,6 +398,20 @@ public List getAliases() { public org.elasticsearch.cluster.metadata.DataStream getDataStream() { return dataStream; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + DataStream that = (DataStream) o; + return dataStream.equals(that.dataStream) && + Objects.equals(referencedByDataStreamAliases, that.referencedByDataStreamAliases); + } + + @Override + public int hashCode() { + return Objects.hash(dataStream, referencedByDataStreamAliases); + } } } diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java index 173622e7bc944..1829fcfba3d9c 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java @@ -27,6 +27,7 @@ import org.elasticsearch.cluster.routing.allocation.DataTier; import org.elasticsearch.cluster.routing.allocation.IndexMetadataUpdater; import org.elasticsearch.cluster.routing.allocation.decider.DiskThresholdDecider; +import org.elasticsearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider; import org.elasticsearch.common.collect.ImmutableOpenIntMap; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.collect.MapBuilder; @@ -42,11 +43,13 @@ import org.elasticsearch.core.Nullable; import org.elasticsearch.gateway.MetadataStateFormat; import org.elasticsearch.index.Index; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.seqno.SequenceNumbers; import org.elasticsearch.index.shard.IndexLongFieldRange; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.rest.RestStatus; +import org.elasticsearch.snapshots.SearchableSnapshotsSettings; import org.elasticsearch.xcontent.ToXContent; import org.elasticsearch.xcontent.ToXContentFragment; import org.elasticsearch.xcontent.XContentBuilder; @@ -93,6 +96,18 @@ public class IndexMetadata implements Diffable, ToXContentFragmen public static final ClusterBlock INDEX_READ_ONLY_ALLOW_DELETE_BLOCK = new ClusterBlock(12, "disk usage exceeded flood-stage watermark, index has read-only-allow-delete block", false, false, true, RestStatus.TOO_MANY_REQUESTS, EnumSet.of(ClusterBlockLevel.METADATA_WRITE, ClusterBlockLevel.WRITE)); + public static final String INDEX_ROUTING_REQUIRE = "index.routing.allocation.require._tier"; + public static final Setting INDEX_ROUTING_REQUIRE_SETTING = Setting.simpleString(INDEX_ROUTING_REQUIRE, + DataTier.DATA_TIER_SETTING_VALIDATOR, Property.Dynamic, Property.IndexScope, Property.Deprecated); + public static final String INDEX_ROUTING_INCLUDE = "index.routing.allocation.include._tier"; + public static final Setting INDEX_ROUTING_INCLUDE_SETTING = Setting.simpleString(INDEX_ROUTING_INCLUDE, + DataTier.DATA_TIER_SETTING_VALIDATOR, Property.Dynamic, Property.IndexScope, Property.Deprecated); + public static final String INDEX_ROUTING_EXCLUDE = "index.routing.allocation.exclude._tier"; + public static final Setting INDEX_ROUTING_EXCLUDE_SETTING = Setting.simpleString(INDEX_ROUTING_EXCLUDE, + DataTier.DATA_TIER_SETTING_VALIDATOR, Property.Dynamic, Property.IndexScope, Property.Deprecated); + public static final String LIFECYCLE_NAME = "index.lifecycle.name"; + public static final Setting LIFECYCLE_NAME_SETTING = Setting.simpleString(LIFECYCLE_NAME, + Property.Dynamic, Property.IndexScope); public enum State { OPEN((byte) 0), @@ -404,6 +419,22 @@ public static APIBlock readFrom(StreamInput input) throws IOException { @Nullable // since we store null if DataTier.TIER_PREFERENCE_SETTING failed validation private final List tierPreference; + private final AutoExpandReplicas autoExpandReplicas; + + private final String indexRoutingRequire; + private final String indexRoutingInclude; + private final String indexRoutingExclude; + + private final boolean isSearchableSnapshotStore; + private final boolean isPartialSearchableSnapshotStore; + + private final String indexLifecycleName; + + @Nullable + private final Integer shardsPerNodeLimit; + + private final LifecycleExecutionState lifecycleExecutionState; + private IndexMetadata( final Index index, final long version, @@ -434,7 +465,16 @@ private IndexMetadata( final int priority, final long creationDate, final boolean ignoreDiskWatermarks, - @Nullable final List tierPreference + @Nullable final List tierPreference, + final AutoExpandReplicas autoExpandReplicas, + final String indexRoutingRequire, + final String indexRoutingInclude, + final String indexRoutingExclude, + final boolean isSearchableSnapshotStore, + final boolean isPartialSearchableSnapshotStore, + final String indexLifecycleName, + @Nullable final Integer shardsPerNodeLimit, + LifecycleExecutionState lifecycleExecutionState ) { this.index = index; @@ -474,6 +514,15 @@ private IndexMetadata( this.creationDate = creationDate; this.ignoreDiskWatermarks = ignoreDiskWatermarks; this.tierPreference = tierPreference; + this.autoExpandReplicas = autoExpandReplicas; + this.indexRoutingRequire = indexRoutingRequire; + this.indexRoutingInclude = indexRoutingInclude; + this.indexRoutingExclude = indexRoutingExclude; + this.isSearchableSnapshotStore = isSearchableSnapshotStore; + this.isPartialSearchableSnapshotStore = isPartialSearchableSnapshotStore; + this.indexLifecycleName = indexLifecycleName; + this.shardsPerNodeLimit = shardsPerNodeLimit; + this.lifecycleExecutionState = lifecycleExecutionState; assert numberOfShards * routingFactor == routingNumShards : routingNumShards + " must be a multiple of " + numberOfShards; } @@ -580,6 +629,43 @@ public ImmutableOpenMap getAliases() { return this.aliases; } + public AutoExpandReplicas getAutoExpandReplicas() { + return autoExpandReplicas; + } + + public String getIndexRoutingRequire() { + return indexRoutingRequire; + } + + public String getIndexRoutingInclude() { + return indexRoutingInclude; + } + + public String getIndexRoutingExclude() { + return indexRoutingExclude; + } + + public boolean isSearchableSnapshotStore() { + return isSearchableSnapshotStore; + } + + public boolean isPartialSearchableSnapshotStore() { + return isPartialSearchableSnapshotStore; + } + + public String getLifecycleName() { + return indexLifecycleName; + } + + @Nullable + public Integer getShardsPerNodeLimit() { + return shardsPerNodeLimit; + } + + public LifecycleExecutionState getLifecycleExecutionState() { + return lifecycleExecutionState; + } + public List getTierPreference() { if (tierPreference == null) { final List parsed = DataTier.parseTierList(DataTier.TIER_PREFERENCE_SETTING.get(settings)); @@ -912,7 +998,7 @@ public void writeTo(StreamOutput out) throws IOException { @Override public IndexMetadata apply(IndexMetadata part) { - Builder builder = builder(index); + Builder builder = builder(part.index); builder.version(version); builder.mappingVersion(mappingVersion); builder.settingsVersion(settingsVersion); @@ -1056,12 +1142,20 @@ public static Builder builder(String index) { return new Builder(index); } + public static Builder builder(Index index) { + final Builder b = new Builder(index.getName()); + b.original = index; + return b; + } + public static Builder builder(IndexMetadata indexMetadata) { return new Builder(indexMetadata); } public static class Builder { + @Nullable + private Index original; private String index; private State state = State.OPEN; private long version = 1; @@ -1090,7 +1184,8 @@ public Builder(String index) { } public Builder(IndexMetadata indexMetadata) { - this.index = indexMetadata.getIndex().getName(); + this.original = indexMetadata.index; + this.index = original.getName(); this.state = indexMetadata.state; this.version = indexMetadata.version; this.mappingVersion = indexMetadata.mappingVersion; @@ -1418,8 +1513,21 @@ public IndexMetadata build() { tierPreference = null; } + final LifecycleExecutionState lifecycleExecutionState; + Map customData = customMetadata.get(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY); + if (customData != null && customData.isEmpty() == false) { + lifecycleExecutionState = LifecycleExecutionState.fromCustomMetadata(customData); + } else { + lifecycleExecutionState = LifecycleExecutionState.EMPTY_STATE; + } + + Index newIndex = new Index(index, uuid); + if (newIndex.equals(original)) { + newIndex = original; + } + return new IndexMetadata( - new Index(index, uuid), + newIndex, version, mappingVersion, settingsVersion, @@ -1448,7 +1556,17 @@ public IndexMetadata build() { IndexMetadata.INDEX_PRIORITY_SETTING.get(settings), settings.getAsLong(SETTING_CREATION_DATE, -1L), DiskThresholdDecider.SETTING_IGNORE_DISK_WATERMARKS.get(settings), - tierPreference + tierPreference, + INDEX_AUTO_EXPAND_REPLICAS_SETTING.get(settings), + INDEX_ROUTING_REQUIRE_SETTING.get(settings), + INDEX_ROUTING_INCLUDE_SETTING.get(settings), + INDEX_ROUTING_EXCLUDE_SETTING.get(settings), + SearchableSnapshotsSettings.isSearchableSnapshotStore(settings), + SearchableSnapshotsSettings.isPartialSearchableSnapshotIndex(settings), + LIFECYCLE_NAME_SETTING.get(settings), + ShardsLimitAllocationDecider.INDEX_TOTAL_SHARDS_PER_NODE_SETTING.exists(settings) + ? ShardsLimitAllocationDecider.INDEX_TOTAL_SHARDS_PER_NODE_SETTING.get(settings) : null, + lifecycleExecutionState ); } diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadataVerifier.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadataVerifier.java index 3f60d2ae8e29e..0ce8dde8b9301 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadataVerifier.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadataVerifier.java @@ -33,8 +33,6 @@ import java.util.Map; import java.util.Set; -import static org.elasticsearch.snapshots.SearchableSnapshotsSettings.isPartialSearchableSnapshotIndex; - /** * This service is responsible for verifying index metadata when an index is introduced * to the cluster, for example when restarting nodes, importing dangling indices, or restoring @@ -196,7 +194,7 @@ IndexMetadata archiveBrokenIndexSettings(IndexMetadata indexMetadata) { IndexMetadata convertSharedCacheTierPreference(IndexMetadata indexMetadata) { final Settings settings = indexMetadata.getSettings(); // Only remove these settings for a shared_cache searchable snapshot - if (isPartialSearchableSnapshotIndex(settings)) { + if (indexMetadata.isPartialSearchableSnapshotStore()) { final Settings.Builder settingsBuilder = Settings.builder().put(settings); // Clear any allocation rules other than preference for tier settingsBuilder.remove("index.routing.allocation.include._tier"); diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/Metadata.java b/server/src/main/java/org/elasticsearch/cluster/metadata/Metadata.java index a6a2da365e0be..95158749c1a85 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/Metadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/Metadata.java @@ -231,6 +231,46 @@ public interface NonRestorableCustom extends Custom { this.indicesLookup = indicesLookup; } + private Metadata(String clusterUUID, boolean clusterUUIDCommitted, long version, CoordinationMetadata coordinationMetadata, + Settings transientSettings, Settings persistentSettings, + Settings settings, + DiffableStringMap hashesOfConsistentSettings, + int totalNumberOfShards, + int totalOpenIndexShards, + ImmutableOpenMap indices, ImmutableOpenMap templates, + ImmutableOpenMap customs, String[] allIndices, String[] visibleIndices, String[] allOpenIndices, + String[] visibleOpenIndices, String[] allClosedIndices, String[] visibleClosedIndices, + SortedMap indicesLookup) { + this.clusterUUID = clusterUUID; + this.clusterUUIDCommitted = clusterUUIDCommitted; + this.version = version; + this.coordinationMetadata = coordinationMetadata; + this.transientSettings = transientSettings; + this.persistentSettings = persistentSettings; + this.settings = settings; + this.hashesOfConsistentSettings = hashesOfConsistentSettings; + this.indices = indices; + this.customs = customs; + this.templates = templates; + this.totalNumberOfShards = totalNumberOfShards; + this.totalOpenIndexShards = totalOpenIndexShards; + this.allIndices = allIndices; + this.visibleIndices = visibleIndices; + this.allOpenIndices = allOpenIndices; + this.visibleOpenIndices = visibleOpenIndices; + this.allClosedIndices = allClosedIndices; + this.visibleClosedIndices = visibleClosedIndices; + this.indicesLookup = indicesLookup; + } + + public Metadata withIncrementedVersion() { + return new Metadata(clusterUUID, clusterUUIDCommitted, version + 1, coordinationMetadata, transientSettings, + persistentSettings, + settings, hashesOfConsistentSettings, totalNumberOfShards, totalOpenIndexShards, indices, templates, + customs, allIndices, visibleIndices, allOpenIndices, visibleOpenIndices, allClosedIndices, visibleClosedIndices, + indicesLookup); + } + public long version() { return this.version; } @@ -898,6 +938,9 @@ public Iterator iterator() { } public static boolean isGlobalStateEquals(Metadata metadata1, Metadata metadata2) { + if (metadata1 == metadata2) { + return true; + } if (metadata1.coordinationMetadata.equals(metadata2.coordinationMetadata) == false) { return false; } @@ -979,6 +1022,8 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws private static class MetadataDiff implements Diff { + private static final Version RECORD_EMPTY_VERSION = Version.V_7_16_0; + private final long version; private final String clusterUUID; private boolean clusterUUIDCommitted; @@ -989,8 +1034,10 @@ private static class MetadataDiff implements Diff { private final Diff> indices; private final Diff> templates; private final Diff> customs; + private final boolean isEmpty; MetadataDiff(Metadata before, Metadata after) { + isEmpty = before == after; clusterUUID = after.clusterUUID; clusterUUIDCommitted = after.clusterUUIDCommitted; version = after.version; @@ -1009,6 +1056,7 @@ private static class MetadataDiff implements Diff { new DiffableUtils.DiffableValueReader<>(IndexTemplateMetadata::readFrom, IndexTemplateMetadata::readDiffFrom); MetadataDiff(StreamInput in) throws IOException { + isEmpty = in.getVersion().onOrAfter(RECORD_EMPTY_VERSION) && in.readBoolean(); clusterUUID = in.readString(); if (in.getVersion().onOrAfter(Version.V_7_0_0)) { clusterUUIDCommitted = in.readBoolean(); @@ -1033,6 +1081,9 @@ private static class MetadataDiff implements Diff { @Override public void writeTo(StreamOutput out) throws IOException { + if (out.getVersion().onOrAfter(RECORD_EMPTY_VERSION)) { + out.writeBoolean(isEmpty); + } out.writeString(clusterUUID); if (out.getVersion().onOrAfter(Version.V_7_0_0)) { out.writeBoolean(clusterUUIDCommitted); @@ -1053,6 +1104,9 @@ public void writeTo(StreamOutput out) throws IOException { @Override public Metadata apply(Metadata part) { + if (isEmpty) { + return part; + } Builder builder = builder(); builder.clusterUUID(clusterUUID); builder.clusterUUIDCommitted(clusterUUIDCommitted); @@ -1160,15 +1214,18 @@ public static class Builder { private final ImmutableOpenMap.Builder templates; private final ImmutableOpenMap.Builder customs; + private SortedMap previousIndicesLookup; + public Builder() { clusterUUID = UNKNOWN_CLUSTER_UUID; indices = ImmutableOpenMap.builder(); templates = ImmutableOpenMap.builder(); customs = ImmutableOpenMap.builder(); indexGraveyard(IndexGraveyard.builder().build()); // create new empty index graveyard to initialize + previousIndicesLookup = null; } - public Builder(Metadata metadata) { + Builder(Metadata metadata) { this.clusterUUID = metadata.clusterUUID; this.clusterUUIDCommitted = metadata.clusterUUIDCommitted; this.coordinationMetadata = metadata.coordinationMetadata; @@ -1179,13 +1236,17 @@ public Builder(Metadata metadata) { this.indices = ImmutableOpenMap.builder(metadata.indices); this.templates = ImmutableOpenMap.builder(metadata.templates); this.customs = ImmutableOpenMap.builder(metadata.customs); + previousIndicesLookup = metadata.getIndicesLookup(); } public Builder put(IndexMetadata.Builder indexMetadataBuilder) { // we know its a new one, increment the version and store indexMetadataBuilder.version(indexMetadataBuilder.version() + 1); IndexMetadata indexMetadata = indexMetadataBuilder.build(); - indices.put(indexMetadata.getIndex().getName(), indexMetadata); + IndexMetadata previous = indices.put(indexMetadata.getIndex().getName(), indexMetadata); + if (unsetPreviousIndicesLookup(previous, indexMetadata)) { + previousIndicesLookup = null; + } return this; } @@ -1197,10 +1258,37 @@ public Builder put(IndexMetadata indexMetadata, boolean incrementVersion) { if (incrementVersion) { indexMetadata = IndexMetadata.builder(indexMetadata).version(indexMetadata.getVersion() + 1).build(); } - indices.put(indexMetadata.getIndex().getName(), indexMetadata); + IndexMetadata previous = indices.put(indexMetadata.getIndex().getName(), indexMetadata); + if (unsetPreviousIndicesLookup(previous, indexMetadata)) { + previousIndicesLookup = null; + } return this; } + boolean unsetPreviousIndicesLookup(IndexMetadata previous, IndexMetadata current) { + if (previous == null) { + return true; + } + + if (previous.getAliases().equals(current.getAliases()) == false) { + return true; + } + + if (previous.isHidden() != current.isHidden()) { + return true; + } + + if (previous.isSystem() != current.isSystem()) { + return true; + } + + if (previous.getState() != current.getState()) { + return true; + } + + return false; + } + public IndexMetadata get(String index) { return indices.get(index); } @@ -1219,16 +1307,22 @@ public IndexMetadata getSafe(Index index) { } public Builder remove(String index) { + previousIndicesLookup = null; + indices.remove(index); return this; } public Builder removeAllIndices() { + previousIndicesLookup = null; + indices.clear(); return this; } public Builder indices(ImmutableOpenMap indices) { + previousIndicesLookup = null; + this.indices.putAll(indices); return this; } @@ -1309,6 +1403,8 @@ public Builder removeIndexTemplate(String name) { } public DataStream dataStream(String dataStreamName) { + previousIndicesLookup = null; + DataStreamMetadata dataStreamMetadata = (DataStreamMetadata) customs.get(DataStreamMetadata.TYPE); if (dataStreamMetadata != null) { return dataStreamMetadata.dataStreams().get(dataStreamName); @@ -1318,11 +1414,15 @@ public DataStream dataStream(String dataStreamName) { } public Builder dataStreams(Map dataStreams, Map dataStreamAliases) { + previousIndicesLookup = null; + this.customs.put(DataStreamMetadata.TYPE, new DataStreamMetadata(dataStreams, dataStreamAliases)); return this; } public Builder put(DataStream dataStream) { + previousIndicesLookup = null; + Objects.requireNonNull(dataStream, "it is invalid to add a null data stream"); Map existingDataStreams = Optional.ofNullable((DataStreamMetadata) this.customs.get(DataStreamMetadata.TYPE)) @@ -1339,6 +1439,8 @@ public Builder put(DataStream dataStream) { } public boolean put(String aliasName, String dataStream, Boolean isWriteDataStream, String filter) { + previousIndicesLookup = null; + Map existingDataStream = Optional.ofNullable((DataStreamMetadata) this.customs.get(DataStreamMetadata.TYPE)) .map(dsmd -> new HashMap<>(dsmd.dataStreams())) @@ -1377,6 +1479,8 @@ public boolean put(String aliasName, String dataStream, Boolean isWriteDataStrea } public Builder removeDataStream(String name) { + previousIndicesLookup = null; + Map existingDataStreams = Optional.ofNullable((DataStreamMetadata) this.customs.get(DataStreamMetadata.TYPE)) .map(dsmd -> new HashMap<>(dsmd.dataStreams())) @@ -1413,6 +1517,8 @@ public Builder removeDataStream(String name) { } public boolean removeDataStreamAlias(String aliasName, String dataStreamName, boolean mustExist) { + previousIndicesLookup = null; + Map dataStreamAliases = Optional.ofNullable((DataStreamMetadata) this.customs.get(DataStreamMetadata.TYPE)) .map(dsmd -> new HashMap<>(dsmd.getDataStreamAliases())) @@ -1665,10 +1771,15 @@ public Metadata build(boolean builtIndicesLookupEagerly) { ImmutableOpenMap indices = this.indices.build(); SortedMap indicesLookup; - if (builtIndicesLookupEagerly) { - indicesLookup = Collections.unmodifiableSortedMap(buildIndicesLookup(dataStreamMetadata, indices)); + if (previousIndicesLookup != null) { + assert previousIndicesLookup.equals(buildIndicesLookup(dataStreamMetadata, indices)); + indicesLookup = previousIndicesLookup; } else { - indicesLookup = null; + if (builtIndicesLookupEagerly) { + indicesLookup = Collections.unmodifiableSortedMap(buildIndicesLookup(dataStreamMetadata, indices)); + } else { + indicesLookup = null; + } } diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java index 53e8bd84eaff0..d9e86f72e7283 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java @@ -108,7 +108,6 @@ import static org.elasticsearch.cluster.metadata.MetadataIndexTemplateService.resolveSettings; import static org.elasticsearch.index.IndexModule.INDEX_RECOVERY_TYPE_SETTING; import static org.elasticsearch.index.IndexModule.INDEX_STORE_TYPE_SETTING; -import static org.elasticsearch.snapshots.SearchableSnapshotsSettings.isSearchableSnapshotStore; /** * Service responsible for submitting create index requests @@ -1201,7 +1200,7 @@ private static List validateIndexCustomPath(Settings settings, @Nullable */ static List validateShrinkIndex(ClusterState state, String sourceIndex, String targetIndexName, Settings targetIndexSettings) { IndexMetadata sourceMetadata = validateResize(state, sourceIndex, targetIndexName, targetIndexSettings); - if (isSearchableSnapshotStore(sourceMetadata.getSettings())) { + if (sourceMetadata.isSearchableSnapshotStore()) { throw new IllegalArgumentException("can't shrink searchable snapshot index [" + sourceIndex + ']'); } assert INDEX_NUMBER_OF_SHARDS_SETTING.exists(targetIndexSettings); @@ -1235,7 +1234,7 @@ static List validateShrinkIndex(ClusterState state, String sourceIndex, static void validateSplitIndex(ClusterState state, String sourceIndex, String targetIndexName, Settings targetIndexSettings) { IndexMetadata sourceMetadata = validateResize(state, sourceIndex, targetIndexName, targetIndexSettings); - if (isSearchableSnapshotStore(sourceMetadata.getSettings())) { + if (sourceMetadata.isSearchableSnapshotStore()) { throw new IllegalArgumentException("can't split searchable snapshot index [" + sourceIndex + ']'); } IndexMetadata.selectSplitShard(0, sourceMetadata, IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING.get(targetIndexSettings)); @@ -1249,7 +1248,7 @@ static void validateSplitIndex(ClusterState state, String sourceIndex, String ta static void validateCloneIndex(ClusterState state, String sourceIndex, String targetIndexName, Settings targetIndexSettings) { IndexMetadata sourceMetadata = validateResize(state, sourceIndex, targetIndexName, targetIndexSettings); - if (isSearchableSnapshotStore(sourceMetadata.getSettings())) { + if (sourceMetadata.isSearchableSnapshotStore()) { for (Setting nonCloneableSetting : Arrays.asList(INDEX_STORE_TYPE_SETTING, INDEX_RECOVERY_TYPE_SETTING)) { if (nonCloneableSetting.exists(targetIndexSettings) == false) { throw new IllegalArgumentException("can't clone searchable snapshot index [" + sourceIndex + "]; setting [" diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexStateService.java b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexStateService.java index bcdb54ef8e21f..a55a78d13e716 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexStateService.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexStateService.java @@ -256,7 +256,6 @@ static ClusterState addIndexClosedBlocks(final Index[] indices, final Map new ParameterizedMessage("closing indices {}", blockedIndices.keySet().stream().map(Object::toString).collect(Collectors.joining(",")))); - return ClusterState.builder(currentState).blocks(blocks).metadata(metadata).routingTable(routingTable.build()).build(); + return ClusterState.builder(currentState).blocks(blocks).metadata(metadata).build(); } /** @@ -311,7 +310,6 @@ static Tuple> addIndexBlock(final Index[] } final ClusterBlocks.Builder blocks = ClusterBlocks.builder().blocks(currentState.blocks()); - final RoutingTable.Builder routingTable = RoutingTable.builder(currentState.routingTable()); final Map blockedIndices = new HashMap<>(); for (Index index : indicesToAddBlock) { @@ -347,8 +345,7 @@ static Tuple> addIndexBlock(final Index[] logger.info("adding block {} to indices {}", block.name, blockedIndices.keySet().stream().map(Object::toString).collect(Collectors.toList())); - return Tuple.tuple(ClusterState.builder(currentState).blocks(blocks).metadata(metadata) - .routingTable(routingTable.build()).build(), blockedIndices); + return Tuple.tuple(ClusterState.builder(currentState).blocks(blocks).metadata(metadata).build(), blockedIndices); } /** @@ -936,9 +933,7 @@ public static ClusterBlock createIndexClosingBlock() { } public static boolean isIndexVerifiedBeforeClosed(final IndexMetadata indexMetadata) { - return indexMetadata.getState() == IndexMetadata.State.CLOSE - && VERIFIED_BEFORE_CLOSE_SETTING.exists(indexMetadata.getSettings()) - && VERIFIED_BEFORE_CLOSE_SETTING.get(indexMetadata.getSettings()); + return indexMetadata.getState() == IndexMetadata.State.CLOSE && VERIFIED_BEFORE_CLOSE_SETTING.get(indexMetadata.getSettings()); } // Create UUID based block based on non-UUID one diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataUpdateSettingsService.java b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataUpdateSettingsService.java index 81b68fcd0ee30..364f325159f8c 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataUpdateSettingsService.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataUpdateSettingsService.java @@ -107,7 +107,7 @@ public void updateSettings(final UpdateSettingsClusterStateUpdateRequest request @Override public ClusterState execute(ClusterState currentState) { - RoutingTable.Builder routingTableBuilder = RoutingTable.builder(currentState.routingTable()); + RoutingTable.Builder routingTableBuilder = null; Metadata.Builder metadataBuilder = Metadata.builder(currentState.metadata()); // allow to change any settings to a close index, and only allow dynamic settings to be changed @@ -143,6 +143,7 @@ public ClusterState execute(ClusterState currentState) { * * TODO: should we update the in-sync allocation IDs once the data is deleted by the node? */ + routingTableBuilder = RoutingTable.builder(currentState.routingTable()); routingTableBuilder.updateNumberOfReplicas(updatedNumberOfReplicas, actualIndices); metadataBuilder.updateNumberOfReplicas(updatedNumberOfReplicas, actualIndices); logger.info("updating number_of_replicas to [{}] for indices {}", updatedNumberOfReplicas, actualIndices); @@ -238,7 +239,8 @@ public ClusterState execute(ClusterState currentState) { } ClusterState updatedState = ClusterState.builder(currentState).metadata(metadataBuilder) - .routingTable(routingTableBuilder.build()).blocks(blocks).build(); + .routingTable(routingTableBuilder == null ? currentState.routingTable() : routingTableBuilder.build()) + .blocks(blocks).build(); // now, reroute in case things change that require it (like number of replicas) updatedState = allocationService.reroute(updatedState, "settings update"); diff --git a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java index 4be5c8e56ca82..6ae385222224a 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java @@ -458,6 +458,22 @@ public Set getRoles() { return roles; } + Set roleNames; + + public Set roleNames() { + Set names = roleNames; + if (names != null) { + return names; + } + names = new HashSet<>(roles.size()); + for (DiscoveryNodeRole role : roles) { + names.add(role.roleName()); + } + names = org.elasticsearch.core.Set.copyOf(names); + roleNames = names; + return names; + } + public Version getVersion() { return this.version; } diff --git a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeFilters.java b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeFilters.java index 3fed998fd82ac..3b07545892fc3 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeFilters.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodeFilters.java @@ -13,14 +13,12 @@ import org.elasticsearch.common.network.NetworkAddress; import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.core.Nullable; import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.function.BiConsumer; -import java.util.stream.Collectors; public class DiscoveryNodeFilters { @@ -67,17 +65,20 @@ public static DiscoveryNodeFilters buildFromKeyValue(OpType opType, Map filters) { this.opType = opType; this.filters = filters; + this.trimmed = doTrim(this); } private boolean matchByIP(String[] values, @Nullable String hostIp, @Nullable String publishIp) { for (String ipOrHost : values) { String value = InetAddresses.isInetAddress(ipOrHost) ? NetworkAddress.format(InetAddresses.forString(ipOrHost)) : ipOrHost; - boolean matchIp = Regex.simpleMatch(value, hostIp) || Regex.simpleMatch(value, publishIp); - if (matchIp) { - return matchIp; + if (Regex.simpleMatch(value, hostIp) || Regex.simpleMatch(value, publishIp)) { + return true; } } return false; @@ -90,17 +91,25 @@ private boolean matchByIP(String[] values, @Nullable String hostIp, @Nullable St */ @Nullable public static DiscoveryNodeFilters trimTier(@Nullable DiscoveryNodeFilters original) { - if (original == null) { - return null; - } + return original == null ? null : original.trimmed; - Map newFilters = original.filters.entrySet().stream() - // Remove all entries that start with "_tier", as these will be handled elsewhere - .filter(entry -> { - String attr = entry.getKey(); - return attr != null && attr.startsWith("_tier") == false; - }) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + } + + private static DiscoveryNodeFilters doTrim(DiscoveryNodeFilters original) { + boolean filtered = false; + final Map newFilters = new HashMap<>(original.filters.size()); + // Remove all entries that start with "_tier", as these will be handled elsewhere + for (Map.Entry entry : original.filters.entrySet()) { + String attr = entry.getKey(); + if (attr != null && attr.startsWith("_tier") == false) { + newFilters.put(entry.getKey(), entry.getValue()); + } else { + filtered = true; + } + } + if (filtered == false) { + return original; + } if (newFilters.size() == 0) { return null; @@ -113,122 +122,130 @@ public boolean match(DiscoveryNode node) { for (Map.Entry entry : filters.entrySet()) { String attr = entry.getKey(); String[] values = entry.getValue(); - if ("_ip".equals(attr)) { - // We check both the host_ip or the publish_ip - String publishAddress = null; - if (node.getAddress() instanceof TransportAddress) { - publishAddress = NetworkAddress.format(node.getAddress().address().getAddress()); - } + switch (attr) { + case "_ip": { + // We check both the host_ip or the publish_ip + String publishAddress = null; + if (node.getAddress() != null) { + publishAddress = NetworkAddress.format(node.getAddress().address().getAddress()); + } - boolean match = matchByIP(values, node.getHostAddress(), publishAddress); + boolean match = matchByIP(values, node.getHostAddress(), publishAddress); - if (opType == OpType.AND) { - if (match) { - // If we match, we can check to the next filter - continue; + if (opType == OpType.AND) { + if (match) { + // If we match, we can check to the next filter + continue; + } + return false; } - return false; - } - if (match && opType == OpType.OR) { - return true; - } - } else if ("_host_ip".equals(attr)) { - // We check explicitly only the host_ip - boolean match = matchByIP(values, node.getHostAddress(), null); - if (opType == OpType.AND) { - if (match) { - // If we match, we can check to the next filter - continue; + if (match && opType == OpType.OR) { + return true; } - return false; - } - - if (match && opType == OpType.OR) { - return true; - } - } else if ("_publish_ip".equals(attr)) { - // We check explicitly only the publish_ip - String address = null; - if (node.getAddress() instanceof TransportAddress) { - address = NetworkAddress.format(node.getAddress().address().getAddress()); + break; } + case "_host_ip": { + // We check explicitly only the host_ip + boolean match = matchByIP(values, node.getHostAddress(), null); + if (opType == OpType.AND) { + if (match) { + // If we match, we can check to the next filter + continue; + } + return false; + } - boolean match = matchByIP(values, address, null); - if (opType == OpType.AND) { - if (match) { - // If we match, we can check to the next filter - continue; + if (match && opType == OpType.OR) { + return true; } - return false; + break; } + case "_publish_ip": { + // We check explicitly only the publish_ip + String address = null; + if (node.getAddress() != null) { + address = NetworkAddress.format(node.getAddress().address().getAddress()); + } - if (match && opType == OpType.OR) { - return true; - } - } else if ("_host".equals(attr)) { - for (String value : values) { - if (Regex.simpleMatch(value, node.getHostName()) || Regex.simpleMatch(value, node.getHostAddress())) { - if (opType == OpType.OR) { - return true; - } - } else { - if (opType == OpType.AND) { - return false; + boolean match = matchByIP(values, address, null); + if (opType == OpType.AND) { + if (match) { + // If we match, we can check to the next filter + continue; } + return false; } + + if (match && opType == OpType.OR) { + return true; + } + break; } - } else if ("_id".equals(attr)) { - for (String value : values) { - if (node.getId().equals(value)) { - if (opType == OpType.OR) { - return true; + case "_host": + for (String value : values) { + if (Regex.simpleMatch(value, node.getHostName()) || Regex.simpleMatch(value, node.getHostAddress())) { + if (opType == OpType.OR) { + return true; + } + } else { + if (opType == OpType.AND) { + return false; + } } - } else { - if (opType == OpType.AND) { - return false; + } + break; + case "_id": + for (String value : values) { + if (node.getId().equals(value)) { + if (opType == OpType.OR) { + return true; + } + } else { + if (opType == OpType.AND) { + return false; + } } } - } - } else if ("_name".equals(attr) || "name".equals(attr)) { - for (String value : values) { - if (Regex.simpleMatch(value, node.getName())) { - if (opType == OpType.OR) { - return true; + break; + case "_name": + case "name": + for (String value : values) { + if (Regex.simpleMatch(value, node.getName())) { + if (opType == OpType.OR) { + return true; + } + } else { + if (opType == OpType.AND) { + return false; + } } - } else { + } + break; + default: + String nodeAttributeValue = node.getAttributes().get(attr); + if (nodeAttributeValue == null) { if (opType == OpType.AND) { return false; + } else { + continue; } } - } - } else { - String nodeAttributeValue = node.getAttributes().get(attr); - if (nodeAttributeValue == null) { - if (opType == OpType.AND) { - return false; - } else { - continue; - } - } - for (String value : values) { - if (Regex.simpleMatch(value, nodeAttributeValue)) { - if (opType == OpType.OR) { - return true; - } - } else { - if (opType == OpType.AND) { - return false; + for (String value : values) { + if (Regex.simpleMatch(value, nodeAttributeValue)) { + if (opType == OpType.OR) { + return true; + } + } else { + if (opType == OpType.AND) { + return false; + } } } - } + break; } } - if (opType == OpType.OR) { - return false; - } else { - return true; - } + return opType != OpType.OR; } /** diff --git a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java index 00994cd04559e..279b583312436 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java @@ -28,6 +28,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -438,6 +439,24 @@ public String[] resolveNodes(String... nodes) { } } + private Set availableRoleNames; + + public Set availableRoleNames() { + Set roles = availableRoleNames; + if (roles != null) { + return roles; + } + roles = new HashSet<>(); + for (DiscoveryNode n : nodes.values()) { + for (DiscoveryNodeRole role : n.getRoles()) { + roles.add(role.roleName()); + } + } + roles = org.elasticsearch.core.Set.copyOf(roles); + availableRoleNames = roles; + return roles; + } + public DiscoveryNodes newNode(DiscoveryNode node) { return new Builder(this).add(node).build(); } diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/IndexRoutingTable.java b/server/src/main/java/org/elasticsearch/cluster/routing/IndexRoutingTable.java index fe8671df80fa9..a754a1ba459cf 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/IndexRoutingTable.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/IndexRoutingTable.java @@ -500,13 +500,14 @@ public Builder addIndexShard(IndexShardRoutingTable indexShard) { * if it needs to be created. */ public Builder addShard(ShardRouting shard) { - IndexShardRoutingTable indexShard = shards.get(shard.id()); + final int id = shard.id(); + IndexShardRoutingTable indexShard = shards.get(id); if (indexShard == null) { - indexShard = new IndexShardRoutingTable.Builder(shard.shardId()).addShard(shard).build(); + indexShard = new IndexShardRoutingTable(shard.shardId(), org.elasticsearch.core.List.of(shard)); } else { - indexShard = new IndexShardRoutingTable.Builder(indexShard).addShard(shard).build(); + indexShard = indexShard.withAddedShard(shard); } - shards.put(indexShard.shardId().id(), indexShard); + shards.put(id, indexShard); return this; } diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java b/server/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java index ff70ab4b71cef..1b6e9aa8d2dd1 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/IndexShardRoutingTable.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; @@ -68,9 +69,8 @@ public class IndexShardRoutingTable implements Iterable { final List allInitializingShards; IndexShardRoutingTable(ShardId shardId, List shards) { - this.shardId = shardId; - this.shuffler = new RotationShardShuffler(Randomness.get().nextInt()); - this.shards = Collections.unmodifiableList(shards); + // don't allow more than one shard copy with same id to be allocated to same node + assert Builder.distinctNodes(shards) : "more than one shard with same id assigned to same node (shards: " + shards + ")"; ShardRouting primary = null; List replicas = new ArrayList<>(); @@ -108,6 +108,9 @@ public class IndexShardRoutingTable implements Iterable { allShardsStarted = false; } } + this.shardId = shardId; + this.shuffler = new RotationShardShuffler(Randomness.get().nextInt()); + this.shards = org.elasticsearch.core.List.copyOf(shards); this.allShardsStarted = allShardsStarted; this.primary = primary; this.replicas = CollectionUtils.wrapUnmodifiableOrEmptySingleton(replicas); @@ -117,6 +120,127 @@ public class IndexShardRoutingTable implements Iterable { this.allAllocationIds = Collections.unmodifiableSet(allAllocationIds); } + private IndexShardRoutingTable(ShardId shardId, List shards, boolean allShardsStarted, + ShardRouting primary, List replicas, List activeShards, + List assignedShards, List allInitializingShards, + Set allAllocationIds) { + assert Builder.distinctNodes(shards) : "more than one shard with same id assigned to same node (shards: " + shards + ")"; + this.shardId = shardId; + this.shuffler = new RotationShardShuffler(Randomness.get().nextInt()); + this.shards = shards; + this.allShardsStarted = allShardsStarted; + this.primary = primary; + this.replicas = replicas; + this.activeShards = activeShards; + this.assignedShards = assignedShards; + this.allInitializingShards = allInitializingShards; + this.allAllocationIds = allAllocationIds; + } + + public IndexShardRoutingTable withAddedShard(ShardRouting shard) { + final int size = shards.size(); + final ShardRouting[] newRoutings = new ShardRouting[size + 1]; + shards.toArray(newRoutings); + newRoutings[size] = shard; + ShardRouting primary = shard.primary() ? shard : this.primary; + final boolean relocating = shard.relocating(); + final List replicas; + if (shard.primary()) { + replicas = this.replicas; + } else { + final int replicaCount = this.replicas.size(); + if (replicaCount == 0) { + replicas = org.elasticsearch.core.List.of(shard); + } else { + final ShardRouting[] newReplicaRoutings = new ShardRouting[replicaCount + 1]; + this.replicas.toArray(newReplicaRoutings); + newReplicaRoutings[replicaCount] = shard; + replicas = Arrays.asList(newReplicaRoutings); + } + } + final int activeCount = this.activeShards.size(); + final List activeShards; + if (shard.active()) { + if (activeCount == 0) { + activeShards = org.elasticsearch.core.List.of(shard); + } else { + final ShardRouting[] newActiveRoutings = new ShardRouting[activeCount + 1]; + this.activeShards.toArray(newActiveRoutings); + newActiveRoutings[activeCount] = shard; + activeShards = Arrays.asList(newActiveRoutings); + } + } else { + activeShards = this.activeShards; + } + final int initializingCount = this.allInitializingShards.size(); + final List allInitializingShards; + if (shard.initializing()) { + if (initializingCount == 0) { + allInitializingShards = org.elasticsearch.core.List.of(shard); + } else { + final ShardRouting[] newInitializingRoutings; + newInitializingRoutings = new ShardRouting[initializingCount + 1]; + this.allInitializingShards.toArray(newInitializingRoutings); + newInitializingRoutings[initializingCount] = shard; + allInitializingShards = Arrays.asList(newInitializingRoutings); + } + } else if (relocating) { + if (initializingCount == 0) { + allInitializingShards = org.elasticsearch.core.List.of(shard.getTargetRelocatingShard()); + } else { + final ShardRouting[] newInitializingRoutings = new ShardRouting[initializingCount + 1]; + this.allInitializingShards.toArray(newInitializingRoutings); + newInitializingRoutings[initializingCount] = shard.getTargetRelocatingShard(); + allInitializingShards = Arrays.asList(newInitializingRoutings); + } + } else { + allInitializingShards = this.allInitializingShards; + } + final Set allAllocationIds = new HashSet<>(this.allAllocationIds); + if (relocating) { + allAllocationIds.add(shard.getTargetRelocatingShard().allocationId().getId()); + } + final int assignedCount = this.assignedShards.size(); + final List assignedShards; + if (shard.assignedToNode()) { + allAllocationIds.add(shard.allocationId().getId()); + if (assignedCount == 0) { + if (relocating) { + assignedShards = org.elasticsearch.core.List.of(shard.getTargetRelocatingShard(), shard); + } else { + assignedShards = org.elasticsearch.core.List.of(shard); + } + } else { + final ShardRouting[] newAssignedRoutings; + if (relocating) { + newAssignedRoutings = new ShardRouting[assignedCount + 2]; + this.assignedShards.toArray(newAssignedRoutings); + newAssignedRoutings[assignedCount] = shard.getTargetRelocatingShard(); + newAssignedRoutings[assignedCount + 1] = shard; + } else { + newAssignedRoutings = new ShardRouting[assignedCount + 1]; + this.assignedShards.toArray(newAssignedRoutings); + newAssignedRoutings[assignedCount] = shard; + } + assignedShards = Arrays.asList(newAssignedRoutings); + } + } else { + assignedShards = this.assignedShards; + } + final boolean allShardsStarted = this.allShardsStarted && shard.started(); + return new IndexShardRoutingTable( + shardId, + org.elasticsearch.core.List.of(newRoutings), + allShardsStarted, + primary, + replicas, + activeShards, + assignedShards, + allInitializingShards, + Collections.unmodifiableSet(allAllocationIds) + ); + } + /** * Returns the shards id * @@ -657,7 +781,7 @@ public List shardsWithState(ShardRoutingState state) { public static class Builder { - private ShardId shardId; + private final ShardId shardId; private final List shards; public Builder(IndexShardRoutingTable indexShard) { @@ -681,9 +805,7 @@ public Builder removeShard(ShardRouting shardEntry) { } public IndexShardRoutingTable build() { - // don't allow more than one shard copy with same id to be allocated to same node - assert distinctNodes(shards) : "more than one shard with same id assigned to same node (shards: " + shards + ")"; - return new IndexShardRoutingTable(shardId, Collections.unmodifiableList(new ArrayList<>(shards))); + return new IndexShardRoutingTable(shardId, shards); } static boolean distinctNodes(List shards) { diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/RoutingNode.java b/server/src/main/java/org/elasticsearch/cluster/routing/RoutingNode.java index f221032bfddcc..750216937f19b 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/RoutingNode.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/RoutingNode.java @@ -65,6 +65,23 @@ public RoutingNode(String nodeId, DiscoveryNode node, ShardRouting... shards) { assert invariant(); } + private RoutingNode(RoutingNode original) { + this.nodeId = original.nodeId; + this.node = original.node; + this.shards = new LinkedHashMap<>(original.shards); + this.relocatingShards = new LinkedHashSet<>(original.relocatingShards); + this.initializingShards = new LinkedHashSet<>(original.initializingShards); + this.shardsByIndex = new LinkedHashMap<>(original.shardsByIndex.size()); + for (Map.Entry> entry : original.shardsByIndex.entrySet()) { + shardsByIndex.put(entry.getKey(), new LinkedHashSet<>(entry.getValue())); + } + assert invariant(); + } + + public RoutingNode copy() { + return new RoutingNode(this); + } + private static LinkedHashMap buildShardRoutingMap(ShardRouting... shardRoutings) { final LinkedHashMap shards = new LinkedHashMap<>(); for (ShardRouting shardRouting : shardRoutings) { @@ -202,6 +219,14 @@ public int numberOfShardsWithState(ShardRoutingState... states) { return count; } + public Iterable initializingShardsIter() { + return initializingShards; + } + + public Iterable relocatingShardsIter() { + return relocatingShards; + } + /** * Determine the shards with a specific state * @param states set of states which should be listed diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java b/server/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java index 448813aac83a5..897506e0ffb34 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java @@ -8,6 +8,7 @@ package org.elasticsearch.cluster.routing; +import com.carrotsearch.hppc.cursors.ObjectCursor; import org.apache.logging.log4j.Logger; import org.apache.lucene.util.CollectionUtil; import org.elasticsearch.Assertions; @@ -15,6 +16,7 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.UnassignedInfo.AllocationStatus; import org.elasticsearch.cluster.routing.allocation.ExistingShardsAllocator; import org.elasticsearch.cluster.service.MasterService; @@ -45,8 +47,7 @@ /** * {@link RoutingNodes} represents a copy the routing information contained in the {@link ClusterState cluster state}. - * It can be either initialized as mutable or immutable (see {@link #RoutingNodes(ClusterState, boolean)}), allowing - * or disallowing changes to its elements. + * It can be either initialized as mutable or immutable, allowing or disallowing changes to its elements. * * The main methods used to update routing entries are: *
    @@ -58,11 +59,11 @@ */ public class RoutingNodes implements Iterable { - private final Map nodesToShards = new HashMap<>(); + private final Map nodesToShards; - private final UnassignedShards unassignedShards = new UnassignedShards(this); + private final UnassignedShards unassignedShards; - private final Map> assignedShards = new HashMap<>(); + private final Map> assignedShards; private final boolean readOnly; @@ -76,21 +77,24 @@ public class RoutingNodes implements Iterable { private int totalShardCount = 0; - private final Map> attributeValuesByAttribute = new HashMap<>(); - private final Map recoveriesPerNode = new HashMap<>(); + private final Map> attributeValuesByAttribute; + private final Map recoveriesPerNode; - public RoutingNodes(ClusterState clusterState) { - this(clusterState, true); + public RoutingNodes(RoutingTable routingTable, DiscoveryNodes discoveryNodes) { + this(routingTable, discoveryNodes, true); } - public RoutingNodes(ClusterState clusterState, boolean readOnly) { + public RoutingNodes(RoutingTable routingTable, DiscoveryNodes discoveryNodes, boolean readOnly) { this.readOnly = readOnly; - final RoutingTable routingTable = clusterState.routingTable(); + this.recoveriesPerNode = new HashMap<>(); + this.assignedShards = new HashMap<>(); + this.unassignedShards = new UnassignedShards(this); + this.attributeValuesByAttribute = new HashMap<>(); - Map> nodesToShards = new HashMap<>(); + final Map> nodesToShards = new HashMap<>(discoveryNodes.getDataNodes().size()); // fill in the nodeToShards with the "live" nodes - for (DiscoveryNode node : clusterState.nodes().getDataNodes().values()) { - nodesToShards.put(node.getId(), new LinkedHashMap<>()); // LinkedHashMap to preserve order + for (ObjectCursor node : discoveryNodes.getDataNodes().keys()) { + nodesToShards.put(node.value, new LinkedHashMap<>()); // LinkedHashMap to preserve order } // fill in the inverse of node -> shards allocated @@ -105,9 +109,9 @@ public RoutingNodes(ClusterState clusterState, boolean readOnly) { // by the ShardId, as this is common for primary and replicas. // A replica Set might have one (and not more) replicas with the state of RELOCATING. if (shard.assignedToNode()) { - Map entries = nodesToShards.computeIfAbsent(shard.currentNodeId(), - k -> new LinkedHashMap<>()); // LinkedHashMap to preserve order - ShardRouting previousValue = entries.put(shard.shardId(), shard); + // LinkedHashMap to preserve order + ShardRouting previousValue = nodesToShards.computeIfAbsent(shard.currentNodeId(), k -> new LinkedHashMap<>()) + .put(shard.shardId(), shard); if (previousValue != null) { throw new IllegalArgumentException("Cannot have two different shards with same shard id on same node"); } @@ -117,14 +121,12 @@ public RoutingNodes(ClusterState clusterState, boolean readOnly) { } if (shard.relocating()) { relocatingShards++; - // LinkedHashMap to preserve order. - // Add the counterpart shard with relocatingNodeId reflecting the source from which - // it's relocating from. - entries = nodesToShards.computeIfAbsent(shard.relocatingNodeId(), - k -> new LinkedHashMap<>()); ShardRouting targetShardRouting = shard.getTargetRelocatingShard(); addInitialRecovery(targetShardRouting, indexShard.primary); - previousValue = entries.put(targetShardRouting.shardId(), targetShardRouting); + // LinkedHashMap to preserve order. + // Add the counterpart shard with relocatingNodeId reflecting the source from which it's relocating from. + previousValue = nodesToShards.computeIfAbsent(shard.relocatingNodeId(), + k -> new LinkedHashMap<>()).put(targetShardRouting.shardId(), targetShardRouting); if (previousValue != null) { throw new IllegalArgumentException("Cannot have two different shards with same shard id on same node"); } @@ -142,12 +144,44 @@ public RoutingNodes(ClusterState clusterState, boolean readOnly) { } } } + this.nodesToShards = new HashMap<>(nodesToShards.size()); for (Map.Entry> entry : nodesToShards.entrySet()) { String nodeId = entry.getKey(); - this.nodesToShards.put(nodeId, new RoutingNode(nodeId, clusterState.nodes().get(nodeId), entry.getValue())); + this.nodesToShards.put(nodeId, new RoutingNode(nodeId, discoveryNodes.get(nodeId), entry.getValue())); } } + private RoutingNodes(RoutingNodes routingNodes) { + this.readOnly = false; + this.nodesToShards = new HashMap<>(routingNodes.nodesToShards.size()); + for (Map.Entry entry : routingNodes.nodesToShards.entrySet()) { + this.nodesToShards.put(entry.getKey(), entry.getValue().copy()); + } + this.assignedShards = new HashMap<>(routingNodes.assignedShards.size()); + for (Map.Entry> entry : routingNodes.assignedShards.entrySet()) { + this.assignedShards.put(entry.getKey(), new ArrayList<>(entry.getValue())); + } + this.unassignedShards = routingNodes.unassignedShards.copyTo(this); + + this.inactivePrimaryCount = routingNodes.inactivePrimaryCount; + this.inactiveShardCount = routingNodes.inactiveShardCount; + this.relocatingShards = routingNodes.relocatingShards; + this.activeShardCount = routingNodes.activeShardCount; + this.totalShardCount = routingNodes.totalShardCount; + this.attributeValuesByAttribute = new HashMap<>(routingNodes.attributeValuesByAttribute.size()); + for (Map.Entry> entry : routingNodes.attributeValuesByAttribute.entrySet()) { + this.attributeValuesByAttribute.put(entry.getKey(), new HashSet<>(entry.getValue())); + } + this.recoveriesPerNode = new HashMap<>(routingNodes.recoveriesPerNode.size()); + for (Map.Entry entry : routingNodes.recoveriesPerNode.entrySet()) { + this.recoveriesPerNode.put(entry.getKey(), entry.getValue().copy()); + } + } + + public RoutingNodes mutableCopy() { + return new RoutingNodes(this); + } + private void addRecovery(ShardRouting routing) { updateRecoveryCounts(routing, true, findAssignedPrimaryIfPeerRecovery(routing)); } @@ -784,15 +818,27 @@ public static final class UnassignedShards implements Iterable { private final List unassigned; private final List ignored; - private int primaries = 0; - private int ignoredPrimaries = 0; + private int primaries; + private int ignoredPrimaries; public UnassignedShards(RoutingNodes nodes) { + this(nodes, new ArrayList<>(), new ArrayList<>(), 0, 0); + } + + private UnassignedShards(RoutingNodes nodes, List unassigned, List ignored, + int primaries, int ignoredPrimaries) { this.nodes = nodes; - unassigned = new ArrayList<>(); - ignored = new ArrayList<>(); + this.unassigned = unassigned; + this.ignored = ignored; + this.primaries = primaries; + this.ignoredPrimaries = ignoredPrimaries; + } + + public UnassignedShards copyTo(RoutingNodes newNodes) { + return new UnassignedShards(newNodes, new ArrayList<>(unassigned), new ArrayList<>(ignored), primaries, ignoredPrimaries); } + public void add(ShardRouting shardRouting) { if(shardRouting.primary()) { primaries++; @@ -1157,6 +1203,13 @@ private static final class Recoveries { private int incoming = 0; private int outgoing = 0; + public Recoveries copy() { + final Recoveries copy = new Recoveries(); + copy.incoming = incoming; + copy.outgoing = outgoing; + return copy; + } + void addOutgoing(int howMany) { assert outgoing + howMany >= 0 : outgoing + howMany+ " must be >= 0"; outgoing += howMany; diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java b/server/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java index 2c30033f84af1..5099f2334f1df 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java @@ -58,6 +58,10 @@ private RoutingTable(long version, ImmutableOpenMap i this.indicesRouting = indicesRouting; } + public RoutingTable withIncrementedVersion() { + return new RoutingTable(version + 1, indicesRouting); + } + /** * Get's the {@link IndexShardRoutingTable} for the given shard id from the given {@link IndexRoutingTable} * or throws a {@link ShardNotFoundException} if no shard by the given id is found in the IndexRoutingTable. @@ -207,7 +211,7 @@ public List allShards(String index) { * @param includeEmpty if true, a shard iterator will be added for non-assigned shards as well */ public GroupShardsIterator allActiveShardsGrouped(String[] indices, boolean includeEmpty) { - return allSatisfyingPredicateShardsGrouped(indices, includeEmpty, ACTIVE_PREDICATE); + return allSatisfyingPredicateShardsGrouped(indices, includeEmpty, ShardRouting::active); } /** @@ -216,12 +220,9 @@ public GroupShardsIterator allActiveShardsGrouped(String[] indice * @param includeEmpty if true, a shard iterator will be added for non-assigned shards as well */ public GroupShardsIterator allAssignedShardsGrouped(String[] indices, boolean includeEmpty) { - return allSatisfyingPredicateShardsGrouped(indices, includeEmpty, ASSIGNED_PREDICATE); + return allSatisfyingPredicateShardsGrouped(indices, includeEmpty, ShardRouting::assignedToNode); } - private static Predicate ACTIVE_PREDICATE = ShardRouting::active; - private static Predicate ASSIGNED_PREDICATE = ShardRouting::assignedToNode; - private GroupShardsIterator allSatisfyingPredicateShardsGrouped(String[] indices, boolean includeEmpty, Predicate predicate) { // use list here since we need to maintain identity across shards @@ -361,6 +362,10 @@ private static class RoutingTableDiff implements Diff { @Override public RoutingTable apply(RoutingTable part) { + final ImmutableOpenMap updatedRouting = indicesRouting.apply(part.indicesRouting); + if (part.version == version && updatedRouting == part.indicesRouting) { + return part; + } return new RoutingTable(version, indicesRouting.apply(part.indicesRouting)); } diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/ShardRouting.java b/server/src/main/java/org/elasticsearch/cluster/routing/ShardRouting.java index d22a5035562e3..0736afcc61383 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/ShardRouting.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/ShardRouting.java @@ -44,7 +44,7 @@ public final class ShardRouting implements Writeable, ToXContentObject { private final RecoverySource recoverySource; private final UnassignedInfo unassignedInfo; private final AllocationId allocationId; - private final transient List asList; + private final List asList; private final long expectedShardSize; @Nullable private final ShardRouting targetRelocatingShard; diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java index 846660f1a1004..2161a3e30734c 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java @@ -34,7 +34,9 @@ import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; import org.elasticsearch.cluster.routing.allocation.decider.Decision; import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.collect.ImmutableOpenMap; +import org.elasticsearch.core.MemoizedSupplier; import org.elasticsearch.gateway.GatewayAllocator; import org.elasticsearch.gateway.PriorityComparator; import org.elasticsearch.snapshots.SnapshotsInfoService; @@ -69,7 +71,7 @@ public class AllocationService { private Map existingShardsAllocators; private final ShardsAllocator shardsAllocator; private final ClusterInfoService clusterInfoService; - private SnapshotsInfoService snapshotsInfoService; + private final SnapshotsInfoService snapshotsInfoService; // only for tests that use the GatewayAllocator as the unique ExistingShardsAllocator public AllocationService(AllocationDeciders allocationDeciders, GatewayAllocator gatewayAllocator, @@ -107,10 +109,12 @@ public ClusterState applyStartedShards(ClusterState clusterState, List(() -> { + RoutingNodes routingNodes = getMutableRoutingNodes(clusterState); + // shuffle the unassigned shards, just so we won't have things like poison failed shards + routingNodes.unassigned().shuffle(); + return routingNodes; + }), clusterState, clusterInfoService.getClusterInfo(), snapshotsInfoService.snapshotShardSizes(), currentNanoTime()); // as starting a primary relocation target can reinitialize replica shards, start replicas first startedShards = new ArrayList<>(startedShards); @@ -181,17 +185,20 @@ public ClusterState applyFailedShards(final ClusterState clusterState, final Lis } ClusterState tmpState = IndexMetadataUpdater.removeStaleIdsWithoutRoutings(clusterState, staleShards, logger); - RoutingNodes routingNodes = getMutableRoutingNodes(tmpState); - // shuffle the unassigned shards, just so we won't have things like poison failed shards - routingNodes.unassigned().shuffle(); long currentNanoTime = currentNanoTime(); - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, routingNodes, tmpState, + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, new MemoizedSupplier<>(() -> { + RoutingNodes routingNodes = getMutableRoutingNodes(tmpState); + // shuffle the unassigned shards, just so we won't have things like poison failed shards + routingNodes.unassigned().shuffle(); + return routingNodes; + }), tmpState, clusterInfoService.getClusterInfo(), snapshotsInfoService.snapshotShardSizes(), currentNanoTime); for (FailedShard failedShardEntry : failedShards) { ShardRouting shardToFail = failedShardEntry.getRoutingEntry(); IndexMetadata indexMetadata = allocation.metadata().getIndexSafe(shardToFail.shardId().getIndex()); allocation.addIgnoreShardForNode(shardToFail.shardId(), shardToFail.currentNodeId()); + final RoutingNodes routingNodes = allocation.routingNodes(); // failing a primary also fails initializing replica shards, re-resolve ShardRouting ShardRouting failedShard = routingNodes.getByAllocationId(shardToFail.shardId(), shardToFail.allocationId().getId()); if (failedShard != null) { @@ -236,10 +243,13 @@ public ClusterState applyFailedShards(final ClusterState clusterState, final Lis * if needed. */ public ClusterState disassociateDeadNodes(ClusterState clusterState, boolean reroute, String reason) { - RoutingNodes routingNodes = getMutableRoutingNodes(clusterState); - // shuffle the unassigned shards, just so we won't have things like poison failed shards - routingNodes.unassigned().shuffle(); - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, routingNodes, clusterState, + final ClusterState finalClusterState = clusterState; + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, new MemoizedSupplier<>(() -> { + RoutingNodes routingNodes = getMutableRoutingNodes(finalClusterState); + // shuffle the unassigned shards, just so we won't have things like poison failed shards + routingNodes.unassigned().shuffle(); + return routingNodes; + }), clusterState, clusterInfoService.getClusterInfo(), snapshotsInfoService.snapshotShardSizes(), currentNanoTime()); // first, clear from the shards any node id they used to belong to that is now dead @@ -260,7 +270,7 @@ public ClusterState disassociateDeadNodes(ClusterState clusterState, boolean rer * Returns an updated cluster state if changes were necessary, or the identical cluster if no changes were required. */ public ClusterState adaptAutoExpandReplicas(ClusterState clusterState) { - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, clusterState.getRoutingNodes(), clusterState, + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, clusterState::getRoutingNodes, clusterState, clusterInfoService.getClusterInfo(), snapshotsInfoService.snapshotShardSizes(), currentNanoTime()); final Map> autoExpandReplicaChanges = AutoExpandReplicas.getAutoExpandReplicaChanges(clusterState.metadata(), allocation); @@ -271,7 +281,7 @@ public ClusterState adaptAutoExpandReplicas(ClusterState clusterState) { final Metadata.Builder metadataBuilder = Metadata.builder(clusterState.metadata()); for (Map.Entry> entry : autoExpandReplicaChanges.entrySet()) { final int numberOfReplicas = entry.getKey(); - final String[] indices = entry.getValue().toArray(new String[entry.getValue().size()]); + final String[] indices = entry.getValue().toArray(Strings.EMPTY_ARRAY); // we do *not* update the in sync allocation ids as they will be removed upon the first index // operation which make these copies stale routingTableBuilder.updateNumberOfReplicas(numberOfReplicas, indices); @@ -374,11 +384,11 @@ public static String firstListElementsToCommaDelimitedString(List element } public CommandsResult reroute(final ClusterState clusterState, AllocationCommands commands, boolean explain, boolean retryFailed) { - RoutingNodes routingNodes = getMutableRoutingNodes(clusterState); // we don't shuffle the unassigned shards here, to try and get as close as possible to // a consistent result of the effect the commands have on the routing // this allows systems to dry run the commands, see the resulting cluster state, and act on it - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, routingNodes, clusterState, + RoutingAllocation allocation = + new RoutingAllocation(allocationDeciders, new MemoizedSupplier<>(() -> getMutableRoutingNodes(clusterState)), clusterState, clusterInfoService.getClusterInfo(), snapshotsInfoService.snapshotShardSizes(), currentNanoTime()); // don't short circuit deciders, we want a full explanation allocation.debugDecision(true); @@ -410,11 +420,12 @@ public CommandsResult reroute(final ClusterState clusterState, AllocationCommand */ public ClusterState reroute(ClusterState clusterState, String reason) { ClusterState fixedClusterState = adaptAutoExpandReplicas(clusterState); - - RoutingNodes routingNodes = getMutableRoutingNodes(fixedClusterState); - // shuffle the unassigned shards, just so we won't have things like poison failed shards - routingNodes.unassigned().shuffle(); - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, routingNodes, fixedClusterState, + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, new MemoizedSupplier<>(() -> { + RoutingNodes routingNodes = getMutableRoutingNodes(fixedClusterState); + // shuffle the unassigned shards, just so we won't have things like poison failed shards + routingNodes.unassigned().shuffle(); + return routingNodes; + }), fixedClusterState, clusterInfoService.getClusterInfo(), snapshotsInfoService.snapshotShardSizes(), currentNanoTime()); reroute(allocation); if (fixedClusterState == clusterState && allocation.routingNodesChanged() == false) { @@ -542,8 +553,8 @@ private void applyStartedShards(RoutingAllocation routingAllocation, List routingNodes; private final Metadata metadata; @@ -85,8 +86,8 @@ public class RoutingAllocation { * @param clusterState cluster state before rerouting * @param currentNanoTime the nano time to use for all delay allocation calculation (typically {@link System#nanoTime()}) */ - public RoutingAllocation(AllocationDeciders deciders, RoutingNodes routingNodes, ClusterState clusterState, ClusterInfo clusterInfo, - SnapshotShardSizeInfo shardSizeInfo, long currentNanoTime) { + public RoutingAllocation(AllocationDeciders deciders, Supplier routingNodes, ClusterState clusterState, + ClusterInfo clusterInfo, SnapshotShardSizeInfo shardSizeInfo, long currentNanoTime) { this.deciders = deciders; this.routingNodes = routingNodes; this.metadata = clusterState.metadata(); @@ -132,7 +133,7 @@ public RoutingTable routingTable() { * @return routing nodes */ public RoutingNodes routingNodes() { - return routingNodes; + return routingNodes.get(); } /** diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java index 83366156a147e..ffdcc02c39bf6 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java @@ -1078,12 +1078,7 @@ public int highestPrimary(String index) { } public void addShard(ShardRouting shard) { - ModelIndex index = indices.get(shard.getIndexName()); - if (index == null) { - index = new ModelIndex(shard.getIndexName()); - indices.put(index.getIndexId(), index); - } - index.addShard(shard); + indices.computeIfAbsent(shard.getIndexName(), ModelIndex::new).addShard(shard); numShards++; } diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AwarenessAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AwarenessAllocationDecider.java index 41093ec8da0b7..a6ff60faea7f7 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AwarenessAllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/AwarenessAllocationDecider.java @@ -29,7 +29,6 @@ import static java.util.Collections.emptyList; import static java.util.stream.Collectors.toList; -import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_AUTO_EXPAND_REPLICAS_SETTING; /** * This {@link AllocationDecider} controls shard allocation based on @@ -151,7 +150,7 @@ private Decision underCapacity(ShardRouting shardRouting, RoutingNode node, Rout final boolean debug = allocation.debugDecision(); final IndexMetadata indexMetadata = allocation.metadata().getIndexSafe(shardRouting.index()); - if (INDEX_AUTO_EXPAND_REPLICAS_SETTING.get(indexMetadata.getSettings()).expandToAllNodes()) { + if (indexMetadata.getAutoExpandReplicas().expandToAllNodes()) { return YES_AUTO_EXPAND_ALL; } diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDecider.java index e8d0e56ffaebc..1a661ae8238b1 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDecider.java @@ -20,7 +20,6 @@ import org.elasticsearch.cluster.routing.RoutingNode; import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.routing.ShardRouting; -import org.elasticsearch.cluster.routing.ShardRoutingState; import org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.common.Strings; @@ -118,7 +117,7 @@ public static long sizeOfRelocatingShards(RoutingNode node, boolean subtractShar // no longer initializing because their recovery failed or was cancelled. // Where reserved space is unavailable (e.g. stats are out-of-sync) compute a conservative estimate for initialising shards - for (ShardRouting routing : node.shardsWithState(ShardRoutingState.INITIALIZING)) { + for (ShardRouting routing : node.initializingShardsIter()) { if (routing.relocatingNodeId() == null) { // in practice the only initializing-but-not-relocating shards with a nonzero expected shard size will be ones created // by a resize (shrink/split/clone) operation which we expect to happen using hard links, so they shouldn't be taking @@ -138,7 +137,7 @@ public static long sizeOfRelocatingShards(RoutingNode node, boolean subtractShar } if (subtractShardsMovingAway) { - for (ShardRouting routing : node.shardsWithState(ShardRoutingState.RELOCATING)) { + for (ShardRouting routing : node.relocatingShardsIter()) { String actualPath = clusterInfo.getDataPath(routing); if (actualPath == null) { // we might know the path of this shard from before when it was relocating diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/SameShardAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/SameShardAllocationDecider.java index 83bcdcd30130c..8524ecab3839d 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/SameShardAllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/SameShardAllocationDecider.java @@ -17,8 +17,6 @@ import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Settings; -import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_AUTO_EXPAND_REPLICAS_SETTING; - /** * An allocation decider that prevents multiple instances of the same shard to * be allocated on the same {@code node}. @@ -71,8 +69,7 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing // if its already a NO decision looking at the node, or we aren't configured to look at the host, return the decision return decision; } - if (INDEX_AUTO_EXPAND_REPLICAS_SETTING.get( - allocation.metadata().getIndexSafe(shardRouting.index()).getSettings()).expandToAllNodes()) { + if (allocation.metadata().getIndexSafe(shardRouting.index()).getAutoExpandReplicas().expandToAllNodes()) { return YES_AUTO_EXPAND_ALL; } if (node.node() != null) { diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ShardsLimitAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ShardsLimitAllocationDecider.java index aa8ae89a45fd4..3449f8657f91b 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ShardsLimitAllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ShardsLimitAllocationDecider.java @@ -46,6 +46,8 @@ public class ShardsLimitAllocationDecider extends AllocationDecider { private volatile int clusterShardLimit; + private final int indexShardLimit; + /** * Controls the maximum number of shards per index on a single Elasticsearch * node. Negative values are interpreted as unlimited. @@ -62,11 +64,9 @@ public class ShardsLimitAllocationDecider extends AllocationDecider { Setting.intSetting("cluster.routing.allocation.total_shards_per_node", -1, -1, Property.Dynamic, Property.NodeScope); - private final Settings settings; - public ShardsLimitAllocationDecider(Settings settings, ClusterSettings clusterSettings) { - this.settings = settings; this.clusterShardLimit = CLUSTER_TOTAL_SHARDS_PER_NODE_SETTING.get(settings); + this.indexShardLimit = INDEX_TOTAL_SHARDS_PER_NODE_SETTING.get(settings); clusterSettings.addSettingsUpdateConsumer(CLUSTER_TOTAL_SHARDS_PER_NODE_SETTING, this::setClusterShardLimit); } @@ -88,7 +88,8 @@ public Decision canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAl private Decision doDecide(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation, BiPredicate decider) { IndexMetadata indexMd = allocation.metadata().getIndexSafe(shardRouting.index()); - final int indexShardLimit = INDEX_TOTAL_SHARDS_PER_NODE_SETTING.get(indexMd.getSettings(), settings); + final Integer indexLevelLimit = indexMd.getShardsPerNodeLimit(); + final int indexShardLimit = indexLevelLimit == null ? this.indexShardLimit : indexLevelLimit; // Capture the limit here in case it changes during this method's // execution final int clusterShardLimit = this.clusterShardLimit; diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ThrottlingAllocationDecider.java b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ThrottlingAllocationDecider.java index f93494fde8d82..2982a00b72ab6 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ThrottlingAllocationDecider.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/allocation/decider/ThrottlingAllocationDecider.java @@ -15,7 +15,6 @@ import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.UnassignedInfo; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; -import org.elasticsearch.cluster.routing.ShardRoutingState; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting.Property; @@ -112,7 +111,7 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing // count *just the primaries* currently doing recovery on the node and check against primariesInitialRecoveries int primariesInRecovery = 0; - for (ShardRouting shard : node.shardsWithState(ShardRoutingState.INITIALIZING)) { + for (ShardRouting shard : node.initializingShardsIter()) { // when a primary shard is INITIALIZING, it can be because of *initial recovery* or *relocation from another node* // we only count initial recoveries here, so we need to make sure that relocating node is null if (shard.primary() && shard.relocatingNodeId() == null) { diff --git a/server/src/main/java/org/elasticsearch/cluster/service/MasterService.java b/server/src/main/java/org/elasticsearch/cluster/service/MasterService.java index 9999b1ddcb8ba..04dcde6bb093a 100644 --- a/server/src/main/java/org/elasticsearch/cluster/service/MasterService.java +++ b/server/src/main/java/org/elasticsearch/cluster/service/MasterService.java @@ -23,11 +23,10 @@ import org.elasticsearch.cluster.ClusterStateTaskListener; import org.elasticsearch.cluster.coordination.ClusterStatePublisher; import org.elasticsearch.cluster.coordination.FailedToCommitClusterStateException; -import org.elasticsearch.cluster.metadata.Metadata; +import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.cluster.metadata.ProcessClusterEventTimeoutException; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; -import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.common.Priority; import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.settings.ClusterSettings; @@ -374,16 +373,17 @@ private ClusterState patchVersions(ClusterState previousClusterState, ClusterTas if (previousClusterState != newClusterState) { // only the master controls the version numbers + final Map previousIndicesLookup = newClusterState.metadata().getIndicesLookup(); Builder builder = incrementVersion(newClusterState); if (previousClusterState.routingTable() != newClusterState.routingTable()) { - builder.routingTable(RoutingTable.builder(newClusterState.routingTable()) - .version(newClusterState.routingTable().version() + 1).build()); + builder.routingTable(newClusterState.routingTable().withIncrementedVersion()); } if (previousClusterState.metadata() != newClusterState.metadata()) { - builder.metadata(Metadata.builder(newClusterState.metadata()).version(newClusterState.metadata().version() + 1)); + builder.metadata(newClusterState.metadata().withIncrementedVersion()); } newClusterState = builder.build(); + assert previousIndicesLookup == newClusterState.metadata().getIndicesLookup(); } return newClusterState; diff --git a/server/src/main/java/org/elasticsearch/common/collect/ImmutableOpenMap.java b/server/src/main/java/org/elasticsearch/common/collect/ImmutableOpenMap.java index 718642764b8fd..92e320fb52962 100644 --- a/server/src/main/java/org/elasticsearch/common/collect/ImmutableOpenMap.java +++ b/server/src/main/java/org/elasticsearch/common/collect/ImmutableOpenMap.java @@ -279,6 +279,8 @@ public static Builder builder(ImmutableOpenMap implements ObjectObjectMap { + private boolean changed = false; + private final ImmutableOpenMap original; private ObjectObjectHashMap map; @SuppressWarnings("unchecked") @@ -287,10 +289,12 @@ public Builder() { } public Builder(int size) { + this.original = null; this.map = new ObjectObjectHashMap<>(size); } public Builder(ImmutableOpenMap map) { + this.original = map; this.map = map.map.clone(); } @@ -298,6 +302,9 @@ public Builder(ImmutableOpenMap map) { * Builds a new instance of the */ public ImmutableOpenMap build() { + if (changed == false && original != null) { + return original; + } ObjectObjectHashMap map = this.map; this.map = null; // nullify the map, so any operation post build will fail! (hackish, but safest) return map.isEmpty() ? of() : new ImmutableOpenMap<>(map); @@ -307,6 +314,7 @@ public ImmutableOpenMap build() { * Puts all the entries in the map to the builder. */ public Builder putAll(Map map) { + changed = true; for (Map.Entry entry : map.entrySet()) { this.map.put(entry.getKey(), entry.getValue()); } @@ -317,12 +325,14 @@ public Builder putAll(Map map) { * A put operation that can be used in the fluent pattern. */ public Builder fPut(KType key, VType value) { + changed = true; map.put(key, value); return this; } @Override public VType put(KType key, VType value) { + changed = true; return map.put(key, value); } @@ -338,11 +348,13 @@ public VType getOrDefault(KType kType, VType vType) { @Override public int putAll(ObjectObjectAssociativeContainer container) { + changed = true; return map.putAll(container); } @Override public int putAll(Iterable> iterable) { + changed = true; return map.putAll(iterable); } @@ -350,12 +362,14 @@ public int putAll(Iterable fRemove(KType key) { + changed = true; map.remove(key); return this; } @Override public VType remove(KType key) { + changed = true; return map.remove(key); } @@ -381,11 +395,13 @@ public boolean isEmpty() { @Override public int removeAll(ObjectContainer container) { + changed = true; return map.removeAll(container); } @Override public int removeAll(ObjectPredicate predicate) { + changed = true; return map.removeAll(predicate); } @@ -396,6 +412,7 @@ public int removeAll(ObjectPredicate predicate) { @Override public void clear() { + changed = true; map.clear(); } @@ -416,7 +433,9 @@ public Builder cast() { @Override public int removeAll(ObjectObjectPredicate predicate) { - return map.removeAll(predicate); + final int removed = map.removeAll(predicate); + changed |= removed > 0; + return removed; } @Override @@ -441,16 +460,19 @@ public VType indexGet(int index) { @Override public VType indexReplace(int index, VType newValue) { + changed = true; return map.indexReplace(index, newValue); } @Override public void indexInsert(int index, KType key, VType value) { + changed = true; map.indexInsert(index, key, value); } @Override public void release() { + changed = true; map.release(); } diff --git a/server/src/main/java/org/elasticsearch/common/settings/Settings.java b/server/src/main/java/org/elasticsearch/common/settings/Settings.java index 8ead4b62f222a..b277e6437fef0 100644 --- a/server/src/main/java/org/elasticsearch/common/settings/Settings.java +++ b/server/src/main/java/org/elasticsearch/common/settings/Settings.java @@ -15,6 +15,7 @@ import org.elasticsearch.Version; import org.elasticsearch.common.Numbers; import org.elasticsearch.common.xcontent.XContentParserUtils; +import org.elasticsearch.common.util.StringLiteralDeduplicator; import org.elasticsearch.core.Booleans; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; @@ -75,6 +76,8 @@ public final class Settings implements ToXContentFragment { public static final Settings EMPTY = new Settings(Collections.emptyMap(), null); + private static final StringLiteralDeduplicator settingLiteralDeduplicator = new StringLiteralDeduplicator(); + /** The raw settings from the full key to raw string value. */ private final NavigableMap settings; @@ -99,7 +102,43 @@ private static Settings of(Map settings, SecureSettings secureSe private Settings(Map settings, SecureSettings secureSettings) { // we use a sorted map for consistent serialization when using getAsMap() - this.settings = Collections.unmodifiableNavigableMap(new TreeMap<>(settings)); + final TreeMap tree = new TreeMap<>(); + for (Map.Entry settingEntry : settings.entrySet()) { + final Object value = settingEntry.getValue(); + final Object internedValue; + if (value instanceof String) { + internedValue = settingLiteralDeduplicator.deduplicate((String) value); + } else if (value instanceof List) { + @SuppressWarnings("unchecked") + List valueList = (List) value; + final int listSize = valueList.size(); + int notInternedOffset = -1; + for (int i = 0; i < listSize; i++) { + final String listValue = valueList.get(i); + final String interned = settingLiteralDeduplicator.deduplicate(listValue); + if (interned != listValue) { + notInternedOffset = i; + break; + } + } + if (notInternedOffset >= 0) { + final String[] internedArr = new String[listSize]; + for (int i = 0; i < notInternedOffset; i++) { + internedArr[i] = valueList.get(i); + } + for (int i = notInternedOffset; i < valueList.size(); i++) { + internedArr[i] = settingLiteralDeduplicator.deduplicate(valueList.get(i)); + } + internedValue = org.elasticsearch.core.List.of(internedArr); + } else { + internedValue = org.elasticsearch.core.List.copyOf(valueList); + } + } else { + internedValue = value; + } + tree.put(settingLiteralDeduplicator.deduplicate(settingEntry.getKey()), internedValue); + } + this.settings = Collections.unmodifiableNavigableMap(tree); this.secureSettings = secureSettings; } @@ -411,7 +450,7 @@ public List getAsList(String key, List defaultValue, Boolean com if (valueFromPrefix instanceof List) { @SuppressWarnings("unchecked") final List valuesAsList = (List) valueFromPrefix; - return Collections.unmodifiableList(valuesAsList); + return valuesAsList; } else if (commaDelimited) { String[] strings = Strings.splitStringByCommaToArray(get(key)); if (strings.length > 0) { @@ -1189,11 +1228,19 @@ public boolean shouldRemoveMissingPlaceholder(String placeholderName) { } if (entry.getValue() instanceof List) { @SuppressWarnings("unchecked") - final ListIterator li = ((List) entry.getValue()).listIterator(); + final List mutableList = new ArrayList<>((List) entry.getValue()); + final ListIterator li = mutableList.listIterator(); + boolean changed = false; while (li.hasNext()) { final String settingValueRaw = li.next(); final String settingValueResolved = propertyPlaceholder.replacePlaceholders(settingValueRaw, placeholderResolver); - li.set(settingValueResolved); + if (settingValueResolved.equals(settingValueRaw) == false) { + li.set(settingValueResolved); + changed = true; + } + } + if (changed) { + entry.setValue(org.elasticsearch.core.List.copyOf(mutableList)); } continue; } diff --git a/server/src/main/java/org/elasticsearch/common/util/StringLiteralDeduplicator.java b/server/src/main/java/org/elasticsearch/common/util/StringLiteralDeduplicator.java index 658d6750aafbc..b306a07a6c10a 100644 --- a/server/src/main/java/org/elasticsearch/common/util/StringLiteralDeduplicator.java +++ b/server/src/main/java/org/elasticsearch/common/util/StringLiteralDeduplicator.java @@ -7,8 +7,6 @@ */ package org.elasticsearch.common.util; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.elasticsearch.common.util.concurrent.ConcurrentCollections; import java.util.Map; @@ -19,9 +17,6 @@ * advisable as its performance may deteriorate to slower than outright calls to {@link String#intern()}. */ public final class StringLiteralDeduplicator { - - private static final Logger logger = LogManager.getLogger(StringLiteralDeduplicator.class); - private static final int MAX_SIZE = 1000; private final Map map = ConcurrentCollections.newConcurrentMapWithAggressiveConcurrency(); @@ -37,7 +32,6 @@ public String deduplicate(String string) { final String interned = string.intern(); if (map.size() > MAX_SIZE) { map.clear(); - logger.debug("clearing intern cache"); } map.put(interned, interned); return interned; diff --git a/server/src/main/java/org/elasticsearch/gateway/PersistedClusterStateService.java b/server/src/main/java/org/elasticsearch/gateway/PersistedClusterStateService.java index 84ae4dba2f154..262920b12e9d9 100644 --- a/server/src/main/java/org/elasticsearch/gateway/PersistedClusterStateService.java +++ b/server/src/main/java/org/elasticsearch/gateway/PersistedClusterStateService.java @@ -21,8 +21,11 @@ import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.LeafReaderContext; +import org.apache.lucene.index.MergePolicy; +import org.apache.lucene.index.NoMergePolicy; import org.apache.lucene.index.SerialMergeScheduler; import org.apache.lucene.index.Term; +import org.apache.lucene.index.TieredMergePolicy; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; @@ -53,6 +56,7 @@ import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Setting; +import org.elasticsearch.core.SuppressForbidden; import org.elasticsearch.core.TimeValue; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.ByteArray; @@ -124,6 +128,9 @@ public class PersistedClusterStateService { private static final String INDEX_UUID_FIELD_NAME = "index_uuid"; private static final int COMMIT_DATA_SIZE = 4; + private static final MergePolicy NO_MERGE_POLICY = noMergePolicy(); + private static final MergePolicy DEFAULT_MERGE_POLICY = defaultMergePolicy(); + public static final String METADATA_DIRECTORY_NAME = MetadataStateFormat.STATE_DIR_NAME; public static final Setting SLOW_WRITE_LOGGING_THRESHOLD = Setting.timeSetting("gateway.slow_write_logging_threshold", @@ -193,10 +200,13 @@ private static IndexWriter createIndexWriter(Directory directory, boolean openEx indexWriterConfig.setOpenMode(openExisting ? IndexWriterConfig.OpenMode.APPEND : IndexWriterConfig.OpenMode.CREATE); // only commit when specifically instructed, we must not write any intermediate states indexWriterConfig.setCommitOnClose(false); - // most of the data goes into stored fields which are not buffered, so we only really need a tiny buffer + // most of the data goes into stored fields which are not buffered, so each doc written accounts for ~500B of indexing buffer + // (see e.g. BufferedUpdates#BYTES_PER_DEL_TERM); a 1MB buffer therefore gets flushed every ~2000 docs. indexWriterConfig.setRAMBufferSizeMB(1.0); // merge on the write thread (e.g. while flushing) indexWriterConfig.setMergeScheduler(new SerialMergeScheduler()); + // apply the adjusted merge policy + indexWriterConfig.setMergePolicy(DEFAULT_MERGE_POLICY); return new IndexWriter(directory, indexWriterConfig); } @@ -485,6 +495,28 @@ private static void consumeFromType(IndexSearcher indexSearcher, String type, FORMAT_PARAMS = new ToXContent.MapParams(params); } + @SuppressForbidden(reason = "merges are only temporarily suppressed, the merge scheduler does not need changing") + private static MergePolicy noMergePolicy() { + return NoMergePolicy.INSTANCE; + } + + private static MergePolicy defaultMergePolicy() { + final TieredMergePolicy mergePolicy = new TieredMergePolicy(); + + // don't worry about cleaning up deletes too much, segments will often get completely deleted once they're old enough + mergePolicy.setDeletesPctAllowed(50.0); + // more/smaller segments means there's a better chance they just get deleted before needing a merge + mergePolicy.setSegmentsPerTier(100); + // ... but if we do end up merging them then do them all + mergePolicy.setMaxMergeAtOnce(100); + // always use compound segments to avoid fsync overhead + mergePolicy.setNoCFSRatio(1.0); + // segments are mostly tiny, so don't pretend they are bigger + mergePolicy.setFloorSegmentMB(0.001); + + return mergePolicy; + } + /** * Encapsulates a single {@link IndexWriter} with its {@link Directory} for ease of closing, and a {@link Logger}. There is one of these * for each data path. @@ -526,7 +558,15 @@ void flush() throws IOException { this.indexWriter.flush(); } + void startWrite() { + // Disable merges during indexing - many older segments will ultimately contain no live docs and simply get deleted. + indexWriter.getConfig().setMergePolicy(NO_MERGE_POLICY); + } + void prepareCommit(String nodeId, long currentTerm, long lastAcceptedVersion) throws IOException { + indexWriter.getConfig().setMergePolicy(DEFAULT_MERGE_POLICY); + indexWriter.maybeMerge(); + final Map commitData = new HashMap<>(COMMIT_DATA_SIZE); commitData.put(CURRENT_TERM_KEY, Long.toString(currentTerm)); commitData.put(LAST_ACCEPTED_VERSION_KEY, Long.toString(lastAcceptedVersion)); @@ -598,6 +638,11 @@ public void writeFullStateAndCommit(long currentTerm, ClusterState clusterState) ensureOpen(); try { final long startTimeMillis = relativeTimeMillisSupplier.getAsLong(); + + for (MetadataIndexWriter metadataIndexWriter : metadataIndexWriters) { + metadataIndexWriter.startWrite(); + } + final WriterStats stats = overwriteMetadata(clusterState.metadata()); commit(currentTerm, clusterState.version()); fullStateWritten = true; @@ -627,6 +672,11 @@ void writeIncrementalStateAndCommit(long currentTerm, ClusterState previousClust try { final long startTimeMillis = relativeTimeMillisSupplier.getAsLong(); + + for (MetadataIndexWriter metadataIndexWriter : metadataIndexWriters) { + metadataIndexWriter.startWrite(); + } + final WriterStats stats = updateMetadata(previousClusterState.metadata(), clusterState.metadata()); commit(currentTerm, clusterState.version()); final long durationMillis = relativeTimeMillisSupplier.getAsLong() - startTimeMillis; diff --git a/server/src/main/java/org/elasticsearch/index/Index.java b/server/src/main/java/org/elasticsearch/index/Index.java index 13d7c242d8dc9..53dd9b51f9bf0 100644 --- a/server/src/main/java/org/elasticsearch/index/Index.java +++ b/server/src/main/java/org/elasticsearch/index/Index.java @@ -47,8 +47,7 @@ public Index(String name, String uuid) { * Read from a stream. */ public Index(StreamInput in) throws IOException { - this.name = in.readString(); - this.uuid = in.readString(); + this(in.readString(), in.readString()); } public String getName() { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecycleExecutionState.java b/server/src/main/java/org/elasticsearch/index/LifecycleExecutionState.java similarity index 97% rename from x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecycleExecutionState.java rename to server/src/main/java/org/elasticsearch/index/LifecycleExecutionState.java index f4651be75bcc2..1aaaa9e71b7db 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecycleExecutionState.java +++ b/server/src/main/java/org/elasticsearch/index/LifecycleExecutionState.java @@ -1,11 +1,12 @@ /* * 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. + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. */ -package org.elasticsearch.xpack.core.ilm; +package org.elasticsearch.index; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.cluster.metadata.IndexMetadata; @@ -24,6 +25,7 @@ */ public class LifecycleExecutionState { public static final String ILM_CUSTOM_METADATA_KEY = "ilm"; + public static final String FROZEN_PHASE = "frozen"; private static final String PHASE = "phase"; private static final String ACTION = "action"; @@ -94,12 +96,7 @@ private LifecycleExecutionState(String phase, String action, String step, String * @return The execution state of that index. */ public static LifecycleExecutionState fromIndexMetadata(IndexMetadata indexMetadata) { - Map customData = indexMetadata.getCustomData(ILM_CUSTOM_METADATA_KEY); - if (customData != null && customData.isEmpty() == false) { - return fromCustomMetadata(customData); - } else { - return EMPTY_STATE; - } + return indexMetadata.getLifecycleExecutionState(); } /** @@ -111,7 +108,7 @@ public static boolean isFrozenPhase(IndexMetadata indexMetadata) { Map customData = indexMetadata.getCustomData(ILM_CUSTOM_METADATA_KEY); // deliberately do not parse out the entire `LifeCycleExecutionState` to avoid the extra work involved since this method is // used heavily by autoscaling. - return customData != null && TimeseriesLifecycleType.FROZEN_PHASE.equals(customData.get(PHASE)); + return customData != null && FROZEN_PHASE.equals(customData.get(PHASE)); } /** * Retrieves the current {@link Step.StepKey} from the lifecycle state. Note that @@ -163,7 +160,7 @@ public static Builder builder(LifecycleExecutionState state) { .setStepTime(state.stepTime); } - static LifecycleExecutionState fromCustomMetadata(Map customData) { + public static LifecycleExecutionState fromCustomMetadata(Map customData) { Builder builder = builder(); String phase = customData.get(PHASE); if (phase != null) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/Step.java b/server/src/main/java/org/elasticsearch/index/Step.java similarity index 94% rename from x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/Step.java rename to server/src/main/java/org/elasticsearch/index/Step.java index 9d7906d91f899..68be04902935c 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/Step.java +++ b/server/src/main/java/org/elasticsearch/index/Step.java @@ -1,10 +1,11 @@ /* * 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. + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. */ -package org.elasticsearch.xpack.core.ilm; +package org.elasticsearch.index; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.common.Strings; @@ -20,7 +21,7 @@ import java.util.Objects; /** - * Represents one part of the execution of a {@link LifecycleAction}. + * Represents one part of the execution of a {@code LifecycleAction}. */ public abstract class Step { private final StepKey key; diff --git a/server/src/main/java/org/elasticsearch/repositories/RepositoriesService.java b/server/src/main/java/org/elasticsearch/repositories/RepositoriesService.java index cd7d95da01e2a..2abd65a9e1690 100644 --- a/server/src/main/java/org/elasticsearch/repositories/RepositoriesService.java +++ b/server/src/main/java/org/elasticsearch/repositories/RepositoriesService.java @@ -61,7 +61,6 @@ import static java.util.Collections.unmodifiableMap; import static org.elasticsearch.snapshots.SearchableSnapshotsSettings.SEARCHABLE_SNAPSHOTS_REPOSITORY_NAME_SETTING_KEY; import static org.elasticsearch.snapshots.SearchableSnapshotsSettings.SEARCHABLE_SNAPSHOTS_REPOSITORY_UUID_SETTING_KEY; -import static org.elasticsearch.snapshots.SearchableSnapshotsSettings.isSearchableSnapshotStore; /** * Service responsible for maintaining and providing access to snapshot repositories on nodes. @@ -712,7 +711,7 @@ private static void ensureNoSearchableSnapshotsIndicesInUse(ClusterState cluster long count = 0L; List indices = null; for (IndexMetadata indexMetadata : clusterState.metadata()) { - if (indexSettingsMatchRepositoryMetadata(indexMetadata.getSettings(), repositoryMetadata)) { + if (indexSettingsMatchRepositoryMetadata(indexMetadata, repositoryMetadata)) { if (indices == null) { indices = new ArrayList<>(); } @@ -734,13 +733,16 @@ private static void ensureNoSearchableSnapshotsIndicesInUse(ClusterState cluster } } - private static boolean indexSettingsMatchRepositoryMetadata(Settings indexSettings, RepositoryMetadata repositoryMetadata) { - if (isSearchableSnapshotStore(indexSettings)) { - final String indexRepositoryUuid = indexSettings.get(SEARCHABLE_SNAPSHOTS_REPOSITORY_UUID_SETTING_KEY); + private static boolean indexSettingsMatchRepositoryMetadata(IndexMetadata indexMetadata, RepositoryMetadata repositoryMetadata) { + if (indexMetadata.isSearchableSnapshotStore()) { + final String indexRepositoryUuid = indexMetadata.getSettings().get(SEARCHABLE_SNAPSHOTS_REPOSITORY_UUID_SETTING_KEY); if (Strings.hasLength(indexRepositoryUuid)) { return Objects.equals(repositoryMetadata.uuid(), indexRepositoryUuid); } else { - return Objects.equals(repositoryMetadata.name(), indexSettings.get(SEARCHABLE_SNAPSHOTS_REPOSITORY_NAME_SETTING_KEY)); + return Objects.equals( + repositoryMetadata.name(), + indexMetadata.getSettings().get(SEARCHABLE_SNAPSHOTS_REPOSITORY_NAME_SETTING_KEY) + ); } } return false; diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainActionTests.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainActionTests.java index 11ec0cdf1b722..9f3b7ff33271b 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainActionTests.java @@ -50,7 +50,7 @@ public void testInitializingOrRelocatingShardExplanation() throws Exception { ClusterState clusterState = ClusterStateCreationUtils.state("idx", randomBoolean(), shardRoutingState); ShardRouting shard = clusterState.getRoutingTable().index("idx").shard(0).primaryShard(); RoutingAllocation allocation = new RoutingAllocation(new AllocationDeciders(Collections.emptyList()), - clusterState.getRoutingNodes(), clusterState, null, null, System.nanoTime()); + clusterState::getRoutingNodes, clusterState, null, null, System.nanoTime()); ClusterAllocationExplanation cae = TransportClusterAllocationExplainAction.explainShard( shard, allocation, @@ -210,6 +210,6 @@ public void testFindShardAssignedToNode() { } private static RoutingAllocation routingAllocation(ClusterState clusterState) { - return new RoutingAllocation(NOOP_DECIDERS, clusterState.getRoutingNodes(), clusterState, null, null, System.nanoTime()); + return new RoutingAllocation(NOOP_DECIDERS, clusterState::getRoutingNodes, clusterState, null, null, System.nanoTime()); } } diff --git a/server/src/test/java/org/elasticsearch/cluster/ClusterChangedEventTests.java b/server/src/test/java/org/elasticsearch/cluster/ClusterChangedEventTests.java index 234a3f8f96e07..f8505cfd26d4c 100644 --- a/server/src/test/java/org/elasticsearch/cluster/ClusterChangedEventTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/ClusterChangedEventTests.java @@ -354,7 +354,7 @@ private static ClusterState createNonInitializedState(final int numNodes, final private static ClusterState nextState(final ClusterState previousState, List customMetadataList) { final ClusterState.Builder builder = ClusterState.builder(previousState); builder.stateUUID(UUIDs.randomBase64UUID()); - Metadata.Builder metadataBuilder = new Metadata.Builder(previousState.metadata()); + Metadata.Builder metadataBuilder = Metadata.builder(previousState.metadata()); for (ObjectObjectCursor customMetadata : previousState.metadata().customs()) { if (customMetadata.value instanceof TestCustomMetadata) { metadataBuilder.removeCustom(customMetadata.key); diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataTests.java index ab6b106a4dc5b..4ae9d03ba8afd 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataTests.java @@ -24,6 +24,7 @@ import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.set.Sets; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.xcontent.XContentParser; @@ -59,8 +60,10 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; +import static org.hamcrest.Matchers.sameInstance; import static org.hamcrest.Matchers.startsWith; public class MetadataTests extends ESTestCase { @@ -1591,6 +1594,103 @@ public void testDataStreamWriteRemoveDataStream() { assertThat(metadata.dataStreamAliases().get("logs-postgres").getDataStreams(), containsInAnyOrder("logs-postgres-replicated")); } + public void testReuseIndicesLookup() { + String indexName = "my-index"; + String aliasName = "my-alias"; + String dataStreamName = "logs-mysql-prod"; + String dataStreamAliasName = "logs-mysql"; + Metadata previous = Metadata.builder().build(); + + // Things that should change indices lookup + { + Metadata.Builder builder = Metadata.builder(previous); + IndexMetadata idx = DataStreamTestHelper.createFirstBackingIndex(dataStreamName).build(); + builder.put(idx, true); + DataStream dataStream = new DataStream(dataStreamName, new DataStream.TimestampField("@timestamp"), + org.elasticsearch.core.List.of(idx.getIndex())); + builder.put(dataStream); + Metadata metadata = builder.build(); + assertThat(previous.getIndicesLookup(), not(sameInstance(metadata.getIndicesLookup()))); + previous = metadata; + } + { + Metadata.Builder builder = Metadata.builder(previous); + builder.put(dataStreamAliasName, dataStreamName, false, null); + Metadata metadata = builder.build(); + assertThat(previous.getIndicesLookup(), not(sameInstance(metadata.getIndicesLookup()))); + previous = metadata; + } + { + Metadata.Builder builder = Metadata.builder(previous); + builder.put(dataStreamAliasName, dataStreamName, true, null); + Metadata metadata = builder.build(); + assertThat(previous.getIndicesLookup(), not(sameInstance(metadata.getIndicesLookup()))); + previous = metadata; + } + { + Metadata.Builder builder = Metadata.builder(previous); + builder.put(IndexMetadata.builder(indexName) + .settings(settings(Version.CURRENT)).creationDate(randomNonNegativeLong()) + .numberOfShards(1).numberOfReplicas(0)); + Metadata metadata = builder.build(); + assertThat(previous.getIndicesLookup(), not(sameInstance(metadata.getIndicesLookup()))); + previous = metadata; + } + { + Metadata.Builder builder = Metadata.builder(previous); + IndexMetadata.Builder imBuilder = IndexMetadata.builder(builder.get(indexName)); + imBuilder.putAlias(AliasMetadata.builder(aliasName).build()); + builder.put(imBuilder); + Metadata metadata = builder.build(); + assertThat(previous.getIndicesLookup(), not(sameInstance(metadata.getIndicesLookup()))); + previous = metadata; + } + { + Metadata.Builder builder = Metadata.builder(previous); + IndexMetadata.Builder imBuilder = IndexMetadata.builder(builder.get(indexName)); + imBuilder.putAlias(AliasMetadata.builder(aliasName).writeIndex(true).build()); + builder.put(imBuilder); + Metadata metadata = builder.build(); + assertThat(previous.getIndicesLookup(), not(sameInstance(metadata.getIndicesLookup()))); + previous = metadata; + } + { + Metadata.Builder builder = Metadata.builder(previous); + IndexMetadata.Builder imBuilder = IndexMetadata.builder(builder.get(indexName)); + Settings.Builder sBuilder = Settings.builder() + .put(builder.get(indexName).getSettings()) + .put(IndexMetadata.INDEX_HIDDEN_SETTING.getKey(), true); + imBuilder.settings(sBuilder.build()); + builder.put(imBuilder); + Metadata metadata = builder.build(); + assertThat(previous.getIndicesLookup(), not(sameInstance(metadata.getIndicesLookup()))); + previous = metadata; + } + + // Things that shouldn't change indices lookup + { + Metadata.Builder builder = Metadata.builder(previous); + IndexMetadata.Builder imBuilder = IndexMetadata.builder(builder.get(indexName)); + imBuilder.numberOfReplicas(2); + builder.put(imBuilder); + Metadata metadata = builder.build(); + assertThat(previous.getIndicesLookup(), sameInstance(metadata.getIndicesLookup())); + previous = metadata; + } + { + Metadata.Builder builder = Metadata.builder(previous); + IndexMetadata.Builder imBuilder = IndexMetadata.builder(builder.get(indexName)); + Settings.Builder sBuilder = Settings.builder() + .put(builder.get(indexName).getSettings()) + .put(IndexSettings.DEFAULT_FIELD_SETTING.getKey(), "val"); + imBuilder.settings(sBuilder.build()); + builder.put(imBuilder); + Metadata metadata = builder.build(); + assertThat(previous.getIndicesLookup(), sameInstance(metadata.getIndicesLookup())); + previous = metadata; + } + } + public static Metadata randomMetadata() { return randomMetadata(1); } diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java index f6c79d25d42fa..769fa30c2cb90 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java @@ -625,8 +625,9 @@ public void testMoveShardToNonDataNode() { Index index = clusterState.getMetadata().index("test").getIndex(); MoveAllocationCommand command = new MoveAllocationCommand(index.getName(), 0, "node1", "node2"); + final RoutingNodes routingNodes = clusterState.mutableRoutingNodes(); RoutingAllocation routingAllocation = new RoutingAllocation(new AllocationDeciders(Collections.emptyList()), - new RoutingNodes(clusterState, false), clusterState, ClusterInfo.EMPTY, SnapshotShardSizeInfo.EMPTY, System.nanoTime()); + () -> routingNodes, clusterState, ClusterInfo.EMPTY, SnapshotShardSizeInfo.EMPTY, System.nanoTime()); logger.info("--> executing move allocation command to non-data node"); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> command.execute(routingAllocation, false)); assertEquals("[move_allocation] can't move [test][0] from " + node1 + " to " + @@ -664,8 +665,9 @@ public void testMoveShardFromNonDataNode() { Index index = clusterState.getMetadata().index("test").getIndex(); MoveAllocationCommand command = new MoveAllocationCommand(index.getName(), 0, "node2", "node1"); + final RoutingNodes routingNodes = clusterState.mutableRoutingNodes(); RoutingAllocation routingAllocation = new RoutingAllocation(new AllocationDeciders(Collections.emptyList()), - new RoutingNodes(clusterState, false), clusterState, ClusterInfo.EMPTY, SnapshotShardSizeInfo.EMPTY, System.nanoTime()); + () -> routingNodes, clusterState, ClusterInfo.EMPTY, SnapshotShardSizeInfo.EMPTY, System.nanoTime()); logger.info("--> executing move allocation command from non-data node"); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> command.execute(routingAllocation, false)); assertEquals("[move_allocation] can't move [test][0] from " + node2 + " to " + node1 + diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationServiceTests.java index a4138bc094195..a197a6e23a655 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationServiceTests.java @@ -237,7 +237,7 @@ public void testExplainsNonAllocationOfShardWithUnknownAllocator() { .build(); final RoutingAllocation allocation = new RoutingAllocation(new AllocationDeciders(Collections.emptyList()), - clusterState.getRoutingNodes(), clusterState, ClusterInfo.EMPTY, null,0L); + clusterState::getRoutingNodes, clusterState, ClusterInfo.EMPTY, null,0L); allocation.setDebugMode(randomBoolean() ? RoutingAllocation.DebugMode.ON : RoutingAllocation.DebugMode.EXCLUDE_YES_DECISIONS); final ShardAllocationDecision shardAllocationDecision diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AwarenessAllocationTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AwarenessAllocationTests.java index 4029dee316cff..8a376f5893976 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AwarenessAllocationTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AwarenessAllocationTests.java @@ -1013,7 +1013,7 @@ private void testExplanation( final RoutingAllocation routingAllocation = new RoutingAllocation( new AllocationDeciders(singletonList(decider)), - clusterState.getRoutingNodes(), + clusterState::getRoutingNodes, clusterState, null, null, diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/BalancedSingleShardTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/BalancedSingleShardTests.java index 6c275ab375626..2674929a759c1 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/BalancedSingleShardTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/BalancedSingleShardTests.java @@ -357,8 +357,9 @@ public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation alloca } private RoutingAllocation newRoutingAllocation(AllocationDeciders deciders, ClusterState state) { + final RoutingNodes routingNodes = state.mutableRoutingNodes(); RoutingAllocation allocation = new RoutingAllocation( - deciders, new RoutingNodes(state, false), state, ClusterInfo.EMPTY, SnapshotShardSizeInfo.EMPTY, System.nanoTime()); + deciders, () -> routingNodes, state, ClusterInfo.EMPTY, SnapshotShardSizeInfo.EMPTY, System.nanoTime()); allocation.debugDecision(true); return allocation; } diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/NodeVersionAllocationDeciderTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/NodeVersionAllocationDeciderTests.java index 2f504851df69f..19642a4489ed0 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/NodeVersionAllocationDeciderTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/NodeVersionAllocationDeciderTests.java @@ -467,7 +467,7 @@ public void testMessages() { final ShardRouting primaryShard = clusterState.routingTable().shardRoutingTable(shardId).primaryShard(); final ShardRouting replicaShard = clusterState.routingTable().shardRoutingTable(shardId).replicaShards().get(0); - RoutingAllocation routingAllocation = new RoutingAllocation(null, clusterState.getRoutingNodes(), clusterState, + RoutingAllocation routingAllocation = new RoutingAllocation(null, clusterState::getRoutingNodes, clusterState, null, null, 0); routingAllocation.debugDecision(true); @@ -509,11 +509,11 @@ public void testMessages() { newNode.node().getVersion() + "] is the same or newer than snapshot version [" + oldNode.node().getVersion() + "]")); final RoutingChangesObserver routingChangesObserver = new RoutingChangesObserver.AbstractRoutingChangesObserver(); - final RoutingNodes routingNodes = new RoutingNodes(clusterState, false); + final RoutingNodes routingNodes = clusterState.mutableRoutingNodes(); final ShardRouting startedPrimary = routingNodes.startShard(logger, routingNodes.initializeShard(primaryShard, "newNode", null, 0, routingChangesObserver), routingChangesObserver); - routingAllocation = new RoutingAllocation(null, routingNodes, clusterState, null, null,0); + routingAllocation = new RoutingAllocation(null, () -> routingNodes, clusterState, null, null,0); routingAllocation.debugDecision(true); decision = allocationDecider.canAllocate(replicaShard, oldNode, routingAllocation); @@ -523,7 +523,7 @@ public void testMessages() { routingNodes.startShard(logger, routingNodes.relocateShard(startedPrimary, "oldNode", 0, routingChangesObserver).v2(), routingChangesObserver); - routingAllocation = new RoutingAllocation(null, routingNodes, clusterState, null, null,0); + routingAllocation = new RoutingAllocation(null, () -> routingNodes, clusterState, null, null,0); routingAllocation.debugDecision(true); decision = allocationDecider.canAllocate(replicaShard, newNode, routingAllocation); diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/ResizeAllocationDeciderTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/ResizeAllocationDeciderTests.java index 9a13f1b808279..319187a103f6f 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/ResizeAllocationDeciderTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/ResizeAllocationDeciderTests.java @@ -147,7 +147,7 @@ public void testSourceNotActive() { ResizeAllocationDecider resizeAllocationDecider = new ResizeAllocationDecider(); - RoutingAllocation routingAllocation = new RoutingAllocation(null, clusterState.getRoutingNodes(), clusterState, null, null, 0); + RoutingAllocation routingAllocation = new RoutingAllocation(null, clusterState::getRoutingNodes, clusterState, null, null, 0); int shardId = randomIntBetween(0, 3); int sourceShardId = IndexMetadata.selectSplitShard(shardId, clusterState.metadata().index("source"), 4).id(); ShardRouting shardRouting = TestShardRouting.newShardRouting(new ShardId(idx, shardId), null, true, ShardRoutingState.UNASSIGNED, @@ -187,7 +187,7 @@ public void testSourcePrimaryActive() { ResizeAllocationDecider resizeAllocationDecider = new ResizeAllocationDecider(); - RoutingAllocation routingAllocation = new RoutingAllocation(null, clusterState.getRoutingNodes(), clusterState, null, null, 0); + RoutingAllocation routingAllocation = new RoutingAllocation(null, clusterState::getRoutingNodes, clusterState, null, null, 0); int shardId = randomIntBetween(0, 3); int sourceShardId = IndexMetadata.selectSplitShard(shardId, clusterState.metadata().index("source"), 4).id(); ShardRouting shardRouting = TestShardRouting.newShardRouting(new ShardId(idx, shardId), null, true, ShardRoutingState.UNASSIGNED, diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/SameShardRoutingTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/SameShardRoutingTests.java index 704b5e32bf2c2..b413b3bbb289f 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/SameShardRoutingTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/SameShardRoutingTests.java @@ -151,8 +151,9 @@ public void testForceAllocatePrimaryOnSameNodeNotAllowed() { Index index = clusterState.getMetadata().index("idx").getIndex(); ShardRouting primaryShard = clusterState.routingTable().index(index).shard(0).primaryShard(); RoutingNode routingNode = clusterState.getRoutingNodes().node(primaryShard.currentNodeId()); + final RoutingNodes routingNodes = clusterState.mutableRoutingNodes(); RoutingAllocation routingAllocation = new RoutingAllocation(new AllocationDeciders(Collections.emptyList()), - new RoutingNodes(clusterState, false), clusterState, ClusterInfo.EMPTY, SnapshotShardSizeInfo.EMPTY, System.nanoTime()); + () -> routingNodes, clusterState, ClusterInfo.EMPTY, SnapshotShardSizeInfo.EMPTY, System.nanoTime()); // can't force allocate same shard copy to the same node ShardRouting newPrimary = TestShardRouting.newShardRouting(primaryShard.shardId(), null, true, ShardRoutingState.UNASSIGNED); diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/ThrottlingAllocationTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/ThrottlingAllocationTests.java index 81e387473f694..c60d00558cf17 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/ThrottlingAllocationTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/ThrottlingAllocationTests.java @@ -334,7 +334,7 @@ private ClusterState createRecoveryStateAndInitializeAllocations( final TestSnapshotsInfoService snapshotsInfoService ) { DiscoveryNode node1 = newNode("node1"); - Metadata.Builder metadataBuilder = new Metadata.Builder(metadata); + Metadata.Builder metadataBuilder = Metadata.builder(metadata); RoutingTable.Builder routingTableBuilder = RoutingTable.builder(); Snapshot snapshot = new Snapshot("repo", new SnapshotId("snap", "randomId")); Set snapshotIndices = new HashSet<>(); diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/AllocationDecidersTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/AllocationDecidersTests.java index ddf9f647e18f6..3cf548d172944 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/AllocationDecidersTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/AllocationDecidersTests.java @@ -81,7 +81,7 @@ public Decision canRebalance(RoutingAllocation allocation) { ClusterState clusterState = ClusterState.builder(new ClusterName("test")).build(); final RoutingAllocation allocation = new RoutingAllocation(deciders, - clusterState.getRoutingNodes(), clusterState, null, null,0L); + clusterState::getRoutingNodes, clusterState, null, null,0L); allocation.setDebugMode(mode); final UnassignedInfo unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "_message"); @@ -211,7 +211,7 @@ private Decision decision(RoutingAllocation allocation) { IndexMetadata.builder("idx").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(0).build(); final RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, - clusterState.getRoutingNodes(), clusterState, null, null,0L); + clusterState::getRoutingNodes, clusterState, null, null,0L); assertSame(Decision.NO, allocationDeciders.canAllocate(shardRouting, routingNode, allocation)); assertSame(Decision.NO, allocationDeciders.canRebalance(shardRouting, allocation)); assertSame(Decision.NO, allocationDeciders.canRemain(shardRouting, routingNode, allocation)); diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java index c6bcf7807c7b5..b88775878c4fd 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java @@ -855,7 +855,7 @@ public void testCanRemainWithShardRelocatingAway() { ) ); ClusterState clusterState = ClusterState.builder(baseClusterState).routingTable(builder.build()).build(); - RoutingAllocation routingAllocation = new RoutingAllocation(null, new RoutingNodes(clusterState), clusterState, clusterInfo, + RoutingAllocation routingAllocation = new RoutingAllocation(null, clusterState::getRoutingNodes, clusterState, clusterInfo, null, System.nanoTime()); routingAllocation.debugDecision(true); Decision decision = diskThresholdDecider.canRemain(firstRouting, firstRoutingNode, routingAllocation); @@ -882,7 +882,7 @@ public void testCanRemainWithShardRelocatingAway() { ) ); clusterState = ClusterState.builder(baseClusterState).routingTable(builder.build()).build(); - routingAllocation = new RoutingAllocation(null, new RoutingNodes(clusterState), clusterState, clusterInfo, null, + routingAllocation = new RoutingAllocation(null, clusterState::getRoutingNodes, clusterState, clusterInfo, null, System.nanoTime()); routingAllocation.debugDecision(true); decision = diskThresholdDecider.canRemain(firstRouting, firstRoutingNode, routingAllocation); @@ -984,7 +984,7 @@ public void testForSingleDataNode() { ) ); ClusterState clusterState = ClusterState.builder(baseClusterState).routingTable(builder.build()).build(); - RoutingAllocation routingAllocation = new RoutingAllocation(null, new RoutingNodes(clusterState), clusterState, clusterInfo, + RoutingAllocation routingAllocation = new RoutingAllocation(null, clusterState::getRoutingNodes, clusterState, clusterInfo, null, System.nanoTime()); routingAllocation.debugDecision(true); Decision decision = diskThresholdDecider.canRemain(firstRouting, firstRoutingNode, routingAllocation); @@ -1038,7 +1038,7 @@ Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLU ); clusterState = ClusterState.builder(updateClusterState).routingTable(builder.build()).build(); - routingAllocation = new RoutingAllocation(null, new RoutingNodes(clusterState), clusterState, clusterInfo, null, + routingAllocation = new RoutingAllocation(null, clusterState::getRoutingNodes, clusterState, clusterInfo, null, System.nanoTime()); routingAllocation.debugDecision(true); decision = diskThresholdDecider.canRemain(firstRouting, firstRoutingNode, routingAllocation); @@ -1123,7 +1123,7 @@ Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLU ).build(); clusterState = ClusterState.builder(clusterState).routingTable(forceAssignedRoutingTable).build(); - RoutingAllocation routingAllocation = new RoutingAllocation(null, new RoutingNodes(clusterState), clusterState, clusterInfo, + RoutingAllocation routingAllocation = new RoutingAllocation(null, clusterState::getRoutingNodes, clusterState, clusterInfo, null, System.nanoTime()); routingAllocation.debugDecision(true); Decision decision = diskThresholdDecider.canRemain(startedShard, clusterState.getRoutingNodes().node("data"), routingAllocation); diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderUnitTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderUnitTests.java index 034a289f97ec6..d1ac2f30900f6 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderUnitTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderUnitTests.java @@ -95,7 +95,7 @@ public void testCanAllocateUsesMaxAvailableSpace() { final ClusterInfo clusterInfo = new ClusterInfo(leastAvailableUsages.build(), mostAvailableUsage.build(), shardSizes.build(), null, ImmutableOpenMap.of(), ImmutableOpenMap.of()); RoutingAllocation allocation = new RoutingAllocation(new AllocationDeciders(Collections.singleton(decider)), - clusterState.getRoutingNodes(), clusterState, clusterInfo, null, System.nanoTime()); + clusterState::getRoutingNodes, clusterState, clusterInfo, null, System.nanoTime()); allocation.debugDecision(true); Decision decision = decider.canAllocate(test_0, new RoutingNode("node_0", node_0), allocation); assertEquals(mostAvailableUsage.toString(), Decision.Type.YES, decision.type()); @@ -150,7 +150,7 @@ public void testCannotAllocateDueToLackOfDiskResources() { ClusterInfo clusterInfo = new ClusterInfo(leastAvailableUsages.build(), mostAvailableUsage.build(), shardSizes.build(), null, ImmutableOpenMap.of(), ImmutableOpenMap.of()); RoutingAllocation allocation = new RoutingAllocation(new AllocationDeciders(Collections.singleton(decider)), - clusterState.getRoutingNodes(), clusterState, clusterInfo, null, System.nanoTime()); + clusterState::getRoutingNodes, clusterState, clusterInfo, null, System.nanoTime()); allocation.debugDecision(true); Decision decision = decider.canAllocate(test_0, new RoutingNode("node_0", node_0), allocation); assertEquals(Decision.Type.NO, decision.type()); @@ -231,7 +231,7 @@ public void testCanRemainUsesLeastAvailableSpace() { final ClusterInfo clusterInfo = new ClusterInfo(leastAvailableUsages.build(), mostAvailableUsage.build(), shardSizes.build(), null, shardRoutingMap.build(), ImmutableOpenMap.of()); RoutingAllocation allocation = new RoutingAllocation(new AllocationDeciders(Collections.singleton(decider)), - clusterState.getRoutingNodes(), clusterState, clusterInfo, null, System.nanoTime()); + clusterState::getRoutingNodes, clusterState, clusterInfo, null, System.nanoTime()); allocation.debugDecision(true); Decision decision = decider.canRemain(test_0, new RoutingNode("node_0", node_0), allocation); assertEquals(Decision.Type.YES, decision.type()); @@ -384,7 +384,7 @@ public void testSizeShrinkIndex() { clusterState = startShardsAndReroute(allocationService, clusterState, clusterState.getRoutingTable().index("test").shardsWithState(ShardRoutingState.UNASSIGNED)); - RoutingAllocation allocation = new RoutingAllocation(null, clusterState.getRoutingNodes(), clusterState, info, null,0); + RoutingAllocation allocation = new RoutingAllocation(null, clusterState::getRoutingNodes, clusterState, info, null,0); final Index index = new Index("test", "1234"); ShardRouting test_0 = ShardRouting.newUnassigned(new ShardId(index, 0), true, @@ -429,7 +429,7 @@ public void testSizeShrinkIndex() { allocationService.reroute(clusterState, "foo"); RoutingAllocation allocationWithMissingSourceIndex = new RoutingAllocation(null, - clusterStateWithMissingSourceIndex.getRoutingNodes(), clusterStateWithMissingSourceIndex, info, null,0); + clusterStateWithMissingSourceIndex::getRoutingNodes, clusterStateWithMissingSourceIndex, info, null,0); assertEquals(42L, getExpectedShardSize(target, 42L, allocationWithMissingSourceIndex)); assertEquals(42L, getExpectedShardSize(target2, 42L, allocationWithMissingSourceIndex)); } @@ -512,7 +512,7 @@ public void testDecidesYesIfWatermarksIgnored() { final ClusterInfo clusterInfo = new ClusterInfo(usages, usages, shardSizes.build(), null, ImmutableOpenMap.of(), ImmutableOpenMap.of()); RoutingAllocation allocation = new RoutingAllocation(new AllocationDeciders(Collections.singleton(decider)), - clusterState.getRoutingNodes(), clusterState, clusterInfo, null, System.nanoTime()); + clusterState::getRoutingNodes, clusterState, clusterInfo, null, System.nanoTime()); allocation.debugDecision(true); final RoutingNode routingNode = new RoutingNode("node_0", node_0); Decision decision = decider.canAllocate(test_0, routingNode, allocation); @@ -566,7 +566,7 @@ public void testCannotForceAllocateOver100PercentUsage() { ClusterInfo clusterInfo = new ClusterInfo(leastAvailableUsages.build(), mostAvailableUsage.build(), shardSizes.build(), null, ImmutableOpenMap.of(), ImmutableOpenMap.of()); RoutingAllocation allocation = new RoutingAllocation(new AllocationDeciders(Collections.singleton(decider)), - clusterState.getRoutingNodes(), clusterState, clusterInfo, null, System.nanoTime()); + clusterState::getRoutingNodes, clusterState, clusterInfo, null, System.nanoTime()); allocation.debugDecision(true); Decision decision = decider.canForceAllocateDuringReplace(test_0, new RoutingNode("node_0", node_0), allocation); assertEquals(Decision.Type.NO, decision.type()); diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/FilterAllocationDeciderTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/FilterAllocationDeciderTests.java index 5ed2979e3af57..eb70e4cf85995 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/FilterAllocationDeciderTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/FilterAllocationDeciderTests.java @@ -31,6 +31,9 @@ import java.util.Arrays; import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_RESIZE_SOURCE_NAME; import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_RESIZE_SOURCE_UUID; @@ -40,6 +43,21 @@ public class FilterAllocationDeciderTests extends ESAllocationTestCase { + @Override + protected List filteredWarnings() { + return Stream.concat( + super.filteredWarnings().stream(), + Stream.of( + "[index.routing.allocation.include._tier] setting was deprecated in Elasticsearch " + + "and will be removed in a future release! See the breaking changes documentation for the next major version.", + "[index.routing.allocation.exclude._tier] setting was deprecated in Elasticsearch " + + "and will be removed in a future release! See the breaking changes documentation for the next major version.", + "[index.routing.allocation.require._tier] setting was deprecated in Elasticsearch " + + "and will be removed in a future release! See the breaking changes documentation for the next major version." + ) + ).collect(Collectors.toList()); + } + public void testFilterInitialRecovery() { ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); FilterAllocationDecider filterAllocationDecider = new FilterAllocationDecider(Settings.EMPTY, clusterSettings); @@ -63,7 +81,7 @@ public void testFilterInitialRecovery() { assertNull(routingTable.index("idx").shard(0).shards().get(0).currentNodeId()); // after failing the shard we are unassigned since the node is blacklisted and we can't initialize on the other node - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state.getRoutingNodes(), state, + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state::getRoutingNodes, state, null, null, 0); allocation.debugDecision(true); Decision.Single decision = (Decision.Single) filterAllocationDecider.canAllocate( @@ -114,7 +132,7 @@ public void testFilterInitialRecovery() { assertEquals(routingTable.index("idx").shard(0).primaryShard().state(), INITIALIZING); assertEquals(routingTable.index("idx").shard(0).primaryShard().currentNodeId(), "node1"); - allocation = new RoutingAllocation(allocationDeciders, state.getRoutingNodes(), state, + allocation = new RoutingAllocation(allocationDeciders,state::getRoutingNodes, state, null, null, 0); allocation.debugDecision(true); decision = (Decision.Single) filterAllocationDecider.canAllocate( @@ -151,10 +169,10 @@ public void testTierFilterIgnored() { .put("cluster.routing.allocation.exclude._tier", "data_cold") .build()); RoutingTable routingTable = state.routingTable(); - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state.getRoutingNodes(), state, + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state::getRoutingNodes, state, null, null, 0); allocation.debugDecision(true); - allocation = new RoutingAllocation(allocationDeciders, state.getRoutingNodes(), state, + allocation = new RoutingAllocation(allocationDeciders, state::getRoutingNodes, state, null, null, 0); allocation.debugDecision(true); Decision.Single decision = (Decision.Single) filterAllocationDecider.canAllocate( diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/NodeReplacementAllocationDeciderTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/NodeReplacementAllocationDeciderTests.java index b31e40e4dfaf6..d472e8dd76018 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/NodeReplacementAllocationDeciderTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/NodeReplacementAllocationDeciderTests.java @@ -89,7 +89,7 @@ public void testNoReplacements() { .build()) .build(); - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state.getRoutingNodes(), state, null, null, 0); + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state::getRoutingNodes, state, null, null, 0); DiscoveryNode node = randomFrom(NODE_A, NODE_B, NODE_C); RoutingNode routingNode = new RoutingNode(node.getId(), node, shard); allocation.debugDecision(true); @@ -111,7 +111,7 @@ public void testNoReplacements() { public void testCanForceAllocate() { ClusterState state = prepareState(service.reroute(ClusterState.EMPTY_STATE, "initial state"), NODE_A.getId(), NODE_B.getName()); - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state.getRoutingNodes(), state, null, null, 0); + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state::getRoutingNodes, state, null, null, 0); RoutingNode routingNode = new RoutingNode(NODE_A.getId(), NODE_A, shard); allocation.debugDecision(true); @@ -149,7 +149,7 @@ public void testCanForceAllocate() { public void testCannotRemainOnReplacedNode() { ClusterState state = prepareState(service.reroute(ClusterState.EMPTY_STATE, "initial state"), NODE_A.getId(), NODE_B.getName()); - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state.getRoutingNodes(), state, null, null, 0); + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state::getRoutingNodes, state, null, null, 0); RoutingNode routingNode = new RoutingNode(NODE_A.getId(), NODE_A, shard); allocation.debugDecision(true); @@ -175,7 +175,7 @@ public void testCannotRemainOnReplacedNode() { public void testCanAllocateToNeitherSourceNorTarget() { ClusterState state = prepareState(service.reroute(ClusterState.EMPTY_STATE, "initial state"), NODE_A.getId(), NODE_B.getName()); - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state.getRoutingNodes(), state, null, null, 0); + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state::getRoutingNodes, state, null, null, 0); RoutingNode routingNode = new RoutingNode(NODE_A.getId(), NODE_A, shard); allocation.debugDecision(true); diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/NodeShutdownAllocationDeciderTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/NodeShutdownAllocationDeciderTests.java index 0b224c690d0b1..5938a3a13b288 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/NodeShutdownAllocationDeciderTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/NodeShutdownAllocationDeciderTests.java @@ -81,7 +81,7 @@ public void testCanAllocateShardsToRestartingNode() { service.reroute(ClusterState.EMPTY_STATE, "initial state"), SingleNodeShutdownMetadata.Type.RESTART ); - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state.getRoutingNodes(), state, null, null, 0); + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state::getRoutingNodes, state, null, null, 0); RoutingNode routingNode = new RoutingNode(DATA_NODE.getId(), DATA_NODE, shard); allocation.debugDecision(true); @@ -99,7 +99,7 @@ public void testCannotAllocateShardsToRemovingNode() { service.reroute(ClusterState.EMPTY_STATE, "initial state"), randomFrom(SingleNodeShutdownMetadata.Type.REMOVE, SingleNodeShutdownMetadata.Type.REPLACE) ); - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state.getRoutingNodes(), state, null, null, 0); + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state::getRoutingNodes, state, null, null, 0); RoutingNode routingNode = new RoutingNode(DATA_NODE.getId(), DATA_NODE, shard); allocation.debugDecision(true); @@ -116,7 +116,7 @@ public void testShardsCanRemainOnRestartingNode() { service.reroute(ClusterState.EMPTY_STATE, "initial state"), SingleNodeShutdownMetadata.Type.RESTART ); - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state.getRoutingNodes(), state, null, null, 0); + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state::getRoutingNodes, state, null, null, 0); RoutingNode routingNode = new RoutingNode(DATA_NODE.getId(), DATA_NODE, shard); allocation.debugDecision(true); @@ -133,7 +133,7 @@ public void testShardsCannotRemainOnRemovingNode() { service.reroute(ClusterState.EMPTY_STATE, "initial state"), randomFrom(SingleNodeShutdownMetadata.Type.REMOVE, SingleNodeShutdownMetadata.Type.REPLACE) ); - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state.getRoutingNodes(), state, null, null, 0); + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state::getRoutingNodes, state, null, null, 0); RoutingNode routingNode = new RoutingNode(DATA_NODE.getId(), DATA_NODE, shard); allocation.debugDecision(true); @@ -150,7 +150,7 @@ public void testCannotAutoExpandToRestartingNode() { service.reroute(ClusterState.EMPTY_STATE, "initial state"), SingleNodeShutdownMetadata.Type.RESTART ); - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state.getRoutingNodes(), state, null, null, 0); + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state::getRoutingNodes, state, null, null, 0); allocation.debugDecision(true); Decision decision = decider.shouldAutoExpandToNode(indexMetadata, DATA_NODE, allocation); @@ -166,7 +166,7 @@ public void testCannotAutoExpandToRemovingNode() { service.reroute(ClusterState.EMPTY_STATE, "initial state"), randomFrom(SingleNodeShutdownMetadata.Type.REMOVE, SingleNodeShutdownMetadata.Type.REPLACE) ); - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state.getRoutingNodes(), state, null, null, 0); + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state::getRoutingNodes, state, null, null, 0); allocation.debugDecision(true); Decision decision = decider.shouldAutoExpandToNode(indexMetadata, DATA_NODE, allocation); diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/RestoreInProgressAllocationDeciderTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/RestoreInProgressAllocationDeciderTests.java index 59d58766fec80..e9505019f03f9 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/RestoreInProgressAllocationDeciderTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/RestoreInProgressAllocationDeciderTests.java @@ -189,7 +189,7 @@ private ClusterState createInitialClusterState() { private Decision executeAllocation(final ClusterState clusterState, final ShardRouting shardRouting) { final AllocationDecider decider = new RestoreInProgressAllocationDecider(); final RoutingAllocation allocation = new RoutingAllocation(new AllocationDeciders(Collections.singleton(decider)), - clusterState.getRoutingNodes(), clusterState, null, null, 0L); + clusterState::getRoutingNodes, clusterState, null, null, 0L); allocation.debugDecision(true); final Decision decision; diff --git a/server/src/test/java/org/elasticsearch/gateway/PrimaryShardAllocatorTests.java b/server/src/test/java/org/elasticsearch/gateway/PrimaryShardAllocatorTests.java index b4a4b9c981179..1a9b53288db10 100644 --- a/server/src/test/java/org/elasticsearch/gateway/PrimaryShardAllocatorTests.java +++ b/server/src/test/java/org/elasticsearch/gateway/PrimaryShardAllocatorTests.java @@ -417,7 +417,8 @@ private RoutingAllocation getRestoreRoutingAllocation(AllocationDeciders allocat .metadata(metadata) .routingTable(routingTable) .nodes(DiscoveryNodes.builder().add(node1).add(node2).add(node3)).build(); - return new RoutingAllocation(allocationDeciders, new RoutingNodes(state, false), state, null, + final RoutingNodes routingNodes = state.mutableRoutingNodes(); + return new RoutingAllocation(allocationDeciders, () -> routingNodes, state, null, new SnapshotShardSizeInfo(ImmutableOpenMap.of()) { @Override public Long getShardSize(ShardRouting shardRouting) { @@ -451,7 +452,8 @@ private RoutingAllocation routingAllocationWithOnePrimaryNoReplicas(AllocationDe .metadata(metadata) .routingTable(routingTableBuilder.build()) .nodes(DiscoveryNodes.builder().add(node1).add(node2).add(node3)).build(); - return new RoutingAllocation(deciders, new RoutingNodes(state, false), state, null, null, System.nanoTime()); + final RoutingNodes routingNodes = state.mutableRoutingNodes(); + return new RoutingAllocation(deciders, () -> routingNodes, state, null, null, System.nanoTime()); } private void assertClusterHealthStatus(RoutingAllocation allocation, ClusterHealthStatus expectedStatus) { diff --git a/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java b/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java index 405b8ccb70a8c..8e56af529d6d1 100644 --- a/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java +++ b/server/src/test/java/org/elasticsearch/gateway/ReplicaShardAllocatorTests.java @@ -479,7 +479,8 @@ private RoutingAllocation onePrimaryOnNode1And1Replica(AllocationDeciders decide .metadata(metadata) .routingTable(routingTable) .nodes(DiscoveryNodes.builder().add(node1).add(node2).add(node3)).build(); - return new RoutingAllocation(deciders, new RoutingNodes(state, false), state, ClusterInfo.EMPTY, SnapshotShardSizeInfo.EMPTY, + final RoutingNodes routingNodes = state.mutableRoutingNodes(); + return new RoutingAllocation(deciders, () -> routingNodes, state, ClusterInfo.EMPTY, SnapshotShardSizeInfo.EMPTY, System.nanoTime()); } @@ -503,7 +504,8 @@ private RoutingAllocation onePrimaryOnNode1And1ReplicaRecovering(AllocationDecid .metadata(metadata) .routingTable(routingTable) .nodes(DiscoveryNodes.builder().add(node1).add(node2).add(node3)).build(); - return new RoutingAllocation(deciders, new RoutingNodes(state, false), state, ClusterInfo.EMPTY, SnapshotShardSizeInfo.EMPTY, + final RoutingNodes routingNodes = state.mutableRoutingNodes(); + return new RoutingAllocation(deciders, () -> routingNodes, state, ClusterInfo.EMPTY, SnapshotShardSizeInfo.EMPTY, System.nanoTime()); } diff --git a/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/existence/FrozenExistenceDeciderIT.java b/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/existence/FrozenExistenceDeciderIT.java index 42bb29eff53fc..dc0a453b7f9fa 100644 --- a/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/existence/FrozenExistenceDeciderIT.java +++ b/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/existence/FrozenExistenceDeciderIT.java @@ -9,6 +9,7 @@ import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; import org.elasticsearch.cluster.health.ClusterHealthStatus; +import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.core.TimeValue; @@ -97,7 +98,7 @@ public void testZeroToOne() throws Exception { .put(indexSettings()) .put(SETTING_NUMBER_OF_SHARDS, 1) .put(SETTING_NUMBER_OF_REPLICAS, 1) - .put(LifecycleSettings.LIFECYCLE_NAME, "policy") + .put(IndexMetadata.LIFECYCLE_NAME, "policy") .build(); CreateIndexResponse res = client().admin().indices().prepareCreate(INDEX_NAME).setSettings(settings).get(); assertTrue(res.isAcknowledged()); diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/existence/FrozenExistenceDeciderService.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/existence/FrozenExistenceDeciderService.java index 21ac32dbaa8aa..74d675748d558 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/existence/FrozenExistenceDeciderService.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/existence/FrozenExistenceDeciderService.java @@ -14,12 +14,12 @@ import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeValue; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingCapacity; import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderContext; import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderResult; import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderService; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; import java.io.IOException; import java.util.Collections; diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderService.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderService.java index 5f8ae6acc5db2..4f6c81ac2b02e 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderService.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderService.java @@ -229,7 +229,7 @@ public static class AllocationState { public long storagePreventsAllocation() { RoutingAllocation allocation = new RoutingAllocation( allocationDeciders, - state.getRoutingNodes(), + state::getRoutingNodes, state, info, shardSizeInfo, @@ -245,7 +245,7 @@ public long storagePreventsAllocation() { public long storagePreventsRemainOrMove() { RoutingAllocation allocation = new RoutingAllocation( allocationDeciders, - state.getRoutingNodes(), + state::getRoutingNodes, state, info, shardSizeInfo, @@ -362,7 +362,7 @@ boolean needsThisTier(ShardRouting shard, RoutingAllocation allocation) { .map( node -> dataTierAllocationDecider.shouldFilter( indexMetadata, - node.node().getRoles(), + node.node().roleNames(), this::highestPreferenceTier, allocation ) @@ -392,7 +392,12 @@ boolean needsThisTier(ShardRouting shard, RoutingAllocation allocation) { private boolean isAssignedToTier(ShardRouting shard, RoutingAllocation allocation) { IndexMetadata indexMetadata = indexMetadata(shard, allocation); - return dataTierAllocationDecider.shouldFilter(indexMetadata, roles, this::highestPreferenceTier, allocation) != Decision.NO; + return dataTierAllocationDecider.shouldFilter( + indexMetadata, + roles.stream().map(DiscoveryNodeRole::roleName).collect(Collectors.toSet()), + this::highestPreferenceTier, + allocation + ) != Decision.NO; } private IndexMetadata indexMetadata(ShardRouting shard, RoutingAllocation allocation) { diff --git a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/existence/FrozenExistenceDeciderServiceTests.java b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/existence/FrozenExistenceDeciderServiceTests.java index f3854556d4921..88c1aff47a5d5 100644 --- a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/existence/FrozenExistenceDeciderServiceTests.java +++ b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/existence/FrozenExistenceDeciderServiceTests.java @@ -14,11 +14,11 @@ import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeValue; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.xpack.autoscaling.AutoscalingTestCase; import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingCapacity; import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderContext; import org.elasticsearch.xpack.autoscaling.capacity.AutoscalingDeciderResult; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; import java.util.function.Consumer; diff --git a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ProactiveStorageDeciderServiceTests.java b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ProactiveStorageDeciderServiceTests.java index 8fcbc30213827..288618dcc3a10 100644 --- a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ProactiveStorageDeciderServiceTests.java +++ b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ProactiveStorageDeciderServiceTests.java @@ -292,9 +292,10 @@ private long totalSize(List indices, RoutingTable routingTable, ClusterIn } private ClusterState randomAllocate(ClusterState state) { + final RoutingNodes routingNodes = state.mutableRoutingNodes(); RoutingAllocation allocation = new RoutingAllocation( new AllocationDeciders(org.elasticsearch.core.List.of()), - new RoutingNodes(state, false), + () -> routingNodes, state, null, null, @@ -323,9 +324,10 @@ private void randomAllocate(RoutingAllocation allocation) { } private ClusterState startAll(ClusterState state) { + final RoutingNodes routingNodes = state.mutableRoutingNodes(); RoutingAllocation allocation = new RoutingAllocation( new AllocationDeciders(org.elasticsearch.core.List.of()), - new RoutingNodes(state, false), + () -> routingNodes, state, null, null, diff --git a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderDecisionTests.java b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderDecisionTests.java index 058f3433d68b7..c1bf02292913b 100644 --- a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderDecisionTests.java +++ b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderDecisionTests.java @@ -301,8 +301,8 @@ private ClusterState moveToCold(Set candidates) { private IndexMetadata moveToCold(IndexMetadata imd) { Settings.Builder builder = Settings.builder().put(imd.getSettings()); - overrideSetting(imd, builder, DataTierAllocationDecider.INDEX_ROUTING_REQUIRE_SETTING, DataTier.DATA_COLD); - overrideSetting(imd, builder, DataTierAllocationDecider.INDEX_ROUTING_INCLUDE_SETTING, DataTier.DATA_COLD); + overrideSetting(imd, builder, IndexMetadata.INDEX_ROUTING_REQUIRE_SETTING, DataTier.DATA_COLD); + overrideSetting(imd, builder, IndexMetadata.INDEX_ROUTING_INCLUDE_SETTING, DataTier.DATA_COLD); overrideSetting( imd, builder, @@ -466,8 +466,8 @@ private static AllocationDeciders createAllocationDeciders(AllocationDecider... } private static RoutingAllocation createRoutingAllocation(ClusterState state, AllocationDeciders allocationDeciders) { - RoutingNodes routingNodes = new RoutingNodes(state, false); - return new RoutingAllocation(allocationDeciders, routingNodes, state, createClusterInfo(state), null, System.nanoTime()); + RoutingNodes routingNodes = state.mutableRoutingNodes(); + return new RoutingAllocation(allocationDeciders, () -> routingNodes, state, createClusterInfo(state), null, System.nanoTime()); } private void withRoutingAllocation(Consumer block) { @@ -620,8 +620,8 @@ public Long getShardSize(ShardRouting shardRouting) { private static ClusterState addRandomIndices(int minShards, int maxShardCopies, ClusterState state) { String[] tierSettingNames = new String[] { - DataTierAllocationDecider.INDEX_ROUTING_REQUIRE, - DataTierAllocationDecider.INDEX_ROUTING_INCLUDE, + IndexMetadata.INDEX_ROUTING_REQUIRE, + IndexMetadata.INDEX_ROUTING_INCLUDE, DataTier.TIER_PREFERENCE }; int shards = randomIntBetween(minShards, 20); Metadata.Builder builder = Metadata.builder(); diff --git a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderServiceTests.java b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderServiceTests.java index 35fdefc635b81..efa2c4ffb2f69 100644 --- a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderServiceTests.java +++ b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderServiceTests.java @@ -233,9 +233,10 @@ public void testSizeOf() { int shardId = randomInt(indexMetadata.getNumberOfShards() - 1); IndexShardRoutingTable subjectRoutings = initialClusterState.routingTable() .shardRoutingTable(indexMetadata.getIndex().getName(), shardId); + final RoutingNodes routingNodes = initialClusterState.mutableRoutingNodes(); RoutingAllocation allocation = new RoutingAllocation( new AllocationDeciders(org.elasticsearch.core.List.of()), - new RoutingNodes(initialClusterState, false), + () -> routingNodes, initialClusterState, null, null, @@ -541,7 +542,7 @@ public boolean canRemainWithNoNodes(ClusterState clusterState, ShardRouting shar RoutingAllocation allocation = new RoutingAllocation( allocationDeciders, - clusterState.getRoutingNodes(), + clusterState::getRoutingNodes, clusterState, null, null, @@ -656,7 +657,7 @@ private void verifyNeedsWarmTier( RoutingAllocation allocation = new RoutingAllocation( allocationDeciders, - clusterState.getRoutingNodes(), + clusterState::getRoutingNodes, clusterState, null, null, diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java index 51adb501ab285..ce231c13fd87d 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/AutoFollowCoordinator.java @@ -38,7 +38,6 @@ import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.license.LicenseUtils; -import org.elasticsearch.snapshots.SearchableSnapshotsSettings; import org.elasticsearch.transport.NoSuchRemoteClusterException; import org.elasticsearch.xpack.ccr.CcrLicenseChecker; import org.elasticsearch.xpack.ccr.CcrSettings; @@ -511,7 +510,8 @@ private void checkAutoFollowPattern(String autoFollowPattenName, new Tuple<>(indexToFollow, new ElasticsearchException("index to follow [" + indexToFollow.getName() + "] for pattern [" + autoFollowPattenName + "] matches with other patterns " + otherMatchingPatterns + ""))); } else { - final Settings leaderIndexSettings = remoteMetadata.getIndexSafe(indexToFollow).getSettings(); + final IndexMetadata remoteIndexMetadata = remoteMetadata.getIndexSafe(indexToFollow); + final Settings leaderIndexSettings = remoteIndexMetadata.getSettings(); if (IndexSettings.INDEX_SOFT_DELETES_SETTING.get(leaderIndexSettings) == false) { String message = String.format(Locale.ROOT, "index [%s] cannot be followed, because soft deletes are not enabled", indexToFollow.getName()); @@ -523,7 +523,7 @@ private void checkAutoFollowPattern(String autoFollowPattenName, } groupedListener.onResponse(new Tuple<>(indexToFollow, failure)); }); - } else if (SearchableSnapshotsSettings.isSearchableSnapshotStore(leaderIndexSettings)) { + } else if (remoteIndexMetadata.isSearchableSnapshotStore()) { String message = String.format(Locale.ROOT, "index to follow [%s] is a searchable snapshot index and cannot be used for cross-cluster replication purpose", indexToFollow.getName() diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java index a0587d308e41c..b3faf308ff16f 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportPutFollowAction.java @@ -35,7 +35,6 @@ import org.elasticsearch.license.LicenseUtils; import org.elasticsearch.snapshots.RestoreInfo; import org.elasticsearch.snapshots.RestoreService; -import org.elasticsearch.snapshots.SearchableSnapshotsSettings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.xpack.ccr.CcrLicenseChecker; @@ -129,7 +128,7 @@ private void createFollowerIndex( "] does not have soft deletes enabled")); return; } - if (SearchableSnapshotsSettings.isSearchableSnapshotStore(leaderIndexMetadata.getSettings())) { + if (leaderIndexMetadata.isSearchableSnapshotStore()) { listener.onFailure(new IllegalArgumentException("leader index [" + request.getLeaderIndex() + "] is a searchable snapshot index and cannot be used as a leader index for cross-cluster replication purpose")); return; diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportResumeFollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportResumeFollowAction.java index fc601137bb3f0..15685cc99ee04 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportResumeFollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportResumeFollowAction.java @@ -43,7 +43,6 @@ import org.elasticsearch.indices.IndicesService; import org.elasticsearch.license.LicenseUtils; import org.elasticsearch.persistent.PersistentTasksService; -import org.elasticsearch.snapshots.SearchableSnapshotsSettings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.xpack.ccr.CcrLicenseChecker; @@ -210,7 +209,7 @@ static void validate( throw new IllegalArgumentException("leader index [" + leaderIndex.getIndex().getName() + "] does not have soft deletes enabled"); } - if (SearchableSnapshotsSettings.isSearchableSnapshotStore(leaderIndex.getSettings())) { + if (leaderIndex.isSearchableSnapshotStore()) { throw new IllegalArgumentException("leader index [" + leaderIndex.getIndex().getName() + "] is a searchable snapshot index and cannot be used for cross-cluster replication purpose"); } @@ -218,7 +217,7 @@ static void validate( throw new IllegalArgumentException("follower index [" + request.getFollowerIndex() + "] does not have soft deletes enabled"); } - if (SearchableSnapshotsSettings.isSearchableSnapshotStore(followIndex.getSettings())) { + if (followIndex.isSearchableSnapshotStore()) { throw new IllegalArgumentException("follower index [" + request.getFollowerIndex() + "] is a searchable snapshot index and cannot be used for cross-cluster replication purpose"); } diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/allocation/CcrPrimaryFollowerAllocationDeciderTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/allocation/CcrPrimaryFollowerAllocationDeciderTests.java index 5fb43dea1fcf5..0c5de02f7dbe8 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/allocation/CcrPrimaryFollowerAllocationDeciderTests.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/allocation/CcrPrimaryFollowerAllocationDeciderTests.java @@ -21,7 +21,6 @@ import org.elasticsearch.cluster.routing.IndexShardRoutingTable; import org.elasticsearch.cluster.routing.RecoverySource; import org.elasticsearch.cluster.routing.RoutingNode; -import org.elasticsearch.cluster.routing.RoutingNodes; import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; @@ -181,7 +180,7 @@ static DiscoveryNode newNodeWithLegacyRoles(String id) { static Decision executeAllocation(ClusterState clusterState, ShardRouting shardRouting, DiscoveryNode node) { final AllocationDecider decider = new CcrPrimaryFollowerAllocationDecider(); final RoutingAllocation routingAllocation = new RoutingAllocation(new AllocationDeciders(Collections.singletonList(decider)), - new RoutingNodes(clusterState), clusterState, ClusterInfo.EMPTY, SnapshotShardSizeInfo.EMPTY, System.nanoTime()); + clusterState::getRoutingNodes, clusterState, ClusterInfo.EMPTY, SnapshotShardSizeInfo.EMPTY, System.nanoTime()); routingAllocation.debugDecision(true); return decider.canAllocate(shardRouting, new RoutingNode(node.getId(), node), routingAllocation); } diff --git a/x-pack/plugin/core/src/internalClusterTest/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDeciderIT.java b/x-pack/plugin/core/src/internalClusterTest/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDeciderIT.java index 3378fc88a1039..e3cce87f4c142 100644 --- a/x-pack/plugin/core/src/internalClusterTest/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDeciderIT.java +++ b/x-pack/plugin/core/src/internalClusterTest/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDeciderIT.java @@ -117,14 +117,14 @@ public void testRequestSettingOverridesAllocation() { client().admin().indices().prepareCreate(index) .setWaitForActiveShards(0) .setSettings(Settings.builder() - .put(DataTierAllocationDecider.INDEX_ROUTING_REQUIRE, DataTier.DATA_COLD)) + .put(IndexMetadata.INDEX_ROUTING_REQUIRE, DataTier.DATA_COLD)) .get(); idxSettings = client().admin().indices().prepareGetIndex().addIndices(index).get().getSettings().get(index); assertThat(DataTier.TIER_PREFERENCE_SETTING.get(idxSettings), equalTo("")); // The key should not be put in place since it was overridden assertFalse(idxSettings.keySet().contains(DataTierAllocationDecider.TIER_PREFERENCE)); - assertThat(DataTierAllocationDecider.INDEX_ROUTING_REQUIRE_SETTING.get(idxSettings), equalTo(DataTier.DATA_COLD)); + assertThat(IndexMetadata.INDEX_ROUTING_REQUIRE_SETTING.get(idxSettings), equalTo(DataTier.DATA_COLD)); // index should be yellow logger.info("--> waiting for {} to be yellow", index); @@ -193,7 +193,7 @@ public void testTemplateOverridesDefaults() { enforceDefaultTierPreference(false); Template t = new Template(Settings.builder() - .put(DataTierAllocationDecider.INDEX_ROUTING_REQUIRE, DataTier.DATA_WARM) + .put(IndexMetadata.INDEX_ROUTING_REQUIRE, DataTier.DATA_WARM) .build(), null, null); ComposableIndexTemplate ct = new ComposableIndexTemplate.Builder() .indexPatterns(Collections.singletonList(index)) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDecider.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDecider.java index 71428c6af6c7e..95808d637ac62 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDecider.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDecider.java @@ -39,9 +39,6 @@ public class DataTierAllocationDecider extends AllocationDecider { public static final String CLUSTER_ROUTING_REQUIRE = "cluster.routing.allocation.require._tier"; public static final String CLUSTER_ROUTING_INCLUDE = "cluster.routing.allocation.include._tier"; public static final String CLUSTER_ROUTING_EXCLUDE = "cluster.routing.allocation.exclude._tier"; - public static final String INDEX_ROUTING_REQUIRE = "index.routing.allocation.require._tier"; - public static final String INDEX_ROUTING_INCLUDE = "index.routing.allocation.include._tier"; - public static final String INDEX_ROUTING_EXCLUDE = "index.routing.allocation.exclude._tier"; public static final String TIER_PREFERENCE = "index.routing.allocation.include._tier_preference"; public static final Setting CLUSTER_ROUTING_REQUIRE_SETTING = Setting.simpleString(CLUSTER_ROUTING_REQUIRE, @@ -50,12 +47,6 @@ public class DataTierAllocationDecider extends AllocationDecider { DataTierAllocationDecider::validateTierSetting, Property.Dynamic, Property.NodeScope, Property.Deprecated); public static final Setting CLUSTER_ROUTING_EXCLUDE_SETTING = Setting.simpleString(CLUSTER_ROUTING_EXCLUDE, DataTierAllocationDecider::validateTierSetting, Property.Dynamic, Property.NodeScope, Property.Deprecated); - public static final Setting INDEX_ROUTING_REQUIRE_SETTING = Setting.simpleString(INDEX_ROUTING_REQUIRE, - DataTier.DATA_TIER_SETTING_VALIDATOR, Property.Dynamic, Property.IndexScope, Property.Deprecated); - public static final Setting INDEX_ROUTING_INCLUDE_SETTING = Setting.simpleString(INDEX_ROUTING_INCLUDE, - DataTier.DATA_TIER_SETTING_VALIDATOR, Property.Dynamic, Property.IndexScope, Property.Deprecated); - public static final Setting INDEX_ROUTING_EXCLUDE_SETTING = Setting.simpleString(INDEX_ROUTING_EXCLUDE, - DataTier.DATA_TIER_SETTING_VALIDATOR, Property.Dynamic, Property.IndexScope, Property.Deprecated); private static void validateTierSetting(String setting) { if (Strings.hasText(setting)) { @@ -88,7 +79,7 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing @Override public Decision canAllocate(IndexMetadata indexMetadata, RoutingNode node, RoutingAllocation allocation) { - return shouldFilter(indexMetadata, node.node().getRoles(), allocation); + return shouldFilter(indexMetadata, node.node().roleNames(), allocation); } @Override @@ -98,14 +89,14 @@ public Decision canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAl @Override public Decision shouldAutoExpandToNode(IndexMetadata indexMetadata, DiscoveryNode node, RoutingAllocation allocation) { - return shouldFilter(indexMetadata, node.getRoles(), allocation); + return shouldFilter(indexMetadata, node.roleNames(), allocation); } private Decision shouldFilter(ShardRouting shardRouting, DiscoveryNode node, RoutingAllocation allocation) { - return shouldFilter(allocation.metadata().getIndexSafe(shardRouting.index()), node.getRoles(), allocation); + return shouldFilter(allocation.metadata().getIndexSafe(shardRouting.index()), node.roleNames(), allocation); } - public Decision shouldFilter(IndexMetadata indexMd, Set roles, RoutingAllocation allocation) { + private Decision shouldFilter(IndexMetadata indexMd, Set roles, RoutingAllocation allocation) { return shouldFilter(indexMd, roles, DataTierAllocationDecider::preferredAvailableTier, allocation); } @@ -113,7 +104,7 @@ public interface PreferredTierFunction { Optional apply(List tierPreference, DiscoveryNodes nodes); } - public Decision shouldFilter(IndexMetadata indexMd, Set roles, + public Decision shouldFilter(IndexMetadata indexMd, Set roles, PreferredTierFunction preferredTierFunction, RoutingAllocation allocation) { Decision decision = shouldClusterFilter(roles, allocation); if (decision != null) { @@ -133,7 +124,7 @@ public Decision shouldFilter(IndexMetadata indexMd, Set roles return allocation.decision(Decision.YES, NAME, "node passes include/exclude/require/prefer tier filters"); } - private Decision shouldIndexPreferTier(IndexMetadata indexMetadata, Set roles, + private Decision shouldIndexPreferTier(IndexMetadata indexMetadata, Set roles, PreferredTierFunction preferredTierFunction, RoutingAllocation allocation) { List tierPreference = indexMetadata.getTierPreference(); @@ -170,34 +161,33 @@ private Decision shouldIndexPreferTier(IndexMetadata indexMetadata, Set roles, RoutingAllocation allocation) { - Settings indexSettings = indexMd.getSettings(); - String indexRequire = INDEX_ROUTING_REQUIRE_SETTING.get(indexSettings); - String indexInclude = INDEX_ROUTING_INCLUDE_SETTING.get(indexSettings); - String indexExclude = INDEX_ROUTING_EXCLUDE_SETTING.get(indexSettings); + private Decision shouldIndexFilter(IndexMetadata indexMd, Set roles, RoutingAllocation allocation) { + String indexRequire = indexMd.getIndexRoutingInclude(); + String indexInclude = indexMd.getIndexRoutingInclude(); + String indexExclude = indexMd.getIndexRoutingExclude(); if (Strings.hasText(indexRequire)) { if (allocationAllowed(OpType.AND, indexRequire, roles) == false) { return allocation.decision(Decision.NO, NAME, "node does not match all index setting [%s] tier filters [%s]", - INDEX_ROUTING_REQUIRE, indexRequire); + IndexMetadata.INDEX_ROUTING_REQUIRE, indexRequire); } } if (Strings.hasText(indexInclude)) { if (allocationAllowed(OpType.OR, indexInclude, roles) == false) { return allocation.decision(Decision.NO, NAME, "node does not match any index setting [%s] tier filters [%s]", - INDEX_ROUTING_INCLUDE, indexInclude); + IndexMetadata.INDEX_ROUTING_INCLUDE, indexInclude); } } if (Strings.hasText(indexExclude)) { if (allocationAllowed(OpType.OR, indexExclude, roles)) { return allocation.decision(Decision.NO, NAME, "node matches any index setting [%s] tier filters [%s]", - INDEX_ROUTING_EXCLUDE, indexExclude); + IndexMetadata.INDEX_ROUTING_EXCLUDE, indexExclude); } } return null; } - private Decision shouldClusterFilter(Set roles, RoutingAllocation allocation) { + private Decision shouldClusterFilter(Set roles, RoutingAllocation allocation) { if (Strings.hasText(clusterRequire)) { if (allocationAllowed(OpType.AND, clusterRequire, roles) == false) { return allocation.decision(Decision.NO, NAME, "node does not match all cluster setting [%s] tier filters [%s]", @@ -231,8 +221,12 @@ private enum OpType { * {@code Optional}. */ public static Optional preferredAvailableTier(List prioritizedTiers, DiscoveryNodes nodes) { + final Set availableRoles = nodes.availableRoleNames(); + if (prioritizedTiers.isEmpty() == false && availableRoles.contains(DiscoveryNodeRole.DATA_ROLE.roleName()) ) { + return Optional.of(prioritizedTiers.get(0)); + } for (String tier : prioritizedTiers) { - if (tierNodesPresent(tier, nodes)) { + if (availableRoles.contains(tier)) { return Optional.of(tier); } } @@ -242,34 +236,21 @@ public static Optional preferredAvailableTier(List prioritizedTi static boolean tierNodesPresent(String singleTier, DiscoveryNodes nodes) { assert singleTier.equals(DiscoveryNodeRole.DATA_ROLE.roleName()) || DataTier.validTierName(singleTier) : "tier " + singleTier + " is an invalid tier name"; - for (DiscoveryNode node : nodes.getNodes().values()) { - for (DiscoveryNodeRole discoveryNodeRole : node.getRoles()) { - String s = discoveryNodeRole.roleName(); - if (s.equals(DiscoveryNodeRole.DATA_ROLE.roleName()) || s.equals(singleTier)) { - return true; - } - } - } - return false; + final Set availableRoleNames = nodes.availableRoleNames(); + return availableRoleNames.contains(DiscoveryNodeRole.DATA_ROLE.roleName()) || availableRoleNames.contains(singleTier); } - private static boolean allocationAllowed(OpType opType, String tierSetting, Set roles) { + private static boolean allocationAllowed(OpType opType, String tierSetting, Set roles) { assert Strings.hasText(tierSetting) : "tierName must be not null and non-empty, but was [" + tierSetting + "]"; - if (roles.contains(DiscoveryNodeRole.DATA_ROLE)) { + if (roles.contains(DiscoveryNodeRole.DATA_ROLE.roleName())) { // generic "data" roles are considered to have all tiers return true; } List values = DataTier.parseTierList(tierSetting); for (String tierName : values) { - boolean containsName = false; - for (DiscoveryNodeRole role : roles) { - if (tierName.equals(role.roleName())) { - containsName = true; - break; - } - } + boolean containsName = roles.contains(tierName); if (containsName) { if (opType == OpType.OR) { return true; @@ -281,19 +262,14 @@ private static boolean allocationAllowed(OpType opType, String tierSetting, Set< return opType == OpType.AND; } - private static boolean allocationAllowed(String tierName, Set roles) { + private static boolean allocationAllowed(String tierName, Set roles) { assert Strings.hasText(tierName) : "tierName must be not null and non-empty, but was [" + tierName + "]"; - if (roles.contains(DiscoveryNodeRole.DATA_ROLE)) { + if (roles.contains(DiscoveryNodeRole.DATA_ROLE.roleName())) { // generic "data" roles are considered to have all tiers return true; } else { - for (DiscoveryNodeRole role : roles) { - if (tierName.equals(role.roleName())) { - return true; - } - } - return false; + return roles.contains(tierName); } } } 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 e37be2cda35ae..ebb013b819815 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 @@ -16,6 +16,7 @@ import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -432,9 +433,9 @@ public List> getSettings() { settings.add(DataTierAllocationDecider.CLUSTER_ROUTING_REQUIRE_SETTING); settings.add(DataTierAllocationDecider.CLUSTER_ROUTING_INCLUDE_SETTING); settings.add(DataTierAllocationDecider.CLUSTER_ROUTING_EXCLUDE_SETTING); - settings.add(DataTierAllocationDecider.INDEX_ROUTING_REQUIRE_SETTING); - settings.add(DataTierAllocationDecider.INDEX_ROUTING_INCLUDE_SETTING); - settings.add(DataTierAllocationDecider.INDEX_ROUTING_EXCLUDE_SETTING); + settings.add(IndexMetadata.INDEX_ROUTING_REQUIRE_SETTING); + settings.add(IndexMetadata.INDEX_ROUTING_INCLUDE_SETTING); + settings.add(IndexMetadata.INDEX_ROUTING_EXCLUDE_SETTING); return settings; } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocateAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocateAction.java index 249d346c522f8..819fd6f1a8521 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocateAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocateAction.java @@ -10,6 +10,7 @@ import org.elasticsearch.client.Client; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; @@ -18,7 +19,7 @@ import org.elasticsearch.xcontent.ConstructingObjectParser; import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentParser; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.io.IOException; import java.util.Arrays; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocationRoutedStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocationRoutedStep.java index aed74be430ba4..8690dd0a8af2a 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocationRoutedStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocationRoutedStep.java @@ -77,7 +77,7 @@ public Result isConditionMet(Index index, ClusterState clusterState) { static int getPendingAllocations(Index index, AllocationDeciders allocationDeciders, ClusterState clusterState) { // All the allocation attributes are already set so just need to check // if the allocation has happened - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, clusterState.getRoutingNodes(), clusterState, null, + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, clusterState::getRoutingNodes, clusterState, null, null, System.nanoTime()); int allocationPendingAllShards = 0; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AsyncActionStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AsyncActionStep.java index e0b69cb28954b..83baa269f7bac 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AsyncActionStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AsyncActionStep.java @@ -11,6 +11,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterStateObserver; import org.elasticsearch.cluster.metadata.IndexMetadata; +import org.elasticsearch.index.Step; /** * Performs an action which must be performed asynchronously because it may take time to complete. diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AsyncWaitStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AsyncWaitStep.java index 658335aef1224..9b68cb9d25641 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AsyncWaitStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AsyncWaitStep.java @@ -9,6 +9,7 @@ import org.elasticsearch.client.Client; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.core.TimeValue; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.ToXContentObject; import org.elasticsearch.index.Index; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CheckNotDataStreamWriteIndexStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CheckNotDataStreamWriteIndexStep.java index 54150d327134d..8d5d6dd02a8ee 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CheckNotDataStreamWriteIndexStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CheckNotDataStreamWriteIndexStep.java @@ -56,7 +56,7 @@ public Result isConditionMet(Index index, ClusterState clusterState) { return new Result(false, new Info(errorMessage)); } - String policyName = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + String policyName = indexMetadata.getSettings().get(IndexMetadata.LIFECYCLE_NAME); IndexAbstraction indexAbstraction = clusterState.metadata().getIndicesLookup().get(indexName); assert indexAbstraction != null : "invalid cluster metadata. index [" + indexName + "] was not found"; IndexAbstraction.DataStream dataStream = indexAbstraction.getParentDataStream(); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CheckTargetShardsCountStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CheckTargetShardsCountStep.java index 8f463918d739e..98e56ab47b2c2 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CheckTargetShardsCountStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CheckTargetShardsCountStep.java @@ -53,7 +53,7 @@ public Result isConditionMet(Index index, ClusterState clusterState) { if (numberOfShards != null) { int sourceNumberOfShards = indexMetadata.getNumberOfShards(); if (sourceNumberOfShards % numberOfShards != 0) { - String policyName = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + String policyName = indexMetadata.getSettings().get(IndexMetadata.LIFECYCLE_NAME); String errorMessage = String.format(Locale.ROOT, "lifecycle action of policy [%s] for index [%s] cannot make progress " + "because the target shards count [%d] must be a factor of the source index's shards count [%d]", policyName, indexName, numberOfShards, sourceNumberOfShards); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CleanupShrinkIndexStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CleanupShrinkIndexStep.java index 99b9a17f142c7..04982008c2dbb 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CleanupShrinkIndexStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CleanupShrinkIndexStep.java @@ -17,8 +17,9 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.core.TimeValue; import org.elasticsearch.index.IndexNotFoundException; +import org.elasticsearch.index.LifecycleExecutionState; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.fromIndexMetadata; +import static org.elasticsearch.index.LifecycleExecutionState.fromIndexMetadata; /** * Deletes the index identified by the shrink index name stored in the lifecycle state of the managed index (if any was generated) @@ -44,7 +45,7 @@ void performDuringNoSnapshot(IndexMetadata indexMetadata, ClusterState currentCl if (currentClusterState.metadata().index(shrunkenIndexSource) == null) { // if the source index does not exist, we'll skip deleting the // (managed) shrunk index as that will cause data loss - String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()); + String policyName = indexMetadata.getLifecycleName(); logger.warn("managed index [{}] as part of policy [{}] is a shrunk index and the source index [{}] does not exist " + "anymore. will skip the [{}] step", indexMetadata.getIndex().getName(), policyName, shrunkenIndexSource, NAME); listener.onResponse(null); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CleanupSnapshotStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CleanupSnapshotStep.java index ec014e8a21c65..9774309a978f0 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CleanupSnapshotStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CleanupSnapshotStep.java @@ -14,10 +14,11 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.common.Strings; import org.elasticsearch.core.TimeValue; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.repositories.RepositoryMissingException; import org.elasticsearch.snapshots.SnapshotMissingException; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.fromIndexMetadata; +import static org.elasticsearch.index.LifecycleExecutionState.fromIndexMetadata; /** * Deletes the snapshot designated by the repository and snapshot name present in the lifecycle execution state. @@ -56,7 +57,7 @@ void performDuringNoSnapshot(IndexMetadata indexMetadata, ClusterState currentCl @Override public void onResponse(AcknowledgedResponse acknowledgedResponse) { if (acknowledgedResponse.isAcknowledged() == false) { - String policyName = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + String policyName = indexMetadata.getSettings().get(IndexMetadata.LIFECYCLE_NAME); throw new ElasticsearchException("cleanup snapshot step request for repository [" + repositoryName + "] and snapshot " + "[" + snapshotName + "] policy [" + policyName + "] and index [" + indexName + "] failed to be acknowledged"); } @@ -70,7 +71,7 @@ public void onFailure(Exception e) { listener.onResponse(null); } else { if (e instanceof RepositoryMissingException) { - String policyName = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + String policyName = indexMetadata.getSettings().get(IndexMetadata.LIFECYCLE_NAME); listener.onFailure(new IllegalStateException("repository [" + repositoryName + "] is missing. [" + policyName + "] policy for index [" + indexName + "] cannot continue until the repository is created", e)); } else { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ClusterStateActionStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ClusterStateActionStep.java index f0507a92fc33a..fc488fe88e3cf 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ClusterStateActionStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ClusterStateActionStep.java @@ -8,6 +8,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.index.Index; +import org.elasticsearch.index.Step; /** * Updates the cluster state, similar to {@link org.elasticsearch.cluster.ClusterStateUpdateTask}. diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ClusterStateWaitStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ClusterStateWaitStep.java index 36b37c73fe19e..6e110d05f869a 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ClusterStateWaitStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ClusterStateWaitStep.java @@ -7,6 +7,7 @@ package org.elasticsearch.xpack.core.ilm; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.ToXContentObject; import org.elasticsearch.index.Index; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ClusterStateWaitUntilThresholdStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ClusterStateWaitUntilThresholdStep.java index cfb0f09423c68..7d5d08afa7539 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ClusterStateWaitUntilThresholdStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ClusterStateWaitUntilThresholdStep.java @@ -15,6 +15,7 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.core.TimeValue; import org.elasticsearch.index.Index; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.xpack.core.ilm.step.info.SingleMessageFieldInfo; import java.time.Clock; @@ -22,7 +23,7 @@ import java.util.Objects; import java.util.concurrent.atomic.AtomicBoolean; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.fromIndexMetadata; +import static org.elasticsearch.index.LifecycleExecutionState.fromIndexMetadata; /** * This step wraps an {@link ClusterStateWaitStep} in order to be able to manipulate what the next step will be, depending on the result of diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CopyExecutionStateStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CopyExecutionStateStep.java index 25a9290a4d469..457b177de7580 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CopyExecutionStateStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CopyExecutionStateStep.java @@ -13,16 +13,18 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.index.Index; +import org.elasticsearch.index.LifecycleExecutionState; +import org.elasticsearch.index.Step; import java.util.Objects; import java.util.function.BiFunction; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; +import static org.elasticsearch.index.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; /** * Copies the execution state data from one index to another, typically after a * new index has been created. As part of the execution state copy it will set the target index - * "current step" to the provided target next step {@link org.elasticsearch.xpack.core.ilm.Step.StepKey}. + * "current step" to the provided target next step {@link Step.StepKey}. * * Useful for actions such as shrink. */ diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CreateSnapshotStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CreateSnapshotStep.java index b8797912b5dfd..2c610ba9dcfe1 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CreateSnapshotStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CreateSnapshotStep.java @@ -16,12 +16,13 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.common.Strings; import org.elasticsearch.core.TimeValue; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.snapshots.SnapshotInfo; import java.util.Locale; import java.util.Objects; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.fromIndexMetadata; +import static org.elasticsearch.index.LifecycleExecutionState.fromIndexMetadata; /** * Creates a snapshot of the managed index into the configured repository and snapshot name. The repository and snapshot names are expected @@ -72,7 +73,7 @@ void createSnapshot(IndexMetadata indexMetadata, ActionListener listene final LifecycleExecutionState lifecycleState = fromIndexMetadata(indexMetadata); - final String policyName = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + final String policyName = indexMetadata.getSettings().get(IndexMetadata.LIFECYCLE_NAME); final String snapshotRepository = lifecycleState.getSnapshotRepository(); if (Strings.hasText(snapshotRepository) == false) { listener.onFailure(new IllegalStateException("snapshot repository is not present for policy [" + policyName + "] and index [" + diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/DeleteAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/DeleteAction.java index 77f69f6fb1ee0..ecbce16f5a532 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/DeleteAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/DeleteAction.java @@ -8,6 +8,7 @@ import org.elasticsearch.Version; import org.elasticsearch.client.Client; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/DeleteStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/DeleteStep.java index 93ea45b57bffe..cd70439188ada 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/DeleteStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/DeleteStep.java @@ -32,7 +32,7 @@ public DeleteStep(StepKey key, StepKey nextStepKey, Client client) { @Override public void performDuringNoSnapshot(IndexMetadata indexMetadata, ClusterState currentState, ActionListener listener) { - String policyName = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + String policyName = indexMetadata.getSettings().get(IndexMetadata.LIFECYCLE_NAME); String indexName = indexMetadata.getIndex().getName(); IndexAbstraction indexAbstraction = currentState.metadata().getIndicesLookup().get(indexName); assert indexAbstraction != null : "invalid cluster metadata. index [" + indexName + "] was not found"; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ErrorStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ErrorStep.java index ce843d2e31967..bd744949bf821 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ErrorStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ErrorStep.java @@ -6,6 +6,8 @@ */ package org.elasticsearch.xpack.core.ilm; +import org.elasticsearch.index.Step; + /** * Signals that an error was encountered during the execution of a policy on an index. */ diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ForceMergeAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ForceMergeAction.java index 0b05c721bdeeb..e9e955d15532f 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ForceMergeAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ForceMergeAction.java @@ -13,6 +13,7 @@ import org.elasticsearch.cluster.health.ClusterHealthStatus; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.core.Nullable; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; @@ -23,7 +24,7 @@ import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.index.codec.CodecService; import org.elasticsearch.index.engine.EngineConfig; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.io.IOException; import java.util.ArrayList; @@ -144,7 +145,7 @@ public List toSteps(Client client, String phase, Step.StepKey nextStepKey) IndexMetadata indexMetadata = clusterState.metadata().index(index); assert indexMetadata != null : "index " + index.getName() + " must exist in the cluster state"; if (indexMetadata.getSettings().get(LifecycleSettings.SNAPSHOT_INDEX_NAME) != null) { - String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()); + String policyName = indexMetadata.getLifecycleName(); logger.warn("[{}] action is configured for index [{}] in policy [{}] which is mounted as searchable snapshot. " + "Skipping this action", ForceMergeAction.NAME, index.getName(), policyName); return true; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ForceMergeStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ForceMergeStep.java index ca31cc8f6dd87..189ac8f57dfc8 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ForceMergeStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ForceMergeStep.java @@ -59,7 +59,7 @@ public void performAction(IndexMetadata indexMetadata, ClusterState currentState listener.onResponse(null); } else { DefaultShardOperationFailedException[] failures = response.getShardFailures(); - String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()); + String policyName = indexMetadata.getLifecycleName(); String errorMessage = String.format(Locale.ROOT, "index [%s] in policy [%s] encountered failures [%s] on step [%s]", indexName, policyName, diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/FreezeAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/FreezeAction.java index f5bc8b8d6fb24..c2fe52f56f8cd 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/FreezeAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/FreezeAction.java @@ -13,10 +13,11 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.ObjectParser; import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentParser; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.io.IOException; import java.util.Arrays; @@ -74,7 +75,7 @@ public List toSteps(Client client, String phase, StepKey nextStepKey) { (index, clusterState) -> { IndexMetadata indexMetadata = clusterState.getMetadata().index(index); assert indexMetadata != null : "index " + index.getName() + " must exist in the cluster state"; - String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()); + String policyName = indexMetadata.getLifecycleName(); if (indexMetadata.getSettings().get(LifecycleSettings.SNAPSHOT_INDEX_NAME) != null) { logger.warn("[{}] action is configured for index [{}] in policy [{}] which is mounted as searchable snapshot. " + "Skipping this action", FreezeAction.NAME, index.getName(), policyName); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/GenerateSnapshotNameStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/GenerateSnapshotNameStep.java index 47492df01b123..d9f8abe2fa036 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/GenerateSnapshotNameStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/GenerateSnapshotNameStep.java @@ -18,14 +18,15 @@ import org.elasticsearch.common.UUIDs; import org.elasticsearch.core.Nullable; import org.elasticsearch.index.Index; +import org.elasticsearch.index.LifecycleExecutionState; import java.util.Collections; import java.util.List; import java.util.Locale; import java.util.Objects; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.fromIndexMetadata; +import static org.elasticsearch.index.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; +import static org.elasticsearch.index.LifecycleExecutionState.fromIndexMetadata; /** * Generates a snapshot name for the given index and records it in the index metadata along with the provided snapshot repository. @@ -62,7 +63,7 @@ public ClusterState performAction(Index index, ClusterState clusterState) { return clusterState; } - String policy = indexMetaData.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + String policy = indexMetaData.getSettings().get(IndexMetadata.LIFECYCLE_NAME); LifecycleExecutionState lifecycleState = fromIndexMetadata(indexMetaData); // validate that the snapshot repository exists -- because policies are refreshed on later retries, and because diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/GenerateUniqueIndexNameStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/GenerateUniqueIndexNameStep.java index 216cdee02efb6..f2bf1e3081f92 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/GenerateUniqueIndexNameStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/GenerateUniqueIndexNameStep.java @@ -16,16 +16,17 @@ import org.elasticsearch.core.Nullable; import org.elasticsearch.common.UUIDs; import org.elasticsearch.index.Index; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.indices.InvalidIndexNameException; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.Builder; +import org.elasticsearch.index.LifecycleExecutionState.Builder; import java.util.Locale; import java.util.Objects; import java.util.function.BiFunction; import java.util.function.Supplier; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.fromIndexMetadata; +import static org.elasticsearch.index.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; +import static org.elasticsearch.index.LifecycleExecutionState.fromIndexMetadata; /** * Generates a unique index name prefixing the original index name with the configured @@ -78,7 +79,7 @@ public ClusterState performAction(Index index, ClusterState clusterState) { LifecycleExecutionState lifecycleState = fromIndexMetadata(indexMetadata); Builder newCustomData = LifecycleExecutionState.builder(lifecycleState); - String policy = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + String policy = indexMetadata.getSettings().get(IndexMetadata.LIFECYCLE_NAME); String generatedIndexName = generateValidIndexName(prefix, index.getName()); ActionRequestValidationException validationException = validateGeneratedIndexName(generatedIndexName, clusterState); if (validationException != null) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/InitializePolicyContextStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/InitializePolicyContextStep.java index d541106dae5d0..4be6168057926 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/InitializePolicyContextStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/InitializePolicyContextStep.java @@ -13,10 +13,12 @@ import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; +import org.elasticsearch.index.LifecycleExecutionState; +import org.elasticsearch.index.Step; import static org.elasticsearch.xpack.core.ilm.IndexLifecycleOriginationDateParser.parseIndexNameAndExtractDate; import static org.elasticsearch.xpack.core.ilm.IndexLifecycleOriginationDateParser.shouldParseIndexName; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; +import static org.elasticsearch.index.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; /** * Initializes the {@link LifecycleExecutionState} for an index. This should be the first Step called on an index. @@ -57,7 +59,7 @@ public ClusterState performAction(Index index, ClusterState clusterState) { ); } } catch (Exception e) { - String policy = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + String policy = indexMetadata.getSettings().get(IndexMetadata.LIFECYCLE_NAME); throw new InitializePolicyException(policy, index.getName(), e); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecycleAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecycleAction.java index 35d26fa36eb15..20c12fb22ba93 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecycleAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecycleAction.java @@ -9,6 +9,7 @@ import org.elasticsearch.client.Client; import org.elasticsearch.core.Nullable; import org.elasticsearch.common.io.stream.NamedWriteable; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.ToXContentObject; import org.elasticsearch.license.XPackLicenseState; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicy.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicy.java index 3adcf368a8671..5160346d27d0c 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicy.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicy.java @@ -11,6 +11,7 @@ import org.elasticsearch.cluster.AbstractDiffable; import org.elasticsearch.cluster.Diffable; import org.elasticsearch.core.Nullable; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; @@ -20,7 +21,7 @@ import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.license.XPackLicenseState; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.io.IOException; import java.nio.charset.StandardCharsets; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyUtils.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyUtils.java index e867288874802..31ca6a7d5d8a9 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyUtils.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyUtils.java @@ -10,6 +10,7 @@ import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.ItemUsage; import org.elasticsearch.cluster.metadata.MetadataIndexTemplateService; @@ -92,7 +93,7 @@ private static void validate(BytesReference source) { public static ItemUsage calculateUsage(final IndexNameExpressionResolver indexNameExpressionResolver, final ClusterState state, final String policyName) { final List indices = state.metadata().indices().values().stream() - .filter(indexMetadata -> policyName.equals(LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()))) + .filter(indexMetadata -> policyName.equals(indexMetadata.getLifecycleName())) .map(indexMetadata -> indexMetadata.getIndex().getName()) .collect(Collectors.toList()); @@ -104,7 +105,7 @@ public static ItemUsage calculateUsage(final IndexNameExpressionResolver indexNa String indexTemplate = MetadataIndexTemplateService.findV2Template(state.metadata(), dsName, false); if (indexTemplate != null) { Settings settings = MetadataIndexTemplateService.resolveSettings(state.metadata(), indexTemplate); - return policyName.equals(LifecycleSettings.LIFECYCLE_NAME_SETTING.get(settings)); + return policyName.equals(IndexMetadata.LIFECYCLE_NAME_SETTING.get(settings)); } else { return false; } @@ -114,7 +115,7 @@ public static ItemUsage calculateUsage(final IndexNameExpressionResolver indexNa final List composableTemplates = state.metadata().templatesV2().keySet().stream() .filter(templateName -> { Settings settings = MetadataIndexTemplateService.resolveSettings(state.metadata(), templateName); - return policyName.equals(LifecycleSettings.LIFECYCLE_NAME_SETTING.get(settings)); + return policyName.equals(IndexMetadata.LIFECYCLE_NAME_SETTING.get(settings)); }) .collect(Collectors.toList()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecycleSettings.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecycleSettings.java index f25fa7f1aa650..9b7bb2b2f8946 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecycleSettings.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecycleSettings.java @@ -18,7 +18,6 @@ */ public class LifecycleSettings { public static final String LIFECYCLE_POLL_INTERVAL = "indices.lifecycle.poll_interval"; - public static final String LIFECYCLE_NAME = "index.lifecycle.name"; public static final String LIFECYCLE_INDEXING_COMPLETE = "index.lifecycle.indexing_complete"; public static final String LIFECYCLE_ORIGINATION_DATE = "index.lifecycle.origination_date"; public static final String LIFECYCLE_PARSE_ORIGINATION_DATE = "index.lifecycle.parse_origination_date"; @@ -37,8 +36,6 @@ public class LifecycleSettings { public static final Setting LIFECYCLE_POLL_INTERVAL_SETTING = Setting.positiveTimeSetting(LIFECYCLE_POLL_INTERVAL, TimeValue.timeValueMinutes(10), Setting.Property.Dynamic, Setting.Property.NodeScope); - public static final Setting LIFECYCLE_NAME_SETTING = Setting.simpleString(LIFECYCLE_NAME, - Setting.Property.Dynamic, Setting.Property.IndexScope); public static final Setting LIFECYCLE_INDEXING_COMPLETE_SETTING = Setting.boolSetting(LIFECYCLE_INDEXING_COMPLETE, false, Setting.Property.Dynamic, Setting.Property.IndexScope); public static final Setting LIFECYCLE_ORIGINATION_DATE_SETTING = diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/MigrateAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/MigrateAction.java index 3a80879ebd44d..c89515f20c192 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/MigrateAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/MigrateAction.java @@ -9,17 +9,17 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.client.Client; +import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.ConstructingObjectParser; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentParser; -import org.elasticsearch.snapshots.SearchableSnapshotsSettings; import org.elasticsearch.cluster.routing.allocation.DataTier; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.io.IOException; import java.util.List; @@ -102,11 +102,11 @@ public List toSteps(Client client, String phase, StepKey nextStepKey) { BranchingStep conditionalSkipActionStep = new BranchingStep(preMigrateBranchingKey, migrationKey, nextStepKey, (index, clusterState) -> { - Settings indexSettings = clusterState.metadata().index(index).getSettings(); + IndexMetadata indexMetadata = clusterState.metadata().index(index); // partially mounted indices will already have data_frozen, and we don't want to change that if they do - if (SearchableSnapshotsSettings.isPartialSearchableSnapshotIndex(indexSettings)) { - String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexSettings); + if (indexMetadata.isPartialSearchableSnapshotStore()) { + String policyName = indexMetadata.getLifecycleName(); logger.debug("[{}] action in policy [{}] is configured for index [{}] which is a partially mounted index. " + "skipping this action", MigrateAction.NAME, policyName, index.getName()); return true; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/MountSnapshotStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/MountSnapshotStep.java index 3649798cd3e9d..57e06437aec1c 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/MountSnapshotStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/MountSnapshotStep.java @@ -16,6 +16,7 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.core.TimeValue; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.cluster.routing.allocation.DataTier; import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotAction; @@ -24,7 +25,7 @@ import java.util.Objects; import java.util.Optional; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.fromIndexMetadata; +import static org.elasticsearch.index.LifecycleExecutionState.fromIndexMetadata; /** * Restores the snapshot created for the designated index via the ILM policy to an index named using the provided prefix appended to the @@ -64,7 +65,7 @@ void performDuringNoSnapshot(IndexMetadata indexMetadata, ClusterState currentCl LifecycleExecutionState lifecycleState = fromIndexMetadata(indexMetadata); - String policyName = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + String policyName = indexMetadata.getSettings().get(IndexMetadata.LIFECYCLE_NAME); final String snapshotRepository = lifecycleState.getSnapshotRepository(); if (Strings.hasText(snapshotRepository) == false) { listener.onFailure(new IllegalStateException("snapshot repository is not present for policy [" + policyName + "] and index [" + @@ -115,7 +116,7 @@ void performDuringNoSnapshot(IndexMetadata indexMetadata, ClusterState currentCl // depending on what ILM execution state was captured at snapshot time, make it's way forward from _that_ step forward in // the ILM policy. // we'll re-set this setting on the restored index at a later step once we restored a deterministic execution state - new String[]{LifecycleSettings.LIFECYCLE_NAME}, + new String[]{IndexMetadata.LIFECYCLE_NAME}, // we'll not wait for the snapshot to complete in this step as the async steps are executed from threads that shouldn't // perform expensive operations (ie. clusterStateProcessed) false, diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/PhaseCacheManagement.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/PhaseCacheManagement.java index 984311aa23d00..9bdcf4ab37086 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/PhaseCacheManagement.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/PhaseCacheManagement.java @@ -15,6 +15,8 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.common.Strings; +import org.elasticsearch.index.LifecycleExecutionState; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.DeprecationHandler; import org.elasticsearch.xcontent.NamedXContentRegistry; import org.elasticsearch.xcontent.XContentParser; @@ -28,7 +30,7 @@ import java.util.Set; import java.util.stream.Collectors; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; +import static org.elasticsearch.index.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; /** * We cache the currently executing ILM phase in the index metadata so the ILM execution for managed indices is not irrecoverably @@ -134,7 +136,7 @@ public static boolean updateIndicesForPolicy(final Metadata.Builder mb, final Cl final List indicesThatCanBeUpdated = currentState.metadata().indices().values().stream() - .filter(meta -> newPolicy.getName().equals(LifecycleSettings.LIFECYCLE_NAME_SETTING.get(meta.getSettings()))) + .filter(meta -> newPolicy.getName().equals(meta.getLifecycleName())) .filter(meta -> isIndexPhaseDefinitionUpdatable(xContentRegistry, client, meta, newPolicy.getPolicy(), licenseState)) .collect(Collectors.toList()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/PhaseCompleteStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/PhaseCompleteStep.java index 623d0d7b97097..d3faacb8ec429 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/PhaseCompleteStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/PhaseCompleteStep.java @@ -6,6 +6,8 @@ */ package org.elasticsearch.xpack.core.ilm; +import org.elasticsearch.index.Step; + /** * This is essentially a marker that a phase has ended, and we need to check * the age of an index before proceeding to the next phase. diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ReadOnlyAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ReadOnlyAction.java index 2f63fb3605fde..578a4e42cd81f 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ReadOnlyAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ReadOnlyAction.java @@ -10,10 +10,11 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.ObjectParser; import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentParser; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.io.IOException; import java.util.Arrays; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ReplaceDataStreamBackingIndexStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ReplaceDataStreamBackingIndexStep.java index 30bc2d8cf053e..d970079922c1c 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ReplaceDataStreamBackingIndexStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ReplaceDataStreamBackingIndexStep.java @@ -13,12 +13,13 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.index.Index; +import org.elasticsearch.index.LifecycleExecutionState; import java.util.Locale; import java.util.Objects; import java.util.function.BiFunction; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.fromIndexMetadata; +import static org.elasticsearch.index.LifecycleExecutionState.fromIndexMetadata; /** * This step replaces a data stream backing index with the target index, as part of the data stream's backing indices. @@ -67,7 +68,7 @@ public ClusterState performAction(Index index, ClusterState clusterState) { String originalIndex = index.getName(); String targetIndexName = targetIndexNameSupplier.apply(originalIndex, fromIndexMetadata(originalIndexMetadata)); - String policyName = originalIndexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + String policyName = originalIndexMetadata.getSettings().get(IndexMetadata.LIFECYCLE_NAME); IndexAbstraction indexAbstraction = clusterState.metadata().getIndicesLookup().get(index.getName()); assert indexAbstraction != null : "invalid cluster metadata. index [" + index.getName() + "] was not found"; IndexAbstraction.DataStream dataStream = indexAbstraction.getParentDataStream(); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RolloverAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RolloverAction.java index 5d21bd893277d..f2fe756027f40 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RolloverAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RolloverAction.java @@ -9,6 +9,7 @@ import org.elasticsearch.Version; import org.elasticsearch.client.Client; import org.elasticsearch.core.Nullable; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; @@ -21,7 +22,7 @@ import org.elasticsearch.xcontent.ObjectParser.ValueType; import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentParser; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.io.IOException; import java.util.Arrays; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RolloverStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RolloverStep.java index 85f984385ad8c..f7affbaf6750f 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RolloverStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RolloverStep.java @@ -57,7 +57,7 @@ public void performAction(IndexMetadata indexMetadata, ClusterState currentClust assert dataStream.getWriteIndex() != null : "datastream " + dataStream.getName() + " has no write index"; if (dataStream.getWriteIndex().equals(indexMetadata.getIndex()) == false) { logger.warn("index [{}] is not the write index for data stream [{}]. skipping rollover for policy [{}]", - indexName, dataStream.getName(), LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings())); + indexName, dataStream.getName(), indexMetadata.getLifecycleName()); listener.onResponse(null); return; } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RollupILMAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RollupILMAction.java index 6e60136b6e246..1ee557767df34 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RollupILMAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RollupILMAction.java @@ -8,6 +8,7 @@ import org.elasticsearch.client.Client; import org.elasticsearch.core.Nullable; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; @@ -16,7 +17,7 @@ import org.elasticsearch.xcontent.ObjectParser; import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentParser; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import org.elasticsearch.xpack.core.rollup.RollupActionConfig; import java.io.IOException; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RollupStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RollupStep.java index 11da6e15b1ceb..e8c0f278ff4f3 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RollupStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RollupStep.java @@ -13,12 +13,13 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.common.Strings; import org.elasticsearch.core.TimeValue; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.xpack.core.rollup.RollupActionConfig; import org.elasticsearch.xpack.core.rollup.action.RollupAction; import java.util.Objects; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.fromIndexMetadata; +import static org.elasticsearch.index.LifecycleExecutionState.fromIndexMetadata; /** * Rolls up index using a {@link RollupActionConfig} @@ -42,7 +43,7 @@ public boolean isRetryable() { @Override public void performAction(IndexMetadata indexMetadata, ClusterState currentState, ClusterStateObserver observer, ActionListener listener) { - final String policyName = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + final String policyName = indexMetadata.getSettings().get(IndexMetadata.LIFECYCLE_NAME); final String indexName = indexMetadata.getIndex().getName(); final LifecycleExecutionState lifecycleState = fromIndexMetadata(indexMetadata); final String rollupIndexName = lifecycleState.getRollupIndexName(); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SearchableSnapshotAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SearchableSnapshotAction.java index 894a126929928..61bf721427e0e 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SearchableSnapshotAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SearchableSnapshotAction.java @@ -16,13 +16,15 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.index.LifecycleExecutionState; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.ConstructingObjectParser; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.license.LicenseUtils; import org.elasticsearch.license.XPackLicenseState; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotRequest; import java.io.IOException; @@ -138,7 +140,7 @@ public List toSteps(Client client, String phase, StepKey nextStepKey, XPac IndexMetadata indexMetadata = clusterState.getMetadata().index(index); assert indexMetadata != null : "index " + index.getName() + " must exist in the cluster state"; - String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()); + String policyName = indexMetadata.getLifecycleName(); if (indexMetadata.getSettings().get(LifecycleSettings.SNAPSHOT_INDEX_NAME) != null) { // The index is already a searchable snapshot, let's see if the repository matches String repo = indexMetadata.getSettings().get(SEARCHABLE_SNAPSHOTS_REPOSITORY_NAME_SETTING_KEY); @@ -186,7 +188,7 @@ public List toSteps(Client client, String phase, StepKey nextStepKey, XPac BranchingStep skipGeneratingSnapshotStep = new BranchingStep(skipGeneratingSnapshotKey, keyForSnapshotGeneration, waitForDataTierKey, (index, clusterState) -> { IndexMetadata indexMetadata = clusterState.getMetadata().index(index); - String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()); + String policyName = indexMetadata.getLifecycleName(); LifecycleExecutionState lifecycleExecutionState = LifecycleExecutionState.fromIndexMetadata(indexMetadata); if (lifecycleExecutionState.getSnapshotName() == null) { // No name exists, so it must be generated @@ -233,7 +235,7 @@ public List toSteps(Client client, String phase, StepKey nextStepKey, XPac CopyExecutionStateStep copyMetadataStep = new CopyExecutionStateStep(copyMetadataKey, copyLifecyclePolicySettingKey, (index, executionState) -> getRestoredIndexPrefix(copyMetadataKey) + index, nextStepKey); CopySettingsStep copySettingsStep = new CopySettingsStep(copyLifecyclePolicySettingKey, dataStreamCheckBranchingKey, - getRestoredIndexPrefix(copyLifecyclePolicySettingKey), LifecycleSettings.LIFECYCLE_NAME); + getRestoredIndexPrefix(copyLifecyclePolicySettingKey), IndexMetadata.LIFECYCLE_NAME); BranchingStep isDataStreamBranchingStep = new BranchingStep(dataStreamCheckBranchingKey, swapAliasesKey, replaceDataStreamIndexKey, (index, clusterState) -> { IndexAbstraction indexAbstraction = clusterState.metadata().getIndicesLookup().get(index.getName()); @@ -276,7 +278,7 @@ public List toSteps(Client client, String phase, StepKey nextStepKey, XPac * Resolves the prefix to be used for the mounted index depending on the provided key */ String getRestoredIndexPrefix(StepKey currentKey) { - if (currentKey.getPhase().equals(TimeseriesLifecycleType.FROZEN_PHASE)) { + if (currentKey.getPhase().equals(LifecycleExecutionState.FROZEN_PHASE)) { return PARTIAL_RESTORED_INDEX_PREFIX; } else { return FULL_RESTORED_INDEX_PREFIX; @@ -285,7 +287,7 @@ String getRestoredIndexPrefix(StepKey currentKey) { // Resolves the storage type depending on which phase the index is in MountSearchableSnapshotRequest.Storage getConcreteStorageType(StepKey currentKey) { - if (currentKey.getPhase().equals(TimeseriesLifecycleType.FROZEN_PHASE)) { + if (currentKey.getPhase().equals(LifecycleExecutionState.FROZEN_PHASE)) { return MountSearchableSnapshotRequest.Storage.SHARED_CACHE; } else { return MountSearchableSnapshotRequest.Storage.FULL_COPY; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SegmentCountStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SegmentCountStep.java index d749b5a22ec61..584c113eaade0 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SegmentCountStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SegmentCountStep.java @@ -16,6 +16,7 @@ import org.elasticsearch.client.Client; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.common.Strings; import org.elasticsearch.core.TimeValue; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SetPriorityAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SetPriorityAction.java index e1ad51b4beb46..60fc89300289f 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SetPriorityAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SetPriorityAction.java @@ -9,6 +9,7 @@ import org.elasticsearch.client.Client; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.core.Nullable; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; @@ -18,7 +19,7 @@ import org.elasticsearch.xcontent.ObjectParser; import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentParser; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.io.IOException; import java.util.Collections; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SetSingleNodeAllocateStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SetSingleNodeAllocateStep.java index 7ddcf1d1a2b5d..0d299b2c9ea95 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SetSingleNodeAllocateStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SetSingleNodeAllocateStep.java @@ -16,7 +16,6 @@ import org.elasticsearch.cluster.ClusterStateObserver; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.routing.RoutingNode; -import org.elasticsearch.cluster.routing.RoutingNodes; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders; @@ -86,8 +85,7 @@ public void performAction(IndexMetadata indexMetadata, ClusterState clusterState new NodeShutdownAllocationDecider(), new NodeReplacementAllocationDecider() )); - final RoutingNodes routingNodes = clusterState.getRoutingNodes(); - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, routingNodes, clusterState, null, + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, clusterState::getRoutingNodes, clusterState, null, null, System.nanoTime()); List validNodeIds = new ArrayList<>(); String indexName = indexMetadata.getIndex().getName(); @@ -97,7 +95,7 @@ public void performAction(IndexMetadata indexMetadata, ClusterState clusterState .collect(Collectors.groupingBy(ShardRouting::shardId)); if (routingsByShardId.isEmpty() == false) { - for (RoutingNode node : routingNodes) { + for (RoutingNode node : clusterState.getRoutingNodes()) { boolean canAllocateOneCopyOfEachShard = routingsByShardId.values().stream() // For each shard .allMatch(shardRoutings -> shardRoutings.stream() // Can we allocate at least one shard copy to this node? .map(shardRouting -> allocationDeciders.canAllocate(shardRouting, node, allocation).type()) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkAction.java index 3b0e4978d05e3..2e1e031a18701 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkAction.java @@ -13,6 +13,7 @@ import org.elasticsearch.cluster.metadata.IndexAbstraction; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.core.Nullable; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; @@ -22,7 +23,7 @@ import org.elasticsearch.xcontent.ObjectParser; import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentParser; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.io.IOException; import java.util.Arrays; @@ -170,7 +171,7 @@ public List toSteps(Client client, String phase, Step.StepKey nextStepKey) if (indexMetadata.getSettings().get(LifecycleSettings.SNAPSHOT_INDEX_NAME) != null) { logger.warn("[{}] action is configured for index [{}] in policy [{}] which is mounted as searchable snapshot. " + "Skipping this action", ShrinkAction.NAME, indexMetadata.getIndex().getName(), - LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings())); + indexMetadata.getLifecycleName()); return true; } return false; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkIndexNameSupplier.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkIndexNameSupplier.java index 0fba484223b1c..de825f03e8c36 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkIndexNameSupplier.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkIndexNameSupplier.java @@ -7,6 +7,8 @@ package org.elasticsearch.xpack.core.ilm; +import org.elasticsearch.index.LifecycleExecutionState; + public final class ShrinkIndexNameSupplier { public static final String SHRUNKEN_INDEX_PREFIX = "shrink-"; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkSetAliasStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkSetAliasStep.java index 7a68f29c641f6..450c50dc58d82 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkSetAliasStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkSetAliasStep.java @@ -10,8 +10,9 @@ import org.elasticsearch.client.Client; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; +import org.elasticsearch.index.LifecycleExecutionState; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.fromIndexMetadata; +import static org.elasticsearch.index.LifecycleExecutionState.fromIndexMetadata; import static org.elasticsearch.xpack.core.ilm.ShrinkIndexNameSupplier.getShrinkIndexName; import static org.elasticsearch.xpack.core.ilm.SwapAliasesAndDeleteSourceIndexStep.deleteSourceIndexAndTransferAliases; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkStep.java index de1eb002b1ae0..0edc53c78173e 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkStep.java @@ -17,6 +17,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.core.TimeValue; +import org.elasticsearch.index.LifecycleExecutionState; import java.util.Objects; @@ -30,8 +31,8 @@ public class ShrinkStep extends AsyncActionStep { private static final Logger logger = LogManager.getLogger(ShrinkStep.class); - private Integer numberOfShards; - private ByteSizeValue maxPrimaryShardSize; + private final Integer numberOfShards; + private final ByteSizeValue maxPrimaryShardSize; public ShrinkStep(StepKey key, StepKey nextStepKey, Client client, Integer numberOfShards, ByteSizeValue maxPrimaryShardSize) { @@ -65,18 +66,17 @@ public void performAction(IndexMetadata indexMetadata, ClusterState currentState String shrunkenIndexName = getShrinkIndexName(indexMetadata.getIndex().getName(), lifecycleState); if (currentState.metadata().index(shrunkenIndexName) != null) { logger.warn("skipping [{}] step for index [{}] as part of policy [{}] as the shrunk index [{}] already exists", - ShrinkStep.NAME, indexMetadata.getIndex().getName(), - LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()), shrunkenIndexName); + ShrinkStep.NAME, indexMetadata.getIndex().getName(), indexMetadata.getLifecycleName(), shrunkenIndexName); listener.onResponse(null); return; } - String lifecycle = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()); + String lifecycle = indexMetadata.getLifecycleName(); Settings.Builder builder = Settings.builder(); // need to remove the single shard, allocation so replicas can be allocated builder.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, indexMetadata.getNumberOfReplicas()) - .put(LifecycleSettings.LIFECYCLE_NAME, lifecycle) + .put(IndexMetadata.LIFECYCLE_NAME, lifecycle) .put(IndexMetadata.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey() + "_id", (String) null); if (numberOfShards != null) { builder.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numberOfShards); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrunkShardsAllocatedStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrunkShardsAllocatedStep.java index 0654959bc01c2..b033ca1378fa9 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrunkShardsAllocatedStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrunkShardsAllocatedStep.java @@ -11,6 +11,7 @@ import org.elasticsearch.action.support.ActiveShardCount; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.common.Strings; import org.elasticsearch.xcontent.ConstructingObjectParser; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrunkenIndexCheckStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrunkenIndexCheckStep.java index 22ec03a0e4fb8..18be9b5f980dd 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrunkenIndexCheckStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrunkenIndexCheckStep.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.Logger; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.common.Strings; import org.elasticsearch.xcontent.ConstructingObjectParser; @@ -20,7 +21,7 @@ import java.io.IOException; import java.util.Objects; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.fromIndexMetadata; +import static org.elasticsearch.index.LifecycleExecutionState.fromIndexMetadata; import static org.elasticsearch.xpack.core.ilm.ShrinkIndexNameSupplier.getShrinkIndexName; /** diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SwapAliasesAndDeleteSourceIndexStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SwapAliasesAndDeleteSourceIndexStep.java index 63cc99301b7a6..89d4b847c0ee9 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SwapAliasesAndDeleteSourceIndexStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SwapAliasesAndDeleteSourceIndexStep.java @@ -51,7 +51,7 @@ public void performAction(IndexMetadata indexMetadata, ClusterState currentClust IndexMetadata targetIndexMetadata = currentClusterState.metadata().index(targetIndexName); if (targetIndexMetadata == null) { - String policyName = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + String policyName = indexMetadata.getSettings().get(IndexMetadata.LIFECYCLE_NAME); String errorMessage = String.format(Locale.ROOT, "target index [%s] doesn't exist. stopping execution of lifecycle [%s] for" + " index [%s]", targetIndexName, policyName, originalIndex); logger.debug(errorMessage); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/TerminalPolicyStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/TerminalPolicyStep.java index 3c4aae1e93973..0fda6367cef01 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/TerminalPolicyStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/TerminalPolicyStep.java @@ -6,6 +6,8 @@ */ package org.elasticsearch.xpack.core.ilm; +import org.elasticsearch.index.Step; + /** * Signals that the policy for an index has been fully executed. */ diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleType.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleType.java index 4b6e1693504ee..0f295cec5ab40 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleType.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleType.java @@ -14,6 +14,7 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.core.TimeValue; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.rollup.RollupV2; import java.io.IOException; @@ -52,9 +53,9 @@ public class TimeseriesLifecycleType implements LifecycleType { static final String HOT_PHASE = "hot"; static final String WARM_PHASE = "warm"; static final String COLD_PHASE = "cold"; - static final String FROZEN_PHASE = "frozen"; static final String DELETE_PHASE = "delete"; - static final List ORDERED_VALID_PHASES = Arrays.asList(HOT_PHASE, WARM_PHASE, COLD_PHASE, FROZEN_PHASE, DELETE_PHASE); + static final List ORDERED_VALID_PHASES = + Arrays.asList(HOT_PHASE, WARM_PHASE, COLD_PHASE, LifecycleExecutionState.FROZEN_PHASE, DELETE_PHASE); public static final String FREEZE_ACTION_DEPRECATION_WARNING = "the freeze action has been deprecated and will be removed in a future" + " release"; @@ -83,7 +84,7 @@ public class TimeseriesLifecycleType implements LifecycleType { WARM_PHASE, VALID_WARM_ACTIONS, COLD_PHASE, VALID_COLD_ACTIONS, DELETE_PHASE, VALID_DELETE_ACTIONS, - FROZEN_PHASE, VALID_FROZEN_ACTIONS + LifecycleExecutionState.FROZEN_PHASE, VALID_FROZEN_ACTIONS ); static final Set HOT_ACTIONS_THAT_REQUIRE_ROLLOVER = Sets.newHashSet(ReadOnlyAction.NAME, ShrinkAction.NAME, @@ -204,7 +205,7 @@ public List getOrderedActions(Phase phase) { case COLD_PHASE: return ORDERED_VALID_COLD_ACTIONS.stream().map(actions::get) .filter(Objects::nonNull).collect(toList()); - case FROZEN_PHASE: + case LifecycleExecutionState.FROZEN_PHASE: return ORDERED_VALID_FROZEN_ACTIONS.stream().map(actions::get) .filter(Objects::nonNull).collect(toList()); case DELETE_PHASE: @@ -228,7 +229,7 @@ public String getNextActionName(String currentActionName, Phase phase) { case COLD_PHASE: orderedActionNames = ORDERED_VALID_COLD_ACTIONS; break; - case FROZEN_PHASE: + case LifecycleExecutionState.FROZEN_PHASE: orderedActionNames = ORDERED_VALID_FROZEN_ACTIONS; break; case DELETE_PHASE: @@ -338,7 +339,7 @@ static void validateActionsFollowingSearchableSnapshot(Collection phases) .findAny(); if (coldPhaseWithSearchableSnapshot.isPresent()) { for (Phase phase : phases) { - if (phase.getName().equals(FROZEN_PHASE)) { + if (phase.getName().equals(LifecycleExecutionState.FROZEN_PHASE)) { phasesFollowingSearchableSnapshot.add(phase); break; } @@ -450,13 +451,14 @@ public static String validateMonotonicallyIncreasingPhaseTimings(Collection phases) { Optional maybeFrozenPhase = phases.stream() - .filter(p -> FROZEN_PHASE.equals(p.getName())) + .filter(p -> LifecycleExecutionState.FROZEN_PHASE.equals(p.getName())) .findFirst(); maybeFrozenPhase.ifPresent(p -> { if (p.getActions().containsKey(SearchableSnapshotAction.NAME) == false) { - throw new IllegalArgumentException("policy specifies the [" + FROZEN_PHASE + "] phase without a corresponding [" + - SearchableSnapshotAction.NAME + "] action, but a searchable snapshot action is required in the frozen phase"); + throw new IllegalArgumentException("policy specifies the [" + LifecycleExecutionState.FROZEN_PHASE + + "] phase without a corresponding [" + SearchableSnapshotAction.NAME + + "] action, but a searchable snapshot action is required in the frozen phase"); } }); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/UnfollowAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/UnfollowAction.java index 95122bb48d1e0..a5759e3b49499 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/UnfollowAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/UnfollowAction.java @@ -12,10 +12,11 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.ObjectParser; import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentParser; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.io.IOException; import java.util.Arrays; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/UpdateRolloverLifecycleDateStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/UpdateRolloverLifecycleDateStep.java index cc942fec2a453..b9492afb7894b 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/UpdateRolloverLifecycleDateStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/UpdateRolloverLifecycleDateStep.java @@ -15,10 +15,11 @@ import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.common.Strings; import org.elasticsearch.index.Index; +import org.elasticsearch.index.LifecycleExecutionState; import java.util.function.LongSupplier; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; +import static org.elasticsearch.index.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; /** * Copies the lifecycle reference date to a new index created by rolling over an alias. diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/UpdateRollupIndexPolicyStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/UpdateRollupIndexPolicyStep.java index de6e599dcf5b4..7042d38e14399 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/UpdateRollupIndexPolicyStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/UpdateRollupIndexPolicyStep.java @@ -16,10 +16,11 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.core.TimeValue; +import org.elasticsearch.index.LifecycleExecutionState; import java.util.Objects; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.fromIndexMetadata; +import static org.elasticsearch.index.LifecycleExecutionState.fromIndexMetadata; /** * Updates the lifecycle policy for the rollup index for the original/currently managed index @@ -46,7 +47,7 @@ public String getRollupPolicy() { @Override public void performAction(IndexMetadata indexMetadata, ClusterState currentState, ClusterStateObserver observer, ActionListener listener) { - final String policyName = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + final String policyName = indexMetadata.getSettings().get(IndexMetadata.LIFECYCLE_NAME); final String indexName = indexMetadata.getIndex().getName(); final LifecycleExecutionState lifecycleState = fromIndexMetadata(indexMetadata); final String rollupIndexName = lifecycleState.getRollupIndexName(); @@ -55,7 +56,7 @@ public void performAction(IndexMetadata indexMetadata, ClusterState currentState "] and index [" + indexName + "]")); return; } - Settings settings = Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, rollupPolicy).build(); + Settings settings = Settings.builder().put(IndexMetadata.LIFECYCLE_NAME, rollupPolicy).build(); UpdateSettingsRequest updateSettingsRequest = new UpdateSettingsRequest(rollupIndexName) .masterNodeTimeout(TimeValue.MAX_VALUE) .settings(settings); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStep.java index 564a14150a0c7..fc4eacd83528b 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStep.java @@ -63,8 +63,7 @@ public void evaluateCondition(Metadata metadata, Index index, Listener listener, assert dataStream.getWriteIndex() != null : "datastream " + dataStream.getName() + " has no write index"; if (dataStream.getWriteIndex().equals(index) == false) { logger.warn("index [{}] is not the write index for data stream [{}]. skipping rollover for policy [{}]", - index.getName(), dataStream.getName(), - LifecycleSettings.LIFECYCLE_NAME_SETTING.get(metadata.index(index).getSettings())); + index.getName(), dataStream.getName(), metadata.index(index).getLifecycleName()); listener.onResponse(true, EmptyInfo.INSTANCE); return; } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForSnapshotAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForSnapshotAction.java index 2b79120facc89..3c9804a8c2b06 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForSnapshotAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForSnapshotAction.java @@ -7,6 +7,7 @@ package org.elasticsearch.xpack.core.ilm; import org.elasticsearch.client.Client; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; @@ -14,7 +15,7 @@ import org.elasticsearch.xcontent.ConstructingObjectParser; import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentParser; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.io.IOException; import java.util.Collections; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForSnapshotStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForSnapshotStep.java index 9ba605a8ce3b6..283f61b6fc70e 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForSnapshotStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForSnapshotStep.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.Logger; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.xcontent.ToXContentObject; import org.elasticsearch.index.Index; import org.elasticsearch.xpack.core.slm.SnapshotLifecycleMetadata; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/action/MoveToStepAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/action/MoveToStepAction.java index 7be24e5c3c337..1078b50a8467d 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/action/MoveToStepAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/action/MoveToStepAction.java @@ -21,7 +21,7 @@ import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.core.Nullable; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.io.IOException; import java.util.Objects; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/searchablesnapshots/SearchableSnapshotsFeatureSet.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/searchablesnapshots/SearchableSnapshotsFeatureSet.java index 19a43e4613364..32f98825bd9d6 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/searchablesnapshots/SearchableSnapshotsFeatureSet.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/searchablesnapshots/SearchableSnapshotsFeatureSet.java @@ -20,8 +20,6 @@ import java.util.Map; -import static org.elasticsearch.snapshots.SearchableSnapshotsSettings.isSearchableSnapshotStore; - public class SearchableSnapshotsFeatureSet implements XPackFeatureSet { private final XPackLicenseState licenseState; @@ -59,7 +57,7 @@ public void usage(ActionListener listener) { int numFullCopySnapIndices = 0; int numSharedCacheSnapIndices = 0; for (IndexMetadata indexMetadata : state.metadata()) { - if (isSearchableSnapshotStore(indexMetadata.getSettings())) { + if (indexMetadata.isSearchableSnapshotStore()) { if (SearchableSnapshotsSettings.SNAPSHOT_PARTIAL_SETTING.get(indexMetadata.getSettings())) { numSharedCacheSnapIndices++; } else { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/template/IndexTemplateConfig.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/template/IndexTemplateConfig.java index bc04c2bfe8418..01ac8d0827ae5 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/template/IndexTemplateConfig.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/template/IndexTemplateConfig.java @@ -95,4 +95,22 @@ public byte[] loadBytes() { : "index template must have a version property set to the given version property"; return template.getBytes(StandardCharsets.UTF_8); } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + IndexTemplateConfig that = (IndexTemplateConfig) o; + return version == that.version && templateName.equals(that.templateName) && fileName.equals(that.fileName) + && versionProperty.equals(that.versionProperty) && variables.equals(that.variables); + } + + @Override + public int hashCode() { + return Objects.hash(templateName, fileName, version, versionProperty, variables); + } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/template/IndexTemplateRegistry.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/template/IndexTemplateRegistry.java index 54170cc5e8c3c..f798912ab2946 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/template/IndexTemplateRegistry.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/template/IndexTemplateRegistry.java @@ -22,6 +22,7 @@ import org.elasticsearch.cluster.ClusterStateListener; import org.elasticsearch.cluster.metadata.ComponentTemplate; import org.elasticsearch.cluster.metadata.ComposableIndexTemplate; +import org.elasticsearch.cluster.metadata.ComposableIndexTemplateMetadata; import org.elasticsearch.cluster.metadata.IndexTemplateMetadata; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; @@ -41,8 +42,8 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Objects; -import java.util.Optional; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -249,27 +250,38 @@ private void addComponentTemplatesIfMissing(ClusterState state) { } } + private ComposableIndexTemplateMetadata allComposableTemplatesFoundMeta; + private void addComposableTemplatesIfMissing(ClusterState state) { + final ComposableIndexTemplateMetadata meta = + state.metadata().custom(ComposableIndexTemplateMetadata.TYPE, ComposableIndexTemplateMetadata.EMPTY); + if (allComposableTemplatesFoundMeta == meta) { + return; + } final List indexTemplates = getComposableTemplateConfigs(); + boolean allFound = true; for (IndexTemplateConfig newTemplate : indexTemplates) { final String templateName = newTemplate.getTemplateName(); final AtomicBoolean creationCheck = templateCreationsInProgress.computeIfAbsent(templateName, key -> new AtomicBoolean(false)); if (creationCheck.compareAndSet(false, true)) { - ComposableIndexTemplate currentTemplate = state.metadata().templatesV2().get(templateName); + ComposableIndexTemplate currentTemplate = meta.indexTemplates().get(templateName); boolean componentTemplatesAvailable = componentTemplatesExist(state, newTemplate); if (componentTemplatesAvailable == false) { creationCheck.set(false); logger.trace("not adding composable template [{}] for [{}] because its required component templates do not exist", templateName, getOrigin()); + allFound = false; } else if (Objects.isNull(currentTemplate)) { logger.debug("adding composable template [{}] for [{}], because it doesn't exist", templateName, getOrigin()); putComposableTemplate(newTemplate, creationCheck); + allFound = false; } else if (Objects.isNull(currentTemplate.version()) || newTemplate.getVersion() > currentTemplate.version()) { // IndexTemplateConfig now enforces templates contain a `version` property, so if the template doesn't have one we can // safely assume it's an old version of the template. logger.info("upgrading composable template [{}] for [{}] from version [{}] to version [{}]", templateName, getOrigin(), currentTemplate.version(), newTemplate.getVersion()); putComposableTemplate(newTemplate, creationCheck); + allFound = false; } else { creationCheck.set(false); logger.trace("not adding composable template [{}] for [{}], because it already exists at version [{}]", @@ -278,8 +290,14 @@ private void addComposableTemplatesIfMissing(ClusterState state) { } else { logger.trace("skipping the creation of composable template [{}] for [{}], because its creation is in progress", templateName, getOrigin()); + allFound = false; } } + if (allFound) { + allComposableTemplatesFoundMeta = meta; + } else { + allComposableTemplatesFoundMeta = null; + } } /** @@ -390,23 +408,29 @@ public void onFailure(Exception e) { }); } + private IndexLifecycleMetadata containsAllPoliciesMetadata; + private void addIndexLifecyclePoliciesIfMissing(ClusterState state) { + final IndexLifecycleMetadata meta = state.metadata().custom(IndexLifecycleMetadata.TYPE, IndexLifecycleMetadata.EMPTY); + if (meta == containsAllPoliciesMetadata) { + return; + } + Map ilmMetaData = meta.getPolicies(); - Optional maybeMeta = Optional.ofNullable(state.metadata().custom(IndexLifecycleMetadata.TYPE)); List policies = getPolicyConfigs().stream() .map(policyConfig -> policyConfig.load(xContentRegistry)) .collect(Collectors.toList()); + boolean allFound = true; for (LifecyclePolicy policy : policies) { final AtomicBoolean creationCheck = policyCreationsInProgress.computeIfAbsent(policy.getName(), key -> new AtomicBoolean(false)); if (creationCheck.compareAndSet(false, true)) { - final boolean policyNeedsToBeCreated = maybeMeta - .flatMap(ilmMeta -> Optional.ofNullable(ilmMeta.getPolicies().get(policy.getName()))) - .isPresent() == false; + final boolean policyNeedsToBeCreated = ilmMetaData.containsKey(policy.getName()) == false; if (policyNeedsToBeCreated) { logger.debug("adding lifecycle policy [{}] for [{}], because it doesn't exist", policy.getName(), getOrigin()); putPolicy(policy, creationCheck); + allFound = false; } else { logger.trace("not adding lifecycle policy [{}] for [{}], because it already exists", policy.getName(), getOrigin()); @@ -414,6 +438,11 @@ private void addIndexLifecyclePoliciesIfMissing(ClusterState state) { } } } + if (allFound) { + this.containsAllPoliciesMetadata = meta; + } else { + containsAllPoliciesMetadata = null; + } } private void putPolicy(final LifecyclePolicy policy, final AtomicBoolean creationCheck) { diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/cluster/metadata/IndexMetadataConversionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/cluster/metadata/IndexMetadataConversionTests.java index 50bb29d504a1e..cf2b74beea998 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/cluster/metadata/IndexMetadataConversionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/cluster/metadata/IndexMetadataConversionTests.java @@ -24,6 +24,7 @@ public class IndexMetadataConversionTests extends ESTestCase { + @AwaitsFix(bugUrl = "/todo") public void testConvertSearchableSnapshotSettings() { IndexMetadataVerifier service = getIndexMetadataVerifier(); IndexMetadata src = newIndexMeta("foo", Settings.EMPTY); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDeciderTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDeciderTests.java index 0c2c0e27bcac2..872ee89082a7f 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDeciderTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierAllocationDeciderTests.java @@ -85,7 +85,7 @@ public class DataTierAllocationDeciderTests extends ESAllocationTestCase { public void testClusterRequires() { ClusterState state = prepareState(service.reroute(ClusterState.EMPTY_STATE, "initial state")); - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state.getRoutingNodes(), state, + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state::getRoutingNodes, state, null, null, 0); allocation.debugDecision(true); clusterSettings.applySettings(Settings.builder() @@ -121,7 +121,7 @@ public void testClusterRequires() { public void testClusterIncludes() { ClusterState state = prepareState(service.reroute(ClusterState.EMPTY_STATE, "initial state")); - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state.getRoutingNodes(), state, + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state::getRoutingNodes, state, null, null, 0); allocation.debugDecision(true); clusterSettings.applySettings(Settings.builder() @@ -158,7 +158,7 @@ public void testClusterIncludes() { public void testClusterExcludes() { ClusterState state = prepareState(service.reroute(ClusterState.EMPTY_STATE, "initial state")); - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state.getRoutingNodes(), state, + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state::getRoutingNodes, state, null, null, 0); allocation.debugDecision(true); clusterSettings.applySettings(Settings.builder() @@ -195,9 +195,9 @@ public void testClusterExcludes() { public void testIndexRequires() { ClusterState state = prepareState(service.reroute(ClusterState.EMPTY_STATE, "initial state"), Settings.builder() - .put(DataTierAllocationDecider.INDEX_ROUTING_REQUIRE, "data_hot") + .put(IndexMetadata.INDEX_ROUTING_REQUIRE, "data_hot") .build()); - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state.getRoutingNodes(), state, + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state::getRoutingNodes, state, null, null, 0); allocation.debugDecision(true); Decision d; @@ -229,9 +229,9 @@ public void testIndexRequires() { public void testIndexIncludes() { ClusterState state = prepareState(service.reroute(ClusterState.EMPTY_STATE, "initial state"), Settings.builder() - .put(DataTierAllocationDecider.INDEX_ROUTING_INCLUDE, "data_warm,data_cold") + .put(IndexMetadata.INDEX_ROUTING_INCLUDE, "data_warm,data_cold") .build()); - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state.getRoutingNodes(), state, + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state::getRoutingNodes, state, null, null, 0); allocation.debugDecision(true); Decision d; @@ -265,9 +265,9 @@ public void testIndexIncludes() { public void testIndexExcludes() { ClusterState state = prepareState(service.reroute(ClusterState.EMPTY_STATE, "initial state"), Settings.builder() - .put(DataTierAllocationDecider.INDEX_ROUTING_EXCLUDE, "data_warm,data_cold") + .put(IndexMetadata.INDEX_ROUTING_EXCLUDE, "data_warm,data_cold") .build()); - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state.getRoutingNodes(), state, + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state::getRoutingNodes, state, null, null,0); allocation.debugDecision(true); Decision d; @@ -315,7 +315,7 @@ public void testIndexPrefer() { .build())) .build()) .build(); - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state.getRoutingNodes(), state, null, null, 0); + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state::getRoutingNodes, state, null, null, 0); allocation.debugDecision(true); Decision d; RoutingNode node; @@ -350,7 +350,7 @@ public void testIndexPrefer() { .build())) .build()) .build(); - allocation = new RoutingAllocation(allocationDeciders, state.getRoutingNodes(), state, null, null, 0); + allocation = new RoutingAllocation(allocationDeciders, state::getRoutingNodes, state, null, null, 0); allocation.debugDecision(true); for (DiscoveryNode n : Arrays.asList(HOT_NODE, WARM_NODE)) { @@ -393,12 +393,12 @@ public void testIndexPreferWithInclude() { .put(IndexMetadata.SETTING_INDEX_UUID, "myindex") .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(DataTierAllocationDecider.INDEX_ROUTING_INCLUDE, "data_cold") + .put(IndexMetadata.INDEX_ROUTING_INCLUDE, "data_cold") .put(DataTierAllocationDecider.TIER_PREFERENCE, "data_warm,data_cold") .build())) .build()) .build(); - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state.getRoutingNodes(), state, null, null, 0); + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state::getRoutingNodes, state, null, null, 0); allocation.debugDecision(true); Decision d; RoutingNode node; @@ -458,12 +458,12 @@ public void testIndexPreferWithExclude() { .put(IndexMetadata.SETTING_INDEX_UUID, "myindex") .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(DataTierAllocationDecider.INDEX_ROUTING_EXCLUDE, "data_warm") + .put(IndexMetadata.INDEX_ROUTING_EXCLUDE, "data_warm") .put(DataTierAllocationDecider.TIER_PREFERENCE, "data_warm,data_cold") .build())) .build()) .build(); - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state.getRoutingNodes(), state, null, null, 0); + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state::getRoutingNodes, state, null, null, 0); allocation.debugDecision(true); Decision d; RoutingNode node; @@ -523,12 +523,12 @@ public void testIndexPreferWithRequire() { .put(IndexMetadata.SETTING_INDEX_UUID, "myindex") .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(DataTierAllocationDecider.INDEX_ROUTING_REQUIRE, "data_cold") + .put(IndexMetadata.INDEX_ROUTING_REQUIRE, "data_cold") .put(DataTierAllocationDecider.TIER_PREFERENCE, "data_warm,data_cold") .build())) .build()) .build(); - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state.getRoutingNodes(), state, null, null, 0); + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state::getRoutingNodes, state, null, null, 0); allocation.debugDecision(true); Decision d; RoutingNode node; @@ -577,9 +577,9 @@ public void testIndexPreferWithRequire() { public void testClusterAndIndex() { ClusterState state = prepareState(service.reroute(ClusterState.EMPTY_STATE, "initial state"), Settings.builder() - .put(DataTierAllocationDecider.INDEX_ROUTING_INCLUDE, "data_warm,data_cold") + .put(IndexMetadata.INDEX_ROUTING_INCLUDE, "data_warm,data_cold") .build()); - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state.getRoutingNodes(), state, + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, state::getRoutingNodes, state, null, null,0); clusterSettings.applySettings(Settings.builder() .put(DataTierAllocationDecider.CLUSTER_ROUTING_EXCLUDE, "data_cold") @@ -706,7 +706,7 @@ public void testExistedClusterFilters() { "and will be removed in a future release! See the breaking changes documentation for the next major version.", "[cluster.routing.allocation.exclude._tier] setting was deprecated in Elasticsearch " + "and will be removed in a future release! See the breaking changes documentation for the next major version."); - RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, clusterState.getRoutingNodes(), clusterState, + RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, clusterState::getRoutingNodes, clusterState, null, null, 0); allocation.debugDecision(true); Decision d; @@ -803,9 +803,9 @@ public void testDefaultValueForPreference() { public Setting randomTierSetting() { //noinspection unchecked return randomFrom( - DataTierAllocationDecider.INDEX_ROUTING_EXCLUDE_SETTING, - DataTierAllocationDecider.INDEX_ROUTING_INCLUDE_SETTING, - DataTierAllocationDecider.INDEX_ROUTING_REQUIRE_SETTING, + IndexMetadata.INDEX_ROUTING_EXCLUDE_SETTING, + IndexMetadata.INDEX_ROUTING_INCLUDE_SETTING, + IndexMetadata.INDEX_ROUTING_REQUIRE_SETTING, DataTier.TIER_PREFERENCE_SETTING); } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AbstractStepTestCase.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AbstractStepTestCase.java index c35f2d070f90b..8d58f32613977 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AbstractStepTestCase.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AbstractStepTestCase.java @@ -12,9 +12,10 @@ import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.core.TimeValue; +import org.elasticsearch.index.Step; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.EqualsHashCodeTestUtils; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import org.junit.Before; import org.mockito.Mockito; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AbstractUnfollowIndexStepTestCase.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AbstractUnfollowIndexStepTestCase.java index a7c9cd02a5626..7bfa75a9ed445 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AbstractUnfollowIndexStepTestCase.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AbstractUnfollowIndexStepTestCase.java @@ -9,6 +9,7 @@ import org.elasticsearch.Version; import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.cluster.metadata.IndexMetadata; +import org.elasticsearch.index.Step; import org.mockito.Mockito; public abstract class AbstractUnfollowIndexStepTestCase extends AbstractStepTestCase { diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java index 1108541f3f06d..1f62e2595ceb4 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocateActionTests.java @@ -11,8 +11,9 @@ import org.elasticsearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider; import org.elasticsearch.common.io.stream.Writeable.Reader; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.XContentParser; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.util.Collections; import java.util.HashMap; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocationRoutedStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocationRoutedStepTests.java index 4cc2a329854b1..f9f368bf05c76 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocationRoutedStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AllocationRoutedStepTests.java @@ -27,7 +27,7 @@ import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.node.Node; import org.elasticsearch.xpack.core.ilm.ClusterStateWaitStep.Result; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.util.Collections; import java.util.Map; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/BranchingStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/BranchingStepTests.java index 655ecb7ed9213..a02662becbff8 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/BranchingStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/BranchingStepTests.java @@ -13,7 +13,7 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.index.Index; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.util.function.BiPredicate; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CheckNoDataStreamWriteIndexStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CheckNoDataStreamWriteIndexStepTests.java index f52bd83530e3b..e91776fa95ed8 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CheckNoDataStreamWriteIndexStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CheckNoDataStreamWriteIndexStepTests.java @@ -12,6 +12,7 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.index.Index; +import org.elasticsearch.index.Step; import java.util.Arrays; import java.util.List; @@ -54,7 +55,7 @@ public void testStepCompleteIfIndexIsNotPartOfDataStream() { String indexName = randomAlphaOfLength(10); String policyName = "test-ilm-policy"; IndexMetadata indexMetadata = - IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build(); ClusterState clusterState = ClusterState.builder(emptyClusterState()).metadata( @@ -71,7 +72,7 @@ public void testStepIncompleteIfIndexIsTheDataStreamWriteIndex() { String indexName = DataStream.getDefaultBackingIndexName(dataStreamName, 1); String policyName = "test-ilm-policy"; IndexMetadata indexMetadata = - IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build(); ClusterState clusterState = ClusterState.builder(emptyClusterState()).metadata( @@ -92,13 +93,13 @@ public void testStepCompleteIfPartOfDataStreamButNotWriteIndex() { String indexName = DataStream.getDefaultBackingIndexName(dataStreamName, 1); String policyName = "test-ilm-policy"; IndexMetadata indexMetadata = IndexMetadata.builder(indexName) - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + .settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)) .build(); String writeIndexName = DataStream.getDefaultBackingIndexName(dataStreamName, 2); IndexMetadata writeIndexMetadata = IndexMetadata.builder(writeIndexName) - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + .settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)) .build(); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CheckShrinkReadyStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CheckShrinkReadyStepTests.java index 041f8ef3dfbb0..9db1a665aa0ea 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CheckShrinkReadyStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CheckShrinkReadyStepTests.java @@ -26,6 +26,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.index.Index; +import org.elasticsearch.index.Step; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.node.Node; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CheckTargetShardsCountStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CheckTargetShardsCountStepTests.java index 9c50e9a20b5cb..18464673dd9ec 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CheckTargetShardsCountStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CheckTargetShardsCountStepTests.java @@ -10,7 +10,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import org.elasticsearch.xpack.core.ilm.step.info.SingleMessageFieldInfo; import static org.hamcrest.Matchers.is; @@ -50,7 +50,7 @@ public void testStepCompleteIfTargetShardsCountIsValid() { String policyName = "test-ilm-policy"; IndexMetadata indexMetadata = IndexMetadata.builder(randomAlphaOfLength(10)).settings(settings(Version.CURRENT) - .put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + .put(IndexMetadata.LIFECYCLE_NAME, policyName)) .numberOfShards(10).numberOfReplicas(randomIntBetween(0, 5)).build(); ClusterState clusterState = ClusterState.builder(emptyClusterState()).metadata( @@ -66,7 +66,7 @@ public void testStepIncompleteIfTargetShardsCountNotValid() { String indexName = randomAlphaOfLength(10); String policyName = "test-ilm-policy"; IndexMetadata indexMetadata = - IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .numberOfShards(10).numberOfReplicas(randomIntBetween(0, 5)).build(); ClusterState clusterState = ClusterState.builder(emptyClusterState()).metadata( diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CleanupShrinkIndexStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CleanupShrinkIndexStepTests.java index 30396ea9fb976..ea59c6fda3603 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CleanupShrinkIndexStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CleanupShrinkIndexStepTests.java @@ -16,8 +16,9 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.test.client.NoOpClient; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.util.Map; @@ -61,7 +62,7 @@ public void testPerformActionDoesntFailIfShrinkingIndexNameIsMissing() { String policyName = "test-ilm-policy"; IndexMetadata.Builder indexMetadataBuilder = - IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)); IndexMetadata indexMetadata = indexMetadataBuilder.build(); @@ -90,7 +91,7 @@ public void testPerformAction() { Map ilmCustom = org.elasticsearch.core.Map.of("shrink_index_name", shrinkIndexName); IndexMetadata.Builder indexMetadataBuilder = - IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .putCustom(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY, ilmCustom) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)); IndexMetadata indexMetadata = indexMetadataBuilder.build(); @@ -121,7 +122,7 @@ public void testDeleteSkippedIfManagedIndexIsShrunkAndSourceDoesntExist() { IndexMetadata.Builder shrunkIndexMetadataBuilder = IndexMetadata.builder(shrinkIndexName) .settings( settings(Version.CURRENT) - .put(LifecycleSettings.LIFECYCLE_NAME, policyName) + .put(IndexMetadata.LIFECYCLE_NAME, policyName) .put(IndexMetadata.INDEX_RESIZE_SOURCE_NAME_KEY, sourceIndex) ) .putCustom(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY, ilmCustom) diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CleanupSnapshotStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CleanupSnapshotStepTests.java index b5916f9c6084e..6276c93276d76 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CleanupSnapshotStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CleanupSnapshotStepTests.java @@ -17,8 +17,9 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.test.client.NoOpClient; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.util.Map; @@ -62,7 +63,7 @@ public void testPerformActionDoesntFailIfSnapshotInfoIsMissing() throws Exceptio { IndexMetadata.Builder indexMetadataBuilder = - IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)); IndexMetadata indexMetadata = indexMetadataBuilder.build(); @@ -76,7 +77,7 @@ public void testPerformActionDoesntFailIfSnapshotInfoIsMissing() throws Exceptio { IndexMetadata.Builder indexMetadataBuilder = - IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)); Map ilmCustom = org.elasticsearch.core.Map.of("snapshot_repository", "repository_name"); indexMetadataBuilder.putCustom(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY, ilmCustom); @@ -98,7 +99,7 @@ public void testPerformAction() { Map ilmCustom = org.elasticsearch.core.Map.of("snapshot_name", snapshotName); IndexMetadata.Builder indexMetadataBuilder = - IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .putCustom(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY, ilmCustom) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)); IndexMetadata indexMetadata = indexMetadataBuilder.build(); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CloseFollowerIndexStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CloseFollowerIndexStepTests.java index 357dd09c62b9e..bcf2ce273b4dd 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CloseFollowerIndexStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CloseFollowerIndexStepTests.java @@ -12,6 +12,7 @@ import org.elasticsearch.action.admin.indices.close.CloseIndexResponse; import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.cluster.metadata.IndexMetadata; +import org.elasticsearch.index.Step; import org.mockito.Mockito; import java.util.Collections; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CloseIndexStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CloseIndexStepTests.java index 6dc8f056712b3..cbbde9f4b89e6 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CloseIndexStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CloseIndexStepTests.java @@ -17,6 +17,7 @@ import org.elasticsearch.client.Client; import org.elasticsearch.client.IndicesAdminClient; import org.elasticsearch.cluster.metadata.IndexMetadata; +import org.elasticsearch.index.Step; import org.junit.Before; import org.mockito.Mockito; import org.mockito.stubbing.Answer; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ClusterStateWaitUntilThresholdStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ClusterStateWaitUntilThresholdStepTests.java index 34c4de56497c5..e8a8cfb82b56b 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ClusterStateWaitUntilThresholdStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ClusterStateWaitUntilThresholdStepTests.java @@ -14,7 +14,8 @@ import org.elasticsearch.core.TimeValue; import org.elasticsearch.core.Map; import org.elasticsearch.index.Index; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.LifecycleExecutionState; +import org.elasticsearch.index.Step.StepKey; import org.elasticsearch.xpack.core.ilm.step.info.SingleMessageFieldInfo; import java.time.Clock; @@ -24,7 +25,7 @@ import java.util.UUID; import static org.elasticsearch.xpack.core.ilm.ClusterStateWaitUntilThresholdStep.waitedMoreThanThresholdLevel; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; +import static org.elasticsearch.index.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; import static org.elasticsearch.xpack.core.ilm.UnfollowAction.CCR_METADATA_KEY; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CopyExecutionStateStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CopyExecutionStateStepTests.java index c232029ec635a..89d33c1ac3a33 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CopyExecutionStateStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CopyExecutionStateStepTests.java @@ -12,13 +12,14 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.LifecycleExecutionState; +import org.elasticsearch.index.Step.StepKey; import java.util.HashMap; import java.util.Map; import java.util.function.BiFunction; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; +import static org.elasticsearch.index.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionStateTests.createCustomMetadata; import static org.hamcrest.Matchers.equalTo; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CopySettingsStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CopySettingsStepTests.java index 1a040f37b7d86..ecb653eac8b9d 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CopySettingsStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CopySettingsStepTests.java @@ -10,6 +10,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; +import org.elasticsearch.index.Step; import static org.hamcrest.Matchers.is; @@ -56,7 +57,7 @@ public void testPerformAction() { String indexName = randomAlphaOfLength(10); String policyName = "test-ilm-policy"; IndexMetadata.Builder sourceIndexMetadataBuilder = - IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)); String indexPrefix = "test-prefix-"; @@ -71,10 +72,10 @@ public void testPerformAction() { ).build(); CopySettingsStep copySettingsStep = new CopySettingsStep(randomStepKey(), randomStepKey(), indexPrefix, - LifecycleSettings.LIFECYCLE_NAME); + IndexMetadata.LIFECYCLE_NAME); ClusterState newClusterState = copySettingsStep.performAction(sourceIndexMetadata.getIndex(), clusterState); IndexMetadata newTargetIndexMetadata = newClusterState.metadata().index(targetIndex); - assertThat(newTargetIndexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME), is(policyName)); + assertThat(newTargetIndexMetadata.getSettings().get(IndexMetadata.LIFECYCLE_NAME), is(policyName)); } } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CreateSnapshotStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CreateSnapshotStepTests.java index 8422a4a50d990..925d873ffe510 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CreateSnapshotStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CreateSnapshotStepTests.java @@ -17,8 +17,9 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.test.client.NoOpClient; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.util.HashMap; import java.util.Map; @@ -64,7 +65,7 @@ public void testPerformActionFailure() { { IndexMetadata.Builder indexMetadataBuilder = - IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)); Map ilmCustom = new HashMap<>(); String repository = "repository"; @@ -85,7 +86,7 @@ public void testPerformActionFailure() { { IndexMetadata.Builder indexMetadataBuilder = - IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)); IndexMetadata indexMetadata = indexMetadataBuilder.build(); @@ -110,7 +111,7 @@ public void testPerformAction() { ilmCustom.put("snapshot_repository", repository); IndexMetadata.Builder indexMetadataBuilder = - IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .putCustom(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY, ilmCustom) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)); IndexMetadata indexMetadata = indexMetadataBuilder.build(); @@ -142,7 +143,7 @@ public void testNextStepKey() { ilmCustom.put("snapshot_repository", repository); IndexMetadata.Builder indexMetadataBuilder = - IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .putCustom(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY, ilmCustom) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)); IndexMetadata indexMetadata = indexMetadataBuilder.build(); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/DataTierMigrationRoutedStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/DataTierMigrationRoutedStepTests.java index 6add879cba1b0..a9825207449fe 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/DataTierMigrationRoutedStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/DataTierMigrationRoutedStepTests.java @@ -21,7 +21,7 @@ import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.cluster.routing.allocation.DataTier; import org.elasticsearch.xpack.core.ilm.ClusterStateWaitStep.Result; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import org.elasticsearch.xpack.core.ilm.step.info.AllocationInfo; import java.util.Collections; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/DeleteActionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/DeleteActionTests.java index 350bedb081a29..1ce7f64a48dfe 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/DeleteActionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/DeleteActionTests.java @@ -7,8 +7,9 @@ package org.elasticsearch.xpack.core.ilm; import org.elasticsearch.common.io.stream.Writeable.Reader; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.XContentParser; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.io.IOException; import java.util.List; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/DeleteStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/DeleteStepTests.java index 378f63dac5b8b..2fb914821f4a4 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/DeleteStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/DeleteStepTests.java @@ -16,7 +16,7 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.core.List; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import org.mockito.Mockito; import static org.elasticsearch.cluster.metadata.DataStreamTestHelper.createTimestampField; @@ -121,7 +121,7 @@ public void testPerformActionThrowsExceptionIfIndexIsTheDataStreamWriteIndex() { { String indexName = DataStream.getDefaultBackingIndexName(dataStreamName, 1); index1 = IndexMetadata.builder(indexName) - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + .settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .numberOfShards(randomIntBetween(1, 5)) .numberOfReplicas(randomIntBetween(0, 5)) .build(); @@ -131,7 +131,7 @@ public void testPerformActionThrowsExceptionIfIndexIsTheDataStreamWriteIndex() { String indexName = DataStream.getDefaultBackingIndexName(dataStreamName, 2); sourceIndexMetadata = IndexMetadata.builder(indexName) - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + .settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .numberOfShards(randomIntBetween(1, 5)) .numberOfReplicas(randomIntBetween(0, 5)) .build(); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ErrorStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ErrorStepTests.java index 32902c2b896ab..48375e4e5bd48 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ErrorStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ErrorStepTests.java @@ -6,7 +6,7 @@ */ package org.elasticsearch.xpack.core.ilm; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; public class ErrorStepTests extends AbstractStepTestCase { diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ForceMergeActionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ForceMergeActionTests.java index 11c4264f5e400..5324f21781969 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ForceMergeActionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ForceMergeActionTests.java @@ -10,6 +10,7 @@ import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.core.Tuple; import org.elasticsearch.common.io.stream.Writeable.Reader; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.DeprecationHandler; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.xcontent.XContentParser; @@ -17,7 +18,7 @@ import org.elasticsearch.xcontent.json.JsonXContent; import org.elasticsearch.index.codec.CodecService; import org.elasticsearch.index.engine.EngineConfig; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.io.IOException; import java.util.List; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ForceMergeStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ForceMergeStepTests.java index bf4d14744af62..feee1425ebb88 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ForceMergeStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ForceMergeStepTests.java @@ -20,8 +20,9 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.index.Index; +import org.elasticsearch.index.Step; import org.elasticsearch.rest.RestStatus; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import org.mockito.Mockito; import static org.hamcrest.Matchers.equalTo; @@ -118,7 +119,7 @@ public void testPerformActionThrowsException() { public void testForcemergeFailsOnSomeShards() { int numberOfShards = randomIntBetween(2, 5); IndexMetadata indexMetadata = IndexMetadata.builder(randomAlphaOfLength(10)) - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, "ilmPolicy")) + .settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, "ilmPolicy")) .numberOfShards(numberOfShards).numberOfReplicas(randomIntBetween(0, 5)).build(); Index index = indexMetadata.getIndex(); ForceMergeResponse forceMergeResponse = Mockito.mock(ForceMergeResponse.class); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/FreezeActionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/FreezeActionTests.java index 7e48a6fa01dd6..3e8a8c1341147 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/FreezeActionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/FreezeActionTests.java @@ -7,8 +7,9 @@ package org.elasticsearch.xpack.core.ilm; import org.elasticsearch.common.io.stream.Writeable.Reader; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.XContentParser; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.io.IOException; import java.util.List; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/FreezeStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/FreezeStepTests.java index 75ccf7be3d069..20215d70043ba 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/FreezeStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/FreezeStepTests.java @@ -15,7 +15,7 @@ import org.elasticsearch.protocol.xpack.frozen.FreezeRequest; import org.elasticsearch.protocol.xpack.frozen.FreezeResponse; import org.elasticsearch.xpack.core.frozen.action.FreezeIndexAction; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import org.mockito.Mockito; import static org.hamcrest.Matchers.is; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/GenerateSnapshotNameStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/GenerateSnapshotNameStepTests.java index 350b70a1d96a1..513620227bb14 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/GenerateSnapshotNameStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/GenerateSnapshotNameStepTests.java @@ -16,13 +16,15 @@ import org.elasticsearch.cluster.metadata.RepositoryMetadata; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.LifecycleExecutionState; +import org.elasticsearch.index.Step; import java.util.Collections; import java.util.Locale; import static org.elasticsearch.xpack.core.ilm.GenerateSnapshotNameStep.generateSnapshotName; import static org.elasticsearch.xpack.core.ilm.GenerateSnapshotNameStep.validateGeneratedSnapshotName; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; +import static org.elasticsearch.index.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.greaterThan; @@ -69,7 +71,7 @@ public void testPerformAction() { String indexName = randomAlphaOfLength(10); String policyName = "test-ilm-policy"; final IndexMetadata indexMetadata = IndexMetadata.builder(indexName) - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + .settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .numberOfShards(randomIntBetween(1, 5)) .numberOfReplicas(randomIntBetween(0, 5)) .build(); @@ -109,7 +111,7 @@ public void testPerformActionRejectsNonexistentRepository() { String indexName = randomAlphaOfLength(10); String policyName = "test-ilm-policy"; final IndexMetadata indexMetadata = IndexMetadata.builder(indexName) - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + .settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .numberOfShards(randomIntBetween(1, 5)) .numberOfReplicas(randomIntBetween(0, 5)) .build(); @@ -138,7 +140,7 @@ public void testPerformActionWillOverwriteCachedRepository() { newCustomData.setSnapshotRepository("snapshot-repository-will-be-reset"); final IndexMetadata indexMetadata = IndexMetadata.builder(indexName) - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + .settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .numberOfShards(randomIntBetween(1, 5)) .numberOfReplicas(randomIntBetween(0, 5)) .putCustom(ILM_CUSTOM_METADATA_KEY, newCustomData.build().asMap()) diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/GenerateUniqueIndexNameStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/GenerateUniqueIndexNameStepTests.java index 56bf5a934b18c..56fe82c0da3c7 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/GenerateUniqueIndexNameStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/GenerateUniqueIndexNameStepTests.java @@ -17,8 +17,10 @@ import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.time.DateFormatter; +import org.elasticsearch.index.LifecycleExecutionState; +import org.elasticsearch.index.Step; import org.elasticsearch.indices.InvalidIndexNameException; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.Builder; +import org.elasticsearch.index.LifecycleExecutionState.Builder; import java.util.Locale; import java.util.function.BiFunction; @@ -78,7 +80,7 @@ public void testPerformAction() { String indexName = randomAlphaOfLength(10); String policyName = "test-ilm-policy"; IndexMetadata.Builder indexMetadataBuilder = - IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)); final IndexMetadata indexMetadata = indexMetadataBuilder.build(); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/InitializePolicyContextStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/InitializePolicyContextStepTests.java index ad554d45c5285..c14499944901e 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/InitializePolicyContextStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/InitializePolicyContextStepTests.java @@ -13,9 +13,10 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.index.Index; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.LifecycleExecutionState; +import org.elasticsearch.index.Step.StepKey; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; +import static org.elasticsearch.index.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; import static org.hamcrest.Matchers.equalTo; public class InitializePolicyContextStepTests extends AbstractStepTestCase { diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/LifecycleExecutionStateTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/LifecycleExecutionStateTests.java index ecf300124d166..887175f44450c 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/LifecycleExecutionStateTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/LifecycleExecutionStateTests.java @@ -7,6 +7,8 @@ package org.elasticsearch.xpack.core.ilm; +import org.elasticsearch.index.LifecycleExecutionState; +import org.elasticsearch.index.Step; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.EqualsHashCodeTestUtils; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyTests.java index 1623526c9d979..121ec23a17a6f 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyTests.java @@ -9,6 +9,8 @@ import org.elasticsearch.client.Client; import org.elasticsearch.cluster.ClusterModule; import org.elasticsearch.core.Nullable; +import org.elasticsearch.index.LifecycleExecutionState; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.Writeable.Reader; @@ -16,7 +18,7 @@ import org.elasticsearch.xcontent.NamedXContentRegistry; import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.test.AbstractSerializingTestCase; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.io.IOException; import java.util.ArrayList; @@ -130,7 +132,7 @@ public static LifecyclePolicy randomTimeseriesLifecyclePolicy(@Nullable String l List phaseNames = randomSubsetOf( between(0, TimeseriesLifecycleType.ORDERED_VALID_PHASES.size() - 1), TimeseriesLifecycleType.ORDERED_VALID_PHASES).stream() // Remove the frozen phase, we'll randomly re-add it later - .filter(pn -> TimeseriesLifecycleType.FROZEN_PHASE.equals(pn) == false) + .filter(pn -> LifecycleExecutionState.FROZEN_PHASE.equals(pn) == false) .collect(Collectors.toList()); Map phases = new HashMap<>(phaseNames.size()); Function> validActions = getPhaseToValidActions(); @@ -196,12 +198,12 @@ public static LifecyclePolicy randomTimeseriesLifecyclePolicy(@Nullable String l if (hotPhaseContainsSearchableSnap == false && coldPhaseContainsSearchableSnap == false && randomBoolean()) { TimeValue frozenTime = prev == null ? TimeValue.parseTimeValue(randomTimeValue(0, 100000, "s", "m", "h", "d"), "test") : TimeValue.timeValueSeconds(prev.seconds() + randomIntBetween(60, 600)); - phases.put(TimeseriesLifecycleType.FROZEN_PHASE, - new Phase(TimeseriesLifecycleType.FROZEN_PHASE, frozenTime, + phases.put(LifecycleExecutionState.FROZEN_PHASE, + new Phase(LifecycleExecutionState.FROZEN_PHASE, frozenTime, Collections.singletonMap(SearchableSnapshotAction.NAME, new SearchableSnapshotAction(randomAlphaOfLength(10), randomBoolean())))); } else { - phases.remove(TimeseriesLifecycleType.FROZEN_PHASE); + phases.remove(LifecycleExecutionState.FROZEN_PHASE); } return new LifecyclePolicy(TimeseriesLifecycleType.INSTANCE, lifecycleName, phases, randomMeta()); } @@ -284,14 +286,14 @@ protected LifecyclePolicy mutateInstance(LifecyclePolicy instance) throws IOExce break; case 1: // Remove the frozen phase, because it makes a lot of invalid phases when randomly mutating an existing policy - phases.remove(TimeseriesLifecycleType.FROZEN_PHASE); + phases.remove(LifecycleExecutionState.FROZEN_PHASE); // Remove a random phase if (phases.size() > 0) { phases.remove(new ArrayList<>(phases.keySet()).remove(randomIntBetween(0, phases.size() - 1))); } String phaseName = randomValueOtherThanMany(phases::containsKey, () -> randomFrom(TimeseriesLifecycleType.ORDERED_VALID_PHASES.stream() - .filter(pn -> TimeseriesLifecycleType.FROZEN_PHASE.equals(pn) == false) + .filter(pn -> LifecycleExecutionState.FROZEN_PHASE.equals(pn) == false) .collect(Collectors.toList()))); phases = new LinkedHashMap<>(phases); phases.put(phaseName, new Phase(phaseName, null, Collections.emptyMap())); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyUtilsTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyUtilsTests.java index 716eb6cd171af..ba9dcbee9708b 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyUtilsTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyUtilsTests.java @@ -65,7 +65,7 @@ public void testCalculateUsage() { .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) .put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT) - .put(LifecycleSettings.LIFECYCLE_NAME, "mypolicy") + .put(IndexMetadata.LIFECYCLE_NAME, "mypolicy") .build())) .build()) .build(); @@ -85,12 +85,12 @@ public void testCalculateUsage() { .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) .put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT) - .put(LifecycleSettings.LIFECYCLE_NAME, "mypolicy") + .put(IndexMetadata.LIFECYCLE_NAME, "mypolicy") .build())) .putCustom(ComposableIndexTemplateMetadata.TYPE, new ComposableIndexTemplateMetadata(Collections.singletonMap("mytemplate", new ComposableIndexTemplate(Collections.singletonList("myds"), - new Template(Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, "mypolicy").build(), null, null), + new Template(Settings.builder().put(IndexMetadata.LIFECYCLE_NAME, "mypolicy").build(), null, null), null, null, null, null, new ComposableIndexTemplate.DataStreamTemplate(false))))) .build()) .build(); @@ -108,27 +108,27 @@ public void testCalculateUsage() { .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) .put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT) - .put(LifecycleSettings.LIFECYCLE_NAME, "mypolicy") + .put(IndexMetadata.LIFECYCLE_NAME, "mypolicy") .build())) .put(IndexMetadata.builder("another") .settings(Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) .put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT) - .put(LifecycleSettings.LIFECYCLE_NAME, "mypolicy") + .put(IndexMetadata.LIFECYCLE_NAME, "mypolicy") .build())) .put(IndexMetadata.builder("other") .settings(Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) .put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT) - .put(LifecycleSettings.LIFECYCLE_NAME, "otherpolicy") + .put(IndexMetadata.LIFECYCLE_NAME, "otherpolicy") .build())) .putCustom(ComposableIndexTemplateMetadata.TYPE, new ComposableIndexTemplateMetadata(Collections.singletonMap("mytemplate", new ComposableIndexTemplate(Collections.singletonList("myds"), - new Template(Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, "mypolicy").build(), null, null), + new Template(Settings.builder().put(IndexMetadata.LIFECYCLE_NAME, "mypolicy").build(), null, null), null, null, null, null, new ComposableIndexTemplate.DataStreamTemplate(false))))); // Need to get the real Index instance of myindex: mBuilder.put(new DataStream("myds", new DataStream.TimestampField("@timestamp"), diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/MigrateActionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/MigrateActionTests.java index 550265f63e2c3..514b81a56ec28 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/MigrateActionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/MigrateActionTests.java @@ -13,8 +13,9 @@ import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.routing.allocation.DataTier; import org.elasticsearch.common.io.stream.Writeable.Reader; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.XContentParser; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.io.IOException; import java.util.List; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/MockAction.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/MockAction.java index c3f903d9ec2e1..188c2a1db364f 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/MockAction.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/MockAction.java @@ -9,6 +9,7 @@ import org.elasticsearch.client.Client; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.ObjectParser; import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentParser; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/MockActionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/MockActionTests.java index c95a1bcfdee07..70e56eed5129c 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/MockActionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/MockActionTests.java @@ -7,6 +7,7 @@ package org.elasticsearch.xpack.core.ilm; import org.elasticsearch.common.io.stream.Writeable.Reader; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.XContentParser; import java.io.IOException; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/MockStep.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/MockStep.java index 1a8a23d2c6da8..ae9577ba8115c 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/MockStep.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/MockStep.java @@ -9,6 +9,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.index.Step; import java.io.IOException; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/MountSnapshotStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/MountSnapshotStepTests.java index 992a6839209c2..761e6128f506c 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/MountSnapshotStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/MountSnapshotStepTests.java @@ -17,9 +17,10 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.core.List; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.snapshots.RestoreInfo; import org.elasticsearch.test.client.NoOpClient; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotAction; import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotRequest; @@ -94,7 +95,7 @@ public void testPerformActionFailure() { { IndexMetadata.Builder indexMetadataBuilder = - IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)); IndexMetadata indexMetadata = indexMetadataBuilder.build(); @@ -110,7 +111,7 @@ public void testPerformActionFailure() { { IndexMetadata.Builder indexMetadataBuilder = - IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)); Map ilmCustom = new HashMap<>(); String repository = "repository"; @@ -139,7 +140,7 @@ public void testPerformAction() throws Exception { ilmCustom.put("snapshot_repository", repository); IndexMetadata.Builder indexMetadataBuilder = - IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .putCustom(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY, ilmCustom) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)); IndexMetadata indexMetadata = indexMetadataBuilder.build(); @@ -165,7 +166,7 @@ public void testResponseStatusHandling() throws Exception { ilmCustom.put("snapshot_repository", repository); IndexMetadata.Builder indexMetadataBuilder = - IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .putCustom(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY, ilmCustom) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)); IndexMetadata indexMetadata = indexMetadataBuilder.build(); @@ -233,7 +234,7 @@ public void doTestMountWithoutSnapshotIndexNameInState(String prefix) throws Exc ilmCustom.put("snapshot_repository", repository); IndexMetadata.Builder indexMetadataBuilder = - IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .putCustom(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY, ilmCustom) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)); IndexMetadata indexMetadata = indexMetadataBuilder.build(); @@ -279,7 +280,7 @@ protected void assertThat("another ILM step will wait for the restore to complete. the " + MountSnapshotStep.NAME + " step should not", mountSearchableSnapshotRequest.waitForCompletion(), is(false)); assertThat(mountSearchableSnapshotRequest.ignoreIndexSettings(), is(notNullValue())); - assertThat(mountSearchableSnapshotRequest.ignoreIndexSettings()[0], is(LifecycleSettings.LIFECYCLE_NAME)); + assertThat(mountSearchableSnapshotRequest.ignoreIndexSettings()[0], is(IndexMetadata.LIFECYCLE_NAME)); assertThat(mountSearchableSnapshotRequest.mountedIndexName(), is(restoredIndexPrefix + indexName)); assertThat(mountSearchableSnapshotRequest.snapshotIndexName(), is(expectedSnapshotIndexName)); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/OpenIndexStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/OpenIndexStepTests.java index 4c522a34571b3..8f09c021e0f6b 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/OpenIndexStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/OpenIndexStepTests.java @@ -16,6 +16,7 @@ import org.elasticsearch.client.Client; import org.elasticsearch.client.IndicesAdminClient; import org.elasticsearch.cluster.metadata.IndexMetadata; +import org.elasticsearch.index.Step; import org.junit.Before; import org.mockito.Mockito; import org.mockito.stubbing.Answer; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/PauseFollowerIndexStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/PauseFollowerIndexStepTests.java index 7b847eeec65b8..59f5f377171ab 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/PauseFollowerIndexStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/PauseFollowerIndexStepTests.java @@ -17,6 +17,7 @@ import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.core.TimeValue; +import org.elasticsearch.index.Step; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.persistent.PersistentTasksCustomMetadata; import org.elasticsearch.xpack.core.ccr.action.PauseFollowAction; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/PhaseCacheManagementTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/PhaseCacheManagementTests.java index 084ed252cce8b..55fb22d633e08 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/PhaseCacheManagementTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/PhaseCacheManagementTests.java @@ -14,6 +14,8 @@ import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.LifecycleExecutionState; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.NamedXContentRegistry; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.core.TimeValue; @@ -23,7 +25,7 @@ import java.util.HashMap; import java.util.Map; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; +import static org.elasticsearch.index.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; import static org.elasticsearch.xpack.core.ilm.PhaseCacheManagement.eligibleToCheckForRefresh; import static org.elasticsearch.xpack.core.ilm.PhaseCacheManagement.isIndexPhaseDefinitionUpdatable; import static org.elasticsearch.xpack.core.ilm.PhaseCacheManagement.readStepKeys; @@ -487,7 +489,7 @@ public void testUpdateIndicesForPolicy() { meta = IndexMetadata.builder(index) .settings(Settings.builder() - .put(LifecycleSettings.LIFECYCLE_NAME, "my-policy") + .put(IndexMetadata.LIFECYCLE_NAME, "my-policy") .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, randomIntBetween(1, 10)) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, randomIntBetween(0, 5)) .put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT) @@ -520,7 +522,7 @@ public void testUpdateIndicesForPolicy() { private IndexMetadata buildIndexMetadata(String policy, LifecycleExecutionState.Builder lifecycleState) { return IndexMetadata.builder("index") - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policy)) + .settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policy)) .numberOfShards(randomIntBetween(1, 5)) .numberOfReplicas(randomIntBetween(0, 5)) .putCustom(ILM_CUSTOM_METADATA_KEY, lifecycleState.build().asMap()) diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/PhaseCompleteStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/PhaseCompleteStepTests.java index 2dc5ca359d458..67c0c42e0c0ef 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/PhaseCompleteStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/PhaseCompleteStepTests.java @@ -6,7 +6,7 @@ */ package org.elasticsearch.xpack.core.ilm; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; public class PhaseCompleteStepTests extends AbstractStepTestCase { diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ReadOnlyActionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ReadOnlyActionTests.java index 0986389072ec0..bc9a60d774bde 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ReadOnlyActionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ReadOnlyActionTests.java @@ -7,8 +7,9 @@ package org.elasticsearch.xpack.core.ilm; import org.elasticsearch.common.io.stream.Writeable.Reader; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.XContentParser; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.util.List; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ReplaceDataStreamBackingIndexStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ReplaceDataStreamBackingIndexStepTests.java index fca27d1cc2ade..2e3270d2b3539 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ReplaceDataStreamBackingIndexStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ReplaceDataStreamBackingIndexStepTests.java @@ -13,6 +13,8 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.index.Index; +import org.elasticsearch.index.LifecycleExecutionState; +import org.elasticsearch.index.Step; import java.util.List; import java.util.UUID; @@ -60,7 +62,7 @@ public void testPerformActionThrowsExceptionIfIndexIsNotPartOfDataStream() { String indexName = randomAlphaOfLength(10); String policyName = "test-ilm-policy"; IndexMetadata sourceIndexMetadata = - IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build(); ClusterState clusterState = ClusterState.builder(emptyClusterState()).metadata( @@ -76,7 +78,7 @@ public void testPerformActionThrowsExceptionIfIndexIsTheDataStreamWriteIndex() { String indexName = DataStream.getDefaultBackingIndexName(dataStreamName, 1); String policyName = "test-ilm-policy"; IndexMetadata sourceIndexMetadata = - IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build(); ClusterState clusterState = ClusterState.builder(emptyClusterState()).metadata( @@ -94,13 +96,13 @@ public void testPerformActionThrowsExceptionIfTargetIndexIsMissing() { String indexName = DataStream.getDefaultBackingIndexName(dataStreamName, 1); String policyName = "test-ilm-policy"; IndexMetadata sourceIndexMetadata = IndexMetadata.builder(indexName) - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + .settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)) .build(); String writeIndexName = DataStream.getDefaultBackingIndexName(dataStreamName, 2); IndexMetadata writeIndexMetadata = IndexMetadata.builder(writeIndexName) - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + .settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)) .build(); @@ -131,13 +133,13 @@ public void testPerformAction() { String indexName = DataStream.getDefaultBackingIndexName(dataStreamName, 1); String policyName = "test-ilm-policy"; IndexMetadata sourceIndexMetadata = IndexMetadata.builder(indexName) - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + .settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)) .build(); String writeIndexName = DataStream.getDefaultBackingIndexName(dataStreamName, 2); IndexMetadata writeIndexMetadata = IndexMetadata.builder(writeIndexName) - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + .settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)) .build(); @@ -175,12 +177,12 @@ public void testPerformActionSameOriginalTargetError() { String indexName = writeIndexName; String policyName = "test-ilm-policy"; IndexMetadata sourceIndexMetadata = IndexMetadata.builder(indexName) - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + .settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)) .build(); IndexMetadata writeIndexMetadata = IndexMetadata.builder(writeIndexName) - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + .settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)) .build(); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/RolloverActionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/RolloverActionTests.java index 4ba29b03c9e8d..3238bff3b0acb 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/RolloverActionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/RolloverActionTests.java @@ -11,8 +11,9 @@ import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.core.TimeValue; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.XContentParser; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.io.IOException; import java.util.List; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/RolloverStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/RolloverStepTests.java index 11f3cea00ab6b..ccc654d94b476 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/RolloverStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/RolloverStepTests.java @@ -21,7 +21,7 @@ import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.core.List; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import org.hamcrest.Matchers; import org.mockito.Mockito; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/RollupILMActionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/RollupILMActionTests.java index 0570fb108cfe2..3b741aceebcce 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/RollupILMActionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/RollupILMActionTests.java @@ -7,9 +7,10 @@ package org.elasticsearch.xpack.core.ilm; import org.elasticsearch.common.io.stream.Writeable.Reader; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.test.EqualsHashCodeTestUtils; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import org.elasticsearch.xpack.core.rollup.RollupActionConfig; import org.elasticsearch.xpack.core.rollup.RollupActionConfigTests; import org.elasticsearch.xpack.core.rollup.job.MetricConfig; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/RollupStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/RollupStepTests.java index 4b9b1da8fc446..0a0651f69b293 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/RollupStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/RollupStepTests.java @@ -15,7 +15,8 @@ import org.elasticsearch.cluster.metadata.DataStream; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.LifecycleExecutionState; +import org.elasticsearch.index.Step.StepKey; import org.elasticsearch.xpack.core.rollup.RollupActionConfig; import org.elasticsearch.xpack.core.rollup.RollupActionConfigTests; import org.elasticsearch.xpack.core.rollup.action.RollupAction; @@ -66,7 +67,7 @@ public RollupStep copyInstance(RollupStep instance) { private IndexMetadata getIndexMetadata(String index) { Map ilmCustom = Collections.singletonMap("rollup_index_name", "rollup-index"); return IndexMetadata.builder(index).settings( - settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, "test-ilm-policy")) + settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, "test-ilm-policy")) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)) .putCustom(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY, ilmCustom) .build(); @@ -97,10 +98,10 @@ public void testPerformAction() throws Exception { public void testPerformActionFailureInvalidExecutionState() { IndexMetadata indexMetadata = IndexMetadata.builder(randomAlphaOfLength(10)).settings( - settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, "test-ilm-policy")) + settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, "test-ilm-policy")) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)) .build(); - String policyName = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + String policyName = indexMetadata.getSettings().get(IndexMetadata.LIFECYCLE_NAME); String indexName = indexMetadata.getIndex().getName(); RollupStep step = createRandomInstance(); step.performAction(indexMetadata, emptyClusterState(), null, new ActionListener() { diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SearchableSnapshotActionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SearchableSnapshotActionTests.java index d7ea2974e0831..9b194a048fe56 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SearchableSnapshotActionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SearchableSnapshotActionTests.java @@ -8,8 +8,9 @@ import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.cluster.routing.allocation.DataTier; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.XContentParser; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotRequest; import java.io.IOException; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SegmentCountStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SegmentCountStepTests.java index e455a21e8e55d..76d5e51f44c48 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SegmentCountStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SegmentCountStepTests.java @@ -17,11 +17,12 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.ToXContentObject; import org.elasticsearch.index.Index; import org.elasticsearch.index.engine.Segment; import org.elasticsearch.rest.RestStatus; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import org.mockito.Mockito; import java.util.ArrayList; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SetPriorityActionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SetPriorityActionTests.java index 52f2c781323c9..608e723bb2670 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SetPriorityActionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SetPriorityActionTests.java @@ -8,9 +8,10 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.common.io.stream.Writeable.Reader; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.test.EqualsHashCodeTestUtils; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.util.List; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SetSingleNodeAllocateStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SetSingleNodeAllocateStepTests.java index 1999a4c118eaa..cb8d71476654b 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SetSingleNodeAllocateStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SetSingleNodeAllocateStepTests.java @@ -30,7 +30,7 @@ import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.node.Node; import org.elasticsearch.test.VersionUtils; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import org.mockito.Mockito; import java.io.IOException; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrinkActionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrinkActionTests.java index 3381350c6de7d..274301be9bd75 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrinkActionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrinkActionTests.java @@ -14,8 +14,10 @@ import org.elasticsearch.common.io.stream.Writeable.Reader; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.core.TimeValue; +import org.elasticsearch.index.LifecycleExecutionState; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.XContentParser; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.io.IOException; import java.util.Collections; @@ -92,7 +94,7 @@ public void testPerformActionWithSkip() { ClusterState state = ClusterState.builder(ClusterName.DEFAULT).metadata(Metadata.builder() .putCustom(IndexLifecycleMetadata.TYPE, new IndexLifecycleMetadata( Collections.singletonMap(policyMetadata.getName(), policyMetadata), OperationMode.RUNNING)) - .put(IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, lifecycleName)) + .put(IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, lifecycleName)) .putCustom(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY, LifecycleExecutionState.builder() .setPhase(step.getKey().getPhase()) @@ -127,7 +129,7 @@ public void testPerformActionWithoutSkip() { ClusterState state = ClusterState.builder(ClusterName.DEFAULT).metadata(Metadata.builder() .putCustom(IndexLifecycleMetadata.TYPE, new IndexLifecycleMetadata( Collections.singletonMap(policyMetadata.getName(), policyMetadata), OperationMode.RUNNING)) - .put(IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, lifecycleName)) + .put(IndexMetadata.builder(indexName).settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, lifecycleName)) .putCustom(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY, LifecycleExecutionState.builder() .setPhase(step.getKey().getPhase()) diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrinkIndexNameSupplierTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrinkIndexNameSupplierTests.java index 02660ce136b77..30a3ea04d8f09 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrinkIndexNameSupplierTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrinkIndexNameSupplierTests.java @@ -7,6 +7,7 @@ package org.elasticsearch.xpack.core.ilm; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.test.ESTestCase; import static org.elasticsearch.xpack.core.ilm.ShrinkIndexNameSupplier.SHRUNKEN_INDEX_PREFIX; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrinkSetAliasStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrinkSetAliasStepTests.java index 2e9366a9f08ce..44f3aabe7e618 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrinkSetAliasStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrinkSetAliasStepTests.java @@ -14,7 +14,7 @@ import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.cluster.metadata.AliasMetadata; import org.elasticsearch.cluster.metadata.IndexMetadata; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import org.mockito.Mockito; import org.mockito.stubbing.Answer; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrinkStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrinkStepTests.java index bac1fa404d7ed..c6daefd0acd15 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrinkStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrinkStepTests.java @@ -19,12 +19,13 @@ import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeValue; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.LifecycleExecutionState; +import org.elasticsearch.index.Step.StepKey; import org.mockito.Mockito; import java.util.Collections; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; +import static org.elasticsearch.index.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; import static org.elasticsearch.xpack.core.ilm.ShrinkIndexNameSupplier.SHRUNKEN_INDEX_PREFIX; import static org.hamcrest.Matchers.equalTo; @@ -89,7 +90,7 @@ public void testPerformAction() throws Exception { lifecycleState.setIndexCreationDate(randomNonNegativeLong()); IndexMetadata sourceIndexMetadata = IndexMetadata.builder(randomAlphaOfLength(10)) .settings(settings(Version.CURRENT) - .put(LifecycleSettings.LIFECYCLE_NAME, lifecycleName) + .put(IndexMetadata.LIFECYCLE_NAME, lifecycleName) ) .putCustom(ILM_CUSTOM_METADATA_KEY, lifecycleState.build().asMap()) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)) @@ -105,7 +106,7 @@ public void testPerformAction() throws Exception { Settings.Builder builder = Settings.builder(); builder.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, sourceIndexMetadata.getNumberOfReplicas()) - .put(LifecycleSettings.LIFECYCLE_NAME, lifecycleName) + .put(IndexMetadata.LIFECYCLE_NAME, lifecycleName) .put(IndexMetadata.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey() + "_id", (String) null); if (step.getNumberOfShards() != null) { builder.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, step.getNumberOfShards()); @@ -140,7 +141,7 @@ public void testPerformActionShrunkenIndexExists() throws Exception { lifecycleState.setShrinkIndexName(generatedShrunkenIndexName); IndexMetadata sourceIndexMetadata = IndexMetadata.builder(sourceIndexName) .settings(settings(Version.CURRENT) - .put(LifecycleSettings.LIFECYCLE_NAME, lifecycleName) + .put(IndexMetadata.LIFECYCLE_NAME, lifecycleName) ) .putCustom(ILM_CUSTOM_METADATA_KEY, lifecycleState.build().asMap()) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)) diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrunkShardsAllocatedStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrunkShardsAllocatedStepTests.java index ec0ed77dd816e..6deb261875e3c 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrunkShardsAllocatedStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrunkShardsAllocatedStepTests.java @@ -22,7 +22,7 @@ import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.test.NodeRoles; import org.elasticsearch.xpack.core.ilm.ClusterStateWaitStep.Result; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import static org.elasticsearch.xpack.core.ilm.ShrinkIndexNameSupplier.SHRUNKEN_INDEX_PREFIX; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrunkenIndexCheckStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrunkenIndexCheckStepTests.java index 16ae32526204e..2a427a661b943 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrunkenIndexCheckStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ShrunkenIndexCheckStepTests.java @@ -12,7 +12,7 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.xpack.core.ilm.ClusterStateWaitStep.Result; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import static org.elasticsearch.xpack.core.ilm.ShrinkIndexNameSupplier.SHRUNKEN_INDEX_PREFIX; import static org.hamcrest.Matchers.equalTo; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/StepKeyTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/StepKeyTests.java index 84ee38d342e39..26fb903458520 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/StepKeyTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/StepKeyTests.java @@ -10,7 +10,7 @@ import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.test.AbstractSerializingTestCase; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; public class StepKeyTests extends AbstractSerializingTestCase { diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SwapAliasesAndDeleteSourceIndexStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SwapAliasesAndDeleteSourceIndexStepTests.java index e4774cd88b473..44f4d3d12a4b2 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SwapAliasesAndDeleteSourceIndexStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SwapAliasesAndDeleteSourceIndexStepTests.java @@ -19,7 +19,7 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.test.client.NoOpClient; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.util.Arrays; import java.util.List; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/TerminalPolicyStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/TerminalPolicyStepTests.java index 7262caa543a01..3b77a01bfe11a 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/TerminalPolicyStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/TerminalPolicyStepTests.java @@ -6,7 +6,8 @@ */ package org.elasticsearch.xpack.core.ilm; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step; +import org.elasticsearch.index.Step.StepKey; public class TerminalPolicyStepTests extends AbstractStepTestCase { diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleTypeTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleTypeTests.java index fef93564aa149..1a30d692c2371 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleTypeTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleTypeTests.java @@ -33,7 +33,7 @@ import static org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleType.ACTIONS_CANNOT_FOLLOW_SEARCHABLE_SNAPSHOT; import static org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleType.COLD_PHASE; import static org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleType.DELETE_PHASE; -import static org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleType.FROZEN_PHASE; +import static org.elasticsearch.index.LifecycleExecutionState.FROZEN_PHASE; import static org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleType.HOT_PHASE; import static org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleType.ORDERED_VALID_COLD_ACTIONS; import static org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleType.ORDERED_VALID_DELETE_ACTIONS; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/UnfollowActionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/UnfollowActionTests.java index 916d06f1cbc24..49b017ceaa570 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/UnfollowActionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/UnfollowActionTests.java @@ -8,8 +8,9 @@ import org.elasticsearch.cluster.health.ClusterHealthStatus; import org.elasticsearch.common.io.stream.Writeable.Reader; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.XContentParser; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.io.IOException; import java.util.List; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/UnfollowFollowerIndexStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/UnfollowFollowerIndexStepTests.java index 78a447a6f80a0..96971583f9fe1 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/UnfollowFollowerIndexStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/UnfollowFollowerIndexStepTests.java @@ -12,6 +12,7 @@ import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.cluster.metadata.IndexMetadata; +import org.elasticsearch.index.Step; import org.elasticsearch.xpack.core.ccr.action.UnfollowAction; import org.mockito.Mockito; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/UpdateRolloverLifecycleDateStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/UpdateRolloverLifecycleDateStepTests.java index 75a53ce934397..cf7b831ee22e3 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/UpdateRolloverLifecycleDateStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/UpdateRolloverLifecycleDateStepTests.java @@ -16,7 +16,8 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.core.List; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.LifecycleExecutionState; +import org.elasticsearch.index.Step.StepKey; import java.util.Collections; import java.util.function.LongSupplier; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/UpdateRollupIndexPolicyStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/UpdateRollupIndexPolicyStepTests.java index d81599c67158f..901dd8587c4d4 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/UpdateRollupIndexPolicyStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/UpdateRollupIndexPolicyStepTests.java @@ -16,7 +16,8 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.LifecycleExecutionState; +import org.elasticsearch.index.Step.StepKey; import org.mockito.Mockito; import java.util.Collections; @@ -69,7 +70,7 @@ public UpdateRollupIndexPolicyStep copyInstance(UpdateRollupIndexPolicyStep inst private static IndexMetadata getIndexMetadata() { Map ilmCustom = Collections.singletonMap("rollup_index_name", "rollup-index"); return IndexMetadata.builder(randomAlphaOfLength(10)).settings( - settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, "test-ilm-policy")) + settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, "test-ilm-policy")) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)) .putCustom(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY, ilmCustom) .build(); @@ -78,7 +79,7 @@ private static IndexMetadata getIndexMetadata() { public void testPerformAction() throws Exception { IndexMetadata indexMetadata = getIndexMetadata(); UpdateRollupIndexPolicyStep step = createRandomInstance(); - Settings settings = Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, step.getRollupPolicy()).build(); + Settings settings = Settings.builder().put(IndexMetadata.LIFECYCLE_NAME, step.getRollupPolicy()).build(); Mockito.doAnswer(invocation -> { UpdateSettingsRequest request = (UpdateSettingsRequest) invocation.getArguments()[0]; @@ -103,7 +104,7 @@ public void testPerformActionFailure() { ClusterState.builder(emptyClusterState()).metadata(Metadata.builder().put(indexMetadata, true).build()).build(); Exception exception = new RuntimeException(); UpdateRollupIndexPolicyStep step = createRandomInstance(); - Settings settings = Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, step.getRollupPolicy()).build(); + Settings settings = Settings.builder().put(IndexMetadata.LIFECYCLE_NAME, step.getRollupPolicy()).build(); Mockito.doAnswer(invocation -> { UpdateSettingsRequest request = (UpdateSettingsRequest) invocation.getArguments()[0]; @@ -125,10 +126,10 @@ public void testPerformActionFailure() { public void testPerformActionFailureIllegalExecutionState() { IndexMetadata indexMetadata = IndexMetadata.builder(randomAlphaOfLength(10)).settings( - settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, "test-ilm-policy")) + settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, "test-ilm-policy")) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)) .build(); - String policyName = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + String policyName = indexMetadata.getSettings().get(IndexMetadata.LIFECYCLE_NAME); String indexName = indexMetadata.getIndex().getName(); UpdateRollupIndexPolicyStep step = createRandomInstance(); step.performAction(indexMetadata, emptyClusterState(), null, new ActionListener() { diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/UpdateSettingsStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/UpdateSettingsStepTests.java index 673e02c8cdaf0..6776ac19d4b80 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/UpdateSettingsStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/UpdateSettingsStepTests.java @@ -14,7 +14,7 @@ import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import org.mockito.Mockito; import static org.hamcrest.Matchers.equalTo; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForActiveShardsTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForActiveShardsTests.java index 8837f8a21f638..e4cfe59b7e603 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForActiveShardsTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForActiveShardsTests.java @@ -23,7 +23,7 @@ import org.elasticsearch.xcontent.json.JsonXContent; import org.elasticsearch.core.List; import org.elasticsearch.index.Index; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.io.IOException; import java.util.UUID; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForFollowShardTasksStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForFollowShardTasksStepTests.java index 71eb7f8a75237..92d90a3169a90 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForFollowShardTasksStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForFollowShardTasksStepTests.java @@ -13,7 +13,7 @@ import org.elasticsearch.xcontent.ToXContentObject; import org.elasticsearch.xpack.core.ccr.ShardFollowNodeTaskStatus; import org.elasticsearch.xpack.core.ccr.action.FollowStatsAction; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import org.mockito.Mockito; import java.util.Arrays; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForIndexColorStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForIndexColorStepTests.java index 86e7392b01b9f..5420ab7832b14 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForIndexColorStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForIndexColorStepTests.java @@ -18,7 +18,7 @@ import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardRoutingState; import org.elasticsearch.cluster.routing.TestShardRouting; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForIndexingCompleteStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForIndexingCompleteStepTests.java index a7764db2e74f9..a6e1307100703 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForIndexingCompleteStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForIndexingCompleteStepTests.java @@ -13,7 +13,7 @@ import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import java.util.Collections; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForNoFollowersStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForNoFollowersStepTests.java index 19c7665cee7ad..c20f88a9cd4f3 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForNoFollowersStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForNoFollowersStepTests.java @@ -17,6 +17,7 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.common.Strings; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.ToXContentObject; import org.elasticsearch.index.seqno.RetentionLease; import org.elasticsearch.index.seqno.RetentionLeaseStats; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStepTests.java index 2010795e54aeb..53ca91c6617f0 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStepTests.java @@ -25,6 +25,7 @@ import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.core.TimeValue; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.ToXContentObject; import org.elasticsearch.core.List; import org.mockito.Mockito; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForSnapshotActionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForSnapshotActionTests.java index c1089e365e9d9..8b5d1f462b5aa 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForSnapshotActionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForSnapshotActionTests.java @@ -7,6 +7,7 @@ package org.elasticsearch.xpack.core.ilm; import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.index.Step; import org.elasticsearch.xcontent.XContentParser; import java.io.IOException; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForSnapshotStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForSnapshotStepTests.java index eaae55d5ed41a..ccc98393a13bb 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForSnapshotStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForSnapshotStepTests.java @@ -13,6 +13,8 @@ import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.common.Strings; import org.elasticsearch.common.collect.ImmutableOpenMap; +import org.elasticsearch.index.LifecycleExecutionState; +import org.elasticsearch.index.Step; import org.elasticsearch.xpack.core.slm.SnapshotInvocationRecord; import org.elasticsearch.xpack.core.slm.SnapshotLifecycleMetadata; import org.elasticsearch.xpack.core.slm.SnapshotLifecyclePolicy; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/action/MoveToStepRequestTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/action/MoveToStepRequestTests.java index dc28e9fd1a520..7515465faaf52 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/action/MoveToStepRequestTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/action/MoveToStepRequestTests.java @@ -9,7 +9,7 @@ import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.test.AbstractSerializingTestCase; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import org.elasticsearch.xpack.core.ilm.StepKeyTests; import org.elasticsearch.xpack.core.ilm.action.MoveToStepAction.Request; import org.junit.Before; diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationInfoAction.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationInfoAction.java index e9c6410800aa8..14b573c214416 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationInfoAction.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationInfoAction.java @@ -248,7 +248,7 @@ public static DeprecationInfoAction.Response from( */ private static ClusterState removeSkippedSettings(ClusterState state, String[] indexNames, List skipTheseDeprecatedSettings) { ClusterState.Builder clusterStateBuilder = new ClusterState.Builder(state); - Metadata.Builder metadataBuilder = new Metadata.Builder(state.metadata()); + Metadata.Builder metadataBuilder = Metadata.builder(state.metadata()); metadataBuilder.transientSettings( metadataBuilder.transientSettings().filter(setting -> Regex.simpleMatch(skipTheseDeprecatedSettings, setting) == false)); metadataBuilder.persistentSettings( diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java index e02d2f882c133..a198e7c98e7cc 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java @@ -38,9 +38,9 @@ import java.util.function.Function; import java.util.stream.Collectors; -import static org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider.INDEX_ROUTING_EXCLUDE_SETTING; -import static org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider.INDEX_ROUTING_INCLUDE_SETTING; -import static org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider.INDEX_ROUTING_REQUIRE_SETTING; +import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_ROUTING_EXCLUDE_SETTING; +import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_ROUTING_INCLUDE_SETTING; +import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_ROUTING_REQUIRE_SETTING; /** diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java index 03a4e10b31ef7..19bd4515c379f 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java @@ -43,9 +43,9 @@ import static java.util.Collections.singletonList; import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder; -import static org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider.INDEX_ROUTING_EXCLUDE_SETTING; -import static org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider.INDEX_ROUTING_INCLUDE_SETTING; -import static org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider.INDEX_ROUTING_REQUIRE_SETTING; +import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_ROUTING_EXCLUDE_SETTING; +import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_ROUTING_INCLUDE_SETTING; +import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_ROUTING_REQUIRE_SETTING; import static org.elasticsearch.xpack.deprecation.DeprecationChecks.INDEX_SETTINGS_CHECKS; import static org.elasticsearch.xpack.deprecation.IndexDeprecationChecks.JODA_TIME_DEPRECATION_DETAILS_SUFFIX; import static org.hamcrest.Matchers.containsInAnyOrder; diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java index 859408b045460..fbf15fb2575ce 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java @@ -50,9 +50,9 @@ import static org.elasticsearch.cluster.coordination.JoinHelper.JOIN_TIMEOUT_SETTING; import static org.elasticsearch.cluster.routing.allocation.DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS_SETTING; -import static org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider.INDEX_ROUTING_EXCLUDE_SETTING; -import static org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider.INDEX_ROUTING_INCLUDE_SETTING; -import static org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider.INDEX_ROUTING_REQUIRE_SETTING; +import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_ROUTING_EXCLUDE_SETTING; +import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_ROUTING_INCLUDE_SETTING; +import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_ROUTING_REQUIRE_SETTING; import static org.elasticsearch.xpack.deprecation.NodeDeprecationChecks.JAVA_DEPRECATION_MESSAGE; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.either; diff --git a/x-pack/plugin/frozen-indices/src/main/java/org/elasticsearch/xpack/frozen/action/TransportFreezeIndexAction.java b/x-pack/plugin/frozen-indices/src/main/java/org/elasticsearch/xpack/frozen/action/TransportFreezeIndexAction.java index 999ef64862cc7..0bc493fb67ef0 100644 --- a/x-pack/plugin/frozen-indices/src/main/java/org/elasticsearch/xpack/frozen/action/TransportFreezeIndexAction.java +++ b/x-pack/plugin/frozen-indices/src/main/java/org/elasticsearch/xpack/frozen/action/TransportFreezeIndexAction.java @@ -37,7 +37,6 @@ import org.elasticsearch.index.engine.frozen.FrozenEngine; import org.elasticsearch.protocol.xpack.frozen.FreezeRequest; import org.elasticsearch.protocol.xpack.frozen.FreezeResponse; -import org.elasticsearch.snapshots.SearchableSnapshotsSettings; import org.elasticsearch.tasks.Task; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; @@ -199,7 +198,7 @@ public ClusterState execute(ClusterState currentState) { } else { settingsBuilder.remove(FrozenEngine.INDEX_FROZEN.getKey()); settingsBuilder.remove(IndexSettings.INDEX_SEARCH_THROTTLED.getKey()); - if (SearchableSnapshotsSettings.isSearchableSnapshotStore(indexMetadata.getSettings()) == false) { + if (indexMetadata.isSearchableSnapshotStore() == false) { settingsBuilder.remove("index.blocks.write"); blocks.removeIndexBlock(index.getName(), IndexMetadata.INDEX_WRITE_BLOCK); } diff --git a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/MigrateToDataTiersIT.java b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/MigrateToDataTiersIT.java index 2fe831273c36f..e5f82386cd3c0 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/MigrateToDataTiersIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/MigrateToDataTiersIT.java @@ -29,7 +29,6 @@ import org.elasticsearch.xpack.core.ilm.DeleteAction; import org.elasticsearch.xpack.core.ilm.ForceMergeAction; import org.elasticsearch.xpack.core.ilm.LifecycleAction; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.OperationMode; import org.elasticsearch.xpack.core.ilm.Phase; import org.elasticsearch.xpack.core.ilm.RolloverAction; @@ -121,7 +120,7 @@ public void testMigrateToDataTiersAction() throws Exception { createIndexWithSettings(client(), index, alias, Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(LifecycleSettings.LIFECYCLE_NAME, policy) + .put(IndexMetadata.LIFECYCLE_NAME, policy) .putNull(DataTier.TIER_PREFERENCE) .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias) ); @@ -249,7 +248,7 @@ public void testMigrationDryRun() throws Exception { createIndexWithSettings(client(), index, alias, Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(LifecycleSettings.LIFECYCLE_NAME, policy) + .put(IndexMetadata.LIFECYCLE_NAME, policy) .putNull(DataTier.TIER_PREFERENCE) .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias) ); diff --git a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/TimeSeriesRestDriver.java b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/TimeSeriesRestDriver.java index 63717775ec0aa..5e2391bfa08a1 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/TimeSeriesRestDriver.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/TimeSeriesRestDriver.java @@ -34,7 +34,7 @@ import org.elasticsearch.xpack.core.ilm.RolloverAction; import org.elasticsearch.xpack.core.ilm.SetPriorityAction; import org.elasticsearch.xpack.core.ilm.ShrinkAction; -import org.elasticsearch.xpack.core.ilm.Step; +import org.elasticsearch.index.Step; import java.io.IOException; import java.io.InputStream; diff --git a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/ChangePolicyforIndexIT.java b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/ChangePolicyforIndexIT.java index 2783c21cd8ed6..a786da211c433 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/ChangePolicyforIndexIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/ChangePolicyforIndexIT.java @@ -19,12 +19,11 @@ import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.xpack.core.ilm.AllocateAction; import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.Phase; import org.elasticsearch.xpack.core.ilm.PhaseCompleteStep; import org.elasticsearch.xpack.core.ilm.RolloverAction; import org.elasticsearch.xpack.core.ilm.SetPriorityAction; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import org.elasticsearch.xpack.core.ilm.WaitForRolloverReadyStep; import java.io.IOException; @@ -90,7 +89,7 @@ public void testChangePolicyForIndex() throws Exception { // create the test-index index and set the policy to policy_1 Settings settings = Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 4) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0).put("index.routing.allocation.include._name", "javaRestTest-0") - .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias").put(LifecycleSettings.LIFECYCLE_NAME, "policy_1").build(); + .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias").put(IndexMetadata.LIFECYCLE_NAME, "policy_1").build(); Request createIndexRequest = new Request("PUT", "/" + indexName); createIndexRequest.setJsonEntity( "{\n \"settings\": " + Strings.toString(settings) + ", \"aliases\" : { \"alias\": { \"is_write_index\": true } } }"); @@ -138,7 +137,7 @@ public void testILMHonoursTheCachedPhaseAfterPolicyUpdate() throws Exception { .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias) - .put(LifecycleSettings.LIFECYCLE_NAME, policyName)); + .put(IndexMetadata.LIFECYCLE_NAME, policyName)); // Check the index is on the check-rollover-ready step assertBusy(() -> assertStep(indexName, new StepKey("hot", RolloverAction.NAME, WaitForRolloverReadyStep.NAME)), 30, diff --git a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/ExplainLifecycleIT.java b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/ExplainLifecycleIT.java index b2f58e88b80e2..86d08f1ae3fc1 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/ExplainLifecycleIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/ExplainLifecycleIT.java @@ -21,7 +21,6 @@ import org.elasticsearch.xpack.core.ilm.DeleteAction; import org.elasticsearch.xpack.core.ilm.LifecycleAction; import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.Phase; import org.elasticsearch.xpack.core.ilm.RolloverAction; import org.elasticsearch.xpack.core.ilm.ShrinkAction; @@ -89,15 +88,15 @@ public void testExplainFilters() throws Exception { createIndexWithSettings(client(), goodIndex, alias, Settings.builder() .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(LifecycleSettings.LIFECYCLE_NAME, policy) + .put(IndexMetadata.LIFECYCLE_NAME, policy) ); createIndexWithSettings(client(), errorIndex, Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(LifecycleSettings.LIFECYCLE_NAME, "shrink-only-policy") + .put(IndexMetadata.LIFECYCLE_NAME, "shrink-only-policy") ); createIndexWithSettings(client(), nonexistantPolicyIndex, Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(LifecycleSettings.LIFECYCLE_NAME, randomValueOtherThan(policy, () -> randomAlphaOfLengthBetween(3, 10)))); + .put(IndexMetadata.LIFECYCLE_NAME, randomValueOtherThan(policy, () -> randomAlphaOfLengthBetween(3, 10)))); createIndexWithSettings(client(), unmanagedIndex, Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)); @@ -125,7 +124,7 @@ public void testExplainIndexContainsAutomaticRetriesInformation() throws Excepti // create index without alias so the rollover action fails and is retried createIndexWithSettings(client(), index, Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(LifecycleSettings.LIFECYCLE_NAME, policy) + .put(IndexMetadata.LIFECYCLE_NAME, policy) ); assertBusy(() -> { @@ -145,11 +144,11 @@ public void testExplainIndicesWildcard() throws Exception { createIndexWithSettings(client(), firstIndex, alias + firstIndex, Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(LifecycleSettings.LIFECYCLE_NAME, policy)); + .put(IndexMetadata.LIFECYCLE_NAME, policy)); createIndexWithSettings(client(), secondIndex, alias + secondIndex, Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(LifecycleSettings.LIFECYCLE_NAME, policy)); + .put(IndexMetadata.LIFECYCLE_NAME, policy)); createIndexWithSettings(client(), unmanagedIndex, alias + unmanagedIndex, Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)); @@ -157,7 +156,7 @@ public void testExplainIndicesWildcard() throws Exception { createIndexWithSettings(client(), indexWithMissingPolicy, alias + indexWithMissingPolicy, Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(LifecycleSettings.LIFECYCLE_NAME, missingPolicyName)); + .put(IndexMetadata.LIFECYCLE_NAME, missingPolicyName)); assertBusy(() -> { Map> explain = explain(client(), this.index + "*", false, false); diff --git a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/LifecycleLicenseIT.java b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/LifecycleLicenseIT.java index 6468a4a249963..71fada7f2893e 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/LifecycleLicenseIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/LifecycleLicenseIT.java @@ -12,6 +12,7 @@ import org.elasticsearch.client.Response; import org.elasticsearch.client.ResponseException; import org.elasticsearch.cluster.metadata.DataStream; +import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Template; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; @@ -23,7 +24,6 @@ import org.elasticsearch.license.TestUtils; import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.xpack.core.ilm.ErrorStep; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.PhaseCompleteStep; import org.elasticsearch.xpack.core.ilm.SearchableSnapshotAction; import org.junit.After; @@ -84,7 +84,7 @@ public void testSearchableSnapshotActionErrorsOnInvalidLicense() throws Exceptio createNewSingletonPolicy(client(), policy, "cold", new SearchableSnapshotAction(snapshotRepo, true)); createComposableTemplate(client(), "template-name", dataStream, - new Template(Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, policy).build(), null, null)); + new Template(Settings.builder().put(IndexMetadata.LIFECYCLE_NAME, policy).build(), null, null)); assertOK(client().performRequest(new Request("DELETE", "/_license"))); checkCurrentLicenseIs("basic"); diff --git a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesDataStreamsIT.java b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesDataStreamsIT.java index c8194efa62a68..e6bbebaad0576 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesDataStreamsIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesDataStreamsIT.java @@ -22,7 +22,6 @@ import org.elasticsearch.xpack.core.ilm.DeleteAction; import org.elasticsearch.xpack.core.ilm.ForceMergeAction; import org.elasticsearch.xpack.core.ilm.FreezeAction; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.PhaseCompleteStep; import org.elasticsearch.xpack.core.ilm.ReadOnlyAction; import org.elasticsearch.xpack.core.ilm.RolloverAction; @@ -263,7 +262,7 @@ private static Template getTemplate(String policyName) throws IOException { private static Settings getLifecycleSettings(String policyName) { return Settings.builder() - .put(LifecycleSettings.LIFECYCLE_NAME, policyName) + .put(IndexMetadata.LIFECYCLE_NAME, policyName) .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 2) .build(); } diff --git a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java index 860a9667b33bd..468ffbeea9551 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java @@ -42,7 +42,7 @@ import org.elasticsearch.xpack.core.ilm.RolloverAction; import org.elasticsearch.xpack.core.ilm.SearchableSnapshotAction; import org.elasticsearch.xpack.core.ilm.SetPriorityAction; -import org.elasticsearch.xpack.core.ilm.Step; +import org.elasticsearch.index.Step; import org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleType; import org.elasticsearch.xpack.core.ilm.WaitForActiveShardsStep; import org.elasticsearch.xpack.core.ilm.WaitForRolloverReadyStep; @@ -595,15 +595,15 @@ public void testDeletePolicyInUse() throws IOException { createIndexWithSettings(client(), managedIndex1, Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, randomIntBetween(1, 10)) - .put(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey(), originalPolicy)); + .put(IndexMetadata.LIFECYCLE_NAME_SETTING.getKey(), originalPolicy)); createIndexWithSettings(client(), managedIndex2, Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, randomIntBetween(1, 10)) - .put(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey(), originalPolicy)); + .put(IndexMetadata.LIFECYCLE_NAME_SETTING.getKey(), originalPolicy)); createIndexWithSettings(client(), unmanagedIndex, Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, randomIntBetween(1, 10))); createIndexWithSettings(client(), managedByOtherPolicyIndex, Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, randomIntBetween(1, 10)) - .put(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey(), otherPolicy)); + .put(IndexMetadata.LIFECYCLE_NAME_SETTING.getKey(), otherPolicy)); Request deleteRequest = new Request("DELETE", "_ilm/policy/" + originalPolicy); ResponseException ex = expectThrows(ResponseException.class, () -> client().performRequest(deleteRequest)); @@ -627,7 +627,7 @@ public void testRemoveAndReaddPolicy() throws Exception { alias, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(LifecycleSettings.LIFECYCLE_NAME, policy) + .put(IndexMetadata.LIFECYCLE_NAME, policy) .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias)); // Index a document @@ -659,7 +659,7 @@ public void testRemoveAndReaddPolicy() throws Exception { public void testCanStopILMWithPolicyUsingNonexistentPolicy() throws Exception { createIndexWithSettings(client(), index, alias, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey(), randomAlphaOfLengthBetween(5,15))); + .put(IndexMetadata.LIFECYCLE_NAME_SETTING.getKey(), randomAlphaOfLengthBetween(5,15))); Request stopILMRequest = new Request("POST", "_ilm/stop"); assertOK(client().performRequest(stopILMRequest)); @@ -794,7 +794,7 @@ public void testRetryableInitializationStep() throws Exception { alias, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(LifecycleSettings.LIFECYCLE_NAME, policy) + .put(IndexMetadata.LIFECYCLE_NAME, policy) .put(LifecycleSettings.LIFECYCLE_PARSE_ORIGINATION_DATE, false)); updateIndexSettings(index, Settings.builder() @@ -861,7 +861,7 @@ public void testHaltAtEndOfPhase() throws Exception { Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(LifecycleSettings.LIFECYCLE_NAME, policy), + .put(IndexMetadata.LIFECYCLE_NAME, policy), randomBoolean()); // Wait for the index to finish the "hot" phase @@ -915,7 +915,7 @@ public void testDeleteActionDoesntDeleteSearchableSnapshot() throws Exception { Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(LifecycleSettings.LIFECYCLE_NAME, policy), + .put(IndexMetadata.LIFECYCLE_NAME, policy), randomBoolean()); String[] snapshotName = new String[1]; diff --git a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeseriesMoveToStepIT.java b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeseriesMoveToStepIT.java index 0ad36fbd65f9e..bae75ba897ec4 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeseriesMoveToStepIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeseriesMoveToStepIT.java @@ -18,11 +18,10 @@ import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.xpack.core.ilm.DeleteAction; import org.elasticsearch.xpack.core.ilm.ForceMergeAction; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.PhaseCompleteStep; import org.elasticsearch.xpack.core.ilm.RolloverAction; import org.elasticsearch.xpack.core.ilm.ShrinkAction; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import org.junit.Before; import java.util.Locale; @@ -60,7 +59,7 @@ public void testMoveToAllocateStep() throws Exception { createIndexWithSettings(client(), originalIndex, alias, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 4) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) .put("index.routing.allocation.include._name", "javaRestTest-0") - .put(LifecycleSettings.LIFECYCLE_NAME, policy) + .put(IndexMetadata.LIFECYCLE_NAME, policy) .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias")); // move to a step @@ -91,7 +90,7 @@ public void testMoveToRolloverStep() throws Exception { createIndexWithSettings(client(), originalIndex, alias, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 4) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) .put("index.routing.allocation.include._name", "javaRestTest-0") - .put(LifecycleSettings.LIFECYCLE_NAME, policy) + .put(IndexMetadata.LIFECYCLE_NAME, policy) .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias)); // move to a step @@ -132,7 +131,7 @@ public void testMoveToInjectedStep() throws Exception { createIndexWithSettings(client(), index, alias, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 3) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(LifecycleSettings.LIFECYCLE_NAME, policy) + .put(IndexMetadata.LIFECYCLE_NAME, policy) .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias)); assertBusy(() -> assertThat(getStepKeyForIndex(client(), index), equalTo(new StepKey("new", "complete", "complete")))); @@ -169,7 +168,7 @@ public void testMoveToStepRereadsPolicy() throws Exception { createIndexWithSettings(client(), "test-1", alias, Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(LifecycleSettings.LIFECYCLE_NAME, policy) + .put(IndexMetadata.LIFECYCLE_NAME, policy) .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias), true); @@ -210,7 +209,7 @@ public void testMoveToStepWithInvalidNextStep() throws Exception { createIndexWithSettings(client(), index, alias, Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(LifecycleSettings.LIFECYCLE_NAME, policy)); + .put(IndexMetadata.LIFECYCLE_NAME, policy)); // move to a step Request moveToStepRequest = new Request("POST", "_ilm/move/" + index); @@ -243,7 +242,7 @@ public void testMoveToStepWithoutStepName() throws Exception { createIndexWithSettings(client(), index, alias, Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(LifecycleSettings.LIFECYCLE_NAME, policy)); + .put(IndexMetadata.LIFECYCLE_NAME, policy)); // move to a step Request moveToStepRequest = new Request("POST", "_ilm/move/" + index); @@ -272,7 +271,7 @@ public void testMoveToStepWithoutAction() throws Exception { createIndexWithSettings(client(), index, alias, Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(LifecycleSettings.LIFECYCLE_NAME, policy)); + .put(IndexMetadata.LIFECYCLE_NAME, policy)); // move to a step Request moveToStepRequest = new Request("POST", "_ilm/move/" + index); @@ -300,7 +299,7 @@ public void testInvalidToMoveToStepWithoutActionButWithName() throws Exception { createIndexWithSettings(client(), index, alias, Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(LifecycleSettings.LIFECYCLE_NAME, policy)); + .put(IndexMetadata.LIFECYCLE_NAME, policy)); // move to a step with an invalid request Request moveToStepRequest = new Request("POST", "_ilm/move/" + index); @@ -331,7 +330,7 @@ public void testResolveToNonexistentStep() throws Exception { createIndexWithSettings(client(), index, alias, Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(LifecycleSettings.LIFECYCLE_NAME, policy)); + .put(IndexMetadata.LIFECYCLE_NAME, policy)); // move to a step with an invalid request Request moveToStepRequest = new Request("POST", "_ilm/move/" + index); diff --git a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/ReadonlyActionIT.java b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/ReadonlyActionIT.java index bab919449ad5c..d8b2fda57331b 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/ReadonlyActionIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/ReadonlyActionIT.java @@ -15,7 +15,6 @@ import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.xpack.core.ilm.LifecycleAction; import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.Phase; import org.elasticsearch.xpack.core.ilm.PhaseCompleteStep; import org.elasticsearch.xpack.core.ilm.ReadOnlyAction; @@ -83,7 +82,7 @@ RolloverAction.NAME, new RolloverAction(null, null, null, 1L), .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias) - .put(LifecycleSettings.LIFECYCLE_NAME, policy)); + .put(IndexMetadata.LIFECYCLE_NAME, policy)); index(client(), originalIndex, "_id", "foo", "bar"); assertBusy(() -> { diff --git a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/RolloverActionIT.java b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/RolloverActionIT.java index 73191b0091eec..fa397504ae223 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/RolloverActionIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/RolloverActionIT.java @@ -153,7 +153,7 @@ public void testILMRolloverRetriesOnReadOnlyBlock() throws Exception { alias, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(LifecycleSettings.LIFECYCLE_NAME, policy) + .put(IndexMetadata.LIFECYCLE_NAME, policy) .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias) .put("index.blocks.read_only", true), true @@ -259,7 +259,7 @@ public void testRolloverStepRetriesUntilRolledOverIndexIsDeleted() throws Except alias, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(LifecycleSettings.LIFECYCLE_NAME, policy) + .put(IndexMetadata.LIFECYCLE_NAME, policy) .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias), true ); @@ -325,7 +325,7 @@ public void testUpdateRolloverLifecycleDateStepRetriesWhenRolloverInfoIsMissing( alias, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(LifecycleSettings.LIFECYCLE_NAME, policy) + .put(IndexMetadata.LIFECYCLE_NAME, policy) .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias), true ); diff --git a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/RollupActionIT.java b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/RollupActionIT.java index 0ce68b3f5f46b..22b1ce94a3aa3 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/RollupActionIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/RollupActionIT.java @@ -14,7 +14,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; import org.elasticsearch.test.rest.ESRestTestCase; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.RollupILMAction; import org.elasticsearch.xpack.core.rollup.RollupActionConfig; import org.elasticsearch.xpack.core.rollup.RollupActionDateHistogramGroupConfig; @@ -63,7 +62,7 @@ public void testRollupIndex() throws Exception { assertBusy(() -> assertNotNull(getRollupIndexName(index))); String rollupIndex = getRollupIndexName(index); assertBusy(() -> assertTrue(indexExists(rollupIndex))); - assertBusy(() -> assertFalse(getOnlyIndexSettings(client(), rollupIndex).containsKey(LifecycleSettings.LIFECYCLE_NAME))); + assertBusy(() -> assertFalse(getOnlyIndexSettings(client(), rollupIndex).containsKey(IndexMetadata.LIFECYCLE_NAME))); assertBusy(() -> assertTrue(indexExists(index))); } @@ -81,7 +80,7 @@ public void testRollupIndexAndSetNewRollupPolicy() throws Exception { assertBusy(() -> assertNotNull(getRollupIndexName(index))); String rollupIndex = getRollupIndexName(index); assertBusy(() -> assertTrue(indexExists(rollupIndex))); - assertBusy(() -> assertThat(getOnlyIndexSettings(client(), rollupIndex).get(LifecycleSettings.LIFECYCLE_NAME), equalTo(policy))); + assertBusy(() -> assertThat(getOnlyIndexSettings(client(), rollupIndex).get(IndexMetadata.LIFECYCLE_NAME), equalTo(policy))); assertBusy(() -> assertTrue(indexExists(index))); } diff --git a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/SearchableSnapshotActionIT.java b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/SearchableSnapshotActionIT.java index 042a351f89b0a..0a19188492af1 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/SearchableSnapshotActionIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/SearchableSnapshotActionIT.java @@ -28,14 +28,13 @@ import org.elasticsearch.xpack.core.ilm.FreezeAction; import org.elasticsearch.xpack.core.ilm.LifecycleAction; import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.Phase; import org.elasticsearch.xpack.core.ilm.PhaseCompleteStep; import org.elasticsearch.xpack.core.ilm.RolloverAction; import org.elasticsearch.xpack.core.ilm.SearchableSnapshotAction; import org.elasticsearch.xpack.core.ilm.SetPriorityAction; import org.elasticsearch.xpack.core.ilm.ShrinkAction; -import org.elasticsearch.xpack.core.ilm.Step; +import org.elasticsearch.index.Step; import org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleType; import org.junit.Before; @@ -88,7 +87,7 @@ public void testSearchableSnapshotAction() throws Exception { createNewSingletonPolicy(client(), policy, "cold", new SearchableSnapshotAction(snapshotRepo, true)); createComposableTemplate(client(), randomAlphaOfLengthBetween(5, 10).toLowerCase(), dataStream, - new Template(Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, policy).build(), null, null)); + new Template(Settings.builder().put(IndexMetadata.LIFECYCLE_NAME, policy).build(), null, null)); indexDocument(client(), dataStream, true); @@ -125,7 +124,7 @@ public void testSearchableSnapshotForceMergesIndexToOneSegment() throws Exceptio // rolling over the data stream so we can apply the searchable snapshot policy to a backing index that's not the write index rolloverMaxOneDocCondition(client(), dataStream); - updateIndexSettings(dataStream, Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, policy)); + updateIndexSettings(dataStream, Settings.builder().put(IndexMetadata.LIFECYCLE_NAME, policy)); assertTrue(waitUntil(() -> { try { Integer numberOfSegments = getNumberOfSegments(client(), backingIndexName); @@ -176,7 +175,7 @@ public void testDeleteActionDeletesSearchableSnapshot() throws Exception { assertOK(client().performRequest(createPolicyRequest)); createComposableTemplate(client(), randomAlphaOfLengthBetween(5, 10).toLowerCase(), dataStream, - new Template(Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, policy).build(), null, null)); + new Template(Settings.builder().put(IndexMetadata.LIFECYCLE_NAME, policy).build(), null, null)); indexDocument(client(), dataStream, true); @@ -237,7 +236,7 @@ public void testUpdatePolicyToAddPhasesYieldsInvalidActionsToBeSkipped() throws createComposableTemplate(client(), randomAlphaOfLengthBetween(5, 10).toLowerCase(), dataStream, new Template(Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 5) - .put(LifecycleSettings.LIFECYCLE_NAME, policy) + .put(IndexMetadata.LIFECYCLE_NAME, policy) .build(), null, null) ); @@ -295,7 +294,7 @@ public void testRestoredIndexManagedByLocalPolicySkipsIllegalActions() throws Ex createComposableTemplate(client(), randomAlphaOfLengthBetween(5, 10).toLowerCase(), dataStream, new Template(Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 5) - .put(LifecycleSettings.LIFECYCLE_NAME, policy) + .put(IndexMetadata.LIFECYCLE_NAME, policy) .build(), null, null) ); @@ -379,7 +378,7 @@ public void testIdenticalSearchableSnapshotActionIsNoop() throws Exception { // enable ILM after we indexed a document as otherwise ILM might sometimes run so fast the indexDocument call will fail with // `index_not_found_exception` - updateIndexSettings(index, Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, policy)); + updateIndexSettings(index, Settings.builder().put(IndexMetadata.LIFECYCLE_NAME, policy)); final String searchableSnapMountedIndexName = SearchableSnapshotAction.FULL_RESTORED_INDEX_PREFIX + index; @@ -426,7 +425,7 @@ public void testConvertingSearchableSnapshotFromFullToPartial() throws Exception // enable ILM after we indexed a document as otherwise ILM might sometimes run so fast the indexDocument call will fail with // `index_not_found_exception` - updateIndexSettings(index, Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, policy)); + updateIndexSettings(index, Settings.builder().put(IndexMetadata.LIFECYCLE_NAME, policy)); final String searchableSnapMountedIndexName = SearchableSnapshotAction.PARTIAL_RESTORED_INDEX_PREFIX + SearchableSnapshotAction.FULL_RESTORED_INDEX_PREFIX + index; @@ -492,7 +491,7 @@ snapshotRepo, randomBoolean())) createComposableTemplate(client(), randomAlphaOfLengthBetween(5, 10).toLowerCase(), dataStream, new Template(Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) - .put(LifecycleSettings.LIFECYCLE_NAME, policy) + .put(IndexMetadata.LIFECYCLE_NAME, policy) .build(), null, null) ); diff --git a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/ShrinkActionIT.java b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/ShrinkActionIT.java index 325764b9bb191..26db41f0b6d85 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/ShrinkActionIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/ShrinkActionIT.java @@ -30,7 +30,7 @@ import org.elasticsearch.xpack.core.ilm.RolloverAction; import org.elasticsearch.xpack.core.ilm.SetSingleNodeAllocateStep; import org.elasticsearch.xpack.core.ilm.ShrinkAction; -import org.elasticsearch.xpack.core.ilm.Step; +import org.elasticsearch.index.Step; import org.junit.Before; import java.io.IOException; diff --git a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/slm/SnapshotLifecycleRestIT.java b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/slm/SnapshotLifecycleRestIT.java index 1aaa2320c039c..e99575504621c 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/slm/SnapshotLifecycleRestIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/slm/SnapshotLifecycleRestIT.java @@ -33,7 +33,7 @@ import org.elasticsearch.test.junit.annotations.TestIssueLogging; import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.xpack.core.ilm.LifecycleSettings; -import org.elasticsearch.xpack.core.ilm.Step; +import org.elasticsearch.index.Step; import org.elasticsearch.xpack.core.ilm.WaitForRolloverReadyStep; import org.elasticsearch.xpack.core.slm.SnapshotLifecyclePolicy; import org.elasticsearch.xpack.core.slm.SnapshotLifecycleStats; diff --git a/x-pack/plugin/ilm/qa/with-security/src/javaRestTest/java/org/elasticsearch/xpack/security/PermissionsIT.java b/x-pack/plugin/ilm/qa/with-security/src/javaRestTest/java/org/elasticsearch/xpack/security/PermissionsIT.java index 9765b646b47af..fa8d151b43502 100644 --- a/x-pack/plugin/ilm/qa/with-security/src/javaRestTest/java/org/elasticsearch/xpack/security/PermissionsIT.java +++ b/x-pack/plugin/ilm/qa/with-security/src/javaRestTest/java/org/elasticsearch/xpack/security/PermissionsIT.java @@ -31,6 +31,7 @@ import org.elasticsearch.client.slm.PutSnapshotLifecyclePolicyRequest; import org.elasticsearch.client.slm.SnapshotLifecyclePolicy; import org.elasticsearch.client.slm.SnapshotRetentionConfiguration; +import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.SecureString; import org.elasticsearch.common.settings.Settings; @@ -102,7 +103,7 @@ public void init() throws Exception { request.setJsonEntity(Strings.toString(pollIntervalEntity)); assertOK(adminClient().performRequest(request)); indexSettingsWithPolicy = Settings.builder() - .put(LifecycleSettings.LIFECYCLE_NAME, deletePolicy) + .put(IndexMetadata.LIFECYCLE_NAME, deletePolicy) .put("number_of_shards", 1) .put("number_of_replicas", 0) .build(); diff --git a/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/ClusterStateWaitThresholdBreachTests.java b/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/ClusterStateWaitThresholdBreachTests.java index 3811c02f45e4a..ab48a2c0a98a7 100644 --- a/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/ClusterStateWaitThresholdBreachTests.java +++ b/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/ClusterStateWaitThresholdBreachTests.java @@ -29,7 +29,7 @@ import org.elasticsearch.xpack.core.ilm.PhaseCompleteStep; import org.elasticsearch.xpack.core.ilm.ShrinkAction; import org.elasticsearch.xpack.core.ilm.ShrunkShardsAllocatedStep; -import org.elasticsearch.xpack.core.ilm.Step; +import org.elasticsearch.index.Step; import org.elasticsearch.xpack.core.ilm.action.ExplainLifecycleAction; import org.elasticsearch.xpack.core.ilm.action.PutLifecycleAction; import org.junit.Before; @@ -114,7 +114,7 @@ public void testWaitInShrunkShardsAllocatedExceedsThreshold() throws Exception { // we're configuring a very high number of replicas. this will make ths shrunk index unable to allocate successfully, so ILM will // wait in the `shrunk-shards-allocated` step (we don't wait for the original index to be GREEN before) Settings settings = Settings.builder().put(indexSettings()).put(SETTING_NUMBER_OF_SHARDS, numShards) - .put(SETTING_NUMBER_OF_REPLICAS, 42).put(LifecycleSettings.LIFECYCLE_NAME, policy) + .put(SETTING_NUMBER_OF_REPLICAS, 42).put(IndexMetadata.LIFECYCLE_NAME, policy) // configuring the threshold to the minimum value .put(LifecycleSettings.LIFECYCLE_STEP_WAIT_TIME_THRESHOLD, "1h") .build(); diff --git a/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/DataTiersMigrationsTests.java b/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/DataTiersMigrationsTests.java index 598e6acbb0486..1c5a7a64adc61 100644 --- a/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/DataTiersMigrationsTests.java +++ b/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/DataTiersMigrationsTests.java @@ -11,6 +11,7 @@ import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainResponse; import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest; +import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.routing.ShardRoutingState; import org.elasticsearch.cluster.routing.allocation.DataTier; @@ -131,7 +132,7 @@ public void testIndexDataTierMigration() throws Exception { assertAcked(client().execute(PutLifecycleAction.INSTANCE, putLifecycleRequest).get()); Settings settings = Settings.builder().put(indexSettings()).put(SETTING_NUMBER_OF_SHARDS, 1) - .put(SETTING_NUMBER_OF_REPLICAS, 1).put(LifecycleSettings.LIFECYCLE_NAME, policy).build(); + .put(SETTING_NUMBER_OF_REPLICAS, 1).put(IndexMetadata.LIFECYCLE_NAME, policy).build(); CreateIndexResponse res = client().admin().indices().prepareCreate(managedIndex).setSettings(settings).get(); assertTrue(res.isAcknowledged()); @@ -193,7 +194,7 @@ public void testUserOptsOutOfTierMigration() throws Exception { assertAcked(client().execute(PutLifecycleAction.INSTANCE, putLifecycleRequest).get()); Settings settings = Settings.builder().put(indexSettings()).put(SETTING_NUMBER_OF_SHARDS, 1) - .put(SETTING_NUMBER_OF_REPLICAS, 1).put(LifecycleSettings.LIFECYCLE_NAME, policy).build(); + .put(SETTING_NUMBER_OF_REPLICAS, 1).put(IndexMetadata.LIFECYCLE_NAME, policy).build(); CreateIndexResponse res = client().admin().indices().prepareCreate(managedIndex).setSettings(settings).get(); assertTrue(res.isAcknowledged()); diff --git a/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/ILMMultiNodeIT.java b/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/ILMMultiNodeIT.java index 3e2bf40d357ba..15c604b948a1c 100644 --- a/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/ILMMultiNodeIT.java +++ b/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/ILMMultiNodeIT.java @@ -110,7 +110,7 @@ public void testShrinkOnTiers() throws Exception { Template t = new Template(Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 2) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(LifecycleSettings.LIFECYCLE_NAME, "shrink-policy") + .put(IndexMetadata.LIFECYCLE_NAME, "shrink-policy") .build(), null, null); ComposableIndexTemplate template = new ComposableIndexTemplate( diff --git a/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/IndexLifecycleInitialisationTests.java b/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/IndexLifecycleInitialisationTests.java index 6e7d354ce25a2..a6ef3b29714f7 100644 --- a/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/IndexLifecycleInitialisationTests.java +++ b/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/IndexLifecycleInitialisationTests.java @@ -8,6 +8,7 @@ import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.routing.RoutingNode; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.common.io.stream.NamedWriteable; @@ -31,7 +32,7 @@ import org.elasticsearch.xpack.core.ilm.ExplainLifecycleResponse; import org.elasticsearch.xpack.core.ilm.IndexLifecycleExplainResponse; import org.elasticsearch.xpack.core.ilm.LifecycleAction; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.LifecycleType; @@ -40,7 +41,7 @@ import org.elasticsearch.xpack.core.ilm.Phase; import org.elasticsearch.xpack.core.ilm.PhaseCompleteStep; import org.elasticsearch.xpack.core.ilm.PhaseExecutionInfo; -import org.elasticsearch.xpack.core.ilm.Step; +import org.elasticsearch.index.Step; import org.elasticsearch.xpack.core.ilm.StopILMRequest; import org.elasticsearch.xpack.core.ilm.action.ExplainLifecycleAction; import org.elasticsearch.xpack.core.ilm.action.GetLifecycleAction; @@ -136,7 +137,7 @@ protected Collection> transportClientPlugins() { @Before public void init() { settings = Settings.builder().put(indexSettings()).put(SETTING_NUMBER_OF_SHARDS, 1) - .put(SETTING_NUMBER_OF_REPLICAS, 0).put(LifecycleSettings.LIFECYCLE_NAME, "test").build(); + .put(SETTING_NUMBER_OF_REPLICAS, 0).put(IndexMetadata.LIFECYCLE_NAME, "test").build(); List steps = new ArrayList<>(); Step.StepKey key = new Step.StepKey("mock", ObservableAction.NAME, ObservableClusterStateWaitStep.NAME); Step.StepKey compKey = new Step.StepKey("mock", "complete", "complete"); 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 00b84ee257ef0..1a057085bee22 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 @@ -28,7 +28,7 @@ import org.elasticsearch.test.ESSingleNodeTestCase; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.watcher.ResourceWatcherService; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import org.elasticsearch.xpack.core.ilm.UpdateSettingsStep; import org.junit.After; diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingService.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingService.java index 9d91edde74e38..b6c9ca72e666b 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingService.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingService.java @@ -25,14 +25,13 @@ import org.elasticsearch.xpack.core.ilm.AllocateAction; import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata; import org.elasticsearch.xpack.core.ilm.LifecycleAction; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; import org.elasticsearch.xpack.core.ilm.LifecyclePolicyMetadata; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.MigrateAction; import org.elasticsearch.xpack.core.ilm.Phase; import org.elasticsearch.xpack.core.ilm.PhaseExecutionInfo; -import org.elasticsearch.xpack.core.ilm.Step; +import org.elasticsearch.index.Step; import java.time.Instant; import java.util.ArrayList; @@ -50,7 +49,7 @@ import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_ROUTING_REQUIRE_GROUP_SETTING; import static org.elasticsearch.cluster.routing.allocation.DataTier.ENFORCE_DEFAULT_TIER_PREFERENCE; import static org.elasticsearch.cluster.routing.allocation.DataTier.TIER_PREFERENCE; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; +import static org.elasticsearch.index.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; import static org.elasticsearch.xpack.core.ilm.OperationMode.STOPPED; import static org.elasticsearch.xpack.core.ilm.PhaseCacheManagement.updateIndicesForPolicy; import static org.elasticsearch.xpack.ilm.IndexLifecycleTransition.moveStateToNextActionAndUpdateCachedPhase; @@ -248,7 +247,7 @@ private static void refreshCachedPhaseForPhasesWithoutAllocateAction(Metadata.Bu String policyName = oldPolicy.getName(); final List managedIndices = currentState.metadata().indices().values().stream() - .filter(meta -> policyName.equals(LifecycleSettings.LIFECYCLE_NAME_SETTING.get(meta.getSettings()))) + .filter(meta -> policyName.equals(meta.getLifecycleName())) .collect(Collectors.toList()); for (IndexMetadata indexMetadata : managedIndices) { diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/ExecuteStepsUpdateTask.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/ExecuteStepsUpdateTask.java index 25db1bb72ad00..84b5bc8d33db7 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/ExecuteStepsUpdateTask.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/ExecuteStepsUpdateTask.java @@ -19,8 +19,8 @@ import org.elasticsearch.xpack.core.ilm.ClusterStateActionStep; import org.elasticsearch.xpack.core.ilm.ClusterStateWaitStep; import org.elasticsearch.xpack.core.ilm.ErrorStep; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; -import org.elasticsearch.xpack.core.ilm.Step; +import org.elasticsearch.index.LifecycleExecutionState; +import org.elasticsearch.index.Step; import org.elasticsearch.xpack.core.ilm.TerminalPolicyStep; import java.io.IOException; 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 503b587a7ddac..9695571b8a3cd 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 @@ -12,6 +12,7 @@ import org.elasticsearch.action.ActionResponse; import org.elasticsearch.client.Client; import org.elasticsearch.client.OriginSettingClient; +import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.node.DiscoveryNodes; @@ -178,7 +179,7 @@ public Collection createGuiceModules() { public List> getSettings() { return Arrays.asList( LifecycleSettings.LIFECYCLE_POLL_INTERVAL_SETTING, - LifecycleSettings.LIFECYCLE_NAME_SETTING, + IndexMetadata.LIFECYCLE_NAME_SETTING, LifecycleSettings.LIFECYCLE_ORIGINATION_DATE_SETTING, LifecycleSettings.LIFECYCLE_PARSE_ORIGINATION_DATE_SETTING, LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE_SETTING, diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleClusterStateUpdateTask.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleClusterStateUpdateTask.java index 98e66b4706344..1cf16503b3832 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleClusterStateUpdateTask.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleClusterStateUpdateTask.java @@ -12,7 +12,7 @@ import org.elasticsearch.cluster.ClusterStateTaskListener; import org.elasticsearch.common.util.concurrent.ListenableFuture; import org.elasticsearch.index.Index; -import org.elasticsearch.xpack.core.ilm.Step; +import org.elasticsearch.index.Step; /** * Base class for index lifecycle cluster state update tasks that requires implementing {@code equals} and {@code hashCode} to allow diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleFeatureSet.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleFeatureSet.java index b374150af132c..c8447ee6f8037 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleFeatureSet.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleFeatureSet.java @@ -21,7 +21,6 @@ import org.elasticsearch.xpack.core.ilm.IndexLifecycleFeatureSetUsage.PolicyStats; import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata; import org.elasticsearch.xpack.core.ilm.LifecycleAction; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.RolloverAction; import org.elasticsearch.xpack.core.ilm.SetPriorityAction; import org.elasticsearch.xpack.core.ilm.ShrinkAction; @@ -37,7 +36,7 @@ public class IndexLifecycleFeatureSet implements XPackFeatureSet { - private ClusterService clusterService; + private final ClusterService clusterService; @Inject public IndexLifecycleFeatureSet(ClusterService clusterService) { @@ -71,7 +70,7 @@ public void usage(ActionListener listener) { if (lifecycleMetadata != null) { Map policyUsage = new HashMap<>(); metadata.indices().forEach(entry -> { - String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(entry.value.getSettings()); + String policyName = entry.value.getLifecycleName(); Integer indicesManaged = policyUsage.get(policyName); if (indicesManaged == null) { indicesManaged = 1; diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunner.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunner.java index 2ca40143d2db6..f9b7d6d66f5cf 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunner.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunner.java @@ -30,11 +30,10 @@ import org.elasticsearch.xpack.core.ilm.ClusterStateActionStep; import org.elasticsearch.xpack.core.ilm.ClusterStateWaitStep; import org.elasticsearch.xpack.core.ilm.ErrorStep; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.xpack.core.ilm.PhaseCompleteStep; -import org.elasticsearch.xpack.core.ilm.Step; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step; +import org.elasticsearch.index.Step.StepKey; import org.elasticsearch.xpack.core.ilm.TerminalPolicyStep; import org.elasticsearch.xpack.ilm.history.ILMHistoryItem; import org.elasticsearch.xpack.ilm.history.ILMHistoryStore; @@ -488,7 +487,7 @@ void registerSuccessfulOperation(IndexMetadata indexMetadata) { Long origination = calculateOriginationMillis(indexMetadata); ilmHistoryStore.putAsync( ILMHistoryItem.success(indexMetadata.getIndex().getName(), - LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()), + indexMetadata.getLifecycleName(), nowSupplier.getAsLong(), origination == null ? null : (nowSupplier.getAsLong() - origination), LifecycleExecutionState.fromIndexMetadata(indexMetadata))); @@ -505,7 +504,7 @@ void registerDeleteOperation(IndexMetadata metadataBeforeDeletion) { Long origination = calculateOriginationMillis(metadataBeforeDeletion); ilmHistoryStore.putAsync( ILMHistoryItem.success(metadataBeforeDeletion.getIndex().getName(), - LifecycleSettings.LIFECYCLE_NAME_SETTING.get(metadataBeforeDeletion.getSettings()), + metadataBeforeDeletion.getLifecycleName(), nowSupplier.getAsLong(), origination == null ? null : (nowSupplier.getAsLong() - origination), LifecycleExecutionState.builder(LifecycleExecutionState.fromIndexMetadata(metadataBeforeDeletion)) @@ -526,7 +525,7 @@ void registerFailedOperation(IndexMetadata indexMetadata, Exception failure) { Long origination = calculateOriginationMillis(indexMetadata); ilmHistoryStore.putAsync( ILMHistoryItem.failure(indexMetadata.getIndex().getName(), - LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()), + indexMetadata.getLifecycleName(), nowSupplier.getAsLong(), origination == null ? null : (nowSupplier.getAsLong() - origination), LifecycleExecutionState.fromIndexMetadata(indexMetadata), diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleService.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleService.java index 371cc70de6575..a73cfec33ae6c 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleService.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleService.java @@ -36,7 +36,7 @@ import org.elasticsearch.xpack.core.XPackField; import org.elasticsearch.xpack.core.ilm.CheckShrinkReadyStep; import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.OperationMode; @@ -45,7 +45,7 @@ import org.elasticsearch.xpack.core.ilm.ShrinkAction; import org.elasticsearch.xpack.core.ilm.ShrinkStep; import org.elasticsearch.xpack.core.ilm.ShrunkShardsAllocatedStep; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import org.elasticsearch.xpack.core.scheduler.SchedulerEngine; import org.elasticsearch.xpack.ilm.history.ILMHistoryStore; @@ -99,8 +99,7 @@ public IndexLifecycleService(Settings settings, Client client, ClusterService cl } public void maybeRunAsyncAction(ClusterState clusterState, IndexMetadata indexMetadata, StepKey nextStepKey) { - String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()); - lifecycleRunner.maybeRunAsyncAction(clusterState, indexMetadata, policyName, nextStepKey); + lifecycleRunner.maybeRunAsyncAction(clusterState, indexMetadata, indexMetadata.getLifecycleName(), nextStepKey); } /** @@ -166,7 +165,7 @@ void onMaster(ClusterState clusterState) { // If we just became master, we need to kick off any async actions that // may have not been run due to master rollover for (IndexMetadata idxMeta : clusterState.metadata().indices().values()) { - String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(idxMeta.getSettings()); + String policyName = idxMeta.getLifecycleName(); if (Strings.isNullOrEmpty(policyName) == false) { final LifecycleExecutionState lifecycleState = LifecycleExecutionState.fromIndexMetadata(idxMeta); StepKey stepKey = LifecycleExecutionState.getCurrentStepKey(lifecycleState); @@ -287,6 +286,7 @@ public void applyClusterState(ClusterChangedEvent event) { policyRegistry.update(ilmMetadata); } } + policyRegistry.clearCache(event.indicesDeleted()); } private void cancelJob() { @@ -336,7 +336,7 @@ void triggerPolicies(ClusterState clusterState, boolean fromClusterStateChange) // managed by the Index Lifecycle Service they have a index.lifecycle.name setting // associated to a policy for (IndexMetadata idxMeta : clusterState.metadata().indices().values()) { - String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(idxMeta.getSettings()); + String policyName = idxMeta.getLifecycleName(); if (Strings.isNullOrEmpty(policyName) == false) { final LifecycleExecutionState lifecycleState = LifecycleExecutionState.fromIndexMetadata(idxMeta); StepKey stepKey = LifecycleExecutionState.getCurrentStepKey(lifecycleState); @@ -431,8 +431,7 @@ static Set indicesOnShuttingDownNodesInDangerousStep(ClusterState state, Set indicesPreventingShutdown = state.metadata().indices().stream() // Filter out to only consider managed indices - .filter(indexToMetadata -> Strings.hasText(LifecycleSettings.LIFECYCLE_NAME_SETTING.get( - indexToMetadata.getValue().getSettings()))) + .filter(indexToMetadata -> Strings.hasText(indexToMetadata.getValue().getLifecycleName())) // Only look at indices in the shrink action .filter(indexToMetadata -> ShrinkAction.NAME.equals(LifecycleExecutionState.fromIndexMetadata(indexToMetadata.getValue()).getAction())) diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleTransition.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleTransition.java index 1765f57fcc172..55a8ce4b169b3 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleTransition.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleTransition.java @@ -28,14 +28,14 @@ import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata; import org.elasticsearch.xpack.core.ilm.InitializePolicyContextStep; import org.elasticsearch.xpack.core.ilm.InitializePolicyException; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; import org.elasticsearch.xpack.core.ilm.LifecyclePolicyMetadata; import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.Phase; import org.elasticsearch.xpack.core.ilm.PhaseExecutionInfo; import org.elasticsearch.xpack.core.ilm.RolloverAction; -import org.elasticsearch.xpack.core.ilm.Step; +import org.elasticsearch.index.Step; import org.elasticsearch.xpack.core.ilm.TerminalPolicyStep; import java.io.IOException; @@ -48,7 +48,7 @@ import java.util.function.LongSupplier; import static org.elasticsearch.ElasticsearchException.REST_EXCEPTION_SKIP_STACK_TRACE; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; +import static org.elasticsearch.index.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; /** * The {@link IndexLifecycleTransition} class handles cluster state transitions @@ -70,8 +70,7 @@ public final class IndexLifecycleTransition { public static void validateTransition(IndexMetadata idxMeta, Step.StepKey currentStepKey, Step.StepKey newStepKey, PolicyStepsRegistry stepRegistry) { String indexName = idxMeta.getIndex().getName(); - Settings indexSettings = idxMeta.getSettings(); - String indexPolicySetting = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexSettings); + String indexPolicySetting = idxMeta.getLifecycleName(); // policy could be updated in-between execution if (Strings.isNullOrEmpty(indexPolicySetting)) { @@ -115,13 +114,11 @@ static ClusterState moveClusterStateToStep(Index index, ClusterState state, Step Step.StepKey currentStepKey = LifecycleExecutionState.getCurrentStepKey(LifecycleExecutionState.fromIndexMetadata(idxMeta)); validateTransition(idxMeta, currentStepKey, newStepKey, stepRegistry); - Settings indexSettings = idxMeta.getSettings(); - String policy = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexSettings); + String policy = idxMeta.getLifecycleName(); logger.info("moving index [{}] from [{}] to [{}] in policy [{}]", index.getName(), currentStepKey, newStepKey, policy); IndexLifecycleMetadata ilmMeta = state.metadata().custom(IndexLifecycleMetadata.TYPE); - LifecyclePolicyMetadata policyMetadata = ilmMeta.getPolicyMetadatas() - .get(LifecycleSettings.LIFECYCLE_NAME_SETTING.get(idxMeta.getSettings())); + LifecyclePolicyMetadata policyMetadata = ilmMeta.getPolicyMetadatas().get(idxMeta.getLifecycleName()); LifecycleExecutionState lifecycleState = LifecycleExecutionState.fromIndexMetadata(idxMeta); LifecycleExecutionState newLifecycleState = updateExecutionStateToStep(policyMetadata, lifecycleState, newStepKey, nowSupplier, forcePhaseDefinitionRefresh); @@ -138,8 +135,7 @@ static ClusterState moveClusterStateToErrorStep(Index index, ClusterState cluste BiFunction stepLookupFunction) throws IOException { IndexMetadata idxMeta = clusterState.getMetadata().index(index); IndexLifecycleMetadata ilmMeta = clusterState.metadata().custom(IndexLifecycleMetadata.TYPE); - LifecyclePolicyMetadata policyMetadata = ilmMeta.getPolicyMetadatas() - .get(LifecycleSettings.LIFECYCLE_NAME_SETTING.get(idxMeta.getSettings())); + LifecyclePolicyMetadata policyMetadata = ilmMeta.getPolicyMetadatas().get(idxMeta.getLifecycleName()); XContentBuilder causeXContentBuilder = JsonXContent.contentBuilder(); causeXContentBuilder.startObject(); ElasticsearchException.generateThrowableXContent(causeXContentBuilder, STACKTRACE_PARAMS, cause); @@ -197,8 +193,7 @@ static ClusterState moveClusterStateToPreviouslyFailedStep(ClusterState currentS IndexLifecycleTransition.validateTransition(indexMetadata, currentStepKey, nextStepKey, stepRegistry); IndexLifecycleMetadata ilmMeta = currentState.metadata().custom(IndexLifecycleMetadata.TYPE); - LifecyclePolicyMetadata policyMetadata = ilmMeta.getPolicyMetadatas() - .get(LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings())); + LifecyclePolicyMetadata policyMetadata = ilmMeta.getPolicyMetadatas().get(indexMetadata.getLifecycleName()); LifecycleExecutionState nextStepState = IndexLifecycleTransition.updateExecutionStateToStep(policyMetadata, lifecycleState, nextStepKey, nowSupplier, true); LifecycleExecutionState.Builder retryStepState = LifecycleExecutionState.builder(nextStepState); @@ -285,7 +280,7 @@ public static LifecycleExecutionState moveStateToNextActionAndUpdateCachedPhase( LongSupplier nowSupplier, LifecyclePolicy oldPolicy, LifecyclePolicyMetadata newPolicyMetadata, Client client, XPackLicenseState licenseState) { - String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()); + String policyName = indexMetadata.getLifecycleName(); Step.StepKey currentStepKey = LifecycleExecutionState.getCurrentStepKey(existingState); if (currentStepKey == null) { logger.warn("unable to identify what the current step is for index [{}] as part of policy [{}]. the " + @@ -419,7 +414,7 @@ private static IndexMetadata.Builder removePolicyForIndex(IndexMetadata indexMet Settings.Builder newSettings = Settings.builder().put(idxSettings); boolean notChanged = true; - notChanged &= Strings.isNullOrEmpty(newSettings.remove(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey())); + notChanged &= Strings.isNullOrEmpty(newSettings.remove(IndexMetadata.LIFECYCLE_NAME_SETTING.getKey())); notChanged &= Strings.isNullOrEmpty(newSettings.remove(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE_SETTING.getKey())); notChanged &= Strings.isNullOrEmpty(newSettings.remove(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS_SETTING.getKey())); long newSettingsVersion = notChanged ? indexMetadata.getSettingsVersion() : 1 + indexMetadata.getSettingsVersion(); diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/LifecyclePolicySecurityClient.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/LifecyclePolicySecurityClient.java index b2992f73307f8..3ca3733085117 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/LifecyclePolicySecurityClient.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/LifecyclePolicySecurityClient.java @@ -14,7 +14,7 @@ import org.elasticsearch.client.Client; import org.elasticsearch.client.support.AbstractClient; import org.elasticsearch.xpack.core.ClientHelper; -import org.elasticsearch.xpack.core.ilm.Step; +import org.elasticsearch.index.Step; import java.util.Map; diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/MoveToErrorStepUpdateTask.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/MoveToErrorStepUpdateTask.java index f83290bcd0cbd..3a351a1f8a451 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/MoveToErrorStepUpdateTask.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/MoveToErrorStepUpdateTask.java @@ -16,11 +16,9 @@ import org.elasticsearch.cluster.NotMasterException; import org.elasticsearch.cluster.coordination.FailedToCommitClusterStateException; import org.elasticsearch.cluster.metadata.IndexMetadata; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; -import org.elasticsearch.xpack.core.ilm.Step; +import org.elasticsearch.index.LifecycleExecutionState; +import org.elasticsearch.index.Step; import java.io.IOException; import java.util.function.BiFunction; @@ -58,10 +56,8 @@ public ClusterState execute(ClusterState currentState) throws IOException { // Index must have been since deleted, ignore it return currentState; } - Settings indexSettings = idxMeta.getSettings(); - LifecycleExecutionState indexILMData = LifecycleExecutionState.fromIndexMetadata(idxMeta); - if (policy.equals(LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexSettings)) - && currentStepKey.equals(LifecycleExecutionState.getCurrentStepKey(indexILMData))) { + if (policy.equals(idxMeta.getLifecycleName()) + && currentStepKey.equals(LifecycleExecutionState.getCurrentStepKey(LifecycleExecutionState.fromIndexMetadata(idxMeta)))) { return IndexLifecycleTransition.moveClusterStateToErrorStep(index, currentState, cause, nowSupplier, stepLookupFunction); } else { // either the policy has changed or the step is now diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/MoveToNextStepUpdateTask.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/MoveToNextStepUpdateTask.java index f3953c4f4008f..135425a9773ad 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/MoveToNextStepUpdateTask.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/MoveToNextStepUpdateTask.java @@ -11,11 +11,9 @@ import org.apache.logging.log4j.message.ParameterizedMessage; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; -import org.elasticsearch.xpack.core.ilm.Step; +import org.elasticsearch.index.LifecycleExecutionState; +import org.elasticsearch.index.Step; import java.util.Objects; import java.util.function.Consumer; @@ -48,10 +46,9 @@ public ClusterState doExecute(ClusterState currentState) { // Index must have been since deleted, ignore it return currentState; } - Settings indexSettings = indexMetadata.getSettings(); - LifecycleExecutionState indexILMData = LifecycleExecutionState.fromIndexMetadata(currentState.getMetadata().index(index)); - if (policy.equals(LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexSettings)) - && currentStepKey.equals(LifecycleExecutionState.getCurrentStepKey(indexILMData))) { + if (policy.equals(indexMetadata.getLifecycleName()) + && currentStepKey.equals(LifecycleExecutionState.getCurrentStepKey( + LifecycleExecutionState.fromIndexMetadata(currentState.getMetadata().index(index))))) { logger.trace("moving [{}] to next step ({})", index.getName(), nextStepKey); return IndexLifecycleTransition.moveClusterStateToStep(index, currentState, nextStepKey, nowSupplier, stepRegistry, false); } else { diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/PolicyStepsRegistry.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/PolicyStepsRegistry.java index d87cb5af10778..ae22da33e298f 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/PolicyStepsRegistry.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/PolicyStepsRegistry.java @@ -16,6 +16,7 @@ import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.core.Tuple; import org.elasticsearch.xcontent.DeprecationHandler; import org.elasticsearch.xcontent.NamedXContentRegistry; import org.elasticsearch.xcontent.XContentParseException; @@ -29,14 +30,13 @@ import org.elasticsearch.xpack.core.ilm.ErrorStep; import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata; import org.elasticsearch.xpack.core.ilm.InitializePolicyContextStep; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; import org.elasticsearch.xpack.core.ilm.LifecyclePolicyMetadata; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.Phase; import org.elasticsearch.xpack.core.ilm.PhaseCacheManagement; import org.elasticsearch.xpack.core.ilm.PhaseExecutionInfo; -import org.elasticsearch.xpack.core.ilm.Step; +import org.elasticsearch.index.Step; import org.elasticsearch.xpack.core.ilm.TerminalPolicyStep; import java.io.IOException; @@ -49,6 +49,7 @@ import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; +import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; public class PolicyStepsRegistry { @@ -91,6 +92,12 @@ Map> getStepMap() { return stepMap; } + public void clearCache(List deleted) { + for (Index index : deleted) { + cachedSteps.remove(index); + } + } + public void update(IndexLifecycleMetadata meta) { assert meta != null : "IndexLifecycleMetadata cannot be null when updating the policy steps registry"; @@ -151,7 +158,7 @@ private List getAllStepsForIndex(ClusterState state, Index index) { throw new IllegalArgumentException("index " + index + " does not exist in the current cluster state"); } final IndexMetadata indexMetadata = metadata.index(index); - final String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()); + final String policyName = indexMetadata.getLifecycleName(); final LifecyclePolicyMetadata policyMetadata = lifecyclePolicyMap.get(policyName); if (policyMetadata == null) { throw new IllegalArgumentException("the policy [" + policyName + "] for index" + index + " does not exist"); @@ -238,14 +245,20 @@ private List parseStepsFromPhase(String policy, String currentPhase, Strin return phaseSteps; } + private final Map> cachedSteps = new ConcurrentHashMap<>(); + @Nullable public Step getStep(final IndexMetadata indexMetadata, final Step.StepKey stepKey) { + final Tuple cachedStep = cachedSteps.get(indexMetadata.getIndex()); + if (cachedStep != null && cachedStep.v1() == indexMetadata && cachedStep.v2().getKey().equals(stepKey)) { + return cachedStep.v2(); + } if (ErrorStep.NAME.equals(stepKey.getName())) { return new ErrorStep(new Step.StepKey(stepKey.getPhase(), stepKey.getAction(), ErrorStep.NAME)); } final String phase = stepKey.getPhase(); - final String policyName = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + final String policyName = indexMetadata.getSettings().get(IndexMetadata.LIFECYCLE_NAME); final Index index = indexMetadata.getIndex(); if (policyName == null) { @@ -271,7 +284,9 @@ public Step getStep(final IndexMetadata indexMetadata, final Step.StepKey stepKe "] but they were not, steps: " + phaseSteps; // Return the step that matches the given stepKey or else null if we couldn't find it - return phaseSteps.stream().filter(step -> step.getKey().equals(stepKey)).findFirst().orElse(null); + final Step s = phaseSteps.stream().filter(step -> step.getKey().equals(stepKey)).findFirst().orElse(null); + cachedSteps.put(indexMetadata.getIndex(), Tuple.tuple(indexMetadata, s)); + return s; } /** diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/SetStepInfoUpdateTask.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/SetStepInfoUpdateTask.java index 620f7da7f9ee5..b09b280b5a3e3 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/SetStepInfoUpdateTask.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/SetStepInfoUpdateTask.java @@ -13,13 +13,11 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.xcontent.ToXContentObject; import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.index.Index; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; -import org.elasticsearch.xpack.core.ilm.Step; +import org.elasticsearch.index.LifecycleExecutionState; +import org.elasticsearch.index.Step; import java.io.IOException; import java.util.Objects; @@ -52,10 +50,9 @@ protected ClusterState doExecute(ClusterState currentState) throws IOException { // Index must have been since deleted, ignore it return currentState; } - Settings indexSettings = idxMeta.getSettings(); - LifecycleExecutionState indexILMData = LifecycleExecutionState.fromIndexMetadata(idxMeta); - if (policy.equals(LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexSettings)) - && Objects.equals(currentStepKey, LifecycleExecutionState.getCurrentStepKey(indexILMData))) { + if (policy.equals(idxMeta.getLifecycleName()) + && Objects.equals(currentStepKey, + LifecycleExecutionState.getCurrentStepKey(LifecycleExecutionState.fromIndexMetadata(idxMeta)))) { return IndexLifecycleTransition.addStepInfoToClusterState(index, currentState, stepInfo); } else { // either the policy has changed or the step is now diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportDeleteLifecycleAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportDeleteLifecycleAction.java index 33cb7cee781ce..5e30f403189fb 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportDeleteLifecycleAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportDeleteLifecycleAction.java @@ -32,8 +32,6 @@ import java.util.TreeMap; import java.util.stream.Collectors; -import static org.elasticsearch.xpack.core.ilm.LifecycleSettings.LIFECYCLE_NAME_SETTING; - public class TransportDeleteLifecycleAction extends TransportMasterNodeAction { @Inject @@ -51,7 +49,7 @@ protected void masterOperation(Request request, ClusterState state, ActionListen public ClusterState execute(ClusterState currentState) { String policyToDelete = request.getPolicyName(); List indicesUsingPolicy = currentState.metadata().indices().values().stream() - .filter(idxMeta -> LIFECYCLE_NAME_SETTING.get(idxMeta.getSettings()).equals(policyToDelete)) + .filter(idxMeta -> idxMeta.getLifecycleName().equals(policyToDelete)) .map(idxMeta -> idxMeta.getIndex().getName()) .collect(Collectors.toList()); if (indicesUsingPolicy.isEmpty() == false) { diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportExplainLifecycleAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportExplainLifecycleAction.java index b8001d97dd861..d69cffc281209 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportExplainLifecycleAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportExplainLifecycleAction.java @@ -31,8 +31,7 @@ import org.elasticsearch.xpack.core.ilm.ExplainLifecycleRequest; import org.elasticsearch.xpack.core.ilm.ExplainLifecycleResponse; import org.elasticsearch.xpack.core.ilm.IndexLifecycleExplainResponse; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.xpack.core.ilm.PhaseExecutionInfo; import org.elasticsearch.xpack.core.ilm.action.ExplainLifecycleAction; import org.elasticsearch.xpack.ilm.IndexLifecycleService; @@ -87,7 +86,7 @@ static IndexLifecycleExplainResponse getIndexLifecycleExplainResponse(IndexMetad NamedXContentRegistry xContentRegistry) throws IOException { Settings idxSettings = indexMetadata.getSettings(); LifecycleExecutionState lifecycleState = LifecycleExecutionState.fromIndexMetadata(indexMetadata); - String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(idxSettings); + String policyName = indexMetadata.getLifecycleName(); String currentPhase = lifecycleState.getPhase(); String stepInfo = lifecycleState.getStepInfo(); BytesArray stepInfoBytes = null; diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportMoveToStepAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportMoveToStepAction.java index 6f495a1af4212..da47965c8ef58 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportMoveToStepAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportMoveToStepAction.java @@ -24,8 +24,7 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; -import org.elasticsearch.xpack.core.ilm.Step; +import org.elasticsearch.index.Step; import org.elasticsearch.xpack.core.ilm.action.MoveToStepAction; import org.elasticsearch.xpack.core.ilm.action.MoveToStepAction.Request; import org.elasticsearch.xpack.ilm.IndexLifecycleService; @@ -51,7 +50,7 @@ protected void masterOperation(Request request, ClusterState state, ActionListen return; } - final String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()); + final String policyName = indexMetadata.getLifecycleName(); if (policyName == null) { listener.onFailure(new IllegalArgumentException("index [" + request.getIndex() + "] is not managed by ILM")); return; diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportRetryAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportRetryAction.java index ed8f21343c6bc..947ec19e6e987 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportRetryAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportRetryAction.java @@ -23,8 +23,8 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.LifecycleExecutionState; +import org.elasticsearch.index.Step.StepKey; import org.elasticsearch.xpack.core.ilm.action.RetryAction; import org.elasticsearch.xpack.core.ilm.action.RetryAction.Request; import org.elasticsearch.xpack.ilm.IndexLifecycleService; diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/history/ILMHistoryItem.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/history/ILMHistoryItem.java index 2495e6d2ef3d7..83112090bb2dc 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/history/ILMHistoryItem.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/history/ILMHistoryItem.java @@ -15,7 +15,7 @@ import org.elasticsearch.xcontent.ToXContentObject; import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.json.JsonXContent; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; +import org.elasticsearch.index.LifecycleExecutionState; import java.io.IOException; import java.util.Collections; diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/package-info.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/package-info.java index dd2e8394a436f..0db3ec6dbc4b8 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/package-info.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/package-info.java @@ -12,8 +12,8 @@ * {@link org.elasticsearch.xpack.ilm.IndexLifecycleRunner}. * * The {@link org.elasticsearch.xpack.ilm.IndexLifecycleService} goes through the indices that have ILM policies configured, retrieves - * the current execution {@link org.elasticsearch.xpack.core.ilm.Step.StepKey} from the index's - * {@link org.elasticsearch.xpack.core.ilm.LifecycleExecutionState} and dispatches the step execution to the appropriate + * the current execution {@link org.elasticsearch.index.Step.StepKey} from the index's + * {@link org.elasticsearch.index.LifecycleExecutionState} and dispatches the step execution to the appropriate * {@link org.elasticsearch.xpack.ilm.IndexLifecycleRunner} method. * This happens in: *
      @@ -47,7 +47,7 @@ * {@link org.elasticsearch.xpack.ilm.IndexLifecycleRunner#maybeRunAsyncAction( * org.elasticsearch.cluster.ClusterState, * org.elasticsearch.cluster.metadata.IndexMetadata, - * java.lang.String, org.elasticsearch.xpack.core.ilm.Step.StepKey + * java.lang.String, Step.StepKey * )} * handles the execution of the async steps {@link org.elasticsearch.xpack.core.ilm.AsyncActionStep}. * @@ -75,7 +75,7 @@ * and then rollover the index {@link org.elasticsearch.xpack.core.ilm.RolloverStep} followed by some more house-keeping steps). * * The ILM runner will advance last executed state (as indicated in - * {@link org.elasticsearch.xpack.core.ilm.LifecycleExecutionState#getStep()}) and execute the next step of the index policy as + * {@link org.elasticsearch.index.LifecycleExecutionState#getStep()}) and execute the next step of the index policy as * defined in the {@link org.elasticsearch.xpack.ilm.PolicyStepsRegistry}. * Once all the steps of a policy are executed successfully the policy execution will reach the * {@link org.elasticsearch.xpack.core.ilm.TerminalPolicyStep} and any changes made to the policy definition will not have any effect on @@ -88,10 +88,11 @@ * {@link org.elasticsearch.xpack.core.ilm.ErrorStep}. * Currently for certain periodic steps we will automatically retry the execution of the failed step until the step executes * successfully (see {@link org.elasticsearch.xpack.ilm.IndexLifecycleRunner#onErrorMaybeRetryFailedStep}). In order to see all retryable - * steps see {@link org.elasticsearch.xpack.core.ilm.Step#isRetryable()}. + * steps see {@link org.elasticsearch.index.Step#isRetryable()}. * For steps that are not retryable the failed step can manually be retried using * {@link org.elasticsearch.xpack.ilm.IndexLifecycleService#moveClusterStateToPreviouslyFailedStep}. * */ package org.elasticsearch.xpack.ilm; +import org.elasticsearch.index.Step; \ No newline at end of file diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/TransportStopSLMAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/TransportStopSLMAction.java index 689a4a176a908..b4ef5140482a8 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/TransportStopSLMAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/TransportStopSLMAction.java @@ -7,6 +7,8 @@ package org.elasticsearch.xpack.slm.action; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.master.AcknowledgedResponse; @@ -26,6 +28,8 @@ public class TransportStopSLMAction extends AcknowledgedTransportMasterNodeAction { + private static final Logger logger = LogManager.getLogger(TransportStopSLMAction.class); + @Inject public TransportStopSLMAction(TransportService transportService, ClusterService clusterService, ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) { @@ -41,6 +45,12 @@ protected void masterOperation(StopSLMAction.Request request, ClusterState state public ClusterState execute(ClusterState currentState) { return (OperationModeUpdateTask.slmMode(OperationMode.STOPPING)).execute(currentState); } + + @Override + public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) { + super.clusterStateProcessed(source, oldState, newState); + logger.info("Stopped SLM"); + } }); } diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingServiceTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingServiceTests.java index cfba5ba68a0d4..42777d05f6b58 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingServiceTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingServiceTests.java @@ -29,10 +29,9 @@ import org.elasticsearch.xpack.core.ilm.AllocateAction; import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata; import org.elasticsearch.xpack.core.ilm.LifecycleAction; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; import org.elasticsearch.xpack.core.ilm.LifecyclePolicyMetadata; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.MigrateAction; import org.elasticsearch.xpack.core.ilm.OperationMode; import org.elasticsearch.xpack.core.ilm.Phase; @@ -56,7 +55,7 @@ import static org.elasticsearch.xpack.cluster.metadata.MetadataMigrateToDataTiersRoutingService.migrateIlmPolicies; import static org.elasticsearch.xpack.cluster.metadata.MetadataMigrateToDataTiersRoutingService.migrateIndices; import static org.elasticsearch.xpack.cluster.metadata.MetadataMigrateToDataTiersRoutingService.migrateToDataTiersRouting; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; +import static org.elasticsearch.index.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.is; @@ -336,7 +335,7 @@ public void testMigrateIlmPolicyRefreshesCachedPhase() { private Settings.Builder getBaseIndexSettings() { return Settings.builder() - .put(LifecycleSettings.LIFECYCLE_NAME, lifecycleName) + .put(IndexMetadata.LIFECYCLE_NAME, lifecycleName) .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, randomIntBetween(1, 10)) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, randomIntBetween(0, 5)) .put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT); diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/ExecuteStepsUpdateTaskTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/ExecuteStepsUpdateTaskTests.java index 2af56b1c31d96..4b4cc9ce3b137 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/ExecuteStepsUpdateTaskTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/ExecuteStepsUpdateTaskTests.java @@ -24,16 +24,15 @@ import org.elasticsearch.test.NodeRoles; import org.elasticsearch.xpack.core.ilm.ErrorStep; import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; import org.elasticsearch.xpack.core.ilm.LifecyclePolicyMetadata; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.MockAction; import org.elasticsearch.xpack.core.ilm.MockStep; import org.elasticsearch.xpack.core.ilm.OperationMode; import org.elasticsearch.xpack.core.ilm.Phase; -import org.elasticsearch.xpack.core.ilm.Step; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step; +import org.elasticsearch.index.Step.StepKey; import org.elasticsearch.xpack.core.ilm.TerminalPolicyStep; import org.elasticsearch.xpack.ilm.IndexLifecycleRunnerTests.MockClusterStateActionStep; import org.elasticsearch.xpack.ilm.IndexLifecycleRunnerTests.MockClusterStateWaitStep; @@ -46,7 +45,7 @@ import java.util.HashMap; import java.util.Map; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; +import static org.elasticsearch.index.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; import static org.elasticsearch.xpack.ilm.LifecyclePolicyTestsUtils.newTestLifecyclePolicy; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; @@ -121,7 +120,7 @@ private IndexMetadata setupIndexPolicy(String policyName) { lifecycleState.setStep("init"); IndexMetadata indexMetadata = IndexMetadata.builder(indexName) .settings(settings(Version.CURRENT) - .put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + .put(IndexMetadata.LIFECYCLE_NAME, policyName)) .putCustom(ILM_CUSTOM_METADATA_KEY, lifecycleState.build().asMap()) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build(); index = indexMetadata.getIndex(); diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleFeatureSetTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleFeatureSetTests.java index d33631d1fbbb9..de47beb0a4815 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleFeatureSetTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleFeatureSetTests.java @@ -21,7 +21,6 @@ import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata; import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; import org.elasticsearch.xpack.core.ilm.LifecyclePolicyMetadata; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.OperationMode; import org.elasticsearch.xpack.core.ilm.Phase; import org.junit.Before; @@ -112,7 +111,7 @@ private ClusterState buildClusterState(List lifecyclePolicies, Metadata.Builder metadata = Metadata.builder().putCustom(IndexLifecycleMetadata.TYPE, indexLifecycleMetadata); indexPolicies.forEach((indexName, policyName) -> { - Settings indexSettings = Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, policyName) + Settings indexSettings = Settings.builder().put(IndexMetadata.LIFECYCLE_NAME, policyName) .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) .put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT).build(); diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunnerTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunnerTests.java index 1330eb8fa0d64..9fc3ce6c3ea82 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunnerTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunnerTests.java @@ -41,7 +41,7 @@ import org.elasticsearch.xpack.core.ilm.ErrorStep; import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata; import org.elasticsearch.xpack.core.ilm.LifecycleAction; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; import org.elasticsearch.xpack.core.ilm.LifecyclePolicyMetadata; import org.elasticsearch.xpack.core.ilm.LifecyclePolicyTests; @@ -55,8 +55,8 @@ import org.elasticsearch.xpack.core.ilm.PhaseExecutionInfo; import org.elasticsearch.xpack.core.ilm.RolloverAction; import org.elasticsearch.xpack.core.ilm.RolloverActionTests; -import org.elasticsearch.xpack.core.ilm.Step; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step; +import org.elasticsearch.index.Step.StepKey; import org.elasticsearch.xpack.core.ilm.TerminalPolicyStep; import org.elasticsearch.xpack.core.ilm.WaitForRolloverReadyStep; import org.elasticsearch.xpack.ilm.history.ILMHistoryItem; @@ -85,7 +85,7 @@ import static java.util.stream.Collectors.toList; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.awaitLatch; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; +import static org.elasticsearch.index.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; import static org.elasticsearch.xpack.ilm.LifecyclePolicyTestsUtils.newTestLifecyclePolicy; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; @@ -191,7 +191,7 @@ public void testRunPolicyErrorStep() { newState.setStep(ErrorStep.NAME); newState.setPhaseDefinition(phaseJson); IndexMetadata indexMetadata = IndexMetadata.builder("test") - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + .settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .putCustom(ILM_CUSTOM_METADATA_KEY, newState.build().asMap()) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)) .build(); @@ -232,7 +232,7 @@ public void testRunPolicyErrorStepOnRetryableFailedStep() { newState.setStep(ErrorStep.NAME); newState.setPhaseDefinition(phaseJson); IndexMetadata indexMetadata = IndexMetadata.builder("test") - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + .settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policyName)) .putCustom(ILM_CUSTOM_METADATA_KEY, newState.build().asMap()) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)) .build(); @@ -253,7 +253,7 @@ public void testRunStateChangePolicyWithNoNextStep() throws Exception { .put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT) .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1) - .put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + .put(IndexMetadata.LIFECYCLE_NAME, policyName)) .build(); ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool); DiscoveryNode node = clusterService.localNode(); @@ -312,7 +312,7 @@ public void testRunStateChangePolicyWithNextStep() throws Exception { .put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT) .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1) - .put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + .put(IndexMetadata.LIFECYCLE_NAME, policyName)) .putCustom(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY, les.asMap()) .build(); ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool); @@ -396,7 +396,7 @@ public void doTestRunPolicyWithFailureToReadPolicy(boolean asyncAction, boolean .put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT) .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1) - .put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + .put(IndexMetadata.LIFECYCLE_NAME, policyName)) .putCustom(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY, les.asMap()) .build(); ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool); @@ -451,7 +451,7 @@ public void testRunAsyncActionDoesNotRun() { .put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT) .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1) - .put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + .put(IndexMetadata.LIFECYCLE_NAME, policyName)) .build(); ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool); DiscoveryNode node = clusterService.localNode(); @@ -508,7 +508,7 @@ public void testRunStateChangePolicyWithAsyncActionNextStep() throws Exception { .put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT) .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1) - .put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + .put(IndexMetadata.LIFECYCLE_NAME, policyName)) .putCustom(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY, les.asMap()) .build(); ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool); @@ -582,7 +582,7 @@ public void testRunPeriodicStep() throws Exception { .put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT) .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1) - .put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + .put(IndexMetadata.LIFECYCLE_NAME, policyName)) .putCustom(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY, les.asMap()) .build(); ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool); @@ -754,7 +754,7 @@ public void testGetCurrentStep() { .put("index.number_of_shards", 1) .put("index.number_of_replicas", 0) .put("index.version.created", Version.CURRENT) - .put(LifecycleSettings.LIFECYCLE_NAME, policyName) + .put(IndexMetadata.LIFECYCLE_NAME, policyName) .build(); LifecycleExecutionState.Builder lifecycleState = LifecycleExecutionState.builder(); lifecycleState.setPhaseDefinition(phaseJson); diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleServiceTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleServiceTests.java index 86b5c51f7ba12..894cda2d64c3c 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleServiceTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleServiceTests.java @@ -37,7 +37,7 @@ import org.elasticsearch.xpack.core.ilm.CheckShrinkReadyStep; import org.elasticsearch.xpack.core.ilm.GenerateUniqueIndexNameStep; import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; import org.elasticsearch.xpack.core.ilm.LifecyclePolicyMetadata; import org.elasticsearch.xpack.core.ilm.LifecycleSettings; @@ -48,7 +48,7 @@ import org.elasticsearch.xpack.core.ilm.ShrinkAction; import org.elasticsearch.xpack.core.ilm.ShrinkStep; import org.elasticsearch.xpack.core.ilm.ShrunkShardsAllocatedStep; -import org.elasticsearch.xpack.core.ilm.Step; +import org.elasticsearch.index.Step; import org.elasticsearch.xpack.core.scheduler.SchedulerEngine; import org.junit.After; import org.junit.Before; @@ -69,7 +69,7 @@ import static java.time.Clock.systemUTC; import static org.elasticsearch.gateway.GatewayService.STATE_NOT_RECOVERED_BLOCK; import static org.elasticsearch.xpack.core.ilm.AbstractStepTestCase.randomStepKey; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; +import static org.elasticsearch.index.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; import static org.elasticsearch.xpack.ilm.LifecyclePolicyTestsUtils.newTestLifecyclePolicy; import static org.hamcrest.Matchers.equalTo; import static org.mockito.Matchers.any; @@ -148,7 +148,7 @@ public void testStoppedModeSkip() { randomNonNegativeLong(), randomNonNegativeLong())); Index index = new Index(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20)); IndexMetadata indexMetadata = IndexMetadata.builder(index.getName()) - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey(), policyName)) + .settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME_SETTING.getKey(), policyName)) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build(); ImmutableOpenMap.Builder indices = ImmutableOpenMap. builder() .fPut(index.getName(), indexMetadata); @@ -184,7 +184,7 @@ public void testRequestedStopOnShrink() { lifecycleState.setAction(mockShrinkStep.getAction()); lifecycleState.setStep(mockShrinkStep.getName()); IndexMetadata indexMetadata = IndexMetadata.builder(index.getName()) - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey(), policyName)) + .settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME_SETTING.getKey(), policyName)) .putCustom(ILM_CUSTOM_METADATA_KEY, lifecycleState.build().asMap()) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build(); ImmutableOpenMap.Builder indices = ImmutableOpenMap. builder() @@ -237,7 +237,7 @@ private void verifyCanStopWithStep(String stoppableStep) { lifecycleState.setAction(mockShrinkStep.getAction()); lifecycleState.setStep(mockShrinkStep.getName()); IndexMetadata indexMetadata = IndexMetadata.builder(index.getName()) - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey(), policyName)) + .settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME_SETTING.getKey(), policyName)) .putCustom(ILM_CUSTOM_METADATA_KEY, lifecycleState.build().asMap()) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build(); ImmutableOpenMap.Builder indices = ImmutableOpenMap. builder() @@ -281,7 +281,7 @@ public void testRequestedStopOnSafeAction() { lifecycleState.setAction(currentStepKey.getAction()); lifecycleState.setStep(currentStepKey.getName()); IndexMetadata indexMetadata = IndexMetadata.builder(index.getName()) - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey(), policyName)) + .settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME_SETTING.getKey(), policyName)) .putCustom(ILM_CUSTOM_METADATA_KEY, lifecycleState.build().asMap()) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build(); ImmutableOpenMap.Builder indices = ImmutableOpenMap. builder() @@ -413,11 +413,11 @@ public void doTestExceptionStillProcessesOtherIndices(boolean useOnMaster) { randomNonNegativeLong(), randomNonNegativeLong())); IndexMetadata i1indexMetadata = IndexMetadata.builder(index1.getName()) - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey(), policy1)) + .settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME_SETTING.getKey(), policy1)) .putCustom(ILM_CUSTOM_METADATA_KEY, i1lifecycleState.build().asMap()) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build(); IndexMetadata i2indexMetadata = IndexMetadata.builder(index2.getName()) - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey(), policy1)) + .settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME_SETTING.getKey(), policy1)) .putCustom(ILM_CUSTOM_METADATA_KEY, i2lifecycleState.build().asMap()) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build(); ImmutableOpenMap.Builder indices = ImmutableOpenMap. builder() @@ -502,7 +502,7 @@ public void testIndicesOnShuttingDownNodesInDangerousStep() { equalTo(Collections.emptySet())); IndexMetadata nonDangerousIndex = IndexMetadata.builder("no_danger") - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey(), "mypolicy")) + .settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME_SETTING.getKey(), "mypolicy")) .putCustom(ILM_CUSTOM_METADATA_KEY, LifecycleExecutionState.builder() .setPhase("warm") .setAction("shrink") @@ -511,7 +511,7 @@ public void testIndicesOnShuttingDownNodesInDangerousStep() { .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build(); IndexMetadata dangerousIndex = IndexMetadata.builder("danger") .settings(settings(Version.CURRENT) - .put(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey(), "mypolicy") + .put(IndexMetadata.LIFECYCLE_NAME_SETTING.getKey(), "mypolicy") .put(IndexMetadata.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey() + "_id", "shutdown_node")) .putCustom(ILM_CUSTOM_METADATA_KEY, LifecycleExecutionState.builder() .setPhase("warm") diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleTransitionTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleTransitionTests.java index 9e0f1bf3547c4..a46edfc7b7303 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleTransitionTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleTransitionTests.java @@ -28,7 +28,7 @@ import org.elasticsearch.xpack.core.ilm.ErrorStep; import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata; import org.elasticsearch.xpack.core.ilm.LifecycleAction; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; import org.elasticsearch.xpack.core.ilm.LifecyclePolicyMetadata; import org.elasticsearch.xpack.core.ilm.LifecyclePolicyTests; @@ -41,7 +41,7 @@ import org.elasticsearch.xpack.core.ilm.RolloverAction; import org.elasticsearch.xpack.core.ilm.RolloverStep; import org.elasticsearch.xpack.core.ilm.SetPriorityAction; -import org.elasticsearch.xpack.core.ilm.Step; +import org.elasticsearch.index.Step; import org.elasticsearch.xpack.core.ilm.WaitForRolloverReadyStep; import java.io.IOException; @@ -53,7 +53,7 @@ import java.util.function.Function; import java.util.stream.Collectors; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; +import static org.elasticsearch.index.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; import static org.elasticsearch.xpack.core.ilm.PhaseCacheManagement.eligibleToCheckForRefresh; import static org.elasticsearch.xpack.core.ilm.PhaseCacheManagement.refreshPhaseDefinition; import static org.elasticsearch.xpack.ilm.IndexLifecycleRunnerTests.createOneStepPolicyStepRegistry; @@ -82,7 +82,7 @@ public void testMoveClusterStateToNextStep() { // test going from null lifecycle settings to next step ClusterState clusterState = buildClusterState(indexName, Settings.builder() - .put(LifecycleSettings.LIFECYCLE_NAME, policy.getName()), LifecycleExecutionState.builder().build(), policyMetadatas); + .put(IndexMetadata.LIFECYCLE_NAME, policy.getName()), LifecycleExecutionState.builder().build(), policyMetadatas); Index index = clusterState.metadata().index(indexName).getIndex(); PolicyStepsRegistry stepsRegistry = createOneStepPolicyStepRegistry(policy.getName(), new MockStep(nextStep, nextStep)); @@ -96,7 +96,7 @@ public void testMoveClusterStateToNextStep() { lifecycleState.setStep(currentStep.getName()); // test going from set currentStep settings to nextStep Settings.Builder indexSettingsBuilder = Settings.builder() - .put(LifecycleSettings.LIFECYCLE_NAME, policy.getName()); + .put(IndexMetadata.LIFECYCLE_NAME, policy.getName()); if (randomBoolean()) { lifecycleState.setStepInfo(randomAlphaOfLength(20)); } @@ -120,7 +120,7 @@ public void testMoveClusterStateToNextStepSamePhase() { ClusterState clusterState = buildClusterState(indexName, Settings.builder() - .put(LifecycleSettings.LIFECYCLE_NAME, policy.getName()), + .put(IndexMetadata.LIFECYCLE_NAME, policy.getName()), LifecycleExecutionState.builder() .setPhase(currentStep.getPhase()) .setAction(currentStep.getAction()) @@ -142,7 +142,7 @@ public void testMoveClusterStateToNextStepSamePhase() { } Settings.Builder indexSettingsBuilder = Settings.builder() - .put(LifecycleSettings.LIFECYCLE_NAME, policy.getName()); + .put(IndexMetadata.LIFECYCLE_NAME, policy.getName()); clusterState = buildClusterState(indexName, indexSettingsBuilder, lifecycleState.build(), policyMetadatas); index = clusterState.metadata().index(indexName).getIndex(); @@ -163,7 +163,7 @@ public void testMoveClusterStateToNextStepSameAction() { ClusterState clusterState = buildClusterState(indexName, Settings.builder() - .put(LifecycleSettings.LIFECYCLE_NAME, policy.getName()), + .put(IndexMetadata.LIFECYCLE_NAME, policy.getName()), LifecycleExecutionState.builder() .setPhase(currentStep.getPhase()) .setAction(currentStep.getAction()) @@ -185,7 +185,7 @@ public void testMoveClusterStateToNextStepSameAction() { } Settings.Builder indexSettingsBuilder = Settings.builder() - .put(LifecycleSettings.LIFECYCLE_NAME, policy.getName()); + .put(IndexMetadata.LIFECYCLE_NAME, policy.getName()); clusterState = buildClusterState(indexName, indexSettingsBuilder, lifecycleState.build(), policyMetadatas); index = clusterState.metadata().index(indexName).getIndex(); @@ -214,7 +214,7 @@ public void testSuccessfulValidatedMoveClusterStateToNextStep() { lifecycleState.setAction(currentStepKey.getAction()); lifecycleState.setStep(currentStepKey.getName()); - Settings.Builder indexSettingsBuilder = Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, policyName); + Settings.Builder indexSettingsBuilder = Settings.builder().put(IndexMetadata.LIFECYCLE_NAME, policyName); ClusterState clusterState = buildClusterState(indexName, indexSettingsBuilder, lifecycleState.build(), policyMetadatas); Index index = clusterState.metadata().index(indexName).getIndex(); ClusterState newClusterState = IndexLifecycleTransition.moveClusterStateToStep(index, clusterState, @@ -231,7 +231,7 @@ public void testValidatedMoveClusterStateToNextStepWithoutPolicy() { Step step = new MockStep(nextStepKey, nextStepKey); PolicyStepsRegistry stepRegistry = createOneStepPolicyStepRegistry(policyName, step); - Settings.Builder indexSettingsBuilder = Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, randomBoolean() ? "" : null); + Settings.Builder indexSettingsBuilder = Settings.builder().put(IndexMetadata.LIFECYCLE_NAME, randomBoolean() ? "" : null); LifecycleExecutionState.Builder lifecycleState = LifecycleExecutionState.builder(); lifecycleState.setPhase(currentStepKey.getPhase()); lifecycleState.setAction(currentStepKey.getAction()); @@ -253,7 +253,7 @@ public void testValidatedMoveClusterStateToNextStepInvalidNextStep() { Step step = new MockStep(currentStepKey, nextStepKey); PolicyStepsRegistry stepRegistry = createOneStepPolicyStepRegistry(policyName, step); - Settings.Builder indexSettingsBuilder = Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, policyName); + Settings.Builder indexSettingsBuilder = Settings.builder().put(IndexMetadata.LIFECYCLE_NAME, policyName); LifecycleExecutionState.Builder lifecycleState = LifecycleExecutionState.builder(); lifecycleState.setPhase(currentStepKey.getPhase()); lifecycleState.setAction(currentStepKey.getAction()); @@ -317,7 +317,7 @@ public void testRemovePolicyForIndex() { String oldPolicyName = "old_policy"; Step.StepKey currentStep = new Step.StepKey(randomAlphaOfLength(10), MockAction.NAME, randomAlphaOfLength(10)); LifecyclePolicy oldPolicy = createPolicy(oldPolicyName, currentStep, null); - Settings.Builder indexSettingsBuilder = Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, oldPolicyName); + Settings.Builder indexSettingsBuilder = Settings.builder().put(IndexMetadata.LIFECYCLE_NAME, oldPolicyName); LifecycleExecutionState.Builder lifecycleState = LifecycleExecutionState.builder(); lifecycleState.setPhase(currentStep.getPhase()); lifecycleState.setAction(currentStep.getAction()); @@ -356,7 +356,7 @@ public void testRemovePolicyForIndexIndexDoesntExist() { String oldPolicyName = "old_policy"; LifecyclePolicy oldPolicy = newTestLifecyclePolicy(oldPolicyName, Collections.emptyMap()); Step.StepKey currentStep = AbstractStepTestCase.randomStepKey(); - Settings.Builder indexSettingsBuilder = Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, oldPolicyName); + Settings.Builder indexSettingsBuilder = Settings.builder().put(IndexMetadata.LIFECYCLE_NAME, oldPolicyName); LifecycleExecutionState.Builder lifecycleState = LifecycleExecutionState.builder(); lifecycleState.setPhase(currentStep.getPhase()); lifecycleState.setAction(currentStep.getAction()); @@ -381,7 +381,7 @@ public void testRemovePolicyForIndexIndexInUnsafe() { String oldPolicyName = "old_policy"; Step.StepKey currentStep = new Step.StepKey(randomAlphaOfLength(10), MockAction.NAME, randomAlphaOfLength(10)); LifecyclePolicy oldPolicy = createPolicy(oldPolicyName, null, currentStep); - Settings.Builder indexSettingsBuilder = Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, oldPolicyName); + Settings.Builder indexSettingsBuilder = Settings.builder().put(IndexMetadata.LIFECYCLE_NAME, oldPolicyName); LifecycleExecutionState.Builder lifecycleState = LifecycleExecutionState.builder(); lifecycleState.setPhase(currentStep.getPhase()); lifecycleState.setAction(currentStep.getAction()); @@ -406,7 +406,7 @@ public void testRemovePolicyWithIndexingComplete() { Step.StepKey currentStep = new Step.StepKey(randomAlphaOfLength(10), MockAction.NAME, randomAlphaOfLength(10)); LifecyclePolicy oldPolicy = createPolicy(oldPolicyName, null, currentStep); Settings.Builder indexSettingsBuilder = Settings.builder() - .put(LifecycleSettings.LIFECYCLE_NAME, oldPolicyName) + .put(IndexMetadata.LIFECYCLE_NAME, oldPolicyName) .put(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, true); LifecycleExecutionState.Builder lifecycleState = LifecycleExecutionState.builder(); lifecycleState.setPhase(currentStep.getPhase()); @@ -559,7 +559,7 @@ public void testMoveClusterStateToFailedStep() { PolicyStepsRegistry policyRegistry = createOneStepPolicyStepRegistry(policyName, step); Settings.Builder indexSettingsBuilder = Settings.builder() - .put(LifecycleSettings.LIFECYCLE_NAME, policyName); + .put(IndexMetadata.LIFECYCLE_NAME, policyName); LifecycleExecutionState.Builder lifecycleState = LifecycleExecutionState.builder(); lifecycleState.setPhase(errorStepKey.getPhase()); lifecycleState.setPhaseTime(now); @@ -595,7 +595,7 @@ public void testMoveClusterStateToFailedStepWithUnknownStep() { PolicyStepsRegistry policyRegistry = createOneStepPolicyStepRegistry(policyName, step); Settings.Builder indexSettingsBuilder = Settings.builder() - .put(LifecycleSettings.LIFECYCLE_NAME, policyName); + .put(IndexMetadata.LIFECYCLE_NAME, policyName); LifecycleExecutionState.Builder lifecycleState = LifecycleExecutionState.builder(); lifecycleState.setPhase(errorStepKey.getPhase()); lifecycleState.setPhaseTime(now); @@ -633,7 +633,7 @@ public void testMoveClusterStateToFailedStepInvalidPolicySetting() { Step step = new MockStep(failedStepKey, null); PolicyStepsRegistry policyRegistry = createOneStepPolicyStepRegistry(policyName, step); Settings.Builder indexSettingsBuilder = Settings.builder() - .put(LifecycleSettings.LIFECYCLE_NAME, (String) null); + .put(IndexMetadata.LIFECYCLE_NAME, (String) null); LifecycleExecutionState.Builder lifecycleState = LifecycleExecutionState.builder(); lifecycleState.setPhase(errorStepKey.getPhase()); lifecycleState.setAction(errorStepKey.getAction()); @@ -654,7 +654,7 @@ public void testMoveClusterStateToFailedNotOnError() { Step step = new MockStep(failedStepKey, null); PolicyStepsRegistry policyRegistry = createOneStepPolicyStepRegistry(policyName, step); Settings.Builder indexSettingsBuilder = Settings.builder() - .put(LifecycleSettings.LIFECYCLE_NAME, (String) null); + .put(IndexMetadata.LIFECYCLE_NAME, (String) null); LifecycleExecutionState.Builder lifecycleState = LifecycleExecutionState.builder(); lifecycleState.setPhase(failedStepKey.getPhase()); lifecycleState.setAction(failedStepKey.getAction()); @@ -680,7 +680,7 @@ public void testMoveClusterStateToPreviouslyFailedStepAsAutomaticRetry() { PolicyStepsRegistry policyRegistry = createOneStepPolicyStepRegistry(policyName, retryableStep); Settings.Builder indexSettingsBuilder = Settings.builder() - .put(LifecycleSettings.LIFECYCLE_NAME, policyName); + .put(IndexMetadata.LIFECYCLE_NAME, policyName); LifecycleExecutionState.Builder lifecycleState = LifecycleExecutionState.builder(); lifecycleState.setPhase(errorStepKey.getPhase()); lifecycleState.setPhaseTime(now); @@ -972,7 +972,7 @@ public static void assertIndexNotManagedByILM(ClusterState clusterState, Index i assertNotNull(indexMetadata); Settings indexSettings = indexMetadata.getSettings(); assertNotNull(indexSettings); - assertFalse(LifecycleSettings.LIFECYCLE_NAME_SETTING.exists(indexSettings)); + assertFalse(IndexMetadata.LIFECYCLE_NAME_SETTING.exists(indexSettings)); assertFalse(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS_SETTING.exists(indexSettings)); assertFalse(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE_SETTING.exists(indexSettings)); } @@ -1011,7 +1011,7 @@ public static void assertClusterStateOnNextStep(ClusterState oldClusterState, In private IndexMetadata buildIndexMetadata(String policy, LifecycleExecutionState.Builder lifecycleState) { return IndexMetadata.builder("index") - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policy)) + .settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, policy)) .numberOfShards(randomIntBetween(1, 5)) .numberOfReplicas(randomIntBetween(0, 5)) .putCustom(ILM_CUSTOM_METADATA_KEY, lifecycleState.build().asMap()) diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/MoveToErrorStepUpdateTaskTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/MoveToErrorStepUpdateTaskTests.java index 858c57cefbe70..edcb2f9c8a6ac 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/MoveToErrorStepUpdateTaskTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/MoveToErrorStepUpdateTaskTests.java @@ -21,20 +21,19 @@ import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.ilm.ErrorStep; import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; import org.elasticsearch.xpack.core.ilm.LifecyclePolicyMetadata; import org.elasticsearch.xpack.core.ilm.LifecyclePolicyTests; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.MockStep; import org.elasticsearch.xpack.core.ilm.OperationMode; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step.StepKey; import org.junit.Before; import java.io.IOException; import java.util.Collections; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; +import static org.elasticsearch.index.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.nullValue; @@ -52,7 +51,7 @@ public void setupClusterState() { LifecyclePolicy lifecyclePolicy = LifecyclePolicyTests.randomTestLifecyclePolicy(policy); IndexMetadata indexMetadata = IndexMetadata.builder(randomAlphaOfLength(5)) .settings(settings(Version.CURRENT) - .put(LifecycleSettings.LIFECYCLE_NAME, policy)) + .put(IndexMetadata.LIFECYCLE_NAME, policy)) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build(); index = indexMetadata.getIndex(); IndexLifecycleMetadata ilmMeta = new IndexLifecycleMetadata( @@ -123,7 +122,7 @@ private void setStatePolicy(String policy) { clusterState = ClusterState.builder(clusterState) .metadata(Metadata.builder(clusterState.metadata()) .updateSettings(Settings.builder() - .put(LifecycleSettings.LIFECYCLE_NAME, policy).build(), index.getName())).build(); + .put(IndexMetadata.LIFECYCLE_NAME, policy).build(), index.getName())).build(); } private void setStateToKey(StepKey stepKey) { LifecycleExecutionState.Builder lifecycleState = LifecycleExecutionState.builder( diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/MoveToNextStepUpdateTaskTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/MoveToNextStepUpdateTaskTests.java index dac83e49a0ef2..db51a4f326595 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/MoveToNextStepUpdateTaskTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/MoveToNextStepUpdateTaskTests.java @@ -17,21 +17,20 @@ import org.elasticsearch.index.Index; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; import org.elasticsearch.xpack.core.ilm.LifecyclePolicyMetadata; import org.elasticsearch.xpack.core.ilm.LifecyclePolicyTests; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.OperationMode; -import org.elasticsearch.xpack.core.ilm.Step; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.Step; +import org.elasticsearch.index.Step.StepKey; import org.junit.Before; import java.util.Collections; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; +import static org.elasticsearch.index.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; import static org.hamcrest.Matchers.equalTo; public class MoveToNextStepUpdateTaskTests extends ESTestCase { @@ -46,7 +45,7 @@ public void setupClusterState() { policy = randomAlphaOfLength(10); IndexMetadata indexMetadata = IndexMetadata.builder(randomAlphaOfLength(5)) .settings(settings(Version.CURRENT) - .put(LifecycleSettings.LIFECYCLE_NAME, policy)) + .put(IndexMetadata.LIFECYCLE_NAME, policy)) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build(); index = indexMetadata.getIndex(); lifecyclePolicy = LifecyclePolicyTests.randomTestLifecyclePolicy(policy); @@ -160,7 +159,7 @@ private void setStatePolicy(String policy) { clusterState = ClusterState.builder(clusterState) .metadata(Metadata.builder(clusterState.metadata()) .updateSettings(Settings.builder() - .put(LifecycleSettings.LIFECYCLE_NAME, policy).build(), index.getName())).build(); + .put(IndexMetadata.LIFECYCLE_NAME, policy).build(), index.getName())).build(); } private void setStateToKey(StepKey stepKey, long now) { diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/PolicyStepsRegistryTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/PolicyStepsRegistryTests.java index 9dcd515d4d49d..139b980f5faea 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/PolicyStepsRegistryTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/PolicyStepsRegistryTests.java @@ -29,11 +29,10 @@ import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata; import org.elasticsearch.xpack.core.ilm.InitializePolicyContextStep; import org.elasticsearch.xpack.core.ilm.LifecycleAction; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; import org.elasticsearch.xpack.core.ilm.LifecyclePolicyMetadata; import org.elasticsearch.xpack.core.ilm.LifecyclePolicyTests; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.MigrateAction; import org.elasticsearch.xpack.core.ilm.MockStep; import org.elasticsearch.xpack.core.ilm.OperationMode; @@ -41,7 +40,7 @@ import org.elasticsearch.xpack.core.ilm.PhaseExecutionInfo; import org.elasticsearch.xpack.core.ilm.ShrinkAction; import org.elasticsearch.xpack.core.ilm.ShrinkStep; -import org.elasticsearch.xpack.core.ilm.Step; +import org.elasticsearch.index.Step; import org.mockito.Mockito; import java.util.Collections; @@ -51,7 +50,7 @@ import java.util.SortedMap; import java.util.TreeMap; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; +import static org.elasticsearch.index.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.sameInstance; @@ -102,7 +101,7 @@ public void testGetStep() { .put("index.number_of_shards", 1) .put("index.number_of_replicas", 0) .put("index.version.created", Version.CURRENT) - .put(LifecycleSettings.LIFECYCLE_NAME, "policy") + .put(IndexMetadata.LIFECYCLE_NAME, "policy") .build()) .putCustom(ILM_CUSTOM_METADATA_KEY, lifecycleState.build().asMap()) .build(); @@ -142,7 +141,7 @@ public void testGetStepForIndexWithNoPhaseGetsInitializationStep() { .put("index.number_of_shards", 1) .put("index.number_of_replicas", 0) .put("index.version.created", Version.CURRENT) - .put(LifecycleSettings.LIFECYCLE_NAME, "policy") + .put(IndexMetadata.LIFECYCLE_NAME, "policy") .build()) .build(); SortedMap metas = new TreeMap<>(); @@ -170,7 +169,7 @@ public void testGetStepUnknownStepKey() { .put("index.number_of_shards", 1) .put("index.number_of_replicas", 0) .put("index.version.created", Version.CURRENT) - .put(LifecycleSettings.LIFECYCLE_NAME, "policy") + .put(IndexMetadata.LIFECYCLE_NAME, "policy") .build()) .putCustom(ILM_CUSTOM_METADATA_KEY, lifecycleState.build().asMap()) .build(); @@ -209,7 +208,7 @@ public void testUpdateFromNothingToSomethingToNothing() throws Exception { .put("index.number_of_shards", 1) .put("index.number_of_replicas", 0) .put("index.version.created", Version.CURRENT.id) - .put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + .put(IndexMetadata.LIFECYCLE_NAME, policyName)) .putCustom(ILM_CUSTOM_METADATA_KEY, lifecycleState.build().asMap())) .build(); try (XContentBuilder builder = JsonXContent.contentBuilder()) { @@ -360,7 +359,7 @@ public void testUpdatePolicyButNoPhaseChangeIndexStepsDontChange() throws Except .put("index.number_of_shards", 1) .put("index.number_of_replicas", 0) .put("index.version.created", Version.CURRENT.id) - .put(LifecycleSettings.LIFECYCLE_NAME, policyName)) + .put(IndexMetadata.LIFECYCLE_NAME, policyName)) .putCustom(ILM_CUSTOM_METADATA_KEY, lifecycleState.build().asMap())) .build(); try (XContentBuilder builder = JsonXContent.contentBuilder()) { diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/SetStepInfoUpdateTaskTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/SetStepInfoUpdateTaskTests.java index 1e1dd8963bc5f..a98aea6ba621b 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/SetStepInfoUpdateTaskTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/SetStepInfoUpdateTaskTests.java @@ -26,12 +26,11 @@ import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.MockLogAppender; import org.elasticsearch.test.junit.annotations.TestLogging; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; -import org.elasticsearch.xpack.core.ilm.Step.StepKey; +import org.elasticsearch.index.LifecycleExecutionState; +import org.elasticsearch.index.Step.StepKey; import org.junit.Before; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; +import static org.elasticsearch.index.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.sameInstance; @@ -47,7 +46,7 @@ public void setupClusterState() { policy = randomAlphaOfLength(10); IndexMetadata indexMetadata = IndexMetadata.builder(randomAlphaOfLength(5)) .settings(settings(Version.CURRENT) - .put(LifecycleSettings.LIFECYCLE_NAME, policy)) + .put(IndexMetadata.LIFECYCLE_NAME, policy)) .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build(); index = indexMetadata.getIndex(); Metadata metadata = Metadata.builder() @@ -142,7 +141,7 @@ private void setStatePolicy(String policy) { clusterState = ClusterState.builder(clusterState) .metadata(Metadata.builder(clusterState.metadata()) .updateSettings(Settings.builder() - .put(LifecycleSettings.LIFECYCLE_NAME, policy).build(), index.getName())).build(); + .put(IndexMetadata.LIFECYCLE_NAME, policy).build(), index.getName())).build(); } private void setStateToKey(StepKey stepKey) { diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/action/TransportExplainLifecycleActionTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/action/TransportExplainLifecycleActionTests.java index 5e1018cdb2b70..87e21984eb4db 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/action/TransportExplainLifecycleActionTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/action/TransportExplainLifecycleActionTests.java @@ -15,15 +15,14 @@ import org.elasticsearch.xpack.core.ilm.ErrorStep; import org.elasticsearch.xpack.core.ilm.IndexLifecycleExplainResponse; import org.elasticsearch.xpack.core.ilm.LifecycleAction; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.xpack.core.ilm.RolloverAction; import org.elasticsearch.xpack.core.ilm.WaitForRolloverReadyStep; import org.elasticsearch.xpack.ilm.IndexLifecycleService; import java.io.IOException; -import static org.elasticsearch.xpack.core.ilm.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; +import static org.elasticsearch.index.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY; import static org.elasticsearch.xpack.ilm.action.TransportExplainLifecycleAction.getIndexLifecycleExplainResponse; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; @@ -70,7 +69,7 @@ public void testGetIndexLifecycleExplainResponse() throws IOException { .setPhaseDefinition(PHASE_DEFINITION); String indexInErrorStep = "index_in_error"; IndexMetadata meta = IndexMetadata.builder(indexInErrorStep) - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, "my-policy")) + .settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, "my-policy")) .numberOfShards(randomIntBetween(1, 5)) .numberOfReplicas(randomIntBetween(0, 5)) .putCustom(ILM_CUSTOM_METADATA_KEY, errorStepState.build().asMap()) @@ -96,7 +95,7 @@ public void testGetIndexLifecycleExplainResponse() throws IOException { String indexInCheckRolloverStep = "index_in_check_rollover"; IndexMetadata meta = IndexMetadata.builder(indexInCheckRolloverStep) - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, "my-policy")) + .settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, "my-policy")) .numberOfShards(randomIntBetween(1, 5)) .numberOfReplicas(randomIntBetween(0, 5)) .putCustom(ILM_CUSTOM_METADATA_KEY, checkRolloverReadyStepState.build().asMap()) @@ -120,7 +119,7 @@ public void testGetIndexLifecycleExplainResponse() throws IOException { String indexWithMissingPolicy = "index_with_missing_policy"; IndexMetadata meta = IndexMetadata.builder(indexWithMissingPolicy) - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, "random-policy")) + .settings(settings(Version.CURRENT).put(IndexMetadata.LIFECYCLE_NAME, "random-policy")) .numberOfShards(randomIntBetween(1, 5)) .numberOfReplicas(randomIntBetween(0, 5)) .build(); diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/history/ILMHistoryItemTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/history/ILMHistoryItemTests.java index 46a2b767480b1..4be9371d42d0d 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/history/ILMHistoryItemTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/history/ILMHistoryItemTests.java @@ -11,7 +11,7 @@ import org.elasticsearch.xcontent.ToXContent; import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; +import org.elasticsearch.index.LifecycleExecutionState; import java.io.IOException; diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/history/ILMHistoryStoreTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/history/ILMHistoryStoreTests.java index 23d4a29ae00fc..3de25458452a4 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/history/ILMHistoryStoreTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/history/ILMHistoryStoreTests.java @@ -36,7 +36,7 @@ import org.elasticsearch.test.client.NoOpClient; import org.elasticsearch.threadpool.TestThreadPool; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.xpack.core.ilm.LifecycleExecutionState; +import org.elasticsearch.index.LifecycleExecutionState; import org.elasticsearch.xpack.core.template.IndexTemplateConfig; import org.hamcrest.Matchers; import org.junit.After; diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/task/AbstractJobPersistentTasksExecutorTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/task/AbstractJobPersistentTasksExecutorTests.java index dfecf00676514..0030c1ddf41b1 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/task/AbstractJobPersistentTasksExecutorTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/task/AbstractJobPersistentTasksExecutorTests.java @@ -55,7 +55,7 @@ public void testVerifyIndicesPrimaryShardsAreActive() { MlMetaIndex.indexName(), MlConfigIndex.indexName()).size()); - metadata = new Metadata.Builder(cs.metadata()); + metadata = Metadata.builder(cs.metadata()); routingTable = new RoutingTable.Builder(cs.routingTable()); String indexToRemove = randomFrom(resolver.concreteIndexNames(cs, IndicesOptions.lenientExpandOpen(), ".ml-anomalies-shared", diff --git a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/cache/blob/SearchableSnapshotsBlobStoreCacheIntegTests.java b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/cache/blob/SearchableSnapshotsBlobStoreCacheIntegTests.java index 7254eb56bb91e..05972e4f0e259 100644 --- a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/cache/blob/SearchableSnapshotsBlobStoreCacheIntegTests.java +++ b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/cache/blob/SearchableSnapshotsBlobStoreCacheIntegTests.java @@ -36,7 +36,6 @@ import org.elasticsearch.plugins.ClusterPlugin; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.reindex.ReindexPlugin; -import org.elasticsearch.snapshots.SearchableSnapshotsSettings; import org.elasticsearch.snapshots.SnapshotId; import org.elasticsearch.test.InternalTestCluster; import org.elasticsearch.xcontent.XContentBuilder; @@ -412,7 +411,7 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing @Override public Decision canAllocate(ShardRouting shardRouting, RoutingAllocation allocation) { final IndexMetadata indexMetadata = allocation.metadata().index(shardRouting.index()); - if (SearchableSnapshotsSettings.isSearchableSnapshotStore(indexMetadata.getSettings()) == false) { + if (indexMetadata.isSearchableSnapshotStore() == false) { return allocation.decision(Decision.YES, name, "index is not a searchable snapshot shard - can allocate"); } if (allocation.metadata().hasIndex(SNAPSHOT_BLOB_CACHE_INDEX) == false) { diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsUsageTracker.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsUsageTracker.java index 054afb0519cff..38effe491d674 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsUsageTracker.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsUsageTracker.java @@ -10,7 +10,6 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.license.XPackLicenseState; -import org.elasticsearch.snapshots.SearchableSnapshotsSettings; import java.util.function.Supplier; @@ -35,7 +34,7 @@ public void run() { private static boolean hasSearchableSnapshotsIndices(ClusterState state) { for (IndexMetadata indexMetadata : state.metadata()) { - if (SearchableSnapshotsSettings.isSearchableSnapshotStore(indexMetadata.getSettings())) { + if (indexMetadata.isSearchableSnapshotStore()) { return true; } } diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/AbstractTransportSearchableSnapshotsAction.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/AbstractTransportSearchableSnapshotsAction.java index 119c55bd66777..7c8ec61c6373c 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/AbstractTransportSearchableSnapshotsAction.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/AbstractTransportSearchableSnapshotsAction.java @@ -21,11 +21,9 @@ import org.elasticsearch.cluster.routing.ShardsIterator; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.Writeable; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.license.XPackLicenseState; -import org.elasticsearch.snapshots.SearchableSnapshotsSettings; import org.elasticsearch.tasks.Task; import org.elasticsearch.transport.TransportService; import org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshots; @@ -95,8 +93,7 @@ protected ShardsIterator shards(ClusterState state, Request request, String[] co for (String concreteIndex : concreteIndices) { IndexMetadata indexMetaData = state.metadata().index(concreteIndex); if (indexMetaData != null) { - Settings indexSettings = indexMetaData.getSettings(); - if (SearchableSnapshotsSettings.isSearchableSnapshotStore(indexSettings)) { + if (indexMetaData.isSearchableSnapshotStore()) { searchableSnapshotIndices.add(concreteIndex); } } diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/TransportMountSearchableSnapshotAction.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/TransportMountSearchableSnapshotAction.java index 569d1c585b547..f7516209d267d 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/TransportMountSearchableSnapshotAction.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/TransportMountSearchableSnapshotAction.java @@ -41,7 +41,6 @@ import org.elasticsearch.snapshots.SnapshotId; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider; import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotAction; import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotRequest; import org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshots; @@ -59,7 +58,6 @@ import static org.elasticsearch.index.IndexModule.INDEX_RECOVERY_TYPE_SETTING; import static org.elasticsearch.index.IndexModule.INDEX_STORE_TYPE_SETTING; import static org.elasticsearch.snapshots.SearchableSnapshotsSettings.SEARCHABLE_SNAPSHOT_STORE_TYPE; -import static org.elasticsearch.snapshots.SearchableSnapshotsSettings.isSearchableSnapshotStore; /** * Action that mounts a snapshot as a searchable snapshot, by converting the mount request into a restore request with specific settings @@ -72,9 +70,9 @@ public class TransportMountSearchableSnapshotAction extends TransportMasterNodeA RestoreSnapshotResponse> { private static final Collection> DATA_TIER_ALLOCATION_SETTINGS = List.of( - DataTierAllocationDecider.INDEX_ROUTING_EXCLUDE_SETTING, - DataTierAllocationDecider.INDEX_ROUTING_INCLUDE_SETTING, - DataTierAllocationDecider.INDEX_ROUTING_REQUIRE_SETTING, + IndexMetadata.INDEX_ROUTING_EXCLUDE_SETTING, + IndexMetadata.INDEX_ROUTING_INCLUDE_SETTING, + IndexMetadata.INDEX_ROUTING_REQUIRE_SETTING, DataTier.TIER_PREFERENCE_SETTING ); @@ -203,7 +201,7 @@ protected void masterOperation( final SnapshotId snapshotId = matchingSnapshotId.get(); final IndexMetadata indexMetadata = repository.getSnapshotIndexMetaData(repoData, snapshotId, indexId); - if (isSearchableSnapshotStore(indexMetadata.getSettings())) { + if (indexMetadata.isSearchableSnapshotStore()) { throw new IllegalArgumentException( String.format( Locale.ROOT, diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/SearchableSnapshotAllocator.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/SearchableSnapshotAllocator.java index 2dd0474990907..ba1db067b0abc 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/SearchableSnapshotAllocator.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/SearchableSnapshotAllocator.java @@ -43,7 +43,6 @@ import org.elasticsearch.gateway.ReplicaShardAllocator; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.repositories.IndexId; -import org.elasticsearch.snapshots.SearchableSnapshotsSettings; import org.elasticsearch.snapshots.Snapshot; import org.elasticsearch.snapshots.SnapshotId; import org.elasticsearch.xpack.searchablesnapshots.action.cache.TransportSearchableSnapshotCacheStoresAction; @@ -108,8 +107,7 @@ public SearchableSnapshotAllocator(Client client, RerouteService rerouteService, public void beforeAllocation(RoutingAllocation allocation) { boolean hasPartialIndices = false; for (IndexMetadata indexMetadata : allocation.metadata()) { - final Settings indexSettings = indexMetadata.getSettings(); - if (SearchableSnapshotsSettings.isPartialSearchableSnapshotIndex(indexSettings)) { + if (indexMetadata.isPartialSearchableSnapshotStore()) { hasPartialIndices = true; break; } diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/SearchableSnapshotIndexEventListener.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/SearchableSnapshotIndexEventListener.java index 35d2243738239..b806150795829 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/SearchableSnapshotIndexEventListener.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/SearchableSnapshotIndexEventListener.java @@ -112,7 +112,7 @@ private static void associateNewEmptyTranslogWithIndex(IndexShard indexShard) { public void beforeIndexRemoved(IndexService indexService, IndexRemovalReason reason) { if (shouldEvictCacheFiles(reason)) { final IndexSettings indexSettings = indexService.getIndexSettings(); - if (isSearchableSnapshotStore(indexSettings.getSettings())) { + if (indexService.getMetadata().isSearchableSnapshotStore()) { for (IndexShard indexShard : indexService) { final ShardId shardId = indexShard.shardId(); diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/DedicatedFrozenNodeAllocationDecider.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/DedicatedFrozenNodeAllocationDecider.java index 0c02f130cf480..7306b506753c7 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/DedicatedFrozenNodeAllocationDecider.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/DedicatedFrozenNodeAllocationDecider.java @@ -15,8 +15,6 @@ import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.Decision; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.snapshots.SearchableSnapshotsSettings; import static org.elasticsearch.cluster.node.DiscoveryNodeRole.DATA_FROZEN_NODE_ROLE; @@ -81,8 +79,7 @@ private Decision canAllocateToNode(IndexMetadata indexMetadata, DiscoveryNode di return YES_NOT_DEDICATED_FROZEN_NODE; } - final Settings indexSettings = indexMetadata.getSettings(); - if (SearchableSnapshotsSettings.isPartialSearchableSnapshotIndex(indexSettings)) { + if (indexMetadata.isPartialSearchableSnapshotStore()) { return YES_IS_PARTIAL_SEARCHABLE_SNAPSHOT; } diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/HasFrozenCacheAllocationDecider.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/HasFrozenCacheAllocationDecider.java index 1823885c6d486..d1701397bea9b 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/HasFrozenCacheAllocationDecider.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/HasFrozenCacheAllocationDecider.java @@ -15,8 +15,6 @@ import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.Decision; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.snapshots.SearchableSnapshotsSettings; import org.elasticsearch.xpack.searchablesnapshots.cache.shared.FrozenCacheInfoService; import static org.elasticsearch.xpack.searchablesnapshots.cache.shared.FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING; @@ -80,9 +78,7 @@ public Decision shouldAutoExpandToNode(IndexMetadata indexMetadata, DiscoveryNod } private Decision canAllocateToNode(IndexMetadata indexMetadata, DiscoveryNode discoveryNode) { - final Settings indexSettings = indexMetadata.getSettings(); - - if (SearchableSnapshotsSettings.isPartialSearchableSnapshotIndex(indexSettings) == false) { + if (indexMetadata.isPartialSearchableSnapshotStore() == false) { return Decision.ALWAYS; } diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/SearchableSnapshotAllocationDecider.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/SearchableSnapshotAllocationDecider.java index 66c10768630a4..74eaa0012e244 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/SearchableSnapshotAllocationDecider.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/SearchableSnapshotAllocationDecider.java @@ -13,7 +13,6 @@ import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider; import org.elasticsearch.cluster.routing.allocation.decider.Decision; -import org.elasticsearch.snapshots.SearchableSnapshotsSettings; import java.util.function.BooleanSupplier; @@ -48,7 +47,7 @@ public Decision canForceAllocatePrimary(ShardRouting shardRouting, RoutingNode n } private Decision allowAllocation(IndexMetadata indexMetadata, RoutingAllocation allocation) { - if (SearchableSnapshotsSettings.isSearchableSnapshotStore(indexMetadata.getSettings())) { + if (indexMetadata.isSearchableSnapshotStore()) { if (hasValidLicenseSupplier.getAsBoolean()) { return allocation.decision(Decision.YES, NAME, "valid license for searchable snapshots"); } else { diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/SearchableSnapshotEnableAllocationDecider.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/SearchableSnapshotEnableAllocationDecider.java index 938feb0303409..79092c4bdb699 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/SearchableSnapshotEnableAllocationDecider.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/SearchableSnapshotEnableAllocationDecider.java @@ -17,7 +17,6 @@ import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.snapshots.SearchableSnapshotsSettings; public class SearchableSnapshotEnableAllocationDecider extends AllocationDecider { @@ -64,7 +63,7 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing @Override public Decision canAllocate(ShardRouting shardRouting, RoutingAllocation allocation) { final IndexMetadata indexMetadata = allocation.metadata().getIndexSafe(shardRouting.index()); - if (SearchableSnapshotsSettings.isSearchableSnapshotStore(indexMetadata.getSettings())) { + if (indexMetadata.isSearchableSnapshotStore()) { EnableAllocationDecider.Allocation enableAllocation = this.enableAllocation; boolean allocateOnRollingRestart = this.allocateOnRollingRestart; if (enableAllocation == EnableAllocationDecider.Allocation.PRIMARIES) { diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/SearchableSnapshotRepositoryExistsAllocationDecider.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/SearchableSnapshotRepositoryExistsAllocationDecider.java index 466e0e631d910..62484bff0f202 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/SearchableSnapshotRepositoryExistsAllocationDecider.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/allocation/decider/SearchableSnapshotRepositoryExistsAllocationDecider.java @@ -17,7 +17,6 @@ import org.elasticsearch.cluster.routing.allocation.decider.Decision; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.snapshots.SearchableSnapshotsSettings; import java.util.List; @@ -57,7 +56,7 @@ public Decision canAllocate(IndexMetadata indexMetadata, RoutingNode node, Routi private static Decision allowAllocation(IndexMetadata indexMetadata, RoutingAllocation allocation) { final Settings settings = indexMetadata.getSettings(); - if (SearchableSnapshotsSettings.isSearchableSnapshotStore(settings)) { + if (indexMetadata.isSearchableSnapshotStore()) { final RepositoriesMetadata repositoriesMetadata = allocation.metadata().custom(RepositoriesMetadata.TYPE); if (repositoriesMetadata == null || repositoriesMetadata.repositories().isEmpty()) { diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/blob/BlobStoreCacheMaintenanceService.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/blob/BlobStoreCacheMaintenanceService.java index ff6ff96373640..c6a789436c769 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/blob/BlobStoreCacheMaintenanceService.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/blob/BlobStoreCacheMaintenanceService.java @@ -61,7 +61,6 @@ import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.fetch.subphase.FieldAndFormat; import org.elasticsearch.search.sort.ShardDocSortField; -import org.elasticsearch.snapshots.SearchableSnapshotsSettings; import org.elasticsearch.threadpool.Scheduler; import org.elasticsearch.threadpool.ThreadPool; @@ -258,7 +257,7 @@ private ShardRouting systemIndexPrimaryShard(final ClusterState state) { private static boolean hasSearchableSnapshotWith(final ClusterState state, final String snapshotId, final String indexId) { for (IndexMetadata indexMetadata : state.metadata()) { final Settings indexSettings = indexMetadata.getSettings(); - if (SearchableSnapshotsSettings.isSearchableSnapshotStore(indexSettings)) { + if (indexMetadata.isSearchableSnapshotStore()) { if (Objects.equals(snapshotId, SNAPSHOT_SNAPSHOT_ID_SETTING.get(indexSettings)) && Objects.equals(indexId, SNAPSHOT_INDEX_ID_SETTING.get(indexSettings))) { return true; @@ -272,7 +271,7 @@ private static Map> listSearchableSnapshots(final ClusterSta Map> snapshots = null; for (IndexMetadata indexMetadata : state.metadata()) { final Settings indexSettings = indexMetadata.getSettings(); - if (SearchableSnapshotsSettings.isSearchableSnapshotStore(indexSettings)) { + if (indexMetadata.isSearchableSnapshotStore()) { if (snapshots == null) { snapshots = new HashMap<>(); } @@ -314,7 +313,7 @@ protected void doRun() { : "no previous metadata found for " + deletedIndex; if (indexMetadata != null) { final Settings indexSetting = indexMetadata.getSettings(); - if (SearchableSnapshotsSettings.isSearchableSnapshotStore(indexSetting)) { + if (indexMetadata.isSearchableSnapshotStore()) { assert state.metadata().hasIndex(deletedIndex) == false; final String snapshotId = SNAPSHOT_SNAPSHOT_ID_SETTING.get(indexSetting); diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/upgrade/SearchableSnapshotIndexMetadataUpgrader.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/upgrade/SearchableSnapshotIndexMetadataUpgrader.java index 37c44f27daada..9b4cdb7eff2b3 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/upgrade/SearchableSnapshotIndexMetadataUpgrader.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/upgrade/SearchableSnapshotIndexMetadataUpgrader.java @@ -19,7 +19,6 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.indices.ShardLimitValidator; -import org.elasticsearch.snapshots.SearchableSnapshotsSettings; import org.elasticsearch.threadpool.ThreadPool; import java.util.concurrent.Executor; @@ -93,9 +92,8 @@ public void onFailure(String source, Exception e) { static boolean needsUpgrade(ClusterState state) { return StreamSupport.stream(state.metadata().spliterator(), false) .filter(imd -> imd.getCreationVersion().onOrAfter(Version.V_7_12_0)) - .map(IndexMetadata::getSettings) - .filter(SearchableSnapshotsSettings::isPartialSearchableSnapshotIndex) - .anyMatch(SearchableSnapshotIndexMetadataUpgrader::notFrozenShardLimitGroup); + .filter(IndexMetadata::isPartialSearchableSnapshotStore) + .anyMatch(metadata -> notFrozenShardLimitGroup(metadata.getSettings())); } static ClusterState upgradeIndices(ClusterState currentState) { @@ -105,10 +103,7 @@ static ClusterState upgradeIndices(ClusterState currentState) { Metadata.Builder builder = Metadata.builder(currentState.metadata()); StreamSupport.stream(currentState.metadata().spliterator(), false) .filter(imd -> imd.getCreationVersion().onOrAfter(Version.V_7_12_0)) - .filter( - imd -> SearchableSnapshotsSettings.isPartialSearchableSnapshotIndex(imd.getSettings()) - && notFrozenShardLimitGroup(imd.getSettings()) - ) + .filter(imd -> imd.isPartialSearchableSnapshotStore() && notFrozenShardLimitGroup(imd.getSettings())) .map(SearchableSnapshotIndexMetadataUpgrader::setShardLimitGroupFrozen) .forEach(imd -> builder.put(imd, true)); return ClusterState.builder(currentState).metadata(builder).build(); diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/allocation/SearchableSnapshotAllocatorTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/allocation/SearchableSnapshotAllocatorTests.java index d3c4383e9c32a..0bf66f53471af 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/allocation/SearchableSnapshotAllocatorTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/allocation/SearchableSnapshotAllocatorTests.java @@ -253,19 +253,13 @@ private static RoutingAllocation buildAllocation( long shardSize, AllocationDeciders allocationDeciders ) { - return new RoutingAllocation( - allocationDeciders, - new RoutingNodes(state, false), - state, - null, - new SnapshotShardSizeInfo(ImmutableOpenMap.of()) { - @Override - public Long getShardSize(ShardRouting shardRouting) { - return shardSize; - } - }, - TimeUnit.MILLISECONDS.toNanos(deterministicTaskQueue.getCurrentTimeMillis()) - ); + final RoutingNodes routingNodes = state.mutableRoutingNodes(); + return new RoutingAllocation(allocationDeciders, () -> routingNodes, state, null, new SnapshotShardSizeInfo(ImmutableOpenMap.of()) { + @Override + public Long getShardSize(ShardRouting shardRouting) { + return shardSize; + } + }, TimeUnit.MILLISECONDS.toNanos(deterministicTaskQueue.getCurrentTimeMillis())); } private static void allocateAllUnassigned(RoutingAllocation allocation, ExistingShardsAllocator allocator) { diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/upgrade/SearchableSnapshotIndexMetadataUpgraderTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/upgrade/SearchableSnapshotIndexMetadataUpgraderTests.java index 328d9d3961858..935f7560c70a3 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/upgrade/SearchableSnapshotIndexMetadataUpgraderTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/upgrade/SearchableSnapshotIndexMetadataUpgraderTests.java @@ -73,13 +73,13 @@ public void testUpgradeIndices() { assertTrue(StreamSupport.stream(upgradedState.metadata().spliterator(), false).anyMatch(upgraded -> { IndexMetadata original = originalState.metadata().index(upgraded.getIndex()); assertThat(original, notNullValue()); - if (isPartial(upgraded) == false + if (upgraded.isPartialSearchableSnapshotStore() == false || ShardLimitValidator.INDEX_SETTING_SHARD_LIMIT_GROUP.get(original.getSettings()) .equals(ShardLimitValidator.FROZEN_GROUP)) { assertThat(upgraded, sameInstance(original)); return false; } else { - assertThat(isPartial(upgraded), is(isPartial(original))); + assertThat(upgraded.isPartialSearchableSnapshotStore(), is(original.isPartialSearchableSnapshotStore())); assertThat(upgraded.getNumberOfShards(), equalTo(original.getNumberOfShards())); assertThat(upgraded.getNumberOfReplicas(), equalTo(original.getNumberOfReplicas())); assertThat( @@ -177,7 +177,4 @@ private ClusterState clusterState(Metadata.Builder metadataBuilder) { return ClusterState.builder(ClusterName.DEFAULT).metadata(metadataBuilder).build(); } - private boolean isPartial(IndexMetadata upgraded) { - return SearchableSnapshotsSettings.isPartialSearchableSnapshotIndex(upgraded.getSettings()); - } } diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/test/SecurityTestUtils.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/test/SecurityTestUtils.java index b45d05def523a..9717c93b5ddbe 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/test/SecurityTestUtils.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/test/SecurityTestUtils.java @@ -83,7 +83,7 @@ public static RoutingTable buildIndexRoutingTable(Index index) { */ public static Metadata addAliasToMetadata(Metadata metadata, String indexName) { AliasMetadata aliasMetadata = AliasMetadata.newAliasMetadataBuilder(SECURITY_MAIN_ALIAS).build(); - Metadata.Builder metadataBuilder = new Metadata.Builder(metadata); + Metadata.Builder metadataBuilder = Metadata.builder(metadata); IndexMetadata indexMetadata = metadata.index(indexName); metadataBuilder.put(IndexMetadata.builder(indexMetadata).putAlias(aliasMetadata)); return metadataBuilder.build(); diff --git a/x-pack/plugin/shutdown/src/main/java/org/elasticsearch/xpack/shutdown/TransportGetShutdownStatusAction.java b/x-pack/plugin/shutdown/src/main/java/org/elasticsearch/xpack/shutdown/TransportGetShutdownStatusAction.java index 38257d1863845..bd72b638ab186 100644 --- a/x-pack/plugin/shutdown/src/main/java/org/elasticsearch/xpack/shutdown/TransportGetShutdownStatusAction.java +++ b/x-pack/plugin/shutdown/src/main/java/org/elasticsearch/xpack/shutdown/TransportGetShutdownStatusAction.java @@ -215,7 +215,7 @@ static ShutdownShardMigrationStatus shardMigrationStatus( // If there's no relocating shards and shards still on this node, we need to figure out why final RoutingAllocation allocation = new RoutingAllocation( allocationDeciders, - currentState.getRoutingNodes(), + currentState::getRoutingNodes, currentState, clusterInfoService.getClusterInfo(), snapshotsInfoService.snapshotShardSizes(), diff --git a/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/transforms/TransformPersistentTasksExecutorTests.java b/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/transforms/TransformPersistentTasksExecutorTests.java index 582c855a609a0..8d2ac775d0b21 100644 --- a/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/transforms/TransformPersistentTasksExecutorTests.java +++ b/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/transforms/TransformPersistentTasksExecutorTests.java @@ -314,7 +314,7 @@ public void testVerifyIndicesPrimaryShardsAreActive() { TransformPersistentTasksExecutor.verifyIndicesPrimaryShardsAreActive(cs, TestIndexNameExpressionResolver.newInstance()).size() ); - metadata = new Metadata.Builder(cs.metadata()); + metadata = Metadata.builder(cs.metadata()); routingTable = new RoutingTable.Builder(cs.routingTable()); String indexToRemove = TransformInternalIndexConstants.LATEST_INDEX_NAME; if (randomBoolean()) {