Search in sources :

Example 11 with ADTask

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

the class ADTaskManagerTests method testCheckTaskSlotsWithNoAvailableTaskSlots.

public void testCheckTaskSlotsWithNoAvailableTaskSlots() throws IOException {
    ADTask adTask = randomAdTask(randomAlphaOfLength(5), ADTaskState.INIT, Instant.now(), randomAlphaOfLength(5), TestHelpers.randomAnomalyDetectorUsingCategoryFields(randomAlphaOfLength(5), ImmutableList.of(randomAlphaOfLength(5))));
    setupHashRingWithSameLocalADVersionNodes();
    setupTaskSlots(0, maxBatchTaskPerNode, maxBatchTaskPerNode, maxBatchTaskPerNode);
    adTaskManager.checkTaskSlots(adTask, adTask.getDetector(), detectionDateRange, randomUser(), ADTaskAction.START, transportService, listener);
    verify(listener, times(1)).onFailure(exceptionCaptor.capture());
    assertTrue(exceptionCaptor.getValue().getMessage().contains("No available task slot"));
}
Also used : ADTask(org.opensearch.ad.model.ADTask)

Example 12 with ADTask

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

the class ADTaskManagerTests method testCheckTaskSlotsWithAvailableTaskSlotsForHC.

public void testCheckTaskSlotsWithAvailableTaskSlotsForHC() throws IOException {
    ADTask adTask = randomAdTask(randomAlphaOfLength(5), ADTaskState.INIT, Instant.now(), randomAlphaOfLength(5), TestHelpers.randomAnomalyDetectorUsingCategoryFields(randomAlphaOfLength(5), ImmutableList.of(randomAlphaOfLength(5))));
    setupSearchTopEntities(4);
    setupHashRingWithSameLocalADVersionNodes();
    setupTaskSlots(0, maxBatchTaskPerNode, maxBatchTaskPerNode, maxBatchTaskPerNode - 1);
    adTaskManager.checkTaskSlots(adTask, adTask.getDetector(), detectionDateRange, randomUser(), ADTaskAction.START, transportService, listener);
    verify(adTaskManager, times(1)).startHistoricalAnalysis(eq(adTask.getDetector()), eq(detectionDateRange), any(), eq(1), eq(transportService), any());
}
Also used : ADTask(org.opensearch.ad.model.ADTask)

Example 13 with ADTask

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

the class ADBatchAnomalyResultRequestTests method testInvalidRequestWithNullTaskIdAndDetectionDateRange.

public void testInvalidRequestWithNullTaskIdAndDetectionDateRange() throws IOException {
    ADTask adTask = TestHelpers.randomAdTask();
    adTask.setTaskId(null);
    adTask.setDetectionDateRange(null);
    ADBatchAnomalyResultRequest request = new ADBatchAnomalyResultRequest(adTask);
    ActionRequestValidationException exception = request.validate();
    assertEquals("Validation Failed: 1: Task id can't be null;2: Detection date range can't be null for batch task;", exception.getMessage());
}
Also used : ActionRequestValidationException(org.opensearch.action.ActionRequestValidationException) ADTask(org.opensearch.ad.model.ADTask)

Example 14 with ADTask

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

the class AnomalyDetectorJobTransportActionTests method testRaceConditionByStartingMultipleTasks.

public void testRaceConditionByStartingMultipleTasks() throws IOException, InterruptedException {
    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);
    client().execute(AnomalyDetectorJobAction.INSTANCE, request);
    client().execute(AnomalyDetectorJobAction.INSTANCE, request);
    Thread.sleep(5000);
    List<ADTask> adTasks = searchADTasks(detectorId, null, 100);
    assertEquals(1, adTasks.size());
    assertTrue(adTasks.get(0).getLatest());
    assertNotEquals(ADTaskState.FAILED.name(), adTasks.get(0).getState());
}
Also used : ADTask(org.opensearch.ad.model.ADTask) AnomalyDetector(org.opensearch.ad.model.AnomalyDetector)

Example 15 with ADTask

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

the class AnomalyDetectorJobTransportActionTests method testStartHistoricalAnalysisWithUser.

public void testStartHistoricalAnalysisWithUser() throws IOException {
    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);
    Client nodeClient = getDataNodeClient();
    if (nodeClient != null) {
        AnomalyDetectorJobResponse response = nodeClient.execute(MockAnomalyDetectorJobAction.INSTANCE, request).actionGet(100000);
        ADTask adTask = getADTask(response.getId());
        assertNotNull(adTask.getStartedBy());
        assertNotNull(adTask.getUser());
    }
}
Also used : ADTask(org.opensearch.ad.model.ADTask) Client(org.opensearch.client.Client) AnomalyDetector(org.opensearch.ad.model.AnomalyDetector)

Aggregations

ADTask (org.opensearch.ad.model.ADTask)108 AnomalyDetector (org.opensearch.ad.model.AnomalyDetector)44 List (java.util.List)36 ArrayList (java.util.ArrayList)35 ActionListener (org.opensearch.action.ActionListener)35 Client (org.opensearch.client.Client)35 ImmutableMap (com.google.common.collect.ImmutableMap)34 AnomalyDetectorJob (org.opensearch.ad.model.AnomalyDetectorJob)34 ImmutableList (com.google.common.collect.ImmutableList)32 Map (java.util.Map)32 Optional (java.util.Optional)32 Entity (org.opensearch.ad.model.Entity)32 Instant (java.time.Instant)31 ADTaskState (org.opensearch.ad.model.ADTaskState)31 ADTaskType (org.opensearch.ad.model.ADTaskType)31 HashMap (java.util.HashMap)30 Collectors (java.util.stream.Collectors)30 DetectionDateRange (org.opensearch.ad.model.DetectionDateRange)30 TransportService (org.opensearch.transport.TransportService)30 LogManager (org.apache.logging.log4j.LogManager)29