Skip to content

Commit d349af5

Browse files
committed
Merge remote-tracking branch 'origin/snapshot-lifecycle-management' into slm-retention
2 parents e383beb + 1a9988e commit d349af5

File tree

98 files changed

+2047
-834
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+2047
-834
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/dataframe/PreviewDataFrameTransformResponse.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,32 @@
2929
public class PreviewDataFrameTransformResponse {
3030

3131
private static final String PREVIEW = "preview";
32+
private static final String MAPPINGS = "mappings";
3233

3334
@SuppressWarnings("unchecked")
3435
public static PreviewDataFrameTransformResponse fromXContent(final XContentParser parser) throws IOException {
35-
Object previewDocs = parser.map().get(PREVIEW);
36-
return new PreviewDataFrameTransformResponse((List<Map<String, Object>>) previewDocs);
36+
Map<String, Object> previewMap = parser.mapOrdered();
37+
Object previewDocs = previewMap.get(PREVIEW);
38+
Object mappings = previewMap.get(MAPPINGS);
39+
return new PreviewDataFrameTransformResponse((List<Map<String, Object>>) previewDocs, (Map<String, Object>) mappings);
3740
}
3841

3942
private List<Map<String, Object>> docs;
43+
private Map<String, Object> mappings;
4044

41-
public PreviewDataFrameTransformResponse(List<Map<String, Object>> docs) {
45+
public PreviewDataFrameTransformResponse(List<Map<String, Object>> docs, Map<String, Object> mappings) {
4246
this.docs = docs;
47+
this.mappings = mappings;
4348
}
4449

4550
public List<Map<String, Object>> getDocs() {
4651
return docs;
4752
}
4853

54+
public Map<String, Object> getMappings() {
55+
return mappings;
56+
}
57+
4958
@Override
5059
public boolean equals(Object obj) {
5160
if (obj == this) {
@@ -57,12 +66,12 @@ public boolean equals(Object obj) {
5766
}
5867

5968
PreviewDataFrameTransformResponse other = (PreviewDataFrameTransformResponse) obj;
60-
return Objects.equals(other.docs, docs);
69+
return Objects.equals(other.docs, docs) && Objects.equals(other.mappings, mappings);
6170
}
6271

6372
@Override
6473
public int hashCode() {
65-
return Objects.hashCode(docs);
74+
return Objects.hash(docs, mappings);
6675
}
6776

6877
}

client/rest-high-level/src/main/java/org/elasticsearch/client/dataframe/transforms/DataFrameTransformState.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class DataFrameTransformState {
4343
private static final ParseField CHECKPOINT = new ParseField("checkpoint");
4444
private static final ParseField REASON = new ParseField("reason");
4545
private static final ParseField PROGRESS = new ParseField("progress");
46+
private static final ParseField NODE = new ParseField("node");
4647

4748
@SuppressWarnings("unchecked")
4849
public static final ConstructingObjectParser<DataFrameTransformState, Void> PARSER =
@@ -52,7 +53,8 @@ public class DataFrameTransformState {
5253
(Map<String, Object>) args[2],
5354
(long) args[3],
5455
(String) args[4],
55-
(DataFrameTransformProgress) args[5]));
56+
(DataFrameTransformProgress) args[5],
57+
(NodeAttributes) args[6]));
5658

5759
static {
5860
PARSER.declareField(constructorArg(), p -> DataFrameTransformTaskState.fromString(p.text()), TASK_STATE, ValueType.STRING);
@@ -61,6 +63,7 @@ public class DataFrameTransformState {
6163
PARSER.declareLong(ConstructingObjectParser.optionalConstructorArg(), CHECKPOINT);
6264
PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), REASON);
6365
PARSER.declareField(optionalConstructorArg(), DataFrameTransformProgress::fromXContent, PROGRESS, ValueType.OBJECT);
66+
PARSER.declareField(optionalConstructorArg(), NodeAttributes.PARSER::apply, NODE, ValueType.OBJECT);
6467
}
6568

