Search in sources :

Example 1 with LimitExceededException

use of org.opensearch.ad.common.exception.LimitExceededException in project anomaly-detection by opensearch-project.

the class AnomalyResultTransportAction method doExecute.

/**
 * All the exceptions thrown by AD is a subclass of AnomalyDetectionException.
 *  ClientException is a subclass of AnomalyDetectionException. All exception visible to
 *   Client is under ClientVisible. Two classes directly extends ClientException:
 *   - InternalFailure for "root cause unknown failure. Maybe transient." We can continue the
 *    detector running.
 *   - EndRunException for "failures that might impact the customer." The method endNow() is
 *    added to indicate whether the client should immediately terminate running a detector.
 *      + endNow() returns true for "unrecoverable issue". We want to terminate the detector run
 *       immediately.
 *      + endNow() returns false for "maybe unrecoverable issue but worth retrying a few more
 *       times." We want to wait for a few more times on different requests before terminating
 *        the detector run.
 *
 *  AD may not be able to get an anomaly grade but can find a feature vector.  Consider the
 *   case when the shingle is not ready.  In that case, AD just put NaN as anomaly grade and
 *    return the feature vector. If AD cannot even find a feature vector, AD throws
 *     EndRunException if there is an issue or returns empty response (all the numeric fields
 *      are Double.NaN and feature array is empty.  Do so so that customer can write painless
 *       script.) otherwise.
 *
 *  Known causes of EndRunException with endNow returning false:
 *   + training data for cold start not available
 *   + cold start cannot succeed
 *   + unknown prediction error
 *   + memory circuit breaker tripped
 *   + invalid search query
 *
 *  Known causes of EndRunException with endNow returning true:
 *   + a model partition's memory size reached limit
 *   + models' total memory size reached limit
 *   + Having trouble querying feature data due to
 *    * index does not exist
 *    * all features have been disabled
 *
 *   + anomaly detector is not available
 *   + AD plugin is disabled
 *   + training data is invalid due to serious internal bug(s)
 *
 *  Known causes of InternalFailure:
 *   + threshold model node is not available
 *   + cluster read/write is blocked
 *   + cold start hasn't been finished
 *   + fail to get all of rcf model nodes' responses
 *   + fail to get threshold model node's response
 *   + RCF/Threshold model node failing to get checkpoint to restore model before timeout
 *   + Detection is throttle because previous detection query is running
 */
