Search in sources :

Example 1 with ResourceShadowCoordinates

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

the class AsyncUpdater method processAsynchronousUpdates.

public void processAsynchronousUpdates(ResourceShadowCoordinates shadowCoordinates, AsyncUpdateEventHandler handler, Task callerTask, OperationResult callerResult) throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException, ExpressionEvaluationException {
    InternalMonitor.recordCount(InternalCounters.PROVISIONING_ALL_EXT_OPERATION_COUNT);
    ProvisioningContext globalContext = ctxFactory.createForCoordinates(shadowCoordinates, callerTask, callerResult);
    // This is a bit of hack to propagate information about async update channel to upper layers
    // e.g. to implement MID-5853. TODO fix this hack
    globalContext.setChannelOverride(SchemaConstants.CHANNEL_ASYNC_UPDATE_URI);
    IndividualEventsAcknowledgeGate<AsyncUpdateEvent> acknowledgeGate = new IndividualEventsAcknowledgeGate<>();
    ResourceObjectAsyncChangeListener listener = (resourceObjectChange, lTask, lResult) -> {
        ShadowedAsyncChange change = new ShadowedAsyncChange(resourceObjectChange, changeProcessingBeans);
        change.initialize(lTask, lResult);
        AsyncUpdateEvent event = new AsyncUpdateEventImpl(change) {

            @Override
            public void acknowledge(boolean release, OperationResult result) {
                LOGGER.trace("Acknowledgement (release={}) sent for {}", release, this);
                change.acknowledge(release, result);
                acknowledgeGate.acknowledgeIssuedEvent(this);
            }
        };
        acknowledgeGate.registerIssuedEvent(event);
        try {
            handler.handle(event, lResult);
        } catch (Throwable t) {
            LoggingUtils.logUnexpectedException(LOGGER, "Got unexpected exception while handling an async update event", t);
            acknowledgeGate.acknowledgeIssuedEvent(event);
        }
    };
    resourceObjectConverter.listenForAsynchronousUpdates(globalContext, listener, callerResult);
    // There may be some events in processing - for example, if the async update task is suspended while
    // receiving a lot of events.
    acknowledgeGate.waitForIssuedEventsAcknowledge(callerResult);
}
Also used : ProvisioningContext(com.evolveum.midpoint.provisioning.impl.ProvisioningContext) ProvisioningContextFactory(com.evolveum.midpoint.provisioning.impl.ProvisioningContextFactory) ShadowedAsyncChange(com.evolveum.midpoint.provisioning.impl.shadows.ShadowedAsyncChange) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) ResourceObjectAsyncChangeListener(com.evolveum.midpoint.provisioning.impl.resourceobjects.ResourceObjectAsyncChangeListener) Trace(com.evolveum.midpoint.util.logging.Trace) InternalMonitor(com.evolveum.midpoint.schema.internals.InternalMonitor) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) Task(com.evolveum.midpoint.task.api.Task) LoggingUtils(com.evolveum.midpoint.util.logging.LoggingUtils) ProvisioningContext(com.evolveum.midpoint.provisioning.impl.ProvisioningContext) Component(org.springframework.stereotype.Component) ResourceObjectConverter(com.evolveum.midpoint.provisioning.impl.resourceobjects.ResourceObjectConverter) ResourceShadowCoordinates(com.evolveum.midpoint.schema.ResourceShadowCoordinates) AsyncUpdateEvent(com.evolveum.midpoint.provisioning.api.AsyncUpdateEvent) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) AsyncUpdateEventHandler(com.evolveum.midpoint.provisioning.api.AsyncUpdateEventHandler) InternalCounters(com.evolveum.midpoint.schema.internals.InternalCounters) ResourceObjectAsyncChangeListener(com.evolveum.midpoint.provisioning.impl.resourceobjects.ResourceObjectAsyncChangeListener) ShadowedAsyncChange(com.evolveum.midpoint.provisioning.impl.shadows.ShadowedAsyncChange) AsyncUpdateEvent(com.evolveum.midpoint.provisioning.api.AsyncUpdateEvent) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 2 with ResourceShadowCoordinates

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

the class TestAsyncUpdate method test100ListeningForShadowAdd.

