Search in sources :

Example 1 with ProvisioningOperationState

use of com.evolveum.midpoint.provisioning.impl.ProvisioningOperationState in project midpoint by Evolveum.

the class AddHelper method addResourceObject.

String addResourceObject(@NotNull PrismObject<ShadowType> resourceObjectToAdd, OperationProvisioningScriptsType scripts, ProvisioningOperationOptions options, @NotNull Task task, @NotNull OperationResult result) throws CommunicationException, GenericFrameworkException, ObjectAlreadyExistsException, SchemaException, ObjectNotFoundException, ConfigurationException, SecurityViolationException, PolicyViolationException, ExpressionEvaluationException, EncryptionException {
    InternalMonitor.recordCount(InternalCounters.SHADOW_CHANGE_OPERATION_COUNT);
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Start adding shadow object{}:\n{}", getAdditionalOperationDesc(scripts, options), resourceObjectToAdd.debugDump(1));
    }
    ResourceType resource = ctxFactory.getResource(resourceObjectToAdd, task, result);
    ProvisioningContext ctx;
    try {
        ctx = ctxFactory.createForShadow(resourceObjectToAdd, resource, task);
        ctx.assertDefinition();
    } catch (SchemaException e) {
        result.recordFatalErrorNotFinish(e);
        ResourceOperationDescription operationDescription = ProvisioningUtil.createResourceFailureDescription(resourceObjectToAdd, resource, resourceObjectToAdd.createAddDelta(), result);
        eventDispatcher.notifyFailure(operationDescription, task, result);
        throw e;
    }
    ProvisioningOperationState<AsynchronousOperationReturnValue<PrismObject<ShadowType>>> opState = new ProvisioningOperationState<>();
    return addShadowAttempt(ctx, resourceObjectToAdd, scripts, opState, options, task, result);
}
Also used : ProvisioningContext(com.evolveum.midpoint.provisioning.impl.ProvisioningContext) AsynchronousOperationReturnValue(com.evolveum.midpoint.schema.result.AsynchronousOperationReturnValue) ResourceOperationDescription(com.evolveum.midpoint.provisioning.api.ResourceOperationDescription) ProvisioningOperationState(com.evolveum.midpoint.provisioning.impl.ProvisioningOperationState)

Example 2 with ProvisioningOperationState

use of com.evolveum.midpoint.provisioning.impl.ProvisioningOperationState in project midpoint by Evolveum.

the class PropagateHelper method propagateOperations.

