77
88package org .elasticsearch .xpack .migrate .action ;
99
10- import org .elasticsearch .ElasticsearchException ;
1110import org .elasticsearch .ResourceNotFoundException ;
1211import org .elasticsearch .action .DocWriteRequest ;
1312import org .elasticsearch .action .admin .indices .create .CreateIndexRequest ;
1615import org .elasticsearch .action .admin .indices .refresh .RefreshRequest ;
1716import org .elasticsearch .action .admin .indices .rollover .RolloverRequest ;
1817import org .elasticsearch .action .admin .indices .settings .get .GetSettingsRequest ;
19- import org .elasticsearch .action .admin .indices .settings .get .GetSettingsResponse ;
2018import org .elasticsearch .action .admin .indices .settings .put .UpdateSettingsRequest ;
2119import org .elasticsearch .action .admin .indices .template .delete .DeleteIndexTemplateRequest ;
2220import org .elasticsearch .action .admin .indices .template .delete .TransportDeleteIndexTemplateAction ;
2624import org .elasticsearch .action .index .IndexRequest ;
2725import org .elasticsearch .action .ingest .PutPipelineRequest ;
2826import org .elasticsearch .action .ingest .PutPipelineTransportAction ;
29- import org .elasticsearch .cluster .block .ClusterBlockException ;
3027import org .elasticsearch .cluster .metadata .ComposableIndexTemplate ;
3128import org .elasticsearch .cluster .metadata .IndexMetadata ;
3229import org .elasticsearch .cluster .metadata .MappingMetadata ;
33- import org .elasticsearch .cluster .metadata .MetadataIndexStateService ;
3430import org .elasticsearch .cluster .metadata .Template ;
3531import org .elasticsearch .common .bytes .BytesArray ;
3632import org .elasticsearch .common .compress .CompressedXContent ;
6359import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertAcked ;
6460import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertHitCount ;
6561import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertResponse ;
66- import static org .elasticsearch .xcontent .XContentFactory .jsonBuilder ;
6762import static org .hamcrest .Matchers .equalTo ;
6863
6964public class ReindexDatastreamIndexTransportActionIT extends ESIntegTestCase {
@@ -243,8 +238,7 @@ public void testDestIndexNameSet_noDotPrefix() throws Exception {
243238 assertEquals (expectedDestIndexName , response .getDestIndex ());
244239 }
245240
246- public void testDestIndexNameSet_withDotPrefix () throws Exception {
247-
241+ public void testDestIndexNameSet_withDotPrefix () {
248242 var sourceIndex = "." + randomAlphaOfLength (20 ).toLowerCase (Locale .ROOT );
249243 safeGet (indicesAdmin ().create (new CreateIndexRequest (sourceIndex )));
250244
@@ -257,13 +251,19 @@ public void testDestIndexNameSet_withDotPrefix() throws Exception {
257251 assertEquals (expectedDestIndexName , response .getDestIndex ());
258252 }
259253
260- public void testDestIndexContainsDocs () throws Exception {
254+ public void testDestIndexContainsDocs () {
261255 // source index with docs
262256 var numDocs = randomIntBetween (1 , 100 );
263257 var sourceIndex = randomAlphaOfLength (20 ).toLowerCase (Locale .ROOT );
264258 safeGet (indicesAdmin ().create (new CreateIndexRequest (sourceIndex )));
265259 indexDocs (sourceIndex , numDocs );
266260
261+ var settings = Settings .builder ()
262+ .put (IndexMetadata .SETTING_BLOCKS_METADATA , randomBoolean ())
263+ .put (IndexMetadata .SETTING_READ_ONLY , randomBoolean ())
264+ .build ();
265+ safeGet (indicesAdmin ().updateSettings (new UpdateSettingsRequest (settings , sourceIndex )));
266+
267267 // call reindex
268268 var response = safeGet (
269269 client ().execute (ReindexDataStreamIndexAction .INSTANCE , new ReindexDataStreamIndexAction .Request (sourceIndex ))
@@ -274,29 +274,6 @@ public void testDestIndexContainsDocs() throws Exception {
274274 assertHitCount (prepareSearch (response .getDestIndex ()).setSize (0 ), numDocs );
275275 }
276276
277- public void testSetSourceToBlockWrites () throws Exception {
278- var settings = randomBoolean () ? Settings .builder ().put (IndexMetadata .SETTING_BLOCKS_WRITE , true ).build () : Settings .EMPTY ;
279-
280- // empty source index
281- var sourceIndex = randomAlphaOfLength (20 ).toLowerCase (Locale .ROOT );
282- safeGet (indicesAdmin ().create (new CreateIndexRequest (sourceIndex , settings )));
283-
284- // call reindex
285- safeGet (client ().execute (ReindexDataStreamIndexAction .INSTANCE , new ReindexDataStreamIndexAction .Request (sourceIndex )));
286-
287- // Assert that source index is now read-only but not verified read-only
288- GetSettingsResponse getSettingsResponse = safeGet (admin ().indices ().getSettings (new GetSettingsRequest ().indices (sourceIndex )));
289- assertTrue (parseBoolean (getSettingsResponse .getSetting (sourceIndex , IndexMetadata .SETTING_BLOCKS_WRITE )));
290- assertFalse (
291- parseBoolean (getSettingsResponse .getSetting (sourceIndex , MetadataIndexStateService .VERIFIED_READ_ONLY_SETTING .getKey ()))
292- );
293-
294- // assert that write to source fails
295- var indexReq = new IndexRequest (sourceIndex ).source (jsonBuilder ().startObject ().field ("field" , "1" ).endObject ());
296- expectThrows (ClusterBlockException .class , client ().index (indexReq ));
297- assertHitCount (prepareSearch (sourceIndex ).setSize (0 ), 0 );
298- }
299-
300277 public void testMissingSourceIndex () {
301278 var nonExistentSourceIndex = randomAlphaOfLength (20 ).toLowerCase (Locale .ROOT );
302279 expectThrows (
@@ -354,34 +331,6 @@ public void testMappingsAddedToDestIndex() {
354331 assertEquals ("text" , XContentMapValues .extractValue ("properties.foo1.type" , destMappings ));
355332 }
356333
357- public void testFailIfMetadataBlockSet () {
358- var sourceIndex = randomAlphaOfLength (20 ).toLowerCase (Locale .ROOT );
359- var settings = Settings .builder ().put (IndexMetadata .SETTING_BLOCKS_METADATA , true ).build ();
360- safeGet (indicesAdmin ().create (new CreateIndexRequest (sourceIndex , settings )));
361-
362- ElasticsearchException e = expectThrows (
363- ElasticsearchException .class ,
364- client ().execute (ReindexDataStreamIndexAction .INSTANCE , new ReindexDataStreamIndexAction .Request (sourceIndex ))
365- );
366- assertTrue (e .getMessage ().contains ("Cannot reindex index" ) || e .getCause ().getMessage ().equals ("Cannot reindex index" ));
367-
368- cleanupMetadataBlocks (sourceIndex );
369- }
370-
371- public void testFailIfReadBlockSet () {
372- var sourceIndex = randomAlphaOfLength (20 ).toLowerCase (Locale .ROOT );
373- var settings = Settings .builder ().put (IndexMetadata .SETTING_BLOCKS_READ , true ).build ();
374- safeGet (indicesAdmin ().create (new CreateIndexRequest (sourceIndex , settings )));
375-
376- ElasticsearchException e = expectThrows (
377- ElasticsearchException .class ,
378- client ().execute (ReindexDataStreamIndexAction .INSTANCE , new ReindexDataStreamIndexAction .Request (sourceIndex ))
379- );
380- assertTrue (e .getMessage ().contains ("Cannot reindex index" ) || e .getCause ().getMessage ().equals ("Cannot reindex index" ));
381-
382- cleanupMetadataBlocks (sourceIndex );
383- }
384-
385334 public void testReadOnlyBlocksNotAddedBack () {
386335 var sourceIndex = randomAlphaOfLength (20 ).toLowerCase (Locale .ROOT );
387336 var settings = Settings .builder ()
@@ -401,7 +350,6 @@ public void testReadOnlyBlocksNotAddedBack() {
401350 assertFalse (parseBoolean (settingsResponse .getSetting (destIndex , IndexMetadata .SETTING_READ_ONLY_ALLOW_DELETE )));
402351 assertFalse (parseBoolean (settingsResponse .getSetting (destIndex , IndexMetadata .SETTING_BLOCKS_WRITE )));
403352
404- cleanupMetadataBlocks (sourceIndex );
405353 cleanupMetadataBlocks (destIndex );
406354 }
407355
@@ -588,9 +536,8 @@ private static void cleanupMetadataBlocks(String index) {
588536 var settings = Settings .builder ()
589537 .putNull (IndexMetadata .SETTING_READ_ONLY )
590538 .putNull (IndexMetadata .SETTING_READ_ONLY_ALLOW_DELETE )
591- .putNull (IndexMetadata .SETTING_BLOCKS_METADATA )
592- .build ();
593- safeGet (indicesAdmin ().updateSettings (new UpdateSettingsRequest (settings , index )));
539+ .putNull (IndexMetadata .SETTING_BLOCKS_METADATA );
540+ updateIndexSettings (settings , index );
594541 }
595542
596543 private static void indexDocs (String index , int numDocs ) {
0 commit comments