Search in sources :

Example 26 with AnomalyDetector

use of org.opensearch.ad.model.AnomalyDetector in project anomaly-detection by opensearch-project.

the class SecureADRestIT method testStopApiFilterByEnabled.

public void testStopApiFilterByEnabled() throws IOException {
    // User Alice has AD full access, should be able to create a detector
    AnomalyDetector aliceDetector = createRandomAnomalyDetector(false, false, aliceClient);
    enableFilterBy();
    // User Cat has AD full access, but is part of different backend role so Cat should not be able to access
    // Alice detector
    Exception exception = expectThrows(IOException.class, () -> {
        stopAnomalyDetector(aliceDetector.getDetectorId(), catClient, true);
    });
    Assert.assertTrue(exception.getMessage().contains("User does not have permissions to access detector: " + aliceDetector.getDetectorId()));
}
Also used : AnomalyDetector(org.opensearch.ad.model.AnomalyDetector) IOException(java.io.IOException)

Example 27 with AnomalyDetector

use of org.opensearch.ad.model.AnomalyDetector in project anomaly-detection by opensearch-project.

the class SecureADRestIT method testPreviewAnomalyDetectorWithFilterEnabled.

public void testPreviewAnomalyDetectorWithFilterEnabled() throws IOException {
    // User Alice has AD full access, should be able to create a detector
    AnomalyDetector aliceDetector = createRandomAnomalyDetector(false, false, aliceClient);
    AnomalyDetectorExecutionInput input = new AnomalyDetectorExecutionInput(aliceDetector.getDetectorId(), Instant.now().minusSeconds(60 * 10), Instant.now(), null);
    enableFilterBy();
    // User Cat has AD full access, but is part of different backend role so Cat should not be able to access
    // Alice detector
    Exception exception = expectThrows(IOException.class, () -> {
        previewAnomalyDetector(aliceDetector.getDetectorId(), catClient, input);
    });
    Assert.assertTrue(exception.getMessage().contains("User does not have permissions to access detector: " + aliceDetector.getDetectorId()));
}
Also used : AnomalyDetectorExecutionInput(org.opensearch.ad.model.AnomalyDetectorExecutionInput) AnomalyDetector(org.opensearch.ad.model.AnomalyDetector) IOException(java.io.IOException)

Example 28 with AnomalyDetector

use of org.opensearch.ad.model.AnomalyDetector in project anomaly-detection by opensearch-project.

the class SecureADRestIT method testPreviewAnomalyDetectorWithReadAccess.

public void testPreviewAnomalyDetectorWithReadAccess() throws IOException {
    // User Alice has AD full access, should be able to create a detector
    AnomalyDetector aliceDetector = createRandomAnomalyDetector(false, false, aliceClient);
    AnomalyDetectorExecutionInput input = new AnomalyDetectorExecutionInput(randomAlphaOfLength(5), Instant.now().minusSeconds(60 * 10), Instant.now(), null);
    // User bob has AD read access, should not be able to preview a detector
    Exception exception = expectThrows(IOException.class, () -> {
        previewAnomalyDetector(aliceDetector.getDetectorId(), bobClient, input);
    });
    Assert.assertTrue(exception.getMessage().contains("no permissions for [cluster:admin/opendistro/ad/detector/preview]"));
}
Also used : AnomalyDetectorExecutionInput(org.opensearch.ad.model.AnomalyDetectorExecutionInput) AnomalyDetector(org.opensearch.ad.model.AnomalyDetector) IOException(java.io.IOException)

Example 29 with AnomalyDetector

use of org.opensearch.ad.model.AnomalyDetector in project anomaly-detection by opensearch-project.

the class SecureADRestIT method testValidateAnomalyDetectorWithNoADAccess.

public void testValidateAnomalyDetectorWithNoADAccess() throws IOException {
    // User Lion has no AD access at all, should not be able to validate a detector
    AnomalyDetector detector = TestHelpers.randomAnomalyDetector(null, Instant.now());
    Exception exception = expectThrows(IOException.class, () -> {
        validateAnomalyDetector(detector, lionClient);
    });
    Assert.assertTrue(exception.getMessage().contains("no permissions for [cluster:admin/opendistro/ad/detector/validate]"));
}
Also used : AnomalyDetector(org.opensearch.ad.model.AnomalyDetector) IOException(java.io.IOException)

Example 30 with AnomalyDetector

use of org.opensearch.ad.model.AnomalyDetector 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());
}
Also used : ADTask(org.opensearch.ad.model.ADTask) AnomalyDetector(org.opensearch.ad.model.AnomalyDetector)

Aggregations

AnomalyDetector (org.opensearch.ad.model.AnomalyDetector)226 IOException (java.io.IOException)71 ActionListener (org.opensearch.action.ActionListener)54 Response (org.opensearch.client.Response)45 Map (java.util.Map)43 List (java.util.List)41 Client (org.opensearch.client.Client)38 SearchRequest (org.opensearch.action.search.SearchRequest)37 LogManager (org.apache.logging.log4j.LogManager)35 Logger (org.apache.logging.log4j.Logger)35 ArrayList (java.util.ArrayList)33 Optional (java.util.Optional)33 Test (org.junit.Test)32 SearchResponse (org.opensearch.action.search.SearchResponse)32 Instant (java.time.Instant)30 TimeValue (org.opensearch.common.unit.TimeValue)30 HashMap (java.util.HashMap)29 Entity (org.opensearch.ad.model.Entity)29 NamedXContentRegistry (org.opensearch.common.xcontent.NamedXContentRegistry)29 SearchSourceBuilder (org.opensearch.search.builder.SearchSourceBuilder)29