use of org.opensearch.ad.model.DetectorProfileName in project anomaly-detection by opensearch-project.
the class AnomalyDetectorJobRunner method updateRealtimeTask.
private void updateRealtimeTask(AnomalyResultResponse response, String detectorId) {
if (response.isHCDetector() != null && response.isHCDetector() && !adTaskManager.skipUpdateHCRealtimeTask(detectorId, response.getError())) {
DiscoveryNode[] dataNodes = nodeFilter.getEligibleDataNodes();
Set<DetectorProfileName> profiles = new HashSet<>();
profiles.add(DetectorProfileName.INIT_PROGRESS);
ProfileRequest profileRequest = new ProfileRequest(detectorId, profiles, true, dataNodes);
client.execute(ProfileAction.INSTANCE, profileRequest, ActionListener.wrap(r -> {
log.debug("Update latest realtime task for HC detector {}, total updates: {}", detectorId, r.getTotalUpdates());
updateLatestRealtimeTask(detectorId, null, r.getTotalUpdates(), response.getDetectorIntervalInMinutes(), response.getError());
}, e -> {
log.error("Failed to update latest realtime task for " + detectorId, e);
}));
} else {
log.debug("Update latest realtime task for SINGLE detector {}, total updates: {}", detectorId, response.getRcfTotalUpdates());
updateLatestRealtimeTask(detectorId, null, response.getRcfTotalUpdates(), response.getDetectorIntervalInMinutes(), response.getError());
}
}
use of org.opensearch.ad.model.DetectorProfileName in project anomaly-detection by opensearch-project.
the class MultiEntityProfileRunnerTests method setUp.
@SuppressWarnings("unchecked")
@Before
@Override
public void setUp() throws Exception {
super.setUp();
client = mock(Client.class);
nodeFilter = mock(DiscoveryNodeFilterer.class);
requiredSamples = 128;
detectorId = "A69pa3UBHuCbh-emo9oR";
detector = TestHelpers.randomAnomalyDetectorUsingCategoryFields(detectorId, Arrays.asList("a"));
result = new DetectorInternalState.Builder().lastUpdateTime(Instant.now());
job = TestHelpers.randomAnomalyDetectorJob(true);
adTaskManager = mock(ADTaskManager.class);
transportService = mock(TransportService.class);
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
Consumer<Optional<ADTask>> function = (Consumer<Optional<ADTask>>) args[2];
function.accept(Optional.of(TestHelpers.randomAdTask()));
return null;
}).when(adTaskManager).getAndExecuteOnLatestDetectorLevelTask(any(), any(), any(), any(), anyBoolean(), any());
runner = new AnomalyDetectorProfileRunner(client, xContentRegistry(), nodeFilter, requiredSamples, transportService, adTaskManager);
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
GetRequest request = (GetRequest) args[0];
ActionListener<GetResponse> listener = (ActionListener<GetResponse>) args[1];
String indexName = request.index();
if (indexName.equals(ANOMALY_DETECTORS_INDEX)) {
listener.onResponse(TestHelpers.createGetResponse(detector, detector.getDetectorId(), AnomalyDetector.ANOMALY_DETECTORS_INDEX));
} else if (indexName.equals(CommonName.DETECTION_STATE_INDEX)) {
listener.onResponse(TestHelpers.createGetResponse(result.build(), detector.getDetectorId(), CommonName.DETECTION_STATE_INDEX));
} else if (indexName.equals(ANOMALY_DETECTOR_JOB_INDEX)) {
listener.onResponse(TestHelpers.createGetResponse(job, detector.getDetectorId(), AnomalyDetectorJob.ANOMALY_DETECTOR_JOB_INDEX));
}
return null;
}).when(client).get(any(), any());
stateNError = new HashSet<DetectorProfileName>();
stateNError.add(DetectorProfileName.ERROR);
stateNError.add(DetectorProfileName.STATE);
}
use of org.opensearch.ad.model.DetectorProfileName in project anomaly-detection by opensearch-project.
the class AbstractProfileRunnerTests method setUpOnce.
@BeforeClass
public static void setUpOnce() {
stateOnly = new HashSet<DetectorProfileName>();
stateOnly.add(DetectorProfileName.STATE);
stateNError = new HashSet<DetectorProfileName>();
stateNError.add(DetectorProfileName.ERROR);
stateNError.add(DetectorProfileName.STATE);
stateInitProgress = new HashSet<DetectorProfileName>();
stateInitProgress.add(DetectorProfileName.INIT_PROGRESS);
stateInitProgress.add(DetectorProfileName.STATE);
modelProfile = new HashSet<DetectorProfileName>(Arrays.asList(DetectorProfileName.SHINGLE_SIZE, DetectorProfileName.MODELS, DetectorProfileName.COORDINATING_NODE, DetectorProfileName.TOTAL_SIZE_IN_BYTES));
totalInitProgress = new HashSet<DetectorProfileName>(Arrays.asList(DetectorProfileName.TOTAL_ENTITIES, DetectorProfileName.INIT_PROGRESS));
initProgressErrorProfile = new HashSet<DetectorProfileName>(Arrays.asList(DetectorProfileName.INIT_PROGRESS, DetectorProfileName.ERROR));
clusterName = "test-cluster-name";
discoveryNode1 = new DiscoveryNode("nodeName1", "node1", new TransportAddress(TransportAddress.META_ADDRESS, 9300), emptyMap(), emptySet(), Version.CURRENT);
}
use of org.opensearch.ad.model.DetectorProfileName in project anomaly-detection by opensearch-project.
the class ProfileTests method testProfileNodeRequest.
@Test
public void testProfileNodeRequest() throws IOException {
Set<DetectorProfileName> profilesToRetrieve = new HashSet<DetectorProfileName>();
profilesToRetrieve.add(DetectorProfileName.COORDINATING_NODE);
ProfileRequest ProfileRequest = new ProfileRequest(detectorId, profilesToRetrieve, false);
ProfileNodeRequest ProfileNodeRequest = new ProfileNodeRequest(ProfileRequest);
assertEquals("ProfileNodeRequest has the wrong detector id", ProfileNodeRequest.getDetectorId(), detectorId);
assertEquals("ProfileNodeRequest has the wrong ProfileRequest", ProfileNodeRequest.getProfilesToBeRetrieved(), profilesToRetrieve);
// Test serialization
BytesStreamOutput output = new BytesStreamOutput();
ProfileNodeRequest.writeTo(output);
StreamInput streamInput = output.bytes().streamInput();
ProfileNodeRequest nodeRequest = new ProfileNodeRequest(streamInput);
assertEquals("serialization has the wrong detector id", nodeRequest.getDetectorId(), detectorId);
assertEquals("serialization has the wrong ProfileRequest", nodeRequest.getProfilesToBeRetrieved(), profilesToRetrieve);
}
use of org.opensearch.ad.model.DetectorProfileName in project anomaly-detection by opensearch-project.
the class ProfileTests method testProfileRequest.
@Test
public void testProfileRequest() throws IOException {
String detectorId = "123";
Set<DetectorProfileName> profilesToRetrieve = new HashSet<DetectorProfileName>();
profilesToRetrieve.add(DetectorProfileName.COORDINATING_NODE);
ProfileRequest profileRequest = new ProfileRequest(detectorId, profilesToRetrieve, false);
// Test Serialization
BytesStreamOutput output = new BytesStreamOutput();
profileRequest.writeTo(output);
StreamInput streamInput = output.bytes().streamInput();
ProfileRequest readRequest = new ProfileRequest(streamInput);
assertEquals("Serialization has the wrong profiles to be retrieved", readRequest.getProfilesToBeRetrieved(), profileRequest.getProfilesToBeRetrieved());
assertEquals("Serialization has the wrong detector id", readRequest.getDetectorId(), profileRequest.getDetectorId());
}
Aggregations