|
@@ -7,6 +7,7 @@ package org.elasticsearch.xpack.ml.action;
|
|
|
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
+import org.apache.logging.log4j.message.ParameterizedMessage;
|
|
|
import org.elasticsearch.ElasticsearchException;
|
|
|
import org.elasticsearch.ElasticsearchStatusException;
|
|
|
import org.elasticsearch.ResourceAlreadyExistsException;
|
|
@@ -58,6 +59,7 @@ import org.elasticsearch.xpack.ml.MachineLearning;
|
|
|
import org.elasticsearch.xpack.ml.MlConfigMigrationEligibilityCheck;
|
|
|
import org.elasticsearch.xpack.ml.job.JobNodeSelector;
|
|
|
import org.elasticsearch.xpack.ml.job.persistence.JobConfigProvider;
|
|
|
+import org.elasticsearch.xpack.ml.job.persistence.JobResultsProvider;
|
|
|
import org.elasticsearch.xpack.ml.job.process.autodetect.AutodetectProcessManager;
|
|
|
import org.elasticsearch.xpack.ml.process.MlMemoryTracker;
|
|
|
|
|
@@ -348,6 +350,7 @@ public class TransportOpenJobAction extends TransportMasterNodeAction<OpenJobAct
|
|
|
private final MlMemoryTracker memoryTracker;
|
|
|
private final Client client;
|
|
|
private final IndexNameExpressionResolver expressionResolver;
|
|
|
+ private final JobResultsProvider jobResultsProvider;
|
|
|
|
|
|
private volatile int maxConcurrentJobAllocations;
|
|
|
private volatile int maxMachineMemoryPercent;
|
|
@@ -363,6 +366,7 @@ public class TransportOpenJobAction extends TransportMasterNodeAction<OpenJobAct
|
|
|
this.memoryTracker = Objects.requireNonNull(memoryTracker);
|
|
|
this.client = Objects.requireNonNull(client);
|
|
|
this.expressionResolver = Objects.requireNonNull(expressionResolver);
|
|
|
+ this.jobResultsProvider = new JobResultsProvider(client, settings, expressionResolver);
|
|
|
this.maxConcurrentJobAllocations = MachineLearning.CONCURRENT_JOB_ALLOCATIONS.get(settings);
|
|
|
this.maxMachineMemoryPercent = MachineLearning.MAX_MACHINE_MEMORY_PERCENT.get(settings);
|
|
|
this.maxLazyMLNodes = MachineLearning.MAX_LAZY_ML_NODES.get(settings);
|
|
@@ -440,6 +444,16 @@ public class TransportOpenJobAction extends TransportMasterNodeAction<OpenJobAct
|
|
|
jobTask.autodetectProcessManager = autodetectProcessManager;
|
|
|
JobTaskState jobTaskState = (JobTaskState) state;
|
|
|
JobState jobState = jobTaskState == null ? null : jobTaskState.getState();
|
|
|
+ jobResultsProvider.setRunningForecastsToFailed(params.getJobId(), ActionListener.wrap(
|
|
|
+ r -> runJob(jobTask, jobState, params),
|
|
|
+ e -> {
|
|
|
+ logger.warn(new ParameterizedMessage("[{}] failed to set forecasts to failed", params.getJobId()), e);
|
|
|
+ runJob(jobTask, jobState, params);
|
|
|
+ }
|
|
|
+ ));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void runJob(JobTask jobTask, JobState jobState, OpenJobAction.JobParams params) {
|
|
|
// If the job is closing, simply stop and return
|
|
|
if (JobState.CLOSING.equals(jobState)) {
|
|
|
// Mark as completed instead of using `stop` as stop assumes native processes have started
|
|
@@ -461,22 +475,22 @@ public class TransportOpenJobAction extends TransportMasterNodeAction<OpenJobAct
|
|
|
FinalizeJobExecutionAction.Request finalizeRequest = new FinalizeJobExecutionAction.Request(new String[]{jobId});
|
|
|
executeAsyncWithOrigin(client, ML_ORIGIN, FinalizeJobExecutionAction.INSTANCE, finalizeRequest,
|
|
|
ActionListener.wrap(
|
|
|
- response -> task.markAsCompleted(),
|
|
|
+ response -> jobTask.markAsCompleted(),
|
|
|
e -> {
|
|
|
logger.error("error finalizing job [" + jobId + "]", e);
|
|
|
Throwable unwrapped = ExceptionsHelper.unwrapCause(e);
|
|
|
if (unwrapped instanceof DocumentMissingException || unwrapped instanceof ResourceNotFoundException) {
|
|
|
- task.markAsCompleted();
|
|
|
+ jobTask.markAsCompleted();
|
|
|
} else {
|
|
|
- task.markAsFailed(e);
|
|
|
+ jobTask.markAsFailed(e);
|
|
|
}
|
|
|
}
|
|
|
));
|
|
|
} else {
|
|
|
- task.markAsCompleted();
|
|
|
+ jobTask.markAsCompleted();
|
|
|
}
|
|
|
} else {
|
|
|
- task.markAsFailed(e2);
|
|
|
+ jobTask.markAsFailed(e2);
|
|
|
}
|
|
|
});
|
|
|
}
|