Search in sources :

Example 1 with REFRESH

use of org.opensearch.ad.util.RestHandlerUtils.REFRESH 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)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 List (java.util.List)1 Locale (java.util.Locale)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 WriteRequest (org.opensearch.action.support.WriteRequest)1 AnomalyDetectorPlugin (org.opensearch.ad.AnomalyDetectorPlugin)1 CommonErrorMessages (org.opensearch.ad.constant.CommonErrorMessages)1 AnomalyDetector (org.opensearch.ad.model.AnomalyDetector)1 EnabledSetting (org.opensearch.ad.settings.EnabledSetting)1 IndexAnomalyDetectorAction (org.opensearch.ad.transport.IndexAnomalyDetectorAction)1 IndexAnomalyDetectorRequest (org.opensearch.ad.transport.IndexAnomalyDetectorRequest)1 IndexAnomalyDetectorResponse (org.opensearch.ad.transport.IndexAnomalyDetectorResponse)1 DETECTOR_ID (org.opensearch.ad.util.RestHandlerUtils.DETECTOR_ID)1 IF_PRIMARY_TERM (org.opensearch.ad.util.RestHandlerUtils.IF_PRIMARY_TERM)1 IF_SEQ_NO (org.opensearch.ad.util.RestHandlerUtils.IF_SEQ_NO)1 REFRESH (org.opensearch.ad.util.RestHandlerUtils.REFRESH)1 NodeClient (org.opensearch.client.node.NodeClient)1 ClusterService (org.opensearch.cluster.service.ClusterService)1