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"));
}
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());
}
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());
}
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());
}
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());
}
}
Aggregations