@@ -80,7 +80,7 @@ public void testFollowIndex() throws Exception {
80
80
refresh (allowedIndex );
81
81
verifyDocuments (adminClient (), allowedIndex , numDocs );
82
82
} else {
83
- follow (allowedIndex , allowedIndex );
83
+ follow (client (), allowedIndex , allowedIndex );
84
84
assertBusy (() -> verifyDocuments (client (), allowedIndex , numDocs ));
85
85
assertThat (countCcrNodeTasks (), equalTo (1 ));
86
86
assertBusy (() -> verifyCcrMonitoring (allowedIndex , allowedIndex ));
@@ -93,7 +93,7 @@ public void testFollowIndex() throws Exception {
93
93
assertThat (countCcrNodeTasks (), equalTo (0 ));
94
94
});
95
95
96
- resumeFollow (allowedIndex , allowedIndex );
96
+ resumeFollow (allowedIndex );
97
97
assertThat (countCcrNodeTasks (), equalTo (1 ));
98
98
assertOK (client ().performRequest (new Request ("POST" , "/" + allowedIndex + "/_ccr/pause_follow" )));
99
99
// Make sure that there are no other ccr relates operations running:
@@ -106,11 +106,11 @@ public void testFollowIndex() throws Exception {
106
106
107
107
assertOK (client ().performRequest (new Request ("POST" , "/" + allowedIndex + "/_close" )));
108
108
assertOK (client ().performRequest (new Request ("POST" , "/" + allowedIndex + "/_ccr/unfollow" )));
109
- Exception e = expectThrows (ResponseException .class , () -> resumeFollow (allowedIndex , allowedIndex ));
109
+ Exception e = expectThrows (ResponseException .class , () -> resumeFollow (allowedIndex ));
110
110
assertThat (e .getMessage (), containsString ("follow index [" + allowedIndex + "] does not have ccr metadata" ));
111
111
112
112
// User does not have manage_follow_index index privilege for 'unallowedIndex':
113
- e = expectThrows (ResponseException .class , () -> follow (unallowedIndex , unallowedIndex ));
113
+ e = expectThrows (ResponseException .class , () -> follow (client (), unallowedIndex , unallowedIndex ));
114
114
assertThat (e .getMessage (),
115
115
containsString ("action [indices:admin/xpack/ccr/put_follow] is unauthorized for user [test_ccr]" ));
116
116
// Verify that the follow index has not been created and no node tasks are running
@@ -119,24 +119,28 @@ public void testFollowIndex() throws Exception {
119
119
120
120
// User does have manage_follow_index index privilege on 'allowed' index,
121
121
// but not read / monitor roles on 'disallowed' index:
122
- e = expectThrows (ResponseException .class , () -> follow (unallowedIndex , allowedIndex ));
122
+ e = expectThrows (ResponseException .class , () -> follow (client (), unallowedIndex , allowedIndex ));
123
123
assertThat (e .getMessage (), containsString ("insufficient privileges to follow index [unallowed-index], " +
124
124
"privilege for action [indices:monitor/stats] is missing, " +
125
125
"privilege for action [indices:data/read/xpack/ccr/shard_changes] is missing" ));
126
126
// Verify that the follow index has not been created and no node tasks are running
127
127
assertThat (indexExists (adminClient (), unallowedIndex ), is (false ));
128
128
assertBusy (() -> assertThat (countCcrNodeTasks (), equalTo (0 )));
129
129
130
- e = expectThrows (ResponseException .class , () -> resumeFollow (unallowedIndex , unallowedIndex ));
130
+ follow (adminClient (), unallowedIndex , unallowedIndex );
131
+ pauseFollow (adminClient (), unallowedIndex );
132
+
133
+ e = expectThrows (ResponseException .class , () -> resumeFollow (unallowedIndex ));
131
134
assertThat (e .getMessage (), containsString ("insufficient privileges to follow index [unallowed-index], " +
132
135
"privilege for action [indices:monitor/stats] is missing, " +
133
136
"privilege for action [indices:data/read/xpack/ccr/shard_changes] is missing" ));
134
- assertThat (indexExists (adminClient (), unallowedIndex ), is (false ));
135
- assertBusy (() -> assertThat (countCcrNodeTasks (), equalTo (0 )));
136
137
137
138
e = expectThrows (ResponseException .class ,
138
139
() -> client ().performRequest (new Request ("POST" , "/" + unallowedIndex + "/_ccr/unfollow" )));
139
140
assertThat (e .getMessage (), containsString ("action [indices:admin/xpack/ccr/unfollow] is unauthorized for user [test_ccr]" ));
141
+ assertOK (adminClient ().performRequest (new Request ("POST" , "/" + unallowedIndex + "/_close" )));
142
+ assertOK (adminClient ().performRequest (new Request ("POST" , "/" + unallowedIndex + "/_ccr/unfollow" )));
143
+ assertBusy (() -> assertThat (countCcrNodeTasks (), equalTo (0 )));
140
144
}
141
145
}
142
146
@@ -187,7 +191,7 @@ public void testAutoFollowPatterns() throws Exception {
187
191
// Cleanup by deleting auto follow pattern and pause following:
188
192
request = new Request ("DELETE" , "/_ccr/auto_follow/test_pattern" );
189
193
assertOK (client ().performRequest (request ));
190
- pauseFollow (allowedIndex );
194
+ pauseFollow (client (), allowedIndex );
191
195
}
192
196
193
197
private int countCcrNodeTasks () throws IOException {
@@ -228,18 +232,17 @@ private static void refresh(String index) throws IOException {
228
232
assertOK (adminClient ().performRequest (new Request ("POST" , "/" + index + "/_refresh" )));
229
233
}
230
234
231
- private static void resumeFollow (String leaderIndex , String followIndex ) throws IOException {
235
+ private static void resumeFollow (String followIndex ) throws IOException {
232
236
final Request request = new Request ("POST" , "/" + followIndex + "/_ccr/resume_follow" );
233
- request .setJsonEntity ("{\" leader_cluster\" : \" leader_cluster\" , \" leader_index\" : \" " + leaderIndex +
234
- "\" , \" poll_timeout\" : \" 10ms\" }" );
237
+ request .setJsonEntity ("{\" poll_timeout\" : \" 10ms\" }" );
235
238
assertOK (client ().performRequest (request ));
236
239
}
237
240
238
- private static void follow (String leaderIndex , String followIndex ) throws IOException {
241
+ private static void follow (RestClient client , String leaderIndex , String followIndex ) throws IOException {
239
242
final Request request = new Request ("PUT" , "/" + followIndex + "/_ccr/follow" );
240
243
request .setJsonEntity ("{\" leader_cluster\" : \" leader_cluster\" , \" leader_index\" : \" " + leaderIndex +
241
244
"\" , \" poll_timeout\" : \" 10ms\" }" );
242
- assertOK (client () .performRequest (request ));
245
+ assertOK (client .performRequest (request ));
243
246
}
244
247
245
248
void verifyDocuments (RestClient client , String index , int expectedNumDocs ) throws IOException {
@@ -302,7 +305,7 @@ private static boolean indexExists(RestClient client, String index) throws IOExc
302
305
return RestStatus .OK .getStatus () == response .getStatusLine ().getStatusCode ();
303
306
}
304
307
305
- private static void pauseFollow (String followIndex ) throws IOException {
308
+ private static void pauseFollow (RestClient client , String followIndex ) throws IOException {
306
309
assertOK (client ().performRequest (new Request ("POST" , "/" + followIndex + "/_ccr/pause_follow" )));
307
310
}
308
311
0 commit comments