@Override
protected void doExecute(Task task, ActionRequest actionRequest, ActionListener<AnomalyResultResponse> listener) {
    try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().stashContext()) {
        AnomalyResultRequest request = AnomalyResultRequest.fromActionRequest(actionRequest);
        String adID = request.getAdID();
        ActionListener<AnomalyResultResponse> original = listener;
        listener = ActionListener.wrap(r -> {
            hcDetectors.remove(adID);
            original.onResponse(r);
        }, e -> {
            // we will not count it in failure stats.
            if (!(e instanceof AnomalyDetectionException) || ((AnomalyDetectionException) e).isCountedInStats()) {
                adStats.getStat(StatNames.AD_EXECUTE_FAIL_COUNT.getName()).increment();
                if (hcDetectors.contains(adID)) {
                    adStats.getStat(StatNames.AD_HC_EXECUTE_FAIL_COUNT.getName()).increment();
                }
            }
            hcDetectors.remove(adID);
            original.onFailure(e);
        });
        if (!EnabledSetting.isADPluginEnabled()) {
            throw new EndRunException(adID, CommonErrorMessages.DISABLED_ERR_MSG, true).countedInStats(false);
        }
        adStats.getStat(StatNames.AD_EXECUTE_REQUEST_COUNT.getName()).increment();
        if (adCircuitBreakerService.isOpen()) {
            listener.onFailure(new LimitExceededException(adID, CommonErrorMessages.MEMORY_CIRCUIT_BROKEN_ERR_MSG, false));
            return;
        }
        try {
            stateManager.getAnomalyDetector(adID, onGetDetector(listener, adID, request));
        } catch (Exception ex) {
            handleExecuteException(ex, listener, adID);
        }
    } catch (Exception e) {
        LOG.error(e);
        listener.onFailure(e);
    }
}
Also used : ResourceNotFoundException(org.opensearch.ad.common.exception.ResourceNotFoundException) ModelManager(org.opensearch.ad.ml.ModelManager) HashRing(org.opensearch.ad.cluster.HashRing) ADStats(org.opensearch.ad.stats.ADStats) ActionRequest(org.opensearch.action.ActionRequest) LimitExceededException(org.opensearch.ad.common.exception.LimitExceededException) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) AnomalyDetectionException(org.opensearch.ad.common.exception.AnomalyDetectionException) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Locale(java.util.Locale) Map(java.util.Map) NodeClosedException(org.opensearch.node.NodeClosedException) Inject(org.opensearch.common.inject.Inject) ActionListener(org.opensearch.action.ActionListener) NodeNotConnectedException(org.opensearch.transport.NodeNotConnectedException) Client(org.opensearch.client.Client) ActionNotFoundTransportException(org.opensearch.transport.ActionNotFoundTransportException) TransportRequestOptions(org.opensearch.transport.TransportRequestOptions) Set(java.util.Set) ExceptionsHelper(org.opensearch.ExceptionsHelper) ADTaskManager(org.opensearch.ad.task.ADTaskManager) Settings(org.opensearch.common.settings.Settings) Task(org.opensearch.tasks.Task) RestStatus(org.opensearch.rest.RestStatus) Collectors(java.util.stream.Collectors) TransportService(org.opensearch.transport.TransportService) ActionFilters(org.opensearch.action.support.ActionFilters) List(java.util.List) Logger(org.apache.logging.log4j.Logger) ExceptionUtil(org.opensearch.ad.util.ExceptionUtil) NodeStateManager(org.opensearch.ad.NodeStateManager) Entry(java.util.Map.Entry) OpenSearchTimeoutException(org.opensearch.OpenSearchTimeoutException) ActionListenerResponseHandler(org.opensearch.action.ActionListenerResponseHandler) Optional(java.util.Optional) SingleStreamModelIdMapper(org.opensearch.ad.ml.SingleStreamModelIdMapper) ConnectTransportException(org.opensearch.transport.ConnectTransportException) ReceiveTimeoutTransportException(org.opensearch.transport.ReceiveTimeoutTransportException) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) ADCircuitBreakerService(org.opensearch.ad.breaker.ADCircuitBreakerService) MAX_ENTITIES_PER_QUERY(org.opensearch.ad.settings.AnomalyDetectorSettings.MAX_ENTITIES_PER_QUERY) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) HandledTransportAction(org.opensearch.action.support.HandledTransportAction) NotSerializableExceptionWrapper(org.opensearch.common.io.stream.NotSerializableExceptionWrapper) ThreadPool(org.opensearch.threadpool.ThreadPool) FeatureData(org.opensearch.ad.model.FeatureData) EnabledSetting(org.opensearch.ad.settings.EnabledSetting) Releasable(org.opensearch.common.lease.Releasable) IndicesOptions(org.opensearch.action.support.IndicesOptions) ThreadedActionListener(org.opensearch.action.support.ThreadedActionListener) AtomicReference(java.util.concurrent.atomic.AtomicReference) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) AnomalyDetectorSettings(org.opensearch.ad.settings.AnomalyDetectorSettings) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ClusterState(org.opensearch.cluster.ClusterState) PAGE_SIZE(org.opensearch.ad.settings.AnomalyDetectorSettings.PAGE_SIZE) ClientException(org.opensearch.ad.common.exception.ClientException) AnomalyDetector(org.opensearch.ad.model.AnomalyDetector) ConnectException(java.net.ConnectException) EndRunException(org.opensearch.ad.common.exception.EndRunException) SinglePointFeatures(org.opensearch.ad.feature.SinglePointFeatures) InternalFailure(org.opensearch.ad.common.exception.InternalFailure) CommonName(org.opensearch.ad.constant.CommonName) Iterator(java.util.Iterator) FeatureManager(org.opensearch.ad.feature.FeatureManager) ClusterBlockLevel(org.opensearch.cluster.block.ClusterBlockLevel) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) NotSerializedADExceptionName(org.opensearch.ad.common.exception.NotSerializedADExceptionName) INVALID_SEARCH_QUERY_MSG(org.opensearch.ad.constant.CommonErrorMessages.INVALID_SEARCH_QUERY_MSG) CompositeRetriever(org.opensearch.ad.feature.CompositeRetriever) PageIterator(org.opensearch.ad.feature.CompositeRetriever.PageIterator) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) CommonErrorMessages(org.opensearch.ad.constant.CommonErrorMessages) Entity(org.opensearch.ad.model.Entity) ShardSearchFailure(org.opensearch.action.search.ShardSearchFailure) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) ClusterService(org.opensearch.cluster.service.ClusterService) AnomalyDetectorPlugin(org.opensearch.ad.AnomalyDetectorPlugin) SearchPhaseExecutionException(org.opensearch.action.search.SearchPhaseExecutionException) IntervalTimeConfiguration(org.opensearch.ad.model.IntervalTimeConfiguration) StatNames(org.opensearch.ad.stats.StatNames) LogManager(org.apache.logging.log4j.LogManager) NetworkExceptionHelper(org.opensearch.common.transport.NetworkExceptionHelper) ParseUtils(org.opensearch.ad.util.ParseUtils) AnomalyDetectionException(org.opensearch.ad.common.exception.AnomalyDetectionException) EndRunException(org.opensearch.ad.common.exception.EndRunException) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) LimitExceededException(org.opensearch.ad.common.exception.LimitExceededException) ResourceNotFoundException(org.opensearch.ad.common.exception.ResourceNotFoundException) LimitExceededException(org.opensearch.ad.common.exception.LimitExceededException) AnomalyDetectionException(org.opensearch.ad.common.exception.AnomalyDetectionException) NodeClosedException(org.opensearch.node.NodeClosedException) NodeNotConnectedException(org.opensearch.transport.NodeNotConnectedException) ActionNotFoundTransportException(org.opensearch.transport.ActionNotFoundTransportException) OpenSearchTimeoutException(org.opensearch.OpenSearchTimeoutException) ConnectTransportException(org.opensearch.transport.ConnectTransportException) ReceiveTimeoutTransportException(org.opensearch.transport.ReceiveTimeoutTransportException) ClientException(org.opensearch.ad.common.exception.ClientException) ConnectException(java.net.ConnectException) EndRunException(org.opensearch.ad.common.exception.EndRunException) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) SearchPhaseExecutionException(org.opensearch.action.search.SearchPhaseExecutionException)

