|
20 | 20 | import org.opensearch.cluster.metadata.Metadata;
|
21 | 21 | import org.opensearch.cluster.node.DiscoveryNodeRole;
|
22 | 22 | import org.opensearch.cluster.node.DiscoveryNodes;
|
| 23 | +import org.opensearch.cluster.routing.RoutingNode; |
23 | 24 | import org.opensearch.cluster.routing.RoutingNodes;
|
| 25 | +import org.opensearch.cluster.routing.RoutingPool; |
24 | 26 | import org.opensearch.cluster.routing.RoutingTable;
|
25 | 27 | import org.opensearch.cluster.routing.ShardRouting;
|
26 | 28 | import org.opensearch.cluster.routing.UnassignedInfo;
|
27 | 29 | import org.opensearch.cluster.routing.allocation.allocator.BalancedShardsAllocator;
|
28 | 30 | import org.opensearch.cluster.routing.allocation.allocator.ShardsAllocator;
|
29 | 31 | import org.opensearch.cluster.routing.allocation.decider.AllocationDecider;
|
30 | 32 | import org.opensearch.cluster.routing.allocation.decider.AllocationDeciders;
|
| 33 | +import org.opensearch.cluster.routing.allocation.decider.Decision; |
31 | 34 | import org.opensearch.common.SuppressForbidden;
|
32 | 35 | import org.opensearch.common.settings.ClusterSettings;
|
33 | 36 | import org.opensearch.common.settings.Settings;
|
@@ -201,6 +204,36 @@ public AllocationService createRemoteCapableAllocationService(String excludeNode
|
201 | 204 | );
|
202 | 205 | }
|
203 | 206 |
|
| 207 | + public AllocationService createRejectRemoteAllocationService(boolean throttle) { |
| 208 | + Settings settings = Settings.Builder.EMPTY_SETTINGS; |
| 209 | + return new OpenSearchAllocationTestCase.MockAllocationService( |
| 210 | + createRejectRemoteAllocationDeciders(throttle), |
| 211 | + new TestGatewayAllocator(), |
| 212 | + createShardAllocator(settings), |
| 213 | + EmptyClusterInfoService.INSTANCE, |
| 214 | + SNAPSHOT_INFO_SERVICE_WITH_NO_SHARD_SIZES |
| 215 | + ); |
| 216 | + } |
| 217 | + |
| 218 | + public AllocationDeciders createRejectRemoteAllocationDeciders(boolean throttle) { |
| 219 | + Settings settings = Settings.Builder.EMPTY_SETTINGS; |
| 220 | + List<AllocationDecider> deciders = new ArrayList<>( |
| 221 | + ClusterModule.createAllocationDeciders(settings, EMPTY_CLUSTER_SETTINGS, Collections.emptyList()) |
| 222 | + ); |
| 223 | + deciders.add(new AllocationDecider() { |
| 224 | + @Override |
| 225 | + public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, RoutingAllocation allocation) { |
| 226 | + if (RoutingPool.REMOTE_CAPABLE.equals(RoutingPool.getShardPool(shardRouting, allocation))) { |
| 227 | + return throttle ? Decision.THROTTLE : Decision.NO; |
| 228 | + } else { |
| 229 | + return Decision.ALWAYS; |
| 230 | + } |
| 231 | + } |
| 232 | + }); |
| 233 | + Collections.shuffle(deciders, random()); |
| 234 | + return new AllocationDeciders(deciders); |
| 235 | + } |
| 236 | + |
204 | 237 | public AllocationDeciders createAllocationDeciders() {
|
205 | 238 | Settings settings = Settings.Builder.EMPTY_SETTINGS;
|
206 | 239 | return randomAllocationDeciders(settings, EMPTY_CLUSTER_SETTINGS, random());
|
|
0 commit comments