Search in sources :

Example 1 with DetectorProfile

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

the class MultiEntityProfileRunnerTests method testRunning.

public void testRunning() throws InterruptedException {
    setUpClientExecuteProfileAction(InittedEverResultStatus.INITTED);
    setUpClientSearch(InittedEverResultStatus.INITTED);
    final CountDownLatch inProgressLatch = new CountDownLatch(1);
    DetectorProfile expectedProfile = new DetectorProfile.Builder().state(DetectorState.RUNNING).build();
    runner.profile(detectorId, ActionListener.wrap(response -> {
        assertEquals(expectedProfile, response);
        inProgressLatch.countDown();
    }, exception -> {
        assertTrue("Should not reach here", false);
        inProgressLatch.countDown();
    }), stateNError);
    assertTrue(inProgressLatch.await(100, TimeUnit.SECONDS));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) DiscoveryNodeFilterer(org.opensearch.ad.util.DiscoveryNodeFilterer) ADTask(org.opensearch.ad.model.ADTask) HashMap(java.util.HashMap) Version(org.opensearch.Version) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) 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) AnomalyDetector(org.opensearch.ad.model.AnomalyDetector) SearchRequest(org.opensearch.action.search.SearchRequest) ActionListener(org.opensearch.action.ActionListener) SearchResponse(org.opensearch.action.search.SearchResponse) GetResponse(org.opensearch.action.get.GetResponse) Before(org.junit.Before) ProfileNodeResponse(org.opensearch.ad.transport.ProfileNodeResponse) ProfileResponse(org.opensearch.ad.transport.ProfileResponse) Collections.emptyMap(java.util.Collections.emptyMap) DetectorProfile(org.opensearch.ad.model.DetectorProfile) Client(org.opensearch.client.Client) CommonName(org.opensearch.ad.constant.CommonName) Collections.emptySet(java.util.Collections.emptySet) FailedNodeException(org.opensearch.action.FailedNodeException) ANOMALY_DETECTORS_INDEX(org.opensearch.ad.model.AnomalyDetector.ANOMALY_DETECTORS_INDEX) GetRequest(org.opensearch.action.get.GetRequest) Set(java.util.Set) ADTaskManager(org.opensearch.ad.task.ADTaskManager) DetectorProfileName(org.opensearch.ad.model.DetectorProfileName) Instant(java.time.Instant) TransportService(org.opensearch.transport.TransportService) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) TransportAddress(org.opensearch.common.transport.TransportAddress) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) AnomalyResult(org.opensearch.ad.model.AnomalyResult) DetectorState(org.opensearch.ad.model.DetectorState) DetectorInternalState(org.opensearch.ad.model.DetectorInternalState) AnomalyDetectorJob(org.opensearch.ad.model.AnomalyDetectorJob) Optional(java.util.Optional) ClusterName(org.opensearch.cluster.ClusterName) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) ProfileAction(org.opensearch.ad.transport.ProfileAction) CountDownLatch(java.util.concurrent.CountDownLatch) DetectorProfile(org.opensearch.ad.model.DetectorProfile)

Example 2 with DetectorProfile

use of org.opensearch.ad.model.DetectorProfile 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 3 with DetectorProfile

use of org.opensearch.ad.model.DetectorProfile 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)

Example 4 with DetectorProfile

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

the class AnomalyDetectorProfileRunnerTests method testDisabledJobIndexTemplate.

public void testDisabledJobIndexTemplate(JobStatus status) throws IOException, InterruptedException {
    setUpClientGet(DetectorStatus.EXIST, status, RCFPollingStatus.EMPTY, ErrorResultStatus.NO_ERROR);
    DetectorProfile expectedProfile = new DetectorProfile.Builder().state(DetectorState.DISABLED).build();
    final CountDownLatch inProgressLatch = new CountDownLatch(1);
    runner.profile(detector.getDetectorId(), ActionListener.wrap(response -> {
        assertEquals(expectedProfile, response);
        inProgressLatch.countDown();
    }, exception -> {
        assertTrue("Should not reach here ", false);
        inProgressLatch.countDown();
    }), stateOnly);
    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) DetectorProfile(org.opensearch.ad.model.DetectorProfile) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 5 with DetectorProfile

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

the class AnomalyDetectorProfileRunnerTests method testInitOrRunningStateTemplate.

public void testInitOrRunningStateTemplate(RCFPollingStatus status, DetectorState expectedState) throws IOException, InterruptedException {
    setUpClientGet(DetectorStatus.EXIST, JobStatus.ENABLED, status, ErrorResultStatus.NO_ERROR);
    DetectorProfile expectedProfile = new DetectorProfile.Builder().state(expectedState).build();
    final CountDownLatch inProgressLatch = new CountDownLatch(1);
    runner.profile(detector.getDetectorId(), ActionListener.wrap(response -> {
        assertEquals(expectedProfile, response);
        inProgressLatch.countDown();
    }, exception -> {
        logger.error(exception);
        for (StackTraceElement ste : exception.getStackTrace()) {
            logger.info(ste);
        }
        assertTrue("Should not reach here ", false);
        inProgressLatch.countDown();
    }), stateOnly);
    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) DetectorProfile(org.opensearch.ad.model.DetectorProfile) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

DetectorProfile (org.opensearch.ad.model.DetectorProfile)16 List (java.util.List)13 Map (java.util.Map)13 Set (java.util.Set)13 ActionListener (org.opensearch.action.ActionListener)13 GetRequest (org.opensearch.action.get.GetRequest)13 CommonName (org.opensearch.ad.constant.CommonName)13 AnomalyDetector (org.opensearch.ad.model.AnomalyDetector)13 ANOMALY_DETECTORS_INDEX (org.opensearch.ad.model.AnomalyDetector.ANOMALY_DETECTORS_INDEX)13 AnomalyDetectorJob (org.opensearch.ad.model.AnomalyDetectorJob)13 ANOMALY_DETECTOR_JOB_INDEX (org.opensearch.ad.model.AnomalyDetectorJob.ANOMALY_DETECTOR_JOB_INDEX)13 DetectorProfileName (org.opensearch.ad.model.DetectorProfileName)13 DetectorState (org.opensearch.ad.model.DetectorState)13 ProfileAction (org.opensearch.ad.transport.ProfileAction)13 ProfileResponse (org.opensearch.ad.transport.ProfileResponse)13 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)13 CountDownLatch (java.util.concurrent.CountDownLatch)11 Instant (java.time.Instant)10 ArrayList (java.util.ArrayList)10 Arrays (java.util.Arrays)10