@@ -110,7 +110,10 @@ private static function wipeCluster(Client $client): void
110
110
{
111
111
if (getenv ('TEST_SUITE ' ) === 'platinum ' ) {
112
112
self ::wipeRollupJobs ($ client );
113
- self ::waitForPendingRollupTasks ($ client );
113
+ self ::waitForPendingRollupTasks ($ client );
114
+ }
115
+
116
+ if (version_compare (getenv ('STACK_VERSION ' ), '7.3.99 ' ) > 0 ) {
114
117
self ::deleteAllSLMPolicies ($ client );
115
118
}
116
119
@@ -262,9 +265,24 @@ private static function deleteAllSLMPolicies(Client $client): void
262
265
*/
263
266
private static function wipeDataStreams (Client $ client ): void
264
267
{
265
- $ client ->indices ()->deleteDataStream ([
266
- 'name ' => '* '
267
- ]);
268
+ try {
269
+ if (version_compare (getenv ('STACK_VERSION ' ), '7.8.99 ' ) > 0 ) {
270
+ $ client ->indices ()->deleteDataStream ([
271
+ 'name ' => '* ' ,
272
+ 'expand_wildcards ' => 'all '
273
+ ]);
274
+ }
275
+ } catch (ElasticsearchException $ e ) {
276
+ // We hit a version of ES that doesn't understand expand_wildcards, try again without it
277
+ try {
278
+ $ client ->indices ()->deleteDataStream ([
279
+ 'name ' => '* '
280
+ ]);
281
+ } catch (ElasticsearchException $ e ) {
282
+ // We hit a version of ES that doesn't serialize DeleteDataStreamAction.Request#wildcardExpressionsOriginallySpecified
283
+ // field or that doesn't support data streams so it's safe to ignore
284
+ }
285
+ }
268
286
}
269
287
270
288
/**
@@ -293,39 +311,51 @@ private static function wipeAllIndices(Client $client): void
293
311
*/
294
312
private static function wipeTemplateForXpack (Client $ client ): void
295
313
{
296
- $ result = $ client ->cat ()->templates ([
297
- 'h ' => 'name '
298
- ]);
299
- $ templates = explode ("\n" , $ result );
300
- foreach ($ templates as $ template ) {
301
- if (empty ($ template ) || self ::isXPackTemplate ($ template )) {
302
- continue ;
303
- }
314
+ if (version_compare (getenv ('STACK_VERSION ' ), '7.6.99 ' ) > 0 ) {
304
315
try {
305
- $ client ->indices ()->deleteTemplate ([
306
- 'name ' => $ template
307
- ]);
308
- } catch (Missing404Exception $ e ) {
309
- $ msg = sprintf ("index_template [%s] missing " , $ template );
310
- if (strpos ($ e ->getMessage (), $ msg ) !== false ) {
311
- $ client ->indices ()->deleteIndexTemplate ([
312
- 'name ' => $ template
316
+ $ result = $ client ->indices ()->getIndexTemplate ();
317
+ foreach ($ result ['index_templates ' ] as $ template ) {
318
+ if (self ::isXPackTemplate ($ template ['name ' ])) {
319
+ continue ;
320
+ }
321
+ try {
322
+ $ client ->indices ()->deleteIndexTemplate ([
323
+ 'name ' => $ template ['name ' ]
324
+ ]);
325
+ } catch (ElasticsearchException $ e ) {
326
+ // unable to remove index template
327
+ }
328
+ }
329
+ } catch (ElasticsearchException $ e ) {
330
+ // We hit a version of ES that doesn't support index templates v2 yet, so it's safe to ignore
331
+ }
332
+ // Delete component template
333
+ $ result = $ client ->cluster ()->getComponentTemplate ();
334
+ foreach ($ result ['component_templates ' ] as $ component ) {
335
+ if (self ::isXPackTemplate ($ component ['name ' ])) {
336
+ continue ;
337
+ }
338
+ try {
339
+ $ client ->cluster ()->deleteComponentTemplate ([
340
+ 'name ' => $ component ['name ' ]
313
341
]);
342
+ } catch (ElasticsearchException $ e ) {
343
+ // We hit a version of ES that doesn't support index templates v2 yet, so it's safe to ignore
314
344
}
315
345
}
316
346
}
317
- // Delete component template
318
- $ result = $ client ->cluster ()->getComponentTemplate ();
319
- foreach ($ result[ ' component_templates ' ] as $ component ) {
320
- if (self ::isXPackTemplate ($ component [ ' name ' ] )) {
347
+ // Always check for legacy templates
348
+ $ result = $ client ->indices ()->getTemplate ();
349
+ foreach ($ result as $ name => $ value ) {
350
+ if (self ::isXPackTemplate ($ name )) {
321
351
continue ;
322
352
}
323
353
try {
324
- $ client ->cluster ()->deleteComponentTemplate ([
325
- 'name ' => $ component [ ' name ' ]
354
+ $ result = $ client ->indices ()->deleteTemplate ([
355
+ 'name ' => $ name
326
356
]);
327
357
} catch (ElasticsearchException $ e ) {
328
- // We hit a version of ES that doesn't support index templates v2 yet, so it's safe to ignore
358
+ // unable to remove index template
329
359
}
330
360
}
331
361
}
@@ -398,6 +428,8 @@ private static function isXPackTemplate(string $name): bool
398
428
case "synthetics-mappings " :
399
429
case ".snapshot-blob-cache " :
400
430
case ".deprecation-indexing-template " :
431
+ case "logstash-index-template " :
432
+ case "security-index-template " :
401
433
return true ;
402
434
}
403
435
return false ;
0 commit comments