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);
}
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();
}
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);
}
Aggregations