Skip to content

Commit

Permalink
[ML][Data Frame] Add support for allow_no_match for endpoints (#43490)
Browse files Browse the repository at this point in the history
* [ML][Data Frame] Add support for allow_no_match parameter in endpoints

Adds support for:
* Get Transforms
* Get Transforms stats
* stop transforms
  • Loading branch information
benwtrent authored Jun 26, 2019
1 parent e737361 commit 9084418
Show file tree
Hide file tree
Showing 28 changed files with 242 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

import static org.elasticsearch.client.RequestConverters.REQUEST_BODY_CONTENT_TYPE;
import static org.elasticsearch.client.RequestConverters.createEntity;
import static org.elasticsearch.client.dataframe.GetDataFrameTransformRequest.ALLOW_NO_MATCH;

final class DataFrameRequestConverters {

Expand Down Expand Up @@ -64,6 +65,9 @@ static Request getDataFrameTransform(GetDataFrameTransformRequest getRequest) {
if (getRequest.getPageParams() != null && getRequest.getPageParams().getSize() != null) {
request.addParameter(PageParams.SIZE.getPreferredName(), getRequest.getPageParams().getSize().toString());
}
if (getRequest.getAllowNoMatch() != null) {
request.addParameter(ALLOW_NO_MATCH, getRequest.getAllowNoMatch().toString());
}
return request;
}

Expand Down Expand Up @@ -91,21 +95,24 @@ static Request startDataFrameTransform(StartDataFrameTransformRequest startReque
}

static Request stopDataFrameTransform(StopDataFrameTransformRequest stopRequest) {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_data_frame", "transforms")
.addPathPart(stopRequest.getId())
.addPathPartAsIs("_stop")
.build();
Request request = new Request(HttpPost.METHOD_NAME, endpoint);
RequestConverters.Params params = new RequestConverters.Params();
if (stopRequest.getWaitForCompletion() != null) {
params.withWaitForCompletion(stopRequest.getWaitForCompletion());
}
if (stopRequest.getTimeout() != null) {
params.withTimeout(stopRequest.getTimeout());
}
request.addParameters(params.asMap());
return request;
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_data_frame", "transforms")
.addPathPart(stopRequest.getId())
.addPathPartAsIs("_stop")
.build();
Request request = new Request(HttpPost.METHOD_NAME, endpoint);
RequestConverters.Params params = new RequestConverters.Params();
if (stopRequest.getWaitForCompletion() != null) {
params.withWaitForCompletion(stopRequest.getWaitForCompletion());
}
if (stopRequest.getTimeout() != null) {
params.withTimeout(stopRequest.getTimeout());
}
if (stopRequest.getAllowNoMatch() != null) {
request.addParameter(ALLOW_NO_MATCH, stopRequest.getAllowNoMatch().toString());
}
request.addParameters(params.asMap());
return request;
}

static Request previewDataFrameTransform(PreviewDataFrameTransformRequest previewRequest) throws IOException {
Expand All @@ -130,6 +137,9 @@ static Request getDataFrameTransformStats(GetDataFrameTransformStatsRequest stat
if (statsRequest.getPageParams() != null && statsRequest.getPageParams().getSize() != null) {
request.addParameter(PageParams.SIZE.getPreferredName(), statsRequest.getPageParams().getSize().toString());
}
if (statsRequest.getAllowNoMatch() != null) {
request.addParameter(ALLOW_NO_MATCH, statsRequest.getAllowNoMatch().toString());
}
return request;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

public class GetDataFrameTransformRequest implements Validatable {

public static final String ALLOW_NO_MATCH = "allow_no_match";
/**
* Helper method to create a request that will get ALL Data Frame Transforms
* @return new {@link GetDataFrameTransformRequest} object for the id "_all"
Expand All @@ -40,6 +41,7 @@ public static GetDataFrameTransformRequest getAllDataFrameTransformsRequest() {

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

public GetDataFrameTransformRequest(String... ids) {
this.ids = Arrays.asList(ids);
Expand All @@ -57,6 +59,14 @@ public void setPageParams(PageParams pageParams) {
this.pageParams = pageParams;
}

public Boolean getAllowNoMatch() {
return allowNoMatch;
}

public void setAllowNoMatch(Boolean allowNoMatch) {
this.allowNoMatch = allowNoMatch;
}

@Override
public Optional<ValidationException> validate() {
if (ids == null || ids.isEmpty()) {
Expand All @@ -70,7 +80,7 @@ public Optional<ValidationException> validate() {

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

@Override
Expand All @@ -83,6 +93,8 @@ public boolean equals(Object obj) {
return false;
}
GetDataFrameTransformRequest other = (GetDataFrameTransformRequest) obj;
return Objects.equals(ids, other.ids) && Objects.equals(pageParams, other.pageParams);
return Objects.equals(ids, other.ids)
&& Objects.equals(pageParams, other.pageParams)
&& Objects.equals(allowNoMatch, other.allowNoMatch);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
public class GetDataFrameTransformStatsRequest implements Validatable {
private final String id;
private PageParams pageParams;
private Boolean allowNoMatch;

public GetDataFrameTransformStatsRequest(String id) {
this.id = id;
Expand All @@ -46,6 +47,14 @@ public void setPageParams(PageParams pageParams) {
this.pageParams = pageParams;
}

public Boolean getAllowNoMatch() {
return allowNoMatch;
}

public void setAllowNoMatch(Boolean allowNoMatch) {
this.allowNoMatch = allowNoMatch;
}

@Override
public Optional<ValidationException> validate() {
if (id == null) {
Expand All @@ -59,7 +68,7 @@ public Optional<ValidationException> validate() {

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

@Override
Expand All @@ -72,6 +81,8 @@ public boolean equals(Object obj) {
return false;
}
GetDataFrameTransformStatsRequest other = (GetDataFrameTransformStatsRequest) obj;
return Objects.equals(id, other.id) && Objects.equals(pageParams, other.pageParams);
return Objects.equals(id, other.id)
&& Objects.equals(pageParams, other.pageParams)
&& Objects.equals(allowNoMatch, other.allowNoMatch);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class StopDataFrameTransformRequest implements Validatable {
private final String id;
private Boolean waitForCompletion;
private TimeValue timeout;
private Boolean allowNoMatch;

public StopDataFrameTransformRequest(String id) {
this.id = id;
Expand Down Expand Up @@ -64,6 +65,14 @@ public TimeValue getTimeout() {
return timeout;
}

public Boolean getAllowNoMatch() {
return allowNoMatch;
}

public void setAllowNoMatch(Boolean allowNoMatch) {
this.allowNoMatch = allowNoMatch;
}

@Override
public Optional<ValidationException> validate() {
if (id == null) {
Expand All @@ -77,7 +86,7 @@ public Optional<ValidationException> validate() {

@Override
public int hashCode() {
return Objects.hash(id, waitForCompletion, timeout);
return Objects.hash(id, waitForCompletion, timeout, allowNoMatch);
}

@Override
Expand All @@ -92,7 +101,8 @@ public boolean equals(Object obj) {
StopDataFrameTransformRequest other = (StopDataFrameTransformRequest) obj;
return Objects.equals(this.id, other.id)
&& Objects.equals(this.waitForCompletion, other.waitForCompletion)
&& Objects.equals(this.timeout, other.timeout);
&& Objects.equals(this.timeout, other.timeout)
&& Objects.equals(this.allowNoMatch, other.allowNoMatch);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import java.util.Collections;
import java.util.List;

import static org.elasticsearch.client.dataframe.GetDataFrameTransformRequest.ALLOW_NO_MATCH;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasEntry;
Expand Down Expand Up @@ -115,7 +116,6 @@ public void testStopDataFrameTransform() {
}
StopDataFrameTransformRequest stopRequest = new StopDataFrameTransformRequest(id, waitForCompletion, timeValue);


Request request = DataFrameRequestConverters.stopDataFrameTransform(stopRequest);
assertEquals(HttpPost.METHOD_NAME, request.getMethod());
assertThat(request.getEndpoint(), equalTo("/_data_frame/transforms/" + stopRequest.getId() + "/_stop"));
Expand All @@ -133,6 +133,11 @@ public void testStopDataFrameTransform() {
} else {
assertFalse(request.getParameters().containsKey("timeout"));
}

assertFalse(request.getParameters().containsKey(ALLOW_NO_MATCH));
stopRequest.setAllowNoMatch(randomBoolean());
request = DataFrameRequestConverters.stopDataFrameTransform(stopRequest);
assertEquals(stopRequest.getAllowNoMatch(), Boolean.parseBoolean(request.getParameters().get(ALLOW_NO_MATCH)));
}

public void testPreviewDataFrameTransform() throws IOException {
Expand All @@ -158,6 +163,7 @@ public void testGetDataFrameTransformStats() {

assertFalse(request.getParameters().containsKey("from"));
assertFalse(request.getParameters().containsKey("size"));
assertFalse(request.getParameters().containsKey(ALLOW_NO_MATCH));

getStatsRequest.setPageParams(new PageParams(0, null));
request = DataFrameRequestConverters.getDataFrameTransformStats(getStatsRequest);
Expand All @@ -172,6 +178,10 @@ public void testGetDataFrameTransformStats() {
getStatsRequest.setPageParams(new PageParams(0, 10));
request = DataFrameRequestConverters.getDataFrameTransformStats(getStatsRequest);
assertThat(request.getParameters(), allOf(hasEntry("from", "0"), hasEntry("size", "10")));

getStatsRequest.setAllowNoMatch(false);
request = DataFrameRequestConverters.getDataFrameTransformStats(getStatsRequest);
assertThat(request.getParameters(), hasEntry("allow_no_match", "false"));
}

public void testGetDataFrameTransform() {
Expand All @@ -183,6 +193,7 @@ public void testGetDataFrameTransform() {

assertFalse(request.getParameters().containsKey("from"));
assertFalse(request.getParameters().containsKey("size"));
assertFalse(request.getParameters().containsKey(ALLOW_NO_MATCH));

getRequest.setPageParams(new PageParams(0, null));
request = DataFrameRequestConverters.getDataFrameTransform(getRequest);
Expand All @@ -197,6 +208,10 @@ public void testGetDataFrameTransform() {
getRequest.setPageParams(new PageParams(0, 10));
request = DataFrameRequestConverters.getDataFrameTransform(getRequest);
assertThat(request.getParameters(), allOf(hasEntry("from", "0"), hasEntry("size", "10")));

getRequest.setAllowNoMatch(false);
request = DataFrameRequestConverters.getDataFrameTransform(getRequest);
assertThat(request.getParameters(), hasEntry("allow_no_match", "false"));
}

public void testGetDataFrameTransform_givenMulitpleIds() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ public void testStartStop() throws IOException, InterruptedException {
// tag::stop-data-frame-transform-request-options
request.setWaitForCompletion(Boolean.TRUE); // <1>
request.setTimeout(TimeValue.timeValueSeconds(30)); // <2>
request.setAllowNoMatch(true); // <3>
// end::stop-data-frame-transform-request-options

// tag::stop-data-frame-transform-execute
Expand Down Expand Up @@ -506,6 +507,11 @@ public void testGetStats() throws IOException, InterruptedException {
new GetDataFrameTransformStatsRequest(id); // <1>
// end::get-data-frame-transform-stats-request

// tag::get-data-frame-transform-stats-request-options
request.setPageParams(new PageParams(0, 100)); // <1>
request.setAllowNoMatch(true); // <2>
// end::get-data-frame-transform-stats-request-params

{
// tag::get-data-frame-transform-stats-execute
GetDataFrameTransformStatsResponse response =
Expand Down Expand Up @@ -597,6 +603,7 @@ public void testGetDataFrameTransform() throws IOException, InterruptedException

// tag::get-data-frame-transform-request-options
request.setPageParams(new PageParams(0, 100)); // <1>
request.setAllowNoMatch(true); // <2>
// end::get-data-frame-transform-request-options

// tag::get-data-frame-transform-execute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ include-tagged::{doc-tests-file}[{api}-request-options]
<1> The page parameters `from` and `size`. `from` specifies the number of
{dataframe-transforms} to skip. `size` specifies the maximum number of
{dataframe-transforms} to get. Defaults to `0` and `100` respectively.
<2> Whether to ignore if a wildcard expression matches no transforms.


include::../execution.asciidoc[]
Expand Down
13 changes: 13 additions & 0 deletions docs/java-rest/high-level/dataframe/get_data_frame_stats.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ include-tagged::{doc-tests-file}[{api}-request]
--------------------------------------------------
<1> Constructing a new GET Stats request referencing an existing {dataframe-transform}

==== Optional Arguments

The following arguments are optional.

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests-file}[{api}-request-options]
--------------------------------------------------
<1> The page parameters `from` and `size`. `from` specifies the number of data frame transform stats to skip.
`size` specifies the maximum number of data frame transform stats to get.
Defaults to `0` and `100` respectively.
<2> Whether to ignore if a wildcard expression matches no transforms.


include::../execution.asciidoc[]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ include-tagged::{doc-tests-file}[{api}-request-options]
--------------------------------------------------
<1> If true wait for the data frame task to stop before responding
<2> Controls the amount of time to wait until the {dataframe-job} stops.
<3> Whether to ignore if a wildcard expression matches no transforms.

include::../execution.asciidoc[]

Expand Down
6 changes: 6 additions & 0 deletions docs/reference/data-frames/apis/get-transform-stats.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,19 @@ Retrieves usage information for {dataframe-transforms}.
specify one of these options, the API returns information for all
{dataframe-transforms}.

==== Query Parameters

`from`::
(integer) Skips the specified number of {dataframe-transforms}. The
default value is `0`.

`size`::
(integer) Specifies the maximum number of {dataframe-transforms} to obtain. The default value is `100`.

`allow_no_match`::
(boolean) Whether to ignore if a wildcard expression matches no data frame transforms.
This includes `_all` string or when no transforms have been specified. The default is `true`.

==== Results

The API returns the following information:
Expand Down
6 changes: 6 additions & 0 deletions docs/reference/data-frames/apis/get-transform.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,19 @@ Retrieves configuration information for {dataframe-transforms}.
specify one of these options, the API returns information for all
{dataframe-transforms}.

==== Query Parameters

`from`::
(integer) Skips the specified number of {dataframe-transforms}. The
default value is `0`.

`size`::
(integer) Specifies the maximum number of {dataframe-transforms} to obtain. The default value is `100`.

`allow_no_match`::
(boolean) Whether to ignore if a wildcard expression matches no data frame transforms.
This includes `_all` string or when no transforms have been specified. The default is `true`.

==== Results

The API returns the following information:
Expand Down
6 changes: 5 additions & 1 deletion docs/reference/data-frames/apis/stop-transform.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ All {dataframe-transforms} can be stopped by using `_all` or `*` as the `<data_f
timeout exception is thrown, the stop request is still processing and
eventually moves the transform to `STOPPED`. The timeout simply means the API
call itself timed out while waiting for the status change. Defaults to `30s`


`allow_no_match`::
(boolean) Whether to ignore if a wildcard expression matches no data frame transforms.
This includes `_all` string or when no transforms have been specified. The default is `true`.

//==== Request Body
==== Authorization

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public final class DataFrameField {
public static final ParseField TIME_BASED_SYNC = new ParseField("time");
public static final ParseField DELAY = new ParseField("delay");

public static final ParseField ALLOW_NO_MATCH = new ParseField("allow_no_match");
/**
* Fields for checkpointing
*/
Expand Down
Loading

0 comments on commit 9084418

Please sign in to comment.