|
9 | 9 |
|
10 | 10 | import org.elasticsearch.ElasticsearchException; |
11 | 11 | import org.elasticsearch.ResourceNotFoundException; |
| 12 | +import org.elasticsearch.action.ActionRequest; |
| 13 | +import org.elasticsearch.action.ActionResponse; |
12 | 14 | import org.elasticsearch.action.DocWriteRequest; |
13 | 15 | import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; |
14 | 16 | import org.elasticsearch.action.admin.indices.get.GetIndexRequest; |
|
38 | 40 | import org.elasticsearch.cluster.metadata.Template; |
39 | 41 | import org.elasticsearch.common.bytes.BytesArray; |
40 | 42 | import org.elasticsearch.common.compress.CompressedXContent; |
| 43 | +import org.elasticsearch.common.settings.Setting; |
41 | 44 | import org.elasticsearch.common.settings.Settings; |
42 | 45 | import org.elasticsearch.common.time.DateFormatter; |
43 | 46 | import org.elasticsearch.common.time.FormatNames; |
44 | 47 | import org.elasticsearch.common.xcontent.support.XContentMapValues; |
45 | 48 | import org.elasticsearch.datastreams.DataStreamsPlugin; |
46 | 49 | import org.elasticsearch.index.IndexSettings; |
| 50 | +import org.elasticsearch.index.engine.frozen.FrozenEngine; |
47 | 51 | import org.elasticsearch.index.mapper.DateFieldMapper; |
48 | 52 | import org.elasticsearch.ingest.common.IngestCommonPlugin; |
| 53 | +import org.elasticsearch.plugins.ActionPlugin; |
49 | 54 | import org.elasticsearch.plugins.Plugin; |
| 55 | +import org.elasticsearch.protocol.xpack.frozen.FreezeRequest; |
| 56 | +import org.elasticsearch.protocol.xpack.frozen.FreezeResponse; |
50 | 57 | import org.elasticsearch.reindex.ReindexPlugin; |
51 | 58 | import org.elasticsearch.test.ESIntegTestCase; |
52 | 59 | import org.elasticsearch.test.transport.MockTransportService; |
53 | 60 | import org.elasticsearch.xcontent.XContentType; |
| 61 | +import org.elasticsearch.xpack.core.frozen.action.FreezeIndexAction; |
| 62 | +import org.elasticsearch.xpack.frozen.action.TransportFreezeIndexAction; |
54 | 63 | import org.elasticsearch.xpack.migrate.MigratePlugin; |
55 | 64 | import org.elasticsearch.xpack.migrate.MigrateTemplateRegistry; |
56 | 65 | import org.junit.Before; |
57 | 66 |
|
58 | 67 | import java.io.IOException; |
59 | 68 | import java.time.Instant; |
| 69 | +import java.util.ArrayList; |
| 70 | +import java.util.Arrays; |
60 | 71 | import java.util.Collection; |
61 | 72 | import java.util.List; |
62 | 73 | import java.util.Locale; |
|
69 | 80 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertResponse; |
70 | 81 | import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder; |
71 | 82 | import static org.hamcrest.Matchers.equalTo; |
| 83 | +import static org.hamcrest.Matchers.not; |
72 | 84 |
|
73 | 85 | public class ReindexDatastreamIndexTransportActionIT extends ESIntegTestCase { |
74 | 86 |
|
@@ -112,7 +124,8 @@ protected Collection<Class<? extends Plugin>> nodePlugins() { |
112 | 124 | ReindexPlugin.class, |
113 | 125 | MockTransportService.TestPlugin.class, |
114 | 126 | DataStreamsPlugin.class, |
115 | | - IngestCommonPlugin.class |
| 127 | + IngestCommonPlugin.class, |
| 128 | + TestFrozenIndicesPlugin.class |
116 | 129 | ); |
117 | 130 | } |
118 | 131 |
|
@@ -595,6 +608,43 @@ public void testTsdbStartEndSet() throws Exception { |
595 | 608 | assertHitCount(prepareSearch(destIndex).setSize(0), 1); |
596 | 609 | } |
597 | 610 |
|
| 611 | + public void testIndexUnfrozen() { |
| 612 | + var sourceIndex = randomAlphaOfLength(20).toLowerCase(Locale.ROOT); |
| 613 | + safeGet(indicesAdmin().create(new CreateIndexRequest(sourceIndex))); |
| 614 | + |
| 615 | + // add doc with timestamp |
| 616 | + String time = DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.formatMillis(System.currentTimeMillis()); |
| 617 | + var doc = String.format(Locale.ROOT, "{\"%s\":\"%s\"}", DEFAULT_TIMESTAMP_FIELD, time); |
| 618 | + addDoc(sourceIndex, doc); |
| 619 | + FreezeRequest freezeRequest = new FreezeRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT, sourceIndex); |
| 620 | + freezeRequest.setFreeze(true); |
| 621 | + FreezeResponse freezeResponse = safeGet(client().execute(FreezeIndexAction.INSTANCE, freezeRequest)); |
| 622 | + assertAcked(freezeResponse); |
| 623 | + assertThat( |
| 624 | + safeGet(admin().indices().getSettings(new GetSettingsRequest().indices(sourceIndex))).getIndexToSettings() |
| 625 | + .get(sourceIndex) |
| 626 | + .get(FrozenEngine.INDEX_FROZEN.getKey()), |
| 627 | + not(equalTo(null)) |
| 628 | + ); |
| 629 | + |
| 630 | + String destIndex = safeGet( |
| 631 | + client().execute(ReindexDataStreamIndexAction.INSTANCE, new ReindexDataStreamIndexAction.Request(sourceIndex)) |
| 632 | + ).getDestIndex(); |
| 633 | + |
| 634 | + assertThat( |
| 635 | + safeGet(admin().indices().getSettings(new GetSettingsRequest().indices(sourceIndex))).getIndexToSettings() |
| 636 | + .get(sourceIndex) |
| 637 | + .get(FrozenEngine.INDEX_FROZEN.getKey()), |
| 638 | + equalTo(null) |
| 639 | + ); |
| 640 | + assertThat( |
| 641 | + safeGet(admin().indices().getSettings(new GetSettingsRequest().indices(destIndex))).getIndexToSettings() |
| 642 | + .get(destIndex) |
| 643 | + .get(FrozenEngine.INDEX_FROZEN.getKey()), |
| 644 | + equalTo(null) |
| 645 | + ); |
| 646 | + } |
| 647 | + |
598 | 648 | private static void cleanupMetadataBlocks(String index) { |
599 | 649 | var settings = Settings.builder() |
600 | 650 | .putNull(IndexMetadata.SETTING_READ_ONLY) |
@@ -635,4 +685,22 @@ private void ensureHealth(String index) { |
635 | 685 | ensureYellow(index); |
636 | 686 | } |
637 | 687 | } |
| 688 | + |
| 689 | + /* |
| 690 | + * This takes the place of the real FrozenIndices plugin. We can't use that one because its EngineFactory conflicts with the one used |
| 691 | + * by this test. We only need the settings and the mapping of the FreezeIndexAction though. |
| 692 | + */ |
| 693 | + public static class TestFrozenIndicesPlugin extends Plugin implements ActionPlugin { |
| 694 | + @Override |
| 695 | + public List<Setting<?>> getSettings() { |
| 696 | + return Arrays.asList(FrozenEngine.INDEX_FROZEN); |
| 697 | + } |
| 698 | + |
| 699 | + @Override |
| 700 | + public List<ActionPlugin.ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() { |
| 701 | + List<ActionPlugin.ActionHandler<? extends ActionRequest, ? extends ActionResponse>> actions = new ArrayList<>(); |
| 702 | + actions.add(new ActionPlugin.ActionHandler<>(FreezeIndexAction.INSTANCE, TransportFreezeIndexAction.class)); |
| 703 | + return actions; |
| 704 | + } |
| 705 | + } |
638 | 706 | } |
0 commit comments