Example 2 with LimitExceededException

use of org.opensearch.ad.common.exception.LimitExceededException in project anomaly-detection by opensearch-project.

the class AnomalyResultTransportAction method coldStartIfNoModel.

/**
 * Verify failure of rcf or threshold models. If there is no model, trigger cold
 * start. If there is an exception for the previous cold start of this detector,
 * throw exception to the caller.
 *
 * @param failure  object that may contain exceptions thrown
 * @param detector detector object
 * @return exception if AD job execution gets resource not found exception
 * @throws Exception when the input failure is not a ResourceNotFoundException.
 *   List of exceptions we can throw
 *     1. Exception from cold start:
 *       1). InternalFailure due to
 *         a. OpenSearchTimeoutException thrown by putModelCheckpoint during cold start
 *       2). EndRunException with endNow equal to false
 *         a. training data not available
 *         b. cold start cannot succeed
 *         c. invalid training data
 *       3) EndRunException with endNow equal to true
 *         a. invalid search query
 *     2. LimitExceededException from one of RCF model node when the total size of the models
 *      is more than X% of heap memory.
 *     3. InternalFailure wrapping OpenSearchTimeoutException inside caused by
 *      RCF/Threshold model node failing to get checkpoint to restore model before timeout.
 */
private Exception coldStartIfNoModel(AtomicReference<Exception> failure, AnomalyDetector detector) throws Exception {
    Exception exp = failure.get();
    if (exp == null) {
        return null;
    }
    // return exceptions like LimitExceededException to caller
    if (!(exp instanceof ResourceNotFoundException)) {
        return exp;
    }
    // fetch previous cold start exception
    String adID = detector.getDetectorId();
    final Optional<Exception> previousException = stateManager.fetchExceptionAndClear(adID);
    if (previousException.isPresent()) {
        Exception exception = previousException.get();
        LOG.error("Previous exception of {}: {}", () -> adID, () -> exception);
        if (exception instanceof EndRunException && ((EndRunException) exception).isEndNow()) {
            return exception;
        }
    }
    LOG.info("Trigger cold start for {}", detector.getDetectorId());
    coldStart(detector);
    return previousException.orElse(new InternalFailure(adID, NO_MODEL_ERR_MSG));
}
Also used : EndRunException(org.opensearch.ad.common.exception.EndRunException) InternalFailure(org.opensearch.ad.common.exception.InternalFailure) ResourceNotFoundException(org.opensearch.ad.common.exception.ResourceNotFoundException) ResourceNotFoundException(org.opensearch.ad.common.exception.ResourceNotFoundException) LimitExceededException(org.opensearch.ad.common.exception.LimitExceededException) AnomalyDetectionException(org.opensearch.ad.common.exception.AnomalyDetectionException) NodeClosedException(org.opensearch.node.NodeClosedException) NodeNotConnectedException(org.opensearch.transport.NodeNotConnectedException) ActionNotFoundTransportException(org.opensearch.transport.ActionNotFoundTransportException) OpenSearchTimeoutException(org.opensearch.OpenSearchTimeoutException) ConnectTransportException(org.opensearch.transport.ConnectTransportException) ReceiveTimeoutTransportException(org.opensearch.transport.ReceiveTimeoutTransportException) ClientException(org.opensearch.ad.common.exception.ClientException) ConnectException(java.net.ConnectException) EndRunException(org.opensearch.ad.common.exception.EndRunException) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) SearchPhaseExecutionException(org.opensearch.action.search.SearchPhaseExecutionException)

Example 3 with LimitExceededException

use of org.opensearch.ad.common.exception.LimitExceededException in project anomaly-detection by opensearch-project.

the class EntityResultTransportAction method doExecute.

