@@ -373,33 +373,33 @@ public Set<String> getUpdateFields() {
373
373
*/
374
374
public Job mergeWithJob (Job source , ByteSizeValue maxModelMemoryLimit ) {
375
375
Job .Builder builder = new Job .Builder (source );
376
+ AnalysisConfig currentAnalysisConfig = source .getAnalysisConfig ();
377
+ AnalysisConfig .Builder newAnalysisConfig = new AnalysisConfig .Builder (currentAnalysisConfig );
378
+
376
379
if (groups != null ) {
377
380
builder .setGroups (groups );
378
381
}
379
382
if (description != null ) {
380
383
builder .setDescription (description );
381
384
}
382
385
if (detectorUpdates != null && detectorUpdates .isEmpty () == false ) {
383
- AnalysisConfig ac = source .getAnalysisConfig ();
384
- int numDetectors = ac .getDetectors ().size ();
386
+ int numDetectors = currentAnalysisConfig .getDetectors ().size ();
385
387
for (DetectorUpdate dd : detectorUpdates ) {
386
388
if (dd .getDetectorIndex () >= numDetectors ) {
387
389
throw ExceptionsHelper .badRequestException ("Supplied detector_index [{}] is >= the number of detectors [{}]" ,
388
390
dd .getDetectorIndex (), numDetectors );
389
391
}
390
392
391
- Detector .Builder detectorbuilder = new Detector .Builder (ac .getDetectors ().get (dd .getDetectorIndex ()));
393
+ Detector .Builder detectorBuilder = new Detector .Builder (currentAnalysisConfig .getDetectors ().get (dd .getDetectorIndex ()));
392
394
if (dd .getDescription () != null ) {
393
- detectorbuilder .setDetectorDescription (dd .getDescription ());
395
+ detectorBuilder .setDetectorDescription (dd .getDescription ());
394
396
}
395
397
if (dd .getRules () != null ) {
396
- detectorbuilder .setRules (dd .getRules ());
398
+ detectorBuilder .setRules (dd .getRules ());
397
399
}
398
- ac .getDetectors ().set (dd .getDetectorIndex (), detectorbuilder .build ());
399
- }
400
400
401
- AnalysisConfig . Builder acBuilder = new AnalysisConfig . Builder ( ac );
402
- builder . setAnalysisConfig ( acBuilder );
401
+ newAnalysisConfig . setDetector ( dd . getDetectorIndex (), detectorBuilder . build () );
402
+ }
403
403
}
404
404
if (modelPlotConfig != null ) {
405
405
builder .setModelPlotConfig (modelPlotConfig );
@@ -422,9 +422,7 @@ public Job mergeWithJob(Job source, ByteSizeValue maxModelMemoryLimit) {
422
422
builder .setResultsRetentionDays (resultsRetentionDays );
423
423
}
424
424
if (categorizationFilters != null ) {
425
- AnalysisConfig .Builder analysisConfigBuilder = new AnalysisConfig .Builder (source .getAnalysisConfig ());
426
- analysisConfigBuilder .setCategorizationFilters (categorizationFilters );
427
- builder .setAnalysisConfig (analysisConfigBuilder );
425
+ newAnalysisConfig .setCategorizationFilters (categorizationFilters );
428
426
}
429
427
if (customSettings != null ) {
430
428
builder .setCustomSettings (customSettings );
@@ -446,9 +444,48 @@ public Job mergeWithJob(Job source, ByteSizeValue maxModelMemoryLimit) {
446
444
if (jobVersion != null ) {
447
445
builder .setJobVersion (jobVersion );
448
446
}
447
+
448
+ builder .setAnalysisConfig (newAnalysisConfig );
449
449
return builder .build ();
450
450
}
451
451
452
+ boolean isNoop (Job job ) {
453
+ return (groups == null || Objects .equals (groups , job .getGroups ()))
454
+ && (description == null || Objects .equals (description , job .getDescription ()))
455
+ && (modelPlotConfig == null || Objects .equals (modelPlotConfig , job .getModelPlotConfig ()))
456
+ && (analysisLimits == null || Objects .equals (analysisLimits , job .getAnalysisLimits ()))
457
+ && updatesDetectors (job ) == false
458
+ && (renormalizationWindowDays == null || Objects .equals (renormalizationWindowDays , job .getRenormalizationWindowDays ()))
459
+ && (backgroundPersistInterval == null || Objects .equals (backgroundPersistInterval , job .getBackgroundPersistInterval ()))
460
+ && (modelSnapshotRetentionDays == null || Objects .equals (modelSnapshotRetentionDays , job .getModelSnapshotRetentionDays ()))
461
+ && (resultsRetentionDays == null || Objects .equals (resultsRetentionDays , job .getResultsRetentionDays ()))
462
+ && (categorizationFilters == null
463
+ || Objects .equals (categorizationFilters , job .getAnalysisConfig ().getCategorizationFilters ()))
464
+ && (customSettings == null || Objects .equals (customSettings , job .getCustomSettings ()))
465
+ && (modelSnapshotId == null || Objects .equals (modelSnapshotId , job .getModelSnapshotId ()))
466
+ && (modelSnapshotMinVersion == null || Objects .equals (modelSnapshotMinVersion , job .getModelSnapshotMinVersion ()))
467
+ && (establishedModelMemory == null || Objects .equals (establishedModelMemory , job .getEstablishedModelMemory ()))
468
+ && (jobVersion == null || Objects .equals (jobVersion , job .getJobVersion ()));
469
+ }
470
+
471
+ boolean updatesDetectors (Job job ) {
472
+ AnalysisConfig analysisConfig = job .getAnalysisConfig ();
473
+ if (detectorUpdates == null ) {
474
+ return false ;
475
+ }
476
+ for (DetectorUpdate detectorUpdate : detectorUpdates ) {
477
+ if (detectorUpdate .description == null && detectorUpdate .rules == null ) {
478
+ continue ;
479
+ }
480
+ Detector detector = analysisConfig .getDetectors ().get (detectorUpdate .detectorIndex );
481
+ if (Objects .equals (detectorUpdate .description , detector .getDetectorDescription ()) == false
482
+ || Objects .equals (detectorUpdate .rules , detector .getRules ()) == false ) {
483
+ return true ;
484
+ }
485
+ }
486
+ return false ;
487
+ }
488
+
452
489
@ Override
453
490
public boolean equals (Object other ) {
454
491
if (this == other ) {
0 commit comments