/
Clockwork.java
1616 lines (1456 loc) · 73.7 KB
/
Clockwork.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2010-2019 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.model.impl.lens;
import static com.evolveum.midpoint.model.api.ProgressInformation.ActivityType.CLOCKWORK;
import static com.evolveum.midpoint.model.api.ProgressInformation.ActivityType.WAITING;
import static com.evolveum.midpoint.model.api.ProgressInformation.StateType.ENTERING;
import static com.evolveum.midpoint.model.api.ProgressInformation.StateType.EXITING;
import static com.evolveum.midpoint.model.impl.lens.LensUtil.getExportType;
import static com.evolveum.midpoint.model.impl.lens.LensUtil.getExportTypeTraceOrReduced;
import static java.util.Collections.emptyList;
import static org.apache.commons.collections4.CollectionUtils.emptyIfNull;
import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;
import com.evolveum.midpoint.model.impl.util.AuditHelper;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.schema.cache.CacheConfigurationManager;
import com.evolveum.midpoint.schema.cache.CacheType;
import com.evolveum.midpoint.schema.result.OperationResultBuilder;
import com.evolveum.midpoint.task.api.*;
import com.evolveum.midpoint.util.logging.*;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.Validate;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import com.evolveum.midpoint.audit.api.AuditEventRecord;
import com.evolveum.midpoint.audit.api.AuditEventStage;
import com.evolveum.midpoint.audit.api.AuditEventType;
import com.evolveum.midpoint.common.Clock;
import com.evolveum.midpoint.model.api.ModelExecuteOptions;
import com.evolveum.midpoint.model.api.ProgressInformation;
import com.evolveum.midpoint.model.api.ProgressListener;
import com.evolveum.midpoint.model.api.context.ModelContext;
import com.evolveum.midpoint.model.api.context.ModelState;
import com.evolveum.midpoint.model.api.hooks.ChangeHook;
import com.evolveum.midpoint.model.api.hooks.HookOperationMode;
import com.evolveum.midpoint.model.api.hooks.HookRegistry;
import com.evolveum.midpoint.model.common.SystemObjectCache;
import com.evolveum.midpoint.model.common.expression.evaluator.caching.AssociationSearchExpressionEvaluatorCache;
import com.evolveum.midpoint.model.common.expression.script.ScriptExpression;
import com.evolveum.midpoint.model.common.expression.script.ScriptExpressionFactory;
import com.evolveum.midpoint.model.impl.lens.projector.ContextLoader;
import com.evolveum.midpoint.model.impl.lens.projector.Projector;
import com.evolveum.midpoint.model.impl.lens.projector.focus.FocusConstraintsChecker;
import com.evolveum.midpoint.model.impl.lens.projector.policy.PolicyRuleScriptExecutor;
import com.evolveum.midpoint.model.impl.lens.projector.policy.PolicyRuleSuspendTaskExecutor;
import com.evolveum.midpoint.model.impl.migrator.Migrator;
import com.evolveum.midpoint.model.impl.sync.RecomputeTaskHandler;
import com.evolveum.midpoint.model.impl.util.ModelImplUtils;
import com.evolveum.midpoint.prism.delta.ChangeType;
import com.evolveum.midpoint.prism.delta.ItemDelta;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.prism.util.CloneUtil;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.provisioning.api.ChangeNotificationDispatcher;
import com.evolveum.midpoint.provisioning.api.ProvisioningService;
import com.evolveum.midpoint.provisioning.api.ResourceObjectChangeListener;
import com.evolveum.midpoint.provisioning.api.ResourceOperationListener;
import com.evolveum.midpoint.repo.api.ConflictWatcher;
import com.evolveum.midpoint.repo.api.PreconditionViolationException;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.repo.common.expression.ExpressionFactory;
import com.evolveum.midpoint.repo.common.expression.ExpressionUtil;
import com.evolveum.midpoint.repo.common.expression.ExpressionVariables;
import com.evolveum.midpoint.schema.ObjectDeltaOperation;
import com.evolveum.midpoint.schema.constants.ExpressionConstants;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.internals.InternalsConfig;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.result.OperationResultStatus;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.schema.util.SystemConfigurationTypeUtil;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.Holder;
import com.evolveum.midpoint.util.exception.CommonException;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.ExpressionEvaluationException;
import com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.PolicyViolationException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SecurityViolationException;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.prism.xml.ns._public.query_3.QueryType;
import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType;
/**
* @author semancik
*
*/
@Component
public class Clockwork {
private static final int DEFAULT_NUMBER_OF_RESULTS_TO_KEEP = 5;
private static final int DEFAULT_MAX_CONFLICT_RESOLUTION_ATTEMPTS = 1; // synchronize with common-core-3.xsd
private static final int DEFAULT_CONFLICT_RESOLUTION_DELAY_UNIT = 5000; // synchronize with common-core-3.xsd
private static final int MAX_PRECONDITION_CONFLICT_RESOLUTION_ATTEMPTS = 3;
private static final Trace LOGGER = TraceManager.getTrace(Clockwork.class);
@Autowired private Projector projector;
@Autowired private ContextLoader contextLoader;
@Autowired private ChangeExecutor changeExecutor;
@Autowired private AuditHelper auditHelper;
@Autowired private Clock clock;
@Autowired private SystemObjectCache systemObjectCache;
@Autowired private transient ProvisioningService provisioningService;
@Autowired private transient ChangeNotificationDispatcher changeNotificationDispatcher;
@Autowired private ExpressionFactory expressionFactory;
@Autowired private ScriptExpressionFactory scriptExpressionFactory;
@Autowired private PersonaProcessor personaProcessor;
@Autowired private PrismContext prismContext;
@Autowired private TaskManager taskManager;
@Autowired private Tracer tracer;
@Autowired private OperationalDataManager metadataManager;
@Autowired private ContextFactory contextFactory;
@Autowired private Migrator migrator;
@Autowired private ClockworkMedic medic;
@Autowired private PolicyRuleScriptExecutor policyRuleScriptExecutor;
@Autowired private PolicyRuleSuspendTaskExecutor policyRuleSuspendTaskExecutor;
@Autowired private ClockworkAuthorizationHelper clockworkAuthorizationHelper;
@Autowired private CacheConfigurationManager cacheConfigurationManager;
@Autowired(required = false)
private HookRegistry hookRegistry;
@Autowired
@Qualifier("cacheRepositoryService")
private transient RepositoryService repositoryService;
private static final int DEFAULT_MAX_CLICKS = 200;
public <F extends ObjectType> HookOperationMode run(LensContext<F> context, Task task, OperationResult parentResult)
throws SchemaException, PolicyViolationException, ExpressionEvaluationException, ObjectNotFoundException,
ObjectAlreadyExistsException, CommunicationException, ConfigurationException, SecurityViolationException, PreconditionViolationException {
OperationResultBuilder builder = parentResult.subresult(Clockwork.class.getName() + ".run");
boolean tracingRequested = startTracingIfRequested(context, task, builder, parentResult);
OperationResult result = builder.build();
ClockworkRunTraceType trace = null;
try {
if (result.isTraced()) {
trace = recordTraceAtStart(context, task, result);
}
LOGGER.trace("Running clockwork for context {}", context);
if (InternalsConfig.consistencyChecks) {
context.checkConsistence();
}
int clicked = 0;
boolean focusConflictPresent = false;
ConflictResolutionType conflictResolutionPolicy = null;
HookOperationMode finalMode;
try {
context.reportProgress(new ProgressInformation(CLOCKWORK, ENTERING));
if (context.getFocusContext() != null && context.getFocusContext().getOid() != null) {
context.createAndRegisterFocusConflictWatcher(context.getFocusContext().getOid(), repositoryService);
}
FocusConstraintsChecker
.enterCache(cacheConfigurationManager.getConfiguration(CacheType.LOCAL_FOCUS_CONSTRAINT_CHECKER_CACHE));
enterAssociationSearchExpressionEvaluatorCache();
//enterDefaultSearchExpressionEvaluatorCache();
provisioningService.enterConstraintsCheckerCache();
while (context.getState() != ModelState.FINAL) {
// TODO implement in model context (as transient or even non-transient attribute) to allow for checking in more complex scenarios
int maxClicks = getMaxClicks(context, result);
if (clicked >= maxClicks) {
throw new IllegalStateException(
"Model operation took too many clicks (limit is " + maxClicks + "). Is there a cycle?");
}
clicked++;
HookOperationMode mode = click(context, task, result);
if (mode == HookOperationMode.BACKGROUND) {
result.recordInProgress();
return mode;
} else if (mode == HookOperationMode.ERROR) {
return mode;
}
}
// One last click in FINAL state
finalMode = click(context, task, result);
if (finalMode == HookOperationMode.FOREGROUND) {
conflictResolutionPolicy = ModelImplUtils.getConflictResolution(context);
focusConflictPresent = checkFocusConflicts(context, conflictResolutionPolicy, task, result);
}
} finally {
context.unregisterConflictWatchers(repositoryService);
FocusConstraintsChecker.exitCache();
//exitDefaultSearchExpressionEvaluatorCache();
exitAssociationSearchExpressionEvaluatorCache();
provisioningService.exitConstraintsCheckerCache();
context.reportProgress(new ProgressInformation(CLOCKWORK, EXITING));
}
// intentionally outside the "try-finally" block to start with clean caches
if (focusConflictPresent) {
assert finalMode == HookOperationMode.FOREGROUND;
finalMode = resolveFocusConflict(context, conflictResolutionPolicy, task, result);
} else if (context.getConflictResolutionAttemptNumber() > 0) {
LOGGER.info("Resolved update conflict on attempt number {}", context.getConflictResolutionAttemptNumber());
}
result.computeStatusIfUnknown();
return finalMode;
} catch (Throwable t) {
result.recordFatalError(t.getMessage(), t);
throw t;
} finally {
recordTraceAtEnd(context, trace, result);
if (tracingRequested) {
tracer.storeTrace(task, result);
TracingAppender.terminateCollecting(); // todo reconsider
LevelOverrideTurboFilter.cancelLoggingOverride(); // todo reconsider
}
result.computeStatusIfUnknown();
}
}
// todo check authorization in this method
private <F extends ObjectType> boolean startTracingIfRequested(LensContext<F> context, Task task,
OperationResultBuilder builder, OperationResult parentResult) throws SchemaException {
// If the result is already traced, we could abstain from recording the final trace ourselves.
// But I think it's more reasonable to do that, because e.g. if there is clockwork-inside-clockwork processing,
// we would like to have two traces, even if the second one is contained also within the first one.
TracingProfileType tracingProfile = ModelExecuteOptions.getTracingProfile(context.getOptions());
if (tracingProfile != null) {
builder.tracingProfile(tracer.compileProfile(tracingProfile, parentResult));
return true;
} else if (task.getTracingRequestedFor().contains(TracingRootType.CLOCKWORK_RUN)) {
TracingProfileType profile = task.getTracingProfile() != null ? task.getTracingProfile() : tracer.getDefaultProfile();
builder.tracingProfile(tracer.compileProfile(profile, parentResult));
return true;
} else {
return false;
}
}
private <F extends ObjectType> ClockworkRunTraceType recordTraceAtStart(LensContext<F> context, Task task,
OperationResult result) throws SchemaException {
ClockworkRunTraceType trace = new ClockworkRunTraceType(prismContext);
trace.setInputLensContextText(context.debugDump());
trace.setInputLensContext(context.toLensContextType(getExportTypeTraceOrReduced(trace, result)));
result.addTrace(trace);
return trace;
}
private <F extends ObjectType> void recordTraceAtEnd(LensContext<F> context, ClockworkRunTraceType trace,
OperationResult result) throws SchemaException {
if (trace != null) {
trace.setOutputLensContextText(context.debugDump());
trace.setOutputLensContext(context.toLensContextType(getExportTypeTraceOrReduced(trace, result)));
if (context.getFocusContext() != null) { // todo reconsider this
PrismObject<F> objectAny = context.getFocusContext().getObjectAny();
if (objectAny != null) {
trace.setFocusName(PolyString.getOrig(objectAny.getName()));
}
}
}
}
public <F extends ObjectType> LensContext<F> previewChanges(LensContext<F> context, Collection<ProgressListener> listeners, Task task, OperationResult result)
throws SchemaException, PolicyViolationException, ExpressionEvaluationException, ObjectNotFoundException, ObjectAlreadyExistsException, CommunicationException, ConfigurationException, SecurityViolationException {
try {
context.setPreview(true);
// context.setOptions(options);
LOGGER.trace("Preview changes context:\n{}", context.debugDumpLazily());
context.setProgressListeners(listeners);
projector.projectAllWaves(context, "preview", task, result);
context.distributeResource();
if (hookRegistry != null) {
for (ChangeHook hook : hookRegistry.getAllChangeHooks()) {
hook.invokePreview(context, task, result);
}
}
policyRuleSuspendTaskExecutor.execute(context, task, result);
} catch (ConfigurationException | SecurityViolationException | ObjectNotFoundException | SchemaException |
CommunicationException | PolicyViolationException | RuntimeException | ObjectAlreadyExistsException |
ExpressionEvaluationException e) {
ModelImplUtils.recordFatalError(result, e);
throw e;
} catch (PreconditionViolationException e) {
ModelImplUtils.recordFatalError(result, e);
// TODO: Temporary fix for 3.6.1
// We do not want to propagate PreconditionViolationException to model API as that might break compatibility
// ... and we do not really need that in 3.6.1
// TODO: expose PreconditionViolationException in 3.7
throw new SystemException(e);
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Preview changes output:\n{}", context.debugDump());
}
result.computeStatus();
result.cleanupResult();
return context;
}
private <F extends ObjectType> boolean checkFocusConflicts(LensContext<F> context, ConflictResolutionType resolutionPolicy,
Task task, OperationResult result) {
ConflictWatcher watcher = context.getFocusConflictWatcher();
if (watcher != null && resolutionPolicy != null && resolutionPolicy.getAction() != ConflictResolutionActionType.NONE &&
repositoryService.hasConflict(watcher, result)) {
LOGGER.debug("Found modify-modify conflict on {}", watcher);
return true;
} else {
return false;
}
}
private <F extends ObjectType> HookOperationMode resolveFocusConflict(LensContext<F> context,
ConflictResolutionType resolutionPolicy, Task task, OperationResult result)
throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, ConfigurationException,
CommunicationException, SecurityViolationException, PolicyViolationException, ObjectAlreadyExistsException {
if (resolutionPolicy == null || resolutionPolicy.getAction() == ConflictResolutionActionType.NONE) {
return HookOperationMode.FOREGROUND;
}
PrismObject<F> focusObject = context.getFocusContext() != null ? context.getFocusContext().getObjectAny() : null;
ModelExecuteOptions options = new ModelExecuteOptions();
switch (resolutionPolicy.getAction()) {
case FAIL: throw new SystemException("Conflict detected while updating " + focusObject);
case LOG:
LOGGER.warn("Conflict detected while updating {}", focusObject);
return HookOperationMode.FOREGROUND;
case RECOMPUTE:
break;
case RECONCILE:
options.setReconcile();
break;
default:
throw new IllegalStateException("Unsupported conflict resolution action: " + resolutionPolicy.getAction());
}
// so, recompute is the action
LOGGER.debug("CONFLICT: Conflict detected while updating {}, recomputing (options={})", focusObject, options);
if (context.getFocusContext() == null) {
LOGGER.warn("No focus context, not possible to resolve conflict by focus recomputation"); // should really never occur
return HookOperationMode.FOREGROUND;
}
String oid = context.getFocusContext().getOid();
if (oid == null) {
LOGGER.warn("No focus OID, not possible to resolve conflict by focus recomputation"); // should really never occur
return HookOperationMode.FOREGROUND;
}
Class<F> focusClass = context.getFocusContext().getObjectTypeClass();
if (focusClass == null) {
LOGGER.warn("Focus class not known, not possible to resolve conflict by focus recomputation"); // should really never occur
return HookOperationMode.FOREGROUND;
}
if (TaskType.class.isAssignableFrom(focusClass)) {
return HookOperationMode.FOREGROUND; // this is actually quite expected, so don't bother anyone with that
}
if (!FocusType.class.isAssignableFrom(focusClass)) {
LOGGER.warn("Focus is not of FocusType (it is {}); not possible to resolve conflict by focus recomputation", focusClass.getName());
return HookOperationMode.FOREGROUND;
}
ConflictResolutionType focusConflictResolution = new ConflictResolutionType();
focusConflictResolution.setAction(ConflictResolutionActionType.ERROR);
options.setFocusConflictResolution(focusConflictResolution);
int preconditionAttempts = 0;
while (true) {
int attemptOld = context.getConflictResolutionAttemptNumber();
int attemptNew = attemptOld + 1;
boolean shouldExecuteAttempt = shouldExecuteAttempt(context, resolutionPolicy, attemptNew);
if (!shouldExecuteAttempt) {
LOGGER.warn("CONFLICT: Couldn't resolve conflict even after {} resolution attempt(s), giving up.", attemptOld);
return HookOperationMode.FOREGROUND;
}
delay(context, resolutionPolicy, attemptNew + preconditionAttempts);
PrismObject<F> focus = repositoryService.getObject(focusClass, oid, null, result);
LensContext<FocusType> contextNew = contextFactory.createRecomputeContext(focus, options, task, result);
contextNew.setProgressListeners(new ArrayList<>(emptyIfNull(context.getProgressListeners())));
contextNew.setConflictResolutionAttemptNumber(attemptNew);
LOGGER.debug("CONFLICT: Recomputing {} as reaction to conflict (options={}, attempts={},{}, readVersion={})",
context.getFocusContext().getHumanReadableName(), options, attemptNew, preconditionAttempts, contextNew.getFocusContext().getObjectReadVersion());
try {
// this is a recursion; but limited to max attempts which should not be a large number
HookOperationMode hookOperationMode = run(contextNew, task, result);
// This may be in fact a giveup after recompute that was not able to cleanly proceed.
LOGGER.debug("CONFLICT: Clean recompute (or giveup) of {} achieved (options={}, attempts={},{})",
context.getFocusContext().getHumanReadableName(), options, attemptNew, preconditionAttempts);
return hookOperationMode;
} catch (PreconditionViolationException e) {
preconditionAttempts++;
LOGGER.debug("CONFLICT: Recompute precondition failed (attempt {}, precondition attempt {}), trying again", attemptNew, preconditionAttempts);
if (preconditionAttempts < MAX_PRECONDITION_CONFLICT_RESOLUTION_ATTEMPTS) {
continue;
}
LOGGER.warn("CONFLICT: Couldn't resolve conflict even after {} resolution attempt(s) and {} precondition attempts, giving up.",
attemptOld, preconditionAttempts);
return HookOperationMode.FOREGROUND;
}
}
}
private <F extends ObjectType> boolean shouldExecuteAttempt(LensContext<F> context, @NotNull ConflictResolutionType resolutionPolicy, int attemptNew) {
int maxAttempts = defaultIfNull(resolutionPolicy.getMaxAttempts(), DEFAULT_MAX_CONFLICT_RESOLUTION_ATTEMPTS);
if (attemptNew > maxAttempts) {
return false;
}
return true;
}
private <F extends ObjectType> void delay(LensContext<F> context, @NotNull ConflictResolutionType resolutionPolicy, int attempts) {
long delayUnit = defaultIfNull(resolutionPolicy.getDelayUnit(), DEFAULT_CONFLICT_RESOLUTION_DELAY_UNIT);
for (int i = 0; i < attempts; i++) {
delayUnit *= 2;
}
long delay = (long) (Math.random() * delayUnit);
String message = "CONFLICT: Waiting "+delay+" milliseconds before starting conflict resolution (delay exponent: "+attempts+")";
// TODO convey information about waiting time after some GUI mechanism for displaying it is available
// (showing text messages is currently really ugly)
context.reportProgress(new ProgressInformation(WAITING, EXITING));
LOGGER.debug(message);
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
// ignore
}
context.reportProgress(new ProgressInformation(WAITING, EXITING));
}
private void enterAssociationSearchExpressionEvaluatorCache() {
AssociationSearchExpressionEvaluatorCache cache = AssociationSearchExpressionEvaluatorCache.enterCache(
cacheConfigurationManager.getConfiguration(CacheType.LOCAL_ASSOCIATION_TARGET_SEARCH_EVALUATOR_CACHE));
if (cache.getClientContextInformation() == null) {
AssociationSearchExpressionCacheInvalidator invalidator = new AssociationSearchExpressionCacheInvalidator(cache);
cache.setClientContextInformation(invalidator);
changeNotificationDispatcher.registerNotificationListener((ResourceObjectChangeListener) invalidator);
changeNotificationDispatcher.registerNotificationListener((ResourceOperationListener) invalidator);
}
}
private void exitAssociationSearchExpressionEvaluatorCache() {
AssociationSearchExpressionEvaluatorCache cache = AssociationSearchExpressionEvaluatorCache.exitCache();
if (cache == null) {
LOGGER.error("exitAssociationSearchExpressionEvaluatorCache: cache instance was not found for the current thread");
return;
}
if (cache.getEntryCount() <= 0) {
Object invalidator = cache.getClientContextInformation();
if (!(invalidator instanceof AssociationSearchExpressionCacheInvalidator)) {
LOGGER.error("exitAssociationSearchExpressionEvaluatorCache: expected {}, got {} instead",
AssociationSearchExpressionCacheInvalidator.class, invalidator);
return;
}
changeNotificationDispatcher.unregisterNotificationListener((ResourceObjectChangeListener) invalidator);
changeNotificationDispatcher.unregisterNotificationListener((ResourceOperationListener) invalidator);
}
}
private void enterDefaultSearchExpressionEvaluatorCache() {
//DefaultSearchExpressionEvaluatorCache.enterCache(cacheConfigurationManager.getConfiguration(CacheType.LOCAL_DEFAULT_SEARCH_EVALUATOR_CACHE));
}
private void exitDefaultSearchExpressionEvaluatorCache() {
//DefaultSearchExpressionEvaluatorCache.exitCache();
}
private <F extends ObjectType> int getMaxClicks(LensContext<F> context, OperationResult result) throws SchemaException, ObjectNotFoundException {
PrismObject<SystemConfigurationType> systemConfiguration = systemObjectCache.getSystemConfiguration(result);
Integer maxClicks = SystemConfigurationTypeUtil.getMaxModelClicks(systemConfiguration);
if (maxClicks == null) {
return DEFAULT_MAX_CLICKS;
} else {
return maxClicks;
}
}
public <F extends ObjectType> HookOperationMode click(LensContext<F> context, Task task, OperationResult parentResult)
throws SchemaException, PolicyViolationException, ExpressionEvaluationException, ObjectNotFoundException,
ObjectAlreadyExistsException, CommunicationException, ConfigurationException, SecurityViolationException, PreconditionViolationException {
// DO NOT CHECK CONSISTENCY of the context here. The context may not be fresh and consistent yet. Project will fix
// that. Check consistency afterwards (and it is also checked inside projector several times).
if (context.getInspector() == null) {
context.setInspector(medic.getClockworkInspector());
}
OperationResult result = parentResult.subresult(Clockwork.class.getName() + ".click")
.addQualifier(context.getOperationQualifier())
.addArbitraryObjectAsContext("context", context)
.addArbitraryObjectAsContext("task", task)
.build();
ClockworkClickTraceType trace;
if (result.isTraced()) {
trace = new ClockworkClickTraceType(prismContext);
if (result.isTracingNormal(ClockworkClickTraceType.class)) {
trace.setInputLensContextText(context.debugDump());
}
trace.setInputLensContext(context.toLensContextType(getExportType(trace, result)));
result.getTraces().add(trace);
} else {
trace = null;
}
try {
XMLGregorianCalendar now = clock.currentTimeXMLGregorianCalendar();
// We need to determine focus before auditing. Otherwise we will not know user
// for the accounts (unless there is a specific delta for it).
// This is ugly, but it is the easiest way now (TODO: cleanup).
contextLoader.determineFocusContext(context, task, result);
ModelState state = context.getState();
if (state == ModelState.INITIAL) {
medic.clockworkStart(context);
metadataManager.setRequestMetadataInContext(context, now, task);
context.getStats().setRequestTimestamp(now);
context.generateRequestIdentifierIfNeeded();
// We need to do this BEFORE projection. If we would do that after projection
// there will be secondary changes that are not part of the request.
audit(context, AuditEventStage.REQUEST, task, result, parentResult); // we need to take the overall ("run" operation result) not the current one
}
boolean recompute = false;
if (!context.isFresh()) {
LOGGER.trace("Context is not fresh -- forcing cleanup and recomputation");
recompute = true;
} else if (context.getExecutionWave() > context.getProjectionWave()) { // should not occur
LOGGER.warn("Execution wave is greater than projection wave -- forcing cleanup and recomputation");
recompute = true;
} else if (state == ModelState.PRIMARY && ModelExecuteOptions.getInitialPartialProcessing(context.getOptions()) != null) {
LOGGER.trace("Initial phase was run with initialPartialProcessing option -- forcing cleanup and recomputation");
recompute = true;
}
if (recompute) {
context.cleanup();
LOGGER.trace("Running projector with cleaned-up context for execution wave {}", context.getExecutionWave());
projector.project(context, "PROJECTOR ("+state+")", task, result);
} else if (context.getExecutionWave() == context.getProjectionWave()) {
LOGGER.trace("Resuming projector for execution wave {}", context.getExecutionWave());
projector.resume(context, "PROJECTOR ("+state+")", task, result);
} else {
LOGGER.trace("Skipping projection because the context is fresh and projection for current wave has already run");
}
if (!context.isRequestAuthorized()) {
clockworkAuthorizationHelper.authorizeContextRequest(context, task, result);
}
medic.traceContext(LOGGER, "CLOCKWORK (" + state + ")", "before processing", true, context, false);
if (InternalsConfig.consistencyChecks) {
try {
context.checkConsistence();
} catch (IllegalStateException e) {
throw new IllegalStateException(e.getMessage()+" in clockwork, state="+state, e);
}
}
if (InternalsConfig.encryptionChecks && !ModelExecuteOptions.isNoCrypt(context.getOptions())) {
context.checkEncrypted();
}
// LOGGER.info("CLOCKWORK: {}: {}", state, context);
switch (state) {
case INITIAL:
processInitialToPrimary(context, task, result);
break;
case PRIMARY:
processPrimaryToSecondary(context, task, result);
break;
case SECONDARY:
processSecondary(context, task, result, parentResult);
break;
case FINAL:
HookOperationMode mode = processFinal(context, task, result, parentResult);
medic.clockworkFinish(context);
return mode;
}
return invokeHooks(context, task, result);
} catch (CommunicationException | ConfigurationException | ExpressionEvaluationException | ObjectNotFoundException |
PolicyViolationException | SchemaException | SecurityViolationException | RuntimeException | Error |
ObjectAlreadyExistsException | PreconditionViolationException e) {
processClockworkException(context, e, task, result, parentResult);
throw e;
} finally {
if (trace != null) {
if (result.isTracingNormal(ClockworkClickTraceType.class)) {
trace.setOutputLensContextText(context.debugDump());
}
trace.setOutputLensContext(context.toLensContextType(getExportType(trace, result)));
}
result.computeStatusIfUnknown();
result.cleanupResultDeeply();
}
}
/**
* Invokes hooks, if there are any.
*
* @return
* - ERROR, if any hook reported error; otherwise returns
* - BACKGROUND, if any hook reported switching to background; otherwise
* - FOREGROUND (if all hooks reported finishing on foreground)
*/
private HookOperationMode invokeHooks(LensContext context, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, PolicyViolationException, CommunicationException, ConfigurationException, SecurityViolationException {
// TODO: following two parts should be merged together in later versions
// Execute configured scripting hooks
PrismObject<SystemConfigurationType> systemConfiguration = systemObjectCache.getSystemConfiguration(result);
// systemConfiguration may be null in some tests
if (systemConfiguration != null) {
ModelHooksType modelHooks = systemConfiguration.asObjectable().getModelHooks();
if (modelHooks != null) {
HookListType changeHooks = modelHooks.getChange();
if (changeHooks != null) {
for (HookType hookType: changeHooks.getHook()) {
String shortDesc;
if (hookType.getName() != null) {
shortDesc = "hook '"+hookType.getName()+"'";
} else {
shortDesc = "scripting hook in system configuration";
}
if (hookType.isEnabled() != null && !hookType.isEnabled()) {
// Disabled hook, skip
continue;
}
if (hookType.getState() != null) {
if (!context.getState().toModelStateType().equals(hookType.getState())) {
continue;
}
}
if (hookType.getFocusType() != null) {
if (context.getFocusContext() == null) {
continue;
}
QName hookFocusTypeQname = hookType.getFocusType();
ObjectTypes hookFocusType = ObjectTypes.getObjectTypeFromTypeQName(hookFocusTypeQname);
if (hookFocusType == null) {
throw new SchemaException("Unknown focus type QName "+hookFocusTypeQname+" in "+shortDesc);
}
Class focusClass = context.getFocusClass();
Class<? extends ObjectType> hookFocusClass = hookFocusType.getClassDefinition();
if (!hookFocusClass.isAssignableFrom(focusClass)) {
continue;
}
}
ScriptExpressionEvaluatorType scriptExpressionEvaluatorType = hookType.getScript();
if (scriptExpressionEvaluatorType == null) {
continue;
}
try {
evaluateScriptingHook(context, hookType, scriptExpressionEvaluatorType, shortDesc, task, result);
} catch (ExpressionEvaluationException e) {
LOGGER.error("Evaluation of {} failed: {}", shortDesc, e.getMessage(), e);
throw new ExpressionEvaluationException("Evaluation of "+shortDesc+" failed: "+e.getMessage(), e);
} catch (ObjectNotFoundException e) {
LOGGER.error("Evaluation of {} failed: {}", shortDesc, e.getMessage(), e);
throw new ObjectNotFoundException("Evaluation of "+shortDesc+" failed: "+e.getMessage(), e);
} catch (SchemaException e) {
LOGGER.error("Evaluation of {} failed: {}", shortDesc, e.getMessage(), e);
throw new SchemaException("Evaluation of "+shortDesc+" failed: "+e.getMessage(), e);
} catch (CommunicationException e) {
LOGGER.error("Evaluation of {} failed: {}", shortDesc, e.getMessage(), e);
throw new CommunicationException("Evaluation of "+shortDesc+" failed: "+e.getMessage(), e);
} catch (ConfigurationException e) {
LOGGER.error("Evaluation of {} failed: {}", shortDesc, e.getMessage(), e);
throw new ConfigurationException("Evaluation of "+shortDesc+" failed: "+e.getMessage(), e);
} catch (SecurityViolationException e) {
LOGGER.error("Evaluation of {} failed: {}", shortDesc, e.getMessage(), e);
throw new SecurityViolationException("Evaluation of "+shortDesc+" failed: "+e.getMessage(), e);
}
}
}
}
}
// Execute registered Java hooks
HookOperationMode resultMode = HookOperationMode.FOREGROUND;
if (hookRegistry != null) {
for (ChangeHook hook : hookRegistry.getAllChangeHooks()) {
HookOperationMode mode = hook.invoke(context, task, result);
if (mode == HookOperationMode.ERROR) {
resultMode = HookOperationMode.ERROR;
} else if (mode == HookOperationMode.BACKGROUND) {
if (resultMode != HookOperationMode.ERROR) {
resultMode = HookOperationMode.BACKGROUND;
}
}
}
}
return resultMode;
}
private void evaluateScriptingHook(LensContext context, HookType hookType,
ScriptExpressionEvaluatorType scriptExpressionEvaluatorType, String shortDesc, Task task, OperationResult result)
throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException {
LOGGER.trace("Evaluating {}", shortDesc);
// TODO: it would be nice to cache this
// null output definition: this script has no output
ScriptExpression scriptExpression = scriptExpressionFactory.createScriptExpression(scriptExpressionEvaluatorType, null, context.getPrivilegedExpressionProfile(), expressionFactory, shortDesc, task, result);
ExpressionVariables variables = new ExpressionVariables();
variables.put(ExpressionConstants.VAR_PRISM_CONTEXT, prismContext, PrismContext.class);
variables.put(ExpressionConstants.VAR_MODEL_CONTEXT, context, ModelContext.class);
LensFocusContext focusContext = context.getFocusContext();
PrismObject focus = null;
if (focusContext != null) {
variables.put(ExpressionConstants.VAR_FOCUS, focusContext.getObjectAny(), focusContext.getObjectDefinition());
} else {
PrismObjectDefinition<ObjectType> def = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ObjectType.class);
variables.put(ExpressionConstants.VAR_FOCUS, null, def);
}
ModelImplUtils.evaluateScript(scriptExpression, context, variables, false, shortDesc, task, result);
LOGGER.trace("Finished evaluation of {}", shortDesc);
}
private <F extends ObjectType> void switchState(LensContext<F> context, ModelState newState) {
medic.clockworkStateSwitch(context, newState);
context.setState(newState);
}
private <F extends ObjectType> void processInitialToPrimary(LensContext<F> context, Task task, OperationResult result) {
// Context loaded, nothing special do. Bump state to PRIMARY.
switchState(context, ModelState.PRIMARY);
}
private <F extends ObjectType> void processPrimaryToSecondary(LensContext<F> context, Task task, OperationResult result) throws PolicyViolationException, ObjectNotFoundException, SchemaException {
// Nothing to do now. The context is already recomputed.
switchState(context, ModelState.SECONDARY);
policyRuleSuspendTaskExecutor.execute(context, task, result);
}
private <F extends ObjectType> void processSecondary(LensContext<F> context, Task task, OperationResult result, OperationResult overallResult)
throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException,
SecurityViolationException, ExpressionEvaluationException, PolicyViolationException, PreconditionViolationException {
if (context.getExecutionWave() > context.getMaxWave() + 1) {
processSecondaryToFinal(context, task, result);
return;
}
Holder<Boolean> restartRequestedHolder = new Holder<>();
medic.partialExecute("execution",
(result1) -> {
boolean restartRequested = changeExecutor.executeChanges(context, task, result1);
restartRequestedHolder.setValue(restartRequested);
},
context.getPartialProcessingOptions()::getExecution,
Clockwork.class, context, result);
audit(context, AuditEventStage.EXECUTION, task, result, overallResult);
rotContextIfNeeded(context);
boolean restartRequested = false;
if (restartRequestedHolder.getValue() != null) {
restartRequested = restartRequestedHolder.getValue();
}
if (!restartRequested) {
// TODO what if restart is requested indefinitely?
context.incrementExecutionWave();
} else {
// explicitly rot context?
}
medic.traceContext(LOGGER, "CLOCKWORK (" + context.getState() + ")", "change execution", false, context, false);
}
private <F extends ObjectType> void processSecondaryToFinal(LensContext<F> context, Task task, OperationResult result) throws PolicyViolationException {
switchState(context, ModelState.FINAL);
policyRuleScriptExecutor.execute(context, task, result);
}
/**
* Force recompute for the next execution wave. Recompute only those contexts that were changed.
* This is more intelligent than context.rot()
*/
private <F extends ObjectType> void rotContextIfNeeded(LensContext<F> context) throws SchemaException {
boolean rot = false;
for (LensProjectionContext projectionContext: context.getProjectionContexts()) {
if (projectionContext.getWave() != context.getExecutionWave()) {
LOGGER.trace("Context rot: projection {} NOT rotten because of wrong wave number", projectionContext);
continue;
}
// if (!projectionContext.isDoReconciliation()) { // meaning volatility is NONE
// LOGGER.trace("Context rot: projection {} NOT rotten because the resource is non-volatile", projectionContext);
// continue;
// }
ObjectDelta<ShadowType> execDelta = projectionContext.getExecutableDelta();
if (isShadowDeltaSignificant(execDelta)) {
LOGGER.debug("Context rot: projection {} rotten because of executable delta {}", projectionContext, execDelta);
projectionContext.setFresh(false);
projectionContext.setFullShadow(false);
rot = true;
// Propagate to higher-order projections
for (LensProjectionContext relCtx: LensUtil.findRelatedContexts(context, projectionContext)) {
relCtx.setFresh(false);
relCtx.setFullShadow(false);
}
} else {
LOGGER.trace("Context rot: projection {} NOT rotten because no delta", projectionContext);
}
}
LensFocusContext<F> focusContext = context.getFocusContext();
if (focusContext != null) {
ObjectDelta<F> execDelta = focusContext.getWaveDelta(context.getExecutionWave());
if (execDelta != null && !execDelta.isEmpty()) {
LOGGER.debug("Context rot: context rotten because of focus execution delta {}", execDelta);
rot = true;
}
if (rot) {
// It is OK to refresh focus all the time there was any change. This is cheap.
focusContext.setFresh(false);
}
//remove secondary deltas from other than execution wave - we need to recompute them..
// cleanUpSecondaryDeltas(context);
}
if (rot) {
context.setFresh(false);
}
}
// // TODO this is quite unclear. Originally here was keeping the delta from the current wave (plus delta from wave #1).
// // The reason was not clear.
// // Let us erase everything.
// private <F extends ObjectType> void cleanUpSecondaryDeltas(LensContext<F> context){
// LensFocusContext focusContext = context.getFocusContext();
// ObjectDeltaWaves<F> executionWaveDeltaList = focusContext.getSecondaryDeltas();
// executionWaveDeltaList.clear();
// }
private <P extends ObjectType> boolean isShadowDeltaSignificant(ObjectDelta<P> delta) {
if (delta == null || delta.isEmpty()) {
return false;
}
if (delta.isAdd() || delta.isDelete()) {
return true;
}
Collection<? extends ItemDelta<?,?>> attrDeltas = delta.findItemDeltasSubPath(ShadowType.F_ATTRIBUTES);
if (attrDeltas != null && !attrDeltas.isEmpty()) {
return true;
}
return false;
}
private <F extends ObjectType> HookOperationMode processFinal(LensContext<F> context, Task task, OperationResult result, OperationResult overallResult)
throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException,
SecurityViolationException, ExpressionEvaluationException, PolicyViolationException, PreconditionViolationException {
auditFinalExecution(context, task, result, overallResult);
logFinalReadable(context, task, result);
recordOperationExecution(context, null, task, result);
migrator.executeAfterOperationMigration(context, result);
HookOperationMode opmode = personaProcessor.processPersonaChanges(context, task, result);
if (opmode == HookOperationMode.BACKGROUND) {
return opmode;
}
return triggerReconcileAffected(context, task, result);
}
private <F extends ObjectType> void recordOperationExecution(LensContext<F> context, Throwable clockworkException,
Task task, OperationResult result) {
boolean skip = context.getInternalsConfiguration() != null &&
context.getInternalsConfiguration().getOperationExecutionRecording() != null &&
Boolean.TRUE.equals(context.getInternalsConfiguration().getOperationExecutionRecording().isSkip());
if (!skip) {
XMLGregorianCalendar now = clock.currentTimeXMLGregorianCalendar();
try {
LOGGER.trace("recordOperationExecution starting; task = {}, clockworkException = {}", task, clockworkException);
boolean opRecordedIntoFocus = recordFocusOperationExecution(context, now, clockworkException, task, result);
for (LensProjectionContext projectionContext : context.getProjectionContexts()) {
Throwable exceptionToProjection;
if (clockworkException != null && !opRecordedIntoFocus && projectionContext.isSynchronizationSource()) {
// We need to record the exception somewhere. Because we were not able to put it into focus,
// we have to do it into sync-source projection.
exceptionToProjection = clockworkException;
} else {
exceptionToProjection = null;
}
recordProjectionOperationExecution(context, projectionContext, now, exceptionToProjection, task, result);
}
} catch (Throwable t) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't record operation execution. Model context:\n{}", t,
context.debugDump());
// Let us ignore this for the moment. It should not have happened, sure. But it's not that crucial.
// Administrator will be able to learn about the problem from the log.
}
} else {
LOGGER.trace("Skipping operation execution recording (as set in system configuration)");
}
}
/**
* @return true if the operation execution was recorded (or would be recorded, but skipped because of the configuration)
*/
private <F extends ObjectType> boolean recordFocusOperationExecution(LensContext<F> context, XMLGregorianCalendar now,
Throwable clockworkException, Task task, OperationResult result)
throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException {
LensFocusContext<F> focusContext = context.getFocusContext();
if (focusContext == null || focusContext.isDelete()) {
LOGGER.trace("focusContext is null or 'delete', not recording focus operation execution");
return false;
}
PrismObject<F> objectNew = focusContext.getObjectNew();
Validate.notNull(objectNew, "No focus object even if the context is not of 'delete' type");
//noinspection unchecked
List<LensObjectDeltaOperation<F>> executedDeltas = getExecutedDeltas(focusContext,
(Class<F>) objectNew.asObjectable().getClass(), clockworkException, result);
LOGGER.trace("recordFocusOperationExecution: executedDeltas: {}", executedDeltas.size());
return recordOperationExecution(objectNew, false, executedDeltas, now, context.getChannel(),
getSkipWhenSuccess(context), task, result);
}
@NotNull
private <O extends ObjectType> List<LensObjectDeltaOperation<O>> getExecutedDeltas(LensElementContext<O> elementContext,
Class<O> objectClass, Throwable clockworkException, OperationResult result) {
List<LensObjectDeltaOperation<O>> executedDeltas;
if (clockworkException != null) {
executedDeltas = new ArrayList<>(elementContext.getExecutedDeltas());
LensObjectDeltaOperation<O> odo = new LensObjectDeltaOperation<>();
ObjectDelta<O> primaryDelta = elementContext.getPrimaryDelta();
if (primaryDelta != null) {
odo.setObjectDelta(primaryDelta);
} else {
ObjectDelta<O> fakeDelta = prismContext.deltaFactory().object().create(objectClass, ChangeType.MODIFY);
odo.setObjectDelta(fakeDelta);
}
odo.setExecutionResult(result); // we rely on the fact that 'result' already contains record of the exception
executedDeltas.add(odo);
} else {
executedDeltas = elementContext.getExecutedDeltas();
}
return executedDeltas;
}
private <F extends ObjectType> boolean getSkipWhenSuccess(LensContext<F> context) {
return context.getInternalsConfiguration() != null &&
context.getInternalsConfiguration().getOperationExecutionRecording() != null &&
Boolean.TRUE.equals(context.getInternalsConfiguration().getOperationExecutionRecording().isSkipWhenSuccess());
}