6669
public static DataFrameTransformState fromXContent(XContentParser parser) throws IOException {
@@ -73,19 +76,22 @@ public static DataFrameTransformState fromXContent(XContentParser parser) throws
7376
private final Map<String, Object> currentPosition;
7477
private final String reason;
7578
private final DataFrameTransformProgress progress;
79+
private final NodeAttributes node;
7680

7781
public DataFrameTransformState(DataFrameTransformTaskState taskState,
7882
IndexerState indexerState,
7983
@Nullable Map<String, Object> position,
8084
long checkpoint,
8185
@Nullable String reason,
82-
@Nullable DataFrameTransformProgress progress) {
86+
@Nullable DataFrameTransformProgress progress,
87+
@Nullable NodeAttributes node) {
8388
this.taskState = taskState;
8489
this.indexerState = indexerState;
8590
this.currentPosition = position == null ? null : Collections.unmodifiableMap(new LinkedHashMap<>(position));
8691
this.checkpoint = checkpoint;
8792
this.reason = reason;
8893
this.progress = progress;
94+
this.node = node;
8995
}
9096

9197
public IndexerState getIndexerState() {
@@ -115,6 +121,11 @@ public DataFrameTransformProgress getProgress() {
115121
return progress;
116122
}
117123

124+
@Nullable
125+
public NodeAttributes getNode() {
126+
return node;
127+
}
128+
118129
@Override
119130
public boolean equals(Object other) {
120131
if (this == other) {
@@ -132,12 +143,13 @@ public boolean equals(Object other) {
132143
Objects.equals(this.currentPosition, that.currentPosition) &&
133144
Objects.equals(this.progress, that.progress) &&
134145
this.checkpoint == that.checkpoint &&
146+
Objects.equals(this.node, that.node) &&
135147
Objects.equals(this.reason, that.reason);
136148
}
137149

138150
@Override
139151
public int hashCode() {
140-
return Objects.hash(taskState, indexerState, currentPosition, checkpoint, reason, progress);
152+
return Objects.hash(taskState, indexerState, currentPosition, checkpoint, reason, progress, node);
141153
}
142154

143155
}
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.elasticsearch.client.dataframe.transforms;
20+
21+
import org.elasticsearch.common.ParseField;
22+
import org.elasticsearch.common.Strings;
23+
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
24+
import org.elasticsearch.common.xcontent.ObjectParser;
25+
import org.elasticsearch.common.xcontent.ToXContentObject;
26+
import org.elasticsearch.common.xcontent.XContentBuilder;
27+
28+
import java.io.IOException;
29+
import java.util.Collections;
30+
import java.util.Map;
31+
import java.util.Objects;
32+
33+
/**
34+
* A Pojo class containing an Elastic Node's attributes
35+
*/
36+
public class NodeAttributes implements ToXContentObject {
37+
38+
public static final ParseField ID = new ParseField("id");
39+
public static final ParseField NAME = new ParseField("name");
40+
public static final ParseField EPHEMERAL_ID = new ParseField("ephemeral_id");
41+
public static final ParseField TRANSPORT_ADDRESS = new ParseField("transport_address");
42+
public static final ParseField ATTRIBUTES = new ParseField("attributes");
43+
44+
@SuppressWarnings("unchecked")
45+
public static final ConstructingObjectParser<NodeAttributes, Void> PARSER =
46+
new ConstructingObjectParser<>("node", true,
47+
(a) -> {
48+
int i = 0;
49+
String id = (String) a[i++];
50+
String name = (String) a[i++];
51+
String ephemeralId = (String) a[i++];
52+
String transportAddress = (String) a[i++];
53+
Map<String, String> attributes = (Map<String, String>) a[i];
54+
return new NodeAttributes(id, name, ephemeralId, transportAddress, attributes);
55+
});
56+
57+
static {
58+
PARSER.declareString(ConstructingObjectParser.constructorArg(), ID);
59+
PARSER.declareString(ConstructingObjectParser.constructorArg(), NAME);
60+
PARSER.declareString(ConstructingObjectParser.constructorArg(), EPHEMERAL_ID);
61+
PARSER.declareString(ConstructingObjectParser.constructorArg(), TRANSPORT_ADDRESS);
62+
PARSER.declareField(ConstructingObjectParser.constructorArg(),
63+
(p, c) -> p.mapStrings(),
64+
ATTRIBUTES,
65+
ObjectParser.ValueType.OBJECT);
66+
}
67+
68+
private final String id;
69+
private final String name;
70+
private final String ephemeralId;
71+
private final String transportAddress;
72+
private final Map<String, String> attributes;
73+
74+
public NodeAttributes(String id, String name, String ephemeralId, String transportAddress, Map<String, String> attributes) {
75+
this.id = id;
76+
this.name = name;
77+
this.ephemeralId = ephemeralId;
78+
this.transportAddress = transportAddress;
79+
this.attributes = Collections.unmodifiableMap(attributes);
80+
}
81+
82+
/**
83+
* The unique identifier of the node.
84+
*/
85+
public String getId() {
86+
return id;
87+
}
88+
89+
/**
90+
* The node name.
91+
*/
92+
public String getName() {
93+
return name;
94+
}
95+
96+
/**
97+
* The ephemeral id of the node.
98+
*/
99+
public String getEphemeralId() {
100+
return ephemeralId;
101+
}
102+
103+
/**
104+
* The host and port where transport HTTP connections are accepted.
105+
*/
106+
public String getTransportAddress() {
107+
return transportAddress;
108+
}
109+
110+
/**
111+
* Additional attributes related to this node
112+
*/
113+
public Map<String, String> getAttributes() {
114+
return attributes;
115+
}
116+
117+
@Override
118+
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
119+
builder.startObject();
120+
builder.field(ID.getPreferredName(), id);
121+
builder.field(NAME.getPreferredName(), name);
122+
builder.field(EPHEMERAL_ID.getPreferredName(), ephemeralId);
123+
builder.field(TRANSPORT_ADDRESS.getPreferredName(), transportAddress);
124+
builder.field(ATTRIBUTES.getPreferredName(), attributes);
125+
builder.endObject();
126+
return builder;
127+
}
128+
129+
@Override
130+
public int hashCode() {
131+
return Objects.hash(id, name, ephemeralId, transportAddress, attributes);
132+
}
133+
134+
@Override
135+
public boolean equals(Object other) {
136+
if (this == other) {
137+
return true;
138+
}
139+
140+
if (other == null || getClass() != other.getClass()) {
141+
return false;
142+
}
143+
144+
NodeAttributes that = (NodeAttributes) other;
145+
return Objects.equals(id, that.id) &&
146+
Objects.equals(name, that.name) &&
147+
Objects.equals(ephemeralId, that.ephemeralId) &&
148+
Objects.equals(transportAddress, that.transportAddress) &&
149+
Objects.equals(attributes, that.attributes);
150+
}
151+
152+
@Override
153+
public String toString() {
154+
return Strings.toString(this);
155+
}
156+
}

client/rest-high-level/src/main/java/org/elasticsearch/client/security/user/privileges/Role.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,12 @@ public static class ClusterPrivilegeName {
299299
public static final String NONE = "none";
300300
public static final String ALL = "all";
301301
public static final String MONITOR = "monitor";
302+
public static final String MONITOR_DATA_FRAME_TRANSFORMS = "monitor_data_frame_transforms";
302303
public static final String MONITOR_ML = "monitor_ml";
303304
public static final String MONITOR_WATCHER = "monitor_watcher";
304305
public static final String MONITOR_ROLLUP = "monitor_rollup";
305306
public static final String MANAGE = "manage";
307+
public static final String MANAGE_DATA_FRAME_TRANSFORMS = "manage_data_frame_transforms";
306308
public static final String MANAGE_ML = "manage_ml";
307309
public static final String MANAGE_WATCHER = "manage_watcher";
308310
public static final String MANAGE_ROLLUP = "manage_rollup";
@@ -318,8 +320,9 @@ public static class ClusterPrivilegeName {
318320
public static final String READ_CCR = "read_ccr";
319321
public static final String MANAGE_ILM = "manage_ilm";
320322
public static final String READ_ILM = "read_ilm";
321-
public static final String[] ALL_ARRAY = new String[] { NONE, ALL, MONITOR, MONITOR_ML, MONITOR_WATCHER, MONITOR_ROLLUP, MANAGE,
322-
MANAGE_ML, MANAGE_WATCHER, MANAGE_ROLLUP, MANAGE_INDEX_TEMPLATES, MANAGE_INGEST_PIPELINES, TRANSPORT_CLIENT,
323+
public static final String[] ALL_ARRAY = new String[] { NONE, ALL, MONITOR, MONITOR_DATA_FRAME_TRANSFORMS, MONITOR_ML,
324+
MONITOR_WATCHER, MONITOR_ROLLUP, MANAGE, MANAGE_DATA_FRAME_TRANSFORMS,
325+
MANAGE_ML, MANAGE_WATCHER, MANAGE_ROLLUP, MANAGE_INDEX_TEMPLATES, MANAGE_INGEST_PIPELINES, TRANSPORT_CLIENT,
323326
MANAGE_SECURITY, MANAGE_SAML, MANAGE_OIDC, MANAGE_TOKEN, MANAGE_PIPELINE, MANAGE_CCR, READ_CCR, MANAGE_ILM, READ_ILM};
324327
}
325328

client/rest-high-level/src/test/java/org/elasticsearch/client/DataFrameTransformIT.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import static org.hamcrest.Matchers.empty;
7272
import static org.hamcrest.Matchers.equalTo;
7373
import static org.hamcrest.Matchers.greaterThan;
74+
import static org.hamcrest.Matchers.hasKey;
7475
import static org.hamcrest.Matchers.hasSize;
7576
import static org.hamcrest.Matchers.is;
7677
import static org.hamcrest.Matchers.oneOf;
@@ -277,6 +278,7 @@ public void testStartStop() throws IOException {
277278
assertThat(taskState, is(DataFrameTransformTaskState.STOPPED));
278279
}
279280

281+
@SuppressWarnings("unchecked")
280282
public void testPreview() throws IOException {
281283
String sourceIndex = "transform-source";
282284
createIndex(sourceIndex);
@@ -298,6 +300,12 @@ public void testPreview() throws IOException {
298300
Optional<Map<String, Object>> michel = docs.stream().filter(doc -> "michel".equals(doc.get("reviewer"))).findFirst();
299301
assertTrue(michel.isPresent());
300302
assertEquals(3.6d, (double) michel.get().get("avg_rating"), 0.1d);
303+
304+
Map<String, Object> mappings = preview.getMappings();
305+
assertThat(mappings, hasKey("properties"));
306+
Map<String, Object> fields = (Map<String, Object>)mappings.get("properties");
307+
assertThat(fields.get("reviewer"), equalTo(Map.of("type", "keyword")));
308+
assertThat(fields.get("avg_rating"), equalTo(Map.of("type", "double")));
301309
}
302310

303311
private DataFrameTransformConfig validDataFrameTransformConfig(String id, String source, String destination) {

client/rest-high-level/src/test/java/org/elasticsearch/client/dataframe/PreviewDataFrameTransformResponseTests.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,13 @@ private PreviewDataFrameTransformResponse createTestInstance() {
5353
}
5454
docs.add(doc);
5555
}
56+
int numMappingEntries = randomIntBetween(5, 10);
57+
Map<String, Object> mappings = new HashMap<>(numMappingEntries);
58+
for (int i = 0; i < numMappingEntries; i++) {
59+
mappings.put(randomAlphaOfLength(10), Map.of("type", randomAlphaOfLength(10)));
60+
}
5661

57-
return new PreviewDataFrameTransformResponse(docs);
62+
return new PreviewDataFrameTransformResponse(docs, mappings);
5863
}
5964

6065
private void toXContent(PreviewDataFrameTransformResponse response, XContentBuilder builder) throws IOException {
@@ -64,6 +69,7 @@ private void toXContent(PreviewDataFrameTransformResponse response, XContentBuil
6469
builder.map(doc);
6570
}
6671
builder.endArray();
72+
builder.field("mappings", response.getMappings());
6773
builder.endObject();
6874
}
6975
}

0 commit comments

Comments
 (0)