|
35 | 35 | import org.opensearch.Version;
|
36 | 36 | import org.opensearch.action.admin.cluster.health.ClusterHealthResponse;
|
37 | 37 | import org.opensearch.action.admin.cluster.node.stats.NodeStats;
|
| 38 | +import org.opensearch.action.admin.cluster.node.stats.NodesStatsRequest; |
38 | 39 | import org.opensearch.action.admin.cluster.node.stats.NodesStatsResponse;
|
39 | 40 | import org.opensearch.client.Requests;
|
40 | 41 | import org.opensearch.cluster.health.ClusterHealthStatus;
|
|
54 | 55 | import java.util.Collections;
|
55 | 56 | import java.util.HashMap;
|
56 | 57 | import java.util.HashSet;
|
| 58 | +import java.util.Locale; |
57 | 59 | import java.util.Map;
|
58 | 60 | import java.util.Set;
|
59 | 61 | import java.util.concurrent.ExecutionException;
|
@@ -83,14 +85,7 @@ private void waitForNodes(int numNodes) {
|
83 | 85 | public void testNodeCounts() {
|
84 | 86 | int total = 1;
|
85 | 87 | internalCluster().startNode();
|
86 |
| - Map<String, Integer> expectedCounts = new HashMap<>(); |
87 |
| - expectedCounts.put(DiscoveryNodeRole.DATA_ROLE.roleName(), 1); |
88 |
| - expectedCounts.put(DiscoveryNodeRole.MASTER_ROLE.roleName(), 1); |
89 |
| - expectedCounts.put(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName(), 1); |
90 |
| - expectedCounts.put(DiscoveryNodeRole.INGEST_ROLE.roleName(), 1); |
91 |
| - expectedCounts.put(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName(), 1); |
92 |
| - expectedCounts.put(DiscoveryNodeRole.SEARCH_ROLE.roleName(), 0); |
93 |
| - expectedCounts.put(ClusterStatsNodes.Counts.COORDINATING_ONLY, 0); |
| 88 | + Map<String, Integer> expectedCounts = getExpectedCounts(1, 1, 1, 1, 1, 0, 0); |
94 | 89 | int numNodes = randomIntBetween(1, 5);
|
95 | 90 |
|
96 | 91 | ClusterStatsResponse response = client().admin().cluster().prepareClusterStats().get();
|
@@ -147,25 +142,21 @@ public void testNodeCounts() {
|
147 | 142 | }
|
148 | 143 |
|
149 | 144 | // Validate assigning value "master" to setting "node.roles" can get correct count in Node Stats response after MASTER_ROLE deprecated.
|
150 |
| - public void testNodeCountsWithDeprecatedMasterRole() { |
| 145 | + public void testNodeCountsWithDeprecatedMasterRole() throws ExecutionException, InterruptedException { |
151 | 146 | int total = 1;
|
152 | 147 | Settings settings = Settings.builder()
|
153 | 148 | .putList(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), Collections.singletonList(DiscoveryNodeRole.MASTER_ROLE.roleName()))
|
154 | 149 | .build();
|
155 | 150 | internalCluster().startNode(settings);
|
156 | 151 | waitForNodes(total);
|
157 | 152 |
|
158 |
| - Map<String, Integer> expectedCounts = new HashMap<>(); |
159 |
| - expectedCounts.put(DiscoveryNodeRole.DATA_ROLE.roleName(), 0); |
160 |
| - expectedCounts.put(DiscoveryNodeRole.MASTER_ROLE.roleName(), 1); |
161 |
| - expectedCounts.put(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName(), 1); |
162 |
| - expectedCounts.put(DiscoveryNodeRole.INGEST_ROLE.roleName(), 0); |
163 |
| - expectedCounts.put(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName(), 0); |
164 |
| - expectedCounts.put(DiscoveryNodeRole.SEARCH_ROLE.roleName(), 0); |
165 |
| - expectedCounts.put(ClusterStatsNodes.Counts.COORDINATING_ONLY, 0); |
| 153 | + Map<String, Integer> expectedCounts = getExpectedCounts(0, 1, 1, 0, 0, 0, 0); |
166 | 154 |
|
167 | 155 | ClusterStatsResponse response = client().admin().cluster().prepareClusterStats().get();
|
168 | 156 | assertCounts(response.getNodesStats().getCounts(), total, expectedCounts);
|
| 157 | + |
| 158 | + Set<String> expectedRoles = Set.of(DiscoveryNodeRole.MASTER_ROLE.roleName()); |
| 159 | + assertEquals(expectedRoles, getNodeRoles(0)); |
169 | 160 | }
|
170 | 161 |
|
171 | 162 | private static void incrementCountForRole(String role, Map<String, Integer> counts) {
|
@@ -322,4 +313,136 @@ public void testFieldTypes() {
|
322 | 313 | }
|
323 | 314 | }
|
324 | 315 | }
|
| 316 | + |
| 317 | + public void testNodeRolesWithMasterLegacySettings() throws ExecutionException, InterruptedException { |
| 318 | + int total = 1; |
| 319 | + Settings legacyMasterSettings = Settings.builder() |
| 320 | + .put("node.master", true) |
| 321 | + .put("node.data", false) |
| 322 | + .put("node.ingest", false) |
| 323 | + .build(); |
| 324 | + |
| 325 | + internalCluster().startNodes(legacyMasterSettings); |
| 326 | + waitForNodes(total); |
| 327 | + |
| 328 | + Map<String, Integer> expectedCounts = getExpectedCounts(0, 1, 1, 0, 1, 0, 0); |
| 329 | + |
| 330 | + ClusterStatsResponse clusterStatsResponse = client().admin().cluster().prepareClusterStats().get(); |
| 331 | + assertCounts(clusterStatsResponse.getNodesStats().getCounts(), total, expectedCounts); |
| 332 | + |
| 333 | + Set<String> expectedRoles = Set.of( |
| 334 | + DiscoveryNodeRole.MASTER_ROLE.roleName(), |
| 335 | + DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName() |
| 336 | + ); |
| 337 | + assertEquals(expectedRoles, getNodeRoles(0)); |
| 338 | + } |
| 339 | + |
| 340 | + public void testNodeRolesWithClusterManagerRole() throws ExecutionException, InterruptedException { |
| 341 | + int total = 1; |
| 342 | + Settings clusterManagerNodeRoleSettings = Settings.builder() |
| 343 | + .put( |
| 344 | + "node.roles", |
| 345 | + String.format( |
| 346 | + Locale.ROOT, |
| 347 | + "%s, %s", |
| 348 | + DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName(), |
| 349 | + DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName() |
| 350 | + ) |
| 351 | + ) |
| 352 | + .build(); |
| 353 | + |
| 354 | + internalCluster().startNodes(clusterManagerNodeRoleSettings); |
| 355 | + waitForNodes(total); |
| 356 | + |
| 357 | + Map<String, Integer> expectedCounts = getExpectedCounts(0, 1, 1, 0, 1, 0, 0); |
| 358 | + |
| 359 | + ClusterStatsResponse clusterStatsResponse = client().admin().cluster().prepareClusterStats().get(); |
| 360 | + assertCounts(clusterStatsResponse.getNodesStats().getCounts(), total, expectedCounts); |
| 361 | + |
| 362 | + Set<String> expectedRoles = Set.of( |
| 363 | + DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName(), |
| 364 | + DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName() |
| 365 | + ); |
| 366 | + assertEquals(expectedRoles, getNodeRoles(0)); |
| 367 | + } |
| 368 | + |
| 369 | + public void testNodeRolesWithSeedDataNodeLegacySettings() throws ExecutionException, InterruptedException { |
| 370 | + int total = 1; |
| 371 | + Settings legacySeedDataNodeSettings = Settings.builder() |
| 372 | + .put("node.master", true) |
| 373 | + .put("node.data", true) |
| 374 | + .put("node.ingest", false) |
| 375 | + .build(); |
| 376 | + |
| 377 | + internalCluster().startNodes(legacySeedDataNodeSettings); |
| 378 | + waitForNodes(total); |
| 379 | + |
| 380 | + Map<String, Integer> expectedRoleCounts = getExpectedCounts(1, 1, 1, 0, 1, 0, 0); |
| 381 | + |
| 382 | + ClusterStatsResponse clusterStatsResponse = client().admin().cluster().prepareClusterStats().get(); |
| 383 | + assertCounts(clusterStatsResponse.getNodesStats().getCounts(), total, expectedRoleCounts); |
| 384 | + |
| 385 | + Set<String> expectedRoles = Set.of( |
| 386 | + DiscoveryNodeRole.MASTER_ROLE.roleName(), |
| 387 | + DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName(), |
| 388 | + DiscoveryNodeRole.DATA_ROLE.roleName() |
| 389 | + ); |
| 390 | + assertEquals(expectedRoles, getNodeRoles(0)); |
| 391 | + } |
| 392 | + |
| 393 | + public void testNodeRolesWithDataNodeLegacySettings() throws ExecutionException, InterruptedException { |
| 394 | + int total = 2; |
| 395 | + Settings legacyDataNodeSettings = Settings.builder() |
| 396 | + .put("node.master", false) |
| 397 | + .put("node.data", true) |
| 398 | + .put("node.ingest", false) |
| 399 | + .build(); |
| 400 | + |
| 401 | + // can't start data-only node without assigning cluster-manager |
| 402 | + internalCluster().startClusterManagerOnlyNodes(1); |
| 403 | + internalCluster().startNodes(legacyDataNodeSettings); |
| 404 | + waitForNodes(total); |
| 405 | + |
| 406 | + Map<String, Integer> expectedRoleCounts = getExpectedCounts(1, 1, 1, 0, 1, 0, 0); |
| 407 | + |
| 408 | + ClusterStatsResponse clusterStatsResponse = client().admin().cluster().prepareClusterStats().get(); |
| 409 | + assertCounts(clusterStatsResponse.getNodesStats().getCounts(), total, expectedRoleCounts); |
| 410 | + |
| 411 | + Set<Set<String>> expectedNodesRoles = Set.of( |
| 412 | + Set.of(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName()), |
| 413 | + Set.of(DiscoveryNodeRole.DATA_ROLE.roleName(), DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName()) |
| 414 | + ); |
| 415 | + assertEquals(expectedNodesRoles, Set.of(getNodeRoles(0), getNodeRoles(1))); |
| 416 | + } |
| 417 | + |
| 418 | + private Map<String, Integer> getExpectedCounts( |
| 419 | + int dataRoleCount, |
| 420 | + int masterRoleCount, |
| 421 | + int clusterManagerRoleCount, |
| 422 | + int ingestRoleCount, |
| 423 | + int remoteClusterClientRoleCount, |
| 424 | + int searchRoleCount, |
| 425 | + int coordinatingOnlyCount |
| 426 | + ) { |
| 427 | + Map<String, Integer> expectedCounts = new HashMap<>(); |
| 428 | + expectedCounts.put(DiscoveryNodeRole.DATA_ROLE.roleName(), dataRoleCount); |
| 429 | + expectedCounts.put(DiscoveryNodeRole.MASTER_ROLE.roleName(), masterRoleCount); |
| 430 | + expectedCounts.put(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName(), clusterManagerRoleCount); |
| 431 | + expectedCounts.put(DiscoveryNodeRole.INGEST_ROLE.roleName(), ingestRoleCount); |
| 432 | + expectedCounts.put(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName(), remoteClusterClientRoleCount); |
| 433 | + expectedCounts.put(DiscoveryNodeRole.SEARCH_ROLE.roleName(), searchRoleCount); |
| 434 | + expectedCounts.put(ClusterStatsNodes.Counts.COORDINATING_ONLY, coordinatingOnlyCount); |
| 435 | + return expectedCounts; |
| 436 | + } |
| 437 | + |
| 438 | + private Set<String> getNodeRoles(int nodeNumber) throws ExecutionException, InterruptedException { |
| 439 | + NodesStatsResponse nodesStatsResponse = client().admin().cluster().nodesStats(new NodesStatsRequest()).get(); |
| 440 | + return nodesStatsResponse.getNodes() |
| 441 | + .get(nodeNumber) |
| 442 | + .getNode() |
| 443 | + .getRoles() |
| 444 | + .stream() |
| 445 | + .map(DiscoveryNodeRole::roleName) |
| 446 | + .collect(Collectors.toSet()); |
| 447 | + } |
325 | 448 | }
|
0 commit comments