/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
package org.opensearch.ad.transport;
import static org.opensearch.action.ValidateActions.addValidationError;
import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken;
import java.io.IOException;
import java.time.Instant;
import java.util.List;
import org.opensearch.action.ActionRequest;
import org.opensearch.action.ActionRequestValidationException;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.timeseries.util.ParseUtils;
/**
* Request for getting the top anomaly results for HC detectors.
*
* size, category field, and order are optional, and will be set to default values if left blank
*/
public class SearchTopAnomalyResultRequest extends ActionRequest {
private static final String TASK_ID_FIELD = "task_id";
private static final String SIZE_FIELD = "size";
private static final String CATEGORY_FIELD_FIELD = "category_field";
private static final String ORDER_FIELD = "order";
private static final String START_TIME_FIELD = "start_time_ms";
private static final String END_TIME_FIELD = "end_time_ms";
private String detectorId;
private String taskId;
private boolean historical;
private Integer size;
private List categoryFields;
private String order;
private Instant startTime;
private Instant endTime;
public SearchTopAnomalyResultRequest(StreamInput in) throws IOException {
super(in);
detectorId = in.readOptionalString();
taskId = in.readOptionalString();
historical = in.readBoolean();
size = in.readOptionalInt();
categoryFields = in.readOptionalStringList();
order = in.readOptionalString();
startTime = in.readInstant();
endTime = in.readInstant();
}
public SearchTopAnomalyResultRequest(
String detectorId,
String taskId,
boolean historical,
Integer size,
List categoryFields,
String order,
Instant startTime,
Instant endTime
) {
super();
this.detectorId = detectorId;
this.taskId = taskId;
this.historical = historical;
this.size = size;
this.categoryFields = categoryFields;
this.order = order;
this.startTime = startTime;
this.endTime = endTime;
}
public String getId() {
return detectorId;
}
public String getTaskId() {
return taskId;
}
public boolean getHistorical() {
return historical;
}
public Integer getSize() {
return size;
}
public List getCategoryFields() {
return categoryFields;
}
public String getOrder() {
return order;
}
public Instant getStartTime() {
return startTime;
}
public Instant getEndTime() {
return endTime;
}
public void setTaskId(String taskId) {
this.taskId = taskId;
}
public void setSize(Integer size) {
this.size = size;
}
public void setCategoryFields(List categoryFields) {
this.categoryFields = categoryFields;
}
public void setOrder(String order) {
this.order = order;
}
@SuppressWarnings("unchecked")
public static SearchTopAnomalyResultRequest parse(XContentParser parser, String detectorId, boolean historical) throws IOException {
String taskId = null;
Integer size = null;
List