|
16 | 16 | import org.elasticsearch.action.admin.indices.resolve.ResolveClusterActionResponse; |
17 | 17 | import org.elasticsearch.action.admin.indices.resolve.ResolveClusterInfo; |
18 | 18 | import org.elasticsearch.action.admin.indices.resolve.TransportResolveClusterAction; |
| 19 | +import org.elasticsearch.action.support.IndicesOptions; |
19 | 20 | import org.elasticsearch.client.internal.Client; |
20 | 21 | import org.elasticsearch.cluster.metadata.IndexMetadata; |
21 | 22 | import org.elasticsearch.common.Strings; |
@@ -405,6 +406,52 @@ public void testClusterResolveWithIndices() throws IOException { |
405 | 406 | } |
406 | 407 | } |
407 | 408 |
|
| 409 | + // corresponds to the GET _resolve/cluster endpoint with no index expression specified |
| 410 | + public void testClusterResolveWithNoIndexExpression() throws IOException { |
| 411 | + Map<String, Object> testClusterInfo = setupThreeClusters(false); |
| 412 | + boolean skipUnavailable1 = (Boolean) testClusterInfo.get("remote1.skip_unavailable"); |
| 413 | + boolean skipUnavailable2 = true; |
| 414 | + |
| 415 | + { |
| 416 | + String[] noIndexSpecified = new String[0]; |
| 417 | + boolean clusterInfoOnly = true; |
| 418 | + boolean runningOnQueryingCluster = true; |
| 419 | + ResolveClusterActionRequest request = new ResolveClusterActionRequest( |
| 420 | + noIndexSpecified, |
| 421 | + IndicesOptions.DEFAULT, |
| 422 | + clusterInfoOnly, |
| 423 | + runningOnQueryingCluster |
| 424 | + ); |
| 425 | + |
| 426 | + ActionFuture<ResolveClusterActionResponse> future = client(LOCAL_CLUSTER).admin() |
| 427 | + .indices() |
| 428 | + .execute(TransportResolveClusterAction.TYPE, request); |
| 429 | + ResolveClusterActionResponse response = future.actionGet(30, TimeUnit.SECONDS); |
| 430 | + assertNotNull(response); |
| 431 | + |
| 432 | + Map<String, ResolveClusterInfo> clusterInfo = response.getResolveClusterInfo(); |
| 433 | + assertEquals(2, clusterInfo.size()); |
| 434 | + |
| 435 | + // only remote clusters should be present (not local) |
| 436 | + Set<String> expectedClusterNames = Set.of(REMOTE_CLUSTER_1, REMOTE_CLUSTER_2); |
| 437 | + assertThat(clusterInfo.keySet(), equalTo(expectedClusterNames)); |
| 438 | + |
| 439 | + ResolveClusterInfo remote1 = clusterInfo.get(REMOTE_CLUSTER_1); |
| 440 | + assertThat(remote1.isConnected(), equalTo(true)); |
| 441 | + assertThat(remote1.getSkipUnavailable(), equalTo(skipUnavailable1)); |
| 442 | + assertThat(remote1.getMatchingIndices(), equalTo(null)); // should not be set |
| 443 | + assertNotNull(remote1.getBuild().version()); |
| 444 | + assertNull(remote1.getError()); |
| 445 | + |
| 446 | + ResolveClusterInfo remote2 = clusterInfo.get(REMOTE_CLUSTER_2); |
| 447 | + assertThat(remote2.isConnected(), equalTo(true)); |
| 448 | + assertThat(remote2.getSkipUnavailable(), equalTo(skipUnavailable2)); |
| 449 | + assertThat(remote2.getMatchingIndices(), equalTo(null)); // should not be set |
| 450 | + assertNotNull(remote2.getBuild().version()); |
| 451 | + assertNull(remote2.getError()); |
| 452 | + } |
| 453 | + } |
| 454 | + |
408 | 455 | public void testClusterResolveWithMatchingAliases() throws IOException { |
409 | 456 | Map<String, Object> testClusterInfo = setupThreeClusters(true); |
410 | 457 | String localAlias = (String) testClusterInfo.get("local.alias"); |
@@ -522,6 +569,24 @@ public void testClusterResolveWithMatchingAliases() throws IOException { |
522 | 569 | } |
523 | 570 | } |
524 | 571 |
|
| 572 | + public void testClusterResolveWithNoMatchingClustersReturnsEmptyResult() throws Exception { |
| 573 | + setupThreeClusters(false); |
| 574 | + { |
| 575 | + String[] indexExpressions = new String[] { "no_matching_cluster*:foo" }; |
| 576 | + ResolveClusterActionRequest request = new ResolveClusterActionRequest(indexExpressions); |
| 577 | + |
| 578 | + ActionFuture<ResolveClusterActionResponse> future = client(LOCAL_CLUSTER).admin() |
| 579 | + .indices() |
| 580 | + .execute(TransportResolveClusterAction.TYPE, request); |
| 581 | + ResolveClusterActionResponse response = future.actionGet(10, TimeUnit.SECONDS); |
| 582 | + assertNotNull(response); |
| 583 | + |
| 584 | + Map<String, ResolveClusterInfo> clusterInfo = response.getResolveClusterInfo(); |
| 585 | + assertEquals(0, clusterInfo.size()); |
| 586 | + assertThat(Strings.toString(response), equalTo("{}")); |
| 587 | + } |
| 588 | + } |
| 589 | + |
525 | 590 | public void testClusterResolveDisconnectedAndErrorScenarios() throws Exception { |
526 | 591 | Map<String, Object> testClusterInfo = setupThreeClusters(false); |
527 | 592 | String localIndex = (String) testClusterInfo.get("local.index"); |
@@ -615,9 +680,49 @@ public void testClusterResolveDisconnectedAndErrorScenarios() throws Exception { |
615 | 680 | assertNotNull(local.getBuild().version()); |
616 | 681 | assertNull(local.getError()); |
617 | 682 | } |
| 683 | + |
| 684 | + // cluster1 was stopped/disconnected, so it should return a connected:false response when querying with no index expression, |
| 685 | + // corresponding to GET _resolve/cluster endpoint |
| 686 | + { |
| 687 | + String[] noIndexSpecified = new String[0]; |
| 688 | + boolean clusterInfoOnly = true; |
| 689 | + boolean runningOnQueryingCluster = true; |
| 690 | + ResolveClusterActionRequest request = new ResolveClusterActionRequest( |
| 691 | + noIndexSpecified, |
| 692 | + IndicesOptions.DEFAULT, |
| 693 | + clusterInfoOnly, |
| 694 | + runningOnQueryingCluster |
| 695 | + ); |
| 696 | + |
| 697 | + ActionFuture<ResolveClusterActionResponse> future = client(LOCAL_CLUSTER).admin() |
| 698 | + .indices() |
| 699 | + .execute(TransportResolveClusterAction.TYPE, request); |
| 700 | + ResolveClusterActionResponse response = future.actionGet(30, TimeUnit.SECONDS); |
| 701 | + assertNotNull(response); |
| 702 | + |
| 703 | + Map<String, ResolveClusterInfo> clusterInfo = response.getResolveClusterInfo(); |
| 704 | + assertEquals(2, clusterInfo.size()); |
| 705 | + // local cluster is not present when querying without an index expression |
| 706 | + Set<String> expectedClusterNames = Set.of(REMOTE_CLUSTER_1, REMOTE_CLUSTER_2); |
| 707 | + assertThat(clusterInfo.keySet(), equalTo(expectedClusterNames)); |
| 708 | + |
| 709 | + ResolveClusterInfo remote1 = clusterInfo.get(REMOTE_CLUSTER_1); |
| 710 | + assertThat(remote1.isConnected(), equalTo(false)); |
| 711 | + assertThat(remote1.getSkipUnavailable(), equalTo(skipUnavailable1)); |
| 712 | + assertNull(remote1.getMatchingIndices()); |
| 713 | + assertNull(remote1.getBuild()); |
| 714 | + assertNull(remote1.getError()); |
| 715 | + |
| 716 | + ResolveClusterInfo remote2 = clusterInfo.get(REMOTE_CLUSTER_2); |
| 717 | + assertThat(remote2.isConnected(), equalTo(true)); |
| 718 | + assertThat(remote2.getSkipUnavailable(), equalTo(skipUnavailable2)); |
| 719 | + assertNull(remote2.getMatchingIndices()); // not present when no index expression specified |
| 720 | + assertNotNull(remote2.getBuild().version()); |
| 721 | + assertNull(remote2.getError()); |
| 722 | + } |
618 | 723 | } |
619 | 724 |
|
620 | | - private Map<String, Object> setupThreeClusters(boolean useAlias) throws IOException { |
| 725 | + private Map<String, Object> setupThreeClusters(boolean useAlias) { |
621 | 726 | String localAlias = randomAlphaOfLengthBetween(5, 25); |
622 | 727 | String remoteAlias1 = randomAlphaOfLengthBetween(5, 25); |
623 | 728 | String remoteAlias2 = randomAlphaOfLengthBetween(5, 25); |
|
0 commit comments