Skip to content

Commit

Permalink
Fix loading full shadows in recon. processor
Browse files Browse the repository at this point in the history
We need "no discovery" option there. E.g. correct handling
of maintenance mode depends on full shadow load throwing
an exception in that stage.

This fixes TestResourceInMaintenance.

Related to MID-7053.
  • Loading branch information
mederly committed Sep 25, 2021
1 parent 1eeb52b commit 7284c38
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1685,4 +1685,9 @@ public void rotWithDeltaDeletion() {
rot();
state.clearSecondaryDelta();
}

/** Assumes that the resource is loaded. */
public boolean isInMaintenance() {
return ResourceTypeUtil.isInMaintenance(resource);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,20 @@ public <F extends ObjectType> void updateFocusTemplate(LensContext<F> context, O
}
}

public <F extends ObjectType> void loadFullShadow(@NotNull LensProjectionContext projCtx, String reason,
public void loadFullShadow(@NotNull LensProjectionContext projCtx, String reason,
Task task, OperationResult parentResult)
throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException,
SecurityViolationException, ExpressionEvaluationException {
new ProjectionFullLoadOperation<>(projCtx.getLensContext(), projCtx, reason, task)
new ProjectionFullLoadOperation<>(projCtx.getLensContext(), projCtx, reason, false, task)
.loadFullShadow(parentResult);
}

@SuppressWarnings("SameParameterValue")
void loadFullShadowNoDiscovery(@NotNull LensProjectionContext projCtx, String reason,
Task task, OperationResult parentResult)
throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException,
SecurityViolationException, ExpressionEvaluationException {
new ProjectionFullLoadOperation<>(projCtx.getLensContext(), projCtx, reason, true, task)
.loadFullShadow(parentResult);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.evolveum.midpoint.schema.processor.ResourceAttributeContainer;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.*;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType;

import org.jetbrains.annotations.NotNull;
Expand All @@ -50,12 +51,6 @@
import com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ShadowUtil;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.ExpressionEvaluationException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SecurityViolationException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
Expand Down Expand Up @@ -127,7 +122,7 @@ private void processReconciliation(LensProjectionContext projCtx, Task task, Ope
}

if (!projCtx.isFullShadow()) {
contextLoader.loadFullShadow(projCtx, "projection reconciliation", task, result);
contextLoader.loadFullShadowNoDiscovery(projCtx, "projection reconciliation", task, result);
}

LOGGER.trace("Starting reconciliation of {}", projCtx.getHumanReadableName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class ProjectionFullLoadOperation<F extends ObjectType> {
@NotNull private final LensProjectionContext projCtx;
@NotNull private final String reason;
@NotNull private final Task task;
private final boolean noDiscovery;
@NotNull private final ModelBeans beans;

private FullShadowLoadedTraceType trace;
Expand All @@ -60,11 +61,13 @@ public ProjectionFullLoadOperation(
@NotNull LensContext<F> context,
@NotNull LensProjectionContext projCtx,
@NotNull String reason,
boolean noDiscovery,
@NotNull Task task) {
this.context = context;
this.projCtx = projCtx;
this.reason = reason;
this.task = task;
this.noDiscovery = noDiscovery;
this.beans = ModelBeans.get();
}

Expand Down Expand Up @@ -159,15 +162,19 @@ private Collection<SelectorOptions<GetOperationOptions>> createOptions() throws
if (projCtx.isDoReconciliation()) {
getOptions.setForceRefresh(true);
}
if (SchemaConstants.CHANNEL_DISCOVERY_URI.equals(context.getChannel())) {
LOGGER.trace("Loading full resource object {} from provisioning - with doNotDiscover to avoid loops; reason: {}",
projCtx, reason);
// Avoid discovery loops
String discoveryDescription;
if (noDiscovery) {
getOptions.setDoNotDiscovery(true);
discoveryDescription = "no discovery - on caller request";
} else if (SchemaConstants.CHANNEL_DISCOVERY_URI.equals(context.getChannel())) {
getOptions.setDoNotDiscovery(true);
discoveryDescription = "no discovery - to avoid loops";
} else {
LOGGER.trace("Loading full resource object {} from provisioning (discovery enabled), reason: {}, channel: {}",
projCtx, reason, context.getChannel());
discoveryDescription = "discovery enabled";
}
LOGGER.trace("Loading full resource object {} from provisioning ({}) as requested; reason: {}",
projCtx, discoveryDescription, reason);

Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(getOptions);
addRetrievePasswordIfNeeded(options);
return options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ public void test500MultiSimple() throws Exception {

when();

traced(() -> assignAccountToUser(user.getOid(), RESOURCE_DUMMY_MULTI_OUTBOUND_SIMPLE_OID, INTENT_DEFAULT, task, result));
assignAccountToUser(user.getOid(), RESOURCE_DUMMY_MULTI_OUTBOUND_SIMPLE_OID, INTENT_DEFAULT, task, result);

then();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,7 @@ public void test115JackAssignRoleDummiesFullErrorIvory() throws Exception {
public void test116JackUnAssignRoleDummiesFullErrorIvory() throws Exception {
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
getDummyResource().setAddBreakMode(BreakMode.NETWORK);
traced(() -> {
try {
jackUnassignRoleDummiesError(ROLE_DUMMIES_IVORY_OID, RESOURCE_DUMMY_IVORY_OID);
} catch (Exception e) {
throw new SystemException(e);
}
});
jackUnassignRoleDummiesError(ROLE_DUMMIES_IVORY_OID, RESOURCE_DUMMY_IVORY_OID);
}

/**
Expand Down Expand Up @@ -525,7 +519,7 @@ public void test224JackKillBeigeAccountAndRecompute() throws Exception {

// WHEN
when();
traced(() -> recomputeUser(USER_JACK_OID, executeOptions().reconcile(), task, result));
recomputeUser(USER_JACK_OID, executeOptions().reconcile(), task, result);

// THEN
then();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public void test040CreateNewAccount() throws Exception {
// lets try recompute just for fun, mp should do nothing and report success:
when("recompute");
OperationResult result2 = createOperationResult();
traced(() -> modelService.recompute(UserType.class, USER2_OID, executeOptions().reconcile(), task, result2));
modelService.recompute(UserType.class, USER2_OID, executeOptions().reconcile(), task, result2);

then("recompute");
assertSuccess(result2, 4); // Deep inside is an exception about maintenance
Expand Down

0 comments on commit 7284c38

Please sign in to comment.