Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
174acb0
Draft of HLRC for DataFrame analytics (data format).
Apr 12, 2019
f70b0c3
Implement data model for HLRC.
Apr 23, 2019
2dfb33c
* Fix typo: analysed -> analyzed
Apr 23, 2019
2cb5971
* Fix spelling: analysed -> analyzed
Apr 23, 2019
245879a
Revert unintentional changes.
Apr 23, 2019
c6edb06
Small fixes.
Apr 23, 2019
14c5a74
Apply fixes resulting from code review.
Apr 23, 2019
fd3ad66
* Add MlDataFrameAnalysisNamedXContentProvider.java so that the outli…
Apr 24, 2019
6083b8a
Fixed unit tests.
Apr 24, 2019
42b2cbb
Implementation of Get/Put/Delete methods on client side together with…
Apr 24, 2019
ec81640
Fix licence.
Apr 24, 2019
f641a0c
Merge branch 'df-analyticsconfig' into df-analyticsconfig-methods
Apr 24, 2019
87d3b3f
Fix style issues.
Apr 24, 2019
fbcef50
Draft of HLRC for DataFrame analytics (data format).
Apr 12, 2019
c51834a
Implement data model for HLRC.
Apr 23, 2019
7f62052
* Fix typo: analysed -> analyzed
Apr 23, 2019
73ed02e
* Fix spelling: analysed -> analyzed
Apr 23, 2019
649baab
Revert unintentional changes.
Apr 23, 2019
5e06f47
Small fixes.
Apr 23, 2019
76e5004
Apply fixes resulting from code review.
Apr 23, 2019
73c570e
* Add MlDataFrameAnalysisNamedXContentProvider.java so that the outli…
Apr 24, 2019
4c24f1f
Fixed unit tests.
Apr 24, 2019
29f222d
Fix licence.
Apr 24, 2019
9fa1a08
Merge branch 'df-analyticsconfig' into df-analyticsconfig-methods
Apr 24, 2019
dd1b0b6
Implement more integration tests.
Apr 25, 2019
b4c3653
* Add constructors with less parameters where applicable
Apr 25, 2019
2b5d9c3
Merge branch 'df-analyticsconfig' into df-analyticsconfig-methods
Apr 25, 2019
6bd4e4a
* Implement Request converter tests for DataFrameAnalytics requests.
Apr 25, 2019
987f1e9
Merge branch 'feature-ml-data-frame-analytics' into df-analyticsconfi…
Apr 25, 2019
fd586b1
Use PageParams in GetDataFrameAnalyticsRequest.
Apr 25, 2019
a888876
Make static field access unqualified.
Apr 25, 2019
ad52eb6
Resolve issues resulting from code review.
Apr 26, 2019
988d5e7
Fix style.
Apr 26, 2019
a0f0c7e
Fix RestHighLevelClientTests.testProvidedNamedXContents test
Apr 26, 2019
4197fd2
Add test snippet for GET pagination
Apr 26, 2019
f164c23
Fix style
Apr 26, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.elasticsearch.client.ml.DeleteCalendarEventRequest;
import org.elasticsearch.client.ml.DeleteCalendarJobRequest;
import org.elasticsearch.client.ml.DeleteCalendarRequest;
import org.elasticsearch.client.ml.DeleteDataFrameAnalyticsRequest;
import org.elasticsearch.client.ml.DeleteDatafeedRequest;
import org.elasticsearch.client.ml.DeleteExpiredDataRequest;
import org.elasticsearch.client.ml.DeleteFilterRequest;
Expand All @@ -44,6 +45,7 @@
import org.elasticsearch.client.ml.GetCalendarEventsRequest;
import org.elasticsearch.client.ml.GetCalendarsRequest;
import org.elasticsearch.client.ml.GetCategoriesRequest;
import org.elasticsearch.client.ml.GetDataFrameAnalyticsRequest;
import org.elasticsearch.client.ml.GetDatafeedRequest;
import org.elasticsearch.client.ml.GetDatafeedStatsRequest;
import org.elasticsearch.client.ml.GetFiltersRequest;
Expand All @@ -60,6 +62,7 @@
import org.elasticsearch.client.ml.PreviewDatafeedRequest;
import org.elasticsearch.client.ml.PutCalendarJobRequest;
import org.elasticsearch.client.ml.PutCalendarRequest;
import org.elasticsearch.client.ml.PutDataFrameAnalyticsRequest;
import org.elasticsearch.client.ml.PutDatafeedRequest;
import org.elasticsearch.client.ml.PutFilterRequest;
import org.elasticsearch.client.ml.PutJobRequest;
Expand Down Expand Up @@ -576,6 +579,49 @@ static Request deleteCalendarEvent(DeleteCalendarEventRequest deleteCalendarEven
return new Request(HttpDelete.METHOD_NAME, endpoint);
}

