@@ -602,58 +602,63 @@ private void wipeCluster() throws Exception {
602602 * slows down the test because xpack will just recreate
603603 * them.
604604 */
605- try {
606- Request getTemplatesRequest = new Request ("GET" , "_index_template" );
607- getTemplatesRequest .setOptions (allowTypesRemovalWarnings ());
608- Map <String , Object > composableIndexTemplates = XContentHelper .convertToMap (JsonXContent .jsonXContent ,
609- EntityUtils .toString (adminClient ().performRequest (getTemplatesRequest ).getEntity ()), false );
610- List <String > names = ((List <?>) composableIndexTemplates .get ("index_templates" )).stream ()
611- .map (ct -> (String ) ((Map <?, ?>) ct ).get ("name" ))
612- .filter (name -> isXPackTemplate (name ) == false )
613- .collect (Collectors .toList ());
614- // Ideally we would want to check the version of the elected master node and
615- // send the delete request directly to that node.
616- if (nodeVersions .stream ().allMatch (version -> version .onOrAfter (Version .V_7_13_0 ))) {
617- try {
618- adminClient ().performRequest (new Request ("DELETE" , "_index_template/" + String .join ("," , names )));
619- } catch (ResponseException e ) {
620- logger .debug (new ParameterizedMessage ("unable to remove multiple composable index template {}" , names ), e );
621- }
622- } else {
623- for (String name : names ) {
605+ // In case of bwc testing, if all nodes are before 7.7.0 then no need to attempt to delete component and composable
606+ // index templates, because these were introduced in 7.7.0:
607+ if (nodeVersions .stream ().allMatch (version -> version .onOrAfter (Version .V_7_7_0 ))) {
608+ try {
609+ Request getTemplatesRequest = new Request ("GET" , "_index_template" );
610+ getTemplatesRequest .setOptions (allowTypesRemovalWarnings ());
611+ Map <String , Object > composableIndexTemplates = XContentHelper .convertToMap (JsonXContent .jsonXContent ,
612+ EntityUtils .toString (adminClient ().performRequest (getTemplatesRequest ).getEntity ()), false );
613+ List <String > names = ((List <?>) composableIndexTemplates .get ("index_templates" )).stream ()
614+ .map (ct -> (String ) ((Map <?, ?>) ct ).get ("name" ))
615+ .filter (name -> isXPackTemplate (name ) == false )
616+ .collect (Collectors .toList ());
617+ // Ideally we would want to check the version of the elected master node and
618+ // send the delete request directly to that node.
619+ if (nodeVersions .stream ().allMatch (version -> version .onOrAfter (Version .V_7_13_0 ))) {
624620 try {
625- adminClient ().performRequest (new Request ("DELETE" , "_index_template/" + name ));
621+ adminClient ().performRequest (new Request ("DELETE" , "_index_template/" + String . join ( "," , names ) ));
626622 } catch (ResponseException e ) {
627- logger .debug (new ParameterizedMessage ("unable to remove composable index template {}" , name ), e );
623+ logger .debug (new ParameterizedMessage ("unable to remove multiple composable index template {}" , names ), e );
624+ }
625+ } else {
626+ for (String name : names ) {
627+ try {
628+ adminClient ().performRequest (new Request ("DELETE" , "_index_template/" + name ));
629+ } catch (ResponseException e ) {
630+ logger .debug (new ParameterizedMessage ("unable to remove composable index template {}" , name ), e );
631+ }
628632 }
629633 }
634+ } catch (Exception e ) {
635+ logger .debug ("ignoring exception removing all composable index templates" , e );
636+ // We hit a version of ES that doesn't support index templates v2 yet, so it's safe to ignore
630637 }
631- } catch ( Exception e ) {
632- logger . debug ( "ignoring exception removing all composable index templates" , e );
633- // We hit a version of ES that doesn't support index templates v2 yet, so it's safe to ignore
634- }
635- try {
636- Request compReq = new Request ( "GET" , "_component_template" );
637- compReq . setOptions ( allowTypesRemovalWarnings ());
638- String componentTemplates = EntityUtils . toString ( adminClient (). performRequest ( compReq ). getEntity ());
639- Map < String , Object > cTemplates = XContentHelper . convertToMap ( JsonXContent . jsonXContent , componentTemplates , false );
640- List < String > names = (( List <?>) cTemplates . get ( "component_templates" )). stream ()
641- . map ( ct -> ( String ) (( Map <?, ?>) ct ). get ( "name" ))
642- . collect ( Collectors . toList ()) ;
643- for ( String componentTemplate : names ) {
644- try {
645- if ( isXPackTemplate ( componentTemplate ) ) {
646- continue ;
638+ try {
639+ Request compReq = new Request ( "GET" , "_component_template" );
640+ compReq . setOptions ( allowTypesRemovalWarnings ());
641+ String componentTemplates = EntityUtils . toString ( adminClient (). performRequest ( compReq ). getEntity ());
642+ Map < String , Object > cTemplates = XContentHelper . convertToMap ( JsonXContent . jsonXContent , componentTemplates , false );
643+ List < String > names = (( List <?>) cTemplates . get ( "component_templates" )). stream ()
644+ . map ( ct -> ( String ) (( Map <?, ?>) ct ). get ( "name" ))
645+ . collect ( Collectors . toList ());
646+ for ( String componentTemplate : names ) {
647+ try {
648+ if ( isXPackTemplate ( componentTemplate )) {
649+ continue ;
650+ }
651+ adminClient (). performRequest ( new Request ( "DELETE" , "_component_template/" + componentTemplate ));
652+ } catch ( ResponseException e ) {
653+ logger . debug ( new ParameterizedMessage ( "unable to remove component template {}" , componentTemplate ), e ) ;
647654 }
648- adminClient ().performRequest (new Request ("DELETE" , "_component_template/" + componentTemplate ));
649- } catch (ResponseException e ) {
650- logger .debug (new ParameterizedMessage ("unable to remove component template {}" , componentTemplate ), e );
651655 }
656+ } catch (Exception e ) {
657+ logger .debug ("ignoring exception removing all component templates" , e );
658+ // We hit a version of ES that doesn't support index templates v2 yet, so it's safe to ignore
652659 }
653- } catch (Exception e ) {
654- logger .debug ("ignoring exception removing all component templates" , e );
655- // We hit a version of ES that doesn't support index templates v2 yet, so it's safe to ignore
656660 }
661+ // Always check for legacy templates:
657662 Request getLegacyTemplatesRequest = new Request ("GET" , "_template" );
658663 getLegacyTemplatesRequest .setOptions (allowTypesRemovalWarnings ());
659664 Map <String , Object > legacyTemplates = XContentHelper .convertToMap (JsonXContent .jsonXContent ,
@@ -730,7 +735,7 @@ protected static void wipeAllIndices() throws IOException {
730735
731736 protected static void wipeDataStreams () throws IOException {
732737 try {
733- if (hasXPack ()) {
738+ if (hasXPack () && nodeVersions . stream (). allMatch ( version -> version . onOrAfter ( Version . V_7_9_0 )) ) {
734739 adminClient ().performRequest (new Request ("DELETE" , "_data_stream/*?expand_wildcards=all" ));
735740 }
736741 } catch (ResponseException e ) {
@@ -1442,6 +1447,8 @@ protected static boolean isXPackTemplate(String name) {
14421447 case "synthetics-mappings" :
14431448 case ".snapshot-blob-cache" :
14441449 case ".deprecation-indexing-template" :
1450+ case "logstash-index-template" :
1451+ case "security-index-template" :
14451452 return true ;
14461453 default :
14471454 return false ;
0 commit comments