Search in sources :

Example 6 with ADTask

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

the class ADTaskManagerTests method testParseEntityForSingleCategoryHC.

public void testParseEntityForSingleCategoryHC() throws IOException {
    ADTask adTask = randomAdTask(randomAlphaOfLength(5), ADTaskState.INIT, Instant.now(), randomAlphaOfLength(5), TestHelpers.randomAnomalyDetectorUsingCategoryFields(randomAlphaOfLength(5), ImmutableList.of(randomAlphaOfLength(5))));
    String entityValue = adTaskManager.convertEntityToString(adTask);
    Entity entity = adTaskManager.parseEntityFromString(entityValue, adTask);
    assertEquals(entity, adTask.getEntity());
}
Also used : Entity.createSingleAttributeEntity(org.opensearch.ad.model.Entity.createSingleAttributeEntity) Entity(org.opensearch.ad.model.Entity) ADTask(org.opensearch.ad.model.ADTask) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Example 7 with ADTask

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

the class ADTaskManagerTests method testCreateADTaskDirectlyWithException.

@SuppressWarnings("unchecked")
public void testCreateADTaskDirectlyWithException() throws IOException {
    ADTask adTask = randomAdTask(ADTaskType.HISTORICAL_HC_DETECTOR);
    Consumer<IndexResponse> function = mock(Consumer.class);
    ActionListener<IndexResponse> listener = mock(ActionListener.class);
    doThrow(new RuntimeException("test")).when(client).index(any(), any());
    adTaskManager.createADTaskDirectly(adTask, function, listener);
    verify(listener, times(1)).onFailure(any());
    doAnswer(invocation -> {
        ActionListener<IndexResponse> actionListener = invocation.getArgument(1);
        actionListener.onFailure(new RuntimeException("test"));
        return null;
    }).when(client).index(any(), any());
    adTaskManager.createADTaskDirectly(adTask, function, listener);
    verify(listener, times(2)).onFailure(any());
}
Also used : IndexResponse(org.opensearch.action.index.IndexResponse) CreateIndexResponse(org.opensearch.action.admin.indices.create.CreateIndexResponse) ADTask(org.opensearch.ad.model.ADTask)

Example 8 with ADTask

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

the class ADTaskManagerTests method testDeleteDuplicateTasks.

public void testDeleteDuplicateTasks() throws IOException {
    ADTask adTask = randomAdTask();
    adTaskManager.handleADTaskException(adTask, new DuplicateTaskException("test"));
    verify(client, times(1)).delete(any(), any());
}
Also used : ADTask(org.opensearch.ad.model.ADTask) DuplicateTaskException(org.opensearch.ad.common.exception.DuplicateTaskException)

Example 9 with ADTask

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

the class ADTaskManagerTests method testCheckTaskSlotsWithAvailableTaskSlotsForSingleEntityDetector.

public void testCheckTaskSlotsWithAvailableTaskSlotsForSingleEntityDetector() throws IOException {
    ADTask adTask = randomAdTask(randomAlphaOfLength(5), ADTaskState.INIT, Instant.now(), randomAlphaOfLength(5), TestHelpers.randomAnomalyDetectorUsingCategoryFields(randomAlphaOfLength(5), ImmutableList.of()));
    setupHashRingWithSameLocalADVersionNodes();
    setupTaskSlots(0, 2, 2, 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 10 with ADTask

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

the class ADTaskManagerTests method testCheckTaskSlotsWithAvailableTaskSlotsAndNoEntity.

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

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