Search in sources :

Example 26 with ResourceShadowDiscriminator

use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.

the class TestSynchronizationService method test010AddedAccountJack.

@Test
public void test010AddedAccountJack() throws Exception {
    final String TEST_NAME = "test010AddedAccountJack";
    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);
    PrismObject<ShadowType> accountShadowJack = repoAddObjectFromFile(ACCOUNT_SHADOW_JACK_DUMMY_FILE, result);
    accountShadowJackDummyOid = accountShadowJack.getOid();
    provisioningService.applyDefinition(accountShadowJack, task, result);
    assertNotNull("No oid in shadow", accountShadowJack.getOid());
    DummyAccount dummyAccount = new DummyAccount();
    dummyAccount.setName(ACCOUNT_JACK_DUMMY_USERNAME);
    dummyAccount.setPassword("deadMenTellNoTales");
    dummyAccount.setEnabled(true);
    dummyAccount.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Jack Sparrow");
    getDummyResource().addAccount(dummyAccount);
    ResourceObjectShadowChangeDescription change = new ResourceObjectShadowChangeDescription();
    change.setCurrentShadow(accountShadowJack);
    change.setResource(getDummyResourceObject());
    // 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);
    assertNull("Unexpected user primary delta", context.getFocusContext().getPrimaryDelta());
    assertSideEffectiveDeltasOnly(context.getFocusContext().getSecondaryDelta(), "user secondary delta", ActivationStatusType.ENABLED);
    ResourceShadowDiscriminator rat = new ResourceShadowDiscriminator(getDummyResourceObject().getOid(), ShadowKindType.ACCOUNT, null);
    LensProjectionContext accCtx = context.findProjectionContext(rat);
    assertNotNull("No account sync context for " + rat, accCtx);
    assertEquals("Wrong detected situation in context", SynchronizationSituationType.UNLINKED, accCtx.getSynchronizationSituationDetected());
    assertEquals("Wrong resolved situation in context", SynchronizationSituationType.LINKED, accCtx.getSynchronizationSituationResolved());
    PrismAsserts.assertNoDelta("Unexpected account primary delta", accCtx.getPrimaryDelta());
    //it this really expected?? delta was already executed, should we expect it in the secondary delta?
    //		assertNotNull("Missing account secondary delta", accCtx.getSecondaryDelta());
    //		assertIterationDelta(accCtx.getSecondaryDelta(), 0, "");
    assertLinked(context.getFocusContext().getObjectOld().getOid(), accountShadowJack.getOid());
    PrismObject<ShadowType> shadow = getShadowModelNoFetch(accountShadowJackDummyOid);
    assertIteration(shadow, 0, "");
    assertSituation(shadow, SynchronizationSituationType.LINKED);
    result.computeStatus();
    TestUtil.assertSuccess(result);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) MockLensDebugListener(com.evolveum.midpoint.model.impl.util.mock.MockLensDebugListener) ResourceObjectShadowChangeDescription(com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Example 27 with ResourceShadowDiscriminator

use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.

the class WfPrepareRootOperationTaskHandler method run.

//endregion
//region run method
@Override
public TaskRunResult run(Task task) {
    TaskRunResultStatus status = TaskRunResultStatus.FINISHED;
    try {
        OperationResult result = task.getResult();
        WfTask rootWfTask = wfTaskController.recreateRootWfTask(task);
        List<WfTask> children = rootWfTask.listChildren(result);
        LensContext rootContext = (LensContext) rootWfTask.retrieveModelContext(result);
        boolean changed = false;
        for (WfTask child : children) {
            if (child.getTaskExecutionStatus() != TaskExecutionStatus.CLOSED) {
                throw new IllegalStateException("Child task " + child + " is not in CLOSED state; its state is " + child.getTaskExecutionStatus());
            }
            if (child.hasModelContext()) {
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Child job {} has model context present - skipping fetching deltas from it.", child);
                }
            } else {
                ObjectTreeDeltas deltas = child.retrieveResultingDeltas();
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Child job {} returned {} deltas", child, deltas != null ? deltas.getDeltaList().size() : 0);
                }
                if (deltas != null) {
                    LensFocusContext focusContext = rootContext.getFocusContext();
                    ObjectDelta focusDelta = deltas.getFocusChange();
                    if (focusDelta != null) {
                        if (LOGGER.isTraceEnabled()) {
                            LOGGER.trace("Adding delta from job {} to root model context; delta = {}", child, focusDelta.debugDump(0));
                        }
                        if (focusContext.getPrimaryDelta() != null && !focusContext.getPrimaryDelta().isEmpty()) {
                            focusContext.addPrimaryDelta(focusDelta);
                        } else {
                            focusContext.setPrimaryDelta(focusDelta);
                        }
                        changed = true;
                    }
                    Set<Map.Entry<ResourceShadowDiscriminator, ObjectDelta<ShadowType>>> entries = deltas.getProjectionChangeMapEntries();
                    for (Map.Entry<ResourceShadowDiscriminator, ObjectDelta<ShadowType>> entry : entries) {
                        if (LOGGER.isTraceEnabled()) {
                            LOGGER.trace("Adding projection delta from job {} to root model context; rsd = {}, delta = {}", child, entry.getKey(), entry.getValue().debugDump());
                        }
                        ModelProjectionContext projectionContext = rootContext.findProjectionContext(entry.getKey());
                        if (projectionContext == null) {
                            // TODO more liberal treatment?
                            throw new IllegalStateException("No projection context for " + entry.getKey());
                        }
                        if (projectionContext.getPrimaryDelta() != null && !projectionContext.getPrimaryDelta().isEmpty()) {
                            projectionContext.addPrimaryDelta(entry.getValue());
                        } else {
                            projectionContext.setPrimaryDelta(entry.getValue());
                        }
                        changed = true;
                    }
                }
            }
        }
        if (!rootContext.hasAnyPrimaryChange()) {
            // deletes the model context
            rootContext = null;
            // regardless of whether rootContext was changed or not
            changed = true;
        }
        if (changed) {
            rootWfTask.storeModelContext(rootContext);
            rootWfTask.commitChanges(result);
        }
    } catch (SchemaException | ObjectNotFoundException | ObjectAlreadyExistsException | ConfigurationException | ExpressionEvaluationException e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't aggregate resulting deltas from child workflow-monitoring tasks due to schema exception", e);
        status = TaskRunResultStatus.PERMANENT_ERROR;
    } catch (CommunicationException e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't aggregate resulting deltas from child workflow-monitoring tasks", e);
        status = TaskRunResultStatus.TEMPORARY_ERROR;
    }
    TaskRunResult runResult = new TaskRunResult();
    runResult.setRunResultStatus(status);
    return runResult;
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ModelProjectionContext(com.evolveum.midpoint.model.api.context.ModelProjectionContext) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ObjectTreeDeltas(com.evolveum.midpoint.schema.ObjectTreeDeltas) TaskRunResultStatus(com.evolveum.midpoint.task.api.TaskRunResult.TaskRunResultStatus) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) WfTask(com.evolveum.midpoint.wf.impl.tasks.WfTask) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) LensFocusContext(com.evolveum.midpoint.model.impl.lens.LensFocusContext) Map(java.util.Map)

