Search in sources :

Example 1 with DETECTOR_ID

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));
}
Also used : IF_SEQ_NO(org.opensearch.ad.util.RestHandlerUtils.IF_SEQ_NO) SequenceNumbers(org.opensearch.index.seqno.SequenceNumbers) ToXContent(org.opensearch.common.xcontent.ToXContent) EnabledSetting(org.opensearch.ad.settings.EnabledSetting) XContentParser(org.opensearch.common.xcontent.XContentParser) WriteRequest(org.opensearch.action.support.WriteRequest) ImmutableList(com.google.common.collect.ImmutableList) IF_PRIMARY_TERM(org.opensearch.ad.util.RestHandlerUtils.IF_PRIMARY_TERM) IndexAnomalyDetectorResponse(org.opensearch.ad.transport.IndexAnomalyDetectorResponse) Locale(java.util.Locale) AnomalyDetector(org.opensearch.ad.model.AnomalyDetector) IndexAnomalyDetectorAction(org.opensearch.ad.transport.IndexAnomalyDetectorAction) RestResponseListener(org.opensearch.rest.action.RestResponseListener) IndexAnomalyDetectorRequest(org.opensearch.ad.transport.IndexAnomalyDetectorRequest) NodeClient(org.opensearch.client.node.NodeClient) RestRequest(org.opensearch.rest.RestRequest) REFRESH(org.opensearch.ad.util.RestHandlerUtils.REFRESH) XContentParserUtils.ensureExpectedToken(org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken) IOException(java.io.IOException) Settings(org.opensearch.common.settings.Settings) RestStatus(org.opensearch.rest.RestStatus) BytesRestResponse(org.opensearch.rest.BytesRestResponse) RestResponse(org.opensearch.rest.RestResponse) List(java.util.List) CommonErrorMessages(org.opensearch.ad.constant.CommonErrorMessages) Logger(org.apache.logging.log4j.Logger) RestChannel(org.opensearch.rest.RestChannel) ClusterService(org.opensearch.cluster.service.ClusterService) AnomalyDetectorPlugin(org.opensearch.ad.AnomalyDetectorPlugin) LogManager(org.apache.logging.log4j.LogManager) DETECTOR_ID(org.opensearch.ad.util.RestHandlerUtils.DETECTOR_ID) RestRequest(org.opensearch.rest.RestRequest) WriteRequest(org.opensearch.action.support.WriteRequest) IndexAnomalyDetectorRequest(org.opensearch.ad.transport.IndexAnomalyDetectorRequest) XContentParser(org.opensearch.common.xcontent.XContentParser) AnomalyDetector(org.opensearch.ad.model.AnomalyDetector)

Example 2 with DETECTOR_ID

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));
}
Also used : IF_SEQ_NO(org.opensearch.ad.util.RestHandlerUtils.IF_SEQ_NO) SequenceNumbers(org.opensearch.index.seqno.SequenceNumbers) REQUEST_TIMEOUT(org.opensearch.ad.settings.AnomalyDetectorSettings.REQUEST_TIMEOUT) EnabledSetting(org.opensearch.ad.settings.EnabledSetting) XContentParser(org.opensearch.common.xcontent.XContentParser) RestToXContentListener(org.opensearch.rest.action.RestToXContentListener) ImmutableList(com.google.common.collect.ImmutableList) IF_PRIMARY_TERM(org.opensearch.ad.util.RestHandlerUtils.IF_PRIMARY_TERM) Locale(java.util.Locale) STOP_JOB(org.opensearch.ad.util.RestHandlerUtils.STOP_JOB) BaseRestHandler(org.opensearch.rest.BaseRestHandler) AnomalyDetectorJobRequest(org.opensearch.ad.transport.AnomalyDetectorJobRequest) AnomalyDetectorJobAction(org.opensearch.ad.transport.AnomalyDetectorJobAction) TimeValue(org.opensearch.common.unit.TimeValue) NodeClient(org.opensearch.client.node.NodeClient) RestRequest(org.opensearch.rest.RestRequest) START_JOB(org.opensearch.ad.util.RestHandlerUtils.START_JOB) XContentParserUtils.ensureExpectedToken(org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken) IOException(java.io.IOException) Settings(org.opensearch.common.settings.Settings) List(java.util.List) CommonErrorMessages(org.opensearch.ad.constant.CommonErrorMessages) DetectionDateRange(org.opensearch.ad.model.DetectionDateRange) ClusterService(org.opensearch.cluster.service.ClusterService) AnomalyDetectorPlugin(org.opensearch.ad.AnomalyDetectorPlugin) DETECTOR_ID(org.opensearch.ad.util.RestHandlerUtils.DETECTOR_ID) AnomalyDetectorJobRequest(org.opensearch.ad.transport.AnomalyDetectorJobRequest) DetectionDateRange(org.opensearch.ad.model.DetectionDateRange)