public void propagateOperations(PrismObject<ResourceType> resource, PrismObject<ShadowType> shadow, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException, GenericFrameworkException, ObjectAlreadyExistsException, SecurityViolationException, PolicyViolationException, EncryptionException {
    ResourceConsistencyType resourceConsistencyType = resource.asObjectable().getConsistency();
    if (resourceConsistencyType == null) {
        LOGGER.warn("Skipping propagation of {} because no there is no consistency definition in resource", shadow);
        return;
    }
    Duration operationGroupingInterval = resourceConsistencyType.getOperationGroupingInterval();
    if (operationGroupingInterval == null) {
        LOGGER.warn("Skipping propagation of {} because no there is no operationGroupingInterval defined in resource", shadow);
        return;
    }
    XMLGregorianCalendar now = clock.currentTimeXMLGregorianCalendar();
    List<PendingOperationType> pendingExecutionOperations = new ArrayList<>();
    boolean triggered = false;
    for (PendingOperationType pendingOperation : shadow.asObjectable().getPendingOperation()) {
        PendingOperationExecutionStatusType executionStatus = pendingOperation.getExecutionStatus();
        if (executionStatus == PendingOperationExecutionStatusType.EXECUTION_PENDING) {
            pendingExecutionOperations.add(pendingOperation);
            if (isPropagationTriggered(pendingOperation, operationGroupingInterval, now)) {
                triggered = true;
            }
        }
    }
    if (!triggered) {
        LOGGER.debug("Skipping propagation of {} because no pending operation triggered propagation", shadow);
        return;
    }
    if (pendingExecutionOperations.isEmpty()) {
        LOGGER.debug("Skipping propagation of {} because there are no pending executions", shadow);
        return;
    }
    LOGGER.debug("Propagating {} pending operations in {} ", pendingExecutionOperations.size(), shadow);
    ObjectDelta<ShadowType> operationDelta = null;
    List<PendingOperationType> sortedOperations = shadowCaretaker.sortPendingOperations(pendingExecutionOperations);
    for (PendingOperationType pendingOperation : sortedOperations) {
        ObjectDeltaType pendingDeltaType = pendingOperation.getDelta();
        ObjectDelta<ShadowType> pendingDelta = DeltaConvertor.createObjectDelta(pendingDeltaType, prismContext);
        definitionsHelper.applyDefinition(pendingDelta, shadow.asObjectable(), task, result);
        if (operationDelta == null) {
            operationDelta = pendingDelta;
        } else {
            operationDelta.merge(pendingDelta);
        }
    }
    // there is at least one pending operation
    assert operationDelta != null;
    ProvisioningContext ctx = ctxFactory.createForShadow(shadow, task, result);
    ctx.setPropagation(true);
    shadowCaretaker.applyAttributesDefinition(ctx, shadow);
    shadowCaretaker.applyAttributesDefinition(ctx, operationDelta);
    LOGGER.trace("Merged operation for {}:\n{} ", shadow, operationDelta.debugDumpLazily(1));
    if (operationDelta.isAdd()) {
        PrismObject<ShadowType> shadowToAdd = operationDelta.getObjectToAdd();
        ProvisioningOperationState<AsynchronousOperationReturnValue<PrismObject<ShadowType>>> opState = ProvisioningOperationState.fromPendingOperations(shadow, sortedOperations);
        shadowToAdd.setOid(shadow.getOid());
        addHelper.addShadowAttempt(ctx, shadowToAdd, null, opState, null, task, result);
        opState.determineExecutionStatusFromResult();
        shadowManager.updatePendingOperations(ctx, shadow, opState, pendingExecutionOperations, now, result);
        addHelper.notifyAfterAdd(ctx, opState.getAsyncResult().getReturnValue(), opState, task, result);
    } else if (operationDelta.isModify()) {
        Collection<? extends ItemDelta<?, ?>> modifications = operationDelta.getModifications();
        ProvisioningOperationState<AsynchronousOperationReturnValue<Collection<PropertyDelta<PrismPropertyValue>>>> opState = modifyHelper.executeResourceModify(ctx, shadow, modifications, null, null, now, task, result);
        opState.determineExecutionStatusFromResult();
        shadowManager.updatePendingOperations(ctx, shadow, opState, pendingExecutionOperations, now, result);
        modifyHelper.notifyAfterModify(ctx, shadow, modifications, opState, task, result);
    } else if (operationDelta.isDelete()) {
        ProvisioningOperationState<AsynchronousOperationResult> opState = deleteHelper.executeResourceDelete(ctx, shadow, null, null, task, result);
        opState.determineExecutionStatusFromResult();
        shadowManager.updatePendingOperations(ctx, shadow, opState, pendingExecutionOperations, now, result);
        deleteHelper.notifyAfterDelete(ctx, shadow, opState, task, result);
    } else {
        throw new IllegalStateException("Delta from outer space: " + operationDelta);
    }
// do we need to modify exists/dead flags?
}
Also used : ArrayList(java.util.ArrayList) AsynchronousOperationReturnValue(com.evolveum.midpoint.schema.result.AsynchronousOperationReturnValue) Duration(javax.xml.datatype.Duration) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ProvisioningContext(com.evolveum.midpoint.provisioning.impl.ProvisioningContext) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult) Collection(java.util.Collection) ProvisioningOperationState(com.evolveum.midpoint.provisioning.impl.ProvisioningOperationState) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Aggregations

ProvisioningContext (com.evolveum.midpoint.provisioning.impl.ProvisioningContext)2 ProvisioningOperationState (com.evolveum.midpoint.provisioning.impl.ProvisioningOperationState)2 AsynchronousOperationReturnValue (com.evolveum.midpoint.schema.result.AsynchronousOperationReturnValue)2 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)1 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)1 ResourceOperationDescription (com.evolveum.midpoint.provisioning.api.ResourceOperationDescription)1 AsynchronousOperationResult (com.evolveum.midpoint.schema.result.AsynchronousOperationResult)1 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Duration (javax.xml.datatype.Duration)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1