Search in sources :

Example 1 with AnomalyDetectorJobResponse

use of org.opensearch.ad.transport.AnomalyDetectorJobResponse 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 AnomalyDetectorJobResponse

use of org.opensearch.ad.transport.AnomalyDetectorJobResponse in project anomaly-detection by opensearch-project.

the class ADTaskManagerTests method testScaleTaskLaneOnCoordinatingNode.

@SuppressWarnings("unchecked")
public void testScaleTaskLaneOnCoordinatingNode() {
    ADTask adTask = mock(ADTask.class);
    when(adTask.getCoordinatingNode()).thenReturn(node1.getId());
    when(nodeFilter.getEligibleDataNodes()).thenReturn(new DiscoveryNode[] { node1, node2 });
    ActionListener<AnomalyDetectorJobResponse> listener = mock(ActionListener.class);
    adTaskManager.scaleTaskLaneOnCoordinatingNode(adTask, 2, transportService, listener);
}
Also used : ADTask(org.opensearch.ad.model.ADTask) AnomalyDetectorJobResponse(org.opensearch.ad.transport.AnomalyDetectorJobResponse)

Example 3 with AnomalyDetectorJobResponse

use of org.opensearch.ad.transport.AnomalyDetectorJobResponse in project anomaly-detection by opensearch-project.

the class ADTaskManagerTests method testStopDetectorWithNonExistingTask.

@SuppressWarnings("unchecked")
public void testStopDetectorWithNonExistingTask() {
    String detectorId = randomAlphaOfLength(5);
    boolean historical = true;
    ActionListener<AnomalyDetectorJobResponse> listener = mock(ActionListener.class);
    doAnswer(invocation -> {
        Consumer<Optional<AnomalyDetector>> function = invocation.getArgument(1);
        AnomalyDetector detector = randomAnomalyDetector(ImmutableList.of(randomFeature(true)));
        function.accept(Optional.of(detector));
        return null;
    }).when(adTaskManager).getDetector(anyString(), any(), any());
    doAnswer(invocation -> {
        ActionListener<SearchResponse> actionListener = invocation.getArgument(1);
        actionListener.onResponse(null);
        return null;
    }).when(client).search(any(), any());
    adTaskManager.stopDetector(detectorId, historical, indexAnomalyDetectorJobActionHandler, null, transportService, listener);
    verify(listener, times(1)).onFailure(any());
}
Also used : Optional(java.util.Optional) AnomalyDetectorJobResponse(org.opensearch.ad.transport.AnomalyDetectorJobResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AnomalyDetector(org.opensearch.ad.model.AnomalyDetector) TestHelpers.randomAnomalyDetector(org.opensearch.ad.TestHelpers.randomAnomalyDetector) InternalSearchResponse(org.opensearch.search.internal.InternalSearchResponse) SearchResponse(org.opensearch.action.search.SearchResponse)

Example 4 with AnomalyDetectorJobResponse

use of org.opensearch.ad.transport.AnomalyDetectorJobResponse in project anomaly-detection by opensearch-project.

the class ADTaskManagerTests method testForwardRequestToLeadNodeWithNotExistingNode.

@SuppressWarnings("unchecked")
public void testForwardRequestToLeadNodeWithNotExistingNode() throws IOException {
    ADTask adTask = randomAdTask(ADTaskType.HISTORICAL_HC_ENTITY);
    ForwardADTaskRequest forwardADTaskRequest = new ForwardADTaskRequest(adTask, ADTaskAction.APPLY_FOR_TASK_SLOTS);
    ActionListener<AnomalyDetectorJobResponse> listener = mock(ActionListener.class);
    doAnswer(invocation -> {
        Consumer<Optional<DiscoveryNode>> function = invocation.getArgument(1);
        function.accept(Optional.empty());
        return null;
    }).when(hashRing).buildAndGetOwningNodeWithSameLocalAdVersion(any(), any(), any());
    adTaskManager.forwardRequestToLeadNode(forwardADTaskRequest, transportService, listener);
    verify(listener, times(1)).onFailure(any());
}
Also used : ForwardADTaskRequest(org.opensearch.ad.transport.ForwardADTaskRequest) Optional(java.util.Optional) ADTask(org.opensearch.ad.model.ADTask) AnomalyDetectorJobResponse(org.opensearch.ad.transport.AnomalyDetectorJobResponse)

Example 5 with AnomalyDetectorJobResponse

use of org.opensearch.ad.transport.AnomalyDetectorJobResponse in project anomaly-detection by opensearch-project.

the class ADTaskManagerTests method testScaleUpTaskSlots.

@SuppressWarnings("unchecked")
public void testScaleUpTaskSlots() throws IOException {
    ADTask adTask = randomAdTask(ADTaskType.HISTORICAL_HC_ENTITY);
    ActionListener<AnomalyDetectorJobResponse> listener = mock(ActionListener.class);
    when(adTaskCacheManager.getAvailableNewEntityTaskLanes(anyString())).thenReturn(0);
    doReturn(2).when(adTaskManager).detectorTaskSlotScaleDelta(anyString());
    when(adTaskCacheManager.getLastScaleEntityTaskLaneTime(anyString())).thenReturn(null);
    assertEquals(0, adTaskManager.scaleTaskSlots(adTask, transportService, listener));
    when(adTaskCacheManager.getLastScaleEntityTaskLaneTime(anyString())).thenReturn(Instant.now());
    assertEquals(2, adTaskManager.scaleTaskSlots(adTask, transportService, listener));
    when(adTaskCacheManager.getLastScaleEntityTaskLaneTime(anyString())).thenReturn(Instant.now().minus(10, ChronoUnit.DAYS));
    assertEquals(2, adTaskManager.scaleTaskSlots(adTask, transportService, listener));
    verify(adTaskCacheManager, times(1)).refreshLastScaleEntityTaskLaneTime(anyString());
    verify(adTaskManager, times(1)).forwardScaleTaskSlotRequestToLeadNode(any(), any(), any());
}
Also used : ADTask(org.opensearch.ad.model.ADTask) AnomalyDetectorJobResponse(org.opensearch.ad.transport.AnomalyDetectorJobResponse)

Aggregations

AnomalyDetectorJobResponse (org.opensearch.ad.transport.AnomalyDetectorJobResponse)23 Optional (java.util.Optional)13 AnomalyDetector (org.opensearch.ad.model.AnomalyDetector)13 DetectionDateRange (org.opensearch.ad.model.DetectionDateRange)13 ADTask (org.opensearch.ad.model.ADTask)12 IOException (java.io.IOException)10 ResourceAlreadyExistsException (org.opensearch.ResourceAlreadyExistsException)10 SearchResponse (org.opensearch.action.search.SearchResponse)10 DuplicateTaskException (org.opensearch.ad.common.exception.DuplicateTaskException)10 User (org.opensearch.commons.authuser.User)10 IndexNotFoundException (org.opensearch.index.IndexNotFoundException)10 Instant (java.time.Instant)9 TotalHits (org.apache.lucene.search.TotalHits)9 OpenSearchStatusException (org.opensearch.OpenSearchStatusException)9 ImmutableList (com.google.common.collect.ImmutableList)8 ImmutableMap (com.google.common.collect.ImmutableMap)8 ChronoUnit (java.time.temporal.ChronoUnit)8 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Locale (java.util.Locale)8