Skip to content

Commit

Permalink
Delete dangling dead (inactive) linkRef values
Browse files Browse the repository at this point in the history
Unlike dangling regular (live ~ org:default) linkRef values, the
dangling dead ones were not automatically deleted when discovered.
This is now fixed.

See MID-8361.

(cherry picked from commit a78ceae)
  • Loading branch information
mederly committed Jan 9, 2023
1 parent 0dee9ac commit dc771d1
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,13 @@ private void refreshInactiveLinkedShadow(String oid, OperationResult result) {
}
try {
beans.provisioningService.getObject(ShadowType.class, oid, options, task, result);
} catch (ObjectNotFoundException e) {
// We will NOT delete the linkRef here. Instead, we will persuade LinkUpdater to do it, by creating a broken
// projection context (just as if the link would be regular one). This is the only situation when there is
// a projection context created for inactive linkRef.
createBrokenProjectionContext(oid);
result.getLastSubresult()
.setErrorsHandled();
} catch (Exception e) {
result.muteLastSubresultError();
LOGGER.debug("Couldn't refresh linked shadow {}. Continuing.", oid, e);
Expand Down Expand Up @@ -476,11 +483,7 @@ private void getOrCreateFromActiveLinkRef(OperationResult result)
try {
return beans.provisioningService.getObject(ShadowType.class, oid, options, task, result);
} catch (ObjectNotFoundException e) {
// Broken linkRef. We need to mark it for deletion.
LensProjectionContext projectionContext = getOrCreateEmptyGone(oid);
projectionContext.setFresh(true);
projectionContext.setExists(false);
projectionContext.setShadowExistsInRepo(false);
createBrokenProjectionContext(oid);
result.getLastSubresult()
.setErrorsHandled();
return null;
Expand Down Expand Up @@ -692,6 +695,14 @@ private void checkExistingContextSanity(
}
}

private void createBrokenProjectionContext(String oid) {
LOGGER.trace("Broken linkRef {}. We need to mark it for deletion.", oid);
LensProjectionContext projectionContext = getOrCreateEmptyGone(oid);
projectionContext.setFresh(true);
projectionContext.setExists(false);
projectionContext.setShadowExistsInRepo(false);
}

/**
* Loads the projection context from specified shadow (determined in {@link LinkLevelOperation}).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
*/
package com.evolveum.midpoint.model.intest;

import static com.evolveum.midpoint.schema.constants.SchemaConstants.RI_ACCOUNT_OBJECT_CLASS;

import static com.evolveum.midpoint.schema.processor.ResourceSchemaTestUtil.findObjectTypeDefinitionRequired;
import static com.evolveum.midpoint.test.DummyResourceContoller.*;

import static java.util.Collections.singleton;
import static org.assertj.core.api.Assertions.assertThat;
import static org.testng.AssertJUnit.*;

import static com.evolveum.midpoint.schema.constants.SchemaConstants.RI_ACCOUNT_OBJECT_CLASS;
import static com.evolveum.midpoint.schema.processor.ResourceSchemaTestUtil.findObjectTypeDefinitionRequired;
import static com.evolveum.midpoint.schema.statistics.AbstractStatisticsPrinter.Format.TEXT;
import static com.evolveum.midpoint.schema.statistics.AbstractStatisticsPrinter.SortBy.TIME;
import static com.evolveum.midpoint.test.DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_PATH;
import static com.evolveum.midpoint.test.DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_WEAPON_PATH;

import java.io.File;
import java.util.ArrayList;
Expand All @@ -28,7 +27,7 @@
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition;
import com.evolveum.midpoint.prism.delta.*;

import org.apache.commons.lang3.StringUtils;
import org.springframework.test.annotation.DirtiesContext;
Expand All @@ -44,7 +43,6 @@
import com.evolveum.midpoint.model.api.ModelExecuteOptions;
import com.evolveum.midpoint.notifications.api.transports.Message;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.delta.*;
import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.polystring.PolyString;
Expand Down Expand Up @@ -3317,6 +3315,60 @@ public void test410RecomputeRole() throws Exception {
dummyAuditService.assertCustomColumn("foo", "test");
}

/**
* Checks whether broken live `linkRef` value is correctly removed.
*
* See MID-8361.
*/
@Test
public void test420DanglingLiveLinkRefCleanup() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();
preTestCleanup(AssignmentPolicyEnforcementType.RELATIVE);

String randomShadowOid = "79898dfa-0d84-43be-b15d-2bb2c8333428";

given("a user with a dangling live `linkRef` exists");
UserType user = new UserType()
.name("test420")
.linkRef(randomShadowOid, ShadowType.COMPLEX_TYPE, SchemaConstants.ORG_DEFAULT);
repositoryService.addObject(user.asPrismObject(), null, result);

when("the user is recomputed");
recomputeUser(user.getOid(), task, result);

then("there should be no link now");
assertUserAfter(user.getOid())
.assertLinks(0, 0);
}

/**
* Checks whether broken dead `linkRef` value is correctly removed.
*
* See MID-8361.
*/
@Test
public void test430DanglingDeadLinkRefCleanup() throws Exception {
Task task = getTestTask();
OperationResult result = task.getResult();
preTestCleanup(AssignmentPolicyEnforcementType.RELATIVE);

String randomShadowOid = "8b61179c-6c7c-4933-ba6a-12a943eb1491";

given("a user with a dangling dead `linkRef` exists");
UserType user = new UserType()
.name("test430")
.linkRef(randomShadowOid, ShadowType.COMPLEX_TYPE, SchemaConstants.ORG_RELATED);
repositoryService.addObject(user.asPrismObject(), null, result);

when("the user is recomputed");
recomputeUser(user.getOid(), task, result);

then("there should be no link now");
assertUserAfter(user.getOid())
.assertLinks(0, 0);
}

/**
* Tests the sanity of transformed schema. Currently there is a specific problem
* with looking up container definitions pretending they are properties. See
Expand Down

0 comments on commit dc771d1

Please sign in to comment.