use of org.opensearch.ad.transport.ADCancelTaskRequest in project anomaly-detection by opensearch-project.
the class ADTaskManager method stopHistoricalAnalysis.
private void stopHistoricalAnalysis(String detectorId, Optional<ADTask> adTask, User user, ActionListener<AnomalyDetectorJobResponse> listener) {
if (!adTask.isPresent()) {
listener.onFailure(new ResourceNotFoundException(detectorId, "Detector not started"));
return;
}
if (adTask.get().isDone()) {
listener.onFailure(new ResourceNotFoundException(detectorId, "No running task found"));
return;
}
String taskId = adTask.get().getTaskId();
DiscoveryNode[] dataNodes = hashRing.getNodesWithSameLocalAdVersion();
String userName = user == null ? null : user.getName();
ADCancelTaskRequest cancelTaskRequest = new ADCancelTaskRequest(detectorId, taskId, userName, dataNodes);
client.execute(ADCancelTaskAction.INSTANCE, cancelTaskRequest, ActionListener.wrap(response -> {
listener.onResponse(new AnomalyDetectorJobResponse(taskId, 0, 0, 0, RestStatus.OK));
}, e -> {
logger.error("Failed to cancel AD task " + taskId + ", detector id: " + detectorId, e);
listener.onFailure(e);
}));
}
Aggregations