-
Notifications
You must be signed in to change notification settings - Fork 81
Adding create and start to AD node client #1611
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,9 +9,13 @@ | |
| import org.opensearch.action.search.SearchResponse; | ||
| import org.opensearch.action.support.PlainActionFuture; | ||
| import org.opensearch.ad.transport.GetAnomalyDetectorResponse; | ||
| import org.opensearch.ad.transport.IndexAnomalyDetectorRequest; | ||
| import org.opensearch.ad.transport.IndexAnomalyDetectorResponse; | ||
| import org.opensearch.common.action.ActionFuture; | ||
| import org.opensearch.core.action.ActionListener; | ||
| import org.opensearch.timeseries.transport.GetConfigRequest; | ||
| import org.opensearch.timeseries.transport.JobRequest; | ||
| import org.opensearch.timeseries.transport.JobResponse; | ||
| import org.opensearch.timeseries.transport.SuggestConfigParamRequest; | ||
| import org.opensearch.timeseries.transport.SuggestConfigParamResponse; | ||
| import org.opensearch.timeseries.transport.ValidateConfigRequest; | ||
|
|
@@ -110,4 +114,40 @@ default ActionFuture<SuggestConfigParamResponse> suggestAnomalyDetector(SuggestC | |
| * @param listener a listener to be notified of the result | ||
| */ | ||
| void suggestAnomalyDetector(SuggestConfigParamRequest suggestRequest, ActionListener<SuggestConfigParamResponse> listener); | ||
|
|
||
| /** | ||
| * Create anomaly detector - refer to https://opensearch.org/docs/latest/observing-your-data/ad/api/#create-detector | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| * @param createRequest request to create the detector | ||
| * @return ActionFuture of IndexAnomalyDetectorResponse | ||
| */ | ||
| default ActionFuture<IndexAnomalyDetectorResponse> createAnomalyDetector(IndexAnomalyDetectorRequest createRequest) { | ||
| PlainActionFuture<IndexAnomalyDetectorResponse> actionFuture = PlainActionFuture.newFuture(); | ||
| createAnomalyDetector(createRequest, actionFuture); | ||
| return actionFuture; | ||
| } | ||
|
|
||
| /** | ||
| * Create anomaly detector - refer to https://opensearch.org/docs/latest/observing-your-data/ad/api/#create-detector | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same issue |
||
| * @param createRequest request to create the detector | ||
| * @param listener a listener to be notified of the result | ||
| */ | ||
| void createAnomalyDetector(IndexAnomalyDetectorRequest createRequest, ActionListener<IndexAnomalyDetectorResponse> listener); | ||
|
|
||
| /** | ||
| * Start anomaly detector - refer to https://opensearch.org/docs/latest/observing-your-data/ad/api/#start-detector | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| * @param startRequest request to start the detector | ||
| * @return ActionFuture of JobResponse | ||
| */ | ||
| default ActionFuture<JobResponse> startAnomalyDetector(JobRequest startRequest) { | ||
| PlainActionFuture<JobResponse> actionFuture = PlainActionFuture.newFuture(); | ||
| startAnomalyDetector(startRequest, actionFuture); | ||
| return actionFuture; | ||
| } | ||
|
|
||
| /** | ||
| * Start anomaly detector - refer to https://opensearch.org/docs/latest/observing-your-data/ad/api/#start-detector | ||
| * @param startRequest request to start the detector | ||
| * @param listener a listener to be notified of the result | ||
| */ | ||
| void startAnomalyDetector(JobRequest startRequest, ActionListener<JobResponse> listener); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |
| import org.opensearch.common.unit.TimeValue; | ||
| import org.opensearch.core.common.io.stream.StreamInput; | ||
| import org.opensearch.core.common.io.stream.StreamOutput; | ||
| import org.opensearch.index.seqno.SequenceNumbers; | ||
| import org.opensearch.rest.RestRequest; | ||
|
|
||
| public class IndexAnomalyDetectorRequest extends ActionRequest implements DocRequest { | ||
|
|
@@ -50,10 +51,10 @@ public IndexAnomalyDetectorRequest(StreamInput in) throws IOException { | |
| detector = new AnomalyDetector(in); | ||
| method = in.readEnum(RestRequest.Method.class); | ||
| requestTimeout = in.readTimeValue(); | ||
| maxSingleEntityAnomalyDetectors = in.readInt(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may cause bwc issue as if the caller sends request between new and old nodes. |
||
| maxMultiEntityAnomalyDetectors = in.readInt(); | ||
| maxAnomalyFeatures = in.readInt(); | ||
| maxCategoricalFields = in.readInt(); | ||
| maxSingleEntityAnomalyDetectors = in.readOptionalInt(); | ||
| maxMultiEntityAnomalyDetectors = in.readOptionalInt(); | ||
| maxAnomalyFeatures = in.readOptionalInt(); | ||
| maxCategoricalFields = in.readOptionalInt(); | ||
| } | ||
|
|
||
| public IndexAnomalyDetectorRequest( | ||
|
|
@@ -83,6 +84,22 @@ public IndexAnomalyDetectorRequest( | |
| this.maxCategoricalFields = maxCategoricalFields; | ||
| } | ||
|
|
||
| public IndexAnomalyDetectorRequest(String detectorID, AnomalyDetector detector, RestRequest.Method method) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where do you call this constructor? |
||
| this( | ||
| detectorID, | ||
| SequenceNumbers.UNASSIGNED_SEQ_NO, | ||
| SequenceNumbers.UNASSIGNED_PRIMARY_TERM, | ||
| WriteRequest.RefreshPolicy.IMMEDIATE, | ||
| detector, | ||
| method, | ||
| TimeValue.timeValueSeconds(60), | ||
| null, | ||
| null, | ||
| null, | ||
| null | ||
| ); | ||
| } | ||
|
|
||
| public String getDetectorID() { | ||
| return detectorID; | ||
| } | ||
|
|
@@ -137,10 +154,10 @@ public void writeTo(StreamOutput out) throws IOException { | |
| detector.writeTo(out); | ||
| out.writeEnum(method); | ||
| out.writeTimeValue(requestTimeout); | ||
| out.writeInt(maxSingleEntityAnomalyDetectors); | ||
| out.writeInt(maxMultiEntityAnomalyDetectors); | ||
| out.writeInt(maxAnomalyFeatures); | ||
| out.writeInt(maxCategoricalFields); | ||
| out.writeOptionalInt(maxSingleEntityAnomalyDetectors); | ||
| out.writeOptionalInt(maxMultiEntityAnomalyDetectors); | ||
| out.writeOptionalInt(maxAnomalyFeatures); | ||
| out.writeOptionalInt(maxCategoricalFields); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -162,4 +179,32 @@ public String index() { | |
| public String id() { | ||
| return detectorID; | ||
| } | ||
|
|
||
| public static IndexAnomalyDetectorRequest fromActionRequest( | ||
| final ActionRequest actionRequest, | ||
| org.opensearch.core.common.io.stream.NamedWriteableRegistry namedWriteableRegistry | ||
| ) { | ||
| if (actionRequest instanceof IndexAnomalyDetectorRequest) { | ||
| return (IndexAnomalyDetectorRequest) actionRequest; | ||
| } | ||
|
|
||
| try ( | ||
| java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(); | ||
| org.opensearch.core.common.io.stream.OutputStreamStreamOutput osso = | ||
| new org.opensearch.core.common.io.stream.OutputStreamStreamOutput(baos) | ||
| ) { | ||
| actionRequest.writeTo(osso); | ||
| try ( | ||
| org.opensearch.core.common.io.stream.StreamInput input = new org.opensearch.core.common.io.stream.InputStreamStreamInput( | ||
| new java.io.ByteArrayInputStream(baos.toByteArray()) | ||
| ); | ||
| org.opensearch.core.common.io.stream.NamedWriteableAwareStreamInput namedInput = | ||
| new org.opensearch.core.common.io.stream.NamedWriteableAwareStreamInput(input, namedWriteableRegistry) | ||
| ) { | ||
| return new IndexAnomalyDetectorRequest(namedInput); | ||
| } | ||
| } catch (java.io.IOException e) { | ||
| throw new IllegalArgumentException("failed to parse ActionRequest into IndexAnomalyDetectorRequest", e); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,10 +11,17 @@ | |
|
|
||
| package org.opensearch.ad.transport; | ||
|
|
||
| import java.io.ByteArrayInputStream; | ||
| import java.io.ByteArrayOutputStream; | ||
| import java.io.IOException; | ||
| import java.io.UncheckedIOException; | ||
|
|
||
| import org.opensearch.ad.model.AnomalyDetector; | ||
| import org.opensearch.core.action.ActionResponse; | ||
| import org.opensearch.core.common.io.stream.InputStreamStreamInput; | ||
| import org.opensearch.core.common.io.stream.NamedWriteableAwareStreamInput; | ||
| import org.opensearch.core.common.io.stream.NamedWriteableRegistry; | ||
| import org.opensearch.core.common.io.stream.OutputStreamStreamOutput; | ||
| import org.opensearch.core.common.io.stream.StreamInput; | ||
| import org.opensearch.core.common.io.stream.StreamOutput; | ||
| import org.opensearch.core.rest.RestStatus; | ||
|
|
@@ -81,4 +88,25 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws | |
| .field(RestHandlerUtils._PRIMARY_TERM, primaryTerm) | ||
| .endObject(); | ||
| } | ||
|
|
||
| public static IndexAnomalyDetectorResponse fromActionResponse( | ||
| ActionResponse actionResponse, | ||
| NamedWriteableRegistry namedWriteableRegistry | ||
| ) { | ||
| if (actionResponse instanceof IndexAnomalyDetectorResponse) { | ||
| return (IndexAnomalyDetectorResponse) actionResponse; | ||
| } | ||
|
|
||
| try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStreamStreamOutput osso = new OutputStreamStreamOutput(baos)) { | ||
| actionResponse.writeTo(osso); | ||
| try ( | ||
| StreamInput input = new InputStreamStreamInput(new ByteArrayInputStream(baos.toByteArray())); | ||
| NamedWriteableAwareStreamInput namedWriteableAwareInput = new NamedWriteableAwareStreamInput(input, namedWriteableRegistry) | ||
| ) { | ||
| return new IndexAnomalyDetectorResponse(namedWriteableAwareInput); | ||
| } | ||
| } catch (IOException e) { | ||
| throw new UncheckedIOException("failed to parse ActionResponse into IndexAnomalyDetectorResponse", e); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. be consistent: IndexAnomalyDetectorRequest.fromActionRequest(...) throws IllegalArgumentException wrapping the IOException, while we throw UncheckedIOException here. |
||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you need ml-plugin?