10
10
import org .apache .logging .log4j .LogManager ;
11
11
import org .apache .logging .log4j .Logger ;
12
12
import org .elasticsearch .client .internal .Client ;
13
+ import org .elasticsearch .cluster .ClusterChangedEvent ;
13
14
import org .elasticsearch .cluster .metadata .ComponentTemplate ;
14
15
import org .elasticsearch .cluster .metadata .ComposableIndexTemplate ;
15
16
import org .elasticsearch .cluster .service .ClusterService ;
16
17
import org .elasticsearch .common .settings .Settings ;
17
18
import org .elasticsearch .common .xcontent .XContentHelper ;
18
19
import org .elasticsearch .core .Nullable ;
20
+ import org .elasticsearch .features .FeatureService ;
21
+ import org .elasticsearch .features .NodeFeature ;
19
22
import org .elasticsearch .threadpool .ThreadPool ;
20
23
import org .elasticsearch .xcontent .NamedXContentRegistry ;
21
24
import org .elasticsearch .xcontent .XContentParserConfiguration ;
39
42
*/
40
43
public class APMIndexTemplateRegistry extends IndexTemplateRegistry {
41
44
private static final Logger logger = LogManager .getLogger (APMIndexTemplateRegistry .class );
42
-
45
+ // this node feature is a redefinition of {@link DataStreamFeatures#DATA_STREAM_LIFECYCLE} and it's meant to avoid adding a
46
+ // dependency to the data-streams module just for this
47
+ public static final NodeFeature DATA_STREAM_LIFECYCLE = new NodeFeature ("data_stream.lifecycle" );
43
48
private final int version ;
44
49
45
50
private final Map <String , ComponentTemplate > componentTemplates ;
46
51
private final Map <String , ComposableIndexTemplate > composableIndexTemplates ;
47
52
private final List <IngestPipelineConfig > ingestPipelines ;
53
+ private final FeatureService featureService ;
48
54
private volatile boolean enabled ;
49
55
50
56
@ SuppressWarnings ("unchecked" )
@@ -53,7 +59,8 @@ public APMIndexTemplateRegistry(
53
59
ClusterService clusterService ,
54
60
ThreadPool threadPool ,
55
61
Client client ,
56
- NamedXContentRegistry xContentRegistry
62
+ NamedXContentRegistry xContentRegistry ,
63
+ FeatureService featureService
57
64
) {
58
65
super (nodeSettings , clusterService , threadPool , client , xContentRegistry );
59
66
@@ -78,6 +85,7 @@ public APMIndexTemplateRegistry(
78
85
Map .Entry <String , Map <String , Object >> pipelineConfig = map .entrySet ().iterator ().next ();
79
86
return loadIngestPipeline (pipelineConfig .getKey (), version , (List <String >) pipelineConfig .getValue ().get ("dependencies" ));
80
87
}).collect (Collectors .toList ());
88
+ this .featureService = featureService ;
81
89
} catch (IOException e ) {
82
90
throw new RuntimeException (e );
83
91
}
@@ -105,6 +113,13 @@ protected String getOrigin() {
105
113
return ClientHelper .APM_ORIGIN ;
106
114
}
107
115
116
+ @ Override
117
+ protected boolean isClusterReady (ClusterChangedEvent event ) {
118
+ // Ensure current version of the components are installed only after versions that support data stream lifecycle
119
+ // due to the use of the feature in all the `@lifecycle` component templates
120
+ return featureService .clusterHasFeature (event .state (), DATA_STREAM_LIFECYCLE );
121
+ }
122
+
108
123
@ Override
109
124
protected boolean requiresMasterNode () {
110
125
return true ;
0 commit comments