|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License; |
| 4 | + * you may not use this file except in compliance with the Elastic License. |
| 5 | + */ |
| 6 | + |
| 7 | +package org.elasticsearch.xpack.ccr; |
| 8 | + |
| 9 | +import org.elasticsearch.common.xcontent.XContentType; |
| 10 | +import org.elasticsearch.index.IndexNotFoundException; |
| 11 | +import org.elasticsearch.index.IndexSettings; |
| 12 | +import org.elasticsearch.xpack.CcrSingleNodeTestCase; |
| 13 | +import org.elasticsearch.xpack.core.ccr.action.FollowInfoAction; |
| 14 | +import org.elasticsearch.xpack.core.ccr.action.PauseFollowAction; |
| 15 | +import org.elasticsearch.xpack.core.ccr.action.PutFollowAction; |
| 16 | + |
| 17 | +import java.util.Comparator; |
| 18 | + |
| 19 | +import static java.util.Collections.singletonMap; |
| 20 | +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; |
| 21 | +import static org.elasticsearch.xpack.ccr.LocalIndexFollowingIT.getIndexSettings; |
| 22 | +import static org.elasticsearch.xpack.core.ccr.action.FollowInfoAction.Response.Status; |
| 23 | +import static org.hamcrest.Matchers.equalTo; |
| 24 | +import static org.hamcrest.Matchers.notNullValue; |
| 25 | +import static org.hamcrest.Matchers.nullValue; |
| 26 | + |
| 27 | +public class FollowInfoIT extends CcrSingleNodeTestCase { |
| 28 | + |
| 29 | + public void testFollowInfoApiFollowerIndexFiltering() throws Exception { |
| 30 | + final String leaderIndexSettings = getIndexSettings(1, 0, |
| 31 | + singletonMap(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "true")); |
| 32 | + assertAcked(client().admin().indices().prepareCreate("leader1").setSource(leaderIndexSettings, XContentType.JSON)); |
| 33 | + ensureGreen("leader1"); |
| 34 | + assertAcked(client().admin().indices().prepareCreate("leader2").setSource(leaderIndexSettings, XContentType.JSON)); |
| 35 | + ensureGreen("leader2"); |
| 36 | + |
| 37 | + PutFollowAction.Request followRequest = getPutFollowRequest("leader1", "follower1"); |
| 38 | + client().execute(PutFollowAction.INSTANCE, followRequest).get(); |
| 39 | + |
| 40 | + followRequest = getPutFollowRequest("leader2", "follower2"); |
| 41 | + client().execute(PutFollowAction.INSTANCE, followRequest).get(); |
| 42 | + |
| 43 | + FollowInfoAction.Request request = new FollowInfoAction.Request(); |
| 44 | + request.setFollowerIndices("follower1"); |
| 45 | + FollowInfoAction.Response response = client().execute(FollowInfoAction.INSTANCE, request).actionGet(); |
| 46 | + assertThat(response.getFollowInfos().size(), equalTo(1)); |
| 47 | + assertThat(response.getFollowInfos().get(0).getFollowerIndex(), equalTo("follower1")); |
| 48 | + assertThat(response.getFollowInfos().get(0).getLeaderIndex(), equalTo("leader1")); |
| 49 | + assertThat(response.getFollowInfos().get(0).getStatus(), equalTo(Status.ACTIVE)); |
| 50 | + assertThat(response.getFollowInfos().get(0).getParameters(), notNullValue()); |
| 51 | + |
| 52 | + request = new FollowInfoAction.Request(); |
| 53 | + request.setFollowerIndices("follower2"); |
| 54 | + response = client().execute(FollowInfoAction.INSTANCE, request).actionGet(); |
| 55 | + assertThat(response.getFollowInfos().size(), equalTo(1)); |
| 56 | + assertThat(response.getFollowInfos().get(0).getFollowerIndex(), equalTo("follower2")); |
| 57 | + assertThat(response.getFollowInfos().get(0).getLeaderIndex(), equalTo("leader2")); |
| 58 | + assertThat(response.getFollowInfos().get(0).getStatus(), equalTo(Status.ACTIVE)); |
| 59 | + assertThat(response.getFollowInfos().get(0).getParameters(), notNullValue()); |
| 60 | + |
| 61 | + request = new FollowInfoAction.Request(); |
| 62 | + request.setFollowerIndices("_all"); |
| 63 | + response = client().execute(FollowInfoAction.INSTANCE, request).actionGet(); |
| 64 | + response.getFollowInfos().sort(Comparator.comparing(FollowInfoAction.Response.FollowerInfo::getFollowerIndex)); |
| 65 | + assertThat(response.getFollowInfos().size(), equalTo(2)); |
| 66 | + assertThat(response.getFollowInfos().get(0).getFollowerIndex(), equalTo("follower1")); |
| 67 | + assertThat(response.getFollowInfos().get(0).getLeaderIndex(), equalTo("leader1")); |
| 68 | + assertThat(response.getFollowInfos().get(0).getStatus(), equalTo(Status.ACTIVE)); |
| 69 | + assertThat(response.getFollowInfos().get(0).getParameters(), notNullValue()); |
| 70 | + assertThat(response.getFollowInfos().get(1).getFollowerIndex(), equalTo("follower2")); |
| 71 | + assertThat(response.getFollowInfos().get(1).getLeaderIndex(), equalTo("leader2")); |
| 72 | + assertThat(response.getFollowInfos().get(1).getStatus(), equalTo(Status.ACTIVE)); |
| 73 | + assertThat(response.getFollowInfos().get(1).getParameters(), notNullValue()); |
| 74 | + |
| 75 | + // Pause follower1 index and check the follower info api: |
| 76 | + assertAcked(client().execute(PauseFollowAction.INSTANCE, new PauseFollowAction.Request("follower1")).actionGet()); |
| 77 | + |
| 78 | + request = new FollowInfoAction.Request(); |
| 79 | + request.setFollowerIndices("follower1"); |
| 80 | + response = client().execute(FollowInfoAction.INSTANCE, request).actionGet(); |
| 81 | + assertThat(response.getFollowInfos().size(), equalTo(1)); |
| 82 | + assertThat(response.getFollowInfos().get(0).getFollowerIndex(), equalTo("follower1")); |
| 83 | + assertThat(response.getFollowInfos().get(0).getLeaderIndex(), equalTo("leader1")); |
| 84 | + assertThat(response.getFollowInfos().get(0).getStatus(), equalTo(Status.PAUSED)); |
| 85 | + assertThat(response.getFollowInfos().get(0).getParameters(), nullValue()); |
| 86 | + |
| 87 | + request = new FollowInfoAction.Request(); |
| 88 | + request.setFollowerIndices("follower2"); |
| 89 | + response = client().execute(FollowInfoAction.INSTANCE, request).actionGet(); |
| 90 | + assertThat(response.getFollowInfos().size(), equalTo(1)); |
| 91 | + assertThat(response.getFollowInfos().get(0).getFollowerIndex(), equalTo("follower2")); |
| 92 | + assertThat(response.getFollowInfos().get(0).getLeaderIndex(), equalTo("leader2")); |
| 93 | + assertThat(response.getFollowInfos().get(0).getStatus(), equalTo(Status.ACTIVE)); |
| 94 | + assertThat(response.getFollowInfos().get(0).getParameters(), notNullValue()); |
| 95 | + |
| 96 | + request = new FollowInfoAction.Request(); |
| 97 | + request.setFollowerIndices("_all"); |
| 98 | + response = client().execute(FollowInfoAction.INSTANCE, request).actionGet(); |
| 99 | + response.getFollowInfos().sort(Comparator.comparing(FollowInfoAction.Response.FollowerInfo::getFollowerIndex)); |
| 100 | + assertThat(response.getFollowInfos().size(), equalTo(2)); |
| 101 | + assertThat(response.getFollowInfos().get(0).getFollowerIndex(), equalTo("follower1")); |
| 102 | + assertThat(response.getFollowInfos().get(0).getLeaderIndex(), equalTo("leader1")); |
| 103 | + assertThat(response.getFollowInfos().get(0).getStatus(), equalTo(Status.PAUSED)); |
| 104 | + assertThat(response.getFollowInfos().get(0).getParameters(), nullValue()); |
| 105 | + assertThat(response.getFollowInfos().get(1).getFollowerIndex(), equalTo("follower2")); |
| 106 | + assertThat(response.getFollowInfos().get(1).getLeaderIndex(), equalTo("leader2")); |
| 107 | + assertThat(response.getFollowInfos().get(1).getStatus(), equalTo(Status.ACTIVE)); |
| 108 | + assertThat(response.getFollowInfos().get(1).getParameters(), notNullValue()); |
| 109 | + |
| 110 | + assertAcked(client().execute(PauseFollowAction.INSTANCE, new PauseFollowAction.Request("follower2")).actionGet()); |
| 111 | + } |
| 112 | + |
| 113 | + public void testFollowInfoApiIndexMissing() throws Exception { |
| 114 | + final String leaderIndexSettings = getIndexSettings(1, 0, |
| 115 | + singletonMap(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "true")); |
| 116 | + assertAcked(client().admin().indices().prepareCreate("leader1").setSource(leaderIndexSettings, XContentType.JSON)); |
| 117 | + ensureGreen("leader1"); |
| 118 | + assertAcked(client().admin().indices().prepareCreate("leader2").setSource(leaderIndexSettings, XContentType.JSON)); |
| 119 | + ensureGreen("leader2"); |
| 120 | + |
| 121 | + PutFollowAction.Request followRequest = getPutFollowRequest("leader1", "follower1"); |
| 122 | + client().execute(PutFollowAction.INSTANCE, followRequest).get(); |
| 123 | + |
| 124 | + followRequest = getPutFollowRequest("leader2", "follower2"); |
| 125 | + client().execute(PutFollowAction.INSTANCE, followRequest).get(); |
| 126 | + |
| 127 | + FollowInfoAction.Request request1 = new FollowInfoAction.Request(); |
| 128 | + request1.setFollowerIndices("follower3"); |
| 129 | + expectThrows(IndexNotFoundException.class, () -> client().execute(FollowInfoAction.INSTANCE, request1).actionGet()); |
| 130 | + |
| 131 | + FollowInfoAction.Request request2 = new FollowInfoAction.Request(); |
| 132 | + request2.setFollowerIndices("follower2", "follower3"); |
| 133 | + expectThrows(IndexNotFoundException.class, () -> client().execute(FollowInfoAction.INSTANCE, request2).actionGet()); |
| 134 | + |
| 135 | + assertAcked(client().execute(PauseFollowAction.INSTANCE, new PauseFollowAction.Request("follower1")).actionGet()); |
| 136 | + assertAcked(client().execute(PauseFollowAction.INSTANCE, new PauseFollowAction.Request("follower2")).actionGet()); |
| 137 | + } |
| 138 | + |
| 139 | +} |
0 commit comments