Skip to content

Commit

Permalink
Fix shadow mgmt simulations + phantom deltas
Browse files Browse the repository at this point in the history
1. Shadow management simulations provided wrong "before" state.
2. Phantom deltas are no longer shown in reports.
  • Loading branch information
mederly committed Feb 28, 2023
1 parent b5e2e92 commit 570c6a5
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,7 @@ private Set<? extends PrismValue> getPrismValuesAfter(@NotNull ItemPath path) {
return delta.getModifications().stream()
.map(itemDelta -> new ProcessedObjectItemDeltaImpl<>(itemDelta))
.filter(itemDelta -> filter.matches(itemDelta))
.filter(itemDelta -> !itemDelta.isPhantom())
.collect(Collectors.toList());
} else {
return List.of();
Expand Down Expand Up @@ -862,6 +863,11 @@ public ItemDelta<V, D> clone() {
ParameterizedEquivalenceStrategy.REAL_VALUE));
}

/** Either we have only operational data changed, or the delta is phantom one indeed. */
public boolean isPhantom() {
return getValuesWithStates().isEmpty();
}

@Override
public @NotNull Collection<ValueWithState> getValuesWithStates() {
List<ValueWithState> all = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ class ShadowUpdater {
@NotNull private final ModelBeans beans;
@NotNull private final List<ItemDelta<?, ?>> deltas = new ArrayList<>();

/** Only for simulation purposes. */
private final ShadowType shadowBefore;

ShadowUpdater(@NotNull SynchronizationContext<?> syncCtx, @NotNull ModelBeans beans) {
this.syncCtx = syncCtx;
this.beans = beans;
this.shadowBefore = isShadowSimulation() ? syncCtx.getShadowedResourceObject().clone() : null;
}

ShadowUpdater updateAllSyncMetadataRespectingMode() throws SchemaException {
Expand Down Expand Up @@ -195,7 +199,7 @@ void commit(OperationResult result) {
return;
}
try {
if (syncCtx.getTask().areShadowChangesSimulated()) {
if (isShadowSimulation()) {
commitToSimulation(result);
} else {
commitToRepository(result);
Expand All @@ -208,15 +212,18 @@ void commit(OperationResult result) {
deltas.clear();
}

private boolean isShadowSimulation() {
return syncCtx.getTask().areShadowChangesSimulated();
}

private void commitToSimulation(OperationResult result) {
Task task = syncCtx.getTask();
ShadowType shadow = syncCtx.getShadowedResourceObject();
SimulationTransaction simulationTransaction = task.getSimulationTransaction();
if (simulationTransaction == null) {
LOGGER.debug("Ignoring simulation data because there is no simulation transaction: {}: {}", shadow, deltas);
LOGGER.debug("Ignoring simulation data because there is no simulation transaction: {}: {}", shadowBefore, deltas);
} else {
simulationTransaction.writeSimulationData(
ShadowSimulationData.of(shadow, deltas), task, result);
ShadowSimulationData.of(shadowBefore, deltas), task, result);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ private void executeSimulatedClassificationAndReclassification(
.assertSize(0);
} else {
// Resource is development mode, task sees the development configuration.
// Hence, both re-classification and re-correlation occurs (the latter because the
// Hence, both re-classification and re-correlation occurs.
and("there is a re-classification delta");
// @formatter:off
assertProcessedObjects(simResult3)
Expand All @@ -943,6 +943,10 @@ private void executeSimulatedClassificationAndReclassification(
.end()
.assertSize(2); // temporarily
// @formatter:on

REPORT_SIMULATION_VALUES_CHANGED.export()
.withDefaultParametersValues(simResult3.getSimulationResultRef())
.execute(result);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.io.FileNotFoundException;
import java.net.ConnectException;

import static com.evolveum.midpoint.model.test.CommonInitialObjects.REPORT_SIMULATION_VALUES_CHANGED;
import static com.evolveum.midpoint.schema.constants.MidPointConstants.NS_RI;
import static com.evolveum.midpoint.schema.constants.SchemaConstants.RI_ACCOUNT_OBJECT_CLASS;

Expand Down Expand Up @@ -151,6 +152,8 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
RESOURCE_SIMPLE_DEVELOPMENT_TARGET.initAndTest(this, initTask, initResult);
RESOURCE_SIMPLE_PRODUCTION_SOURCE.initAndTest(this, initTask, initResult);
RESOURCE_SIMPLE_DEVELOPMENT_SOURCE.initAndTest(this, initTask, initResult);

REPORT_SIMULATION_VALUES_CHANGED.init(this, initTask, initResult);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ public void test110DisableAndRenameUsers() throws Exception {
assertCsv(itemsLines2, "after")
.parse()
.display()
.assertRecords((a) -> a.hasSizeGreaterThan(50)); // too many
.assertRecords((a) -> a.hasSizeGreaterThan(40)); // too many

when("item-level report is created - 'name' only");
var itemsLines3 = REPORT_SIMULATION_ITEMS_CHANGED.export()
Expand Down

0 comments on commit 570c6a5

Please sign in to comment.