Skip to content

[ML] JIndex: Check group names against job Ids on update #36317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -328,49 +328,63 @@ public void onFailure(Exception e) {

public void updateJob(UpdateJobAction.Request request, ActionListener<PutJobAction.Response> actionListener) {

ActionListener<Job> postUpdateAction;
Runnable doUpdate = () -> {
jobConfigProvider.updateJobWithValidation(request.getJobId(), request.getJobUpdate(), maxModelMemoryLimit,
this::validate, ActionListener.wrap(
updatedJob -> postJobUpdate(request, updatedJob, actionListener),
actionListener::onFailure
));
};

// Autodetect must be updated if the fields that the C++ uses are changed
if (request.getJobUpdate().isAutodetectProcessUpdate()) {
postUpdateAction = ActionListener.wrap(
updatedJob -> {
JobUpdate jobUpdate = request.getJobUpdate();
if (isJobOpen(clusterService.state(), request.getJobId())) {
updateJobProcessNotifier.submitJobUpdate(UpdateParams.fromJobUpdate(jobUpdate), ActionListener.wrap(
isUpdated -> {
if (isUpdated) {
auditJobUpdatedIfNotInternal(request);
}
}, e -> {
// No need to do anything
}
));
if (request.getJobUpdate().getGroups() != null && request.getJobUpdate().getGroups().isEmpty() == false) {

// check the new groups are not job Ids
jobConfigProvider.jobIdMatches(request.getJobUpdate().getGroups(), ActionListener.wrap(
matchingIds -> {
if (matchingIds.isEmpty()) {
doUpdate.run();
} else {
actionListener.onFailure(new ResourceAlreadyExistsException(
Messages.getMessage(Messages.JOB_AND_GROUP_NAMES_MUST_BE_UNIQUE, matchingIds.get(0))));
}
actionListener.onResponse(new PutJobAction.Response(updatedJob));
},
actionListener::onFailure
);
));
} else {
postUpdateAction = ActionListener.wrap(job -> {
logger.debug("[{}] No process update required for job update: {}", () -> request.getJobId(), () -> {
try {
XContentBuilder jsonBuilder = XContentFactory.jsonBuilder();
request.getJobUpdate().toXContent(jsonBuilder, ToXContent.EMPTY_PARAMS);
return Strings.toString(jsonBuilder);
} catch (IOException e) {
return "(unprintable due to " + e.getMessage() + ")";
doUpdate.run();
}
}

private void postJobUpdate(UpdateJobAction.Request request, Job updatedJob, ActionListener<PutJobAction.Response> actionListener) {
// Autodetect must be updated if the fields that the C++ uses are changed
if (request.getJobUpdate().isAutodetectProcessUpdate()) {
JobUpdate jobUpdate = request.getJobUpdate();
if (isJobOpen(clusterService.state(), request.getJobId())) {
updateJobProcessNotifier.submitJobUpdate(UpdateParams.fromJobUpdate(jobUpdate), ActionListener.wrap(
isUpdated -> {
if (isUpdated) {
auditJobUpdatedIfNotInternal(request);
}
});
}, e -> {
// No need to do anything
}
));
}
} else {
logger.debug("[{}] No process update required for job update: {}", () -> request.getJobId(), () -> {
try {
XContentBuilder jsonBuilder = XContentFactory.jsonBuilder();
request.getJobUpdate().toXContent(jsonBuilder, ToXContent.EMPTY_PARAMS);
return Strings.toString(jsonBuilder);
} catch (IOException e) {
return "(unprintable due to " + e.getMessage() + ")";
}
});

auditJobUpdatedIfNotInternal(request);
actionListener.onResponse(new PutJobAction.Response(job));
},
actionListener::onFailure);
auditJobUpdatedIfNotInternal(request);
}


jobConfigProvider.updateJobWithValidation(request.getJobId(), request.getJobUpdate(), maxModelMemoryLimit,
this::validate, postUpdateAction);
actionListener.onResponse(new PutJobAction.Response(updatedJob));
}

private void validate(Job job, JobUpdate jobUpdate, ActionListener<Void> handler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,28 @@
"description":"Can't update all description"
}

- do:
xpack.ml.put_job:
job_id: job-crud-update-group-name-clash
body: >
{
"analysis_config" : {
"bucket_span": "1h",
"detectors" :[{"function":"metric","field_name":"responsetime","by_field_name":"airline"}]
},
"data_description" : {
}
}

- do:
catch: "/job and group names must be unique/"
xpack.ml.update_job:
job_id: jobs-crud-update-job
body: >
{
"groups": ["job-crud-update-group-name-clash"]
}

---
"Test cannot decrease model_memory_limit below current usage":
- skip:
Expand Down