Search in sources :

Example 1 with InitProgressProfile

use of org.opensearch.ad.model.InitProgressProfile in project anomaly-detection by opensearch-project.

the class CacheBuffer method equals.

@Override
public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    if (obj instanceof InitProgressProfile) {
        CacheBuffer other = (CacheBuffer) obj;
        EqualsBuilder equalsBuilder = new EqualsBuilder();
        equalsBuilder.append(detectorId, other.detectorId);
        return equalsBuilder.isEquals();
    }
    return false;
}
Also used : InitProgressProfile(org.opensearch.ad.model.InitProgressProfile) EqualsBuilder(org.apache.commons.lang.builder.EqualsBuilder)

Example 2 with InitProgressProfile

use of org.opensearch.ad.model.InitProgressProfile in project anomaly-detection by opensearch-project.

the class EntityProfileRunner method sendRunningState.

private void sendRunningState(Set<EntityProfileName> profilesToCollect, Entity entityValue, MultiResponsesDelegateActionListener<EntityProfile> delegateListener) {
    EntityProfile.Builder builder = new EntityProfile.Builder();
    if (profilesToCollect.contains(EntityProfileName.STATE)) {
        builder.state(EntityState.RUNNING);
    }
    if (profilesToCollect.contains(EntityProfileName.INIT_PROGRESS)) {
        InitProgressProfile initProgress = new InitProgressProfile("100%", 0, 0);
        builder.initProgress(initProgress);
    }
    delegateListener.onResponse(builder.build());
}
Also used : NestedQueryBuilder(org.opensearch.index.query.NestedQueryBuilder) TermQueryBuilder(org.opensearch.index.query.TermQueryBuilder) SearchSourceBuilder(org.opensearch.search.builder.SearchSourceBuilder) BoolQueryBuilder(org.opensearch.index.query.BoolQueryBuilder) InitProgressProfile(org.opensearch.ad.model.InitProgressProfile) EntityProfile(org.opensearch.ad.model.EntityProfile)

Example 3 with InitProgressProfile

use of org.opensearch.ad.model.InitProgressProfile in project anomaly-detection by opensearch-project.

the class AnomalyDetectorProfileRunner method processInitResponse.

private void processInitResponse(AnomalyDetector detector, Set<DetectorProfileName> profilesToCollect, long totalUpdates, boolean hideMinutesLeft, DetectorProfile.Builder builder, MultiResponsesDelegateActionListener<DetectorProfile> listener) {
    if (profilesToCollect.contains(DetectorProfileName.STATE)) {
        builder.state(DetectorState.INIT);
    }
    if (profilesToCollect.contains(DetectorProfileName.INIT_PROGRESS)) {
        if (hideMinutesLeft) {
            InitProgressProfile initProgress = computeInitProgressProfile(totalUpdates, 0);
            builder.initProgress(initProgress);
        } else {
            long intervalMins = ((IntervalTimeConfiguration) detector.getDetectionInterval()).toDuration().toMinutes();
            InitProgressProfile initProgress = computeInitProgressProfile(totalUpdates, intervalMins);
            builder.initProgress(initProgress);
        }
    }
    listener.onResponse(builder.build());
}
Also used : InitProgressProfile(org.opensearch.ad.model.InitProgressProfile)

Example 4 with InitProgressProfile

use of org.opensearch.ad.model.InitProgressProfile in project anomaly-detection by opensearch-project.

the class AnomalyDetectorProfileRunnerTests method testInitNoUpdateNoIndex.

