Skip to content
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

[ML] adding for_export flag for ml plugin GET resource APIs #63092

Merged
merged 6 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -121,7 +121,10 @@ static Request getJob(GetJobRequest getJobRequest) {

RequestConverters.Params params = new RequestConverters.Params();
if (getJobRequest.getAllowNoMatch() != null) {
params.putParam("allow_no_match", Boolean.toString(getJobRequest.getAllowNoMatch()));
params.putParam(GetJobRequest.ALLOW_NO_MATCH.getPreferredName(), Boolean.toString(getJobRequest.getAllowNoMatch()));
}
if (getJobRequest.getForExport() != null) {
params.putParam(GetJobRequest.FOR_EXPORT, Boolean.toString(getJobRequest.getForExport()));
}
request.addParameters(params.asMap());
return request;
Expand Down Expand Up @@ -270,6 +273,9 @@ static Request getDatafeed(GetDatafeedRequest getDatafeedRequest) {
params.putParam(GetDatafeedRequest.ALLOW_NO_MATCH.getPreferredName(),
Boolean.toString(getDatafeedRequest.getAllowNoMatch()));
}
if (getDatafeedRequest.getForExport() != null) {
params.putParam(GetDatafeedRequest.FOR_EXPORT, Boolean.toString(getDatafeedRequest.getForExport()));
}
request.addParameters(params.asMap());
return request;
}
Expand Down Expand Up @@ -645,7 +651,10 @@ static Request getDataFrameAnalytics(GetDataFrameAnalyticsRequest getRequest) {
}
}
if (getRequest.getAllowNoMatch() != null) {
params.putParam(GetDataFrameAnalyticsRequest.ALLOW_NO_MATCH.getPreferredName(), Boolean.toString(getRequest.getAllowNoMatch()));
params.putParam(GetDataFrameAnalyticsRequest.ALLOW_NO_MATCH, Boolean.toString(getRequest.getAllowNoMatch()));
}
if (getRequest.getForExport() != null) {
params.putParam(GetDataFrameAnalyticsRequest.FOR_EXPORT, Boolean.toString(getRequest.getForExport()));
}
request.addParameters(params.asMap());
return request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.elasticsearch.client.ValidationException;
import org.elasticsearch.client.core.PageParams;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.ParseField;

import java.util.Arrays;
import java.util.List;
Expand All @@ -32,11 +31,13 @@

