[ML] Closing an unknown job should throw resource not found exception (elastic/x-pack-elasticsearch#1673)
Original commit: elastic/x-pack-elasticsearch@c244d2809b
This commit is contained in:
parent
d6e92c19da
commit
d64bea14dc
|
@ -563,12 +563,9 @@ public class CloseJobAction extends Action<CloseJobAction.Request, CloseJobActio
|
|||
*/
|
||||
static void resolveAndValidateJobId(String jobId, ClusterState state, List<String> openJobIds, List<String> closingJobIds,
|
||||
boolean allowFailed) {
|
||||
MlMetadata mlMetadata = state.metaData().custom(MlMetadata.TYPE);
|
||||
PersistentTasksCustomMetaData tasksMetaData = state.getMetaData().custom(PersistentTasksCustomMetaData.TYPE);
|
||||
|
||||
if (mlMetadata.getJobs().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
MlMetadata maybeNull = state.metaData().custom(MlMetadata.TYPE);
|
||||
final MlMetadata mlMetadata = (maybeNull == null) ? MlMetadata.EMPTY_METADATA : maybeNull;
|
||||
|
||||
List<String> failedJobs = new ArrayList<>();
|
||||
|
||||
|
@ -582,6 +579,9 @@ public class CloseJobAction extends Action<CloseJobAction.Request, CloseJobActio
|
|||
};
|
||||
|
||||
if (!Job.ALL.equals(jobId)) {
|
||||
if (mlMetadata.getJobs().containsKey(jobId) == false) {
|
||||
throw ExceptionsHelper.missingJobException(jobId);
|
||||
}
|
||||
jobIdProcessor.accept(jobId);
|
||||
|
||||
if (allowFailed == false && failedJobs.size() > 0) {
|
||||
|
|
|
@ -177,6 +177,21 @@ public class CloseJobActionRequestTests extends AbstractStreamableXContentTestCa
|
|||
assertEquals(Collections.emptyList(), closingJobs);
|
||||
}
|
||||
|
||||
public void testResolve_throwsWithUnknownJobId() {
|
||||
MlMetadata.Builder mlBuilder = new MlMetadata.Builder();
|
||||
mlBuilder.putJob(BaseMlIntegTestCase.createFareQuoteJob("job_id_1").build(new Date()), false);
|
||||
|
||||
ClusterState cs1 = ClusterState.builder(new ClusterName("_name"))
|
||||
.metaData(new MetaData.Builder().putCustom(MlMetadata.TYPE, mlBuilder.build()))
|
||||
.build();
|
||||
|
||||
List<String> openJobs = new ArrayList<>();
|
||||
List<String> closingJobs = new ArrayList<>();
|
||||
|
||||
expectThrows(ResourceNotFoundException.class,
|
||||
() -> CloseJobAction.resolveAndValidateJobId("missing-job", cs1, openJobs, closingJobs, false));
|
||||
}
|
||||
|
||||
public void testResolve_givenJobIdFailed() {
|
||||
MlMetadata.Builder mlBuilder = new MlMetadata.Builder();
|
||||
mlBuilder.putJob(BaseMlIntegTestCase.createFareQuoteJob("job_id_failed").build(new Date()), false);
|
||||
|
|
|
@ -572,6 +572,18 @@
|
|||
force: true
|
||||
- match: { closed: true }
|
||||
|
||||
---
|
||||
"Test open and close an unknown job is resource not found":
|
||||
- do:
|
||||
catch: missing
|
||||
xpack.ml.open_job:
|
||||
job_id: jobs-crud-some-missing-job-i-made-up
|
||||
|
||||
- do:
|
||||
catch: missing
|
||||
xpack.ml.close_job:
|
||||
job_id: jobs-crud-some-missing-job-i-made-up
|
||||
|
||||
---
|
||||
"Test cannot create job with existing categorizer state document":
|
||||
|
||||
|
|
Loading…
Reference in New Issue