use of org.opensearch.ad.model.DetectorProfile in project anomaly-detection by opensearch-project.
the class MultiEntityProfileRunnerTests method testRunning.
public void testRunning() throws InterruptedException {
setUpClientExecuteProfileAction(InittedEverResultStatus.INITTED);
setUpClientSearch(InittedEverResultStatus.INITTED);
final CountDownLatch inProgressLatch = new CountDownLatch(1);
DetectorProfile expectedProfile = new DetectorProfile.Builder().state(DetectorState.RUNNING).build();
runner.profile(detectorId, ActionListener.wrap(response -> {
assertEquals(expectedProfile, response);
inProgressLatch.countDown();
}, exception -> {
assertTrue("Should not reach here", false);
inProgressLatch.countDown();
}), stateNError);
assertTrue(inProgressLatch.await(100, TimeUnit.SECONDS));
}
use of org.opensearch.ad.model.DetectorProfile in project anomaly-detection by opensearch-project.
the class AnomalyDetectorProfileRunnerTests method testInitNoUpdateNoIndex.
public void testInitNoUpdateNoIndex() throws IOException, InterruptedException {
setUpClientGet(DetectorStatus.EXIST, JobStatus.ENABLED, RCFPollingStatus.EMPTY, ErrorResultStatus.NO_ERROR);
DetectorProfile expectedProfile = new DetectorProfile.Builder().state(DetectorState.INIT).initProgress(new InitProgressProfile("0%", detectorIntervalMin * requiredSamples, requiredSamples)).build();
final CountDownLatch inProgressLatch = new CountDownLatch(1);
runner.profile(detector.getDetectorId(), ActionListener.wrap(response -> {
assertEquals(expectedProfile, response);
inProgressLatch.countDown();
}, exception -> {
LOG.error(exception);
for (StackTraceElement ste : exception.getStackTrace()) {
LOG.info(ste);
}
assertTrue("Should not reach here ", false);
inProgressLatch.countDown();
}), stateInitProgress);
assertTrue(inProgressLatch.await(100, TimeUnit.SECONDS));
}
use of org.opensearch.ad.model.DetectorProfile in project anomaly-detection by opensearch-project.
the class AnomalyDetectorProfileRunnerTests method testInitProgressFailImmediately.
public void testInitProgressFailImmediately() throws IOException, InterruptedException {
setUpClientGet(DetectorStatus.NO_DOC, JobStatus.ENABLED, RCFPollingStatus.INITTING, ErrorResultStatus.NO_ERROR);
DetectorProfile expectedProfile = new DetectorProfile.Builder().state(DetectorState.INIT).build();
// 123 / 128 rounded to 96%
InitProgressProfile profile = new InitProgressProfile("96%", neededSamples * detectorIntervalMin, neededSamples);
expectedProfile.setInitProgress(profile);
final CountDownLatch inProgressLatch = new CountDownLatch(1);
runner.profile(detector.getDetectorId(), ActionListener.wrap(response -> {
assertTrue("Should not reach here ", false);
inProgressLatch.countDown();
}, exception -> {
assertTrue(exception.getMessage().contains(CommonErrorMessages.FAIL_TO_FIND_DETECTOR_MSG));
inProgressLatch.countDown();
}), stateInitProgress);
assertTrue(inProgressLatch.await(100, TimeUnit.SECONDS));
}
use of org.opensearch.ad.model.DetectorProfile in project anomaly-detection by opensearch-project.
the class AnomalyDetectorProfileRunnerTests method testDisabledJobIndexTemplate.
public void testDisabledJobIndexTemplate(JobStatus status) throws IOException, InterruptedException {
setUpClientGet(DetectorStatus.EXIST, status, RCFPollingStatus.EMPTY, ErrorResultStatus.NO_ERROR);
DetectorProfile expectedProfile = new DetectorProfile.Builder().state(DetectorState.DISABLED).build();
final CountDownLatch inProgressLatch = new CountDownLatch(1);
runner.profile(detector.getDetectorId(), ActionListener.wrap(response -> {
assertEquals(expectedProfile, response);
inProgressLatch.countDown();
}, exception -> {
assertTrue("Should not reach here ", false);
inProgressLatch.countDown();
}), stateOnly);
assertTrue(inProgressLatch.await(100, TimeUnit.SECONDS));
}
use of org.opensearch.ad.model.DetectorProfile in project anomaly-detection by opensearch-project.
the class AnomalyDetectorProfileRunnerTests method testInitOrRunningStateTemplate.
public void testInitOrRunningStateTemplate(RCFPollingStatus status, DetectorState expectedState) throws IOException, InterruptedException {
setUpClientGet(DetectorStatus.EXIST, JobStatus.ENABLED, status, ErrorResultStatus.NO_ERROR);
DetectorProfile expectedProfile = new DetectorProfile.Builder().state(expectedState).build();
final CountDownLatch inProgressLatch = new CountDownLatch(1);
runner.profile(detector.getDetectorId(), ActionListener.wrap(response -> {
assertEquals(expectedProfile, response);
inProgressLatch.countDown();
}, exception -> {
logger.error(exception);
for (StackTraceElement ste : exception.getStackTrace()) {
logger.info(ste);
}
assertTrue("Should not reach here ", false);
inProgressLatch.countDown();
}), stateOnly);
assertTrue(inProgressLatch.await(100, TimeUnit.SECONDS));
}
Aggregations