Search in sources :

Example 6 with AsynchronousOperationResult

use of com.evolveum.midpoint.schema.result.AsynchronousOperationResult in project midpoint by Evolveum.

the class ObjectAlreadyExistHandler method discoverConflictingShadow.

private void discoverConflictingShadow(ProvisioningContext ctx, PrismObject<ShadowType> newShadow, ProvisioningOperationOptions options, ProvisioningOperationState<? extends AsynchronousOperationResult> opState, Exception cause, OperationResult failedOperationResult, Task task, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException, SecurityViolationException {
    OperationResult result = parentResult.createSubresult(OP_DISCOVERY);
    try {
        ObjectQuery query = createQueryBySecondaryIdentifier(newShadow.asObjectable(), prismContext);
        final List<PrismObject<ShadowType>> conflictingRepoShadows = findConflictingShadowsInRepo(query, result);
        PrismObject<ShadowType> oldShadow = selectLiveShadow(conflictingRepoShadows);
        if (oldShadow != null) {
            shadowCaretaker.applyAttributesDefinition(ctx, oldShadow);
        }
        LOGGER.trace("DISCOVERY: looking for conflicting shadow for {}", ShadowUtil.shortDumpShadowLazily(newShadow));
        final List<PrismObject<ShadowType>> conflictingResourceShadows = findConflictingShadowsOnResource(query, task, result);
        PrismObject<ShadowType> conflictingShadow = selectLiveShadow(conflictingResourceShadows);
        LOGGER.trace("DISCOVERY: found conflicting shadow for {}:\n{}", newShadow, conflictingShadow == null ? "  no conflicting shadow" : conflictingShadow.debugDumpLazily(1));
        LOGGER.debug("DISCOVERY: discovered new shadow {}", ShadowUtil.shortDumpShadowLazily(conflictingShadow));
        LOGGER.trace("Processing \"already exists\" error for shadow:\n{}\nConflicting repo shadow:\n{}\nConflicting resource shadow:\n{}", newShadow.debugDumpLazily(1), oldShadow == null ? "  null" : oldShadow.debugDumpLazily(1), conflictingShadow == null ? "  null" : conflictingShadow.debugDumpLazily(1));
        if (conflictingShadow != null) {
            // Original object and found object share the same object class, therefore they must
            // also share a kind. We can use this short-cut.
            conflictingShadow.asObjectable().setKind(newShadow.asObjectable().getKind());
            ResourceObjectShadowChangeDescription change = new ResourceObjectShadowChangeDescription();
            change.setResource(ctx.getResource().asPrismObject());
            change.setSourceChannel(QNameUtil.qNameToUri(SchemaConstants.CHANNEL_DISCOVERY));
            change.setShadowedResourceObject(conflictingShadow);
            change.setShadowExistsInRepo(true);
            eventDispatcher.notifyChange(change, task, result);
        }
    } finally {
        result.computeStatus();
    }
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ResourceObjectShadowChangeDescription(com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 7 with AsynchronousOperationResult

use of com.evolveum.midpoint.schema.result.AsynchronousOperationResult in project midpoint by Evolveum.

the class CommunicationExceptionHandler method handleDeleteError.

@Override
public OperationResultStatus handleDeleteError(ProvisioningContext ctx, PrismObject<ShadowType> repoShadow, ProvisioningOperationOptions options, ProvisioningOperationState<AsynchronousOperationResult> opState, Exception cause, OperationResult failedOperationResult, Task task, OperationResult parentResult) throws SchemaException, CommunicationException, ObjectNotFoundException, ConfigurationException, ExpressionEvaluationException {
    OperationResult result = parentResult.createSubresult(OPERATION_HANDLE_DELETE_ERROR);
    result.addParam("exception", cause.getMessage());
    try {
        String stateChangeReason = "deleting " + repoShadow + " ended with communication problem, " + cause.getMessage();
        markResourceDown(ctx.getResourceOid(), stateChangeReason, result, task);
        handleRetriesAndAttempts(ctx, opState, options, cause, result);
        return postponeDelete(ctx, repoShadow, opState, failedOperationResult, result);
    } catch (Throwable t) {
        result.recordFatalError(t);
        throw t;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult)

Example 8 with AsynchronousOperationResult

use of com.evolveum.midpoint.schema.result.AsynchronousOperationResult in project midpoint by Evolveum.

the class ConnectorInstanceConnIdImpl method deleteObject.

@Override
public AsynchronousOperationResult deleteObject(ObjectClassComplexTypeDefinition objectClass, Collection<Operation> additionalOperations, Collection<? extends ResourceAttribute<?>> identifiers, StateReporter reporter, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, GenericFrameworkException, SchemaException {
    Validate.notNull(objectClass, "No objectclass");
    OperationResult result = parentResult.createSubresult(ConnectorInstance.class.getName() + ".deleteObject");
    result.addCollectionOfSerializablesAsParam("identifiers", identifiers);
    ObjectClass objClass = connIdNameMapper.objectClassToIcf(objectClass, getSchemaNamespace(), connectorType, legacySchema);
    Uid uid;
    try {
        uid = getUid(objectClass, identifiers);
    } catch (SchemaException e) {
        result.recordFatalError(e);
        throw e;
    }
    checkAndExecuteAdditionalOperation(reporter, additionalOperations, BeforeAfterType.BEFORE, result);
    OperationResult icfResult = result.createSubresult(ConnectorFacade.class.getName() + ".delete");
    icfResult.addArbitraryObjectAsParam("uid", uid);
    icfResult.addArbitraryObjectAsParam("objectClass", objClass);
    icfResult.addContext("connector", connIdConnectorFacade.getClass());
    try {
        InternalMonitor.recordConnectorOperation("delete");
        recordIcfOperationStart(reporter, ProvisioningOperation.ICF_DELETE, objectClass, uid);
        connIdConnectorFacade.delete(objClass, uid, new OperationOptionsBuilder().build());
        recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_DELETE, objectClass, null, uid);
        icfResult.recordSuccess();
    } catch (Throwable ex) {
        recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_DELETE, objectClass, ex, uid);
        String desc = this.getHumanReadableName() + " while deleting object identified by ICF UID '" + uid.getUidValue() + "'";
        Throwable midpointEx = processIcfException(ex, desc, icfResult);
        result.computeStatus("Removing attribute values failed");
        // exception
        if (midpointEx instanceof ObjectNotFoundException) {
            throw (ObjectNotFoundException) midpointEx;
        } else if (midpointEx instanceof CommunicationException) {
            throw (CommunicationException) midpointEx;
        } else if (midpointEx instanceof GenericFrameworkException) {
            throw (GenericFrameworkException) midpointEx;
        } else if (midpointEx instanceof SchemaException) {
            // Schema exception during delete? It must be a missing UID
            throw new IllegalArgumentException(midpointEx.getMessage(), midpointEx);
        } else if (midpointEx instanceof RuntimeException) {
            throw (RuntimeException) midpointEx;
        } else if (midpointEx instanceof Error) {
            throw (Error) midpointEx;
        } else {
            throw new SystemException("Got unexpected exception: " + ex.getClass().getName() + ": " + ex.getMessage(), ex);
        }
    }
    checkAndExecuteAdditionalOperation(reporter, additionalOperations, BeforeAfterType.AFTER, result);
    result.computeStatus();
    return AsynchronousOperationResult.wrap(result);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult) GuardedString(org.identityconnectors.common.security.GuardedString) OperationOptionsBuilder(org.identityconnectors.framework.common.objects.OperationOptionsBuilder) Uid(org.identityconnectors.framework.common.objects.Uid) QualifiedUid(org.identityconnectors.framework.common.objects.QualifiedUid) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 9 with AsynchronousOperationResult

use of com.evolveum.midpoint.schema.result.AsynchronousOperationResult in project midpoint by Evolveum.

the class ShadowCache method deleteShadow.

public void deleteShadow(PrismObject<ShadowType> shadow, ProvisioningOperationOptions options, OperationProvisioningScriptsType scripts, Task task, OperationResult parentResult) throws CommunicationException, GenericFrameworkException, ObjectNotFoundException, SchemaException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    Validate.notNull(shadow, "Object to delete must not be null.");
    Validate.notNull(parentResult, "Operation result must not be null.");
    InternalMonitor.recordShadowChangeOperation();
    ProvisioningContext ctx = ctxFactory.create(shadow, task, parentResult);
    try {
        ctx.assertDefinition();
    } catch (ObjectNotFoundException ex) {
        // although the resource does not exists..
        if (ProvisioningOperationOptions.isForce(options)) {
            parentResult.muteLastSubresultError();
            shadowManager.deleteShadow(ctx, shadow, null, parentResult);
            parentResult.recordHandledError("Resource defined in shadow does not exists. Shadow was deleted from the repository.");
            return;
        } else {
            throw ex;
        }
    }
    applyAttributesDefinition(ctx, shadow);
    LOGGER.trace("Deleting object {} from the resource {}.", shadow, ctx.getResource());
    AsynchronousOperationResult asyncReturnValue = null;
    if (shadow.asObjectable().getFailedOperationType() == null || (shadow.asObjectable().getFailedOperationType() != null && FailedOperationTypeType.ADD != shadow.asObjectable().getFailedOperationType())) {
        try {
            asyncReturnValue = resouceObjectConverter.deleteResourceObject(ctx, shadow, scripts, parentResult);
        } catch (Exception ex) {
            try {
                handleError(ctx, ex, shadow, FailedOperation.DELETE, null, isDoDiscovery(ctx.getResource(), options), isCompensate(options), parentResult);
            } catch (ObjectAlreadyExistsException e) {
                parentResult.recordFatalError(e);
                throw new SystemException(e.getMessage(), e);
            }
            return;
        }
    }
    LOGGER.trace("Detele object with oid {} form repository.", shadow.getOid());
    try {
        shadowManager.deleteShadow(ctx, shadow, asyncReturnValue == null ? null : asyncReturnValue.getOperationResult(), parentResult);
    } catch (ObjectNotFoundException ex) {
        parentResult.recordFatalError("Can't delete object " + shadow + ". Reason: " + ex.getMessage(), ex);
        throw new ObjectNotFoundException("An error occured while deleting resource object " + shadow + "whith identifiers " + shadow + ": " + ex.getMessage(), ex);
    }
    ObjectDelta<ShadowType> delta = ObjectDelta.createDeleteDelta(shadow.getCompileTimeClass(), shadow.getOid(), prismContext);
    ResourceOperationDescription operationDescription = createSuccessOperationDescription(ctx, shadow, delta, parentResult);
    if (asyncReturnValue != null && asyncReturnValue.isInProgress()) {
        operationListener.notifyInProgress(operationDescription, task, parentResult);
    } else {
        operationListener.notifySuccess(operationDescription, task, parentResult);
    }
    LOGGER.trace("Object deleted from repository successfully.");
    parentResult.computeStatus();
    resourceManager.modifyResourceAvailabilityStatus(ctx.getResource().asPrismObject(), AvailabilityStatusType.UP, parentResult);
}
Also used : AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)

Example 10 with AsynchronousOperationResult

use of com.evolveum.midpoint.schema.result.AsynchronousOperationResult in project midpoint by Evolveum.

the class AbstractManualConnectorInstance method deleteObject.

@Override
public AsynchronousOperationResult deleteObject(ResourceObjectDefinition objectDefinition, PrismObject<ShadowType> shadow, Collection<? extends ResourceAttribute<?>> identifiers, UcfExecutionContext ctx, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, GenericFrameworkException, SchemaException, ConfigurationException {
    OperationResult result = parentResult.createSubresult(OPERATION_DELETE);
    InternalMonitor.recordConnectorOperation("delete");
    InternalMonitor.recordConnectorModification("delete");
    String ticketIdentifier;
    try {
        ticketIdentifier = createTicketDelete(objectDefinition, shadow, identifiers, ctx.getResourceOid(), ctx.getTask(), result);
    } catch (ObjectNotFoundException | CommunicationException | GenericFrameworkException | SchemaException | ConfigurationException | RuntimeException | Error e) {
        result.recordFatalError(e);
        throw e;
    }
    result.recordInProgress();
    result.setAsynchronousOperationReference(ticketIdentifier);
    AsynchronousOperationResult ret = AsynchronousOperationResult.wrap(result);
    ret.setOperationType(PendingOperationTypeType.MANUAL);
    return ret;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult)

Aggregations

AsynchronousOperationResult (com.evolveum.midpoint.schema.result.AsynchronousOperationResult)17 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)10 GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)6 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)3 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)3 ArrayList (java.util.ArrayList)3 Duration (javax.xml.datatype.Duration)3 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)3 EncryptionException (com.evolveum.midpoint.prism.crypto.EncryptionException)2 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)2 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 ConnectorOperationOptions (com.evolveum.midpoint.provisioning.ucf.api.ConnectorOperationOptions)2 AsynchronousOperationReturnValue (com.evolveum.midpoint.schema.result.AsynchronousOperationReturnValue)2 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)2 GuardedString (org.identityconnectors.common.security.GuardedString)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)1 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)1