Search in sources :

Example 6 with ProvisioningOperationOptions

use of com.evolveum.midpoint.provisioning.api.ProvisioningOperationOptions in project midpoint by Evolveum.

the class DeltaExecution method modifyProvisioningObject.

private String modifyProvisioningObject(OperationResult result) throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException, ObjectAlreadyExistsException, PolicyViolationException {
    Class<E> objectClass = delta.getObjectTypeClass();
    String oid = delta.getOid();
    PrismObject<E> objectToModify = null;
    try {
        Collection<SelectorOptions<GetOperationOptions>> getOptions = b.schemaService.getOperationOptionsBuilder().readOnly().noFetch().futurePointInTime().build();
        objectToModify = b.provisioningService.getObject(objectClass, oid, getOptions, task, result);
    } catch (ObjectNotFoundException e) {
        // We do not want the operation to fail here. The object might have been re-created on the resource
        // or discovery might re-create it. So simply ignore this error and give provisioning a chance to fail properly.
        // TODO This is maybe a false hope. In fact, if OID is not in repo, the modifyObject call fails immediately.
        result.muteLastSubresultError();
        LOGGER.warn("Repository object {}: {} is gone. But trying to modify resource object anyway", objectClass, oid);
    }
    OperationProvisioningScriptsType scripts;
    if (ShadowType.class.isAssignableFrom(objectClass)) {
        scripts = prepareScripts(objectToModify, ProvisioningOperationTypeType.MODIFY, result);
    } else {
        scripts = null;
    }
    ModelImplUtils.setRequestee(task, context);
    try {
        ProvisioningOperationOptions options = getProvisioningOptions();
        String updatedOid = b.provisioningService.modifyObject(objectClass, oid, delta.getModifications(), scripts, options, task, result);
        determineLivenessFromObject(objectToModify);
        return updatedOid;
    } catch (ObjectNotFoundException e) {
        // rough attempt at guessing if the exception is related to the shadow (and not e.g. to the resource)
        if (e.getOid() == null || e.getOid().equals(oid)) {
            shadowLivenessState = ShadowLivenessState.DELETED;
        }
        throw e;
    } finally {
        ModelImplUtils.clearRequestee(task);
    }
}
Also used : ProvisioningOperationOptions(com.evolveum.midpoint.provisioning.api.ProvisioningOperationOptions)

Example 7 with ProvisioningOperationOptions

use of com.evolveum.midpoint.provisioning.api.ProvisioningOperationOptions in project midpoint by Evolveum.

the class DeltaExecution method getProvisioningOptions.

// endregion
// region Provisioning options
private ProvisioningOperationOptions getProvisioningOptions() throws SecurityViolationException {
    ModelExecuteOptions modelOptions = context.getOptions();
    ProvisioningOperationOptions provisioningOptions = copyFromModelOptions(modelOptions);
    E existingObject = asObjectable(elementContext.getObjectCurrent());
    if (existingObject instanceof ShadowType) {
        ShadowType existingShadow = (ShadowType) existingObject;
        if (isExecuteAsSelf(existingShadow)) {
            LOGGER.trace("Setting 'execute as self' provisioning option for {}", existingShadow);
            provisioningOptions.setRunAsAccountOid(existingShadow.getOid());
        }
    }
    if (context.getChannel() != null) {
        if (context.getChannel().equals(QNameUtil.qNameToUri(SchemaConstants.CHANNEL_RECON))) {
            // TODO: this is probably wrong. We should not have special case
            // for recon channel! This should be handled by the provisioning task
            // setting the right options there.
            provisioningOptions.setCompletePostponed(false);
        }
        if (context.getChannel().equals(SchemaConstants.CHANNEL_DISCOVERY_URI)) {
            // We want to avoid endless loops in error handling.
            provisioningOptions.setDoNotDiscovery(true);
        }
    }
    return provisioningOptions;
}
Also used : ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) ProvisioningOperationOptions(com.evolveum.midpoint.provisioning.api.ProvisioningOperationOptions)

Example 8 with ProvisioningOperationOptions

use of com.evolveum.midpoint.provisioning.api.ProvisioningOperationOptions in project midpoint by Evolveum.

the class DeltaExecution method addProvisioningObject.

private String addProvisioningObject(PrismObject<E> object, OperationResult result) throws ObjectNotFoundException, ObjectAlreadyExistsException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException, PolicyViolationException {
    OperationProvisioningScriptsType scripts;
    if (object.canRepresent(ShadowType.class)) {
        ShadowType shadow = (ShadowType) object.asObjectable();
        argCheck(ShadowUtil.getResourceOid(shadow) != null, "Resource OID is null in shadow");
        scripts = prepareScripts(object, ProvisioningOperationTypeType.ADD, result);
    } else {
        scripts = null;
    }
    ModelImplUtils.setRequestee(task, context);
    try {
        ProvisioningOperationOptions options = getProvisioningOptions();
        return b.provisioningService.addObject(object, scripts, options, task, result);
    } finally {
        ModelImplUtils.clearRequestee(task);
    }
}
Also used : ProvisioningOperationOptions(com.evolveum.midpoint.provisioning.api.ProvisioningOperationOptions)

Example 9 with ProvisioningOperationOptions

use of com.evolveum.midpoint.provisioning.api.ProvisioningOperationOptions in project midpoint by Evolveum.

the class DeltaExecution method copyFromModelOptions.

