use of org.opensearch.ad.util.RestHandlerUtils.DETECTOR_ID in project anomaly-detection by opensearch-project.
the class RestIndexAnomalyDetectorAction method prepareRequest.
@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
if (!EnabledSetting.isADPluginEnabled()) {
throw new IllegalStateException(CommonErrorMessages.DISABLED_ERR_MSG);
}
String detectorId = request.param(DETECTOR_ID, AnomalyDetector.NO_ID);
logger.info("AnomalyDetector {} action for detectorId {}", request.method(), detectorId);
XContentParser parser = request.contentParser();
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser);
// TODO: check detection interval < modelTTL
AnomalyDetector detector = AnomalyDetector.parse(parser, detectorId, null, detectionInterval, detectionWindowDelay);
long seqNo = request.paramAsLong(IF_SEQ_NO, SequenceNumbers.UNASSIGNED_SEQ_NO);
long primaryTerm = request.paramAsLong(IF_PRIMARY_TERM, SequenceNumbers.UNASSIGNED_PRIMARY_TERM);
WriteRequest.RefreshPolicy refreshPolicy = request.hasParam(REFRESH) ? WriteRequest.RefreshPolicy.parse(request.param(REFRESH)) : WriteRequest.RefreshPolicy.IMMEDIATE;
RestRequest.Method method = request.getHttpRequest().method();
IndexAnomalyDetectorRequest indexAnomalyDetectorRequest = new IndexAnomalyDetectorRequest(detectorId, seqNo, primaryTerm, refreshPolicy, detector, method, requestTimeout, maxSingleEntityDetectors, maxMultiEntityDetectors, maxAnomalyFeatures);
return channel -> client.execute(IndexAnomalyDetectorAction.INSTANCE, indexAnomalyDetectorRequest, indexAnomalyDetectorResponse(channel, method));
}
use of org.opensearch.ad.util.RestHandlerUtils.DETECTOR_ID in project anomaly-detection by opensearch-project.
the class RestAnomalyDetectorJobAction method prepareRequest.
@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
if (!EnabledSetting.isADPluginEnabled()) {
throw new IllegalStateException(CommonErrorMessages.DISABLED_ERR_MSG);
}
String detectorId = request.param(DETECTOR_ID);
long seqNo = request.paramAsLong(IF_SEQ_NO, SequenceNumbers.UNASSIGNED_SEQ_NO);
long primaryTerm = request.paramAsLong(IF_PRIMARY_TERM, SequenceNumbers.UNASSIGNED_PRIMARY_TERM);
boolean historical = request.paramAsBoolean("historical", false);
String rawPath = request.rawPath();
DetectionDateRange detectionDateRange = parseDetectionDateRange(request);
AnomalyDetectorJobRequest anomalyDetectorJobRequest = new AnomalyDetectorJobRequest(detectorId, detectionDateRange, historical, seqNo, primaryTerm, rawPath);
return channel -> client.execute(AnomalyDetectorJobAction.INSTANCE, anomalyDetectorJobRequest, new RestToXContentListener<>(channel));
}
use of org.opensearch.ad.util.RestHandlerUtils.DETECTOR_ID in project anomaly-detection by opensearch-project.
the class RestDeleteAnomalyDetectorAction method prepareRequest.
@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
if (!EnabledSetting.isADPluginEnabled()) {
throw new IllegalStateException(CommonErrorMessages.DISABLED_ERR_MSG);
}
String detectorId = request.param(DETECTOR_ID);
DeleteAnomalyDetectorRequest deleteAnomalyDetectorRequest = new DeleteAnomalyDetectorRequest(detectorId);
return channel -> client.execute(DeleteAnomalyDetectorAction.INSTANCE, deleteAnomalyDetectorRequest, new RestToXContentListener<>(channel));
}
use of org.opensearch.ad.util.RestHandlerUtils.DETECTOR_ID in project anomaly-detection by opensearch-project.
the class RestGetAnomalyDetectorAction method prepareRequest.
@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
if (!EnabledSetting.isADPluginEnabled()) {
throw new IllegalStateException(CommonErrorMessages.DISABLED_ERR_MSG);
}
String detectorId = request.param(DETECTOR_ID);
String typesStr = request.param(TYPE);
String rawPath = request.rawPath();
boolean returnJob = request.paramAsBoolean("job", false);
boolean returnTask = request.paramAsBoolean("task", false);
boolean all = request.paramAsBoolean("_all", false);
GetAnomalyDetectorRequest getAnomalyDetectorRequest = new GetAnomalyDetectorRequest(detectorId, RestActions.parseVersion(request), returnJob, returnTask, typesStr, rawPath, all, buildEntity(request, detectorId));
return channel -> client.execute(GetAnomalyDetectorAction.INSTANCE, getAnomalyDetectorRequest, new RestToXContentListener<>(channel));
}
Aggregations