Search in sources :

Example 1 with FAIL_TO_FIND_DETECTOR_MSG

use of org.opensearch.ad.constant.CommonErrorMessages.FAIL_TO_FIND_DETECTOR_MSG in project anomaly-detection by opensearch-project.

the class AnomalyDetectorProfileRunner method calculateTotalResponsesToWait.

private void calculateTotalResponsesToWait(String detectorId, Set<DetectorProfileName> profilesToCollect, ActionListener<DetectorProfile> listener) {
    GetRequest getDetectorRequest = new GetRequest(ANOMALY_DETECTORS_INDEX, detectorId);
    client.get(getDetectorRequest, ActionListener.wrap(getDetectorResponse -> {
        if (getDetectorResponse != null && getDetectorResponse.isExists()) {
            try (XContentParser xContentParser = XContentType.JSON.xContent().createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, getDetectorResponse.getSourceAsString())) {
                ensureExpectedToken(XContentParser.Token.START_OBJECT, xContentParser.nextToken(), xContentParser);
                AnomalyDetector detector = AnomalyDetector.parse(xContentParser, detectorId);
                prepareProfile(detector, listener, profilesToCollect);
            } catch (Exception e) {
                logger.error(FAIL_TO_PARSE_DETECTOR_MSG + detectorId, e);
                listener.onFailure(new OpenSearchStatusException(FAIL_TO_PARSE_DETECTOR_MSG + detectorId, BAD_REQUEST));
            }
        } else {
            listener.onFailure(new OpenSearchStatusException(FAIL_TO_FIND_DETECTOR_MSG + detectorId, BAD_REQUEST));
        }
    }, exception -> {
        logger.error(FAIL_TO_FIND_DETECTOR_MSG + detectorId, exception);
        listener.onFailure(new OpenSearchStatusException(FAIL_TO_FIND_DETECTOR_MSG + detectorId, INTERNAL_SERVER_ERROR));
    }));
}
Also used : Aggregation(org.opensearch.search.aggregations.Aggregation) ResourceNotFoundException(org.opensearch.ad.common.exception.ResourceNotFoundException) OpenSearchStatusException(org.opensearch.OpenSearchStatusException) FAIL_TO_FIND_DETECTOR_MSG(org.opensearch.ad.constant.CommonErrorMessages.FAIL_TO_FIND_DETECTOR_MSG) XContentParser(org.opensearch.common.xcontent.XContentParser) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) AggregationBuilder(org.opensearch.search.aggregations.AggregationBuilder) Throwables(org.apache.logging.log4j.core.util.Throwables) ANOMALY_DETECTOR_JOB_INDEX(org.opensearch.ad.model.AnomalyDetectorJob.ANOMALY_DETECTOR_JOB_INDEX) Map(java.util.Map) RCFPollingAction(org.opensearch.ad.transport.RCFPollingAction) ActionListener(org.opensearch.action.ActionListener) DetectorProfile(org.opensearch.ad.model.DetectorProfile) Client(org.opensearch.client.Client) NumericSetting(org.opensearch.ad.settings.NumericSetting) LoggingDeprecationHandler(org.opensearch.common.xcontent.LoggingDeprecationHandler) Set(java.util.Set) ADTaskType(org.opensearch.ad.model.ADTaskType) XContentParserUtils.ensureExpectedToken(org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken) ADTaskManager(org.opensearch.ad.task.ADTaskManager) Collectors(java.util.stream.Collectors) TransportService(org.opensearch.transport.TransportService) MultiResponsesDelegateActionListener(org.opensearch.ad.util.MultiResponsesDelegateActionListener) List(java.util.List) Logger(org.apache.logging.log4j.Logger) AnomalyResult(org.opensearch.ad.model.AnomalyResult) ExceptionUtil(org.opensearch.ad.util.ExceptionUtil) CardinalityAggregationBuilder(org.opensearch.search.aggregations.metrics.CardinalityAggregationBuilder) DetectorState(org.opensearch.ad.model.DetectorState) INTERNAL_SERVER_ERROR(org.opensearch.rest.RestStatus.INTERNAL_SERVER_ERROR) SearchSourceBuilder(org.opensearch.search.builder.SearchSourceBuilder) XContentType(org.opensearch.common.xcontent.XContentType) TermsValuesSourceBuilder(org.opensearch.search.aggregations.bucket.composite.TermsValuesSourceBuilder) BoolQueryBuilder(org.opensearch.index.query.BoolQueryBuilder) DiscoveryNodeFilterer(org.opensearch.ad.util.DiscoveryNodeFilterer) Aggregations(org.opensearch.search.aggregations.Aggregations) SearchHits(org.opensearch.search.SearchHits) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) AnomalyDetectorSettings(org.opensearch.ad.settings.AnomalyDetectorSettings) ProfileRequest(org.opensearch.ad.transport.ProfileRequest) AnomalyDetector(org.opensearch.ad.model.AnomalyDetector) SearchRequest(org.opensearch.action.search.SearchRequest) SearchResponse(org.opensearch.action.search.SearchResponse) InternalCardinality(org.opensearch.search.aggregations.metrics.InternalCardinality) ProfileResponse(org.opensearch.ad.transport.ProfileResponse) QueryBuilders(org.opensearch.index.query.QueryBuilders) CommonName(org.opensearch.ad.constant.CommonName) InitProgressProfile(org.opensearch.ad.model.InitProgressProfile) ANOMALY_DETECTORS_INDEX(org.opensearch.ad.model.AnomalyDetector.ANOMALY_DETECTORS_INDEX) GetRequest(org.opensearch.action.get.GetRequest) NotSerializedADExceptionName(org.opensearch.ad.common.exception.NotSerializedADExceptionName) DetectorProfileName(org.opensearch.ad.model.DetectorProfileName) CompositeAggregation(org.opensearch.search.aggregations.bucket.composite.CompositeAggregation) RCFPollingResponse(org.opensearch.ad.transport.RCFPollingResponse) AggregationBuilders(org.opensearch.search.aggregations.AggregationBuilders) FAIL_TO_PARSE_DETECTOR_MSG(org.opensearch.ad.constant.CommonErrorMessages.FAIL_TO_PARSE_DETECTOR_MSG) CommonErrorMessages(org.opensearch.ad.constant.CommonErrorMessages) RCFPollingRequest(org.opensearch.ad.transport.RCFPollingRequest) AnomalyDetectorJob(org.opensearch.ad.model.AnomalyDetectorJob) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) IntervalTimeConfiguration(org.opensearch.ad.model.IntervalTimeConfiguration) LogManager(org.apache.logging.log4j.LogManager) BAD_REQUEST(org.opensearch.rest.RestStatus.BAD_REQUEST) ProfileAction(org.opensearch.ad.transport.ProfileAction) GetRequest(org.opensearch.action.get.GetRequest) XContentParser(org.opensearch.common.xcontent.XContentParser) AnomalyDetector(org.opensearch.ad.model.AnomalyDetector) ResourceNotFoundException(org.opensearch.ad.common.exception.ResourceNotFoundException) OpenSearchStatusException(org.opensearch.OpenSearchStatusException) OpenSearchStatusException(org.opensearch.OpenSearchStatusException)

Aggregations

List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 Throwables (org.apache.logging.log4j.core.util.Throwables)1 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)1 OpenSearchStatusException (org.opensearch.OpenSearchStatusException)1 ActionListener (org.opensearch.action.ActionListener)1 GetRequest (org.opensearch.action.get.GetRequest)1 SearchRequest (org.opensearch.action.search.SearchRequest)1 SearchResponse (org.opensearch.action.search.SearchResponse)1 NotSerializedADExceptionName (org.opensearch.ad.common.exception.NotSerializedADExceptionName)1 ResourceNotFoundException (org.opensearch.ad.common.exception.ResourceNotFoundException)1 CommonErrorMessages (org.opensearch.ad.constant.CommonErrorMessages)1 FAIL_TO_FIND_DETECTOR_MSG (org.opensearch.ad.constant.CommonErrorMessages.FAIL_TO_FIND_DETECTOR_MSG)1 FAIL_TO_PARSE_DETECTOR_MSG (org.opensearch.ad.constant.CommonErrorMessages.FAIL_TO_PARSE_DETECTOR_MSG)1 CommonName (org.opensearch.ad.constant.CommonName)1 ADTaskType (org.opensearch.ad.model.ADTaskType)1