-
Notifications
You must be signed in to change notification settings - Fork 25.2k
[CCR] Move leader_index and leader_cluster parameters from resume follow to put follow api #34638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
87b8f60
21dc7c6
aa9319c
2e72fe9
989e335
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,7 +80,7 @@ public void testFollowIndex() throws Exception { | |
refresh(allowedIndex); | ||
verifyDocuments(adminClient(), allowedIndex, numDocs); | ||
} else { | ||
follow(allowedIndex, allowedIndex); | ||
follow(client(), allowedIndex, allowedIndex); | ||
assertBusy(() -> verifyDocuments(client(), allowedIndex, numDocs)); | ||
assertThat(countCcrNodeTasks(), equalTo(1)); | ||
assertBusy(() -> verifyCcrMonitoring(allowedIndex, allowedIndex)); | ||
|
@@ -93,7 +93,7 @@ public void testFollowIndex() throws Exception { | |
assertThat(countCcrNodeTasks(), equalTo(0)); | ||
}); | ||
|
||
resumeFollow(allowedIndex, allowedIndex); | ||
resumeFollow(allowedIndex); | ||
assertThat(countCcrNodeTasks(), equalTo(1)); | ||
assertOK(client().performRequest(new Request("POST", "/" + allowedIndex + "/_ccr/pause_follow"))); | ||
// Make sure that there are no other ccr relates operations running: | ||
|
@@ -106,11 +106,11 @@ public void testFollowIndex() throws Exception { | |
|
||
assertOK(client().performRequest(new Request("POST", "/" + allowedIndex + "/_close"))); | ||
assertOK(client().performRequest(new Request("POST", "/" + allowedIndex + "/_ccr/unfollow"))); | ||
Exception e = expectThrows(ResponseException.class, () -> resumeFollow(allowedIndex, allowedIndex)); | ||
Exception e = expectThrows(ResponseException.class, () -> resumeFollow(allowedIndex)); | ||
assertThat(e.getMessage(), containsString("follow index [" + allowedIndex + "] does not have ccr metadata")); | ||
|
||
// User does not have manage_follow_index index privilege for 'unallowedIndex': | ||
e = expectThrows(ResponseException.class, () -> follow(unallowedIndex, unallowedIndex)); | ||
e = expectThrows(ResponseException.class, () -> follow(client(), unallowedIndex, unallowedIndex)); | ||
assertThat(e.getMessage(), | ||
containsString("action [indices:admin/xpack/ccr/put_follow] is unauthorized for user [test_ccr]")); | ||
// Verify that the follow index has not been created and no node tasks are running | ||
|
@@ -119,24 +119,28 @@ public void testFollowIndex() throws Exception { | |
|
||
// User does have manage_follow_index index privilege on 'allowed' index, | ||
// but not read / monitor roles on 'disallowed' index: | ||
e = expectThrows(ResponseException.class, () -> follow(unallowedIndex, allowedIndex)); | ||
e = expectThrows(ResponseException.class, () -> follow(client(), unallowedIndex, allowedIndex)); | ||
assertThat(e.getMessage(), containsString("insufficient privileges to follow index [unallowed-index], " + | ||
"privilege for action [indices:monitor/stats] is missing, " + | ||
"privilege for action [indices:data/read/xpack/ccr/shard_changes] is missing")); | ||
// Verify that the follow index has not been created and no node tasks are running | ||
assertThat(indexExists(adminClient(), unallowedIndex), is(false)); | ||
assertBusy(() -> assertThat(countCcrNodeTasks(), equalTo(0))); | ||
|
||
e = expectThrows(ResponseException.class, () -> resumeFollow(unallowedIndex, unallowedIndex)); | ||
follow(adminClient(), unallowedIndex, unallowedIndex); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Execute put follow api with admin client, so that we can check whether we fail with the right error when a normal user resumes following an unallowed index. |
||
pauseFollow(adminClient(), unallowedIndex); | ||
|
||
e = expectThrows(ResponseException.class, () -> resumeFollow(unallowedIndex)); | ||
assertThat(e.getMessage(), containsString("insufficient privileges to follow index [unallowed-index], " + | ||
"privilege for action [indices:monitor/stats] is missing, " + | ||
"privilege for action [indices:data/read/xpack/ccr/shard_changes] is missing")); | ||
assertThat(indexExists(adminClient(), unallowedIndex), is(false)); | ||
assertBusy(() -> assertThat(countCcrNodeTasks(), equalTo(0))); | ||
|
||
e = expectThrows(ResponseException.class, | ||
() -> client().performRequest(new Request("POST", "/" + unallowedIndex + "/_ccr/unfollow"))); | ||
assertThat(e.getMessage(), containsString("action [indices:admin/xpack/ccr/unfollow] is unauthorized for user [test_ccr]")); | ||
assertOK(adminClient().performRequest(new Request("POST", "/" + unallowedIndex + "/_close"))); | ||
assertOK(adminClient().performRequest(new Request("POST", "/" + unallowedIndex + "/_ccr/unfollow"))); | ||
assertBusy(() -> assertThat(countCcrNodeTasks(), equalTo(0))); | ||
} | ||
} | ||
|
||
|
@@ -187,7 +191,7 @@ public void testAutoFollowPatterns() throws Exception { | |
// Cleanup by deleting auto follow pattern and pause following: | ||
request = new Request("DELETE", "/_ccr/auto_follow/test_pattern"); | ||
assertOK(client().performRequest(request)); | ||
pauseFollow(allowedIndex); | ||
pauseFollow(client(), allowedIndex); | ||
} | ||
|
||
private int countCcrNodeTasks() throws IOException { | ||
|
@@ -228,18 +232,17 @@ private static void refresh(String index) throws IOException { | |
assertOK(adminClient().performRequest(new Request("POST", "/" + index + "/_refresh"))); | ||
} | ||
|
||
private static void resumeFollow(String leaderIndex, String followIndex) throws IOException { | ||
private static void resumeFollow(String followIndex) throws IOException { | ||
final Request request = new Request("POST", "/" + followIndex + "/_ccr/resume_follow"); | ||
request.setJsonEntity("{\"leader_cluster\": \"leader_cluster\", \"leader_index\": \"" + leaderIndex + | ||
"\", \"poll_timeout\": \"10ms\"}"); | ||
request.setJsonEntity("{\"poll_timeout\": \"10ms\"}"); | ||
assertOK(client().performRequest(request)); | ||
} | ||
|
||
private static void follow(String leaderIndex, String followIndex) throws IOException { | ||
private static void follow(RestClient client, String leaderIndex, String followIndex) throws IOException { | ||
final Request request = new Request("PUT", "/" + followIndex + "/_ccr/follow"); | ||
request.setJsonEntity("{\"leader_cluster\": \"leader_cluster\", \"leader_index\": \"" + leaderIndex + | ||
"\", \"poll_timeout\": \"10ms\"}"); | ||
assertOK(client().performRequest(request)); | ||
assertOK(client.performRequest(request)); | ||
} | ||
|
||
void verifyDocuments(RestClient client, String index, int expectedNumDocs) throws IOException { | ||
|
@@ -302,7 +305,7 @@ private static boolean indexExists(RestClient client, String index) throws IOExc | |
return RestStatus.OK.getStatus() == response.getStatusLine().getStatusCode(); | ||
} | ||
|
||
private static void pauseFollow(String followIndex) throws IOException { | ||
private static void pauseFollow(RestClient client, String followIndex) throws IOException { | ||
assertOK(client().performRequest(new Request("POST", "/" + followIndex + "/_ccr/pause_follow"))); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,11 +94,11 @@ protected void masterOperation( | |
listener.onFailure(LicenseUtils.newComplianceException("ccr")); | ||
return; | ||
} | ||
String leaderCluster = request.getFollowRequest().getLeaderCluster(); | ||
String leaderCluster = request.getLeaderCluster(); | ||
// Validates whether the leader cluster has been configured properly: | ||
client.getRemoteClusterClient(leaderCluster); | ||
|
||
String leaderIndex = request.getFollowRequest().getLeaderIndex(); | ||
String leaderIndex = request.getLeaderIndex(); | ||
createFollowerIndexAndFollowRemoteIndex(request, leaderCluster, leaderIndex, listener); | ||
} | ||
|
||
|
@@ -121,8 +121,7 @@ private void createFollowerIndex( | |
final PutFollowAction.Request request, | ||
final ActionListener<PutFollowAction.Response> listener) { | ||
if (leaderIndexMetaData == null) { | ||
listener.onFailure(new IllegalArgumentException("leader index [" + request.getFollowRequest().getLeaderIndex() + | ||
"] does not exist")); | ||
listener.onFailure(new IllegalArgumentException("leader index [" + request.getLeaderIndex() + "] does not exist")); | ||
return; | ||
} | ||
|
||
|
@@ -159,6 +158,8 @@ public ClusterState execute(final ClusterState currentState) throws Exception { | |
Map<String, String> metadata = new HashMap<>(); | ||
metadata.put(Ccr.CCR_CUSTOM_METADATA_LEADER_INDEX_SHARD_HISTORY_UUIDS, String.join(",", historyUUIDs)); | ||
metadata.put(Ccr.CCR_CUSTOM_METADATA_LEADER_INDEX_UUID_KEY, leaderIndexMetaData.getIndexUUID()); | ||
metadata.put(Ccr.CCR_CUSTOM_METADATA_LEADER_INDEX_NAME_KEY, leaderIndexMetaData.getIndex().getName()); | ||
metadata.put(Ccr.CCR_CUSTOM_METADATA_LEADER_CLUSTER_NAME_KEY, request.getLeaderCluster()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By remember this two additional key value pairs the resume api no longer needs to accept a leader index / cluster parameters. The leader index name isn't really necessary as the leader index uuid can also be used to lookup the leader index metadata in the leader cluster. The |
||
imdBuilder.putCustom(Ccr.CCR_CUSTOM_METADATA_KEY, metadata); | ||
|
||
// Copy all settings, but overwrite a few settings. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The resume api now looks up the follow index metadata in order to get the leader index name and leader cluster name and because of that this fails with a different error. We can't execute a put follow to create the follow index, because the leader cluster runs with a basic license. So I don't see a way how to test this in another way.