public class GetDataFrameAnalyticsRequest implements Validatable {

public static final ParseField ALLOW_NO_MATCH = new ParseField("allow_no_match");
public static final String ALLOW_NO_MATCH = "allow_no_match";
public static final String FOR_EXPORT = "for_export";

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

/**
* Helper method to create a request that will get ALL Data Frame Analytics
Expand All @@ -58,6 +59,22 @@ public Boolean getAllowNoMatch() {
return allowNoMatch;
}

/**
* Setting this flag to `true` removes certain fields from the configuration on retrieval.
*
* This is useful when getting the configuration and wanting to put it in another cluster.
*
* Default value is false.
* @param forExport Boolean value indicating if certain fields should be removed
*/
public void setForExport(boolean forExport) {
this.forExport = forExport;
}

public Boolean getForExport() {
return forExport;
}

/**
* Whether to ignore if a wildcard expression matches no data frame analytics.
*
Expand Down Expand Up @@ -94,11 +111,12 @@ public boolean equals(Object o) {
GetDataFrameAnalyticsRequest other = (GetDataFrameAnalyticsRequest) o;
return Objects.equals(ids, other.ids)
&& Objects.equals(allowNoMatch, other.allowNoMatch)
&& Objects.equals(forExport, other.forExport)
&& Objects.equals(pageParams, other.pageParams);
}

@Override
public int hashCode() {
return Objects.hash(ids, allowNoMatch, pageParams);
return Objects.hash(ids, allowNoMatch, forExport, pageParams);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ public class GetDatafeedRequest implements Validatable, ToXContentObject {

public static final ParseField DATAFEED_IDS = new ParseField("datafeed_ids");
public static final ParseField ALLOW_NO_MATCH = new ParseField("allow_no_match");
public static final String FOR_EXPORT = "for_export";

private static final String ALL_DATAFEEDS = "_all";
private final List<String> datafeedIds;
private Boolean allowNoMatch;
private Boolean forExport;

@SuppressWarnings("unchecked")
public static final ConstructingObjectParser<GetDatafeedRequest, Void> PARSER = new ConstructingObjectParser<>(
Expand Down Expand Up @@ -100,9 +102,25 @@ public Boolean getAllowNoMatch() {
return allowNoMatch;
}

/**
* Setting this flag to `true` removes certain fields from the configuration on retrieval.
*
* This is useful when getting the configuration and wanting to put it in another cluster.
*
* Default value is false.
* @param forExport Boolean value indicating if certain fields should be removed
*/
public void setForExport(boolean forExport) {
this.forExport = forExport;
}

public Boolean getForExport() {
return forExport;
}

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

@Override
Expand All @@ -117,7 +135,8 @@ public boolean equals(Object other) {

GetDatafeedRequest that = (GetDatafeedRequest) other;
return Objects.equals(datafeedIds, that.datafeedIds) &&
Objects.equals(allowNoMatch, that.allowNoMatch);
Objects.equals(allowNoMatch, that.allowNoMatch) &&
Objects.equals(forExport, that.forExport);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ public class GetJobRequest implements Validatable, ToXContentObject {

public static final ParseField JOB_IDS = new ParseField("job_ids");
public static final ParseField ALLOW_NO_MATCH = new ParseField("allow_no_match");
public static final String FOR_EXPORT = "for_export";

private static final String ALL_JOBS = "_all";
private final List<String> jobIds;
private Boolean allowNoMatch;
private Boolean forExport;

@SuppressWarnings("unchecked")
public static final ConstructingObjectParser<GetJobRequest, Void> PARSER = new ConstructingObjectParser<>(
Expand Down Expand Up @@ -100,9 +102,25 @@ public Boolean getAllowNoMatch() {
return allowNoMatch;
}

/**
* Setting this flag to `true` removes certain fields from the configuration on retrieval.
*
* This is useful when getting the configuration and wanting to put it in another cluster.
*
* Default value is false.
* @param forExport Boolean value indicating if certain fields should be removed
*/
public void setForExport(boolean forExport) {
this.forExport = forExport;
}

public Boolean getForExport() {
return forExport;
}

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

@Override
Expand All @@ -117,6 +135,7 @@ public boolean equals(Object other) {

GetJobRequest that = (GetJobRequest) other;
return Objects.equals(jobIds, that.jobIds) &&
Objects.equals(forExport, that.forExport) &&
Objects.equals(allowNoMatch, that.allowNoMatch);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ public void testGetJob() throws Exception {
// tag::get-job-request
GetJobRequest request = new GetJobRequest("get-machine-learning-job1", "get-machine-learning-job*"); // <1>
request.setAllowNoMatch(true); // <2>
request.setForExport(false); // <3>
// end::get-job-request

// tag::get-job-execute
Expand Down Expand Up @@ -836,6 +837,7 @@ public void testGetDatafeed() throws Exception {
// tag::get-datafeed-request
GetDatafeedRequest request = new GetDatafeedRequest(datafeedId); // <1>
request.setAllowNoMatch(true); // <2>
request.setForExport(false); // <3>
// end::get-datafeed-request

// tag::get-datafeed-execute
Expand Down Expand Up @@ -2861,6 +2863,7 @@ public void testGetDataFrameAnalytics() throws Exception {
{
// tag::get-data-frame-analytics-request
GetDataFrameAnalyticsRequest request = new GetDataFrameAnalyticsRequest("my-analytics-config"); // <1>
request.setForExport(false); // <2>
// end::get-data-frame-analytics-request

// tag::get-data-frame-analytics-execute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ IDs, or the special wildcard `_all` to get all {dfanalytics-jobs}.
include-tagged::{doc-tests-file}[{api}-request]
--------------------------------------------------
<1> Constructing a new GET request referencing an existing {dfanalytics-job}
<2> Optional boolean value for requesting the {dfanalytics-job} in a format that can
then be put into another cluster. Certain fields that can only be set when
the {dfanalytics-job} is created are removed.

include::../execution.asciidoc[]

Expand Down
3 changes: 3 additions & 0 deletions docs/java-rest/high-level/ml/get-datafeed.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ include-tagged::{doc-tests-file}[{api}-request]
contain wildcards.
<2> Whether to ignore if a wildcard expression matches no datafeeds.
(This includes `_all` string or when no datafeeds have been specified).
<3> Optional boolean value for requesting the datafeed in a format that can
then be put into another cluster. Certain fields that can only be set when
the datafeed is created are removed.

[id="{upid}-{api}-response"]
==== Get datafeed response
Expand Down
3 changes: 3 additions & 0 deletions docs/java-rest/high-level/ml/get-job.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ include-tagged::{doc-tests-file}[{api}-request]
wildcards.
<2> Whether to ignore if a wildcard expression matches no {anomaly-jobs}.
(This includes `_all` string or when no jobs have been specified).
<3> Optional boolean value for requesting the job in a format that can
then be put into another cluster. Certain fields that can only be set when
the job is created are removed.

[id="{upid}-{api}-response"]
==== Get {anomaly-jobs} response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ all {dfeeds}.
(Optional, boolean)
include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=allow-no-datafeeds]

`for_export`::
(Optional, boolean)
include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=for-export]

[[ml-get-datafeed-results]]
== {api-response-body-title}

Expand Down
3 changes: 3 additions & 0 deletions docs/reference/ml/anomaly-detection/apis/get-job.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=job-id-anomaly-detection-defaul
(Optional, boolean)
include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=allow-no-jobs]

`for_export`::
(Optional, boolean)
include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=for-export]

[[ml-get-job-results]]
== {api-response-body-title}
Expand Down
4 changes: 4 additions & 0 deletions docs/reference/ml/df-analytics/apis/get-dfanalytics.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=from]
(Optional, integer)
include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=size]

`for_export`::
(Optional, boolean)
include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=for-export]

[role="child_attributes"]
[[ml-get-dfanalytics-results]]
== {api-response-body-title}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ Specifies whether the included model definition should be returned as a JSON map

`for_export`::
(Optional, boolean)
Indicates if certain fields should be removed from the model configuration on
retrieval. This allows the model to be in an acceptable format to be retrieved
and then added to another cluster. Default is false.
include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=for-export]

`from`::
(Optional, integer)
Expand Down
6 changes: 6 additions & 0 deletions docs/reference/ml/ml-shared.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,12 @@ The number of individual forecasts currently available for the job. A value of
`1` or more indicates that forecasts exist.
end::forecast-total[]

tag::for-export[]
Indicates if certain fields should be removed from the configuration on
retrieval. This allows the configuration to be in an acceptable format to be retrieved
and then added to another cluster. Default is false.
end::for-export[]

tag::frequency[]
The interval at which scheduled queries are made while the {dfeed} runs in real
time. The default value is either the bucket span for short bucket spans, or,
Expand Down
Loading