Skip to content

Commit 2783e12

Browse files
committed
[ML][Data Frame] Add update transform api endpoint (elastic#45154)
This adds the ability to `_update` stored data frame transforms. All mutable fields are applied when the next checkpoint starts. The exception being `description`. This PR contains all that is necessary for this addition: * HLRC * Docs * Server side
1 parent be911e6 commit 2783e12

File tree

36 files changed

+2903
-89
lines changed

36 files changed

+2903
-89
lines changed

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

+47
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import org.elasticsearch.client.dataframe.StartDataFrameTransformResponse;
3434
import org.elasticsearch.client.dataframe.StopDataFrameTransformRequest;
3535
import org.elasticsearch.client.dataframe.StopDataFrameTransformResponse;
36+
import org.elasticsearch.client.dataframe.UpdateDataFrameTransformRequest;
37+
import org.elasticsearch.client.dataframe.UpdateDataFrameTransformResponse;
3638

3739
import java.io.IOException;
3840
import java.util.Collections;
@@ -88,6 +90,51 @@ public void putDataFrameTransformAsync(PutDataFrameTransformRequest request, Req
8890
Collections.emptySet());
8991
}
9092

93+
/**
94+
* Updates an existing Data Frame Transform
95+
* <p>
96+
* For additional info
97+
* see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/update-data-frame-transform.html">
98+
* Create data frame transform documentation</a>
99+
*
100+
* @param request The UpdateDataFrameTransformRequest containing the
101+
* {@link org.elasticsearch.client.dataframe.transforms.DataFrameTransformConfigUpdate}.
102+
* @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
103+
* @return An UpdateDataFrameTransformResponse object containing the updated configuration
104+
* @throws IOException when there is a serialization issue sending the request or receiving the response
105+
*/
106+
public UpdateDataFrameTransformResponse updateDataFrameTransform(UpdateDataFrameTransformRequest request,
107+
RequestOptions options) throws IOException {
108+
return restHighLevelClient.performRequestAndParseEntity(request,
109+
DataFrameRequestConverters::updateDataFrameTransform,
110+
options,
111+
UpdateDataFrameTransformResponse::fromXContent,
112+
Collections.emptySet());
113+
}
114+
115+
/**
116+
* Updates an existing Data Frame Transform asynchronously and notifies listener on completion
117+
* <p>
118+
* For additional info
119+
* see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/update-data-frame-transform.html">
120+
* Create data frame transform documentation</a>
121+
*
122+
* @param request The UpdateDataFrameTransformRequest containing the
123+
* {@link org.elasticsearch.client.dataframe.transforms.DataFrameTransformConfigUpdate}.
124+
* @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
125+
* @param listener Listener to be notified upon request completion
126+
*/
127+
public void updateDataFrameTransformAsync(UpdateDataFrameTransformRequest request,
128+
RequestOptions options,
129+
ActionListener<UpdateDataFrameTransformResponse> listener) {
130+
restHighLevelClient.performRequestAsyncAndParseEntity(request,
131+
DataFrameRequestConverters::updateDataFrameTransform,
132+
options,
133+
UpdateDataFrameTransformResponse::fromXContent,
134+
listener,
135+
Collections.emptySet());
136+
}
137+
91138
/**
92139
* Get the running statistics of a Data Frame Transform
93140
* <p>

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

+15
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.elasticsearch.client.dataframe.PutDataFrameTransformRequest;
3232
import org.elasticsearch.client.dataframe.StartDataFrameTransformRequest;
3333
import org.elasticsearch.client.dataframe.StopDataFrameTransformRequest;
34+
import org.elasticsearch.client.dataframe.UpdateDataFrameTransformRequest;
3435
import org.elasticsearch.common.Strings;
3536

3637
import java.io.IOException;
@@ -58,6 +59,20 @@ static Request putDataFrameTransform(PutDataFrameTransformRequest putRequest) th
5859
return request;
5960
}
6061

62+
static Request updateDataFrameTransform(UpdateDataFrameTransformRequest updateDataFrameTransformRequest) throws IOException {
63+
String endpoint = new RequestConverters.EndpointBuilder()
64+
.addPathPartAsIs("_data_frame", "transforms")
65+
.addPathPart(updateDataFrameTransformRequest.getId())
66+
.addPathPart("_update")
67+
.build();
68+
Request request = new Request(HttpPost.METHOD_NAME, endpoint);
69+
request.setEntity(createEntity(updateDataFrameTransformRequest, REQUEST_BODY_CONTENT_TYPE));
70+
if (updateDataFrameTransformRequest.getDeferValidation() != null) {
71+
request.addParameter(DEFER_VALIDATION, Boolean.toString(updateDataFrameTransformRequest.getDeferValidation()));
72+
}
73+
return request;
74+
}
75+
6176
static Request getDataFrameTransform(GetDataFrameTransformRequest getRequest) {
6277
String endpoint = new RequestConverters.EndpointBuilder()
6378
.addPathPartAsIs("_data_frame", "transforms")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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+
20+
package org.elasticsearch.client.dataframe;
21+
22+
import org.elasticsearch.client.Validatable;
23+
import org.elasticsearch.client.ValidationException;
24+
import org.elasticsearch.client.dataframe.transforms.DataFrameTransformConfigUpdate;
25+
import org.elasticsearch.common.xcontent.ToXContentObject;
26+
import org.elasticsearch.common.xcontent.XContentBuilder;
27+
28+
import java.io.IOException;
29+
import java.util.Objects;
30+
import java.util.Optional;
31+
32+
public class UpdateDataFrameTransformRequest implements ToXContentObject, Validatable {
33+
34+
private final DataFrameTransformConfigUpdate update;
35+
private final String id;
36+
private Boolean deferValidation;
37+
38+
public UpdateDataFrameTransformRequest(DataFrameTransformConfigUpdate update, String id) {
39+
this.update = update;
40+
this.id = id;
41+
}
42+
43+
public DataFrameTransformConfigUpdate getUpdate() {
44+
return update;
45+
}
46+
47+
public Boolean getDeferValidation() {
48+
return deferValidation;
49+
}
50+
51+
public String getId() {
52+
return id;
53+
}
54+
55+
/**
56+
* Indicates if deferrable validations should be skipped until the transform starts
57+
*
58+
* @param deferValidation {@code true} will cause validations to be deferred
59+
*/
60+
public void setDeferValidation(boolean deferValidation) {
61+
this.deferValidation = deferValidation;
62+
}
63+
64+
@Override
65+
public Optional<ValidationException> validate() {
66+
ValidationException validationException = new ValidationException();
67+
if (update == null) {
68+
validationException.addValidationError("put requires a non-null data frame config update object");
69+
}
70+
if (id == null) {
71+
validationException.addValidationError("data frame transform id cannot be null");
72+
}
73+
if (validationException.validationErrors().isEmpty()) {
74+
return Optional.empty();
75+
} else {
76+
return Optional.of(validationException);
77+
}
78+
}
79+
80+
@Override
81+
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
82+
return update.toXContent(builder, params);
83+
}
84+
85+
@Override
86+
public int hashCode() {
87+
return Objects.hash(update, deferValidation, id);
88+
}
89+
90+
@Override
91+
public boolean equals(Object obj) {
92+
if (obj == null) {
93+
return false;
94+
}
95+
if (getClass() != obj.getClass()) {
96+
return false;
97+
}
98+
UpdateDataFrameTransformRequest other = (UpdateDataFrameTransformRequest) obj;
99+
return Objects.equals(update, other.update)
100+
&& Objects.equals(id, other.id)
101+
&& Objects.equals(deferValidation, other.deferValidation);
102+
}
103+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
20+
package org.elasticsearch.client.dataframe;
21+
22+
import org.elasticsearch.client.dataframe.transforms.DataFrameTransformConfig;
23+
import org.elasticsearch.common.xcontent.XContentParser;
24+
25+
import java.util.Objects;
26+
27+
public class UpdateDataFrameTransformResponse {
28+
29+
public static UpdateDataFrameTransformResponse fromXContent(final XContentParser parser) {
30+
return new UpdateDataFrameTransformResponse(DataFrameTransformConfig.PARSER.apply(parser, null));
31+
}
32+
33+
private DataFrameTransformConfig transformConfiguration;
34+
35+
public UpdateDataFrameTransformResponse(DataFrameTransformConfig transformConfiguration) {
36+
this.transformConfiguration = transformConfiguration;
37+
}
38+
39+
public DataFrameTransformConfig getTransformConfiguration() {
40+
return transformConfiguration;
41+
}
42+
43+
@Override
44+
public int hashCode() {
45+
return Objects.hash(transformConfiguration);
46+
}
47+
48+
@Override
49+
public boolean equals(Object other) {
50+
if (this == other) {
51+
return true;
52+
}
53+
54+
if (other == null || getClass() != other.getClass()) {
55+
return false;
56+
}
57+
58+
final UpdateDataFrameTransformResponse that = (UpdateDataFrameTransformResponse) other;
59+
return Objects.equals(this.transformConfiguration, that.transformConfiguration);
60+
}
61+
}

0 commit comments

Comments
 (0)