Skip to content

Commit 5a934cf

Browse files
committed
Test for warning header on snapshot restore
When missing templates
1 parent a167980 commit 5a934cf

File tree

1 file changed

+104
-2
lines changed

1 file changed

+104
-2
lines changed

modules/data-streams/src/internalClusterTest/java/org/elasticsearch/datastreams/DataStreamsSnapshotsIT.java

Lines changed: 104 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest;
1616
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse;
1717
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest;
18+
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequestBuilder;
1819
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse;
1920
import org.elasticsearch.action.admin.indices.alias.Alias;
2021
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
@@ -45,6 +46,7 @@
4546
import org.elasticsearch.search.SearchHit;
4647
import org.elasticsearch.snapshots.AbstractSnapshotIntegTestCase;
4748
import org.elasticsearch.snapshots.RestoreInfo;
49+
import org.elasticsearch.snapshots.SnapshotId;
4850
import org.elasticsearch.snapshots.SnapshotInProgressException;
4951
import org.elasticsearch.snapshots.SnapshotInfo;
5052
import org.elasticsearch.snapshots.SnapshotRestoreException;
@@ -62,7 +64,9 @@
6264
import java.util.stream.Collectors;
6365

6466
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
67+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoWarningHeaderOnResponse;
6568
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertResponse;
69+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertWarningHeaderOnResponse;
6670
import static org.hamcrest.Matchers.anEmptyMap;
6771
import static org.hamcrest.Matchers.contains;
6872
import static org.hamcrest.Matchers.containsInAnyOrder;
@@ -80,6 +84,8 @@ public class DataStreamsSnapshotsIT extends AbstractSnapshotIntegTestCase {
8084
private static final Map<String, Integer> DOCUMENT_SOURCE = Collections.singletonMap("@timestamp", 123);
8185
public static final String REPO = "repo";
8286
public static final String SNAPSHOT = "snap";
87+
public static final String TEMPLATE_1_ID = "t1";
88+
public static final String TEMPLATE_2_ID = "t2";
8389
private Client client;
8490

8591
private String dsBackingIndexName;
@@ -103,8 +109,8 @@ public void setup() throws Exception {
103109
Path location = randomRepoPath();
104110
createRepository(REPO, "fs", location);
105111

106-
DataStreamIT.putComposableIndexTemplate("t1", List.of("ds", "other-ds"));
107-
DataStreamIT.putComposableIndexTemplate("t2", """
112+
DataStreamIT.putComposableIndexTemplate(TEMPLATE_1_ID, List.of("ds", "other-ds"));
113+
DataStreamIT.putComposableIndexTemplate(TEMPLATE_2_ID, """
108114
{
109115
"properties": {
110116
"@timestamp": {
@@ -1335,4 +1341,100 @@ public void testRestoreDataStreamAliasWithConflictingIndicesAlias() throws Excep
13351341
);
13361342
assertThat(e.getMessage(), containsString("data stream alias and indices alias have the same name (my-alias)"));
13371343
}
1344+
1345+
public void testWarningHeaderOnRestoreWithoutTemplates() throws Exception {
1346+
String datastreamName = "ds";
1347+
1348+
CreateSnapshotResponse createSnapshotResponse = client.admin()
1349+
.cluster()
1350+
.prepareCreateSnapshot(TEST_REQUEST_TIMEOUT, REPO, SNAPSHOT)
1351+
.setWaitForCompletion(true)
1352+
.setIndices(datastreamName)
1353+
.setIncludeGlobalState(false)
1354+
.get();
1355+
1356+
RestStatus status = createSnapshotResponse.getSnapshotInfo().status();
1357+
SnapshotId snapshotId = createSnapshotResponse.getSnapshotInfo().snapshotId();
1358+
assertEquals(RestStatus.OK, status);
1359+
1360+
assertEquals(Collections.singletonList(dsBackingIndexName), getSnapshot(REPO, SNAPSHOT).indices());
1361+
1362+
assertAcked(
1363+
client.execute(
1364+
DeleteDataStreamAction.INSTANCE,
1365+
new DeleteDataStreamAction.Request(TEST_REQUEST_TIMEOUT, datastreamName, "other-ds", "with-fs")
1366+
)
1367+
);
1368+
1369+
assertAcked(
1370+
client.execute(
1371+
TransportDeleteComposableIndexTemplateAction.TYPE,
1372+
new TransportDeleteComposableIndexTemplateAction.Request(TEMPLATE_1_ID)
1373+
).get()
1374+
);
1375+
1376+
assertAcked(
1377+
client.execute(
1378+
TransportDeleteComposableIndexTemplateAction.TYPE,
1379+
new TransportDeleteComposableIndexTemplateAction.Request(TEMPLATE_2_ID)
1380+
).get()
1381+
);
1382+
1383+
RestoreSnapshotRequestBuilder request = client.admin()
1384+
.cluster()
1385+
.prepareRestoreSnapshot(TEST_REQUEST_TIMEOUT, REPO, SNAPSHOT)
1386+
.setWaitForCompletion(true)
1387+
.setIndices(datastreamName);
1388+
1389+
assertWarningHeaderOnResponse(
1390+
client,
1391+
request,
1392+
"Snapshot ["
1393+
+ snapshotId
1394+
+ "] contains data stream ["
1395+
+ datastreamName
1396+
+ "] but custer does not have a matching index "
1397+
+ "template. This will cause rollover to fail until a matching index template is created"
1398+
);
1399+
1400+
}
1401+
1402+
public void testWarningHeaderAbsentOnRestoreWithTemplates() throws Exception {
1403+
String datastreamName = "ds";
1404+
1405+
CreateSnapshotResponse createSnapshotResponse = client.admin()
1406+
.cluster()
1407+
.prepareCreateSnapshot(TEST_REQUEST_TIMEOUT, REPO, SNAPSHOT)
1408+
.setWaitForCompletion(true)
1409+
.setIndices(datastreamName)
1410+
.setIncludeGlobalState(false)
1411+
.get();
1412+
1413+
RestStatus status = createSnapshotResponse.getSnapshotInfo().status();
1414+
SnapshotId snapshotId = createSnapshotResponse.getSnapshotInfo().snapshotId();
1415+
assertEquals(RestStatus.OK, status);
1416+
1417+
assertEquals(Collections.singletonList(dsBackingIndexName), getSnapshot(REPO, SNAPSHOT).indices());
1418+
1419+
assertAcked(
1420+
client.execute(
1421+
DeleteDataStreamAction.INSTANCE,
1422+
new DeleteDataStreamAction.Request(TEST_REQUEST_TIMEOUT, datastreamName, "other-ds", "with-fs")
1423+
)
1424+
);
1425+
1426+
RestoreSnapshotRequestBuilder request = client.admin()
1427+
.cluster()
1428+
.prepareRestoreSnapshot(TEST_REQUEST_TIMEOUT, REPO, SNAPSHOT)
1429+
.setWaitForCompletion(true)
1430+
.setIndices(datastreamName);
1431+
1432+
assertNoWarningHeaderOnResponse(
1433+
client,
1434+
request,
1435+
"but custer does not have a matching index template. This will cause rollover to fail until a matching index "
1436+
+ "template is created"
1437+
);
1438+
1439+
}
13381440
}

0 commit comments

Comments
 (0)