@Override
protected void doExecute(Task task, EntityResultRequest request, ActionListener<AcknowledgedResponse> listener) {
    if (adCircuitBreakerService.isOpen()) {
        threadPool.executor(AnomalyDetectorPlugin.AD_THREAD_POOL_NAME).execute(() -> cache.get().releaseMemoryForOpenCircuitBreaker());
        listener.onFailure(new LimitExceededException(request.getDetectorId(), CommonErrorMessages.MEMORY_CIRCUIT_BROKEN_ERR_MSG, false));
        return;
    }
    try {
        String detectorId = request.getDetectorId();
        Optional<Exception> previousException = stateManager.fetchExceptionAndClear(detectorId);
        if (previousException.isPresent()) {
            Exception exception = previousException.get();
            LOG.error("Previous exception of {}: {}", detectorId, exception);
            if (exception instanceof EndRunException) {
                EndRunException endRunException = (EndRunException) exception;
                if (endRunException.isEndNow()) {
                    listener.onFailure(exception);
                    return;
                }
            }
            listener = ExceptionUtil.wrapListener(listener, exception, detectorId);
        }
        stateManager.getAnomalyDetector(detectorId, onGetDetector(listener, detectorId, request, previousException));
    } catch (Exception exception) {
        LOG.error("fail to get entity's anomaly grade", exception);
        listener.onFailure(exception);
    }
}
Also used : EndRunException(org.opensearch.ad.common.exception.EndRunException) LimitExceededException(org.opensearch.ad.common.exception.LimitExceededException) LimitExceededException(org.opensearch.ad.common.exception.LimitExceededException) EndRunException(org.opensearch.ad.common.exception.EndRunException)

Example 4 with LimitExceededException

use of org.opensearch.ad.common.exception.LimitExceededException in project anomaly-detection by opensearch-project.

the class RCFResultTransportAction method doExecute.

@Override
protected void doExecute(Task task, RCFResultRequest request, ActionListener<RCFResultResponse> listener) {
    if (adCircuitBreakerService.isOpen()) {
        listener.onFailure(new LimitExceededException(request.getAdID(), CommonErrorMessages.MEMORY_CIRCUIT_BROKEN_ERR_MSG));
        return;
    }
    Optional<DiscoveryNode> remoteNode = hashRing.getNodeByAddress(request.remoteAddress());
    if (!remoteNode.isPresent()) {
        listener.onFailure(new ConnectException("Can't find remote node by address"));
        return;
    }
    String remoteNodeId = remoteNode.get().getId();
    Version remoteAdVersion = hashRing.getAdVersion(remoteNodeId);
    try {
        LOG.info("Serve rcf request for {}", request.getModelID());
        manager.getTRcfResult(request.getAdID(), request.getModelID(), request.getFeatures(), ActionListener.wrap(result -> listener.onResponse(new RCFResultResponse(result.getRcfScore(), result.getConfidence(), result.getForestSize(), result.getRelevantAttribution(), result.getTotalUpdates(), result.getGrade(), remoteAdVersion, result.getRelativeIndex(), result.getPastValues(), result.getExpectedValuesList(), result.getLikelihoodOfValues(), result.getThreshold())), exception -> {
            LOG.warn(exception);
            listener.onFailure(exception);
        }));
    } catch (Exception e) {
        LOG.error(e);
        listener.onFailure(e);
    }
}
Also used : ADCircuitBreakerService(org.opensearch.ad.breaker.ADCircuitBreakerService) HandledTransportAction(org.opensearch.action.support.HandledTransportAction) ModelManager(org.opensearch.ad.ml.ModelManager) HashRing(org.opensearch.ad.cluster.HashRing) Version(org.opensearch.Version) Task(org.opensearch.tasks.Task) LimitExceededException(org.opensearch.ad.common.exception.LimitExceededException) TransportService(org.opensearch.transport.TransportService) ActionFilters(org.opensearch.action.support.ActionFilters) CommonErrorMessages(org.opensearch.ad.constant.CommonErrorMessages) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Logger(org.apache.logging.log4j.Logger) Optional(java.util.Optional) Inject(org.opensearch.common.inject.Inject) ConnectException(java.net.ConnectException) ActionListener(org.opensearch.action.ActionListener) LogManager(org.apache.logging.log4j.LogManager) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Version(org.opensearch.Version) LimitExceededException(org.opensearch.ad.common.exception.LimitExceededException) LimitExceededException(org.opensearch.ad.common.exception.LimitExceededException) ConnectException(java.net.ConnectException) ConnectException(java.net.ConnectException)

Example 5 with LimitExceededException

use of org.opensearch.ad.common.exception.LimitExceededException in project anomaly-detection by opensearch-project.

the class ADTaskManager method setHCDetectorTaskDone.

/**
 * Set state for HC detector level task when all entities done.
 *
 * The state could be FINISHED,FAILED or STOPPED.
 * 1. If input task state is FINISHED, will check FINISHED entity task count. If
 * there is no FINISHED entity task, will set HC detector level task as FAILED; otherwise
 * set as FINISHED.
 * 2. If input task state is not FINISHED, will set HC detector level task's state as the same.
 *
 * @param adTask AD task
 * @param state AD task state
 * @param listener action listener
 */
