Search in sources :

Example 1 with DetectionDateRange

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

the class ADTaskManagerTests method testStartHistoricalAnalysisWithNoOwningNode.

@SuppressWarnings("unchecked")
public void testStartHistoricalAnalysisWithNoOwningNode() throws IOException {
    AnomalyDetector detector = TestHelpers.randomAnomalyDetector(ImmutableList.of());
    DetectionDateRange detectionDateRange = TestHelpers.randomDetectionDateRange();
    User user = null;
    int availableTaskSlots = randomIntBetween(1, 10);
    ActionListener<AnomalyDetectorJobResponse> listener = mock(ActionListener.class);
    doAnswer(invocation -> {
        Consumer<Optional<DiscoveryNode>> function = invocation.getArgument(1);
        function.accept(Optional.empty());
        return null;
    }).when(hashRing).buildAndGetOwningNodeWithSameLocalAdVersion(anyString(), any(), any());
    adTaskManager.startHistoricalAnalysis(detector, detectionDateRange, user, availableTaskSlots, transportService, listener);
    verify(listener, times(1)).onFailure(any());
}
Also used : TestHelpers.randomUser(org.opensearch.ad.TestHelpers.randomUser) User(org.opensearch.commons.authuser.User) Optional(java.util.Optional) AnomalyDetectorJobResponse(org.opensearch.ad.transport.AnomalyDetectorJobResponse) AnomalyDetector(org.opensearch.ad.model.AnomalyDetector) TestHelpers.randomAnomalyDetector(org.opensearch.ad.TestHelpers.randomAnomalyDetector) TestHelpers.randomDetectionDateRange(org.opensearch.ad.TestHelpers.randomDetectionDateRange) DetectionDateRange(org.opensearch.ad.model.DetectionDateRange)

Example 2 with DetectionDateRange

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

the class ADBatchAnomalyResultTransportActionTests method testHistoricalAnalysisWithValidDateRange.

public void testHistoricalAnalysisWithValidDateRange() throws IOException, InterruptedException {
    DetectionDateRange dateRange = new DetectionDateRange(startTime, endTime);
    ADBatchAnomalyResultRequest request = adBatchAnomalyResultRequest(dateRange);
    client().execute(ADBatchAnomalyResultAction.INSTANCE, request).actionGet(5000);
    Thread.sleep(20000);
    GetResponse doc = getDoc(CommonName.DETECTION_STATE_INDEX, request.getAdTask().getTaskId());
    assertTrue(HISTORICAL_ANALYSIS_FINISHED_FAILED_STATS.contains(doc.getSourceAsMap().get(ADTask.STATE_FIELD)));
}
Also used : GetResponse(org.opensearch.action.get.GetResponse) DetectionDateRange(org.opensearch.ad.model.DetectionDateRange)

Example 3 with DetectionDateRange

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

the class ADBatchAnomalyResultTransportActionTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    testIndex = "test_historical_data";
    startTime = Instant.now().minus(10, ChronoUnit.DAYS);
    endTime = Instant.now();
    dateRange = new DetectionDateRange(endTime, endTime.plus(10, ChronoUnit.DAYS));
    ingestTestData(testIndex, startTime, detectionIntervalInMinutes, type);
    createDetectionStateIndex();
}
Also used : DetectionDateRange(org.opensearch.ad.model.DetectionDateRange) Before(org.junit.Before)

Example 4 with DetectionDateRange

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

the class ADBatchAnomalyResultTransportActionTests method testHistoricalAnalysisWithFutureDateRange.

public void testHistoricalAnalysisWithFutureDateRange() throws IOException, InterruptedException {
    DetectionDateRange dateRange = new DetectionDateRange(endTime, endTime.plus(10, ChronoUnit.DAYS));
    testInvalidDetectionDateRange(dateRange);
}
Also used : DetectionDateRange(org.opensearch.ad.model.DetectionDateRange)

Example 5 with DetectionDateRange

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

the class ADBatchAnomalyResultTransportActionTests method testHistoricalAnalysisWithNonExistingIndex.

public void testHistoricalAnalysisWithNonExistingIndex() throws IOException {
    ADBatchAnomalyResultRequest request = adBatchAnomalyResultRequest(new DetectionDateRange(startTime, endTime), randomAlphaOfLength(5));
    client().execute(ADBatchAnomalyResultAction.INSTANCE, request).actionGet(10_000);
}
Also used : DetectionDateRange(org.opensearch.ad.model.DetectionDateRange)

Aggregations

DetectionDateRange (org.opensearch.ad.model.DetectionDateRange)32 AnomalyDetector (org.opensearch.ad.model.AnomalyDetector)14 Instant (java.time.Instant)13 IOException (java.io.IOException)8 AnomalyDetectorJobResponse (org.opensearch.ad.transport.AnomalyDetectorJobResponse)8 TimeValue (org.opensearch.common.unit.TimeValue)8 List (java.util.List)7 ActionListener (org.opensearch.action.ActionListener)7 EndRunException (org.opensearch.ad.common.exception.EndRunException)7 ClusterService (org.opensearch.cluster.service.ClusterService)7 ImmutableList (com.google.common.collect.ImmutableList)6 ImmutableMap (com.google.common.collect.ImmutableMap)6 Optional (java.util.Optional)6 LogManager (org.apache.logging.log4j.LogManager)6 Logger (org.apache.logging.log4j.Logger)6 HashRing (org.opensearch.ad.cluster.HashRing)6 AnomalyDetectionIndices (org.opensearch.ad.indices.AnomalyDetectionIndices)6 ADTask (org.opensearch.ad.model.ADTask)6 User (org.opensearch.commons.authuser.User)6 ImmutableSet (com.google.common.collect.ImmutableSet)5