Skip to content

Commit 263ab23

Browse files
committed
Check job groups on update
1 parent b1f891b commit 263ab23

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/JobManager.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,35 @@ public void onFailure(Exception e) {
437437

438438
public void updateJob(UpdateJobAction.Request request, ActionListener<PutJobAction.Response> actionListener) {
439439
MlMetadata mlMetadata = MlMetadata.getMlMetadata(clusterService.state());
440+
441+
if (request.getJobUpdate().getGroups() != null && request.getJobUpdate().getGroups().isEmpty() == false) {
442+
443+
// check the new groups are not job Ids
444+
for (String group : request.getJobUpdate().getGroups()) {
445+
if (mlMetadata.getJobs().containsKey(group)) {
446+
actionListener.onFailure(new ResourceAlreadyExistsException(
447+
Messages.getMessage(Messages.JOB_AND_GROUP_NAMES_MUST_BE_UNIQUE, group)));
448+
}
449+
}
450+
451+
jobConfigProvider.jobIdMatches(request.getJobUpdate().getGroups(), ActionListener.wrap(
452+
matchingIds -> {
453+
if (matchingIds.isEmpty()) {
454+
updateJobPostInitialChecks(request, mlMetadata, actionListener);
455+
} else {
456+
actionListener.onFailure(new ResourceAlreadyExistsException(
457+
Messages.getMessage(Messages.JOB_AND_GROUP_NAMES_MUST_BE_UNIQUE, matchingIds.get(0))));
458+
}
459+
},
460+
actionListener::onFailure
461+
));
462+
} else {
463+
updateJobPostInitialChecks(request, mlMetadata, actionListener);
464+
}
465+
}
466+
467+
private void updateJobPostInitialChecks(UpdateJobAction.Request request, MlMetadata mlMetadata,
468+
ActionListener<PutJobAction.Response> actionListener) {
440469
if (ClusterStateJobUpdate.jobIsInMlMetadata(mlMetadata, request.getJobId())) {
441470
updateJobClusterState(request, actionListener);
442471
} else {

x-pack/plugin/src/test/resources/rest-api-spec/test/ml/jobs_crud.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,28 @@
397397
"description":"Can't update all description"
398398
}
399399
400+
- do:
401+
xpack.ml.put_job:
402+
job_id: job-crud-update-group-name-clash
403+
body: >
404+
{
405+
"analysis_config" : {
406+
"bucket_span": "1h",
407+
"detectors" :[{"function":"metric","field_name":"responsetime","by_field_name":"airline"}]
408+
},
409+
"data_description" : {
410+
}
411+
}
412+
413+
- do:
414+
catch: "/job and group names must be unique/"
415+
xpack.ml.update_job:
416+
job_id: jobs-crud-update-job
417+
body: >
418+
{
419+
"groups": ["job-crud-update-group-name-clash"]
420+
}
421+
400422
---
401423
"Test cannot decrease model_memory_limit below current usage":
402424
- skip:

0 commit comments

Comments
 (0)