static Request putDataFrameAnalytics(PutDataFrameAnalyticsRequest putRequest) throws IOException {
String endpoint = new EndpointBuilder()
.addPathPartAsIs("_ml")
.addPathPartAsIs("data_frame")
.addPathPartAsIs("analytics")
.addPathPart(putRequest.getConfig().getId())
.build();
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
request.setEntity(createEntity(putRequest, REQUEST_BODY_CONTENT_TYPE));
return request;
}

static Request getDataFrameAnalytics(GetDataFrameAnalyticsRequest getRequest) {
String endpoint = new EndpointBuilder()
.addPathPartAsIs("_ml")
.addPathPartAsIs("data_frame")
.addPathPartAsIs("analytics")
.addPathPart(Strings.collectionToCommaDelimitedString(getRequest.getIds()))
.build();
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
RequestConverters.Params params = new RequestConverters.Params(request);
if (getRequest.getPageParams() != null) {
PageParams pageParams = getRequest.getPageParams();
if (pageParams.getFrom() != null) {
params.putParam(PageParams.FROM.getPreferredName(), pageParams.getFrom().toString());
}
if (pageParams.getSize() != null) {
params.putParam(PageParams.SIZE.getPreferredName(), pageParams.getSize().toString());
}
}
return request;
}

static Request deleteDataFrameAnalytics(DeleteDataFrameAnalyticsRequest deleteRequest) {
String endpoint = new EndpointBuilder()
.addPathPartAsIs("_ml")
.addPathPartAsIs("data_frame")
.addPathPartAsIs("analytics")
.addPathPart(deleteRequest.getId())
.build();
return new Request(HttpDelete.METHOD_NAME, endpoint);
}

static Request putFilter(PutFilterRequest putFilterRequest) throws IOException {
String endpoint = new EndpointBuilder()
.addPathPartAsIs("_ml")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.elasticsearch.client.ml.DeleteCalendarEventRequest;
import org.elasticsearch.client.ml.DeleteCalendarJobRequest;
import org.elasticsearch.client.ml.DeleteCalendarRequest;
import org.elasticsearch.client.ml.DeleteDataFrameAnalyticsRequest;
import org.elasticsearch.client.ml.DeleteDatafeedRequest;
import org.elasticsearch.client.ml.DeleteExpiredDataRequest;
import org.elasticsearch.client.ml.DeleteExpiredDataResponse;
Expand All @@ -47,6 +48,8 @@
import org.elasticsearch.client.ml.GetCalendarsResponse;
import org.elasticsearch.client.ml.GetCategoriesRequest;
import org.elasticsearch.client.ml.GetCategoriesResponse;
import org.elasticsearch.client.ml.GetDataFrameAnalyticsRequest;
import org.elasticsearch.client.ml.GetDataFrameAnalyticsResponse;
import org.elasticsearch.client.ml.GetDatafeedRequest;
import org.elasticsearch.client.ml.GetDatafeedResponse;
import org.elasticsearch.client.ml.GetDatafeedStatsRequest;
Expand Down Expand Up @@ -78,6 +81,8 @@
import org.elasticsearch.client.ml.PutCalendarJobRequest;
import org.elasticsearch.client.ml.PutCalendarRequest;
import org.elasticsearch.client.ml.PutCalendarResponse;
import org.elasticsearch.client.ml.PutDataFrameAnalyticsRequest;
import org.elasticsearch.client.ml.PutDataFrameAnalyticsResponse;
import org.elasticsearch.client.ml.PutDatafeedRequest;
import org.elasticsearch.client.ml.PutDatafeedResponse;
import org.elasticsearch.client.ml.PutFilterRequest;
Expand Down Expand Up @@ -1877,4 +1882,128 @@ public void setUpgradeModeAsync(SetUpgradeModeRequest request, RequestOptions op
listener,
Collections.emptySet());
}

