Search in sources :

Example 71 with CommunicationException

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

the class ConnectorInstanceConnIdImpl method executeScriptIcf.

private Object executeScriptIcf(StateReporter reporter, ExecuteProvisioningScriptOperation scriptOperation, OperationResult result) throws CommunicationException, GenericFrameworkException {
    String icfOpName = null;
    if (scriptOperation.isConnectorHost()) {
        icfOpName = "runScriptOnConnector";
    } else if (scriptOperation.isResourceHost()) {
        icfOpName = "runScriptOnResource";
    } else {
        result.recordFatalError("Where to execute the script?");
        throw new IllegalArgumentException("Where to execute the script?");
    }
    // convert execute script operation to the script context required from
    // the connector
    ScriptContext scriptContext = convertToScriptContext(scriptOperation);
    OperationResult icfResult = result.createSubresult(ConnectorFacade.class.getName() + "." + icfOpName);
    icfResult.addContext("connector", connIdConnectorFacade.getClass());
    Object output = null;
    try {
        LOGGER.trace("Running script ({})", icfOpName);
        recordIcfOperationStart(reporter, ProvisioningOperation.ICF_SCRIPT, null);
        if (scriptOperation.isConnectorHost()) {
            InternalMonitor.recordConnectorOperation("runScriptOnConnector");
            output = connIdConnectorFacade.runScriptOnConnector(scriptContext, new OperationOptionsBuilder().build());
        } else if (scriptOperation.isResourceHost()) {
            InternalMonitor.recordConnectorOperation("runScriptOnResource");
            output = connIdConnectorFacade.runScriptOnResource(scriptContext, new OperationOptionsBuilder().build());
        }
        recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_SCRIPT, null);
        icfResult.recordSuccess();
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Finished running script ({}), script result: {}", icfOpName, PrettyPrinter.prettyPrint(output));
        }
    } catch (Throwable ex) {
        recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_SCRIPT, null, ex);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Finished running script ({}), ERROR: {}", icfOpName, ex.getMessage());
        }
        Throwable midpointEx = processIcfException(ex, this, icfResult);
        result.computeStatus();
        // exception
        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);
        }
    }
    return output;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) ScriptContext(org.identityconnectors.framework.common.objects.ScriptContext) 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) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConnectorFacade(org.identityconnectors.framework.api.ConnectorFacade) ConnectorObject(org.identityconnectors.framework.common.objects.ConnectorObject)

Example 72 with CommunicationException

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

the class ConnectorInstanceConnIdImpl method fetchResourceSchema.

@Override
public ResourceSchema fetchResourceSchema(List<QName> generateObjectClasses, OperationResult parentResult) throws CommunicationException, GenericFrameworkException, ConfigurationException {
    // Result type for this operation
    OperationResult result = parentResult.createSubresult(ConnectorInstance.class.getName() + ".fetchResourceSchema");
    result.addContext("connector", connectorType);
    try {
        boolean supportsSchema = processOperationCapabilities(result);
        if (!supportsSchema) {
            result.recordStatus(OperationResultStatus.NOT_APPLICABLE, "Connector does not support schema");
            LOGGER.trace("Connector instance {} does not support schema, skipping", this);
            return null;
        }
        retrieveResourceSchema(generateObjectClasses, result);
    } catch (CommunicationException ex) {
        result.recordFatalError(ex);
        throw ex;
    } catch (ConfigurationException ex) {
        result.recordFatalError(ex);
        throw ex;
    } catch (GenericFrameworkException ex) {
        result.recordFatalError(ex);
        throw ex;
    }
    if (resourceSchema == null) {
        result.recordStatus(OperationResultStatus.NOT_APPLICABLE, "Connector does not support schema");
    } else {
        result.recordSuccess();
    }
    return resourceSchema;
}
Also used : CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) GenericFrameworkException(com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) AsynchronousOperationResult(com.evolveum.midpoint.schema.result.AsynchronousOperationResult)

Example 73 with CommunicationException

use of com.evolveum.midpoint.util.exception.CommunicationException 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 74 with CommunicationException

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

the class AbstractLdapHierarchyTest method reconcileAllUsers.

protected void reconcileAllUsers() throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    final Task task = createTask("reconcileAllUsers");
    OperationResult result = task.getResult();
    ResultHandler<UserType> handler = new ResultHandler<UserType>() {

        @Override
        public boolean handle(PrismObject<UserType> object, OperationResult parentResult) {
            try {
                display("reconciling " + object);
                reconcileUser(object.getOid(), task, parentResult);
            } catch (SchemaException | PolicyViolationException | ExpressionEvaluationException | ObjectNotFoundException | ObjectAlreadyExistsException | CommunicationException | ConfigurationException | SecurityViolationException e) {
                throw new SystemException(e.getMessage(), e);
            }
            return true;
        }
    };
    display("Reconciling all users");
    modelService.searchObjectsIterative(UserType.class, null, handler, null, task, result);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) PrismObject(com.evolveum.midpoint.prism.PrismObject) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Example 75 with CommunicationException

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