@Test
public void test100ListeningForShadowAdd() throws Exception {
    Task task = getTestTask();
    OperationResult result = getTestOperationResult();
    // GIVEN
    prepareMessage(CHANGE_100);
    syncServiceMock.reset();
    addDummyAccount("banderson");
    ResourceShadowCoordinates coords = new ResourceShadowCoordinates(RESOURCE_ASYNC_OID);
    mockAsyncUpdateTaskHandler.processUpdates(coords, task, result);
    ResourceObjectShadowChangeDescription lastChange = syncServiceMock.getLastChange();
    assertNotNull("No last change", lastChange);
    displayDumpable("The change", lastChange);
    assertNotNull("Delta is missing", lastChange.getObjectDelta());
    assertNotNull("Current shadow is not present", lastChange.getShadowedResourceObject());
    PrismObject<ShadowType> accountRepo = findAccountShadowByUsername("banderson", resource, result);
    assertNotNull("Shadow was not created in the repository", accountRepo);
    display("Repository shadow", accountRepo);
    checkRepoAccountShadow(accountRepo);
    assertNoUnacknowledgedMessages();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ResourceObjectShadowChangeDescription(com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceShadowCoordinates(com.evolveum.midpoint.schema.ResourceShadowCoordinates) Test(org.testng.annotations.Test) AbstractProvisioningIntegrationTest(com.evolveum.midpoint.provisioning.impl.AbstractProvisioningIntegrationTest)

Example 3 with ResourceShadowCoordinates

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

the class DefinitionsHelper method applyDefinition.

public void applyDefinition(ObjectDelta<ShadowType> delta, @Nullable ShadowType repoShadow, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    PrismObject<ShadowType> shadow = null;
    ResourceShadowCoordinates coordinates = null;
    if (delta.isAdd()) {
        shadow = delta.getObjectToAdd();
    } else if (delta.isModify()) {
        if (delta instanceof ShadowCoordinatesQualifiedObjectDelta) {
            // This one does not have OID, it has to be specially processed
            coordinates = ((ShadowCoordinatesQualifiedObjectDelta<?>) delta).getCoordinates();
        } else {
            String shadowOid = delta.getOid();
            if (shadowOid == null) {
                if (repoShadow == null) {
                    throw new IllegalArgumentException("No OID in object delta " + delta + " and no externally-supplied shadow is present as well.");
                }
                shadow = repoShadow.asPrismObject();
            } else {
                // TODO consider fetching only when really necessary
                shadow = repositoryService.getObject(delta.getObjectTypeClass(), shadowOid, null, result);
            }
        }
    } else {
        // Delete delta, nothing to do at all
        return;
    }
    ProvisioningContext ctx;
    if (shadow == null) {
        stateCheck(coordinates != null, "No shadow nor coordinates");
        ctx = ctxFactory.createForCoordinates(coordinates, task, result);
    } else {
        ctx = ctxFactory.createForShadow(shadow, task, result);
    }
    shadowCaretaker.applyAttributesDefinition(ctx, delta);
}
Also used : ProvisioningContext(com.evolveum.midpoint.provisioning.impl.ProvisioningContext) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ShadowCoordinatesQualifiedObjectDelta(com.evolveum.midpoint.schema.processor.ShadowCoordinatesQualifiedObjectDelta) ResourceShadowCoordinates(com.evolveum.midpoint.schema.ResourceShadowCoordinates)

Aggregations

ResourceShadowCoordinates (com.evolveum.midpoint.schema.ResourceShadowCoordinates)3 ProvisioningContext (com.evolveum.midpoint.provisioning.impl.ProvisioningContext)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 Task (com.evolveum.midpoint.task.api.Task)2 AsyncUpdateEvent (com.evolveum.midpoint.provisioning.api.AsyncUpdateEvent)1 AsyncUpdateEventHandler (com.evolveum.midpoint.provisioning.api.AsyncUpdateEventHandler)1 ResourceObjectShadowChangeDescription (com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription)1 AbstractProvisioningIntegrationTest (com.evolveum.midpoint.provisioning.impl.AbstractProvisioningIntegrationTest)1 ProvisioningContextFactory (com.evolveum.midpoint.provisioning.impl.ProvisioningContextFactory)1 ResourceObjectAsyncChangeListener (com.evolveum.midpoint.provisioning.impl.resourceobjects.ResourceObjectAsyncChangeListener)1 ResourceObjectConverter (com.evolveum.midpoint.provisioning.impl.resourceobjects.ResourceObjectConverter)1 ShadowedAsyncChange (com.evolveum.midpoint.provisioning.impl.shadows.ShadowedAsyncChange)1 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)1 InternalCounters (com.evolveum.midpoint.schema.internals.InternalCounters)1 InternalMonitor (com.evolveum.midpoint.schema.internals.InternalMonitor)1 ShadowCoordinatesQualifiedObjectDelta (com.evolveum.midpoint.schema.processor.ShadowCoordinatesQualifiedObjectDelta)1 com.evolveum.midpoint.util.exception (com.evolveum.midpoint.util.exception)1 LoggingUtils (com.evolveum.midpoint.util.logging.LoggingUtils)1 Trace (com.evolveum.midpoint.util.logging.Trace)1 TraceManager (com.evolveum.midpoint.util.logging.TraceManager)1