Search in sources :

Example 6 with DetectionDateRange

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

the class SecureADRestIT method testStartDetectorForWriteUser.

public void testStartDetectorForWriteUser() throws IOException {
    // User Alice has AD full access, should be able to modify a detector
    AnomalyDetector aliceDetector = createRandomAnomalyDetector(false, false, aliceClient);
    Assert.assertNotNull(aliceDetector.getDetectorId());
    Instant now = Instant.now();
    Response response = startAnomalyDetector(aliceDetector.getDetectorId(), new DetectionDateRange(now.minus(10, ChronoUnit.DAYS), now), aliceClient);
    Assert.assertEquals(response.getStatusLine().toString(), "HTTP/1.1 200 OK");
}
Also used : Response(org.opensearch.client.Response) Instant(java.time.Instant) AnomalyDetector(org.opensearch.ad.model.AnomalyDetector) DetectionDateRange(org.opensearch.ad.model.DetectionDateRange)

Example 7 with DetectionDateRange

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

the class ADBatchAnomalyResultTransportActionTests method testHistoricalAnalysisWithInvalidHistoricalDateRange.

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

Example 8 with DetectionDateRange

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

the class ADBatchAnomalyResultTransportActionTests method testHistoricalAnalysisExceedsMaxRunningTaskLimit.

public void testHistoricalAnalysisExceedsMaxRunningTaskLimit() throws IOException, InterruptedException {
    updateTransientSettings(ImmutableMap.of(MAX_BATCH_TASK_PER_NODE.getKey(), 1));
    updateTransientSettings(ImmutableMap.of(BATCH_TASK_PIECE_INTERVAL_SECONDS.getKey(), 5));
    DetectionDateRange dateRange = new DetectionDateRange(startTime, endTime);
    int totalDataNodes = getDataNodes().size();
    for (int i = 0; i < totalDataNodes; i++) {
        client().execute(ADBatchAnomalyResultAction.INSTANCE, adBatchAnomalyResultRequest(dateRange)).actionGet(5000);
    }
    waitUntil(() -> countDocs(CommonName.DETECTION_STATE_INDEX) >= totalDataNodes, 10, TimeUnit.SECONDS);
    ADBatchAnomalyResultRequest request = adBatchAnomalyResultRequest(dateRange);
    try {
        client().execute(ADBatchAnomalyResultAction.INSTANCE, request).actionGet(5000);
    } catch (Exception e) {
        assertTrue(ExceptionUtil.getErrorMessage(e).contains("All nodes' executing batch tasks exceeds limitation No eligible node to run detector"));
    }
}
Also used : DetectionDateRange(org.opensearch.ad.model.DetectionDateRange) IOException(java.io.IOException) ActionRequestValidationException(org.opensearch.action.ActionRequestValidationException) EndRunException(org.opensearch.ad.common.exception.EndRunException)

Example 9 with DetectionDateRange

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

the class HistoricalAnalysisIntegTestCase method startHistoricalAnalysis.

public ADTask startHistoricalAnalysis(String detectorId, Instant startTime, Instant endTime) throws IOException {
    DetectionDateRange dateRange = new DetectionDateRange(startTime, endTime);
    AnomalyDetectorJobRequest request = new AnomalyDetectorJobRequest(detectorId, dateRange, true, UNASSIGNED_SEQ_NO, UNASSIGNED_PRIMARY_TERM, START_JOB);
    AnomalyDetectorJobResponse response = client().execute(AnomalyDetectorJobAction.INSTANCE, request).actionGet(10000);
    return getADTask(response.getId());
}
Also used : AnomalyDetectorJobResponse(org.opensearch.ad.transport.AnomalyDetectorJobResponse) AnomalyDetectorJobRequest(org.opensearch.ad.transport.AnomalyDetectorJobRequest) DetectionDateRange(org.opensearch.ad.model.DetectionDateRange)

Example 10 with DetectionDateRange

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

the class HistoricalAnalysisIntegTestCase method startHistoricalAnalysis.

public ADTask startHistoricalAnalysis(Instant startTime, Instant endTime) throws IOException {
    DetectionDateRange dateRange = new DetectionDateRange(startTime, endTime);
    AnomalyDetector detector = TestHelpers.randomDetector(ImmutableList.of(maxValueFeature()), testIndex, detectionIntervalInMinutes, timeField);
    String detectorId = createDetector(detector);
    AnomalyDetectorJobRequest request = new AnomalyDetectorJobRequest(detectorId, dateRange, true, UNASSIGNED_SEQ_NO, UNASSIGNED_PRIMARY_TERM, START_JOB);
    AnomalyDetectorJobResponse response = client().execute(AnomalyDetectorJobAction.INSTANCE, request).actionGet(10000);
    return getADTask(response.getId());
}
Also used : AnomalyDetectorJobResponse(org.opensearch.ad.transport.AnomalyDetectorJobResponse) AnomalyDetectorJobRequest(org.opensearch.ad.transport.AnomalyDetectorJobRequest) DetectionDateRange(org.opensearch.ad.model.DetectionDateRange) AnomalyDetector(org.opensearch.ad.model.AnomalyDetector)

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