/**
* Creates a new Data Frame Analytics config
* <p>
* For additional info
* see <a href="https://www.TODO.com">PUT Data Frame Analytics documentation</a>
*
* @param request The {@link PutDataFrameAnalyticsRequest} containing the
* {@link org.elasticsearch.client.ml.dataframe.DataFrameAnalyticsConfig}
* @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return The {@link PutDataFrameAnalyticsResponse} containing the created
* {@link org.elasticsearch.client.ml.dataframe.DataFrameAnalyticsConfig}
* @throws IOException when there is a serialization issue sending the request or receiving the response
*/
public PutDataFrameAnalyticsResponse putDataFrameAnalytics(PutDataFrameAnalyticsRequest request,
RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(request,
MLRequestConverters::putDataFrameAnalytics,
options,
PutDataFrameAnalyticsResponse::fromXContent,
Collections.emptySet());
}

/**
* Creates a new Data Frame Analytics config asynchronously and notifies listener upon completion
* <p>
* For additional info
* see <a href="https://www.TODO.com">PUT Data Frame Analytics documentation</a>
*
* @param request The {@link PutDataFrameAnalyticsRequest} containing the
* {@link org.elasticsearch.client.ml.dataframe.DataFrameAnalyticsConfig}
* @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 putDataFrameAnalyticsAsync(PutDataFrameAnalyticsRequest request, RequestOptions options,
ActionListener<PutDataFrameAnalyticsResponse> listener) {
restHighLevelClient.performRequestAsyncAndParseEntity(request,
MLRequestConverters::putDataFrameAnalytics,
options,
PutDataFrameAnalyticsResponse::fromXContent,
listener,
Collections.emptySet());
}

/**
* Gets a single or multiple Data Frame Analytics configs
* <p>
* For additional info
* see <a href="https://www.TODO.com">GET Data Frame Analytics documentation</a>
*
* @param request The {@link GetDataFrameAnalyticsRequest}
* @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return {@link GetDataFrameAnalyticsResponse} response object containing the
* {@link org.elasticsearch.client.ml.dataframe.DataFrameAnalyticsConfig} objects
*/
public GetDataFrameAnalyticsResponse getDataFrameAnalytics(GetDataFrameAnalyticsRequest request,
RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(request,
MLRequestConverters::getDataFrameAnalytics,
options,
GetDataFrameAnalyticsResponse::fromXContent,
Collections.emptySet());
}

