use of org.opensearch.ad.model.DetectorInternalState in project anomaly-detection by opensearch-project.
the class ADDataMigrator method backfillRealtimeTask.
/**
* Backfill realtiem task for realtime job.
* @param detectorJobs realtime AD jobs
* @param backfillAllJob backfill task for all realtime job or not
*/
public void backfillRealtimeTask(ConcurrentLinkedQueue<AnomalyDetectorJob> detectorJobs, boolean backfillAllJob) {
AnomalyDetectorJob job = detectorJobs.poll();
if (job == null) {
logger.info("AD data migration done.");
if (backfillAllJob) {
this.dataMigrated.set(true);
}
return;
}
String jobId = job.getName();
AnomalyDetectorFunction createRealtimeTaskFunction = () -> {
GetRequest getRequest = new GetRequest(DETECTION_STATE_INDEX, jobId);
client.get(getRequest, ActionListener.wrap(r -> {
if (r != null && r.isExists()) {
try (XContentParser parser = createXContentParserFromRegistry(xContentRegistry, r.getSourceAsBytesRef())) {
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser);
DetectorInternalState detectorState = DetectorInternalState.parse(parser);
createRealtimeADTask(job, detectorState.getError(), detectorJobs, backfillAllJob);
} catch (IOException e) {
logger.error("Failed to parse detector internal state " + jobId, e);
createRealtimeADTask(job, null, detectorJobs, backfillAllJob);
}
} else {
createRealtimeADTask(job, null, detectorJobs, backfillAllJob);
}
}, e -> {
logger.error("Failed to query detector internal state " + jobId, e);
createRealtimeADTask(job, null, detectorJobs, backfillAllJob);
}));
};
checkIfRealtimeTaskExistsAndBackfill(job, createRealtimeTaskFunction, detectorJobs, backfillAllJob);
}
Aggregations