Example 28 with ResourceShadowDiscriminator

use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.

the class PrimaryChangeProcessor method contextCopyWithDeltasReplaced.

private LensContext contextCopyWithDeltasReplaced(ModelContext context, ObjectTreeDeltas changes) throws SchemaException {
    Validate.notNull(changes, "changes");
    LensContext contextCopy = ((LensContext) context).clone();
    contextCopy.replacePrimaryFocusDelta(changes.getFocusChange());
    Map<ResourceShadowDiscriminator, ObjectDelta<ShadowType>> changeMap = changes.getProjectionChangeMap();
    Collection<ModelProjectionContext> projectionContexts = contextCopy.getProjectionContexts();
    for (ModelProjectionContext projectionContext : projectionContexts) {
        ObjectDelta<ShadowType> projectionDelta = changeMap.get(projectionContext.getResourceShadowDiscriminator());
        projectionContext.setPrimaryDelta(projectionDelta);
    }
    return contextCopy;
}
Also used : ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) ModelProjectionContext(com.evolveum.midpoint.model.api.context.ModelProjectionContext) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 29 with ResourceShadowDiscriminator

use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.

the class WfPrepareChildOperationTaskHandler method run.

//endregion
//region Body
@SuppressWarnings("unchecked")
@Override
public TaskRunResult run(Task task) {
    TaskRunResult.TaskRunResultStatus status = TaskRunResult.TaskRunResultStatus.FINISHED;
    LOGGER.trace("WfPrepareChildOperationTaskHandler starting... task = {}", task);
    try {
        WfTask wfTask = wfTaskController.recreateWfTask(task);
        OperationResult result = task.getResult();
        ModelContext<?> modelContext = wfTask.retrieveModelContext(result);
        if (modelContext == null) {
            throw new IllegalStateException("There's no model context in child task; task = " + task);
        }
        // prepare deltaOut to be used
        ObjectTreeDeltas deltasOut = wfTask.retrieveResultingDeltas();
        if (LOGGER.isTraceEnabled()) {
            dumpDeltaOut(deltasOut);
        }
        if (deltasOut == null || deltasOut.isEmpty()) {
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("There's no primary delta in focus context; we'll delete model operation context. Task = {}, model context:\n{}", task, modelContext.debugDump());
            }
            wfTask.deleteModelOperationContext();
        } else {
            // place deltaOut into model context
            modelContext.getFocusContext().setPrimaryDelta(deltasOut.getFocusChange());
            Set<Map.Entry<ResourceShadowDiscriminator, ObjectDelta<ShadowType>>> entries = deltasOut.getProjectionChangeMapEntries();
            for (Map.Entry<ResourceShadowDiscriminator, ObjectDelta<ShadowType>> entry : entries) {
                // TODO what if projection context does not exist?
                modelContext.findProjectionContext(entry.getKey()).setPrimaryDelta(entry.getValue());
            }
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Resulting model context to be stored into task {}:\n{}", task, modelContext.debugDump(0));
            }
            wfTask.storeModelContext(modelContext);
        }
        task.savePendingModifications(result);
    } catch (SchemaException | ObjectNotFoundException | ObjectAlreadyExistsException | ConfigurationException | ExpressionEvaluationException | RuntimeException | Error e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't prepare child model context", e);
        status = TaskRunResult.TaskRunResultStatus.PERMANENT_ERROR;
    } catch (CommunicationException e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't prepare child model context", e);
        status = TaskRunResult.TaskRunResultStatus.TEMPORARY_ERROR;
    }
    TaskRunResult runResult = new TaskRunResult();
    runResult.setRunResultStatus(status);
    return runResult;
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) WfTask(com.evolveum.midpoint.wf.impl.tasks.WfTask) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Map(java.util.Map) ObjectTreeDeltas(com.evolveum.midpoint.schema.ObjectTreeDeltas)

Example 30 with ResourceShadowDiscriminator

use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.

the class TestSynchronizationService method test210AddedGroupPirates.

@Test
public void test210AddedGroupPirates() throws Exception {
    final String TEST_NAME = "test210AddedGroupPirates";
    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);
    PrismObject<ShadowType> shadowPirates = repoAddObjectFromFile(SHADOW_PIRATES_DUMMY_FILE, result);
    provisioningService.applyDefinition(shadowPirates, task, result);
    assertNotNull("No oid in shadow", shadowPirates.getOid());
    DummyGroup dummyGroup = new DummyGroup();
    dummyGroup.setName(GROUP_PIRATES_DUMMY_NAME);
    dummyGroup.setEnabled(true);
    dummyGroup.addAttributeValues(DummyResourceContoller.DUMMY_GROUP_ATTRIBUTE_DESCRIPTION, "Scurvy Pirates");
    getDummyResource().addGroup(dummyGroup);
    ResourceObjectShadowChangeDescription change = new ResourceObjectShadowChangeDescription();
    change.setCurrentShadow(shadowPirates);
    change.setResource(getDummyResourceObject());
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    synchronizationService.notifyChange(change, task, result);
    // THEN
    TestUtil.displayWhen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    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 primary delta", context.getFocusContext().getPrimaryDelta());
    //        assertNotNull("No focus secondary delta", context.getFocusContext().getSecondaryDelta());
    assertFalse("No executed focus deltas", context.getFocusContext().getExecutedDeltas().isEmpty());
    ObjectDelta<UserType> userSecondaryDelta = (ObjectDelta<UserType>) context.getFocusContext().getExecutedDeltas().iterator().next().getObjectDelta();
    ResourceShadowDiscriminator rat = new ResourceShadowDiscriminator(getDummyResourceObject().getOid(), ShadowKindType.ENTITLEMENT, INTENT_GROUP);
    LensProjectionContext projCtx = context.findProjectionContext(rat);
    assertNotNull("No projection sync context for " + rat, projCtx);
    assertEquals("Wrong detected situation in context", SynchronizationSituationType.UNMATCHED, projCtx.getSynchronizationSituationDetected());
    assertEquals("Wrong resolved situation in context", SynchronizationSituationType.LINKED, projCtx.getSynchronizationSituationResolved());
    PrismAsserts.assertNoDelta("Unexpected projection primary delta", projCtx.getPrimaryDelta());
    //it this really expected?? delta was already executed, should we expect it in the secondary delta?
    //		assertNotNull("Missing account secondary delta", accCtx.getSecondaryDelta());
    //		assertIterationDelta(accCtx.getSecondaryDelta(), 0, "");
    assertLinked(RoleType.class, context.getFocusContext().getOid(), shadowPirates.getOid());
    PrismObject<ShadowType> shadow = getShadowModelNoFetch(shadowPirates.getOid());
    assertIteration(shadow, 0, "");
    assertSituation(shadow, SynchronizationSituationType.LINKED);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) MockLensDebugListener(com.evolveum.midpoint.model.impl.util.mock.MockLensDebugListener) ResourceObjectShadowChangeDescription(com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) DummyGroup(com.evolveum.icf.dummy.resource.DummyGroup) Test(org.testng.annotations.Test) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Aggregations

ResourceShadowDiscriminator (com.evolveum.midpoint.schema.ResourceShadowDiscriminator)78 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)41 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)34 Task (com.evolveum.midpoint.task.api.Task)30 Test (org.testng.annotations.Test)30 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)28 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)18 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)17 ResourceObjectShadowChangeDescription (com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription)17 ModelProjectionContext (com.evolveum.midpoint.model.api.context.ModelProjectionContext)11 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)10 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)10 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)9 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)9 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)9 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)8 MockLensDebugListener (com.evolveum.midpoint.model.impl.util.mock.MockLensDebugListener)8 PrismObject (com.evolveum.midpoint.prism.PrismObject)8 QName (javax.xml.namespace.QName)7 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)6