use of org.opensearch.ad.model.AnomalyDetector in project anomaly-detection by opensearch-project.
the class AnomalyDetectorRestApiIT method testValidateAnomalyDetectorWithNoIssue.
public void testValidateAnomalyDetectorWithNoIssue() throws Exception {
AnomalyDetector detector = createIndexAndGetAnomalyDetector(INDEX_NAME);
Response resp = TestHelpers.makeRequest(client(), "POST", TestHelpers.AD_BASE_DETECTORS_URI + "/_validate/detector", ImmutableMap.of(), TestHelpers.toHttpEntity(detector), null);
Map<String, Object> responseMap = entityAsMap(resp);
assertEquals("no issue, empty response body", new HashMap<String, Object>(), responseMap);
}
use of org.opensearch.ad.model.AnomalyDetector in project anomaly-detection by opensearch-project.
the class HistoricalAnalysisRestApiIT method testDeleteHistoricalAnalysis.
// TODO: fix delete
public void testDeleteHistoricalAnalysis() throws IOException, IllegalAccessException {
// create historical detector
AnomalyDetector detector = createAnomalyDetector();
String detectorId = detector.getDetectorId();
// delete detector
Response response = TestHelpers.makeRequest(client(), "DELETE", TestHelpers.AD_BASE_DETECTORS_URI + "/" + detectorId, ImmutableMap.of(), "", null);
assertEquals(RestStatus.OK, TestHelpers.restStatus(response));
}
use of org.opensearch.ad.model.AnomalyDetector in project anomaly-detection by opensearch-project.
the class HistoricalAnalysisRestApiIT method testSearchTasks.
public void testSearchTasks() throws IOException, InterruptedException, IllegalAccessException {
// create historical detector
AnomalyDetector detector = createAnomalyDetector();
String detectorId = detector.getDetectorId();
// start historical detector
String taskId = startHistoricalAnalysis(detectorId);
waitUntilTaskDone(detectorId);
String query = String.format("{\"query\":{\"term\":{\"detector_id\":{\"value\":\"%s\"}}}}", detectorId);
Response response = TestHelpers.makeRequest(client(), "POST", TestHelpers.AD_BASE_DETECTORS_URI + "/tasks/_search", ImmutableMap.of(), query, null);
String searchResult = EntityUtils.toString(response.getEntity());
assertTrue(searchResult.contains(taskId));
assertTrue(searchResult.contains(detector.getDetectorId()));
}
use of org.opensearch.ad.model.AnomalyDetector in project anomaly-detection by opensearch-project.
the class HistoricalAnalysisRestApiIT method testStopHistoricalAnalysis.
@SuppressWarnings("unchecked")
public void testStopHistoricalAnalysis() throws Exception {
// create historical detector
AnomalyDetector detector = createAnomalyDetector();
String detectorId = detector.getDetectorId();
// start historical detector
String taskId = startHistoricalAnalysis(detectorId);
waitUntilGetTaskProfile(detectorId);
// stop historical detector
Response stopDetectorResponse = stopAnomalyDetector(detectorId, client(), false);
assertEquals(RestStatus.OK, TestHelpers.restStatus(stopDetectorResponse));
// get task profile
checkIfTaskCanFinishCorrectly(detectorId, taskId, ImmutableSet.of(ADTaskState.STOPPED.name()));
updateClusterSettings(BATCH_TASK_PIECE_INTERVAL_SECONDS.getKey(), 1);
waitUntilTaskDone(detectorId);
// get AD stats
Response statsResponse = TestHelpers.makeRequest(client(), "GET", AD_BASE_STATS_URI, ImmutableMap.of(), "", null);
String statsResult = EntityUtils.toString(statsResponse.getEntity());
Map<String, Object> stringObjectMap = TestHelpers.parseStatsResult(statsResult);
assertTrue((long) stringObjectMap.get("single_entity_detector_count") > 0);
Map<String, Object> nodes = (Map<String, Object>) stringObjectMap.get("nodes");
long cancelledTaskCount = 0;
for (String key : nodes.keySet()) {
Map<String, Object> nodeStats = (Map<String, Object>) nodes.get(key);
cancelledTaskCount += (long) nodeStats.get("ad_canceled_batch_task_count");
}
assertTrue(cancelledTaskCount >= 1);
}
use of org.opensearch.ad.model.AnomalyDetector in project anomaly-detection by opensearch-project.
the class SecureADRestIT method testValidateAnomalyDetectorWithNoBackendRole.
public void testValidateAnomalyDetectorWithNoBackendRole() throws IOException {
AnomalyDetector detector = TestHelpers.randomAnomalyDetector(null, Instant.now());
enableFilterBy();
// User Dog has AD full access, but has no backend role
// When filter by is enabled, we block validating Detectors
Exception exception = expectThrows(IOException.class, () -> {
validateAnomalyDetector(detector, dogClient);
});
Assert.assertTrue(exception.getMessage().contains("Filter by backend roles is enabled and User dog does not have backend roles configured"));
}
Aggregations