77
88package org .elasticsearch .xpack .migrate .action ;
99
10- import org .elasticsearch .ElasticsearchException ;
1110import org .elasticsearch .ResourceNotFoundException ;
1211import org .elasticsearch .action .ActionRequest ;
1312import org .elasticsearch .action .ActionResponse ;
1817import org .elasticsearch .action .admin .indices .refresh .RefreshRequest ;
1918import org .elasticsearch .action .admin .indices .rollover .RolloverRequest ;
2019import org .elasticsearch .action .admin .indices .settings .get .GetSettingsRequest ;
21- import org .elasticsearch .action .admin .indices .settings .get .GetSettingsResponse ;
2220import org .elasticsearch .action .admin .indices .settings .put .UpdateSettingsRequest ;
2321import org .elasticsearch .action .admin .indices .template .delete .DeleteIndexTemplateRequest ;
2422import org .elasticsearch .action .admin .indices .template .delete .TransportDeleteIndexTemplateAction ;
3634import org .elasticsearch .action .ingest .PutPipelineTransportAction ;
3735import org .elasticsearch .action .support .IndicesOptions ;
3836import org .elasticsearch .action .support .master .AcknowledgedRequest ;
39- import org .elasticsearch .cluster .block .ClusterBlockException ;
4037import org .elasticsearch .cluster .metadata .ComposableIndexTemplate ;
4138import org .elasticsearch .cluster .metadata .IndexMetadata ;
4239import org .elasticsearch .cluster .metadata .MappingMetadata ;
43- import org .elasticsearch .cluster .metadata .MetadataIndexStateService ;
4440import org .elasticsearch .cluster .metadata .Template ;
4541import org .elasticsearch .common .bytes .BytesArray ;
4642import org .elasticsearch .common .compress .CompressedXContent ;
9793import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertAcked ;
9894import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertHitCount ;
9995import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertResponse ;
100- import static org .elasticsearch .xcontent .XContentFactory .jsonBuilder ;
10196import static org .hamcrest .Matchers .equalTo ;
10297import static org .hamcrest .Matchers .not ;
10398
@@ -304,8 +299,7 @@ public void testDestIndexNameSet_noDotPrefix() throws Exception {
304299 assertEquals (expectedDestIndexName , response .getDestIndex ());
305300 }
306301
307- public void testDestIndexNameSet_withDotPrefix () throws Exception {
308-
302+ public void testDestIndexNameSet_withDotPrefix () {
309303 var sourceIndex = "." + randomAlphaOfLength (20 ).toLowerCase (Locale .ROOT );
310304 safeGet (indicesAdmin ().create (new CreateIndexRequest (sourceIndex )));
311305
@@ -318,13 +312,19 @@ public void testDestIndexNameSet_withDotPrefix() throws Exception {
318312 assertEquals (expectedDestIndexName , response .getDestIndex ());
319313 }
320314
321- public void testDestIndexContainsDocs () throws Exception {
315+ public void testDestIndexContainsDocs () {
322316 // source index with docs
323317 var numDocs = randomIntBetween (1 , 100 );
324318 var sourceIndex = randomAlphaOfLength (20 ).toLowerCase (Locale .ROOT );
325319 safeGet (indicesAdmin ().create (new CreateIndexRequest (sourceIndex )));
326320 indexDocs (sourceIndex , numDocs );
327321
322+ var settings = Settings .builder ()
323+ .put (IndexMetadata .SETTING_BLOCKS_METADATA , randomBoolean ())
324+ .put (IndexMetadata .SETTING_READ_ONLY , randomBoolean ())
325+ .build ();
326+ safeGet (indicesAdmin ().updateSettings (new UpdateSettingsRequest (settings , sourceIndex )));
327+
328328 // call reindex
329329 var response = safeGet (
330330 client ().execute (ReindexDataStreamIndexAction .INSTANCE , new ReindexDataStreamIndexAction .Request (sourceIndex ))
@@ -335,29 +335,6 @@ public void testDestIndexContainsDocs() throws Exception {
335335 assertHitCount (prepareSearch (response .getDestIndex ()).setSize (0 ), numDocs );
336336 }
337337
338- public void testSetSourceToBlockWrites () throws Exception {
339- var settings = randomBoolean () ? Settings .builder ().put (IndexMetadata .SETTING_BLOCKS_WRITE , true ).build () : Settings .EMPTY ;
340-
341- // empty source index
342- var sourceIndex = randomAlphaOfLength (20 ).toLowerCase (Locale .ROOT );
343- safeGet (indicesAdmin ().create (new CreateIndexRequest (sourceIndex , settings )));
344-
345- // call reindex
346- safeGet (client ().execute (ReindexDataStreamIndexAction .INSTANCE , new ReindexDataStreamIndexAction .Request (sourceIndex )));
347-
348- // Assert that source index is now read-only but not verified read-only
349- GetSettingsResponse getSettingsResponse = safeGet (admin ().indices ().getSettings (new GetSettingsRequest ().indices (sourceIndex )));
350- assertTrue (parseBoolean (getSettingsResponse .getSetting (sourceIndex , IndexMetadata .SETTING_BLOCKS_WRITE )));
351- assertFalse (
352- parseBoolean (getSettingsResponse .getSetting (sourceIndex , MetadataIndexStateService .VERIFIED_READ_ONLY_SETTING .getKey ()))
353- );
354-
355- // assert that write to source fails
356- var indexReq = new IndexRequest (sourceIndex ).source (jsonBuilder ().startObject ().field ("field" , "1" ).endObject ());
357- expectThrows (ClusterBlockException .class , client ().index (indexReq ));
358- assertHitCount (prepareSearch (sourceIndex ).setSize (0 ), 0 );
359- }
360-
361338 public void testMissingSourceIndex () {
362339 var nonExistentSourceIndex = randomAlphaOfLength (20 ).toLowerCase (Locale .ROOT );
363340 expectThrows (
@@ -413,34 +390,6 @@ public void testMappingsAddedToDestIndex() {
413390 assertEquals ("text" , XContentMapValues .extractValue ("properties.foo1.type" , destMappings ));
414391 }
415392
416- public void testFailIfMetadataBlockSet () {
417- var sourceIndex = randomAlphaOfLength (20 ).toLowerCase (Locale .ROOT );
418- var settings = Settings .builder ().put (IndexMetadata .SETTING_BLOCKS_METADATA , true ).build ();
419- safeGet (indicesAdmin ().create (new CreateIndexRequest (sourceIndex , settings )));
420-
421- ElasticsearchException e = expectThrows (
422- ElasticsearchException .class ,
423- client ().execute (ReindexDataStreamIndexAction .INSTANCE , new ReindexDataStreamIndexAction .Request (sourceIndex ))
424- );
425- assertTrue (e .getMessage ().contains ("Cannot reindex index" ) || e .getCause ().getMessage ().equals ("Cannot reindex index" ));
426-
427- cleanupMetadataBlocks (sourceIndex );
428- }
429-
430- public void testFailIfReadBlockSet () {
431- var sourceIndex = randomAlphaOfLength (20 ).toLowerCase (Locale .ROOT );
432- var settings = Settings .builder ().put (IndexMetadata .SETTING_BLOCKS_READ , true ).build ();
433- safeGet (indicesAdmin ().create (new CreateIndexRequest (sourceIndex , settings )));
434-
435- ElasticsearchException e = expectThrows (
436- ElasticsearchException .class ,
437- client ().execute (ReindexDataStreamIndexAction .INSTANCE , new ReindexDataStreamIndexAction .Request (sourceIndex ))
438- );
439- assertTrue (e .getMessage ().contains ("Cannot reindex index" ) || e .getCause ().getMessage ().equals ("Cannot reindex index" ));
440-
441- cleanupMetadataBlocks (sourceIndex );
442- }
443-
444393 public void testReadOnlyBlocksNotAddedBack () {
445394 var sourceIndex = randomAlphaOfLength (20 ).toLowerCase (Locale .ROOT );
446395 var settings = Settings .builder ()
@@ -460,7 +409,6 @@ public void testReadOnlyBlocksNotAddedBack() {
460409 assertFalse (parseBoolean (settingsResponse .getSetting (destIndex , IndexMetadata .SETTING_READ_ONLY_ALLOW_DELETE )));
461410 assertFalse (parseBoolean (settingsResponse .getSetting (destIndex , IndexMetadata .SETTING_BLOCKS_WRITE )));
462411
463- cleanupMetadataBlocks (sourceIndex );
464412 cleanupMetadataBlocks (destIndex );
465413 }
466414
@@ -807,9 +755,8 @@ private static void cleanupMetadataBlocks(String index) {
807755 var settings = Settings .builder ()
808756 .putNull (IndexMetadata .SETTING_READ_ONLY )
809757 .putNull (IndexMetadata .SETTING_READ_ONLY_ALLOW_DELETE )
810- .putNull (IndexMetadata .SETTING_BLOCKS_METADATA )
811- .build ();
812- safeGet (indicesAdmin ().updateSettings (new UpdateSettingsRequest (settings , index )));
758+ .putNull (IndexMetadata .SETTING_BLOCKS_METADATA );
759+ updateIndexSettings (settings , index );
813760 }
814761
815762 private static void indexDocs (String index , int numDocs ) {
0 commit comments