|
40 | 40 | import org.elasticsearch.xpack.core.ml.job.config.JobState;
|
41 | 41 | import org.elasticsearch.xpack.core.ml.job.config.JobTaskState;
|
42 | 42 | import org.elasticsearch.xpack.core.ml.job.persistence.AnomalyDetectorsIndex;
|
| 43 | +import org.elasticsearch.xpack.core.ml.job.persistence.ElasticsearchMappings; |
43 | 44 | import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSnapshot;
|
44 | 45 | import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper;
|
45 | 46 | import org.elasticsearch.xpack.ml.MachineLearning;
|
@@ -195,13 +196,27 @@ protected void nodeOperation(AllocatedPersistentTask task, OpenJobAction.JobPara
|
195 | 196 | jobTask.setAutodetectProcessManager(autodetectProcessManager);
|
196 | 197 | JobTaskState jobTaskState = (JobTaskState) state;
|
197 | 198 | JobState jobState = jobTaskState == null ? null : jobTaskState.getState();
|
198 |
| - jobResultsProvider.setRunningForecastsToFailed(params.getJobId(), ActionListener.wrap( |
199 |
| - r -> runJob(jobTask, jobState, params), |
| 199 | + ActionListener<Boolean> resultsMappingUpdateHandler = ActionListener.wrap( |
| 200 | + mappingsUpdate -> jobResultsProvider.setRunningForecastsToFailed(params.getJobId(), ActionListener.wrap( |
| 201 | + r -> runJob(jobTask, jobState, params), |
| 202 | + e -> { |
| 203 | + logger.warn(new ParameterizedMessage("[{}] failed to set forecasts to failed", params.getJobId()), e); |
| 204 | + runJob(jobTask, jobState, params); |
| 205 | + } |
| 206 | + )), |
200 | 207 | e -> {
|
201 |
| - logger.warn(new ParameterizedMessage("[{}] failed to set forecasts to failed", params.getJobId()), e); |
202 |
| - runJob(jobTask, jobState, params); |
| 208 | + logger.error(new ParameterizedMessage("[{}] Failed to update results mapping", params.getJobId()), e); |
| 209 | + jobTask.markAsFailed(e); |
203 | 210 | }
|
204 |
| - )); |
| 211 | + ); |
| 212 | + // We need to update the results index as we MAY update the current forecast results, setting the running forcasts to failed |
| 213 | + // This writes to the results index, which might need updating |
| 214 | + ElasticsearchMappings.addDocMappingIfMissing( |
| 215 | + AnomalyDetectorsIndex.jobResultsAliasedName(params.getJobId()), |
| 216 | + AnomalyDetectorsIndex::resultsMapping, |
| 217 | + client, |
| 218 | + clusterState, |
| 219 | + resultsMappingUpdateHandler); |
205 | 220 | }
|
206 | 221 |
|
207 | 222 | private void runJob(JobTask jobTask, JobState jobState, OpenJobAction.JobParams params) {
|
|
0 commit comments