the class Construction method resolveTarget.

private ResourceType resolveTarget(String sourceDescription, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
    // SearchFilterType filter = targetRef.getFilter();
    ExpressionVariables variables = Utils.getDefaultExpressionVariables(getFocusOdo().getNewObject().asObjectable(), null, null, null);
    if (assignmentPathVariables == null) {
        assignmentPathVariables = LensUtil.computeAssignmentPathVariables(getAssignmentPath());
    }
    Utils.addAssignmentPathVariables(assignmentPathVariables, variables);
    LOGGER.info("Expression variables for filter evaluation: {}", variables);
    ObjectFilter origFilter = QueryConvertor.parseFilter(getConstructionType().getResourceRef().getFilter(), ResourceType.class, getPrismContext());
    LOGGER.info("Orig filter {}", origFilter);
    ObjectFilter evaluatedFilter = ExpressionUtil.evaluateFilterExpressions(origFilter, variables, getMappingFactory().getExpressionFactory(), getPrismContext(), " evaluating resource filter expression ", task, result);
    LOGGER.info("evaluatedFilter filter {}", evaluatedFilter);
    if (evaluatedFilter == null) {
        throw new SchemaException("The OID is null and filter could not be evaluated in assignment targetRef in " + getSource());
    }
    final Collection<PrismObject<ResourceType>> results = new ArrayList<>();
    ResultHandler<ResourceType> handler = (object, parentResult) -> {
        LOGGER.info("Found object {}", object);
        return results.add(object);
    };
    getObjectResolver().searchIterative(ResourceType.class, ObjectQuery.createObjectQuery(evaluatedFilter), null, handler, task, result);
    if (org.apache.commons.collections.CollectionUtils.isEmpty(results)) {
        throw new IllegalArgumentException("Got no target from repository, filter:" + evaluatedFilter + ", class:" + ResourceType.class + " in " + sourceDescription);
    }
    if (results.size() > 1) {
        throw new IllegalArgumentException("Got more than one target from repository, filter:" + evaluatedFilter + ", class:" + ResourceType.class + " in " + sourceDescription);
    }
    PrismObject<ResourceType> target = results.iterator().next();
    // assignmentType.getTargetRef().setOid(target.getOid());
    return target.asObjectable();
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) PrismValue(com.evolveum.midpoint.prism.PrismValue) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) ResourceObjectAssociationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectAssociationType) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) ConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType) ExpressionConstants(com.evolveum.midpoint.schema.constants.ExpressionConstants) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) MappingFactory(com.evolveum.midpoint.model.common.mapping.MappingFactory) PrismValueDeltaSetTriple(com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple) OriginType(com.evolveum.midpoint.prism.OriginType) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) Utils(com.evolveum.midpoint.model.impl.util.Utils) ItemPathUtil(com.evolveum.midpoint.prism.util.ItemPathUtil) Mapping(com.evolveum.midpoint.model.common.mapping.Mapping) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Collection(java.util.Collection) MappingEvaluator(com.evolveum.midpoint.model.impl.lens.projector.MappingEvaluator) Task(com.evolveum.midpoint.task.api.Task) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType) List(java.util.List) ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) SystemException(com.evolveum.midpoint.util.exception.SystemException) FocusType(com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType) ExpressionUtil(com.evolveum.midpoint.repo.common.expression.ExpressionUtil) RefinedAssociationDefinition(com.evolveum.midpoint.common.refinery.RefinedAssociationDefinition) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) QName(javax.xml.namespace.QName) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) Trace(com.evolveum.midpoint.util.logging.Trace) DebugUtil(com.evolveum.midpoint.util.DebugUtil) PrettyPrinter(com.evolveum.midpoint.util.PrettyPrinter) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ArrayList(java.util.ArrayList) PrismObjectDefinition(com.evolveum.midpoint.prism.PrismObjectDefinition) ResourceAttributeDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceAttributeDefinitionType) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) RefinedResourceSchemaImpl(com.evolveum.midpoint.common.refinery.RefinedResourceSchemaImpl) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) RefinedAttributeDefinition(com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition) ConstructionStrengthType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionStrengthType) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) ShadowAssociationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType) PrismObject(com.evolveum.midpoint.prism.PrismObject) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) QueryConvertor(com.evolveum.midpoint.prism.marshaller.QueryConvertor) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) LayerType(com.evolveum.midpoint.xml.ns._public.common.common_3.LayerType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismObject(com.evolveum.midpoint.prism.PrismObject) ArrayList(java.util.ArrayList) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter)

Aggregations

CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)108 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)87 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)87 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)86 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)82 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)69 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)67 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)39 SystemException (com.evolveum.midpoint.util.exception.SystemException)38 GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)36 Task (com.evolveum.midpoint.task.api.Task)30 PrismObject (com.evolveum.midpoint.prism.PrismObject)29 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)24 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)21 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)21 AsynchronousOperationResult (com.evolveum.midpoint.schema.result.AsynchronousOperationResult)19 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)18 QName (javax.xml.namespace.QName)18 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)14 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)13