Search in sources :

Example 21 with CommunicationException

use of com.evolveum.midpoint.util.exception.CommunicationException in project midpoint by Evolveum.

the class ProvisioningServiceImpl method synchronize.

@SuppressWarnings("rawtypes")
@Override
public int synchronize(ResourceShadowDiscriminator shadowCoordinates, Task task, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    Validate.notNull(shadowCoordinates, "Coordinates oid must not be null.");
    String resourceOid = shadowCoordinates.getResourceOid();
    Validate.notNull(resourceOid, "Resource oid must not be null.");
    Validate.notNull(task, "Task must not be null.");
    Validate.notNull(parentResult, "Operation result must not be null.");
    OperationResult result = parentResult.createSubresult(ProvisioningService.class.getName() + ".synchronize");
    result.addParam(OperationResult.PARAM_OID, resourceOid);
    result.addParam(OperationResult.PARAM_TASK, task.toString());
    int processedChanges = 0;
    try {
        // Resolve resource
        PrismObject<ResourceType> resource = getObject(ResourceType.class, resourceOid, null, task, result);
        ResourceType resourceType = resource.asObjectable();
        LOGGER.trace("**PROVISIONING: Start synchronization of resource {} ", resourceType);
        // getting token form task
        PrismProperty tokenProperty = getTokenProperty(shadowCoordinates, task, result);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("**PROVISIONING: Got token property: {} from the task extension.", SchemaDebugUtil.prettyPrint(tokenProperty));
        }
        processedChanges = getShadowCache(Mode.STANDARD).synchronize(shadowCoordinates, tokenProperty, task, result);
        LOGGER.debug("Synchronization of {} done, token {}, {} changes", resource, tokenProperty, processedChanges);
    } catch (ObjectNotFoundException e) {
        ProvisioningUtil.recordFatalError(LOGGER, result, "Synchronization error: object not found: " + e.getMessage(), e);
        throw e;
    } catch (CommunicationException e) {
        ProvisioningUtil.recordFatalError(LOGGER, result, "Synchronization error: communication problem: " + e.getMessage(), e);
        throw e;
    } catch (ObjectAlreadyExistsException e) {
        ProvisioningUtil.recordFatalError(LOGGER, result, "Synchronization error: object already exists problem: " + e.getMessage(), e);
        throw new SystemException(e);
    } catch (GenericFrameworkException e) {
        ProvisioningUtil.recordFatalError(LOGGER, result, "Synchronization error: generic connector framework error: " + e.getMessage(), e);
        throw new GenericConnectorException(e.getMessage(), e);
    } catch (SchemaException e) {
        ProvisioningUtil.recordFatalError(LOGGER, result, "Synchronization error: schema problem: " + e.getMessage(), e);
        throw e;
    } catch (SecurityViolationException e) {
        ProvisioningUtil.recordFatalError(LOGGER, result, "Synchronization error: security violation: " + e.getMessage(), e);
        throw e;
    } catch (ConfigurationException e) {
        ProvisioningUtil.recordFatalError(LOGGER, result, "Synchronization error: configuration problem: " + e.getMessage(), e);
        throw e;
    } catch (RuntimeException e) {
        ProvisioningUtil.recordFatalError(LOGGER, result, "Synchronization error: unexpected problem: " + e.getMessage(), e);
        throw e;
    } catch (ExpressionEvaluationException e) {
        ProvisioningUtil.recordFatalError(LOGGER, result, "Synchronization error: expression error: " + e.getMessage(), e);
        throw e;
    }
    result.recordSuccess();
    result.cleanupResult();
    return processedChanges;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) LabeledString(com.evolveum.midpoint.schema.LabeledString) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) SystemException(com.evolveum.midpoint.util.exception.SystemException) GenericConnectorException(com.evolveum.midpoint.provisioning.api.GenericConnectorException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 22 with CommunicationException

use of com.evolveum.midpoint.util.exception.CommunicationException in project midpoint by Evolveum.

the class ProvisioningServiceImpl method handleRepoObject.

private <T extends ObjectType> boolean handleRepoObject(final Class<T> type, PrismObject<T> object, final Collection<SelectorOptions<GetOperationOptions>> options, final ResultHandler<T> handler, Task task, final OperationResult objResult) {
    PrismObject<T> completeObject;
    try {
        completeObject = completeObject(type, object, options, task, objResult);
    } catch (SchemaException | ObjectNotFoundException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
        LOGGER.error("Error while completing {}: {}. Using non-complete object.", new Object[] { object, e.getMessage(), e });
        objResult.recordFatalError(e);
        object.asObjectable().setFetchResult(objResult.createOperationResultType());
        completeObject = object;
    }
    validateObject(completeObject);
    if (ShadowType.class.isAssignableFrom(type) && GetOperationOptions.isMaxStaleness(SelectorOptions.findRootOptions(options))) {
        CachingMetadataType cachingMetadata = ((ShadowType) completeObject.asObjectable()).getCachingMetadata();
        if (cachingMetadata == null) {
            objResult.recordFatalError("Requested cached data but no cached data are available in the shadow");
        }
    }
    objResult.computeStatus();
    objResult.recordSuccessIfUnknown();
    if (!objResult.isSuccess()) {
        OperationResultType resultType = objResult.createOperationResultType();
        completeObject.asObjectable().setFetchResult(resultType);
    }
    return handler.handle(completeObject, objResult);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PrismObject(com.evolveum.midpoint.prism.PrismObject) CachingMetadataType(com.evolveum.midpoint.xml.ns._public.common.common_3.CachingMetadataType)

Example 23 with CommunicationException

use of com.evolveum.midpoint.util.exception.CommunicationException in project midpoint by Evolveum.

the class ResourceManager method completeResource.

/**
	 * Make sure that the resource is complete.
	 * 
	 * It will check if the resource has a sufficiently fresh schema, etc.
	 * 
	 * Returned resource may be the same or may be a different instance, but it
	 * is guaranteed that it will be "fresher" and will correspond to the
	 * repository state (assuming that the provided resource also corresponded
	 * to the repository state).
	 * 
	 * The connector schema that was fetched before can be supplied to this
	 * method. This is just an optimization. It comes handy e.g. in test
	 * connection case.
	 * 
	 * Note: This is not really the best place for this method. Need to figure
	 * out correct place later.
	 * 
	 * @param repoResource
	 *            Resource to check
	 * @param resourceSchema
	 *            schema that was freshly pre-fetched (or null)
	 * @param parentResult
	 * 
	 * @return completed resource
	 */
private PrismObject<ResourceType> completeResource(PrismObject<ResourceType> repoResource, ResourceSchema resourceSchema, boolean fetchedSchema, Map<String, Collection<Object>> capabilityMap, GetOperationOptions options, Task task, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    // do not add as a subresult..it will be added later, if the completing
    // of resource will be successfull.if not, it will be only set as a
    // fetch result in the resource..
    OperationResult result = parentResult.createMinorSubresult(OPERATION_COMPLETE_RESOURCE);
    try {
        applyConnectorSchemaToResource(repoResource, task, result);
    } catch (SchemaException e) {
        String message = "Schema error while applying connector schema to connectorConfiguration section of " + repoResource + ": " + e.getMessage();
        result.recordPartialError(message, e);
        LOGGER.warn(message, e);
        return repoResource;
    } catch (ObjectNotFoundException e) {
        String message = "Object not found error while processing connector configuration of " + repoResource + ": " + e.getMessage();
        result.recordPartialError(message, e);
        LOGGER.warn(message, e);
        return repoResource;
    } catch (RuntimeException e) {
        String message = "Unexpected error while processing connector configuration of " + repoResource + ": " + e.getMessage();
        result.recordPartialError(message, e);
        LOGGER.warn(message, e);
        return repoResource;
    }
    PrismObject<ResourceType> newResource;
    if (isComplete(repoResource)) {
        // The resource is complete.
        newResource = repoResource;
    } else {
        if (GetOperationOptions.isNoFetch(options)) {
            // We need to fetch schema, but the noFetch option is specified. Therefore return whatever we have.
            result.recordSuccessIfUnknown();
            return repoResource;
        }
        try {
            completeSchemaAndCapabilities(repoResource, resourceSchema, fetchedSchema, capabilityMap, task, result);
        } catch (Exception ex) {
            // Catch the exceptions. There are not critical. We need to catch them all because the connector may
            // throw even undocumented runtime exceptions.
            // Even non-complete resource may still be usable. The fetchResult indicates that there was an error
            result.recordPartialError("Cannot complete resource schema and capabilities: " + ex.getMessage(), ex);
            return repoResource;
        }
        try {
            // Now we need to re-read the resource from the repository and re-aply the schemas. This ensures that we will
            // cache the correct version and that we avoid race conditions, etc.
            newResource = repositoryService.getObject(ResourceType.class, repoResource.getOid(), null, result);
            applyConnectorSchemaToResource(newResource, task, result);
        } catch (SchemaException e) {
            result.recordFatalError(e);
            throw e;
        } catch (ObjectNotFoundException e) {
            result.recordFatalError(e);
            throw e;
        } catch (RuntimeException e) {
            result.recordFatalError(e);
            throw e;
        }
    }
    try {
        // make sure it has parsed resource and refined schema. We are going to cache
        // it, so we want to cache it with the parsed schemas
        RefinedResourceSchemaImpl.getResourceSchema(newResource, prismContext);
        RefinedResourceSchemaImpl.getRefinedSchema(newResource);
    } catch (SchemaException e) {
        String message = "Schema error while processing schemaHandling section of " + newResource + ": " + e.getMessage();
        result.recordPartialError(message, e);
        LOGGER.warn(message, e);
        return newResource;
    } catch (RuntimeException e) {
        String message = "Unexpected error while processing schemaHandling section of " + newResource + ": " + e.getMessage();
        result.recordPartialError(message, e);
        LOGGER.warn(message, e);
        return newResource;
    }
    result.recordSuccessIfUnknown();
    return newResource;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) SystemException(com.evolveum.midpoint.util.exception.SystemException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) GenericConnectorException(com.evolveum.midpoint.provisioning.api.GenericConnectorException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) TunnelException(com.evolveum.midpoint.util.exception.TunnelException)

Example 24 with CommunicationException

use of com.evolveum.midpoint.util.exception.CommunicationException in project midpoint by Evolveum.

the class ConnectorInstanceConnIdImpl method fetchConnectorObject.

/**
	 * Returns null if nothing is found.
	 */
private ConnectorObject fetchConnectorObject(StateReporter reporter, ObjectClassComplexTypeDefinition objectClassDefinition, ObjectClass icfObjectClass, Uid uid, OperationOptions options, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, GenericFrameworkException, SecurityViolationException, SchemaException, ConfigurationException {
    // Connector operation cannot create result for itself, so we need to
    // create result for it
    OperationResult icfResult = parentResult.createMinorSubresult(ConnectorFacade.class.getName() + ".getObject");
    icfResult.addParam("objectClass", icfObjectClass.toString());
    icfResult.addParam("uid", uid.getUidValue());
    icfResult.addArbitraryObjectAsParam("options", options);
    icfResult.addContext("connector", connIdConnectorFacade.getClass());
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Fetching connector object ObjectClass={}, UID={}, options={}", new Object[] { icfObjectClass, uid, ConnIdUtil.dumpOptions(options) });
    }
    ConnectorObject co = null;
    try {
        // Invoke the ICF connector
        InternalMonitor.recordConnectorOperation("getObject");
        recordIcfOperationStart(reporter, ProvisioningOperation.ICF_GET, objectClassDefinition, uid);
        co = connIdConnectorFacade.getObject(icfObjectClass, uid, options);
        recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_GET, objectClassDefinition, uid);
        icfResult.recordSuccess();
    } catch (Throwable ex) {
        recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_GET, objectClassDefinition, ex, uid);
        String desc = this.getHumanReadableName() + " while getting object identified by ICF UID '" + uid.getUidValue() + "'";
        Throwable midpointEx = processIcfException(ex, desc, icfResult);
        icfResult.computeStatus("Add object failed");
        // exception
        if (midpointEx instanceof CommunicationException) {
            icfResult.muteError();
            throw (CommunicationException) midpointEx;
        } else if (midpointEx instanceof GenericFrameworkException) {
            throw (GenericFrameworkException) midpointEx;
        } else if (midpointEx instanceof ConfigurationException) {
            throw (ConfigurationException) midpointEx;
        } else if (midpointEx instanceof SecurityViolationException) {
            throw (SecurityViolationException) midpointEx;
        } else if (midpointEx instanceof ObjectNotFoundException) {
            LOGGER.trace("Got ObjectNotFoundException while looking for resource object ConnId UID: {}", uid);
            return null;
        } else if (midpointEx instanceof RuntimeException) {
            throw (RuntimeException) midpointEx;
        } else if (midpointEx instanceof Error) {
            // This should not happen. But some connectors are very strange.
            throw new SystemException("ERROR: " + midpointEx.getClass().getName() + ": " + midpointEx.getMessage(), midpointEx);
        } else {
            throw new SystemException(midpointEx.getClass().getName() + ": " + midpointEx.getMessage(), midpointEx);
        }
    }
    return co;
}
Also used : CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult) GuardedString(org.identityconnectors.common.security.GuardedString)

