diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/storage/ProactiveStorageDeciderService.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/storage/ProactiveStorageDeciderService.java index 9dc5eb76c259d..42254baafcb0b 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/storage/ProactiveStorageDeciderService.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/storage/ProactiveStorageDeciderService.java @@ -21,7 +21,6 @@ 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.cluster.routing.allocation.DataTierAllocationDecider; import java.io.IOException; import java.util.List; @@ -33,11 +32,9 @@ public class ProactiveStorageDeciderService implements AutoscalingDeciderService private final DiskThresholdSettings diskThresholdSettings; private final AllocationDeciders allocationDeciders; - private final DataTierAllocationDecider dataTierAllocationDecider; public ProactiveStorageDeciderService(Settings settings, ClusterSettings clusterSettings, AllocationDeciders allocationDeciders) { this.diskThresholdSettings = new DiskThresholdSettings(settings, clusterSettings); - this.dataTierAllocationDecider = new DataTierAllocationDecider(); this.allocationDeciders = allocationDeciders; } @@ -64,8 +61,7 @@ public AutoscalingDeciderResult scale(Settings configuration, AutoscalingDecider ReactiveStorageDeciderService.AllocationState allocationState = new ReactiveStorageDeciderService.AllocationState( context, diskThresholdSettings, - allocationDeciders, - dataTierAllocationDecider + allocationDeciders ); long unassignedBytesBeforeForecast = allocationState.storagePreventsAllocation(); assert unassignedBytesBeforeForecast >= 0; 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 7c387b729d98f..a73450df10e32 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 @@ -71,12 +71,10 @@ public class ReactiveStorageDeciderService implements AutoscalingDeciderService public static final String NAME = "reactive_storage"; private final DiskThresholdSettings diskThresholdSettings; - private final DataTierAllocationDecider dataTierAllocationDecider; private final AllocationDeciders allocationDeciders; public ReactiveStorageDeciderService(Settings settings, ClusterSettings clusterSettings, AllocationDeciders allocationDeciders) { this.diskThresholdSettings = new DiskThresholdSettings(settings, clusterSettings); - this.dataTierAllocationDecider = new DataTierAllocationDecider(); this.allocationDeciders = allocationDeciders; } @@ -108,12 +106,7 @@ public AutoscalingDeciderResult scale(Settings configuration, AutoscalingDecider return new AutoscalingDeciderResult(null, new ReactiveReason("current capacity not available", -1, -1)); } - AllocationState allocationState = new AllocationState( - context, - diskThresholdSettings, - allocationDeciders, - dataTierAllocationDecider - ); + AllocationState allocationState = new AllocationState(context, diskThresholdSettings, allocationDeciders); long unassignedBytes = allocationState.storagePreventsAllocation(); long assignedBytes = allocationState.storagePreventsRemainOrMove(); long maxShardSize = allocationState.maxShardSize(); @@ -177,7 +170,6 @@ static Optional singleNoDecision(Decision decision, Predicate public static class AllocationState { private final ClusterState state; private final AllocationDeciders allocationDeciders; - private final DataTierAllocationDecider dataTierAllocationDecider; private final DiskThresholdSettings diskThresholdSettings; private final ClusterInfo info; private final SnapshotShardSizeInfo shardSizeInfo; @@ -189,13 +181,11 @@ public static class AllocationState { AllocationState( AutoscalingDeciderContext context, DiskThresholdSettings diskThresholdSettings, - AllocationDeciders allocationDeciders, - DataTierAllocationDecider dataTierAllocationDecider + AllocationDeciders allocationDeciders ) { this( context.state(), allocationDeciders, - dataTierAllocationDecider, diskThresholdSettings, context.info(), context.snapshotShardSizeInfo(), @@ -207,7 +197,6 @@ public static class AllocationState { AllocationState( ClusterState state, AllocationDeciders allocationDeciders, - DataTierAllocationDecider dataTierAllocationDecider, DiskThresholdSettings diskThresholdSettings, ClusterInfo info, SnapshotShardSizeInfo shardSizeInfo, @@ -216,7 +205,6 @@ public static class AllocationState { ) { this.state = state; this.allocationDeciders = allocationDeciders; - this.dataTierAllocationDecider = dataTierAllocationDecider; this.diskThresholdSettings = diskThresholdSettings; this.info = info; this.shardSizeInfo = shardSizeInfo; @@ -346,7 +334,7 @@ boolean needsThisTier(ShardRouting shard, RoutingAllocation allocation) { IndexMetadata indexMetadata = indexMetadata(shard, allocation); Set decisionTypes = StreamSupport.stream(allocation.routingNodes().spliterator(), false) .map( - node -> dataTierAllocationDecider.shouldFilter( + node -> DataTierAllocationDecider.shouldFilter( indexMetadata, node.node().getRoles(), this::highestPreferenceTier, @@ -378,7 +366,7 @@ 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, this::highestPreferenceTier, allocation) != Decision.NO; } private IndexMetadata indexMetadata(ShardRouting shard, RoutingAllocation allocation) { @@ -502,7 +490,6 @@ public AllocationState forecast(long forecastWindow, long now) { return new AllocationState( forecastClusterState, allocationDeciders, - dataTierAllocationDecider, diskThresholdSettings, forecastInfo, shardSizeInfo, 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 f8bf596226342..a49c660aa9aff 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 @@ -178,7 +178,6 @@ public void testForecastNoDates() { null, null, null, - null, Set.of(), Set.of() ); @@ -209,7 +208,6 @@ public void testForecastZero() { state, null, null, - null, randomClusterInfo(state), null, Sets.newHashSet(state.nodes()), @@ -254,7 +252,6 @@ public void testForecast() { state, null, null, - null, info, null, Sets.newHashSet(state.nodes()), 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 95bca4a437f28..c88be8993f0bf 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 @@ -96,8 +96,6 @@ public Decision canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAl new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS) ); - private static final DataTierAllocationDecider DATA_TIER_ALLOCATION_DECIDER = new DataTierAllocationDecider(); - private ClusterState state; private final int hotNodes = randomIntBetween(1, 8); private final int warmNodes = randomIntBetween(1, 3); @@ -366,8 +364,7 @@ private static void verify( ReactiveStorageDeciderService.AllocationState allocationState = new ReactiveStorageDeciderService.AllocationState( createContext(state, Set.of(role)), DISK_THRESHOLD_SETTINGS, - createAllocationDeciders(allocationDeciders), - DATA_TIER_ALLOCATION_DECIDER + createAllocationDeciders(allocationDeciders) ); assertThat(subject.invoke(allocationState), equalTo(expected)); } @@ -429,7 +426,7 @@ private static AllocationDeciders createAllocationDeciders(AllocationDecider... Collections.emptyList() ); return new AllocationDeciders( - Stream.of(Stream.of(extraDeciders), Stream.of(new DataTierAllocationDecider()), systemAllocationDeciders.stream()) + Stream.of(Stream.of(extraDeciders), Stream.of(DataTierAllocationDecider.INSTANCE), systemAllocationDeciders.stream()) .flatMap(s -> s) .collect(Collectors.toList()) ); 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 5039d7fb0da43..056bea9165f69 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 @@ -280,7 +280,6 @@ public void validateSizeOf( clusterState, null, null, - null, info, null, Set.of(), @@ -358,7 +357,6 @@ private void validateSizeOfSnapshotShard( null, null, null, - null, shardSizeInfo, Set.of(), Set.of() @@ -448,7 +446,6 @@ public void testUnmovableSize() { ReactiveStorageDeciderService.AllocationState allocationState = new ReactiveStorageDeciderService.AllocationState( clusterState, null, - null, thresholdSettings, info, null, @@ -521,11 +518,9 @@ public ClusterState addPreference(IndexMetadata indexMetadata, ClusterState clus public boolean canRemainWithNoNodes(ClusterState clusterState, ShardRouting shardRouting, AllocationDecider... deciders) { AllocationDeciders allocationDeciders = new AllocationDeciders(Arrays.asList(deciders)); - DataTierAllocationDecider dataTierAllocationDecider = new DataTierAllocationDecider(); ReactiveStorageDeciderService.AllocationState allocationState = new ReactiveStorageDeciderService.AllocationState( clusterState, allocationDeciders, - dataTierAllocationDecider, new DiskThresholdSettings(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)), ClusterInfo.EMPTY, null, @@ -626,11 +621,9 @@ private void verifyNeedsWarmTier( AllocationDecider... deciders ) { AllocationDeciders allocationDeciders = new AllocationDeciders(Arrays.asList(deciders)); - DataTierAllocationDecider dataTierAllocationDecider = new DataTierAllocationDecider(); ReactiveStorageDeciderService.AllocationState allocationState = new ReactiveStorageDeciderService.AllocationState( clusterState, allocationDeciders, - dataTierAllocationDecider, new DiskThresholdSettings(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)), ClusterInfo.EMPTY, null, 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 30082aa65f50d..59704538b3a4a 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 @@ -28,11 +28,13 @@ * {@link org.elasticsearch.cluster.routing.allocation.decider.FilterAllocationDecider}, however it * is specific to the {@code _tier} setting for both the cluster and index level. */ -public class DataTierAllocationDecider extends AllocationDecider { +public final class DataTierAllocationDecider extends AllocationDecider { public static final String NAME = "data_tier"; - public DataTierAllocationDecider() {} + public static final DataTierAllocationDecider INSTANCE = new DataTierAllocationDecider(); + + private DataTierAllocationDecider() {} @Override public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { @@ -58,7 +60,7 @@ private Decision shouldFilter(ShardRouting shardRouting, DiscoveryNode node, Rou return shouldFilter(allocation.metadata().getIndexSafe(shardRouting.index()), node.getRoles(), allocation); } - public Decision shouldFilter(IndexMetadata indexMd, Set roles, RoutingAllocation allocation) { + private static Decision shouldFilter(IndexMetadata indexMd, Set roles, RoutingAllocation allocation) { return shouldFilter(indexMd, roles, DataTierAllocationDecider::preferredAvailableTier, allocation); } @@ -66,68 +68,65 @@ public interface PreferredTierFunction { Optional apply(List tierPreference, DiscoveryNodes nodes); } - public Decision shouldFilter( + private static final Decision YES_PASSES = Decision.single(Decision.YES.type(), NAME, "node passes tier preference filters"); + + public static Decision shouldFilter( IndexMetadata indexMd, Set roles, PreferredTierFunction preferredTierFunction, RoutingAllocation allocation ) { - Decision decision = shouldIndexPreferTier(indexMd, roles, preferredTierFunction, allocation); - if (decision != null) { - return decision; + List tierPreference = indexMd.getTierPreference(); + if (tierPreference.isEmpty() != false) { + return YES_PASSES; } - - return allocation.decision(Decision.YES, NAME, "node passes tier preference filters"); - } - - private Decision shouldIndexPreferTier( - IndexMetadata indexMetadata, - Set roles, - PreferredTierFunction preferredTierFunction, - RoutingAllocation allocation - ) { - List tierPreference = indexMetadata.getTierPreference(); - - if (tierPreference.isEmpty() == false) { - Optional tier = preferredTierFunction.apply(tierPreference, allocation.nodes()); - if (tier.isPresent()) { - String tierName = tier.get(); - if (allocationAllowed(tierName, roles)) { - if (allocation.debugDecision() == false) { - return Decision.YES; - } - return allocation.decision( - Decision.YES, - NAME, - "index has a preference for tiers [%s] and node has tier [%s]", - String.join(",", tierPreference), - tierName - ); - } else { - if (allocation.debugDecision() == false) { - return Decision.NO; - } - return allocation.decision( - Decision.NO, - NAME, - "index has a preference for tiers [%s] and node does not meet the required [%s] tier", - String.join(",", tierPreference), - tierName - ); + Optional tier = preferredTierFunction.apply(tierPreference, allocation.nodes()); + if (tier.isPresent()) { + String tierName = tier.get(); + if (allocationAllowed(tierName, roles)) { + if (allocation.debugDecision()) { + return debugYesAllowed(allocation, tierPreference, tierName); } - } else { - if (allocation.debugDecision() == false) { - return Decision.NO; - } - return allocation.decision( - Decision.NO, - NAME, - "index has a preference for tiers [%s], " + "but no nodes for any of those tiers are available in the cluster", - String.join(",", tierPreference) - ); + return Decision.YES; + } + if (allocation.debugDecision()) { + return debugNoRequirementsNotMet(allocation, tierPreference, tierName); } + return Decision.NO; } - return null; + if (allocation.debugDecision()) { + return debugNoNoNodesAvailable(allocation, tierPreference); + } + return Decision.NO; + } + + private static Decision debugNoNoNodesAvailable(RoutingAllocation allocation, List tierPreference) { + return allocation.decision( + Decision.NO, + NAME, + "index has a preference for tiers [%s], but no nodes for any of those tiers are available in the cluster", + String.join(",", tierPreference) + ); + } + + private static Decision debugNoRequirementsNotMet(RoutingAllocation allocation, List tierPreference, String tierName) { + return allocation.decision( + Decision.NO, + NAME, + "index has a preference for tiers [%s] and node does not meet the required [%s] tier", + String.join(",", tierPreference), + tierName + ); + } + + private static Decision debugYesAllowed(RoutingAllocation allocation, List tierPreference, String tierName) { + return allocation.decision( + Decision.YES, + NAME, + "index has a preference for tiers [%s] and node has tier [%s]", + String.join(",", tierPreference), + tierName + ); } /** @@ -148,12 +147,9 @@ 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; - } + for (DiscoveryNode node : nodes) { + if (allocationAllowed(singleTier, node.getRoles())) { + return true; } } return false; @@ -165,13 +161,12 @@ private static boolean allocationAllowed(String tierName, Set if (roles.contains(DiscoveryNodeRole.DATA_ROLE)) { // generic "data" roles are considered to have all tiers return true; - } else { - for (DiscoveryNodeRole role : roles) { - if (tierName.equals(role.roleName())) { - return true; - } + } + for (DiscoveryNodeRole role : roles) { + if (tierName.equals(role.roleName())) { + return true; } - return false; } + return false; } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java index f22cb6bf8e7b2..2289f804d66be 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 @@ -455,7 +455,7 @@ public List> getSettings() { @Override public Collection createAllocationDeciders(Settings settings, ClusterSettings clusterSettings) { - return Collections.singleton(new DataTierAllocationDecider()); + return Collections.singleton(DataTierAllocationDecider.INSTANCE); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/DataTierMigrationRoutedStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/DataTierMigrationRoutedStep.java index b8293279527ab..7a6ccc1300f19 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/DataTierMigrationRoutedStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/DataTierMigrationRoutedStep.java @@ -32,6 +32,8 @@ public class DataTierMigrationRoutedStep extends ClusterStateWaitStep { private static final Logger logger = LogManager.getLogger(DataTierMigrationRoutedStep.class); + private static final AllocationDeciders DECIDERS = new AllocationDeciders(List.of(DataTierAllocationDecider.INSTANCE)); + DataTierMigrationRoutedStep(StepKey key, StepKey nextStepKey) { super(key, nextStepKey); } @@ -43,7 +45,6 @@ public boolean isRetryable() { @Override public Result isConditionMet(Index index, ClusterState clusterState) { - AllocationDeciders allocationDeciders = new AllocationDeciders(List.of(new DataTierAllocationDecider())); IndexMetadata idxMeta = clusterState.metadata().index(index); if (idxMeta == null) { // Index must have been since deleted, ignore it @@ -95,7 +96,7 @@ public Result isConditionMet(Index index, ClusterState clusterState) { return new Result(true, null); } - int allocationPendingAllShards = getPendingAllocations(index, allocationDeciders, clusterState); + int allocationPendingAllShards = getPendingAllocations(index, DECIDERS, clusterState); if (allocationPendingAllShards > 0) { String statusMessage = availableDestinationTier.map( 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 0bfc3f92d4d4b..1ad577f626cda 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 @@ -73,7 +73,7 @@ public void performAction( clusterState.getMetadata().settings(), new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS) ), - new DataTierAllocationDecider(), + DataTierAllocationDecider.INSTANCE, new NodeVersionAllocationDecider(), new NodeShutdownAllocationDecider(), new NodeReplacementAllocationDecider() 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 2777aeb076897..06a85a87766aa 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 @@ -63,10 +63,9 @@ public class DataTierAllocationDeciderTests extends ESAllocationTestCase { private static final DiscoveryNode DATA_NODE = newNode("node-data", Collections.singleton(DiscoveryNodeRole.DATA_ROLE)); private final ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); - private final DataTierAllocationDecider decider = new DataTierAllocationDecider(); private final AllocationDeciders allocationDeciders = new AllocationDeciders( Arrays.asList( - decider, + DataTierAllocationDecider.INSTANCE, new SameShardAllocationDecider(Settings.EMPTY, clusterSettings), new ReplicaAfterPrimaryActiveAllocationDecider() ) @@ -113,7 +112,7 @@ public void testIndexPrefer() { for (DiscoveryNode n : Arrays.asList(HOT_NODE, WARM_NODE, COLD_NODE)) { node = new RoutingNode(n.getId(), n, shard); - d = decider.canAllocate(shard, node, allocation); + d = DataTierAllocationDecider.INSTANCE.canAllocate(shard, node, allocation); assertThat(node.toString(), d.type(), equalTo(Decision.Type.NO)); assertThat( node.toString(), @@ -123,7 +122,7 @@ public void testIndexPrefer() { + "but no nodes for any of those tiers are available in the cluster" ) ); - d = decider.canRemain(shard, node, allocation); + d = DataTierAllocationDecider.INSTANCE.canRemain(shard, node, allocation); assertThat(node.toString(), d.type(), equalTo(Decision.Type.NO)); assertThat( node.toString(), @@ -159,7 +158,7 @@ public void testIndexPrefer() { for (DiscoveryNode n : Arrays.asList(HOT_NODE, WARM_NODE)) { node = new RoutingNode(n.getId(), n, shard); - d = decider.canAllocate(shard, node, allocation); + d = DataTierAllocationDecider.INSTANCE.canAllocate(shard, node, allocation); assertThat(node.toString(), d.type(), equalTo(Decision.Type.NO)); assertThat( node.toString(), @@ -168,7 +167,7 @@ public void testIndexPrefer() { "index has a preference for tiers [data_warm,data_cold] " + "and node does not meet the required [data_cold] tier" ) ); - d = decider.canRemain(shard, node, allocation); + d = DataTierAllocationDecider.INSTANCE.canRemain(shard, node, allocation); assertThat(node.toString(), d.type(), equalTo(Decision.Type.NO)); assertThat( node.toString(), @@ -179,23 +178,21 @@ public void testIndexPrefer() { ); } - for (DiscoveryNode n : Arrays.asList(COLD_NODE)) { - node = new RoutingNode(n.getId(), n, shard); - d = decider.canAllocate(shard, node, allocation); - assertThat(node.toString(), d.type(), equalTo(Decision.Type.YES)); - assertThat( - node.toString(), - d.getExplanation(), - containsString("index has a preference for tiers [data_warm,data_cold] and node has tier [data_cold]") - ); - d = decider.canRemain(shard, node, allocation); - assertThat(node.toString(), d.type(), equalTo(Decision.Type.YES)); - assertThat( - node.toString(), - d.getExplanation(), - containsString("index has a preference for tiers [data_warm,data_cold] and node has tier [data_cold]") - ); - } + node = new RoutingNode(COLD_NODE.getId(), COLD_NODE, shard); + d = DataTierAllocationDecider.INSTANCE.canAllocate(shard, node, allocation); + assertThat(node.toString(), d.type(), equalTo(Decision.Type.YES)); + assertThat( + node.toString(), + d.getExplanation(), + containsString("index has a preference for tiers [data_warm,data_cold] and node has tier [data_cold]") + ); + d = DataTierAllocationDecider.INSTANCE.canRemain(shard, node, allocation); + assertThat(node.toString(), d.type(), equalTo(Decision.Type.YES)); + assertThat( + node.toString(), + d.getExplanation(), + containsString("index has a preference for tiers [data_warm,data_cold] and node has tier [data_cold]") + ); } public void testTierNodesPresent() {