use of com.evolveum.midpoint.task.api.ExecutionSupport in project midpoint by Evolveum.
the class OperationExecutionRecorderForClockwork method createExecutionRecord.
private OperationExecutionType createExecutionRecord(Collection<LensObjectDeltaOperation<?>> executedDeltas, Context<?> ctx) {
assert !executedDeltas.isEmpty();
OperationExecutionType record = new OperationExecutionType(prismContext);
record.setRecordType(OperationExecutionRecordTypeType.SIMPLE);
OperationResult summaryResult = new OperationResult("recordOperationExecution");
for (LensObjectDeltaOperation<?> deltaOperation : executedDeltas) {
record.getOperation().add(createObjectDeltaOperation(deltaOperation));
if (deltaOperation.getExecutionResult() != null) {
// todo eliminate the following clone (but beware of modifying the subresult)
summaryResult.addSubresult(deltaOperation.getExecutionResult().clone());
}
}
createTaskRef(record, ctx);
ExecutionSupport executionSupport = ctx.task.getExecutionSupport();
if (executionSupport != null) {
record.setActivityPath(executionSupport.getActivityPath().toBean());
}
summaryResult.computeStatus();
record.setStatus(summaryResult.getStatus().createStatusType());
record.setMessage(summaryResult.getMessage());
// TODO what if the real initiator is different? (e.g. when executing approved changes)
record.setInitiatorRef(ObjectTypeUtil.createObjectRefCopy(ctx.task.getOwnerRef()));
record.setChannel(ctx.lensContext.getChannel());
record.setTimestamp(ctx.now);
return record;
}
use of com.evolveum.midpoint.task.api.ExecutionSupport in project midpoint by Evolveum.
the class PolicyRuleCounterUpdater method updateCounters.
@ProcessorMethod
public <AH extends AssignmentHolderType> void updateCounters(LensContext<AH> context, @SuppressWarnings("unused") XMLGregorianCalendar now, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ObjectAlreadyExistsException {
ExecutionSupport executionSupport = task.getExecutionSupport();
if (executionSupport == null) {
return;
}
/*
* We update the counters in rules with thresholds in the following ways:
*
* 1) If a rule counter was already incremented in this clockwork run, we copy the counter value into the rule.
* (Regardless of whether it has been triggered during the latest evaluation.)
*
* 2) All remaining rules are incremented - if they are triggered.
*
* All of this is needed because the rules are quite temporary; they are recreated on each projector run,
* currently even on each focus iteration (which is maybe unnecessary). We certainly do not want to increase
* the counters each time. But we need to have the current counter value in the rules even on further projector
* runs.
*/
LensFocusContext<AH> focusContext = context.getFocusContextRequired();
List<EvaluatedPolicyRule> rulesToIncrement = new ArrayList<>();
for (EvaluatedPolicyRuleImpl rule : focusContext.getObjectPolicyRules()) {
if (!rule.hasThreshold()) {
continue;
}
Integer alreadyIncrementedValue = focusContext.getPolicyRuleCounter(rule.getPolicyRuleIdentifier());
if (alreadyIncrementedValue != null) {
rule.setCount(alreadyIncrementedValue);
continue;
}
if (!rule.isTriggered()) {
continue;
}
rulesToIncrement.add(rule);
}
if (rulesToIncrement.isEmpty()) {
return;
}
Map<String, EvaluatedPolicyRule> rulesByIdentifier = rulesToIncrement.stream().collect(Collectors.toMap(EvaluatedPolicyRule::getPolicyRuleIdentifier, Function.identity()));
ExecutionSupport.CountersGroup group = executionSupport.getExecutionMode() == ExecutionModeType.FULL ? FULL_EXECUTION_MODE_POLICY_RULES : PREVIEW_MODE_POLICY_RULES;
Map<String, Integer> currentValues = executionSupport.incrementCounters(group, rulesByIdentifier.keySet(), result);
currentValues.forEach((id, value) -> {
rulesByIdentifier.get(id).setCount(value);
focusContext.setPolicyRuleCounter(id, value);
});
}
Aggregations