77package org .elasticsearch .xpack .transform .notifications ;
88
99import com .carrotsearch .hppc .cursors .ObjectObjectCursor ;
10+
11+ import org .elasticsearch .ElasticsearchException ;
12+ import org .elasticsearch .Version ;
1013import org .elasticsearch .action .admin .indices .alias .Alias ;
14+ import org .elasticsearch .action .admin .indices .template .put .PutComposableIndexTemplateAction ;
1115import org .elasticsearch .action .admin .indices .template .put .PutIndexTemplateRequest ;
1216import org .elasticsearch .client .Client ;
1317import org .elasticsearch .client .OriginSettingClient ;
1418import org .elasticsearch .cluster .metadata .AliasMetadata ;
19+ import org .elasticsearch .cluster .metadata .ComposableIndexTemplate ;
1520import org .elasticsearch .cluster .metadata .IndexTemplateMetadata ;
1621import org .elasticsearch .cluster .service .ClusterService ;
1722import org .elasticsearch .xcontent .ToXContent ;
2328import org .elasticsearch .xpack .transform .persistence .TransformInternalIndex ;
2429
2530import java .io .IOException ;
31+ import java .util .Collections ;
2632
2733import static org .elasticsearch .xpack .core .ClientHelper .TRANSFORM_ORIGIN ;
2834
@@ -34,22 +40,24 @@ public class TransformAuditor extends AbstractAuditor<TransformAuditMessage> {
3440 private volatile boolean isResetMode = false ;
3541
3642 public TransformAuditor (Client client , String nodeName , ClusterService clusterService ) {
37- super (new OriginSettingClient (client , TRANSFORM_ORIGIN ), TransformInternalIndexConstants .AUDIT_INDEX ,
38- TransformInternalIndexConstants .AUDIT_INDEX , null ,
43+ super (
44+ new OriginSettingClient (client , TRANSFORM_ORIGIN ),
45+ TransformInternalIndexConstants .AUDIT_INDEX ,
46+ TransformInternalIndexConstants .AUDIT_INDEX ,
47+ Version .V_7_16_0 ,
3948 () -> {
49+ // legacy template implementation, to be removed in 8.x
4050 try {
4151 IndexTemplateMetadata templateMeta = TransformInternalIndex .getAuditIndexTemplateMetadata ();
4252
43- PutIndexTemplateRequest request = new PutIndexTemplateRequest (templateMeta .name ())
44- .patterns (templateMeta .patterns ())
53+ PutIndexTemplateRequest request = new PutIndexTemplateRequest (templateMeta .name ()).patterns (templateMeta .patterns ())
4554 .version (templateMeta .version ())
4655 .settings (templateMeta .settings ())
4756 .mapping (templateMeta .mappings ().uncompressed (), XContentType .JSON );
4857
4958 for (ObjectObjectCursor <String , AliasMetadata > cursor : templateMeta .getAliases ()) {
5059 AliasMetadata meta = cursor .value ;
51- Alias alias = new Alias (meta .alias ())
52- .indexRouting (meta .indexRouting ())
60+ Alias alias = new Alias (meta .alias ()).indexRouting (meta .indexRouting ())
5361 .searchRouting (meta .searchRouting ())
5462 .isHidden (meta .isHidden ())
5563 .writeIndex (meta .writeIndex ());
@@ -62,10 +70,29 @@ public TransformAuditor(Client client, String nodeName, ClusterService clusterSe
6270
6371 return request ;
6472 } catch (IOException e ) {
65- return null ;
73+ throw new ElasticsearchException ("Failure creating transform notification index" , e );
74+ }
75+ },
76+ () -> {
77+ try {
78+ PutComposableIndexTemplateAction .Request request = new PutComposableIndexTemplateAction .Request (
79+ TransformInternalIndexConstants .AUDIT_INDEX
80+ ).indexTemplate (
81+ new ComposableIndexTemplate .Builder ().template (TransformInternalIndex .getAuditIndexTemplate ())
82+ .version ((long ) Version .CURRENT .id )
83+ .indexPatterns (Collections .singletonList (TransformInternalIndexConstants .AUDIT_INDEX_PREFIX + "*" ))
84+ .priority (Long .MAX_VALUE )
85+ .build ()
86+ );
87+ return request ;
88+ } catch (IOException e ) {
89+ throw new ElasticsearchException ("Failure creating transform notification index" , e );
6690 }
6791 },
68- () -> null , nodeName , TransformAuditMessage ::new , clusterService );
92+ nodeName ,
93+ TransformAuditMessage ::new ,
94+ clusterService
95+ );
6996 clusterService .addListener (event -> {
7097 if (event .metadataChanged ()) {
7198 isResetMode = TransformMetadata .getTransformMetadata (event .state ()).isResetMode ();
0 commit comments