Search in sources :

Example 1 with ProfileRequest

use of org.opensearch.ad.transport.ProfileRequest in project anomaly-detection by opensearch-project.

the class AnomalyDetectorJobRunner method updateRealtimeTask.

private void updateRealtimeTask(AnomalyResultResponse response, String detectorId) {
    if (response.isHCDetector() != null && response.isHCDetector() && !adTaskManager.skipUpdateHCRealtimeTask(detectorId, response.getError())) {
        DiscoveryNode[] dataNodes = nodeFilter.getEligibleDataNodes();
        Set<DetectorProfileName> profiles = new HashSet<>();
        profiles.add(DetectorProfileName.INIT_PROGRESS);
        ProfileRequest profileRequest = new ProfileRequest(detectorId, profiles, true, dataNodes);
        client.execute(ProfileAction.INSTANCE, profileRequest, ActionListener.wrap(r -> {
            log.debug("Update latest realtime task for HC detector {}, total updates: {}", detectorId, r.getTotalUpdates());
            updateLatestRealtimeTask(detectorId, null, r.getTotalUpdates(), response.getDetectorIntervalInMinutes(), response.getError());
        }, e -> {
            log.error("Failed to update latest realtime task for " + detectorId, e);
        }));
    } else {
        log.debug("Update latest realtime task for SINGLE detector {}, total updates: {}", detectorId, response.getRcfTotalUpdates());
        updateLatestRealtimeTask(detectorId, null, response.getRcfTotalUpdates(), response.getDetectorIntervalInMinutes(), response.getError());
    }
}
Also used : ResourceNotFoundException(org.opensearch.ad.common.exception.ResourceNotFoundException) ADTaskState(org.opensearch.ad.model.ADTaskState) AnomalyDetectionException(org.opensearch.ad.common.exception.AnomalyDetectionException) AnomalyDetectorFunction(org.opensearch.ad.rest.handler.AnomalyDetectorFunction) XContentParser(org.opensearch.common.xcontent.XContentParser) AD_THREAD_POOL_NAME(org.opensearch.ad.AnomalyDetectorPlugin.AD_THREAD_POOL_NAME) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) WriteRequest(org.opensearch.action.support.WriteRequest) ADIndex(org.opensearch.ad.indices.ADIndex) ActionListener(org.opensearch.action.ActionListener) GetResponse(org.opensearch.action.get.GetResponse) Client(org.opensearch.client.Client) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LoggingDeprecationHandler(org.opensearch.common.xcontent.LoggingDeprecationHandler) Set(java.util.Set) XContentParserUtils.ensureExpectedToken(org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken) ADTaskManager(org.opensearch.ad.task.ADTaskManager) Settings(org.opensearch.common.settings.Settings) Instant(java.time.Instant) UPDATED(org.opensearch.action.DocWriteResponse.Result.UPDATED) List(java.util.List) AnomalyResultAction(org.opensearch.ad.transport.AnomalyResultAction) Logger(org.apache.logging.log4j.Logger) AnomalyResult(org.opensearch.ad.model.AnomalyResult) CAN_NOT_FIND_LATEST_TASK(org.opensearch.ad.constant.CommonErrorMessages.CAN_NOT_FIND_LATEST_TASK) CREATED(org.opensearch.action.DocWriteResponse.Result.CREATED) IntervalSchedule(org.opensearch.jobscheduler.spi.schedule.IntervalSchedule) XContentType(org.opensearch.common.xcontent.XContentType) InjectSecurity(org.opensearch.commons.InjectSecurity) JobExecutionContext(org.opensearch.jobscheduler.spi.JobExecutionContext) DiscoveryNodeFilterer(org.opensearch.ad.util.DiscoveryNodeFilterer) AnomalyIndexHandler(org.opensearch.ad.transport.handler.AnomalyIndexHandler) AnomalyResultRequest(org.opensearch.ad.transport.AnomalyResultRequest) ThreadPool(org.opensearch.threadpool.ThreadPool) FeatureData(org.opensearch.ad.model.FeatureData) AnomalyDetectorSettings(org.opensearch.ad.settings.AnomalyDetectorSettings) ArrayList(java.util.ArrayList) ProfileRequest(org.opensearch.ad.transport.ProfileRequest) XCONTENT_WITH_TYPE(org.opensearch.ad.util.RestHandlerUtils.XCONTENT_WITH_TYPE) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) LockModel(org.opensearch.jobscheduler.spi.LockModel) ExecutorService(java.util.concurrent.ExecutorService) EndRunException(org.opensearch.ad.common.exception.EndRunException) LockService(org.opensearch.jobscheduler.spi.utils.LockService) InternalFailure(org.opensearch.ad.common.exception.InternalFailure) GetRequest(org.opensearch.action.get.GetRequest) Throwables(com.google.common.base.Throwables) IOException(java.io.IOException) AnomalyDetectionIndices(org.opensearch.ad.indices.AnomalyDetectionIndices) DetectorProfileName(org.opensearch.ad.model.DetectorProfileName) ScheduledJobParameter(org.opensearch.jobscheduler.spi.ScheduledJobParameter) AnomalyResultTransportAction(org.opensearch.ad.transport.AnomalyResultTransportAction) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) User(org.opensearch.commons.authuser.User) AnomalyResultResponse(org.opensearch.ad.transport.AnomalyResultResponse) AnomalyDetectorJob(org.opensearch.ad.model.AnomalyDetectorJob) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) ScheduledJobRunner(org.opensearch.jobscheduler.spi.ScheduledJobRunner) IndexRequest(org.opensearch.action.index.IndexRequest) IntervalTimeConfiguration(org.opensearch.ad.model.IntervalTimeConfiguration) LogManager(org.apache.logging.log4j.LogManager) ProfileAction(org.opensearch.ad.transport.ProfileAction) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) DetectorProfileName(org.opensearch.ad.model.DetectorProfileName) ProfileRequest(org.opensearch.ad.transport.ProfileRequest) HashSet(java.util.HashSet)

Example 2 with ProfileRequest

use of org.opensearch.ad.transport.ProfileRequest in project anomaly-detection by opensearch-project.

the class AnomalyDetectorProfileRunner method profileModels.

private void profileModels(AnomalyDetector detector, Set<DetectorProfileName> profiles, AnomalyDetectorJob job, boolean forMultiEntityDetector, MultiResponsesDelegateActionListener<DetectorProfile> listener) {
    DiscoveryNode[] dataNodes = nodeFilter.getEligibleDataNodes();
    ProfileRequest profileRequest = new ProfileRequest(detector.getDetectorId(), profiles, forMultiEntityDetector, dataNodes);
    // get init progress
    client.execute(ProfileAction.INSTANCE, profileRequest, onModelResponse(detector, profiles, job, listener));
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) ProfileRequest(org.opensearch.ad.transport.ProfileRequest)

Aggregations

Throwables (com.google.common.base.Throwables)1 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 ActionListener (org.opensearch.action.ActionListener)1 CREATED (org.opensearch.action.DocWriteResponse.Result.CREATED)1 UPDATED (org.opensearch.action.DocWriteResponse.Result.UPDATED)1 GetRequest (org.opensearch.action.get.GetRequest)1 GetResponse (org.opensearch.action.get.GetResponse)1 IndexRequest (org.opensearch.action.index.IndexRequest)1 WriteRequest (org.opensearch.action.support.WriteRequest)1 AD_THREAD_POOL_NAME (org.opensearch.ad.AnomalyDetectorPlugin.AD_THREAD_POOL_NAME)1