Example 25 with CommunicationException

use of com.evolveum.midpoint.util.exception.CommunicationException in project midpoint by Evolveum.

the class ConnectorInstanceConnIdImpl method executeScript.

@Override
public Object executeScript(ExecuteProvisioningScriptOperation scriptOperation, StateReporter reporter, OperationResult parentResult) throws CommunicationException, GenericFrameworkException {
    OperationResult result = parentResult.createSubresult(ConnectorInstance.class.getName() + ".executeScript");
    Object output = null;
    try {
        output = executeScriptIcf(reporter, scriptOperation, result);
    } catch (CommunicationException e) {
        result.recordFatalError(e);
        throw e;
    } catch (GenericFrameworkException e) {
        result.recordFatalError(e);
        throw e;
    } catch (RuntimeException e) {
        result.recordFatalError(e);
        throw e;
    }
    result.computeStatus();
    return output;
}
Also used : 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) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject)

Aggregations

CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)105 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)90 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)84 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)83 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)72 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)70 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)62 SystemException (com.evolveum.midpoint.util.exception.SystemException)42 GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)37 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)35 PrismObject (com.evolveum.midpoint.prism.PrismObject)29 Task (com.evolveum.midpoint.task.api.Task)29 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)24 AsynchronousOperationResult (com.evolveum.midpoint.schema.result.AsynchronousOperationResult)20 Collection (java.util.Collection)17 ArrayList (java.util.ArrayList)16 QName (javax.xml.namespace.QName)16 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)13 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)13 List (java.util.List)13