Skip to content

Commit

Permalink
Fix progress & item stats for bulk actions
Browse files Browse the repository at this point in the history
This commit enables limited support for progress and item processing
statistics for legacy bulk actions.

Related to MID-7209.
  • Loading branch information
mederly committed Mar 24, 2022
1 parent bd68312 commit 06cf1b6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ default Operation recordIterativeOperationStart(PrismObject<? extends ObjectType
* The operation end is recorded by calling appropriate method on the returned object.
*/
@NotNull default Operation recordIterativeOperationStart(IterationItemInformation info) {
return recordIterativeOperationStart(new IterativeOperationStartInfo(info));
IterativeOperationStartInfo startInfo = new IterativeOperationStartInfo(info);
startInfo.setSimpleCaller(true);
return recordIterativeOperationStart(startInfo);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

import com.evolveum.midpoint.repo.common.activity.run.*;

import com.evolveum.midpoint.task.api.RunningTask;

import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -92,19 +94,27 @@ final static class MyActivityRun
@Override
public @NotNull ActivityReportingCharacteristics createReportingCharacteristics() {
return super.createReportingCharacteristics()
.statisticsSupported(false);
.statisticsSupported(true)
.progressSupported(true)
.progressCommitPointsSupported(false);
}

@Override
protected @NotNull ActivityRunResult runLocally(OperationResult result)
throws ActivityRunException, CommonException {
throws CommonException {
RunningTask runningTask = getRunningTask();
ExecuteScriptType executeScriptRequest = getWorkDefinition().getScriptExecutionRequest().clone();
ScriptExecutionResult executionResult = getActivityHandler().scriptingService
.evaluateExpression(executeScriptRequest,
VariablesMap.emptyMap(), false, getRunningTask(), result);
LOGGER.debug("Execution output: {} item(s)", executionResult.getDataOutput().size());
LOGGER.debug("Execution result:\n{}", executionResult.getConsoleOutput());
return standardRunResult();
runningTask.setExecutionSupport(this);
try {
ScriptExecutionResult executionResult = getActivityHandler().scriptingService
.evaluateExpression(executeScriptRequest,
VariablesMap.emptyMap(), true, runningTask, result);
LOGGER.debug("Execution output: {} item(s)", executionResult.getDataOutput().size());
LOGGER.debug("Execution result:\n{}", executionResult.getConsoleOutput());
return standardRunResult();
} finally {
runningTask.setExecutionSupport(null);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ public <T extends ObjectType> PrismObject<T> getObject(Class<T> type, String oid

public Operation recordStart(ExecutionContext context, ObjectType object) {
if (context.isRecordProgressAndIterationStatistics()) {
if (context.getTask() != null && object != null) {
return context.getTask().recordIterativeOperationStart(object.asPrismObject());
Task task = context.getTask();
if (task != null && object != null) {
return task.recordIterativeOperationStart(object.asPrismObject());
} else {
LOGGER.warn("Couldn't record operation start in script execution; task = {}, object = {}",
context.getTask(), object);
LOGGER.warn("Couldn't record operation start in script execution; task = {}, object = {}", task, object);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.schema.statistics.AbstractStatisticsPrinter;
import com.evolveum.midpoint.schema.statistics.IterationItemInformation;
Expand Down Expand Up @@ -84,7 +83,7 @@ public class ActivityItemProcessingStatistics extends Initializable {

ActivityItemProcessingStatistics(@NotNull CurrentActivityState<?> activityState) {
this.activityState = activityState;
this.value = new ActivityItemProcessingStatisticsType(PrismContext.get());
this.value = new ActivityItemProcessingStatisticsType();
}

/**
Expand Down Expand Up @@ -118,7 +117,7 @@ public void initialize(ActivityItemProcessingStatisticsType initialValue) {
public synchronized Operation recordOperationStart(IterativeOperationStartInfo startInfo) {
assertInitialized();
IterationItemInformation item = startInfo.getItem();
ProcessedItemType processedItem = new ProcessedItemType(PrismContext.get())
ProcessedItemType processedItem = new ProcessedItemType()
.name(item.getObjectName())
.displayName(item.getObjectDisplayName())
.type(item.getObjectType())
Expand Down Expand Up @@ -162,7 +161,7 @@ private static ActivityRunRecordType findOrCreateMatchingRunRecord(List<Activity
return record;
}
}
ActivityRunRecordType newRecord = new ActivityRunRecordType(PrismContext.get())
ActivityRunRecordType newRecord = new ActivityRunRecordType()
.startTimestamp(startAsGregorian);
records.add(newRecord);
return newRecord;
Expand Down Expand Up @@ -213,7 +212,7 @@ private ProcessedItemSetType findOrCreateProcessedItemSet(ActivityItemProcessing
.orElseGet(
() -> ActivityItemProcessingStatisticsUtil.add(
part.getProcessed(),
new ProcessedItemSetType(PrismContext.get())
new ProcessedItemSetType()
.outcome(outcome.cloneWithoutId())));
}

Expand Down

0 comments on commit 06cf1b6

Please sign in to comment.