|
9 | 9 | package org.opensearch.cluster.routing; |
10 | 10 |
|
11 | 11 | import org.opensearch.action.admin.cluster.health.ClusterHealthResponse; |
| 12 | +import org.opensearch.action.admin.cluster.shards.routing.weighted.delete.ClusterDeleteWeightedRoutingResponse; |
12 | 13 | import org.opensearch.action.admin.cluster.shards.routing.weighted.get.ClusterGetWeightedRoutingResponse; |
13 | 14 | import org.opensearch.action.admin.cluster.shards.routing.weighted.put.ClusterPutWeightedRoutingResponse; |
14 | 15 | import org.opensearch.common.settings.Settings; |
@@ -242,4 +243,67 @@ public void testGetWeightedRouting_WeightsAreSet() throws IOException { |
242 | 243 | assertEquals(weightedRouting, weightedRoutingResponse.weights()); |
243 | 244 | assertEquals("3.0", weightedRoutingResponse.getLocalNodeWeight()); |
244 | 245 | } |
| 246 | + |
| 247 | + public void testDeleteWeightedRouting_WeightsNotSet() { |
| 248 | + Settings commonSettings = Settings.builder() |
| 249 | + .put("cluster.routing.allocation.awareness.attributes", "zone") |
| 250 | + .put("cluster.routing.allocation.awareness.force.zone.values", "a,b,c") |
| 251 | + .build(); |
| 252 | + |
| 253 | + internalCluster().startNodes( |
| 254 | + Settings.builder().put(commonSettings).put("node.attr.zone", "a").build(), |
| 255 | + Settings.builder().put(commonSettings).put("node.attr.zone", "b").build(), |
| 256 | + Settings.builder().put(commonSettings).put("node.attr.zone", "c").build() |
| 257 | + ); |
| 258 | + |
| 259 | + logger.info("--> waiting for nodes to form a cluster"); |
| 260 | + ClusterHealthResponse health = client().admin().cluster().prepareHealth().setWaitForNodes("3").execute().actionGet(); |
| 261 | + assertThat(health.isTimedOut(), equalTo(false)); |
| 262 | + |
| 263 | + ensureGreen(); |
| 264 | + |
| 265 | + assertNull(internalCluster().clusterService().state().metadata().weightedRoutingMetadata()); |
| 266 | + |
| 267 | + // delete weighted routing metadata |
| 268 | + ClusterDeleteWeightedRoutingResponse deleteResponse = client().admin().cluster().prepareDeleteWeightedRouting().get(); |
| 269 | + assertTrue(deleteResponse.isAcknowledged()); |
| 270 | + assertNull(internalCluster().clusterService().state().metadata().weightedRoutingMetadata()); |
| 271 | + } |
| 272 | + |
| 273 | + public void testDeleteWeightedRouting_WeightsAreSet() { |
| 274 | + Settings commonSettings = Settings.builder() |
| 275 | + .put("cluster.routing.allocation.awareness.attributes", "zone") |
| 276 | + .put("cluster.routing.allocation.awareness.force.zone.values", "a,b,c") |
| 277 | + .build(); |
| 278 | + |
| 279 | + internalCluster().startNodes( |
| 280 | + Settings.builder().put(commonSettings).put("node.attr.zone", "a").build(), |
| 281 | + Settings.builder().put(commonSettings).put("node.attr.zone", "b").build(), |
| 282 | + Settings.builder().put(commonSettings).put("node.attr.zone", "c").build() |
| 283 | + ); |
| 284 | + |
| 285 | + logger.info("--> waiting for nodes to form a cluster"); |
| 286 | + ClusterHealthResponse health = client().admin().cluster().prepareHealth().setWaitForNodes("3").execute().actionGet(); |
| 287 | + assertThat(health.isTimedOut(), equalTo(false)); |
| 288 | + |
| 289 | + ensureGreen(); |
| 290 | + |
| 291 | + logger.info("--> setting shard routing weights for weighted round robin"); |
| 292 | + Map<String, Double> weights = Map.of("a", 1.0, "b", 2.0, "c", 3.0); |
| 293 | + WeightedRouting weightedRouting = new WeightedRouting("zone", weights); |
| 294 | + |
| 295 | + // put api call to set weights |
| 296 | + ClusterPutWeightedRoutingResponse response = client().admin() |
| 297 | + .cluster() |
| 298 | + .prepareWeightedRouting() |
| 299 | + .setWeightedRouting(weightedRouting) |
| 300 | + .get(); |
| 301 | + assertEquals(response.isAcknowledged(), true); |
| 302 | + assertNotNull(internalCluster().clusterService().state().metadata().weightedRoutingMetadata()); |
| 303 | + |
| 304 | + // delete weighted routing metadata |
| 305 | + ClusterDeleteWeightedRoutingResponse deleteResponse = client().admin().cluster().prepareDeleteWeightedRouting().get(); |
| 306 | + assertTrue(deleteResponse.isAcknowledged()); |
| 307 | + assertNull(internalCluster().clusterService().state().metadata().weightedRoutingMetadata()); |
| 308 | + } |
245 | 309 | } |
0 commit comments