Skip to content

Commit

Permalink
Clean up ResourceObjectShadowChangeDescription
Browse files Browse the repository at this point in the history
This is quite a harsh change:
- oldShadow was removed,
- shadowedResourceObject is now obligatory.

Also:
 - fix ExternalResourceObjectChange processing
 - fix two LS-based tests (wrong timing of tasks)
  • Loading branch information
mederly committed Feb 17, 2021
1 parent 6a35c59 commit 4b5b3de
Show file tree
Hide file tree
Showing 24 changed files with 155 additions and 359 deletions.
Expand Up @@ -28,7 +28,7 @@ public AssociationSearchExpressionCacheInvalidator(AssociationSearchExpressionEv

@Override
public void notifyChange(ResourceObjectShadowChangeDescription change, Task task, OperationResult parentResult) {
cache.invalidate(change.getResource(), change.getCurrentShadow());
cache.invalidate(change.getResource(), change.getShadowedResourceObject());
}

@Override
Expand Down
Expand Up @@ -118,23 +118,16 @@ public void notifyChange(ResourceObjectShadowChangeDescription change, Task task
return;
}

PrismObject<ShadowType> currentShadow = change.getCurrentShadow();
PrismObject<ShadowType> applicableShadow;
if (currentShadow != null) {
applicableShadow = currentShadow;
} else {
// We need this e.g. in case of delete
applicableShadow = change.getOldShadow();
}
String applicableShadowOid = applicableShadow != null ? applicableShadow.getOid() : null;
PrismObject<ShadowType> currentShadow = change.getShadowedResourceObject();
String applicableShadowOid = currentShadow != null ? currentShadow.getOid() : null;

XMLGregorianCalendar now = clock.currentTimeXMLGregorianCalendar();
SynchronizationEventInformation eventInfo = new SynchronizationEventInformation();

try {
PrismObject<SystemConfigurationType> configuration = systemObjectCache.getSystemConfiguration(subResult);
SynchronizationContext<?> syncCtx = loadSynchronizationContext(
applicableShadow, currentShadow, change.getObjectDelta(), change.getResource(),
currentShadow, currentShadow, change.getObjectDelta(), change.getResource(),
change.getSourceChannel(), change.getItemProcessingIdentifier(), configuration, task, subResult);
LOGGER.trace("SYNCHRONIZATION determined policy: {}", syncCtx);

Expand Down Expand Up @@ -177,7 +170,7 @@ public void notifyChange(ResourceObjectShadowChangeDescription change, Task task

private <F extends FocusType> void cleanDeadShadow(ResourceObjectShadowChangeDescription change, OperationResult subResult) {
LOGGER.trace("Cleaning old dead shadows, checking for old links, cleaning them up");
String shadowOid = getOidFromChange(change);
String shadowOid = change.getShadowOid();
if (shadowOid == null) {
LOGGER.trace("No shadow oid, nothing to clean up.");
return;
Expand Down Expand Up @@ -418,14 +411,13 @@ private boolean isLogDebug(ResourceObjectShadowChangeDescription change) {

private void validate(ResourceObjectShadowChangeDescription change) {
Validate.notNull(change, "Resource object shadow change description must not be null.");
Validate.isTrue(change.getCurrentShadow() != null || change.getObjectDelta() != null,
"Object delta and current shadow are null. At least one must be provided.");
Validate.notNull(change.getShadowedResourceObject(), "Current shadow must not be null.");
Validate.notNull(change.getResource(), "Resource in change must not be null.");

if (consistencyChecks) {
if (change.getCurrentShadow() != null) {
change.getCurrentShadow().checkConsistence();
ShadowUtil.checkConsistence(change.getCurrentShadow(),
if (change.getShadowedResourceObject() != null) {
change.getShadowedResourceObject().checkConsistence();
ShadowUtil.checkConsistence(change.getShadowedResourceObject(),
"current shadow in change description");
}
if (change.getObjectDelta() != null) {
Expand All @@ -452,7 +444,7 @@ private <F extends FocusType> void setupSituation(SynchronizationContext<F> sync
LOGGER.trace("Determining situation for resource object shadow.");

try {
String shadowOid = getOidFromChange(change);
String shadowOid = change.getShadowOid();
Validate.notEmpty(shadowOid, "Couldn't get resource object shadow oid from change.");

F currentOwner;
Expand Down Expand Up @@ -527,22 +519,6 @@ private <F extends FocusType> boolean isCorrelatedOwnerSameAsCurrentOwner(F expe
return expectedOwner == null || currentOwnerType == null || expectedOwner.getOid().equals(currentOwnerType.getOid());
}

private String getOidFromChange(ResourceObjectShadowChangeDescription change) {
if (change.getCurrentShadow() != null && StringUtils.isNotEmpty(change.getCurrentShadow().getOid())) {
return change.getCurrentShadow().getOid();
}
if (change.getOldShadow() != null && StringUtils.isNotEmpty(change.getOldShadow().getOid())) {
return change.getOldShadow().getOid();
}

if (change.getObjectDelta() == null || StringUtils.isEmpty(change.getObjectDelta().getOid())) {
throw new IllegalArgumentException(
"Oid was not defined in change (not in current, old shadow, delta).");
}

return change.getObjectDelta().getOid();
}

/**
* Tries to match specified focus and shadow. Return true if it matches,
* false otherwise.
Expand Down Expand Up @@ -589,14 +565,14 @@ private <F extends FocusType> void determineSituationWithCorrelation(Synchroniza
return;
}

PrismObject<? extends ShadowType> resourceShadow = change.getCurrentShadow();
PrismObject<? extends ShadowType> resourceShadow = change.getShadowedResourceObject();

ObjectDelta<ShadowType> syncDelta = change.getObjectDelta();
if (resourceShadow == null && syncDelta != null && ChangeType.ADD.equals(syncDelta.getChangeType())) {
LOGGER.trace("Trying to compute current shadow from change delta add.");
PrismObject<ShadowType> shadow = syncDelta.computeChangedObject(syncDelta.getObjectToAdd());
resourceShadow = shadow;
change.setCurrentShadow(shadow);
change.setShadowedResourceObject(shadow);
}
Validate.notNull(resourceShadow, "Current shadow must not be null.");

Expand Down Expand Up @@ -803,7 +779,7 @@ private <F extends FocusType> LensContext<F> createLensContext(SynchronizationCo
}

context.rememberResource(resource);
PrismObject<ShadowType> shadow = getShadowFromChange(change);
PrismObject<ShadowType> shadow = change.getShadowedResourceObject();
if (shadow == null) {
throw new IllegalStateException("No shadow in change: " + change);
}
Expand All @@ -818,7 +794,7 @@ private <F extends FocusType> LensContext<F> createLensContext(SynchronizationCo
ResourceShadowDiscriminator discriminator = new ResourceShadowDiscriminator(resource.getOid(), kind, intent, shadow.asObjectable().getTag(), tombstone);
LensProjectionContext projectionContext = context.createProjectionContext(discriminator);
projectionContext.setResource(resource);
projectionContext.setOid(getOidFromChange(change));
projectionContext.setOid(change.getShadowOid());
projectionContext.setSynchronizationSituationDetected(syncCtx.getSituation());
projectionContext.setShadowExistsInRepo(syncCtx.isShadowExistsInRepo());

Expand Down Expand Up @@ -874,16 +850,6 @@ private boolean containsIncompleteItems(PrismObject<ShadowType> shadow) {
}
}

private PrismObject<ShadowType> getShadowFromChange(ResourceObjectShadowChangeDescription change) {
if (change.getCurrentShadow() != null) {
return change.getCurrentShadow();
}
if (change.getOldShadow() != null) {
return change.getOldShadow();
}
return null;
}

private ShadowKindType getKind(PrismObject<ShadowType> shadow, ShadowKindType objectSynchronizationKind) {
ShadowKindType shadowKind = shadow.asObjectable().getKind();
if (shadowKind != null) {
Expand All @@ -902,16 +868,9 @@ private String getIntent(PrismObject<ShadowType> shadow,
}

private boolean isTombstone(ResourceObjectShadowChangeDescription change) {
PrismObject<? extends ShadowType> shadow = null;
if (change.getOldShadow() != null) {
shadow = change.getOldShadow(); // FIXME Why we are checking old shadow first?!
} else if (change.getCurrentShadow() != null) {
shadow = change.getCurrentShadow();
}
if (shadow != null) {
if (shadow.asObjectable().isDead() != null) {
return shadow.asObjectable().isDead();
}
PrismObject<? extends ShadowType> shadow = change.getShadowedResourceObject();
if (shadow.asObjectable().isDead() != null) {
return shadow.asObjectable().isDead();
}
ObjectDelta<? extends ShadowType> objectDelta = change.getObjectDelta();
return objectDelta != null && objectDelta.isDelete();
Expand Down
Expand Up @@ -66,8 +66,8 @@ public String getObjectOidToRecordRetryTrigger() {
@Override
public @NotNull IterationItemInformation getIterationItemInformation() {
ResourceObjectShadowChangeDescription changeDescription = getItem().getChangeDescription();
if (changeDescription != null && changeDescription.getCurrentShadow() != null) {
return new IterationItemInformation(changeDescription.getCurrentShadow());
if (changeDescription != null && changeDescription.getShadowedResourceObject() != null) {
return new IterationItemInformation(changeDescription.getShadowedResourceObject());
} else {
return new IterationItemInformation(); // TODO
}
Expand All @@ -90,8 +90,8 @@ public int compareTo(@NotNull SyncItemProcessingRequest<SE> o) {
return event.getShadowOid();
}
ResourceObjectShadowChangeDescription changeDescription = event.getChangeDescription();
if (changeDescription != null && changeDescription.getCurrentShadow() != null) {
return changeDescription.getCurrentShadow().getOid(); // TODO
if (changeDescription != null && changeDescription.getShadowedResourceObject() != null) {
return changeDescription.getShadowedResourceObject().getOid(); // TODO
} else {
return null;
}
Expand All @@ -102,13 +102,9 @@ public int compareTo(@NotNull SyncItemProcessingRequest<SE> o) {
public @Nullable SynchronizationSituationType getSynchronizationSituationOnProcessingStart() {
ResourceObjectShadowChangeDescription changeDescription = item.getChangeDescription();
if (changeDescription != null) {
if (changeDescription.getOldShadow() != null) {
return changeDescription.getOldShadow().asObjectable().getSynchronizationSituation();
}
if (changeDescription.getCurrentShadow() != null) {
return changeDescription.getCurrentShadow().asObjectable().getSynchronizationSituation();
}
return changeDescription.getShadowedResourceObject().asObjectable().getSynchronizationSituation();
} else {
return null;
}
return null;
}
}
Expand Up @@ -128,7 +128,7 @@ private void handleObjectInternal(PrismObject<ShadowType> shadowObject, String i
} else {
// No change, therefore the delta stays null. But we will set the current
}
change.setCurrentShadow(shadowObject);
change.setShadowedResourceObject(shadowObject);

try {
change.checkConsistence();
Expand Down
Expand Up @@ -155,7 +155,7 @@ private void reactShadowGone(PrismObject<ShadowType> shadow, Task task, Operatio
ObjectDelta<ShadowType> shadowDelta = shadow.getPrismContext().deltaFactory().object()
.createDeleteDelta(ShadowType.class, shadow.getOid());
change.setObjectDelta(shadowDelta);
change.setCurrentShadow(shadow); // TODO why current shadow?!
change.setShadowedResourceObject(shadow);
ModelImplUtils.clearRequestee(task);
taskHandler.changeNotificationDispatcher.notifyChange(change, task, result);
}
Expand Down
Expand Up @@ -176,8 +176,7 @@ private void deleteShadow(PrismObject<ShadowType> shadow, Task workerTask, Opera
ResourceObjectShadowChangeDescription change = new ResourceObjectShadowChangeDescription();
change.setObjectDelta(shadow.createDeleteDelta());
change.setResource(ctx.resource);
change.setOldShadow(shadow);
change.setCurrentShadow(shadow); // TODO why?!
change.setShadowedResourceObject(shadow);
synchronizationService.notifyChange(change, workerTask, result);
}
}
Expand Down
Expand Up @@ -104,11 +104,11 @@ private OperationResult synchronizeShadow(ShadowType shadow, TriggerType trigger
.addParam("attemptNumber", getNumber(trigger))
.build();
try {
PrismObject<ShadowType> shadowizedResourceObject = provisioningService.getObject(ShadowType.class, shadowOid, null, task, result);
PrismObject<ResourceType> resource = getResource(shadowizedResourceObject, task, result);
PrismObject<ShadowType> shadowedResourceObject = provisioningService.getObject(ShadowType.class, shadowOid, null, task, result);
PrismObject<ResourceType> resource = getResource(shadowedResourceObject, task, result);

ResourceObjectShadowChangeDescription change = new ResourceObjectShadowChangeDescription();
change.setCurrentShadow(shadowizedResourceObject);
change.setShadowedResourceObject(shadowedResourceObject);
change.setResource(resource);
change.setSourceChannel(SchemaConstants.CHANNEL_RECON_URI); // to be reconsidered later

Expand Down

0 comments on commit 4b5b3de

Please sign in to comment.