8
8
package org .elasticsearch .datastreams ;
9
9
10
10
import org .elasticsearch .action .DocWriteRequest ;
11
- import org .elasticsearch .action .admin .cluster .snapshots .create .CreateSnapshotResponse ;
12
11
import org .elasticsearch .action .admin .cluster .snapshots .restore .RestoreSnapshotResponse ;
13
12
import org .elasticsearch .action .admin .indices .get .GetIndexResponse ;
14
13
import org .elasticsearch .action .index .IndexResponse ;
20
19
import org .elasticsearch .plugins .Plugin ;
21
20
import org .elasticsearch .plugins .SystemIndexPlugin ;
22
21
import org .elasticsearch .snapshots .AbstractSnapshotIntegTestCase ;
22
+ import org .elasticsearch .snapshots .SnapshotInfo ;
23
23
import org .elasticsearch .snapshots .mockstore .MockRepository ;
24
24
import org .elasticsearch .threadpool .ThreadPool ;
25
25
import org .elasticsearch .xpack .core .action .CreateDataStreamAction ;
35
35
import java .util .Map ;
36
36
37
37
import static org .elasticsearch .datastreams .SystemDataStreamSnapshotIT .SystemDataStreamTestPlugin .SYSTEM_DATA_STREAM_NAME ;
38
+ import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertAcked ;
38
39
import static org .hamcrest .Matchers .arrayWithSize ;
40
+ import static org .hamcrest .Matchers .empty ;
39
41
import static org .hamcrest .Matchers .hasSize ;
42
+ import static org .hamcrest .Matchers .not ;
40
43
import static org .hamcrest .Matchers .oneOf ;
41
44
42
45
public class SystemDataStreamSnapshotIT extends AbstractSnapshotIntegTestCase {
@@ -82,12 +85,91 @@ public void testSystemDataStreamSnapshotIT() throws Exception {
82
85
assertTrue (response .getDataStreams ().get (0 ).getDataStream ().isSystem ());
83
86
}
84
87
85
- CreateSnapshotResponse createSnapshotResponse = client ().admin ()
88
+ assertSuccessful (
89
+ client ().admin ()
90
+ .cluster ()
91
+ .prepareCreateSnapshot (REPO , SNAPSHOT )
92
+ .setWaitForCompletion (true )
93
+ .setIncludeGlobalState (false )
94
+ .execute ()
95
+ );
96
+
97
+ // We have to delete the data stream directly, as the feature reset API doesn't clean up system data streams yet
98
+ // See https://github.com/elastic/elasticsearch/issues/75818
99
+ {
100
+ DeleteDataStreamAction .Request request = new DeleteDataStreamAction .Request (new String [] { SYSTEM_DATA_STREAM_NAME });
101
+ AcknowledgedResponse response = client ().execute (DeleteDataStreamAction .INSTANCE , request ).get ();
102
+ assertTrue (response .isAcknowledged ());
103
+ }
104
+
105
+ {
106
+ GetIndexResponse indicesRemaining = client ().admin ().indices ().prepareGetIndex ().addIndices ("_all" ).get ();
107
+ assertThat (indicesRemaining .indices (), arrayWithSize (0 ));
108
+ }
109
+
110
+ RestoreSnapshotResponse restoreSnapshotResponse = client ().admin ()
86
111
.cluster ()
87
- .prepareCreateSnapshot (REPO , SNAPSHOT )
112
+ .prepareRestoreSnapshot (REPO , SNAPSHOT )
88
113
.setWaitForCompletion (true )
89
- .setIncludeGlobalState (false )
114
+ .setRestoreGlobalState (false )
90
115
.get ();
116
+ assertEquals (restoreSnapshotResponse .getRestoreInfo ().totalShards (), restoreSnapshotResponse .getRestoreInfo ().successfulShards ());
117
+
118
+ {
119
+ GetDataStreamAction .Request request = new GetDataStreamAction .Request (new String [] { SYSTEM_DATA_STREAM_NAME });
120
+ GetDataStreamAction .Response response = client ().execute (GetDataStreamAction .INSTANCE , request ).get ();
121
+ assertThat (response .getDataStreams (), hasSize (1 ));
122
+ assertTrue (response .getDataStreams ().get (0 ).getDataStream ().isSystem ());
123
+ }
124
+ }
125
+
126
+ public void testSystemDataStreamInFeatureState () throws Exception {
127
+ Path location = randomRepoPath ();
128
+ createRepository (REPO , "fs" , location );
129
+
130
+ {
131
+ CreateDataStreamAction .Request request = new CreateDataStreamAction .Request (SYSTEM_DATA_STREAM_NAME );
132
+ final AcknowledgedResponse response = client ().execute (CreateDataStreamAction .INSTANCE , request ).get ();
133
+ assertTrue (response .isAcknowledged ());
134
+ }
135
+
136
+ // Index a doc so that a concrete backing index will be created
137
+ IndexResponse indexToDataStreamResponse = client ().prepareIndex (SYSTEM_DATA_STREAM_NAME )
138
+ .setId ("42" )
139
+ .setSource ("{ \" @timestamp\" : \" 2099-03-08T11:06:07.000Z\" , \" name\" : \" my-name\" }" , XContentType .JSON )
140
+ .setOpType (DocWriteRequest .OpType .CREATE )
141
+ .execute ()
142
+ .actionGet ();
143
+ assertThat (indexToDataStreamResponse .status ().getStatus (), oneOf (200 , 201 ));
144
+
145
+ // Index a doc so that a concrete backing index will be created
146
+ IndexResponse indexResponse = client ().prepareIndex ("my-index" )
147
+ .setId ("42" )
148
+ .setSource ("{ \" name\" : \" my-name\" }" , XContentType .JSON )
149
+ .setOpType (DocWriteRequest .OpType .CREATE )
150
+ .execute ()
151
+ .get ();
152
+ assertThat (indexResponse .status ().getStatus (), oneOf (200 , 201 ));
153
+
154
+ {
155
+ GetDataStreamAction .Request request = new GetDataStreamAction .Request (new String [] { SYSTEM_DATA_STREAM_NAME });
156
+ GetDataStreamAction .Response response = client ().execute (GetDataStreamAction .INSTANCE , request ).get ();
157
+ assertThat (response .getDataStreams (), hasSize (1 ));
158
+ assertTrue (response .getDataStreams ().get (0 ).getDataStream ().isSystem ());
159
+ }
160
+
161
+ SnapshotInfo snapshotInfo = assertSuccessful (
162
+ client ().admin ()
163
+ .cluster ()
164
+ .prepareCreateSnapshot (REPO , SNAPSHOT )
165
+ .setIndices ("my-index" )
166
+ .setFeatureStates (SystemDataStreamTestPlugin .class .getSimpleName ())
167
+ .setWaitForCompletion (true )
168
+ .setIncludeGlobalState (false )
169
+ .execute ()
170
+ );
171
+
172
+ assertThat (snapshotInfo .dataStreams (), not (empty ()));
91
173
92
174
// We have to delete the data stream directly, as the feature reset API doesn't clean up system data streams yet
93
175
// See https://github.com/elastic/elasticsearch/issues/75818
@@ -97,6 +179,8 @@ public void testSystemDataStreamSnapshotIT() throws Exception {
97
179
assertTrue (response .isAcknowledged ());
98
180
}
99
181
182
+ assertAcked (client ().admin ().indices ().prepareDelete ("my-index" ));
183
+
100
184
{
101
185
GetIndexResponse indicesRemaining = client ().admin ().indices ().prepareGetIndex ().addIndices ("_all" ).get ();
102
186
assertThat (indicesRemaining .indices (), arrayWithSize (0 ));
@@ -106,7 +190,8 @@ public void testSystemDataStreamSnapshotIT() throws Exception {
106
190
.cluster ()
107
191
.prepareRestoreSnapshot (REPO , SNAPSHOT )
108
192
.setWaitForCompletion (true )
109
- .setRestoreGlobalState (false )
193
+ .setIndices ("my-index" )
194
+ .setFeatureStates (SystemDataStreamTestPlugin .class .getSimpleName ())
110
195
.get ();
111
196
assertEquals (restoreSnapshotResponse .getRestoreInfo ().totalShards (), restoreSnapshotResponse .getRestoreInfo ().successfulShards ());
112
197
0 commit comments