Skip to content

Commit

Permalink
Fix simulations for perpetual state activities
Browse files Browse the repository at this point in the history
Activities that have perpetual state (e.g. LiveSync) will now create
a new simulation result on each individual realization (~ run). This is
to avoid writing to already closed simulation results. It may be
reconsidered later; the official statement is that simulations are
supported for LS tasks, but only for a single execution.
  • Loading branch information
mederly committed Feb 2, 2023
1 parent 6ded554 commit 0e19fe2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void getOrCreateSimulationResult(OperationResult result) throws ActivityRunExcep
}
if (simulationResult != null) {
if (InternalsConfig.consistencyChecks) {
throw new IllegalStateException("Simulation result OID is already present");
throw new IllegalStateException("Simulation result is already present");
} else {
LOGGER.warn("Simulation result is already present for {} - even at the start of the realization", activityRun);
return;
Expand All @@ -67,7 +67,7 @@ void getOrCreateSimulationResult(OperationResult result) throws ActivityRunExcep
var activityState = activityRun.getActivityState();
if (activityState.getSimulationResultRef() != null) {
if (InternalsConfig.consistencyChecks) {
throw new IllegalStateException("Simulation result is already present");
throw new IllegalStateException("Simulation result OID is already present");
} else {
LOGGER.warn("Simulation result OID is already set for {} - even at the start of the realization", activityRun);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,11 @@ private void purgeCurrentState(Context ctx) throws SchemaException {
.item(ctx.currentStateItemPath.append(ActivityStateType.F_REALIZATION_END_TIMESTAMP)).replace()
.item(ctx.currentStateItemPath.append(ActivityStateType.F_RESULT_STATUS)).replace()
.item(ctx.currentStateItemPath.append(ActivityStateType.F_BUCKETING)).replace()
.item(ctx.currentStateItemPath.append(ActivityStateType.F_SIMULATION)).replace()
.asItemDeltas());

if (ctx.currentState.getPersistence() != ActivityStatePersistenceType.PERPETUAL) {
// E.g. "perpetual except for statistics"
swallow(
beans.prismContext.deltaFor(TaskType.class)
.item(ctx.currentStateItemPath.append(ActivityStateType.F_PROGRESS)).replace()
Expand All @@ -256,7 +258,8 @@ private void swallow(Collection<ItemDelta<?, ?>> deltas) {
}

private boolean isTransient(ActivityStateType state) {
return state.getPersistence() == null || state.getPersistence() == ActivityStatePersistenceType.SINGLE_REALIZATION;
ActivityStatePersistenceType persistence = state.getPersistence();
return persistence == null || persistence == ActivityStatePersistenceType.SINGLE_REALIZATION;
}
}

Expand Down

0 comments on commit 0e19fe2

Please sign in to comment.