public void testInitNoUpdateNoIndex() throws IOException, InterruptedException {
    setUpClientGet(DetectorStatus.EXIST, JobStatus.ENABLED, RCFPollingStatus.EMPTY, ErrorResultStatus.NO_ERROR);
    DetectorProfile expectedProfile = new DetectorProfile.Builder().state(DetectorState.INIT).initProgress(new InitProgressProfile("0%", detectorIntervalMin * requiredSamples, requiredSamples)).build();
    final CountDownLatch inProgressLatch = new CountDownLatch(1);
    runner.profile(detector.getDetectorId(), ActionListener.wrap(response -> {
        assertEquals(expectedProfile, response);
        inProgressLatch.countDown();
    }, exception -> {
        LOG.error(exception);
        for (StackTraceElement ste : exception.getStackTrace()) {
            LOG.info(ste);
        }
        assertTrue("Should not reach here ", false);
        inProgressLatch.countDown();
    }), stateInitProgress);
    assertTrue(inProgressLatch.await(100, TimeUnit.SECONDS));
}
Also used : Arrays(java.util.Arrays) ResourceNotFoundException(org.opensearch.ad.common.exception.ResourceNotFoundException) Version(org.opensearch.Version) AnomalyDetectionException(org.opensearch.ad.common.exception.AnomalyDetectionException) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) ANOMALY_DETECTOR_JOB_INDEX(org.opensearch.ad.model.AnomalyDetectorJob.ANOMALY_DETECTOR_JOB_INDEX) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) RCFPollingAction(org.opensearch.ad.transport.RCFPollingAction) ActionListener(org.opensearch.action.ActionListener) GetResponse(org.opensearch.action.get.GetResponse) ProfileNodeResponse(org.opensearch.ad.transport.ProfileNodeResponse) DetectorProfile(org.opensearch.ad.model.DetectorProfile) RemoteTransportException(org.opensearch.transport.RemoteTransportException) Set(java.util.Set) Instant(java.time.Instant) TransportAddress(org.opensearch.common.transport.TransportAddress) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) DetectorState(org.opensearch.ad.model.DetectorState) DetectorInternalState(org.opensearch.ad.model.DetectorInternalState) Optional(java.util.Optional) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) NotSerializableExceptionWrapper(org.opensearch.common.io.stream.NotSerializableExceptionWrapper) ADTask(org.opensearch.ad.model.ADTask) HashMap(java.util.HashMap) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) ModelProfileOnNode(org.opensearch.ad.model.ModelProfileOnNode) ArrayList(java.util.ArrayList) AnomalyDetector(org.opensearch.ad.model.AnomalyDetector) ProfileResponse(org.opensearch.ad.transport.ProfileResponse) Collections.emptyMap(java.util.Collections.emptyMap) CommonName(org.opensearch.ad.constant.CommonName) Collections.emptySet(java.util.Collections.emptySet) FailedNodeException(org.opensearch.action.FailedNodeException) InitProgressProfile(org.opensearch.ad.model.InitProgressProfile) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) ANOMALY_DETECTORS_INDEX(org.opensearch.ad.model.AnomalyDetector.ANOMALY_DETECTORS_INDEX) GetRequest(org.opensearch.action.get.GetRequest) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) DetectorProfileName(org.opensearch.ad.model.DetectorProfileName) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) RCFPollingResponse(org.opensearch.ad.transport.RCFPollingResponse) CommonErrorMessages(org.opensearch.ad.constant.CommonErrorMessages) ChronoUnit(java.time.temporal.ChronoUnit) AnomalyDetectorJob(org.opensearch.ad.model.AnomalyDetectorJob) ClusterName(org.opensearch.cluster.ClusterName) IntervalTimeConfiguration(org.opensearch.ad.model.IntervalTimeConfiguration) Collections(java.util.Collections) ProfileAction(org.opensearch.ad.transport.ProfileAction) InitProgressProfile(org.opensearch.ad.model.InitProgressProfile) DetectorProfile(org.opensearch.ad.model.DetectorProfile) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 5 with InitProgressProfile

use of org.opensearch.ad.model.InitProgressProfile in project anomaly-detection by opensearch-project.

the class AnomalyDetectorProfileRunnerTests method testInitProgressFailImmediately.

