[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);
|
||||
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);
|
||||
jobBuilder.setDeleted(true);
|
||||
|
|
|
@ -573,21 +573,18 @@ public class CloseJobAction extends Action<CloseJobAction.Request, CloseJobActio
|
|||
.custom(PersistentTasksCustomMetaData.TYPE);
|
||||
PersistentTask<?> jobTask = MlMetadata.getJobTask(jobId, tasks);
|
||||
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();
|
||||
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);
|
||||
if (datafeed.isPresent()) {
|
||||
DatafeedState datafeedState = MlMetadata.getDatafeedState(datafeed.get().getId(),
|
||||
tasks);
|
||||
DatafeedState datafeedState = MlMetadata.getDatafeedState(datafeed.get().getId(), tasks);
|
||||
if (datafeedState != DatafeedState.STOPPED) {
|
||||
throw new ElasticsearchStatusException(
|
||||
"cannot close job [{}], datafeed hasn't been stopped", RestStatus.CONFLICT,
|
||||
jobId);
|
||||
throw ExceptionsHelper.conflictStatusException("cannot close job [{}], datafeed hasn't been stopped", jobId);
|
||||
}
|
||||
}
|
||||
return jobTask;
|
||||
|
|
|
@ -16,6 +16,8 @@ import org.elasticsearch.xpack.ml.job.messages.Messages;
|
|||
|
||||
public class ExceptionsHelper {
|
||||
|
||||
private ExceptionsHelper() {}
|
||||
|
||||
public static ResourceNotFoundException missingJobException(String jobId) {
|
||||
return new ResourceNotFoundException(Messages.getMessage(Messages.JOB_UNKNOWN_ID, jobId));
|
||||
}
|
||||
|
@ -36,8 +38,8 @@ public class ExceptionsHelper {
|
|||
return new ElasticsearchException(msg, cause);
|
||||
}
|
||||
|
||||
public static ElasticsearchStatusException conflictStatusException(String msg) {
|
||||
return new ElasticsearchStatusException(msg, RestStatus.CONFLICT);
|
||||
public static ElasticsearchStatusException conflictStatusException(String msg, Object... args) {
|
||||
return new ElasticsearchStatusException(msg, RestStatus.CONFLICT, args);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue