[ML] Add the current job state in conflict error messages (elastic/x-pack-elasticsearch#1158)
Relates elastic/x-pack-elasticsearch#878 Original commit: elastic/x-pack-elasticsearch@2be8b6c9a1
This commit is contained in:
parent
d993926ba4
commit
e0b6630e3d
|
@ -361,7 +361,8 @@ public class MlMetadata implements MetaData.Custom {
|
||||||
}
|
}
|
||||||
PersistentTask<?> jobTask = getJobTask(jobId, tasks);
|
PersistentTask<?> jobTask = getJobTask(jobId, tasks);
|
||||||
if (jobTask != null) {
|
if (jobTask != null) {
|
||||||
throw ExceptionsHelper.conflictStatusException("Cannot delete job [" + jobId + "] because the job hasn't been closed");
|
throw ExceptionsHelper.conflictStatusException("Cannot delete job [" + jobId + "] because the job is "
|
||||||
|
+ jobTask.getStatus());
|
||||||
}
|
}
|
||||||
Job.Builder jobBuilder = new Job.Builder(job);
|
Job.Builder jobBuilder = new Job.Builder(job);
|
||||||
jobBuilder.setDeleted(true);
|
jobBuilder.setDeleted(true);
|
||||||
|
|
|
@ -573,21 +573,18 @@ public class CloseJobAction extends Action<CloseJobAction.Request, CloseJobActio
|
||||||
.custom(PersistentTasksCustomMetaData.TYPE);
|
.custom(PersistentTasksCustomMetaData.TYPE);
|
||||||
PersistentTask<?> jobTask = MlMetadata.getJobTask(jobId, tasks);
|
PersistentTask<?> jobTask = MlMetadata.getJobTask(jobId, tasks);
|
||||||
if (jobTask == null || jobTask.getStatus() == null) {
|
if (jobTask == null || jobTask.getStatus() == null) {
|
||||||
throw new ElasticsearchStatusException("cannot close job, because job [" + jobId + "] is not open", RestStatus.CONFLICT);
|
throw ExceptionsHelper.conflictStatusException("cannot close job, because job [" + jobId + "] is " + JobState.CLOSED);
|
||||||
}
|
}
|
||||||
JobTaskStatus jobTaskStatus = (JobTaskStatus) jobTask.getStatus();
|
JobTaskStatus jobTaskStatus = (JobTaskStatus) jobTask.getStatus();
|
||||||
if (jobTaskStatus.getState().isAnyOf(JobState.OPENED, JobState.FAILED) == false) {
|
if (jobTaskStatus.getState().isAnyOf(JobState.OPENED, JobState.FAILED) == false) {
|
||||||
throw new ElasticsearchStatusException("cannot close job, because job [" + jobId + "] is not open", RestStatus.CONFLICT);
|
throw ExceptionsHelper.conflictStatusException("cannot close job, because job [" + jobId + "] is " + jobTaskStatus.getState());
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<DatafeedConfig> datafeed = mlMetadata.getDatafeedByJobId(jobId);
|
Optional<DatafeedConfig> datafeed = mlMetadata.getDatafeedByJobId(jobId);
|
||||||
if (datafeed.isPresent()) {
|
if (datafeed.isPresent()) {
|
||||||
DatafeedState datafeedState = MlMetadata.getDatafeedState(datafeed.get().getId(),
|
DatafeedState datafeedState = MlMetadata.getDatafeedState(datafeed.get().getId(), tasks);
|
||||||
tasks);
|
|
||||||
if (datafeedState != DatafeedState.STOPPED) {
|
if (datafeedState != DatafeedState.STOPPED) {
|
||||||
throw new ElasticsearchStatusException(
|
throw ExceptionsHelper.conflictStatusException("cannot close job [{}], datafeed hasn't been stopped", jobId);
|
||||||
"cannot close job [{}], datafeed hasn't been stopped", RestStatus.CONFLICT,
|
|
||||||
jobId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return jobTask;
|
return jobTask;
|
||||||
|
|
|
@ -16,6 +16,8 @@ import org.elasticsearch.xpack.ml.job.messages.Messages;
|
||||||
|
|
||||||
public class ExceptionsHelper {
|
public class ExceptionsHelper {
|
||||||
|
|
||||||
|
private ExceptionsHelper() {}
|
||||||
|
|
||||||
public static ResourceNotFoundException missingJobException(String jobId) {
|
public static ResourceNotFoundException missingJobException(String jobId) {
|
||||||
return new ResourceNotFoundException(Messages.getMessage(Messages.JOB_UNKNOWN_ID, jobId));
|
return new ResourceNotFoundException(Messages.getMessage(Messages.JOB_UNKNOWN_ID, jobId));
|
||||||
}
|
}
|
||||||
|
@ -36,8 +38,8 @@ public class ExceptionsHelper {
|
||||||
return new ElasticsearchException(msg, cause);
|
return new ElasticsearchException(msg, cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ElasticsearchStatusException conflictStatusException(String msg) {
|
public static ElasticsearchStatusException conflictStatusException(String msg, Object... args) {
|
||||||
return new ElasticsearchStatusException(msg, RestStatus.CONFLICT);
|
return new ElasticsearchStatusException(msg, RestStatus.CONFLICT, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue