use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.
the class LensUtil method getProjectionContext.
public static <F extends FocusType> LensProjectionContext getProjectionContext(LensContext<F> context, String resourceOid, ShadowKindType kind, String intent, ProvisioningService provisioningService, PrismContext prismContext, Task task, OperationResult result) throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
ResourceType resource = getResourceReadOnly(context, resourceOid, provisioningService, task, result);
String refinedIntent = refineProjectionIntent(kind, intent, resource, prismContext);
ResourceShadowDiscriminator rsd = new ResourceShadowDiscriminator(resourceOid, kind, refinedIntent);
return context.findProjectionContext(rsd);
}
use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.
the class LensUtil method findLowerOrderContext.
public static <F extends ObjectType> LensProjectionContext findLowerOrderContext(LensContext<F> context, LensProjectionContext refProjCtx) {
int minOrder = -1;
LensProjectionContext foundCtx = null;
ResourceShadowDiscriminator refDiscr = refProjCtx.getResourceShadowDiscriminator();
for (LensProjectionContext aProjCtx : context.getProjectionContexts()) {
ResourceShadowDiscriminator aDiscr = aProjCtx.getResourceShadowDiscriminator();
if (refDiscr.equivalent(aDiscr) && (refDiscr.getOrder() > aDiscr.getOrder())) {
if (minOrder < 0 || (aDiscr.getOrder() < minOrder)) {
minOrder = aDiscr.getOrder();
foundCtx = aProjCtx;
}
}
}
return foundCtx;
}
use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.
the class SynchronizationServiceImpl method createLensContext.
@NotNull
private <F extends FocusType> LensContext<F> createLensContext(Class<F> focusClass, ResourceObjectShadowChangeDescription change, SynchronizationReactionType reactionDefinition, ObjectSynchronizationType synchronizationPolicy, SynchronizationSituation<F> situation, ModelExecuteOptions options, PrismObject<SystemConfigurationType> configuration, OperationResult parentResult) throws ObjectNotFoundException, SchemaException {
LensContext<F> context = contextFactory.createSyncContext(focusClass, change);
context.setLazyAuditRequest(true);
context.setSystemConfiguration(configuration);
context.setOptions(options);
ResourceType resource = change.getResource().asObjectable();
if (ModelExecuteOptions.isLimitPropagation(options)) {
context.setTriggeredResource(resource);
}
context.rememberResource(resource);
PrismObject<ShadowType> shadow = getShadowFromChange(change);
if (InternalsConfig.consistencyChecks)
shadow.checkConsistence();
// Projection context
ShadowKindType kind = getKind(shadow, synchronizationPolicy);
String intent = getIntent(shadow, synchronizationPolicy);
boolean thombstone = isThombstone(change);
ResourceShadowDiscriminator descr = new ResourceShadowDiscriminator(resource.getOid(), kind, intent, thombstone);
LensProjectionContext projectionContext = context.createProjectionContext(descr);
projectionContext.setResource(resource);
projectionContext.setOid(getOidFromChange(change));
projectionContext.setSynchronizationSituationDetected(situation.getSituation());
// insert object delta if available in change
ObjectDelta<? extends ShadowType> delta = change.getObjectDelta();
if (delta != null) {
projectionContext.setSyncDelta((ObjectDelta<ShadowType>) delta);
} else {
projectionContext.setSyncAbsoluteTrigger(true);
}
// we insert account if available in change
PrismObject<ShadowType> currentAccount = shadow;
if (currentAccount != null) {
projectionContext.setLoadedObject(currentAccount);
if (!thombstone) {
projectionContext.setFullShadow(true);
}
projectionContext.setFresh(true);
}
if (delta != null && delta.isDelete()) {
projectionContext.setExists(false);
} else {
projectionContext.setExists(true);
}
projectionContext.setDoReconciliation(ModelExecuteOptions.isReconcile(options));
// Focus context
if (situation.getCurrentOwner() != null) {
F focusType = situation.getCurrentOwner();
LensFocusContext<F> focusContext = context.createFocusContext();
PrismObject<F> focusOld = (PrismObject<F>) focusType.asPrismObject();
focusContext.setLoadedObject(focusOld);
}
// Global stuff
ObjectReferenceType objectTemplateRef = null;
if (reactionDefinition.getObjectTemplateRef() != null) {
objectTemplateRef = reactionDefinition.getObjectTemplateRef();
} else if (synchronizationPolicy.getObjectTemplateRef() != null) {
objectTemplateRef = synchronizationPolicy.getObjectTemplateRef();
}
if (objectTemplateRef != null) {
ObjectTemplateType objectTemplate = repositoryService.getObject(ObjectTemplateType.class, objectTemplateRef.getOid(), null, parentResult).asObjectable();
context.setFocusTemplate(objectTemplate);
}
return context;
}
use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.
the class LiveSyncTaskHandler method runInternal.
private TaskRunResult runInternal(Task task) {
LOGGER.trace("LiveSyncTaskHandler.run starting");
long progress = task.getProgress();
OperationResult opResult = new OperationResult(OperationConstants.LIVE_SYNC);
TaskRunResult runResult = new TaskRunResult();
runResult.setOperationResult(opResult);
String resourceOid = task.getObjectOid();
if (resourceOid == null) {
LOGGER.error("Live Sync: No resource OID specified in the task");
opResult.recordFatalError("No resource OID specified in the task");
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
}
ResourceType resource = null;
try {
resource = provisioningService.getObject(ResourceType.class, resourceOid, null, task, opResult).asObjectable();
} catch (ObjectNotFoundException ex) {
LOGGER.error("Live Sync: Resource {} not found: {}", new Object[] { resourceOid, ex.getMessage(), ex });
// This is bad. The resource does not exist. Permanent problem.
opResult.recordFatalError("Resource not found " + resourceOid, ex);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
} catch (SchemaException ex) {
LOGGER.error("Live Sync: Error dealing with schema: {}", ex.getMessage(), ex);
// Not sure about this. But most likely it is a misconfigured resource or connector
// It may be worth to retry. Error is fatal, but may not be permanent.
opResult.recordFatalError("Error dealing with schema: " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.TEMPORARY_ERROR);
return runResult;
} catch (RuntimeException ex) {
LOGGER.error("Live Sync: Internal Error: {}", ex.getMessage(), ex);
// Can be anything ... but we can't recover from that.
// It is most likely a programming error. Does not make much sense to retry.
opResult.recordFatalError("Internal Error: " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
} catch (CommunicationException ex) {
LOGGER.error("Live Sync: Error getting resource {}: {}", new Object[] { resourceOid, ex.getMessage(), ex });
opResult.recordFatalError("Error getting resource " + resourceOid + ": " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.TEMPORARY_ERROR);
return runResult;
} catch (ConfigurationException ex) {
LOGGER.error("Live Sync: Error getting resource {}: {}", new Object[] { resourceOid, ex.getMessage(), ex });
opResult.recordFatalError("Error getting resource " + resourceOid + ": " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
} catch (SecurityViolationException ex) {
LOGGER.error("Live Sync: Error getting resource {}: {}", new Object[] { resourceOid, ex.getMessage(), ex });
opResult.recordFatalError("Error getting resource " + resourceOid + ": " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
} catch (ExpressionEvaluationException ex) {
LOGGER.error("Live Sync: Error getting resource {}: {}", new Object[] { resourceOid, ex.getMessage(), ex });
opResult.recordFatalError("Error getting resource " + resourceOid + ": " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
}
if (resource == null) {
LOGGER.error("Live Sync: No resource specified");
opResult.recordFatalError("No resource specified");
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
}
RefinedResourceSchema refinedSchema;
try {
refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource, LayerType.MODEL, prismContext);
} catch (SchemaException e) {
LOGGER.error("Live Sync: Schema error during processing account definition: {}", e.getMessage());
opResult.recordFatalError("Schema error during processing account definition: " + e.getMessage(), e);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
}
if (refinedSchema == null) {
opResult.recordFatalError("No refined schema defined. Probably some configuration problem.");
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
LOGGER.error("Live Sync: No refined schema defined. Probably some configuration problem.");
return runResult;
}
ObjectClassComplexTypeDefinition objectClass;
try {
objectClass = Utils.determineObjectClass(refinedSchema, task);
} catch (SchemaException e) {
LOGGER.error("Live Sync: schema error: {}", e.getMessage());
opResult.recordFatalError(e);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
return runResult;
}
if (objectClass == null) {
LOGGER.debug("Syncing all object classes");
}
ResourceShadowDiscriminator coords = new ResourceShadowDiscriminator(resourceOid, objectClass == null ? null : objectClass.getTypeName());
int changesProcessed;
try {
// MAIN PART
// Calling synchronize(..) in provisioning.
// This will detect the changes and notify model about them.
// It will use extension of task to store synchronization state
Utils.clearRequestee(task);
changesProcessed = provisioningService.synchronize(coords, task, opResult);
progress += changesProcessed;
} catch (ObjectNotFoundException ex) {
LOGGER.error("Live Sync: A required object does not exist, OID: {}", ex.getOid());
LOGGER.error("Exception stack trace", ex);
// This is bad. The resource or task or something like that does not exist. Permanent problem.
opResult.recordFatalError("A required object does not exist, OID: " + ex.getOid(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
runResult.setProgress(progress);
return runResult;
} catch (CommunicationException ex) {
LOGGER.error("Live Sync: Communication error:", ex);
// Error, but not critical. Just try later.
opResult.recordPartialError("Communication error: " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.TEMPORARY_ERROR);
runResult.setProgress(progress);
return runResult;
} catch (SchemaException ex) {
LOGGER.error("Live Sync: Error dealing with schema:", ex);
// Not sure about this. But most likely it is a misconfigured resource or connector
// It may be worth to retry. Error is fatal, but may not be permanent.
opResult.recordFatalError("Error dealing with schema: " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.TEMPORARY_ERROR);
runResult.setProgress(progress);
return runResult;
} catch (RuntimeException ex) {
LOGGER.error("Live Sync: Internal Error:", ex);
// Can be anything ... but we can't recover from that.
// It is most likely a programming error. Does not make much sense to retry.
opResult.recordFatalError("Internal Error: " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
runResult.setProgress(progress);
return runResult;
} catch (ConfigurationException ex) {
LOGGER.error("Live Sync: Configuration error:", ex);
// Not sure about this. But most likely it is a misconfigured resource or connector
// It may be worth to retry. Error is fatal, but may not be permanent.
opResult.recordFatalError("Configuration error: " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.TEMPORARY_ERROR);
runResult.setProgress(progress);
return runResult;
} catch (SecurityViolationException ex) {
LOGGER.error("Recompute: Security violation: {}", ex.getMessage(), ex);
opResult.recordFatalError("Security violation: " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
runResult.setProgress(progress);
return runResult;
} catch (ExpressionEvaluationException ex) {
LOGGER.error("Recompute: Expression error: {}", ex.getMessage(), ex);
opResult.recordFatalError("Expression error: " + ex.getMessage(), ex);
runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
runResult.setProgress(progress);
return runResult;
}
opResult.computeStatus("Live sync run has failed");
opResult.createSubresult(OperationConstants.LIVE_SYNC_STATISTICS).recordStatus(OperationResultStatus.SUCCESS, "Changes processed: " + changesProcessed);
// This "run" is finished. But the task goes on ...
runResult.setRunResultStatus(TaskRunResultStatus.FINISHED);
// Might collide with increasing progress in provisioning module, e.g. when an exception is thrown. But that's OK for now.
runResult.setProgress(progress);
LOGGER.trace("LiveSyncTaskHandler.run stopping (resource {})", resourceOid);
return runResult;
}
use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.
the class TestSynchronizationService method test199DeletedAccountJackTotal.
/**
* Delete the account but also the shadow in the repo. The system should work well.
*/
@Test
public void test199DeletedAccountJackTotal() throws Exception {
final String TEST_NAME = "test199DeletedAccountJackTotal";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestSynchronizationService.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
MockLensDebugListener mockListener = new MockLensDebugListener();
clockwork.setDebugListener(mockListener);
getDummyResource().deleteAccountByName(ACCOUNT_JACK_DUMMY_USERNAME);
PrismObject<ShadowType> shadow = getShadowModelNoFetch(accountShadowJackDummyOid);
ResourceObjectShadowChangeDescription change = new ResourceObjectShadowChangeDescription();
change.setCurrentShadow(shadow);
change.setResource(getDummyResourceObject());
ObjectDelta<ShadowType> syncDelta = ObjectDelta.createDeleteDelta(ShadowType.class, accountShadowJackDummyOid, prismContext);
change.setObjectDelta(syncDelta);
repositoryService.deleteObject(ShadowType.class, accountShadowJackDummyOid, result);
// WHEN
synchronizationService.notifyChange(change, task, result);
// THEN
LensContext<UserType> context = mockListener.getLastSyncContext();
display("Resulting context (as seen by debug listener)", context);
assertNotNull("No resulting context (as seen by debug listener)", context);
assertNotNull("No focus context", context.getFocusContext());
assertNull("Unexpected user primary delta", context.getFocusContext().getPrimaryDelta());
assertSideEffectiveDeltasOnly("user secondary delta", context.getFocusContext().getSecondaryDelta());
ResourceShadowDiscriminator rat = new ResourceShadowDiscriminator(getDummyResourceObject().getOid(), ShadowKindType.ACCOUNT, null, true);
LensProjectionContext accCtx = context.findProjectionContext(rat);
assertNotNull("No account sync context for " + rat, accCtx);
assertEquals("Wrong detected situation in context", SynchronizationSituationType.DELETED, accCtx.getSynchronizationSituationDetected());
PrismAsserts.assertNoDelta("Unexpected account primary delta", accCtx.getPrimaryDelta());
assertNotLinked(context.getFocusContext().getObjectOld().getOid(), accountShadowJackDummyOid);
PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
assertLinks(userAfter, 0);
result.computeStatus();
display("Final result", result);
TestUtil.assertSuccess(result, 1);
assertNoObject(ShadowType.class, accountShadowJackDummyOid, task, result);
}
Aggregations