private ProvisioningOperationOptions copyFromModelOptions(ModelExecuteOptions options) {
    ProvisioningOperationOptions provisioningOptions = new ProvisioningOperationOptions();
    if (options == null) {
        return provisioningOptions;
    }
    provisioningOptions.setForce(options.getForce());
    provisioningOptions.setOverwrite(options.getOverwrite());
    return provisioningOptions;
}
Also used : ProvisioningOperationOptions(com.evolveum.midpoint.provisioning.api.ProvisioningOperationOptions)

Example 10 with ProvisioningOperationOptions

use of com.evolveum.midpoint.provisioning.api.ProvisioningOperationOptions in project midpoint by Evolveum.

the class LinkUpdater method updateSituationInShadow.

private void updateSituationInShadow(SynchronizationSituationType newSituation, OperationResult parentResult) {
    OperationResult result = parentResult.subresult(OP_UPDATE_SITUATION_IN_SHADOW).setMinor().addArbitraryObjectAsParam("situation", newSituation).addParam("accountRef", projectionOid).build();
    try {
        LOGGER.trace("updateSituationInShadow: called with newSituation={}", newSituation);
        PrismObject<ShadowType> currentShadow;
        Collection<SelectorOptions<GetOperationOptions>> getOptions = schemaService.getOperationOptionsBuilder().readOnly().noFetch().allowNotFound(true).build();
        try {
            // TODO consider skipping this operation - at least in some cases
            currentShadow = provisioningService.getObject(ShadowType.class, projectionOid, getOptions, task, result);
        } catch (ObjectNotFoundException ex) {
            LOGGER.trace("Shadow is gone, skipping modifying situation in shadow.");
            result.muteLastSubresultError();
            result.recordSuccess();
            // TODO or what?
            task.onSynchronizationSituationChange(context.getItemProcessingIdentifier(), projectionOid, null);
            return;
        } catch (Exception ex) {
            LOGGER.trace("Problem with getting shadow, skipping modifying situation in shadow.");
            result.recordPartialError(ex);
            // TODO or what?
            task.onSynchronizationSituationChange(context.getItemProcessingIdentifier(), projectionOid, null);
            return;
        }
        // Note there can be some discrepancies between computed situation and the one that will be really present
        // in the repository after the task finishes. It can occur if the modify operation does not succeed.
        task.onSynchronizationSituationChange(context.getItemProcessingIdentifier(), projectionOid, newSituation);
        projCtx.setSynchronizationSituationResolved(newSituation);
        SynchronizationSituationType currentSynchronizationSituation = currentShadow.asObjectable().getSynchronizationSituation();
        if (currentSynchronizationSituation == SynchronizationSituationType.DELETED && ShadowUtil.isDead(currentShadow.asObjectable())) {
            LOGGER.trace("Skipping update of synchronization situation for deleted dead shadow");
            result.recordSuccess();
            return;
        }
        if (isSkipWhenNoChange()) {
            if (newSituation == currentSynchronizationSituation) {
                LOGGER.trace("Skipping update of synchronization situation because there is no change ({})", currentSynchronizationSituation);
                result.recordSuccess();
                return;
            } else {
                LOGGER.trace("Updating synchronization situation {} -> {}", currentSynchronizationSituation, newSituation);
            }
        }
        XMLGregorianCalendar now = clock.currentTimeXMLGregorianCalendar();
        List<ItemDelta<?, ?>> syncSituationDeltas = SynchronizationUtils.createSynchronizationSituationAndDescriptionDelta(currentShadow, newSituation, task.getChannel(), projCtx.hasFullShadow() && TaskUtil.isExecute(task), now);
        try {
            ModelImplUtils.setRequestee(task, focusContext);
            ProvisioningOperationOptions options = ProvisioningOperationOptions.createCompletePostponed(false);
            options.setDoNotDiscovery(true);
            provisioningService.modifyObject(ShadowType.class, projectionOid, syncSituationDeltas, null, options, task, result);
            LOGGER.trace("Situation in projection {} was updated to {}", projCtx, newSituation);
        } catch (ObjectNotFoundException ex) {
            // if the object not found exception is thrown, it's ok..probably
            // the account was deleted by previous execution of changes..just
            // log in the trace the message for the user..
            LOGGER.debug("Situation in account could not be updated. Account not found on the resource.");
        } finally {
            ModelImplUtils.clearRequestee(task);
        }
    } catch (Exception ex) {
        result.recordFatalError(ex);
        throw new SystemException(ex.getMessage(), ex);
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : ProvisioningOperationOptions(com.evolveum.midpoint.provisioning.api.ProvisioningOperationOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) SystemException(com.evolveum.midpoint.util.exception.SystemException) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) SystemException(com.evolveum.midpoint.util.exception.SystemException) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Aggregations

ProvisioningOperationOptions (com.evolveum.midpoint.provisioning.api.ProvisioningOperationOptions)18 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)5 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)3 OwnerResolver (com.evolveum.midpoint.security.api.OwnerResolver)3 EncryptionException (com.evolveum.midpoint.prism.crypto.EncryptionException)2 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)2 GetOperationOptions (com.evolveum.midpoint.schema.GetOperationOptions)2 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)2 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)2 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)1 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)1 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 GenericConnectorException (com.evolveum.midpoint.provisioning.api.GenericConnectorException)1 ResourceObjectShadowChangeDescription (com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription)1 ResourceOperationDescription (com.evolveum.midpoint.provisioning.api.ResourceOperationDescription)1 GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)1 RepoAddOptions (com.evolveum.midpoint.repo.api.RepoAddOptions)1