use of org.opensearch.ad.model.ADTask in project anomaly-detection by opensearch-project.
the class AnomalyDetectorJobTransportActionTests method testStopRealtimeDetector.
public void testStopRealtimeDetector() throws IOException {
List<String> realtimeResult = startRealtimeDetector();
String detectorId = realtimeResult.get(0);
String jobId = realtimeResult.get(1);
AnomalyDetectorJobRequest request = stopDetectorJobRequest(detectorId, false);
client().execute(AnomalyDetectorJobAction.INSTANCE, request).actionGet(10000);
GetResponse doc = getDoc(AnomalyDetectorJob.ANOMALY_DETECTOR_JOB_INDEX, detectorId);
AnomalyDetectorJob job = toADJob(doc);
assertFalse(job.isEnabled());
assertEquals(detectorId, job.getName());
List<ADTask> adTasks = searchADTasks(detectorId, true, 10);
assertEquals(1, adTasks.size());
assertEquals(ADTaskType.REALTIME_SINGLE_ENTITY.name(), adTasks.get(0).getTaskType());
assertNotEquals(jobId, adTasks.get(0).getTaskId());
assertEquals(ADTaskState.STOPPED.name(), adTasks.get(0).getState());
}
use of org.opensearch.ad.model.ADTask in project anomaly-detection by opensearch-project.
the class AnomalyDetectorJobTransportActionTests method testValidHistoricalAnalysis.
public void testValidHistoricalAnalysis() throws IOException, InterruptedException {
ADTask adTask = startHistoricalAnalysis(startTime, endTime);
Thread.sleep(10000);
ADTask finishedTask = getADTask(adTask.getTaskId());
assertTrue(HISTORICAL_ANALYSIS_FINISHED_FAILED_STATS.contains(finishedTask.getState()));
}
use of org.opensearch.ad.model.ADTask in project anomaly-detection by opensearch-project.
the class AnomalyDetectorJobTransportActionTests method testStartRealtimeDetector.
public void testStartRealtimeDetector() throws IOException {
List<String> realtimeResult = startRealtimeDetector();
String detectorId = realtimeResult.get(0);
String jobId = realtimeResult.get(1);
GetResponse jobDoc = getDoc(AnomalyDetectorJob.ANOMALY_DETECTOR_JOB_INDEX, detectorId);
AnomalyDetectorJob job = toADJob(jobDoc);
assertTrue(job.isEnabled());
assertEquals(detectorId, job.getName());
List<ADTask> adTasks = searchADTasks(detectorId, true, 10);
assertEquals(1, adTasks.size());
assertEquals(ADTaskType.REALTIME_SINGLE_ENTITY.name(), adTasks.get(0).getTaskType());
assertNotEquals(jobId, adTasks.get(0).getTaskId());
}
use of org.opensearch.ad.model.ADTask in project anomaly-detection by opensearch-project.
the class AnomalyDetectorJobTransportActionTests method testProfileHistoricalDetector.
public void testProfileHistoricalDetector() throws IOException, InterruptedException {
ADTask adTask = startHistoricalAnalysis(startTime, endTime);
GetAnomalyDetectorRequest request = taskProfileRequest(adTask.getDetectorId());
GetAnomalyDetectorResponse response = client().execute(GetAnomalyDetectorAction.INSTANCE, request).actionGet(10000);
assertTrue(response.getDetectorProfile().getAdTaskProfile() != null);
ADTask finishedTask = getADTask(adTask.getTaskId());
int i = 0;
while (TestHelpers.HISTORICAL_ANALYSIS_RUNNING_STATS.contains(finishedTask.getState()) && i < 10) {
finishedTask = getADTask(adTask.getTaskId());
Thread.sleep(2000);
i++;
}
assertTrue(HISTORICAL_ANALYSIS_FINISHED_FAILED_STATS.contains(finishedTask.getState()));
response = client().execute(GetAnomalyDetectorAction.INSTANCE, request).actionGet(10000);
assertNull(response.getDetectorProfile().getAdTaskProfile().getNodeId());
ADTask profileAdTask = response.getDetectorProfile().getAdTaskProfile().getAdTask();
assertEquals(finishedTask.getTaskId(), profileAdTask.getTaskId());
assertEquals(finishedTask.getDetectorId(), profileAdTask.getDetectorId());
assertEquals(finishedTask.getDetector(), profileAdTask.getDetector());
assertEquals(finishedTask.getState(), profileAdTask.getState());
}
use of org.opensearch.ad.model.ADTask in project anomaly-detection by opensearch-project.
the class AnomalyDetectorJobTransportActionTests method testRunMultipleTasksForHistoricalAnalysis.
public void testRunMultipleTasksForHistoricalAnalysis() throws IOException, InterruptedException {
AnomalyDetector detector = TestHelpers.randomDetector(ImmutableList.of(maxValueFeature()), testIndex, detectionIntervalInMinutes, timeField);
String detectorId = createDetector(detector);
AnomalyDetectorJobRequest request = startDetectorJobRequest(detectorId, dateRange);
AnomalyDetectorJobResponse response = client().execute(AnomalyDetectorJobAction.INSTANCE, request).actionGet(10000);
assertNotNull(response.getId());
OpenSearchStatusException exception = null;
// Add retry to solve the flaky test
for (int i = 0; i < 10; i++) {
exception = expectThrows(OpenSearchStatusException.class, () -> client().execute(AnomalyDetectorJobAction.INSTANCE, request).actionGet(10000));
if (exception.getMessage().contains(DETECTOR_IS_RUNNING)) {
break;
} else {
logger.error("Unexpected error happened when rerun detector", exception);
}
Thread.sleep(1000);
}
assertNotNull(exception);
assertTrue(exception.getMessage().contains(DETECTOR_IS_RUNNING));
assertEquals(DETECTOR_IS_RUNNING, exception.getMessage());
Thread.sleep(20000);
List<ADTask> adTasks = searchADTasks(detectorId, null, 100);
assertEquals(1, adTasks.size());
assertTrue(HISTORICAL_ANALYSIS_FINISHED_FAILED_STATS.contains(adTasks.get(0).getState()));
}
Aggregations