/**
* Gets a single or multiple Data Frame Analytics configs asynchronously and notifies listener upon completion
* <p>
* For additional info
* see <a href="https://www.TODO.com">GET Data Frame Analytics documentation</a>
*
* @param request The {@link GetDataFrameAnalyticsRequest}
* @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 getDataFrameAnalyticsAsync(GetDataFrameAnalyticsRequest request, RequestOptions options,
ActionListener<GetDataFrameAnalyticsResponse> listener) {
restHighLevelClient.performRequestAsyncAndParseEntity(request,
MLRequestConverters::getDataFrameAnalytics,
options,
GetDataFrameAnalyticsResponse::fromXContent,
listener,
Collections.emptySet());
}


/**
* Deletes the given Data Frame Analytics config
* <p>
* For additional info
* see <a href="https://www.TODO.com">DELETE Data Frame Analytics documentation</a>
*
* @param request The {@link DeleteDataFrameAnalyticsRequest}
* @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return action acknowledgement
* @throws IOException when there is a serialization issue sending the request or receiving the response
*/
public AcknowledgedResponse deleteDataFrameAnalytics(DeleteDataFrameAnalyticsRequest request,
RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(request,
MLRequestConverters::deleteDataFrameAnalytics,
options,
AcknowledgedResponse::fromXContent,
Collections.emptySet());
}

/**
* Deletes the given Data Frame Analytics config asynchronously and notifies listener upon completion
* <p>
* For additional info
* see <a href="https://www.TODO.com">DELETE Data Frame Analytics documentation</a>
*
* @param request The {@link DeleteDataFrameAnalyticsRequest}
* @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 deleteDataFrameAnalyticsAsync(DeleteDataFrameAnalyticsRequest request, RequestOptions options,
ActionListener<AcknowledgedResponse> listener) {
restHighLevelClient.performRequestAsyncAndParseEntity(request,
MLRequestConverters::deleteDataFrameAnalytics,
options,
AcknowledgedResponse::fromXContent,
listener,
Collections.emptySet());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
* Encapsulates an accumulation of validation errors
*/
public class ValidationException extends IllegalArgumentException {

public static ValidationException withError(String error) {
ValidationException e = new ValidationException();
e.addValidationError(error);
return e;
}

private final List<String> validationErrors = new ArrayList<>();

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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.Validatable;
import org.elasticsearch.client.ValidationException;

import java.util.Objects;
import java.util.Optional;

/**
* Request to delete a data frame analytics config
*/
public class DeleteDataFrameAnalyticsRequest implements Validatable {

private final String id;

public DeleteDataFrameAnalyticsRequest(String id) {
this.id = id;
}

public String getId() {
return id;
}

@Override
public Optional<ValidationException> validate() {
if (id == null) {
return Optional.of(ValidationException.withError("data frame analytics id must not be null"));
}
return Optional.empty();
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

DeleteDataFrameAnalyticsRequest other = (DeleteDataFrameAnalyticsRequest) o;
return Objects.equals(id, other.id);
}

@Override
public int hashCode() {
return Objects.hash(id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* 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.Validatable;
import org.elasticsearch.client.ValidationException;
import org.elasticsearch.client.ml.job.util.PageParams;
import org.elasticsearch.common.Nullable;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

public class GetDataFrameAnalyticsRequest implements Validatable {

private final List<String> ids;
private PageParams pageParams;

/**
* Helper method to create a request that will get ALL Data Frame Analytics
* @return new {@link GetDataFrameAnalyticsRequest} object for the id "_all"
*/
public static GetDataFrameAnalyticsRequest getAllDataFrameAnalyticsRequest() {
return new GetDataFrameAnalyticsRequest("_all");
}

public GetDataFrameAnalyticsRequest(String... ids) {
this.ids = Arrays.asList(ids);
}

public List<String> getIds() {
return ids;
}

public PageParams getPageParams() {
return pageParams;
}

public void setPageParams(@Nullable PageParams pageParams) {
this.pageParams = pageParams;
}

@Override
public Optional<ValidationException> validate() {
if (ids == null || ids.isEmpty()) {
return Optional.of(ValidationException.withError("data frame analytics id must not be null"));
}
return Optional.empty();
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

GetDataFrameAnalyticsRequest other = (GetDataFrameAnalyticsRequest) o;
return Objects.equals(ids, other.ids)
&& Objects.equals(pageParams, other.pageParams);
}

@Override
public int hashCode() {
return Objects.hash(ids, pageParams);
}
}
Loading