[ML] Fix NPE

Original commit: elastic/x-pack-elasticsearch@421491bce0
This commit is contained in:
Martijn van Groningen 2017-04-04 16:15:56 +02:00
parent 543319f966
commit 71149fb6d4
1 changed files with 7 additions and 2 deletions

View File

@ -249,8 +249,13 @@ public class CloseJobAction extends Action<CloseJobAction.Request, CloseJobActio
ClusterState currentState = clusterService.state();
if (request.isForce()) {
PersistentTasksCustomMetaData tasks = currentState.getMetaData().custom(PersistentTasksCustomMetaData.TYPE);
PersistentTask<?> jobTask = MlMetadata.getJobTask(request.getJobId(), tasks);
forceCloseJob(jobTask.getId(), request.getJobId(), listener);
String jobId = request.getJobId();
PersistentTask<?> jobTask = MlMetadata.getJobTask(jobId, tasks);
if (jobTask == null) {
throw new ElasticsearchStatusException("cannot force close job, because job [" + jobId + "] is not open",
RestStatus.CONFLICT);
}
forceCloseJob(jobTask.getId(), jobId, listener);
} else {
PersistentTask<?> jobTask = validateAndReturnJobTask(request.getJobId(), currentState);
normalCloseJob(task, jobTask.getId(), request, listener);