Example 3 with DETECTOR_ID

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));
}
Also used : NodeClient(org.opensearch.client.node.NodeClient) RestRequest(org.opensearch.rest.RestRequest) AnomalyDetectorActionHandler(org.opensearch.ad.rest.handler.AnomalyDetectorActionHandler) IOException(java.io.IOException) EnabledSetting(org.opensearch.ad.settings.EnabledSetting) DeleteAnomalyDetectorAction(org.opensearch.ad.transport.DeleteAnomalyDetectorAction) List(java.util.List) CommonErrorMessages(org.opensearch.ad.constant.CommonErrorMessages) DeleteAnomalyDetectorRequest(org.opensearch.ad.transport.DeleteAnomalyDetectorRequest) Logger(org.apache.logging.log4j.Logger) RestToXContentListener(org.opensearch.rest.action.RestToXContentListener) ImmutableList(com.google.common.collect.ImmutableList) Locale(java.util.Locale) AnomalyDetectorPlugin(org.opensearch.ad.AnomalyDetectorPlugin) BaseRestHandler(org.opensearch.rest.BaseRestHandler) LogManager(org.apache.logging.log4j.LogManager) DETECTOR_ID(org.opensearch.ad.util.RestHandlerUtils.DETECTOR_ID) DeleteAnomalyDetectorRequest(org.opensearch.ad.transport.DeleteAnomalyDetectorRequest)

Example 4 with DETECTOR_ID

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));
}
Also used : GetAnomalyDetectorRequest(org.opensearch.ad.transport.GetAnomalyDetectorRequest) CommonName(org.opensearch.ad.constant.CommonName) NodeClient(org.opensearch.client.node.NodeClient) PROFILE(org.opensearch.ad.util.RestHandlerUtils.PROFILE) RestRequest(org.opensearch.rest.RestRequest) IOException(java.io.IOException) EnabledSetting(org.opensearch.ad.settings.EnabledSetting) Strings(org.opensearch.common.Strings) List(java.util.List) CommonErrorMessages(org.opensearch.ad.constant.CommonErrorMessages) Logger(org.apache.logging.log4j.Logger) RestActions(org.opensearch.rest.action.RestActions) Entity(org.opensearch.ad.model.Entity) RestToXContentListener(org.opensearch.rest.action.RestToXContentListener) ImmutableList(com.google.common.collect.ImmutableList) Locale(java.util.Locale) Optional(java.util.Optional) AnomalyDetectorPlugin(org.opensearch.ad.AnomalyDetectorPlugin) GetAnomalyDetectorAction(org.opensearch.ad.transport.GetAnomalyDetectorAction) BaseRestHandler(org.opensearch.rest.BaseRestHandler) TYPE(org.opensearch.ad.util.RestHandlerUtils.TYPE) LogManager(org.apache.logging.log4j.LogManager) DETECTOR_ID(org.opensearch.ad.util.RestHandlerUtils.DETECTOR_ID) GetAnomalyDetectorRequest(org.opensearch.ad.transport.GetAnomalyDetectorRequest)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)4 IOException (java.io.IOException)4 List (java.util.List)4 Locale (java.util.Locale)4 AnomalyDetectorPlugin (org.opensearch.ad.AnomalyDetectorPlugin)4 CommonErrorMessages (org.opensearch.ad.constant.CommonErrorMessages)4 EnabledSetting (org.opensearch.ad.settings.EnabledSetting)4 DETECTOR_ID (org.opensearch.ad.util.RestHandlerUtils.DETECTOR_ID)4 NodeClient (org.opensearch.client.node.NodeClient)4 RestRequest (org.opensearch.rest.RestRequest)4 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3 BaseRestHandler (org.opensearch.rest.BaseRestHandler)3 RestToXContentListener (org.opensearch.rest.action.RestToXContentListener)3 IF_PRIMARY_TERM (org.opensearch.ad.util.RestHandlerUtils.IF_PRIMARY_TERM)2 IF_SEQ_NO (org.opensearch.ad.util.RestHandlerUtils.IF_SEQ_NO)2 ClusterService (org.opensearch.cluster.service.ClusterService)2 Settings (org.opensearch.common.settings.Settings)2 XContentParser (org.opensearch.common.xcontent.XContentParser)2 XContentParserUtils.ensureExpectedToken (org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken)2