Skip to content

Commit 68b070a

Browse files
committed
add ilm tests
1 parent 5917abc commit 68b070a

File tree

5 files changed

+55
-103
lines changed

5 files changed

+55
-103
lines changed

x-pack/plugin/migrate/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ dependencies {
1717
compileOnly project(path: xpackModule('core'))
1818
testImplementation(testArtifact(project(xpackModule('core'))))
1919
testImplementation project(xpackModule('ccr'))
20+
testImplementation project(xpackModule('ilm'))
2021
testImplementation project(':modules:data-streams')
2122
testImplementation project(path: ':modules:reindex')
2223
testImplementation project(path: ':modules:ingest-common')

x-pack/plugin/migrate/src/internalClusterTest/java/org/elasticsearch/xpack/migrate/action/CopyIndexMetadataTransportActionIT.java

Lines changed: 49 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,31 @@
1616
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest;
1717
import org.elasticsearch.action.admin.indices.template.put.TransportPutComposableIndexTemplateAction;
1818
import org.elasticsearch.action.datastreams.CreateDataStreamAction;
19-
import org.elasticsearch.action.datastreams.GetDataStreamAction;
2019
import org.elasticsearch.action.index.IndexRequest;
2120
import org.elasticsearch.action.support.IndicesOptions;
2221
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
2322
import org.elasticsearch.cluster.metadata.IndexMetadata;
2423
import org.elasticsearch.cluster.metadata.LifecycleExecutionState;
24+
import org.elasticsearch.cluster.metadata.Metadata;
2525
import org.elasticsearch.cluster.metadata.Template;
2626
import org.elasticsearch.common.compress.CompressedXContent;
2727
import org.elasticsearch.common.settings.Settings;
2828
import org.elasticsearch.core.TimeValue;
2929
import org.elasticsearch.datastreams.DataStreamsPlugin;
30+
import org.elasticsearch.ingest.common.IngestCommonPlugin;
3031
import org.elasticsearch.plugins.Plugin;
31-
import org.elasticsearch.reindex.ReindexPlugin;
3232
import org.elasticsearch.test.ESIntegTestCase;
33-
import org.elasticsearch.test.transport.MockTransportService;
3433
import org.elasticsearch.xcontent.json.JsonXContent;
35-
//import org.elasticsearch.xpack.core.LocalStateCompositeXPackPlugin;
34+
import org.elasticsearch.xpack.core.LocalStateCompositeXPackPlugin;
3635
import org.elasticsearch.xpack.core.ilm.LifecyclePolicy;
36+
import org.elasticsearch.xpack.core.ilm.LifecycleSettings;
3737
import org.elasticsearch.xpack.core.ilm.Phase;
3838
import org.elasticsearch.xpack.core.ilm.StartILMRequest;
3939
import org.elasticsearch.xpack.core.ilm.action.ILMActions;
4040
import org.elasticsearch.xpack.core.ilm.action.PutLifecycleRequest;
41-
//import org.elasticsearch.xpack.ilm.IndexLifecycle;
41+
import org.elasticsearch.xpack.ilm.IndexLifecycle;
4242
import org.elasticsearch.xpack.migrate.MigratePlugin;
43+
import org.junit.After;
4344

4445
import java.util.Collection;
4546
import java.util.List;
@@ -50,15 +51,19 @@
5051
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
5152

5253
public class CopyIndexMetadataTransportActionIT extends ESIntegTestCase {
54+
@After
55+
public void cleanup() {
56+
updateClusterSettings(Settings.builder().putNull("*"));
57+
}
5358

5459
@Override
5560
protected Collection<Class<? extends Plugin>> nodePlugins() {
5661
return List.of(
57-
// LocalStateCompositeXPackPlugin.class,
62+
LocalStateCompositeXPackPlugin.class,
5863
MigratePlugin.class,
59-
ReindexPlugin.class,
60-
MockTransportService.TestPlugin.class,
61-
DataStreamsPlugin.class
64+
DataStreamsPlugin.class,
65+
IngestCommonPlugin.class,
66+
IndexLifecycle.class
6267
);
6368
}
6469

@@ -96,12 +101,17 @@ public void testCreationDate() throws Exception {
96101

97102
public void testILMState() throws Exception {
98103

104+
updateClusterSettings(Settings.builder().put(LifecycleSettings.LIFECYCLE_POLL_INTERVAL, "1s"));
105+
99106
Map<String, Phase> phases = Map.of(
100-
"warm",
107+
"hot",
101108
new Phase(
102-
"warm",
109+
"hot",
103110
TimeValue.ZERO,
104-
Map.of("rollover", new org.elasticsearch.xpack.core.ilm.RolloverAction(null, null, null, 1L, null, null, null, null, null, null))
111+
Map.of(
112+
"rollover",
113+
new org.elasticsearch.xpack.core.ilm.RolloverAction(null, null, null, 1L, null, null, null, null, null, null)
114+
)
105115
)
106116
);
107117

@@ -110,60 +120,36 @@ public void testILMState() throws Exception {
110120
PutLifecycleRequest putLifecycleRequest = new PutLifecycleRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT, policy);
111121
assertAcked(client().execute(ILMActions.PUT, putLifecycleRequest).actionGet());
112122

123+
// create data stream with a document and wait for ILM to roll it over
113124
var dataStream = createDataStream(policyName);
114-
115-
assertAcked(safeGet(client().execute(ILMActions.START, new StartILMRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT))));
116-
117-
// rollover a few times
118125
createDocument(dataStream);
119-
createDocument(dataStream);
120-
createDocument(dataStream);
121-
122-
var writeIndex = safeGet(
123-
indicesAdmin().execute(
124-
GetDataStreamAction.INSTANCE,
125-
new GetDataStreamAction.Request(TEST_REQUEST_TIMEOUT, new String[] { dataStream })
126-
)
127-
).getDataStreams().get(0).getDataStream().getWriteIndex().getName();
126+
assertAcked(safeGet(client().execute(ILMActions.START, new StartILMRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT))));
127+
assertBusy(() -> {
128+
var getIndexResponse = indicesAdmin().getIndex(new GetIndexRequest(TEST_REQUEST_TIMEOUT).indices(dataStream)).get();
129+
assertTrue(getIndexResponse.indices().length > 1);
130+
});
131+
// stop ILM so source does not change after copying metadata
132+
assertAcked(safeGet(client().execute(ILMActions.STOP, new StartILMRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT))));
128133

129134
var getIndexResponse = indicesAdmin().getIndex(new GetIndexRequest(TEST_REQUEST_TIMEOUT).indices(dataStream)).get();
130135
for (var backingIndex : getIndexResponse.indices()) {
131-
132136
var destIndex = randomAlphaOfLength(20).toLowerCase(Locale.ROOT);
133137
indicesAdmin().create(new CreateIndexRequest(destIndex)).get();
134138

135-
var metadataBefore = safeGet(
136-
clusterAdmin().state(new ClusterStateRequest(TEST_REQUEST_TIMEOUT).indices(backingIndex, destIndex))
137-
).getState().metadata();
139+
var metadataBefore = getClusterMetadata(backingIndex, destIndex);
138140
IndexMetadata source = metadataBefore.index(backingIndex);
139141
IndexMetadata destBefore = metadataBefore.index(destIndex);
140142

143+
// sanity check
141144
assertNotEquals(
142145
source.getCustomData(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY),
143146
destBefore.getCustomData(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY)
144147
);
145148

146-
// sanity check not equal before the copy
147-
if (backingIndex.equals(writeIndex)) {
148-
assertTrue(source.getRolloverInfos().isEmpty());
149-
assertTrue(destBefore.getRolloverInfos().isEmpty());
150-
} else {
151-
assertNotEquals(source.getRolloverInfos(), destBefore.getRolloverInfos());
152-
}
153-
154149
// copy over the metadata
155150
copyMetadata(backingIndex, destIndex);
156151

157-
var metadataAfter = safeGet(clusterAdmin().state(new ClusterStateRequest(TEST_REQUEST_TIMEOUT).indices(destIndex)))
158-
.getState()
159-
.metadata();
160-
IndexMetadata destAfter = metadataAfter.index(destIndex);
161-
162-
// now rollover info should be equal
163-
assertEquals(source.getRolloverInfos(), destAfter.getRolloverInfos());
164-
165-
Map<String, String> customData = source.getCustomData(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY);
166-
//
152+
IndexMetadata destAfter = getClusterMetadata(destIndex).index(destIndex);
167153
assertEquals(
168154
source.getCustomData(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY),
169155
destAfter.getCustomData(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY)
@@ -172,60 +158,27 @@ public void testILMState() throws Exception {
172158
}
173159
}
174160

175-
176-
177-
178161
public void testRolloverInfos() throws Exception {
179-
180162
var dataStream = createDataStream(null);
181-
Map<String, Phase> phases = Map.of(
182-
"warm",
183-
new Phase(
184-
"warm",
185-
TimeValue.ZERO,
186-
Map.of("rollover", new org.elasticsearch.xpack.core.ilm.RolloverAction(null, null, null, 1L, null, null, null, null, null, null))
187-
)
188-
);
189-
190-
var policyName = "my-policy";
191-
LifecyclePolicy policy = new LifecyclePolicy(policyName, phases);
192-
PutLifecycleRequest putLifecycleRequest = new PutLifecycleRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT, policy);
193-
assertAcked(client().execute(ILMActions.PUT, putLifecycleRequest).actionGet());
194-
195-
196163

197164
// rollover a few times
198165
createDocument(dataStream);
199-
assertTrue(indicesAdmin().rolloverIndex(new RolloverRequest(dataStream, null)).get().isAcknowledged());
166+
rollover(dataStream);
200167
createDocument(dataStream);
201-
assertTrue(indicesAdmin().rolloverIndex(new RolloverRequest(dataStream, null)).get().isAcknowledged());
168+
rollover(dataStream);
202169
createDocument(dataStream);
203-
assertTrue(indicesAdmin().rolloverIndex(new RolloverRequest(dataStream, null)).get().isAcknowledged());
204-
205-
var writeIndex = safeGet(
206-
indicesAdmin().execute(
207-
GetDataStreamAction.INSTANCE,
208-
new GetDataStreamAction.Request(TEST_REQUEST_TIMEOUT, new String[] { dataStream })
209-
)
210-
).getDataStreams().get(0).getDataStream().getWriteIndex().getName();
170+
var writeIndex = rollover(dataStream);
211171

212172
var getIndexResponse = indicesAdmin().getIndex(new GetIndexRequest(TEST_REQUEST_TIMEOUT).indices(dataStream)).get();
213173
for (var backingIndex : getIndexResponse.indices()) {
214174

215175
var destIndex = randomAlphaOfLength(20).toLowerCase(Locale.ROOT);
216176
indicesAdmin().create(new CreateIndexRequest(destIndex)).get();
217177

218-
var metadataBefore = safeGet(
219-
clusterAdmin().state(new ClusterStateRequest(TEST_REQUEST_TIMEOUT).indices(backingIndex, destIndex))
220-
).getState().metadata();
178+
var metadataBefore = getClusterMetadata(backingIndex, destIndex);
221179
IndexMetadata source = metadataBefore.index(backingIndex);
222180
IndexMetadata destBefore = metadataBefore.index(destIndex);
223181

224-
// assertNotEquals(
225-
// source.getCustomData(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY),
226-
// destBefore.getCustomData(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY)
227-
// );
228-
229182
// sanity check not equal before the copy
230183
if (backingIndex.equals(writeIndex)) {
231184
assertTrue(source.getRolloverInfos().isEmpty());
@@ -237,30 +190,16 @@ public void testRolloverInfos() throws Exception {
237190
// copy over the metadata
238191
copyMetadata(backingIndex, destIndex);
239192

240-
var metadataAfter = safeGet(clusterAdmin().state(new ClusterStateRequest(TEST_REQUEST_TIMEOUT).indices(destIndex)))
241-
.getState()
242-
.metadata();
243-
IndexMetadata destAfter = metadataAfter.index(destIndex);
244-
245193
// now rollover info should be equal
194+
IndexMetadata destAfter = getClusterMetadata(destIndex).index(destIndex);
246195
assertEquals(source.getRolloverInfos(), destAfter.getRolloverInfos());
247-
248-
Map<String, String> customData = source.getCustomData(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY);
249-
//
250-
assertEquals(
251-
source.getCustomData(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY),
252-
destAfter.getCustomData(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY)
253-
);
254-
255196
}
256197
}
257198

258199
private String createDataStream(String ilmPolicy) throws Exception {
259200
String dataStreamName = randomAlphaOfLength(10).toLowerCase(Locale.getDefault());
260201

261-
Settings settings = ilmPolicy != null ?
262-
Settings.builder().put(IndexMetadata.LIFECYCLE_NAME, ilmPolicy).build()
263-
: null;
202+
Settings settings = ilmPolicy != null ? Settings.builder().put(IndexMetadata.LIFECYCLE_NAME, ilmPolicy).build() : null;
264203

265204
String mapping = """
266205
{
@@ -324,4 +263,14 @@ private void copyMetadata(String sourceIndex, String destIndex) {
324263
)
325264
);
326265
}
266+
267+
private String rollover(String dataStream) {
268+
var rolloverResponse = safeGet(indicesAdmin().rolloverIndex(new RolloverRequest(dataStream, null)));
269+
assertTrue(rolloverResponse.isAcknowledged());
270+
return rolloverResponse.getNewIndex();
271+
}
272+
273+
private Metadata getClusterMetadata(String... indices) {
274+
return safeGet(clusterAdmin().state(new ClusterStateRequest(TEST_REQUEST_TIMEOUT).indices(indices))).getState().metadata();
275+
}
327276
}

x-pack/plugin/migrate/src/internalClusterTest/java/org/elasticsearch/xpack/migrate/action/ReindexDataStreamTransportActionIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.elasticsearch.test.ESIntegTestCase;
2727
import org.elasticsearch.transport.TransportService;
2828
import org.elasticsearch.xcontent.XContentType;
29+
import org.elasticsearch.xpack.core.LocalStateCompositeXPackPlugin;
2930
import org.elasticsearch.xpack.migrate.MigratePlugin;
3031
import org.elasticsearch.xpack.migrate.action.ReindexDataStreamAction.ReindexDataStreamRequest;
3132
import org.elasticsearch.xpack.migrate.task.ReindexDataStreamEnrichedStatus;
@@ -47,7 +48,7 @@ public class ReindexDataStreamTransportActionIT extends ESIntegTestCase {
4748

4849
@Override
4950
protected Collection<Class<? extends Plugin>> nodePlugins() {
50-
return List.of(DataStreamsPlugin.class, MigratePlugin.class);
51+
return List.of(LocalStateCompositeXPackPlugin.class, DataStreamsPlugin.class, MigratePlugin.class);
5152
}
5253

5354
public void testNonExistentDataStream() {

x-pack/plugin/migrate/src/internalClusterTest/java/org/elasticsearch/xpack/migrate/action/ReindexDatastreamIndexTransportActionIT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.elasticsearch.test.ESIntegTestCase;
4848
import org.elasticsearch.test.transport.MockTransportService;
4949
import org.elasticsearch.xcontent.XContentType;
50+
import org.elasticsearch.xpack.core.LocalStateCompositeXPackPlugin;
5051
import org.elasticsearch.xpack.migrate.MigratePlugin;
5152
import org.elasticsearch.xpack.migrate.MigrateTemplateRegistry;
5253
import org.junit.Before;
@@ -89,6 +90,7 @@ private void setup() throws Exception {
8990
@Override
9091
protected Collection<Class<? extends Plugin>> nodePlugins() {
9192
return List.of(
93+
LocalStateCompositeXPackPlugin.class,
9294
MigratePlugin.class,
9395
ReindexPlugin.class,
9496
MockTransportService.TestPlugin.class,

x-pack/plugin/migrate/src/main/java/org/elasticsearch/xpack/migrate/action/CopyIndexMetadataTransportAction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.elasticsearch.tasks.Task;
3535
import org.elasticsearch.threadpool.ThreadPool;
3636
import org.elasticsearch.transport.TransportService;
37-
import org.elasticsearch.xpack.cluster.action.MigrateToDataTiersAction;
3837

3938
import java.util.HashMap;
4039

@@ -51,7 +50,7 @@ public CopyIndexMetadataTransportAction(
5150
ActionFilters actionFilters
5251
) {
5352
super(
54-
MigrateToDataTiersAction.NAME,
53+
CopyIndexMetadataAction.NAME,
5554
transportService,
5655
clusterService,
5756
threadPool,

0 commit comments

Comments
 (0)