public void testInitProgressFailImmediately() throws IOException, InterruptedException {
    setUpClientGet(DetectorStatus.NO_DOC, JobStatus.ENABLED, RCFPollingStatus.INITTING, ErrorResultStatus.NO_ERROR);
    DetectorProfile expectedProfile = new DetectorProfile.Builder().state(DetectorState.INIT).build();
    // 123 / 128 rounded to 96%
    InitProgressProfile profile = new InitProgressProfile("96%", neededSamples * detectorIntervalMin, neededSamples);
    expectedProfile.setInitProgress(profile);
    final CountDownLatch inProgressLatch = new CountDownLatch(1);
    runner.profile(detector.getDetectorId(), ActionListener.wrap(response -> {
        assertTrue("Should not reach here ", false);
        inProgressLatch.countDown();
    }, exception -> {
        assertTrue(exception.getMessage().contains(CommonErrorMessages.FAIL_TO_FIND_DETECTOR_MSG));
        inProgressLatch.countDown();
    }), stateInitProgress);
    assertTrue(inProgressLatch.await(100, TimeUnit.SECONDS));
}
Also used : Arrays(java.util.Arrays) ResourceNotFoundException(org.opensearch.ad.common.exception.ResourceNotFoundException) Version(org.opensearch.Version) AnomalyDetectionException(org.opensearch.ad.common.exception.AnomalyDetectionException) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) ANOMALY_DETECTOR_JOB_INDEX(org.opensearch.ad.model.AnomalyDetectorJob.ANOMALY_DETECTOR_JOB_INDEX) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) RCFPollingAction(org.opensearch.ad.transport.RCFPollingAction) ActionListener(org.opensearch.action.ActionListener) GetResponse(org.opensearch.action.get.GetResponse) ProfileNodeResponse(org.opensearch.ad.transport.ProfileNodeResponse) DetectorProfile(org.opensearch.ad.model.DetectorProfile) RemoteTransportException(org.opensearch.transport.RemoteTransportException) Set(java.util.Set) Instant(java.time.Instant) TransportAddress(org.opensearch.common.transport.TransportAddress) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) DetectorState(org.opensearch.ad.model.DetectorState) DetectorInternalState(org.opensearch.ad.model.DetectorInternalState) Optional(java.util.Optional) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) NotSerializableExceptionWrapper(org.opensearch.common.io.stream.NotSerializableExceptionWrapper) ADTask(org.opensearch.ad.model.ADTask) HashMap(java.util.HashMap) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) ModelProfileOnNode(org.opensearch.ad.model.ModelProfileOnNode) ArrayList(java.util.ArrayList) AnomalyDetector(org.opensearch.ad.model.AnomalyDetector) ProfileResponse(org.opensearch.ad.transport.ProfileResponse) Collections.emptyMap(java.util.Collections.emptyMap) CommonName(org.opensearch.ad.constant.CommonName) Collections.emptySet(java.util.Collections.emptySet) FailedNodeException(org.opensearch.action.FailedNodeException) InitProgressProfile(org.opensearch.ad.model.InitProgressProfile) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) ANOMALY_DETECTORS_INDEX(org.opensearch.ad.model.AnomalyDetector.ANOMALY_DETECTORS_INDEX) GetRequest(org.opensearch.action.get.GetRequest) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) DetectorProfileName(org.opensearch.ad.model.DetectorProfileName) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) RCFPollingResponse(org.opensearch.ad.transport.RCFPollingResponse) CommonErrorMessages(org.opensearch.ad.constant.CommonErrorMessages) ChronoUnit(java.time.temporal.ChronoUnit) AnomalyDetectorJob(org.opensearch.ad.model.AnomalyDetectorJob) ClusterName(org.opensearch.cluster.ClusterName) IntervalTimeConfiguration(org.opensearch.ad.model.IntervalTimeConfiguration) Collections(java.util.Collections) ProfileAction(org.opensearch.ad.transport.ProfileAction) InitProgressProfile(org.opensearch.ad.model.InitProgressProfile) DetectorProfile(org.opensearch.ad.model.DetectorProfile) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

InitProgressProfile (org.opensearch.ad.model.InitProgressProfile)11 AnomalyDetector (org.opensearch.ad.model.AnomalyDetector)6 AnomalyDetectorJob (org.opensearch.ad.model.AnomalyDetectorJob)6 IOException (java.io.IOException)5 ChronoUnit (java.time.temporal.ChronoUnit)5 Arrays (java.util.Arrays)5 Collections (java.util.Collections)5 Collections.emptyMap (java.util.Collections.emptyMap)5 Map (java.util.Map)5 Set (java.util.Set)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 TimeUnit (java.util.concurrent.TimeUnit)5 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)5 Mockito.doAnswer (org.mockito.Mockito.doAnswer)5 ActionListener (org.opensearch.action.ActionListener)5 GetRequest (org.opensearch.action.get.GetRequest)5 GetResponse (org.opensearch.action.get.GetResponse)5 CommonErrorMessages (org.opensearch.ad.constant.CommonErrorMessages)5 CommonName (org.opensearch.ad.constant.CommonName)5 ADTask (org.opensearch.ad.model.ADTask)5