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 ;
3028import org .elasticsearch .action .ingest .PutPipelineTransportAction ;
3129import org .elasticsearch .action .support .IndicesOptions ;
3230import org .elasticsearch .action .support .master .AcknowledgedRequest ;
33- import org .elasticsearch .cluster .block .ClusterBlockException ;
3431import org .elasticsearch .cluster .metadata .ComposableIndexTemplate ;
3532import org .elasticsearch .cluster .metadata .IndexMetadata ;
3633import org .elasticsearch .cluster .metadata .MappingMetadata ;
37- import org .elasticsearch .cluster .metadata .MetadataIndexStateService ;
3834import org .elasticsearch .cluster .metadata .Template ;
3935import org .elasticsearch .common .bytes .BytesArray ;
4036import org .elasticsearch .common .compress .CompressedXContent ;
8278import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertAcked ;
8379import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertHitCount ;
8480import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertResponse ;
85- import static org .elasticsearch .xcontent .XContentFactory .jsonBuilder ;
8681import static org .hamcrest .Matchers .equalTo ;
8782
8883public class ReindexDatastreamIndexTransportActionIT extends ESIntegTestCase {
@@ -274,8 +269,7 @@ public void testDestIndexNameSet_noDotPrefix() throws Exception {
274269 assertEquals (expectedDestIndexName , response .getDestIndex ());
275270 }
276271
277- public void testDestIndexNameSet_withDotPrefix () throws Exception {
278-
272+ public void testDestIndexNameSet_withDotPrefix () {
279273 var sourceIndex = "." + randomAlphaOfLength (20 ).toLowerCase (Locale .ROOT );
280274 safeGet (indicesAdmin ().create (new CreateIndexRequest (sourceIndex )));
281275
@@ -288,13 +282,19 @@ public void testDestIndexNameSet_withDotPrefix() throws Exception {
288282 assertEquals (expectedDestIndexName , response .getDestIndex ());
289283 }
290284
291- public void testDestIndexContainsDocs () throws Exception {
285+ public void testDestIndexContainsDocs () {
292286 // source index with docs
293287 var numDocs = randomIntBetween (1 , 100 );
294288 var sourceIndex = randomAlphaOfLength (20 ).toLowerCase (Locale .ROOT );
295289 safeGet (indicesAdmin ().create (new CreateIndexRequest (sourceIndex )));
296290 indexDocs (sourceIndex , numDocs );
297291
292+ var settings = Settings .builder ()
293+ .put (IndexMetadata .SETTING_BLOCKS_METADATA , randomBoolean ())
294+ .put (IndexMetadata .SETTING_READ_ONLY , randomBoolean ())
295+ .build ();
296+ safeGet (indicesAdmin ().updateSettings (new UpdateSettingsRequest (settings , sourceIndex )));
297+
298298 // call reindex
299299 var response = safeGet (
300300 client ().execute (ReindexDataStreamIndexAction .INSTANCE , new ReindexDataStreamIndexAction .Request (sourceIndex ))
@@ -305,31 +305,6 @@ public void testDestIndexContainsDocs() throws Exception {
305305 assertHitCount (prepareSearch (response .getDestIndex ()).setSize (0 ), numDocs );
306306 }
307307
308- public void testSetSourceToBlockWrites () throws Exception {
309- var settings = randomBoolean () ? Settings .builder ().put (IndexMetadata .SETTING_BLOCKS_WRITE , true ).build () : Settings .EMPTY ;
310-
311- // empty source index
312- var sourceIndex = randomAlphaOfLength (20 ).toLowerCase (Locale .ROOT );
313- safeGet (indicesAdmin ().create (new CreateIndexRequest (sourceIndex , settings )));
314-
315- // call reindex
316- safeGet (client ().execute (ReindexDataStreamIndexAction .INSTANCE , new ReindexDataStreamIndexAction .Request (sourceIndex )));
317-
318- // Assert that source index is now read-only but not verified read-only
319- GetSettingsResponse getSettingsResponse = safeGet (
320- admin ().indices ().getSettings (new GetSettingsRequest (TEST_REQUEST_TIMEOUT ).indices (sourceIndex ))
321- );
322- assertTrue (parseBoolean (getSettingsResponse .getSetting (sourceIndex , IndexMetadata .SETTING_BLOCKS_WRITE )));
323- assertFalse (
324- parseBoolean (getSettingsResponse .getSetting (sourceIndex , MetadataIndexStateService .VERIFIED_READ_ONLY_SETTING .getKey ()))
325- );
326-
327- // assert that write to source fails
328- var indexReq = new IndexRequest (sourceIndex ).source (jsonBuilder ().startObject ().field ("field" , "1" ).endObject ());
329- expectThrows (ClusterBlockException .class , client ().index (indexReq ));
330- assertHitCount (prepareSearch (sourceIndex ).setSize (0 ), 0 );
331- }
332-
333308 public void testMissingSourceIndex () {
334309 var nonExistentSourceIndex = randomAlphaOfLength (20 ).toLowerCase (Locale .ROOT );
335310 expectThrows (
@@ -387,34 +362,6 @@ public void testMappingsAddedToDestIndex() {
387362 assertEquals ("text" , XContentMapValues .extractValue ("properties.foo1.type" , destMappings ));
388363 }
389364
390- public void testFailIfMetadataBlockSet () {
391- var sourceIndex = randomAlphaOfLength (20 ).toLowerCase (Locale .ROOT );
392- var settings = Settings .builder ().put (IndexMetadata .SETTING_BLOCKS_METADATA , true ).build ();
393- safeGet (indicesAdmin ().create (new CreateIndexRequest (sourceIndex , settings )));
394-
395- ElasticsearchException e = expectThrows (
396- ElasticsearchException .class ,
397- client ().execute (ReindexDataStreamIndexAction .INSTANCE , new ReindexDataStreamIndexAction .Request (sourceIndex ))
398- );
399- assertTrue (e .getMessage ().contains ("Cannot reindex index" ) || e .getCause ().getMessage ().equals ("Cannot reindex index" ));
400-
401- cleanupMetadataBlocks (sourceIndex );
402- }
403-
404- public void testFailIfReadBlockSet () {
405- var sourceIndex = randomAlphaOfLength (20 ).toLowerCase (Locale .ROOT );
406- var settings = Settings .builder ().put (IndexMetadata .SETTING_BLOCKS_READ , true ).build ();
407- safeGet (indicesAdmin ().create (new CreateIndexRequest (sourceIndex , settings )));
408-
409- ElasticsearchException e = expectThrows (
410- ElasticsearchException .class ,
411- client ().execute (ReindexDataStreamIndexAction .INSTANCE , new ReindexDataStreamIndexAction .Request (sourceIndex ))
412- );
413- assertTrue (e .getMessage ().contains ("Cannot reindex index" ) || e .getCause ().getMessage ().equals ("Cannot reindex index" ));
414-
415- cleanupMetadataBlocks (sourceIndex );
416- }
417-
418365 public void testReadOnlyBlocksNotAddedBack () {
419366 var sourceIndex = randomAlphaOfLength (20 ).toLowerCase (Locale .ROOT );
420367 var settings = Settings .builder ()
@@ -434,7 +381,6 @@ public void testReadOnlyBlocksNotAddedBack() {
434381 assertFalse (parseBoolean (settingsResponse .getSetting (destIndex , IndexMetadata .SETTING_READ_ONLY_ALLOW_DELETE )));
435382 assertFalse (parseBoolean (settingsResponse .getSetting (destIndex , IndexMetadata .SETTING_BLOCKS_WRITE )));
436383
437- cleanupMetadataBlocks (sourceIndex );
438384 cleanupMetadataBlocks (destIndex );
439385 }
440386
@@ -752,9 +698,8 @@ private static void cleanupMetadataBlocks(String index) {
752698 var settings = Settings .builder ()
753699 .putNull (IndexMetadata .SETTING_READ_ONLY )
754700 .putNull (IndexMetadata .SETTING_READ_ONLY_ALLOW_DELETE )
755- .putNull (IndexMetadata .SETTING_BLOCKS_METADATA )
756- .build ();
757- safeGet (indicesAdmin ().updateSettings (new UpdateSettingsRequest (settings , index )));
701+ .putNull (IndexMetadata .SETTING_BLOCKS_METADATA );
702+ updateIndexSettings (settings , index );
758703 }
759704
760705 private static void indexDocs (String index , int numDocs ) {
0 commit comments