public void setHCDetectorTaskDone(ADTask adTask, ADTaskState state, ActionListener<AnomalyDetectorJobResponse> listener) {
    String detectorId = adTask.getDetectorId();
    String taskId = adTask.isEntityTask() ? adTask.getParentTaskId() : adTask.getTaskId();
    String detectorTaskId = adTask.getDetectorLevelTaskId();
    ActionListener<UpdateResponse> wrappedListener = ActionListener.wrap(response -> {
        logger.info("Historical HC detector done with state: {}. Remove from cache, detector id:{}", state.name(), detectorId);
        adTaskCacheManager.removeHistoricalTaskCache(detectorId);
    }, e -> {
        // Will reset task state when get detector with task or maintain tasks in hourly cron.
        if (e instanceof LimitExceededException && e.getMessage().contains(HC_DETECTOR_TASK_IS_UPDATING)) {
            logger.warn("HC task is updating, skip this update for task: " + taskId);
        } else {
            logger.error("Failed to update task: " + taskId, e);
        }
        adTaskCacheManager.removeHistoricalTaskCache(detectorId);
    });
    // wait for 2 seconds to acquire updating HC detector task semaphore
    long timeoutInMillis = 2000;
    if (state == ADTaskState.FINISHED) {
        this.countEntityTasksByState(detectorTaskId, ImmutableList.of(ADTaskState.FINISHED), ActionListener.wrap(r -> {
            logger.info("number of finished entity tasks: {}, for detector {}", r, adTask.getDetectorId());
            // Set task as FAILED if no finished entity task; otherwise set as FINISHED
            ADTaskState hcDetectorTaskState = r == 0 ? ADTaskState.FAILED : ADTaskState.FINISHED;
            // execute in AD batch task thread pool in case waiting for semaphore waste any shared OpenSearch thread pool
            threadPool.executor(AD_BATCH_TASK_THREAD_POOL_NAME).execute(() -> {
                updateADHCDetectorTask(detectorId, taskId, ImmutableMap.of(STATE_FIELD, hcDetectorTaskState.name(), TASK_PROGRESS_FIELD, 1.0, EXECUTION_END_TIME_FIELD, Instant.now().toEpochMilli()), timeoutInMillis, wrappedListener);
            });
        }, e -> {
            logger.error("Failed to get finished entity tasks", e);
            String errorMessage = getErrorMessage(e);
            threadPool.executor(AD_BATCH_TASK_THREAD_POOL_NAME).execute(() -> {
                updateADHCDetectorTask(detectorId, taskId, ImmutableMap.of(STATE_FIELD, // set as FAILED if fail to get finished entity tasks.
                ADTaskState.FAILED.name(), TASK_PROGRESS_FIELD, 1.0, ERROR_FIELD, errorMessage, EXECUTION_END_TIME_FIELD, Instant.now().toEpochMilli()), timeoutInMillis, wrappedListener);
            });
        }));
    } else {
        threadPool.executor(AD_BATCH_TASK_THREAD_POOL_NAME).execute(() -> {
            updateADHCDetectorTask(detectorId, taskId, ImmutableMap.of(STATE_FIELD, state.name(), ERROR_FIELD, adTask.getError(), EXECUTION_END_TIME_FIELD, Instant.now().toEpochMilli()), timeoutInMillis, wrappedListener);
        });
    }
    listener.onResponse(new AnomalyDetectorJobResponse(taskId, 0, 0, 0, RestStatus.OK));
}
Also used : PARENT_TASK_ID_FIELD(org.opensearch.ad.model.ADTask.PARENT_TASK_ID_FIELD) IndexResponse(org.opensearch.action.index.IndexResponse) HashRing(org.opensearch.ad.cluster.HashRing) Version(org.opensearch.Version) FAIL_TO_FIND_DETECTOR_MSG(org.opensearch.ad.constant.CommonErrorMessages.FAIL_TO_FIND_DETECTOR_MSG) BulkAction(org.opensearch.action.bulk.BulkAction) LimitExceededException(org.opensearch.ad.common.exception.LimitExceededException) ExceptionUtil.getShardsFailure(org.opensearch.ad.util.ExceptionUtil.getShardsFailure) ADTaskState(org.opensearch.ad.model.ADTaskState) AnomalyDetectorFunction(org.opensearch.ad.rest.handler.AnomalyDetectorFunction) STOPPED_BY_FIELD(org.opensearch.ad.model.ADTask.STOPPED_BY_FIELD) WriteRequest(org.opensearch.action.support.WriteRequest) ANOMALY_DETECTOR_JOB_INDEX(org.opensearch.ad.model.AnomalyDetectorJob.ANOMALY_DETECTOR_JOB_INDEX) MAX_OLD_AD_TASK_DOCS_PER_DETECTOR(org.opensearch.ad.settings.AnomalyDetectorSettings.MAX_OLD_AD_TASK_DOCS_PER_DETECTOR) Map(java.util.Map) ForwardADTaskAction(org.opensearch.ad.transport.ForwardADTaskAction) ActionListener(org.opensearch.action.ActionListener) DETECTOR_IS_RUNNING(org.opensearch.ad.constant.CommonErrorMessages.DETECTOR_IS_RUNNING) ADStatsNodeResponse(org.opensearch.ad.transport.ADStatsNodeResponse) DeleteRequest(org.opensearch.action.delete.DeleteRequest) MAX_RUNNING_ENTITIES_PER_DETECTOR_FOR_HISTORICAL_ANALYSIS(org.opensearch.ad.settings.AnomalyDetectorSettings.MAX_RUNNING_ENTITIES_PER_DETECTOR_FOR_HISTORICAL_ANALYSIS) Client(org.opensearch.client.Client) UpdateByQueryAction(org.opensearch.index.reindex.UpdateByQueryAction) AD_BATCH_TASK_THREAD_POOL_NAME(org.opensearch.ad.AnomalyDetectorPlugin.AD_BATCH_TASK_THREAD_POOL_NAME) ADTaskProfileRequest(org.opensearch.ad.transport.ADTaskProfileRequest) TimeValue(org.opensearch.common.unit.TimeValue) RestHandlerUtils.createXContentParserFromRegistry(org.opensearch.ad.util.RestHandlerUtils.createXContentParserFromRegistry) SearchHit(org.opensearch.search.SearchHit) TransportRequestOptions(org.opensearch.transport.TransportRequestOptions) Set(java.util.Set) ExceptionsHelper(org.opensearch.ExceptionsHelper) Settings(org.opensearch.common.settings.Settings) NO_ELIGIBLE_NODE_TO_RUN_DETECTOR(org.opensearch.ad.constant.CommonErrorMessages.NO_ELIGIBLE_NODE_TO_RUN_DETECTOR) IS_LATEST_FIELD(org.opensearch.ad.model.ADTask.IS_LATEST_FIELD) DETECTION_STATE_INDEX(org.opensearch.ad.constant.CommonName.DETECTION_STATE_INDEX) ScoreMode(org.apache.lucene.search.join.ScoreMode) TransportService(org.opensearch.transport.TransportService) Logger(org.apache.logging.log4j.Logger) CAN_NOT_FIND_LATEST_TASK(org.opensearch.ad.constant.CommonErrorMessages.CAN_NOT_FIND_LATEST_TASK) ADEntityTaskProfile(org.opensearch.ad.model.ADEntityTaskProfile) ActionListenerResponseHandler(org.opensearch.action.ActionListenerResponseHandler) TermsQueryBuilder(org.opensearch.index.query.TermsQueryBuilder) EXECUTION_END_TIME_FIELD(org.opensearch.ad.model.ADTask.EXECUTION_END_TIME_FIELD) UpdateRequest(org.opensearch.action.update.UpdateRequest) XContentType(org.opensearch.common.xcontent.XContentType) BoolQueryBuilder(org.opensearch.index.query.BoolQueryBuilder) BATCH_TASK_PIECE_INTERVAL_SECONDS(org.opensearch.ad.settings.AnomalyDetectorSettings.BATCH_TASK_PIECE_INTERVAL_SECONDS) MAX_BATCH_TASK_PER_NODE(org.opensearch.ad.settings.AnomalyDetectorSettings.MAX_BATCH_TASK_PER_NODE) UpdateResponse(org.opensearch.action.update.UpdateResponse) ThreadPool(org.opensearch.threadpool.ThreadPool) ADTaskType.taskTypeToString(org.opensearch.ad.model.ADTaskType.taskTypeToString) ADTaskProfile(org.opensearch.ad.model.ADTaskProfile) ArrayList(java.util.ArrayList) XCONTENT_WITH_TYPE(org.opensearch.ad.util.RestHandlerUtils.XCONTENT_WITH_TYPE) HC_DETECTOR_TASK_IS_UPDATING(org.opensearch.ad.constant.CommonErrorMessages.HC_DETECTOR_TASK_IS_UPDATING) AnomalyDetector(org.opensearch.ad.model.AnomalyDetector) ADCancelTaskAction(org.opensearch.ad.transport.ADCancelTaskAction) BiConsumer(java.util.function.BiConsumer) DeleteResponse(org.opensearch.action.delete.DeleteResponse) SearchRequest(org.opensearch.action.search.SearchRequest) INIT_PROGRESS_FIELD(org.opensearch.ad.model.ADTask.INIT_PROGRESS_FIELD) QueryBuilders(org.opensearch.index.query.QueryBuilders) ADStatsNodesAction(org.opensearch.ad.transport.ADStatsNodesAction) IOException(java.io.IOException) TotalHits(org.apache.lucene.search.TotalHits) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) ChronoUnit(java.time.temporal.ChronoUnit) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) ClusterService(org.opensearch.cluster.service.ClusterService) ExceptionUtil.getErrorMessage(org.opensearch.ad.util.ExceptionUtil.getErrorMessage) ADTaskAction(org.opensearch.ad.model.ADTaskAction) DeleteByQueryRequest(org.opensearch.index.reindex.DeleteByQueryRequest) AD_DETECTOR_ASSIGNED_BATCH_TASK_SLOT_COUNT(org.opensearch.ad.stats.InternalStatNames.AD_DETECTOR_ASSIGNED_BATCH_TASK_SLOT_COUNT) DeleteByQueryAction(org.opensearch.index.reindex.DeleteByQueryAction) COORDINATING_NODE_FIELD(org.opensearch.ad.model.ADTask.COORDINATING_NODE_FIELD) DELETE_AD_RESULT_WHEN_DELETE_DETECTOR(org.opensearch.ad.settings.AnomalyDetectorSettings.DELETE_AD_RESULT_WHEN_DELETE_DETECTOR) ResourceNotFoundException(org.opensearch.ad.common.exception.ResourceNotFoundException) MAX_OLD_AD_TASK_DOCS(org.opensearch.ad.settings.AnomalyDetectorSettings.MAX_OLD_AD_TASK_DOCS) ADBatchAnomalyResultAction(org.opensearch.ad.transport.ADBatchAnomalyResultAction) ToXContent(org.opensearch.common.xcontent.ToXContent) OpenSearchStatusException(org.opensearch.OpenSearchStatusException) BulkRequest(org.opensearch.action.bulk.BulkRequest) ERROR_FIELD(org.opensearch.ad.model.ADTask.ERROR_FIELD) EXECUTION_START_TIME_FIELD(org.opensearch.ad.model.ADTask.EXECUTION_START_TIME_FIELD) ParseUtils.isNullOrEmpty(org.opensearch.ad.util.ParseUtils.isNullOrEmpty) ADTaskCancelledException(org.opensearch.ad.common.exception.ADTaskCancelledException) ADStatsRequest(org.opensearch.ad.transport.ADStatsRequest) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) AnomalyDetectionException(org.opensearch.ad.common.exception.AnomalyDetectionException) XContentParser(org.opensearch.common.xcontent.XContentParser) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) IndexAnomalyDetectorJobActionHandler(org.opensearch.ad.rest.handler.IndexAnomalyDetectorJobActionHandler) DETECTOR_ID_FIELD(org.opensearch.ad.model.ADTask.DETECTOR_ID_FIELD) Locale(java.util.Locale) BulkItemResponse(org.opensearch.action.bulk.BulkItemResponse) XContentFactory(org.opensearch.common.xcontent.XContentFactory) REALTIME_TASK_TYPES(org.opensearch.ad.model.ADTaskType.REALTIME_TASK_TYPES) NestedQueryBuilder(org.opensearch.index.query.NestedQueryBuilder) TASK_PROGRESS_FIELD(org.opensearch.ad.model.ADTask.TASK_PROGRESS_FIELD) DetectorProfile(org.opensearch.ad.model.DetectorProfile) ImmutableSet(com.google.common.collect.ImmutableSet) ESTIMATED_MINUTES_LEFT_FIELD(org.opensearch.ad.model.ADTask.ESTIMATED_MINUTES_LEFT_FIELD) NOT_ENDED_STATES(org.opensearch.ad.model.ADTaskState.NOT_ENDED_STATES) ImmutableMap(com.google.common.collect.ImmutableMap) Script(org.opensearch.script.Script) LoggingDeprecationHandler(org.opensearch.common.xcontent.LoggingDeprecationHandler) ADTaskType(org.opensearch.ad.model.ADTaskType) XContentParserUtils.ensureExpectedToken(org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken) ADTaskProfileNodeResponse(org.opensearch.ad.transport.ADTaskProfileNodeResponse) LAST_UPDATE_TIME_FIELD(org.opensearch.ad.model.ADTask.LAST_UPDATE_TIME_FIELD) Instant(java.time.Instant) RestStatus(org.opensearch.rest.RestStatus) Collectors(java.util.stream.Collectors) TASK_TYPE_FIELD(org.opensearch.ad.model.ADTask.TASK_TYPE_FIELD) Objects(java.util.Objects) AnomalyDetectorJobResponse(org.opensearch.ad.transport.AnomalyDetectorJobResponse) List(java.util.List) ForwardADTaskRequest(org.opensearch.ad.transport.ForwardADTaskRequest) DuplicateTaskException(org.opensearch.ad.common.exception.DuplicateTaskException) SearchSourceBuilder(org.opensearch.search.builder.SearchSourceBuilder) CREATED(org.opensearch.action.DocWriteResponse.Result.CREATED) DetectionDateRange(org.opensearch.ad.model.DetectionDateRange) NUM_MIN_SAMPLES(org.opensearch.ad.settings.AnomalyDetectorSettings.NUM_MIN_SAMPLES) Optional(java.util.Optional) ResourceAlreadyExistsException(org.opensearch.ResourceAlreadyExistsException) ALL_HISTORICAL_TASK_TYPES(org.opensearch.ad.model.ADTaskType.ALL_HISTORICAL_TASK_TYPES) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) RestHandlerUtils(org.opensearch.ad.util.RestHandlerUtils) TASK_ID_FIELD(org.opensearch.ad.model.AnomalyResult.TASK_ID_FIELD) REQUEST_TIMEOUT(org.opensearch.ad.settings.AnomalyDetectorSettings.REQUEST_TIMEOUT) DiscoveryNodeFilterer(org.opensearch.ad.util.DiscoveryNodeFilterer) BytesReference(org.opensearch.common.bytes.BytesReference) ADTask(org.opensearch.ad.model.ADTask) HashMap(java.util.HashMap) SortOrder(org.opensearch.search.sort.SortOrder) ImmutableList(com.google.common.collect.ImmutableList) EXCEED_HISTORICAL_ANALYSIS_LIMIT(org.opensearch.ad.constant.CommonErrorMessages.EXCEED_HISTORICAL_ANALYSIS_LIMIT) ADCancelTaskRequest(org.opensearch.ad.transport.ADCancelTaskRequest) SearchResponse(org.opensearch.action.search.SearchResponse) EndRunException(org.opensearch.ad.common.exception.EndRunException) ADBatchAnomalyResultRequest(org.opensearch.ad.transport.ADBatchAnomalyResultRequest) HISTORICAL_DETECTOR_TASK_TYPES(org.opensearch.ad.model.ADTaskType.HISTORICAL_DETECTOR_TASK_TYPES) Iterator(java.util.Iterator) ALL_AD_RESULTS_INDEX_PATTERN(org.opensearch.ad.indices.AnomalyDetectionIndices.ALL_AD_RESULTS_INDEX_PATTERN) Semaphore(java.util.concurrent.Semaphore) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) ANOMALY_DETECTORS_INDEX(org.opensearch.ad.model.AnomalyDetector.ANOMALY_DETECTORS_INDEX) GetRequest(org.opensearch.action.get.GetRequest) TermQueryBuilder(org.opensearch.index.query.TermQueryBuilder) AnomalyDetectionIndices(org.opensearch.ad.indices.AnomalyDetectionIndices) STATE_FIELD(org.opensearch.ad.model.ADTask.STATE_FIELD) CREATE_INDEX_NOT_ACKNOWLEDGED(org.opensearch.ad.constant.CommonErrorMessages.CREATE_INDEX_NOT_ACKNOWLEDGED) Consumer(java.util.function.Consumer) UpdateByQueryRequest(org.opensearch.index.reindex.UpdateByQueryRequest) AD_USED_BATCH_TASK_SLOT_COUNT(org.opensearch.ad.stats.InternalStatNames.AD_USED_BATCH_TASK_SLOT_COUNT) Entity(org.opensearch.ad.model.Entity) User(org.opensearch.commons.authuser.User) AnomalyDetectorJob(org.opensearch.ad.model.AnomalyDetectorJob) IndexRequest(org.opensearch.action.index.IndexRequest) LogManager(org.apache.logging.log4j.LogManager) ADTaskProfileAction(org.opensearch.ad.transport.ADTaskProfileAction) UpdateResponse(org.opensearch.action.update.UpdateResponse) AnomalyDetectorJobResponse(org.opensearch.ad.transport.AnomalyDetectorJobResponse) LimitExceededException(org.opensearch.ad.common.exception.LimitExceededException) ADTaskType.taskTypeToString(org.opensearch.ad.model.ADTaskType.taskTypeToString) ADTaskState(org.opensearch.ad.model.ADTaskState)

Aggregations

LimitExceededException (org.opensearch.ad.common.exception.LimitExceededException)13 ActionListener (org.opensearch.action.ActionListener)6 AnomalyDetectionException (org.opensearch.ad.common.exception.AnomalyDetectionException)5 EndRunException (org.opensearch.ad.common.exception.EndRunException)5 ModelManager (org.opensearch.ad.ml.ModelManager)5 Instant (java.time.Instant)4 ArrayList (java.util.ArrayList)4 Optional (java.util.Optional)4 LogManager (org.apache.logging.log4j.LogManager)4 Logger (org.apache.logging.log4j.Logger)4 HashRing (org.opensearch.ad.cluster.HashRing)4 ResourceNotFoundException (org.opensearch.ad.common.exception.ResourceNotFoundException)4 AnomalyDetector (org.opensearch.ad.model.AnomalyDetector)4 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)4 TransportService (org.opensearch.transport.TransportService)4 ConnectException (java.net.ConnectException)3 List (java.util.List)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 ActionListenerResponseHandler (org.opensearch.action.ActionListenerResponseHandler)3