Skip to content

Commit

Permalink
Add yet another simulation tests and fixes
Browse files Browse the repository at this point in the history
Hooks (certification, notification, workflow) are skipped in simulation
mode. Also, projection deactivation determination is fixed.
  • Loading branch information
mederly committed Feb 14, 2023
1 parent be8bf11 commit 073addd
Show file tree
Hide file tree
Showing 10 changed files with 285 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ public void init() {
}

@Override
public <O extends ObjectType> HookOperationMode invoke(@NotNull ModelContext<O> context, @NotNull Task task,
@NotNull OperationResult result) {
public <O extends ObjectType> HookOperationMode invoke(
@NotNull ModelContext<O> context, @NotNull Task task, @NotNull OperationResult result) {
if (context.isPreview() || context.isSimulation()) {
return HookOperationMode.FOREGROUND;
}
if (context.getState() != ModelState.FINAL) {
return HookOperationMode.FOREGROUND;
}
Expand Down Expand Up @@ -91,9 +94,9 @@ private Collection<CertificationPolicyActionType> getCertificationActions(Collec
}

@Override
public void invokeOnException(@NotNull ModelContext context, @NotNull Throwable throwable, @NotNull Task task,
public void invokeOnException(
@NotNull ModelContext<?> context, @NotNull Throwable throwable, @NotNull Task task,
@NotNull OperationResult result) {
// Nothing to do
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.delta.DeltaSetTriple;
import com.evolveum.midpoint.model.api.ObjectTreeDeltas;
import com.evolveum.midpoint.schema.TaskExecutionMode;
import com.evolveum.midpoint.schema.expression.ExpressionProfile;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
Expand Down Expand Up @@ -92,7 +93,7 @@ default String dumpObjectPolicyRules(int indent) {

String dumpObjectPolicyRules(int indent, boolean alsoMessages);

Map<String, Collection<Containerable>> getHookPreviewResultsMap();
Map<String, Collection<? extends Containerable>> getHookPreviewResultsMap();

@NotNull
<T> List<T> getHookPreviewResults(@NotNull Class<T> clazz);
Expand All @@ -102,6 +103,11 @@ default String dumpObjectPolicyRules(int indent) {

boolean isPreview();

/** TODO reconcile with {@link #isPreview()} */
default boolean isSimulation() {
return !getTaskExecutionMode().isFullyPersistent();
}

@NotNull
ObjectTreeDeltas<F> getTreeDeltas();

Expand All @@ -114,4 +120,6 @@ default String dumpObjectPolicyRules(int indent) {
String getTaskTreeOid(Task task, OperationResult result);

ExpressionProfile getPrivilegedExpressionProfile();

@NotNull TaskExecutionMode getTaskExecutionMode();
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public interface ChangeHook {
* This method has no return value, as it is not expected that the processing would continue in
* the background. (This could change in the future.)
*/
void invokeOnException(@NotNull ModelContext context, @NotNull Throwable throwable, @NotNull Task task, @NotNull OperationResult result);
void invokeOnException(
@NotNull ModelContext<?> context, @NotNull Throwable throwable, @NotNull Task task, @NotNull OperationResult result);

default int getPriority() {
return Integer.MAX_VALUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;

import com.evolveum.midpoint.repo.common.expression.ExpressionEnvironmentThreadLocalHolder;
import com.evolveum.midpoint.schema.TaskExecutionMode;
import com.evolveum.midpoint.schema.expression.ExpressionProfile;

import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -1199,7 +1200,7 @@ public String dumpObjectPolicyRules(int indent, boolean alsoMessages) {
}

@Override
public Map<String, Collection<Containerable>> getHookPreviewResultsMap() {
public Map<String, Collection<? extends Containerable>> getHookPreviewResultsMap() {
return null;
}

Expand Down Expand Up @@ -1252,6 +1253,11 @@ public String getTaskTreeOid(Task task, OperationResult result) {
public ExpressionProfile getPrivilegedExpressionProfile() {
return null;
}

@Override
public @NotNull TaskExecutionMode getTaskExecutionMode() {
return TaskExecutionMode.PRODUCTION;
}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,14 +431,20 @@ private boolean isProjectionActivationChanged(ModelProjectionContext projectionC
public boolean isCurrentProjectionActivated()
throws SchemaException, ExpressionEvaluationException, CommunicationException, SecurityViolationException,
ConfigurationException, ObjectNotFoundException {
return !wasCurrentProjectionActive() && willCurrentProjectionBeActive();
boolean wasActive = wasCurrentProjectionActive();
boolean willBeActive = willCurrentProjectionBeActive();
LOGGER.trace("isCurrentProjectionActivated: wasActive = {}, willBeActive = {}", wasActive, willBeActive);
return !wasActive && willBeActive;
}

@Override
public boolean isCurrentProjectionDeactivated()
throws SchemaException, ExpressionEvaluationException, CommunicationException, SecurityViolationException,
ConfigurationException, ObjectNotFoundException {
return wasCurrentProjectionActive() && !willCurrentProjectionBeActive();
boolean wasActive = wasCurrentProjectionActive();
boolean willBeActive = willCurrentProjectionBeActive();
LOGGER.trace("isCurrentProjectionDeactivated: wasActive = {}, willBeActive = {}", wasActive, willBeActive);
return wasActive && !willBeActive;
}

private boolean wasCurrentProjectionActive()
Expand All @@ -458,14 +464,15 @@ private boolean wasCurrentProjectionActive()
private boolean willCurrentProjectionBeActive()
throws SchemaException, ExpressionEvaluationException, CommunicationException, SecurityViolationException,
ConfigurationException, ObjectNotFoundException {
// "objectNew" is not a good indicator here - we have to look at sync decision instead
LensProjectionContext projCtx = getCurrentProjectionContextRequired();
if (projCtx.isAdministrativeStatusSupported()) {
ensureActivationInformationAvailable(projCtx);
ShadowType objectNew = asObjectable(projCtx.getObjectNew());
return objectNew != null && isShadowEnabled(objectNew);
return objectNew != null && !projCtx.isDelete() && isShadowEnabled(objectNew);
} else {
// No need to load the shadow, as the administrative status is not relevant here
return projCtx.getObjectNew() != null;
return projCtx.getObjectNew() != null && !projCtx.isDelete();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public class LensContext<F extends ObjectType> implements ModelContext<F>, Clone
/** Denotes (legacy) "preview changes" mode. */
private transient boolean preview;

private transient Map<String, Collection<Containerable>> hookPreviewResultsMap;
private transient Map<String, Collection<? extends Containerable>> hookPreviewResultsMap;

private transient PolicyRuleEnforcerPreviewOutputType policyRuleEnforcerPreviewOutput;

Expand Down Expand Up @@ -1604,22 +1604,22 @@ public boolean hasExplosiveProjection() throws SchemaException, ConfigurationExc
}

@NotNull
public Map<String, Collection<Containerable>> getHookPreviewResultsMap() {
public Map<String, Collection<? extends Containerable>> getHookPreviewResultsMap() {
if (hookPreviewResultsMap == null) {
hookPreviewResultsMap = new HashMap<>();
}
return hookPreviewResultsMap;
}

public void addHookPreviewResults(String hookUri, Collection<Containerable> results) {
public void addHookPreviewResults(String hookUri, Collection<? extends Containerable> results) {
getHookPreviewResultsMap().put(hookUri, results);
}

@NotNull
@Override
public <T> List<T> getHookPreviewResults(@NotNull Class<T> clazz) {
List<T> rv = new ArrayList<>();
for (Collection<Containerable> previewResults : getHookPreviewResultsMap().values()) {
for (Collection<? extends Containerable> previewResults : getHookPreviewResultsMap().values()) {
for (Containerable previewResult : CollectionUtils.emptyIfNull(previewResults)) {
if (previewResult != null && clazz.isAssignableFrom(previewResult.getClass())) {
//noinspection unchecked
Expand Down Expand Up @@ -1988,7 +1988,8 @@ public void markMatchingProjectionsBroken(@NotNull ConstructionType construction
return modelBeans;
}

@NotNull TaskExecutionMode getTaskExecutionMode() {
@Override
public @NotNull TaskExecutionMode getTaskExecutionMode() {
return taskExecutionMode;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ public LensContext<?> getLastAsyncContext() {
return lastAsyncContext;
}

/* (non-Javadoc)
* @see com.evolveum.midpoint.model.api.hooks.ChangeHook#invoke(com.evolveum.midpoint.model.api.context.ModelContext, com.evolveum.midpoint.task.api.Task, com.evolveum.midpoint.schema.result.OperationResult)
*/
@Override
public HookOperationMode invoke(@NotNull ModelContext context, @NotNull Task task, @NotNull OperationResult result) {
assertTrue("Unexpected INITIAL state of the context in the hook", context.getState() != ModelState.INITIAL);
Expand All @@ -91,23 +88,10 @@ public HookOperationMode invoke(@NotNull ModelContext context, @NotNull Task tas
}

@Override
public void invokeOnException(@NotNull ModelContext context, @NotNull Throwable throwable, @NotNull Task task, @NotNull OperationResult result) {
public void invokeOnException(@NotNull ModelContext<?> context, @NotNull Throwable throwable, @NotNull Task task, @NotNull OperationResult result) {
// do nothing
}

/* (non-Javadoc)
* @see com.evolveum.midpoint.model.api.hooks.ChangeHook#postChange(java.util.Collection, com.evolveum.midpoint.task.api.Task, com.evolveum.midpoint.schema.result.OperationResult)
*/
// @Override
// public void postChange(Collection<ObjectDelta<? extends ObjectType>> changes, Task task,
// OperationResult result) {
// // TODO Auto-generated method stub
//
// }

/* (non-Javadoc)
* @see com.evolveum.midpoint.util.DebugDumpable#debugDump(int)
*/
@Override
public String debugDump(int indent) {
StringBuilder sb = new StringBuilder();
Expand Down

0 comments on commit 073addd

Please sign in to comment.