Skip to content

Commit deb0d4c

Browse files
authored
[7.16] Add replicated field to get data stream api response. (#81140)
* [7.16] Add replicated field to get data stream api response. Backporting #80988 to 7.16 branch. Internally we already kept track of whether a data stream is replicated by CCR. It is part of the `DataStream` class. This just adds it to the xcontent serialization of the get data stream api response class. Relates to elastic/kibana#118899 * adjust to 7.16 reality
1 parent af5fa3f commit deb0d4c

File tree

5 files changed

+34
-9
lines changed

5 files changed

+34
-9
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/indices/DataStream.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public final class DataStream {
3434
String ilmPolicyName;
3535
@Nullable
3636
private final Map<String, Object> metadata;
37+
private final boolean replicated;
3738

3839
public DataStream(
3940
String name,
@@ -45,7 +46,8 @@ public DataStream(
4546
@Nullable String ilmPolicyName,
4647
@Nullable Map<String, Object> metadata,
4748
boolean hidden,
48-
boolean system
49+
boolean system,
50+
boolean replicated
4951
) {
5052
this.name = name;
5153
this.timeStampField = timeStampField;
@@ -57,6 +59,7 @@ public DataStream(
5759
this.metadata = metadata;
5860
this.hidden = hidden;
5961
this.system = system;
62+
this.replicated = replicated;
6063
}
6164

6265
public String getName() {
@@ -99,6 +102,10 @@ public boolean isSystem() {
99102
return system;
100103
}
101104

105+
public boolean isReplicated() {
106+
return replicated;
107+
}
108+
102109
public static final ParseField NAME_FIELD = new ParseField("name");
103110
public static final ParseField TIMESTAMP_FIELD_FIELD = new ParseField("timestamp_field");
104111
public static final ParseField INDICES_FIELD = new ParseField("indices");
@@ -109,6 +116,7 @@ public boolean isSystem() {
109116
public static final ParseField METADATA_FIELD = new ParseField("_meta");
110117
public static final ParseField HIDDEN_FIELD = new ParseField("hidden");
111118
public static final ParseField SYSTEM_FIELD = new ParseField("system");
119+
public static final ParseField REPLICATED = new ParseField("replicated");
112120

113121
@SuppressWarnings("unchecked")
114122
private static final ConstructingObjectParser<DataStream, Void> PARSER = new ConstructingObjectParser<>("data_stream", args -> {
@@ -123,6 +131,7 @@ public boolean isSystem() {
123131
Map<String, Object> metadata = (Map<String, Object>) args[7];
124132
boolean hidden = args[8] != null && (boolean) args[8];
125133
boolean system = args[9] != null && (boolean) args[9];
134+
boolean replicated = args[10] != null && (boolean) args[10];
126135
return new DataStream(
127136
dataStreamName,
128137
timeStampField,
@@ -133,7 +142,8 @@ public boolean isSystem() {
133142
ilmPolicy,
134143
metadata,
135144
hidden,
136-
system
145+
system,
146+
replicated
137147
);
138148
});
139149

@@ -148,6 +158,7 @@ public boolean isSystem() {
148158
PARSER.declareObject(ConstructingObjectParser.optionalConstructorArg(), (p, c) -> p.map(), METADATA_FIELD);
149159
PARSER.declareBoolean(ConstructingObjectParser.optionalConstructorArg(), HIDDEN_FIELD);
150160
PARSER.declareBoolean(ConstructingObjectParser.optionalConstructorArg(), SYSTEM_FIELD);
161+
PARSER.declareBoolean(ConstructingObjectParser.optionalConstructorArg(), REPLICATED);
151162
}
152163

153164
public static DataStream fromXContent(XContentParser parser) throws IOException {
@@ -168,7 +179,8 @@ public boolean equals(Object o) {
168179
&& system == that.system
169180
&& Objects.equals(indexTemplate, that.indexTemplate)
170181
&& Objects.equals(ilmPolicyName, that.ilmPolicyName)
171-
&& Objects.equals(metadata, that.metadata);
182+
&& Objects.equals(metadata, that.metadata)
183+
&& replicated == that.replicated;
172184
}
173185

174186
@Override
@@ -183,7 +195,8 @@ public int hashCode() {
183195
ilmPolicyName,
184196
metadata,
185197
hidden,
186-
system
198+
system,
199+
replicated
187200
);
188201
}
189202
}

docs/reference/data-streams/change-mappings-and-settings.asciidoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,8 @@ stream's oldest backing index.
577577
"status": "GREEN",
578578
"template": "my-data-stream-template",
579579
"hidden": false,
580-
"system": false
580+
"system": false,
581+
"replicated": false
581582
}
582583
]
583584
}

docs/reference/indices/get-data-stream.asciidoc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ use the <<indices-get-settings,get index settings API>>.
207207
(Boolean)
208208
If `true`, the data stream is created and managed by an Elastic stack component
209209
and cannot be modified through normal user interaction.
210+
211+
`replicated`::
212+
(Boolean)
213+
If `true`, the data stream is created and managed by {ccr} and the local
214+
cluster can not write into this data stream or change its mappings.
210215
====
211216

212217
[[get-data-stream-api-example]]
@@ -246,7 +251,8 @@ The API returns the following response:
246251
"template": "my-index-template",
247252
"ilm_policy": "my-lifecycle-policy",
248253
"hidden": false,
249-
"system": false
254+
"system": false,
255+
"replicated": false
250256
},
251257
{
252258
"name": "my-data-stream-two",
@@ -267,7 +273,8 @@ The API returns the following response:
267273
"template": "my-index-template",
268274
"ilm_policy": "my-lifecycle-policy",
269275
"hidden": false,
270-
"system": false
276+
"system": false,
277+
"replicated": false
271278
}
272279
]
273280
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/GetDataStreamAction.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ public static class DataStreamInfo extends AbstractDiffable<DataStreamInfo> impl
123123
public static final ParseField ILM_POLICY_FIELD = new ParseField("ilm_policy");
124124
public static final ParseField HIDDEN_FIELD = new ParseField("hidden");
125125
public static final ParseField SYSTEM_FIELD = new ParseField("system");
126+
public static final ParseField REPLICATED = new ParseField("replicated");
126127

127128
DataStream dataStream;
128129
ClusterHealthStatus dataStreamStatus;
@@ -192,6 +193,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
192193
}
193194
builder.field(HIDDEN_FIELD.getPreferredName(), dataStream.isHidden());
194195
builder.field(SYSTEM_FIELD.getPreferredName(), dataStream.isSystem());
196+
builder.field(REPLICATED.getPreferredName(), dataStream.isReplicated());
195197
builder.endObject();
196198
return builder;
197199
}

x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/data_stream/10_basic.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ setup:
5454
- match: { data_streams.0.status: 'GREEN' }
5555
- match: { data_streams.0.template: 'my-template1' }
5656
- match: { data_streams.0.hidden: false }
57+
- match: { data_streams.0.replicated: false }
5758
- match: { data_streams.1.name: simple-data-stream2 }
5859
- match: { data_streams.1.timestamp_field.name: '@timestamp' }
59-
- match: { data_streams.0.generation: 1 }
60+
- match: { data_streams.1.generation: 1 }
6061
- length: { data_streams.1.indices: 1 }
6162
- match: { data_streams.1.indices.0.index_name: '/\.ds-simple-data-stream2-(\d{4}\.\d{2}\.\d{2}-)?000001/' }
6263
- match: { data_streams.1.template: 'my-template2' }
63-
- match: { data_streams.0.hidden: false }
64+
- match: { data_streams.1.hidden: false }
65+
- match: { data_streams.1.replicated: false }
6466

6567
# save the backing index names for later use
6668
- set: { data_streams.0.indices.0.index_name: idx0name }

0 commit comments

Comments
 (0)