-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HLRC: Adding Update datafeed API #34882
Changes from 2 commits
570b57a
7377587
33f089c
6a1d4be
f78f32d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,7 @@ | |
import org.elasticsearch.client.ml.StartDatafeedResponse; | ||
import org.elasticsearch.client.ml.StopDatafeedRequest; | ||
import org.elasticsearch.client.ml.StopDatafeedResponse; | ||
import org.elasticsearch.client.ml.UpdateDatafeedRequest; | ||
import org.elasticsearch.client.ml.UpdateJobRequest; | ||
import org.elasticsearch.client.ml.job.stats.JobStats; | ||
|
||
|
@@ -494,6 +495,46 @@ public void putDatafeedAsync(PutDatafeedRequest request, RequestOptions options, | |
Collections.emptySet()); | ||
} | ||
|
||
/** | ||
* Updated a Machine Learning Datafeed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo: Updated -> Updates |
||
* <p> | ||
* For additional info | ||
* see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-update-datafeed.html"> | ||
* ML Update datafeed documentation</a> | ||
* | ||
* @param request The UpdateDatafeedRequest containing the {@link org.elasticsearch.client.ml.datafeed.DatafeedUpdate} settings | ||
* @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized | ||
* @return PutDatafeedResponse with enclosed, updated {@link org.elasticsearch.client.ml.datafeed.DatafeedConfig} object | ||
* @throws IOException when there is a serialization issue sending the request or receiving the response | ||
*/ | ||
public PutDatafeedResponse updateDatafeed(UpdateDatafeedRequest request, RequestOptions options) throws IOException { | ||
return restHighLevelClient.performRequestAndParseEntity(request, | ||
MLRequestConverters::updateDatafeed, | ||
options, | ||
PutDatafeedResponse::fromXContent, | ||
Collections.emptySet()); | ||
} | ||
|
||
/** | ||
* Updates a Machine Learning Datafeed asynchronously and notifies listener on completion | ||
* <p> | ||
* For additional info | ||
* see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-update-datafeed.html"> | ||
* ML Update datafeed documentation</a> | ||
* | ||
* @param request The request containing the {@link org.elasticsearch.client.ml.datafeed.DatafeedUpdate} settings | ||
* @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized | ||
* @param listener Listener to be notified upon request completion | ||
*/ | ||
public void updateDatafeedAsync(UpdateDatafeedRequest request, RequestOptions options, ActionListener<PutDatafeedResponse> listener) { | ||
restHighLevelClient.performRequestAsyncAndParseEntity(request, | ||
MLRequestConverters::updateDatafeed, | ||
options, | ||
PutDatafeedResponse::fromXContent, | ||
listener, | ||
Collections.emptySet()); | ||
} | ||
|
||
/** | ||
* Gets one or more Machine Learning datafeed configuration info. | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.elasticsearch.client.ml; | ||
|
||
import org.elasticsearch.action.ActionRequest; | ||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.client.ml.datafeed.DatafeedUpdate; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Updates a {@link org.elasticsearch.client.ml.datafeed.DatafeedConfig} with the passed {@link DatafeedUpdate} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment implies this class is the action. Reword to suit it is a request? |
||
* settings | ||
*/ | ||
public class UpdateDatafeedRequest extends ActionRequest implements ToXContentObject { | ||
|
||
private final DatafeedUpdate update; | ||
|
||
public UpdateDatafeedRequest(DatafeedUpdate update) { | ||
this.update = update; | ||
} | ||
|
||
public DatafeedUpdate getDatafeedUpdate() { | ||
return update; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
return update.toXContent(builder, params); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
|
||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
UpdateDatafeedRequest that = (UpdateDatafeedRequest) o; | ||
return Objects.equals(update, that.update); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(update); | ||
} | ||
|
||
@Override | ||
public final String toString() { | ||
return Strings.toString(this); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,12 +64,14 @@ | |
import org.elasticsearch.client.ml.StartDatafeedResponse; | ||
import org.elasticsearch.client.ml.StopDatafeedRequest; | ||
import org.elasticsearch.client.ml.StopDatafeedResponse; | ||
import org.elasticsearch.client.ml.UpdateDatafeedRequest; | ||
import org.elasticsearch.client.ml.UpdateJobRequest; | ||
import org.elasticsearch.client.ml.calendars.Calendar; | ||
import org.elasticsearch.client.ml.calendars.CalendarTests; | ||
import org.elasticsearch.client.ml.datafeed.DatafeedConfig; | ||
import org.elasticsearch.client.ml.datafeed.DatafeedState; | ||
import org.elasticsearch.client.ml.datafeed.DatafeedStats; | ||
import org.elasticsearch.client.ml.datafeed.DatafeedUpdate; | ||
import org.elasticsearch.client.ml.job.config.AnalysisConfig; | ||
import org.elasticsearch.client.ml.job.config.DataDescription; | ||
import org.elasticsearch.client.ml.job.config.Detector; | ||
|
@@ -357,6 +359,33 @@ public void testPutDatafeed() throws Exception { | |
assertThat(createdDatafeed.getIndices(), equalTo(datafeedConfig.getIndices())); | ||
} | ||
|
||
public void testUpdateDatafeed() throws Exception { | ||
String jobId = randomValidJobId(); | ||
Job job = buildJob(jobId); | ||
MachineLearningClient machineLearningClient = highLevelClient().machineLearning(); | ||
execute(new PutJobRequest(job), machineLearningClient::putJob, machineLearningClient::putJobAsync); | ||
|
||
String datafeedId = "datafeed-" + jobId; | ||
DatafeedConfig datafeedConfig = DatafeedConfig.builder(datafeedId, jobId).setIndices("some_data_index").build(); | ||
|
||
PutDatafeedResponse response = machineLearningClient.putDatafeed(new PutDatafeedRequest(datafeedConfig), RequestOptions.DEFAULT); | ||
|
||
DatafeedConfig createdDatafeed = response.getResponse(); | ||
assertThat(createdDatafeed.getId(), equalTo(datafeedId)); | ||
assertThat(createdDatafeed.getIndices(), equalTo(datafeedConfig.getIndices())); | ||
|
||
DatafeedUpdate datafeedUpdate = DatafeedUpdate.builder(datafeedId).setIndices("some_other_data_index").setScrollSize(10).build(); | ||
|
||
response = execute(new UpdateDatafeedRequest(datafeedUpdate), | ||
machineLearningClient::updateDatafeed, | ||
machineLearningClient::updateDatafeedAsync); | ||
|
||
DatafeedConfig updatedDatafeed= response.getResponse(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: missing space before equals |
||
assertThat(datafeedUpdate.getId(), equalTo(updatedDatafeed.getId())); | ||
assertThat(datafeedUpdate.getIndices(), equalTo(updatedDatafeed.getIndices())); | ||
assertThat(datafeedUpdate.getScrollSize(), equalTo(updatedDatafeed.getScrollSize())); | ||
} | ||
|
||
public void testGetDatafeed() throws Exception { | ||
String jobId1 = "test-get-datafeed-job-1"; | ||
String jobId2 = "test-get-datafeed-job-2"; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.elasticsearch.client.ml; | ||
|
||
import org.elasticsearch.client.ml.datafeed.DatafeedUpdate; | ||
import org.elasticsearch.client.ml.datafeed.DatafeedUpdateTests; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.test.AbstractXContentTestCase; | ||
|
||
|
||
public class UpdateDatafeedRequestTests extends AbstractXContentTestCase<UpdateDatafeedRequest> { | ||
|
||
@Override | ||
protected UpdateDatafeedRequest createTestInstance() { | ||
return new UpdateDatafeedRequest(DatafeedUpdateTests.createRandom()); | ||
} | ||
|
||
@Override | ||
protected UpdateDatafeedRequest doParseInstance(XContentParser parser) { | ||
return new UpdateDatafeedRequest(DatafeedUpdate.PARSER.apply(parser, null).build()); | ||
} | ||
|
||
@Override | ||
protected boolean supportsUnknownFields() { | ||
return false; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first empty part seems redundant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
definitely :D copy paste error