|
8 | 8 |
|
9 | 9 | import org.apache.logging.log4j.LogManager;
|
10 | 10 | import org.apache.logging.log4j.Logger;
|
| 11 | +import org.apache.logging.log4j.message.ParameterizedMessage; |
11 | 12 | import org.elasticsearch.ResourceAlreadyExistsException;
|
12 | 13 | import org.elasticsearch.ResourceNotFoundException;
|
13 | 14 | import org.elasticsearch.Version;
|
|
31 | 32 | import org.elasticsearch.persistent.PersistentTasksCustomMetadata;
|
32 | 33 | import org.elasticsearch.threadpool.ThreadPool;
|
33 | 34 | import org.elasticsearch.xcontent.NamedXContentRegistry;
|
34 |
| -import org.elasticsearch.xcontent.ToXContent; |
35 |
| -import org.elasticsearch.xcontent.XContentBuilder; |
36 |
| -import org.elasticsearch.xcontent.XContentFactory; |
37 | 35 | import org.elasticsearch.xpack.core.action.util.QueryPage;
|
38 | 36 | import org.elasticsearch.xpack.core.ml.MachineLearningField;
|
39 | 37 | import org.elasticsearch.xpack.core.ml.MlConfigIndex;
|
|
72 | 70 |
|
73 | 71 | import java.io.IOException;
|
74 | 72 | import java.util.ArrayList;
|
| 73 | +import java.util.Collection; |
75 | 74 | import java.util.Collections;
|
76 | 75 | import java.util.Comparator;
|
77 | 76 | import java.util.Date;
|
@@ -527,28 +526,28 @@ public void deleteJob(
|
527 | 526 |
|
528 | 527 | private void postJobUpdate(UpdateJobAction.Request request, Job updatedJob, ActionListener<PutJobAction.Response> actionListener) {
|
529 | 528 | // Autodetect must be updated if the fields that the C++ uses are changed
|
530 |
| - if (request.getJobUpdate().isAutodetectProcessUpdate()) { |
531 |
| - JobUpdate jobUpdate = request.getJobUpdate(); |
| 529 | + JobUpdate jobUpdate = request.getJobUpdate(); |
| 530 | + if (jobUpdate.isAutodetectProcessUpdate()) { |
532 | 531 | if (isJobOpen(clusterService.state(), request.getJobId())) {
|
533 | 532 | updateJobProcessNotifier.submitJobUpdate(UpdateParams.fromJobUpdate(jobUpdate), ActionListener.wrap(isUpdated -> {
|
534 | 533 | if (isUpdated) {
|
535 | 534 | auditJobUpdatedIfNotInternal(request);
|
| 535 | + } else { |
| 536 | + logger.error("[{}] Updating autodetect failed for job update [{}]", jobUpdate.getJobId(), jobUpdate); |
536 | 537 | }
|
537 | 538 | }, e -> {
|
538 |
| - // No need to do anything |
| 539 | + logger.error( |
| 540 | + new ParameterizedMessage( |
| 541 | + "[{}] Updating autodetect failed with an exception, job update [{}] ", |
| 542 | + jobUpdate.getJobId(), |
| 543 | + jobUpdate |
| 544 | + ), |
| 545 | + e |
| 546 | + ); |
539 | 547 | }));
|
540 | 548 | }
|
541 | 549 | } else {
|
542 |
| - logger.debug("[{}] No process update required for job update: {}", request::getJobId, () -> { |
543 |
| - try { |
544 |
| - XContentBuilder jsonBuilder = XContentFactory.jsonBuilder(); |
545 |
| - request.getJobUpdate().toXContent(jsonBuilder, ToXContent.EMPTY_PARAMS); |
546 |
| - return Strings.toString(jsonBuilder); |
547 |
| - } catch (IOException e) { |
548 |
| - return "(unprintable due to " + e.getMessage() + ")"; |
549 |
| - } |
550 |
| - }); |
551 |
| - |
| 550 | + logger.debug("[{}] No process update required for job update: {}", jobUpdate::getJobId, jobUpdate::toString); |
552 | 551 | auditJobUpdatedIfNotInternal(request);
|
553 | 552 | }
|
554 | 553 |
|
@@ -714,29 +713,38 @@ public void updateProcessOnCalendarChanged(List<String> calendarJobIds, ActionLi
|
714 | 713 | return;
|
715 | 714 | }
|
716 | 715 |
|
| 716 | + boolean appliesToAllJobs = calendarJobIds.stream().anyMatch(Metadata.ALL::equals); |
| 717 | + if (appliesToAllJobs) { |
| 718 | + submitJobEventUpdate(openJobIds, updateListener); |
| 719 | + return; |
| 720 | + } |
| 721 | + |
717 | 722 | // calendarJobIds may be a group or job
|
718 |
| - jobConfigProvider.expandGroupIds(calendarJobIds, ActionListener.wrap(expandedIds -> { |
719 |
| - threadPool.executor(MachineLearning.UTILITY_THREAD_POOL_NAME).execute(() -> { |
720 |
| - // Merge the expended group members with the request Ids. |
| 723 | + jobConfigProvider.expandGroupIds( |
| 724 | + calendarJobIds, |
| 725 | + ActionListener.wrap(expandedIds -> threadPool.executor(MachineLearning.UTILITY_THREAD_POOL_NAME).execute(() -> { |
| 726 | + // Merge the expanded group members with the request Ids. |
721 | 727 | // Ids that aren't jobs will be filtered by isJobOpen()
|
722 | 728 | expandedIds.addAll(calendarJobIds);
|
723 | 729 |
|
724 |
| - for (String jobId : expandedIds) { |
725 |
| - if (isJobOpen(clusterState, jobId)) { |
726 |
| - updateJobProcessNotifier.submitJobUpdate( |
727 |
| - UpdateParams.scheduledEventsUpdate(jobId), |
728 |
| - ActionListener.wrap(isUpdated -> { |
729 |
| - if (isUpdated) { |
730 |
| - auditor.info(jobId, Messages.getMessage(Messages.JOB_AUDIT_CALENDARS_UPDATED_ON_PROCESS)); |
731 |
| - } |
732 |
| - }, e -> logger.error("[" + jobId + "] failed submitting process update on calendar change", e)) |
733 |
| - ); |
734 |
| - } |
735 |
| - } |
| 730 | + openJobIds.retainAll(expandedIds); |
| 731 | + submitJobEventUpdate(openJobIds, updateListener); |
| 732 | + }), updateListener::onFailure) |
| 733 | + ); |
| 734 | + } |
736 | 735 |
|
737 |
| - updateListener.onResponse(Boolean.TRUE); |
738 |
| - }); |
739 |
| - }, updateListener::onFailure)); |
| 736 | + private void submitJobEventUpdate(Collection<String> jobIds, ActionListener<Boolean> updateListener) { |
| 737 | + for (String jobId : jobIds) { |
| 738 | + updateJobProcessNotifier.submitJobUpdate( |
| 739 | + UpdateParams.scheduledEventsUpdate(jobId), |
| 740 | + ActionListener.wrap( |
| 741 | + isUpdated -> { auditor.info(jobId, Messages.getMessage(Messages.JOB_AUDIT_CALENDARS_UPDATED_ON_PROCESS)); }, |
| 742 | + e -> logger.error("[" + jobId + "] failed submitting process update on calendar change", e) |
| 743 | + ) |
| 744 | + ); |
| 745 | + } |
| 746 | + |
| 747 | + updateListener.onResponse(Boolean.TRUE); |
740 | 748 | }
|
741 | 749 |
|
742 | 750 | public void revertSnapshot(
|
|
0 commit comments