31
31
import org .elasticsearch .common .bytes .BytesReference ;
32
32
import org .elasticsearch .common .io .stream .StreamInput ;
33
33
import org .elasticsearch .common .io .stream .StreamOutput ;
34
+ import org .elasticsearch .common .settings .Settings ;
34
35
import org .elasticsearch .common .time .DateFormatter ;
35
36
import org .elasticsearch .common .time .DateFormatters ;
36
37
import org .elasticsearch .common .xcontent .XContentHelper ;
67
68
import java .util .function .Predicate ;
68
69
import java .util .stream .Collectors ;
69
70
71
+ import static org .elasticsearch .cluster .metadata .MetadataCreateDataStreamService .lookupTemplateForDataStream ;
70
72
import static org .elasticsearch .common .xcontent .XContentParserUtils .ensureExpectedToken ;
71
73
import static org .elasticsearch .index .IndexSettings .LIFECYCLE_ORIGINATION_DATE ;
72
74
import static org .elasticsearch .index .IndexSettings .PREFER_ILM_SETTING ;
@@ -114,6 +116,7 @@ public final class DataStream implements SimpleDiffable<DataStream>, ToXContentO
114
116
private final long generation ;
115
117
@ Nullable
116
118
private final Map <String , Object > metadata ;
119
+ private final Settings settings ;
117
120
private final boolean hidden ;
118
121
private final boolean replicated ;
119
122
private final boolean system ;
@@ -146,8 +149,46 @@ public DataStream(
146
149
) {
147
150
this (
148
151
name ,
152
+ indices ,
149
153
generation ,
150
154
metadata ,
155
+ Settings .EMPTY ,
156
+ hidden ,
157
+ replicated ,
158
+ system ,
159
+ allowCustomRouting ,
160
+ indexMode ,
161
+ lifecycle ,
162
+ dataStreamOptions ,
163
+ failureIndices ,
164
+ rolloverOnWrite ,
165
+ autoShardingEvent
166
+ );
167
+ }
168
+
169
+ // visible for testing
170
+ public DataStream (
171
+ String name ,
172
+ List <Index > indices ,
173
+ long generation ,
174
+ Map <String , Object > metadata ,
175
+ Settings settings ,
176
+ boolean hidden ,
177
+ boolean replicated ,
178
+ boolean system ,
179
+ boolean allowCustomRouting ,
180
+ IndexMode indexMode ,
181
+ DataStreamLifecycle lifecycle ,
182
+ @ Nullable DataStreamOptions dataStreamOptions ,
183
+ List <Index > failureIndices ,
184
+ boolean rolloverOnWrite ,
185
+ @ Nullable DataStreamAutoShardingEvent autoShardingEvent
186
+ ) {
187
+ this (
188
+ name ,
189
+ generation ,
190
+ metadata ,
191
+ settings ,
151
192
hidden ,
152
193
replicated ,
153
194
system ,
@@ -165,6 +206,7 @@ public DataStream(
165
206
String name ,
166
207
long generation ,
167
208
Map <String , Object > metadata ,
209
+ Settings settings ,
168
210
boolean hidden ,
169
211
boolean replicated ,
170
212
boolean system ,
@@ -179,6 +221,7 @@ public DataStream(
179
221
this .name = name ;
180
222
this .generation = generation ;
181
223
this .metadata = metadata ;
224
+ this .settings = Objects .requireNonNull (settings );
182
225
assert system == false || hidden ; // system indices must be hidden
183
226
this .hidden = hidden ;
184
227
this .replicated = replicated ;
@@ -231,10 +274,17 @@ public static DataStream read(StreamInput in) throws IOException {
231
274
// is still behind a feature flag in previous version we use the default value instead of explicitly disabling it.
232
275
dataStreamOptions = failureStoreEnabled ? DataStreamOptions .FAILURE_STORE_ENABLED : null ;
233
276
}
277
+ final Settings settings ;
278
+ if (in .getTransportVersion ().onOrAfter (TransportVersions .SETTINGS_IN_DATA_STREAMS )) {
279
+ settings = Settings .readSettingsFromStream (in );
280
+ } else {
281
+ settings = Settings .EMPTY ;
282
+ }
234
283
return new DataStream (
235
284
name ,
236
285
generation ,
237
286
metadata ,
287
+ settings ,
238
288
hidden ,
239
289
replicated ,
240
290
system ,
@@ -325,6 +375,20 @@ public boolean rolloverOnWrite() {
325
375
return backingIndices .rolloverOnWrite ;
326
376
}
327
377
378
+ public ComposableIndexTemplate getEffectiveIndexTemplate (ProjectMetadata projectMetadata ) {
379
+ return getMatchingIndexTemplate (projectMetadata ).mergeSettings (settings );
380
+ }
381
+
382
+ public Settings getEffectiveSettings (ProjectMetadata projectMetadata ) {
383
+ ComposableIndexTemplate template = getMatchingIndexTemplate (projectMetadata );
384
+ Settings templateSettings = template .template () == null ? Settings .EMPTY : template .template ().settings ();
385
+ return templateSettings .merge (settings );
386
+ }
387
+
388
+ private ComposableIndexTemplate getMatchingIndexTemplate (ProjectMetadata projectMetadata ) {
389
+ return lookupTemplateForDataStream (name , projectMetadata );
390
+ }
391
+
328
392
/**
329
393
* We define that a data stream is considered internal either if it is a system index or if
330
394
* its name starts with a dot.
@@ -436,6 +500,10 @@ public Map<String, Object> getMetadata() {
436
500
return metadata ;
437
501
}
438
502
503
+ public Settings getSettings () {
504
+ return settings ;
505
+ }
506
+
439
507
@ Override
440
508
public boolean isHidden () {
441
509
return hidden ;
@@ -1263,6 +1331,9 @@ public void writeTo(StreamOutput out) throws IOException {
1263
1331
if (out .getTransportVersion ().onOrAfter (DataStream .ADD_DATA_STREAM_OPTIONS_VERSION )) {
1264
1332
out .writeOptionalWriteable (dataStreamOptions .isEmpty () ? null : dataStreamOptions );
1265
1333
}
1334
+ if (out .getTransportVersion ().onOrAfter (TransportVersions .SETTINGS_IN_DATA_STREAMS )) {
1335
+ settings .writeTo (out );
1336
+ }
1266
1337
}
1267
1338
1268
1339
public static final ParseField NAME_FIELD = new ParseField ("name" );
@@ -1284,6 +1355,7 @@ public void writeTo(StreamOutput out) throws IOException {
1284
1355
public static final ParseField FAILURE_ROLLOVER_ON_WRITE_FIELD = new ParseField ("failure_rollover_on_write" );
1285
1356
public static final ParseField FAILURE_AUTO_SHARDING_FIELD = new ParseField ("failure_auto_sharding" );
1286
1357
public static final ParseField DATA_STREAM_OPTIONS_FIELD = new ParseField ("options" );
1358
+ public static final ParseField SETTINGS_FIELD = new ParseField ("settings" );
1287
1359
1288
1360
@ SuppressWarnings ("unchecked" )
1289
1361
private static final ConstructingObjectParser <DataStream , Void > PARSER = new ConstructingObjectParser <>(
@@ -1292,6 +1364,7 @@ public void writeTo(StreamOutput out) throws IOException {
1292
1364
(String ) args [0 ],
1293
1365
(Long ) args [2 ],
1294
1366
(Map <String , Object >) args [3 ],
1367
+ args [17 ] == null ? Settings .EMPTY : (Settings ) args [17 ],
1295
1368
args [4 ] != null && (boolean ) args [4 ],
1296
1369
args [5 ] != null && (boolean ) args [5 ],
1297
1370
args [6 ] != null && (boolean ) args [6 ],
@@ -1358,6 +1431,7 @@ public void writeTo(StreamOutput out) throws IOException {
1358
1431
(p , c ) -> DataStreamOptions .fromXContent (p ),
1359
1432
DATA_STREAM_OPTIONS_FIELD
1360
1433
);
1434
+ PARSER .declareObject (ConstructingObjectParser .optionalConstructorArg (), (p , c ) -> Settings .fromXContent (p ), SETTINGS_FIELD );
1361
1435
}
1362
1436
1363
1437
public static DataStream fromXContent (XContentParser parser ) throws IOException {
@@ -1419,6 +1493,9 @@ public XContentBuilder toXContent(
1419
1493
backingIndices .autoShardingEvent .toXContent (builder , params );
1420
1494
builder .endObject ();
1421
1495
}
1496
+ builder .startObject (SETTINGS_FIELD .getPreferredName ());
1497
+ this .settings .toXContent (builder , params );
1498
+ builder .endObject ();
1422
1499
builder .endObject ();
1423
1500
return builder ;
1424
1501
}
@@ -1431,6 +1508,7 @@ public boolean equals(Object o) {
1431
1508
return name .equals (that .name )
1432
1509
&& generation == that .generation
1433
1510
&& Objects .equals (metadata , that .metadata )
1511
+ && Objects .equals (settings , that .settings )
1434
1512
&& hidden == that .hidden
1435
1513
&& system == that .system
1436
1514
&& replicated == that .replicated
@@ -1448,6 +1526,7 @@ public int hashCode() {
1448
1526
name ,
1449
1527
generation ,
1450
1528
metadata ,
1529
+ settings ,
1451
1530
hidden ,
1452
1531
system ,
1453
1532
replicated ,
@@ -1760,6 +1839,7 @@ public static class Builder {
1760
1839
private long generation = 1 ;
1761
1840
@ Nullable
1762
1841
private Map <String , Object > metadata = null ;
1842
+ private Settings settings = Settings .EMPTY ;
1763
1843
private boolean hidden = false ;
1764
1844
private boolean replicated = false ;
1765
1845
private boolean system = false ;
@@ -1787,6 +1867,7 @@ private Builder(DataStream dataStream) {
1787
1867
name = dataStream .name ;
1788
1868
generation = dataStream .generation ;
1789
1869
metadata = dataStream .metadata ;
1870
+ settings = dataStream .settings ;
1790
1871
hidden = dataStream .hidden ;
1791
1872
replicated = dataStream .replicated ;
1792
1873
system = dataStream .system ;
@@ -1818,6 +1899,11 @@ public Builder setMetadata(Map<String, Object> metadata) {
1818
1899
return this ;
1819
1900
}
1820
1901
1902
+ public Builder setSettings (Settings settings ) {
1903
+ this .settings = settings ;
1904
+ return this ;
1905
+ }
1906
+
1821
1907
public Builder setHidden (boolean hidden ) {
1822
1908
this .hidden = hidden ;
1823
1909
return this ;
@@ -1878,6 +1964,7 @@ public DataStream build() {
1878
1964
name ,
1879
1965
generation ,
1880
1966
metadata ,
1967
+ settings ,
1881
1968
hidden ,
1882
1969
replicated ,
1883
1970
system ,
0 commit comments