Skip to content

Commit c48b068

Browse files
committed
Merge branch 'master' into search-remote-migration
* master: [HLRC][ML] Add ML put datafeed API to HLRC (elastic#33603) Update AWS SDK to 1.11.406 in repository-s3 (elastic#30723)
2 parents 80dfc9d + 2eb2313 commit c48b068

26 files changed

+828
-149
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.elasticsearch.client.ml.GetRecordsRequest;
4242
import org.elasticsearch.client.ml.OpenJobRequest;
4343
import org.elasticsearch.client.ml.PostDataRequest;
44+
import org.elasticsearch.client.ml.PutDatafeedRequest;
4445
import org.elasticsearch.client.ml.PutJobRequest;
4546
import org.elasticsearch.client.ml.UpdateJobRequest;
4647
import org.elasticsearch.common.Strings;
@@ -182,6 +183,18 @@ static Request updateJob(UpdateJobRequest updateJobRequest) throws IOException {
182183
return request;
183184
}
184185

186+
static Request putDatafeed(PutDatafeedRequest putDatafeedRequest) throws IOException {
187+
String endpoint = new EndpointBuilder()
188+
.addPathPartAsIs("_xpack")
189+
.addPathPartAsIs("ml")
190+
.addPathPartAsIs("datafeeds")
191+
.addPathPart(putDatafeedRequest.getDatafeed().getId())
192+
.build();
193+
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
194+
request.setEntity(createEntity(putDatafeedRequest, REQUEST_BODY_CONTENT_TYPE));
195+
return request;
196+
}
197+
185198
static Request deleteForecast(DeleteForecastRequest deleteForecastRequest) throws IOException {
186199
String endpoint = new EndpointBuilder()
187200
.addPathPartAsIs("_xpack")

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

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,15 @@
2020

2121
import org.elasticsearch.action.ActionListener;
2222
import org.elasticsearch.action.support.master.AcknowledgedResponse;
23-
import org.elasticsearch.client.ml.DeleteForecastRequest;
24-
import org.elasticsearch.client.ml.ForecastJobRequest;
25-
import org.elasticsearch.client.ml.ForecastJobResponse;
26-
import org.elasticsearch.client.ml.PostDataRequest;
27-
import org.elasticsearch.client.ml.PostDataResponse;
28-
import org.elasticsearch.client.ml.UpdateJobRequest;
2923
import org.elasticsearch.client.ml.CloseJobRequest;
3024
import org.elasticsearch.client.ml.CloseJobResponse;
25+
import org.elasticsearch.client.ml.DeleteForecastRequest;
3126
import org.elasticsearch.client.ml.DeleteJobRequest;
3227
import org.elasticsearch.client.ml.DeleteJobResponse;
3328
import org.elasticsearch.client.ml.FlushJobRequest;
3429
import org.elasticsearch.client.ml.FlushJobResponse;
30+
import org.elasticsearch.client.ml.ForecastJobRequest;
31+
import org.elasticsearch.client.ml.ForecastJobResponse;
3532
import org.elasticsearch.client.ml.GetBucketsRequest;
3633
import org.elasticsearch.client.ml.GetBucketsResponse;
3734
import org.elasticsearch.client.ml.GetCategoriesRequest;
@@ -48,13 +45,19 @@
4845
import org.elasticsearch.client.ml.GetRecordsResponse;
4946
import org.elasticsearch.client.ml.OpenJobRequest;
5047
import org.elasticsearch.client.ml.OpenJobResponse;
48+
import org.elasticsearch.client.ml.PostDataRequest;
49+
import org.elasticsearch.client.ml.PostDataResponse;
50+
import org.elasticsearch.client.ml.PutDatafeedRequest;
51+
import org.elasticsearch.client.ml.PutDatafeedResponse;
5152
import org.elasticsearch.client.ml.PutJobRequest;
5253
import org.elasticsearch.client.ml.PutJobResponse;
54+
import org.elasticsearch.client.ml.UpdateJobRequest;
5355
import org.elasticsearch.client.ml.job.stats.JobStats;
5456

5557
import java.io.IOException;
5658
import java.util.Collections;
5759

60+
5861
/**
5962
* Machine Learning API client wrapper for the {@link RestHighLevelClient}
6063
*
@@ -451,6 +454,44 @@ public void updateJobAsync(UpdateJobRequest request, RequestOptions options, Act
451454
Collections.emptySet());
452455
}
453456

457+
/**
458+
* Creates a new Machine Learning Datafeed
459+
* <p>
460+
* For additional info
461+
* see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-put-datafeed.html">ML PUT datafeed documentation</a>
462+
*
463+
* @param request The PutDatafeedRequest containing the {@link org.elasticsearch.client.ml.datafeed.DatafeedConfig} settings
464+
* @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
465+
* @return PutDatafeedResponse with enclosed {@link org.elasticsearch.client.ml.datafeed.DatafeedConfig} object
466+
* @throws IOException when there is a serialization issue sending the request or receiving the response
467+
*/
468+
public PutDatafeedResponse putDatafeed(PutDatafeedRequest request, RequestOptions options) throws IOException {
469+
return restHighLevelClient.performRequestAndParseEntity(request,
470+
MLRequestConverters::putDatafeed,
471+
options,
472+
PutDatafeedResponse::fromXContent,
473+
Collections.emptySet());
474+
}
475+
476+
/**
477+
* Creates a new Machine Learning Datafeed asynchronously and notifies listener on completion
478+
* <p>
479+
* For additional info
480+
* see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-put-datafeed.html">ML PUT datafeed documentation</a>
481+
*
482+
* @param request The request containing the {@link org.elasticsearch.client.ml.datafeed.DatafeedConfig} settings
483+
* @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
484+
* @param listener Listener to be notified upon request completion
485+
*/
486+
public void putDatafeedAsync(PutDatafeedRequest request, RequestOptions options, ActionListener<PutDatafeedResponse> listener) {
487+
restHighLevelClient.performRequestAsyncAndParseEntity(request,
488+
MLRequestConverters::putDatafeed,
489+
options,
490+
PutDatafeedResponse::fromXContent,
491+
listener,
492+
Collections.emptySet());
493+
}
494+
454495
/**
455496
* Deletes Machine Learning Job Forecasts
456497
*
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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.ml;
20+
21+
import org.elasticsearch.action.ActionRequest;
22+
import org.elasticsearch.action.ActionRequestValidationException;
23+
import org.elasticsearch.client.ml.datafeed.DatafeedConfig;
24+
import org.elasticsearch.common.Strings;
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+
31+
/**
32+
* Request to create a new Machine Learning Datafeed given a {@link DatafeedConfig} configuration
33+
*/
34+
public class PutDatafeedRequest extends ActionRequest implements ToXContentObject {
35+
36+
private final DatafeedConfig datafeed;
37+
38+
/**
39+
* Construct a new PutDatafeedRequest
40+
*
41+
* @param datafeed a {@link DatafeedConfig} configuration to create
42+
*/
43+
public PutDatafeedRequest(DatafeedConfig datafeed) {
44+
this.datafeed = datafeed;
45+
}
46+
47+
public DatafeedConfig getDatafeed() {
48+
return datafeed;
49+
}
50+
51+
@Override
52+
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
53+
return datafeed.toXContent(builder, params);
54+
}
55+
56+
@Override
57+
public boolean equals(Object object) {
58+
if (this == object) {
59+
return true;
60+
}
61+
62+
if (object == null || getClass() != object.getClass()) {
63+
return false;
64+
}
65+
66+
PutDatafeedRequest request = (PutDatafeedRequest) object;
67+
return Objects.equals(datafeed, request.datafeed);
68+
}
69+
70+
@Override
71+
public int hashCode() {
72+
return Objects.hash(datafeed);
73+
}
74+
75+
@Override
76+
public final String toString() {
77+
return Strings.toString(this);
78+
}
79+
80+
@Override
81+
public ActionRequestValidationException validate() {
82+
return null;
83+
}
84+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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.ml;
20+
21+
import org.elasticsearch.client.ml.datafeed.DatafeedConfig;
22+
import org.elasticsearch.common.xcontent.ToXContentObject;
23+
import org.elasticsearch.common.xcontent.XContentBuilder;
24+
import org.elasticsearch.common.xcontent.XContentParser;
25+
26+
import java.io.IOException;
27+
import java.util.Objects;
28+
29+
/**
30+
* Response containing the newly created {@link DatafeedConfig}
31+
*/
32+
public class PutDatafeedResponse implements ToXContentObject {
33+
34+
private DatafeedConfig datafeed;
35+
36+
public static PutDatafeedResponse fromXContent(XContentParser parser) throws IOException {
37+
return new PutDatafeedResponse(DatafeedConfig.PARSER.parse(parser, null).build());
38+
}
39+
40+
PutDatafeedResponse(DatafeedConfig datafeed) {
41+
this.datafeed = datafeed;
42+
}
43+
44+
public DatafeedConfig getResponse() {
45+
return datafeed;
46+
}
47+
48+
@Override
49+
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
50+
datafeed.toXContent(builder, params);
51+
return builder;
52+
}
53+
54+
@Override
55+
public boolean equals(Object object) {
56+
if (this == object) {
57+
return true;
58+
}
59+
if (object == null || getClass() != object.getClass()) {
60+
return false;
61+
}
62+
PutDatafeedResponse response = (PutDatafeedResponse) object;
63+
return Objects.equals(datafeed, response.datafeed);
64+
}
65+
66+
@Override
67+
public int hashCode() {
68+
return Objects.hash(datafeed);
69+
}
70+
}

0 commit comments

Comments
 (0)