|
20 | 20 | import org.elasticsearch.cluster.node.DiscoveryNode;
|
21 | 21 | import org.elasticsearch.cluster.node.DiscoveryNodeRole;
|
22 | 22 | import org.elasticsearch.cluster.node.DiscoveryNodes;
|
| 23 | +import org.elasticsearch.cluster.routing.ShardRoutingState; |
23 | 24 | import org.elasticsearch.cluster.service.ClusterService;
|
24 | 25 | import org.elasticsearch.common.settings.ClusterSettings;
|
25 | 26 | import org.elasticsearch.common.settings.Settings;
|
|
43 | 44 | import java.util.concurrent.atomic.AtomicInteger;
|
44 | 45 | import java.util.concurrent.atomic.AtomicReference;
|
45 | 46 |
|
| 47 | +import static org.elasticsearch.action.support.replication.ClusterStateCreationUtils.state; |
46 | 48 | import static org.hamcrest.Matchers.equalTo;
|
| 49 | +import static org.hamcrest.Matchers.is; |
47 | 50 | import static org.hamcrest.Matchers.nullValue;
|
48 | 51 | import static org.mockito.ArgumentMatchers.any;
|
49 | 52 | import static org.mockito.ArgumentMatchers.eq;
|
@@ -306,6 +309,49 @@ public void testFrozenRedDiskStatus() {
|
306 | 309 | assertThat(diskHealth, equalTo(new DiskHealthInfo(HealthStatus.RED, DiskHealthInfo.Cause.FROZEN_NODE_OVER_FLOOD_STAGE_THRESHOLD)));
|
307 | 310 | }
|
308 | 311 |
|
| 312 | + public void testYellowStatusForNonDataNode() { |
| 313 | + DiscoveryNode dedicatedMasterNode = new DiscoveryNode( |
| 314 | + "master-node", |
| 315 | + "master-node-1", |
| 316 | + ESTestCase.buildNewFakeTransportAddress(), |
| 317 | + Collections.emptyMap(), |
| 318 | + Set.of(DiscoveryNodeRole.MASTER_ROLE), |
| 319 | + Version.CURRENT |
| 320 | + ); |
| 321 | + clusterState = ClusterStateCreationUtils.state( |
| 322 | + dedicatedMasterNode, |
| 323 | + dedicatedMasterNode, |
| 324 | + node, |
| 325 | + new DiscoveryNode[] { node, dedicatedMasterNode } |
| 326 | + ).copyAndUpdate(b -> b.putCustom(HealthMetadata.TYPE, healthMetadata)); |
| 327 | + |
| 328 | + initializeIncreasedDiskSpaceUsage(); |
| 329 | + LocalHealthMonitor.DiskCheck diskMonitor = new LocalHealthMonitor.DiskCheck(nodeService); |
| 330 | + DiskHealthInfo diskHealth = diskMonitor.getHealth(healthMetadata, clusterState); |
| 331 | + assertThat(diskHealth, equalTo(new DiskHealthInfo(HealthStatus.YELLOW, DiskHealthInfo.Cause.NODE_OVER_HIGH_THRESHOLD))); |
| 332 | + } |
| 333 | + |
| 334 | + public void testHasRelocatingShards() { |
| 335 | + String indexName = "my-index"; |
| 336 | + final ClusterState state = state(indexName, true, ShardRoutingState.RELOCATING); |
| 337 | + // local node coincides with the node hosting the (relocating) primary shard |
| 338 | + DiscoveryNode localNode = state.nodes().getLocalNode(); |
| 339 | + assertThat(LocalHealthMonitor.DiskCheck.hasRelocatingShards(state, localNode), is(true)); |
| 340 | + |
| 341 | + DiscoveryNode dedicatedMasterNode = new DiscoveryNode( |
| 342 | + "master-node", |
| 343 | + "master-node-1", |
| 344 | + ESTestCase.buildNewFakeTransportAddress(), |
| 345 | + Collections.emptyMap(), |
| 346 | + Set.of(DiscoveryNodeRole.MASTER_ROLE), |
| 347 | + Version.CURRENT |
| 348 | + ); |
| 349 | + ClusterState newState = ClusterState.builder(state) |
| 350 | + .nodes(new DiscoveryNodes.Builder(state.nodes()).add(dedicatedMasterNode)) |
| 351 | + .build(); |
| 352 | + assertThat(LocalHealthMonitor.DiskCheck.hasRelocatingShards(newState, dedicatedMasterNode), is(false)); |
| 353 | + } |
| 354 | + |
309 | 355 | private void simulateDiskOutOfSpace() {
|
310 | 356 | when(
|
311 | 357 | nodeService.stats(
|
|
0 commit comments