use of org.opensearch.ad.model.ADTask 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);
}
use of org.opensearch.ad.model.ADTask in project anomaly-detection by opensearch-project.
the class ADTaskManagerTests method testParseEntityForMultiCategoryHC.
public void testParseEntityForMultiCategoryHC() throws IOException {
ADTask adTask = randomAdTask(randomAlphaOfLength(5), ADTaskState.INIT, Instant.now(), randomAlphaOfLength(5), TestHelpers.randomAnomalyDetectorUsingCategoryFields(randomAlphaOfLength(5), ImmutableList.of(randomAlphaOfLength(5), randomAlphaOfLength(5))));
String entityValue = adTaskManager.convertEntityToString(adTask);
Entity entity = adTaskManager.parseEntityFromString(entityValue, adTask);
assertEquals(entity, adTask.getEntity());
}
use of org.opensearch.ad.model.ADTask 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());
}
use of org.opensearch.ad.model.ADTask 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());
}
use of org.opensearch.ad.model.ADTask in project anomaly-detection by opensearch-project.
the class ADTaskManagerTests method testGetAndExecuteOnLatestADTasksWithRunningRealtimeTaskWithTaskStopped.
@SuppressWarnings("unchecked")
public void testGetAndExecuteOnLatestADTasksWithRunningRealtimeTaskWithTaskStopped() throws IOException {
String detectorId = randomAlphaOfLength(5);
Consumer<List<ADTask>> function = mock(Consumer.class);
AnomalyDetector detector = TestHelpers.randomDetector(ImmutableList.of(randomFeature(true)), randomAlphaOfLength(5), randomIntBetween(1, 10), MockSimpleLog.TIME_FIELD, ImmutableList.of(randomAlphaOfLength(5)));
ADTask adTask = ADTask.builder().taskId(randomAlphaOfLength(5)).taskType(ADTaskType.HISTORICAL_HC_DETECTOR.name()).detectorId(randomAlphaOfLength(5)).detector(detector).entity(null).state(ADTaskState.RUNNING.name()).taskProgress(0.5f).initProgress(1.0f).currentPiece(Instant.now().truncatedTo(ChronoUnit.SECONDS).minus(randomIntBetween(1, 100), ChronoUnit.MINUTES)).executionStartTime(Instant.now().truncatedTo(ChronoUnit.SECONDS).minus(100, ChronoUnit.MINUTES)).isLatest(true).error(randomAlphaOfLength(5)).checkpointId(randomAlphaOfLength(5)).lastUpdateTime(Instant.now().truncatedTo(ChronoUnit.SECONDS)).startedBy(randomAlphaOfLength(5)).lastUpdateTime(Instant.now().truncatedTo(ChronoUnit.SECONDS)).coordinatingNode(node1.getId()).build();
ADTaskProfile profile = new ADTaskProfile(adTask, randomInt(), randomLong(), randomBoolean(), randomInt(), randomLong(), randomAlphaOfLength(5), randomAlphaOfLength(5), randomAlphaOfLength(5), randomInt(), randomBoolean(), randomInt(), randomInt(), randomInt(), ImmutableList.of(randomAlphaOfLength(5)), Instant.now().toEpochMilli());
setupGetAndExecuteOnLatestADTasks(profile);
adTaskManager.getAndExecuteOnLatestADTasks(detectorId, null, null, ADTaskType.ALL_DETECTOR_TASK_TYPES, function, transportService, true, 10, listener);
verify(client, times(2)).update(any(), any());
}
Aggregations