-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
12 changed files
with
784 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
222 changes: 222 additions & 0 deletions
222
client/rest-high-level/src/main/java/org/elasticsearch/client/ml/GetRecordsRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
/* | ||
* 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.ml.job.config.Job; | ||
import org.elasticsearch.client.ml.job.util.PageParams; | ||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.xcontent.ObjectParser; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
/** | ||
* A request to retrieve records of a given job | ||
*/ | ||
public class GetRecordsRequest implements ToXContentObject, Validatable { | ||
|
||
public static final ParseField EXCLUDE_INTERIM = new ParseField("exclude_interim"); | ||
public static final ParseField START = new ParseField("start"); | ||
public static final ParseField END = new ParseField("end"); | ||
public static final ParseField RECORD_SCORE = new ParseField("record_score"); | ||
public static final ParseField SORT = new ParseField("sort"); | ||
public static final ParseField DESCENDING = new ParseField("desc"); | ||
|
||
public static final ObjectParser<GetRecordsRequest, Void> PARSER = new ObjectParser<>("get_buckets_request", GetRecordsRequest::new); | ||
|
||
static { | ||
PARSER.declareString((request, jobId) -> request.jobId = jobId, Job.ID); | ||
PARSER.declareBoolean(GetRecordsRequest::setExcludeInterim, EXCLUDE_INTERIM); | ||
PARSER.declareStringOrNull(GetRecordsRequest::setStart, START); | ||
PARSER.declareStringOrNull(GetRecordsRequest::setEnd, END); | ||
PARSER.declareObject(GetRecordsRequest::setPageParams, PageParams.PARSER, PageParams.PAGE); | ||
PARSER.declareDouble(GetRecordsRequest::setRecordScore, RECORD_SCORE); | ||
PARSER.declareString(GetRecordsRequest::setSort, SORT); | ||
PARSER.declareBoolean(GetRecordsRequest::setDescending, DESCENDING); | ||
} | ||
|
||
private String jobId; | ||
private Boolean excludeInterim; | ||
private String start; | ||
private String end; | ||
private PageParams pageParams; | ||
private Double recordScore; | ||
private String sort; | ||
private Boolean descending; | ||
|
||
private GetRecordsRequest() {} | ||
|
||
/** | ||
* Constructs a request to retrieve records of a given job | ||
* @param jobId id of the job to retrieve records of | ||
*/ | ||
public GetRecordsRequest(String jobId) { | ||
this.jobId = Objects.requireNonNull(jobId); | ||
} | ||
|
||
public String getJobId() { | ||
return jobId; | ||
} | ||
|
||
public boolean isExcludeInterim() { | ||
return excludeInterim; | ||
} | ||
|
||
/** | ||
* Sets the value of "exclude_interim". | ||
* When {@code true}, interim records will be filtered out. | ||
* @param excludeInterim value of "exclude_interim" to be set | ||
*/ | ||
public void setExcludeInterim(boolean excludeInterim) { | ||
this.excludeInterim = excludeInterim; | ||
} | ||
|
||
public String getStart() { | ||
return start; | ||
} | ||
|
||
/** | ||
* Sets the value of "start" which is a timestamp. | ||
* Only records whose timestamp is on or after the "start" value will be returned. | ||
* @param start value of "start" to be set | ||
*/ | ||
public void setStart(String start) { | ||
this.start = start; | ||
} | ||
|
||
public String getEnd() { | ||
return end; | ||
} | ||
|
||
/** | ||
* Sets the value of "end" which is a timestamp. | ||
* Only records whose timestamp is before the "end" value will be returned. | ||
* @param end value of "end" to be set | ||
*/ | ||
public void setEnd(String end) { | ||
this.end = end; | ||
} | ||
|
||
public PageParams getPageParams() { | ||
return pageParams; | ||
} | ||
|
||
/** | ||
* Sets the paging parameters | ||
* @param pageParams The paging parameters | ||
*/ | ||
public void setPageParams(PageParams pageParams) { | ||
this.pageParams = pageParams; | ||
} | ||
|
||
public Double getRecordScore() { | ||
return recordScore; | ||
} | ||
|
||
/** | ||
* Sets the value of "record_score". | ||
* Only records with "record_score" equal or greater will be returned. | ||
* @param recordScore value of "record_score". | ||
*/ | ||
public void setRecordScore(double recordScore) { | ||
this.recordScore = recordScore; | ||
} | ||
|
||
public String getSort() { | ||
return sort; | ||
} | ||
|
||
/** | ||
* Sets the value of "sort". | ||
* Specifies the bucket field to sort on. | ||
* @param sort value of "sort". | ||
*/ | ||
public void setSort(String sort) { | ||
this.sort = sort; | ||
} | ||
|
||
public boolean isDescending() { | ||
return descending; | ||
} | ||
|
||
/** | ||
* Sets the value of "desc". | ||
* Specifies the sorting order. | ||
* @param descending value of "desc" | ||
*/ | ||
public void setDescending(boolean descending) { | ||
this.descending = descending; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
builder.field(Job.ID.getPreferredName(), jobId); | ||
if (excludeInterim != null) { | ||
builder.field(EXCLUDE_INTERIM.getPreferredName(), excludeInterim); | ||
} | ||
if (start != null) { | ||
builder.field(START.getPreferredName(), start); | ||
} | ||
if (end != null) { | ||
builder.field(END.getPreferredName(), end); | ||
} | ||
if (pageParams != null) { | ||
builder.field(PageParams.PAGE.getPreferredName(), pageParams); | ||
} | ||
if (recordScore != null) { | ||
builder.field(RECORD_SCORE.getPreferredName(), recordScore); | ||
} | ||
if (sort != null) { | ||
builder.field(SORT.getPreferredName(), sort); | ||
} | ||
if (descending != null) { | ||
builder.field(DESCENDING.getPreferredName(), descending); | ||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(jobId, excludeInterim, recordScore, pageParams, start, end, sort, descending); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == null) { | ||
return false; | ||
} | ||
if (getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
GetRecordsRequest other = (GetRecordsRequest) obj; | ||
return Objects.equals(jobId, other.jobId) && | ||
Objects.equals(excludeInterim, other.excludeInterim) && | ||
Objects.equals(recordScore, other.recordScore) && | ||
Objects.equals(pageParams, other.pageParams) && | ||
Objects.equals(start, other.start) && | ||
Objects.equals(end, other.end) && | ||
Objects.equals(sort, other.sort) && | ||
Objects.equals(descending, other.descending); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
client/rest-high-level/src/main/java/org/elasticsearch/client/ml/GetRecordsResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* 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.job.results.AnomalyRecord; | ||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
/** | ||
* A response containing the requested buckets | ||
*/ | ||
public class GetRecordsResponse extends AbstractResultResponse<AnomalyRecord> { | ||
|
||
public static final ParseField RECORDS = new ParseField("records"); | ||
|
||
@SuppressWarnings("unchecked") | ||
public static final ConstructingObjectParser<GetRecordsResponse, Void> PARSER = new ConstructingObjectParser<>("get_records_response", | ||
true, a -> new GetRecordsResponse((List<AnomalyRecord>) a[0], (long) a[1])); | ||
|
||
static { | ||
PARSER.declareObjectArray(ConstructingObjectParser.constructorArg(), AnomalyRecord.PARSER, RECORDS); | ||
PARSER.declareLong(ConstructingObjectParser.constructorArg(), COUNT); | ||
} | ||
|
||
public static GetRecordsResponse fromXContent(XContentParser parser) throws IOException { | ||
return PARSER.parse(parser, null); | ||
} | ||
|
||
GetRecordsResponse(List<AnomalyRecord> buckets, long count) { | ||
super(RECORDS, buckets, count); | ||
} | ||
|
||
/** | ||
* The retrieved records | ||
* @return the retrieved records | ||
*/ | ||
public List<AnomalyRecord> records() { | ||
return results; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(count, results); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == null) { | ||
return false; | ||
} | ||
if (getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
GetRecordsResponse other = (GetRecordsResponse) obj; | ||
return count == other.count && Objects.equals(results, other.results); | ||
} | ||
} |
Oops, something went wrong.