Search in sources :

Example 46 with ExpressionEvaluationException

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

the class AbstractLdapHierarchyTest method reconcileAllOrgs.

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

        @Override
        public boolean handle(PrismObject<OrgType> object, OperationResult parentResult) {
            try {
                display("reconciling " + object);
                reconcileOrg(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 orgs");
    modelService.searchObjectsIterative(OrgType.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) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 47 with ExpressionEvaluationException

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

the class ProvisioningServiceImpl method getConnectorOperationalStatus.

@Override
public List<ConnectorOperationalStatus> getConnectorOperationalStatus(String resourceOid, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    OperationResult result = parentResult.createMinorSubresult(ProvisioningService.class.getName() + ".getConnectorOperationalStatus");
    result.addParam("resourceOid", resourceOid);
    result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, ProvisioningServiceImpl.class);
    PrismObject<ResourceType> resource;
    try {
        resource = resourceManager.getResource(resourceOid, null, task, result);
    } catch (SchemaException | ObjectNotFoundException | ExpressionEvaluationException ex) {
        ProvisioningUtil.recordFatalError(LOGGER, result, ex.getMessage(), ex);
        throw ex;
    }
    List<ConnectorOperationalStatus> stats;
    try {
        stats = resourceManager.getConnectorOperationalStatus(resource, result);
    } catch (ObjectNotFoundException | SchemaException | CommunicationException | ConfigurationException ex) {
        ProvisioningUtil.recordFatalError(LOGGER, result, "Getting operations status from connector for resource " + resourceOid + " failed: " + ex.getMessage(), ex);
        throw ex;
    }
    result.computeStatus();
    result.cleanupResult();
    return stats;
}
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) 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) ConnectorOperationalStatus(com.evolveum.midpoint.schema.statistics.ConnectorOperationalStatus)

Example 48 with ExpressionEvaluationException

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

the class ResourceManager method testConnectionConnector.

public void testConnectionConnector(ConnectorSpec connectorSpec, Map<String, Collection<Object>> capabilityMap, Task task, OperationResult parentResult) {
    // === test INITIALIZATION ===
    OperationResult initResult = parentResult.createSubresult(ConnectorTestOperation.CONNECTOR_INITIALIZATION.getOperation());
    ConnectorInstance connector;
    try {
        // TODO: this returns configured instance. Then there is another configuration down below.
        // this means double configuration of the connector. TODO: clean this up
        connector = connectorManager.getConfiguredConnectorInstance(connectorSpec, true, initResult);
        initResult.recordSuccess();
    } catch (ObjectNotFoundException e) {
        // The connector was not found. The resource definition is either
        // wrong or the connector is not
        // installed.
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        initResult.recordFatalError("The connector was not found: " + e.getMessage(), e);
        return;
    } catch (SchemaException e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        initResult.recordFatalError("Schema error while dealing with the connector definition: " + e.getMessage(), e);
        return;
    } catch (RuntimeException | Error e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        initResult.recordFatalError("Unexpected runtime error: " + e.getMessage(), e);
        return;
    } catch (CommunicationException e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        initResult.recordFatalError("Communication error: " + e.getMessage(), e);
        return;
    } catch (ConfigurationException e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        initResult.recordFatalError("Configuration error: " + e.getMessage(), e);
        return;
    }
    LOGGER.debug("Testing connection using {}", connectorSpec);
    // === test CONFIGURATION ===
    OperationResult configResult = parentResult.createSubresult(ConnectorTestOperation.CONNECTOR_CONFIGURATION.getOperation());
    try {
        PrismObject<ResourceType> resource = connectorSpec.getResource();
        PrismObjectDefinition<ResourceType> newResourceDefinition = resource.getDefinition().clone();
        applyConnectorSchemaToResource(connectorSpec, newResourceDefinition, resource, task, configResult);
        PrismContainerValue<ConnectorConfigurationType> connectorConfiguration = connectorSpec.getConnectorConfiguration().getValue();
        connector.configure(connectorConfiguration, configResult);
        configResult.recordSuccess();
    } catch (CommunicationException e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        configResult.recordFatalError("Communication error", e);
        return;
    } catch (GenericFrameworkException e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        configResult.recordFatalError("Generic error", e);
        return;
    } catch (SchemaException e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        configResult.recordFatalError("Schema error", e);
        return;
    } catch (ConfigurationException e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        configResult.recordFatalError("Configuration error", e);
        return;
    } catch (ObjectNotFoundException e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        configResult.recordFatalError("Object not found", e);
        return;
    } catch (ExpressionEvaluationException e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        configResult.recordFatalError("Expression error", e);
        return;
    } catch (RuntimeException | Error e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        configResult.recordFatalError("Unexpected runtime error", e);
        return;
    }
    // === test CONNECTION ===
    // delegate the main part of the test to the connector
    connector.test(parentResult);
    parentResult.computeStatus();
    if (!parentResult.isAcceptable()) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.DOWN, parentResult);
        // messages.
        return;
    } else {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.UP, parentResult);
    }
    OperationResult capabilitiesResult = parentResult.createSubresult(ConnectorTestOperation.CONNECTOR_CAPABILITIES.getOperation());
    try {
        InternalMonitor.recordConnectorCapabilitiesFetchCount();
        Collection<Object> capabilities = connector.fetchCapabilities(capabilitiesResult);
        capabilityMap.put(connectorSpec.getConnectorName(), capabilities);
        capabilitiesResult.recordSuccess();
    } catch (CommunicationException e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        capabilitiesResult.recordFatalError("Communication error", e);
        return;
    } catch (GenericFrameworkException e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        capabilitiesResult.recordFatalError("Generic error", e);
        return;
    } catch (ConfigurationException e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        capabilitiesResult.recordFatalError("Configuration error", e);
        return;
    } catch (RuntimeException | Error e) {
        modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
        capabilitiesResult.recordFatalError("Unexpected runtime error", e);
        return;
    }
}
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) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ConnectorConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType) ConnectorInstance(com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 49 with ExpressionEvaluationException

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

the class ResourceManager method applyConnectorSchemaToResource.

/**
	 * Apply proper definition (connector schema) to the resource.
	 */
private void applyConnectorSchemaToResource(ConnectorSpec connectorSpec, PrismObjectDefinition<ResourceType> resourceDefinition, PrismObject<ResourceType> resource, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
    ConnectorType connectorType = connectorManager.getConnectorTypeReadOnly(connectorSpec, result);
    PrismSchema connectorSchema = connectorManager.getConnectorSchema(connectorType);
    if (connectorSchema == null) {
        throw new SchemaException("No connector schema in " + connectorType);
    }
    PrismContainerDefinition<ConnectorConfigurationType> configurationContainerDefinition = ConnectorTypeUtil.findConfigurationContainerDefinition(connectorType, connectorSchema);
    if (configurationContainerDefinition == null) {
        throw new SchemaException("No configuration container definition in schema of " + connectorType);
    }
    configurationContainerDefinition = configurationContainerDefinition.clone();
    PrismContainer<ConnectorConfigurationType> configurationContainer = connectorSpec.getConnectorConfiguration();
    // the element is global in the connector schema. therefore it does not have correct maxOccurs
    if (configurationContainer != null) {
        configurationContainerDefinition.adoptElementDefinitionFrom(configurationContainer.getDefinition());
        configurationContainer.applyDefinition(configurationContainerDefinition, true);
        try {
            configurationContainer.accept(visitable -> {
                if ((visitable instanceof PrismProperty<?>)) {
                    try {
                        evaluateExpression((PrismProperty<?>) visitable, resource, task, result);
                    } catch (SchemaException | ObjectNotFoundException | ExpressionEvaluationException e) {
                        throw new TunnelException(e);
                    }
                }
            });
        } catch (TunnelException te) {
            Throwable e = te.getCause();
            if (e instanceof SchemaException) {
                throw (SchemaException) e;
            } else if (e instanceof ObjectNotFoundException) {
                throw (ObjectNotFoundException) e;
            } else if (e instanceof ExpressionEvaluationException) {
                throw (ExpressionEvaluationException) e;
            } else if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            } else if (e instanceof Error) {
                throw (Error) e;
            } else {
                throw new SystemException(e);
            }
        }
    } else {
        configurationContainerDefinition.adoptElementDefinitionFrom(resourceDefinition.findContainerDefinition(ResourceType.F_CONNECTOR_CONFIGURATION));
    }
    if (connectorSpec.getConnectorName() == null) {
        // Default connector, for compatibility
        // It does not make sense to update this for any other connectors.
        // We cannot have one definition for addiitionalConnector[1]/connectorConfiguraiton and
        // different definition for addiitionalConnector[2]/connectorConfiguraiton in the object definition.
        // The way to go is to set up definitions on the container level.
        resourceDefinition.replaceDefinition(ResourceType.F_CONNECTOR_CONFIGURATION, configurationContainerDefinition);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) PrismSchema(com.evolveum.midpoint.prism.schema.PrismSchema) ConnectorConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType) TunnelException(com.evolveum.midpoint.util.exception.TunnelException) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 50 with ExpressionEvaluationException

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

the class ResourceManager method testConnection.

public void testConnection(PrismObject<ResourceType> resource, Task task, OperationResult parentResult) {
    List<ConnectorSpec> allConnectorSpecs;
    try {
        allConnectorSpecs = getAllConnectorSpecs(resource);
    } catch (SchemaException e) {
        modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
        parentResult.recordFatalError("Configuration error: " + e.getMessage(), e);
        return;
    }
    Map<String, Collection<Object>> capabilityMap = new HashMap<>();
    for (ConnectorSpec connectorSpec : allConnectorSpecs) {
        OperationResult connectorTestResult = parentResult.createSubresult(ConnectorTestOperation.CONNECTOR_TEST.getOperation());
        connectorTestResult.addParam(OperationResult.PARAM_NAME, connectorSpec.getConnectorName());
        connectorTestResult.addParam(OperationResult.PARAM_OID, connectorSpec.getConnectorOid());
        testConnectionConnector(connectorSpec, capabilityMap, task, connectorTestResult);
        connectorTestResult.computeStatus();
    }
    // === test SCHEMA ===
    OperationResult schemaResult = parentResult.createSubresult(ConnectorTestOperation.RESOURCE_SCHEMA.getOperation());
    ResourceSchema schema = null;
    try {
        schema = fetchResourceSchema(resource, capabilityMap, task, schemaResult);
    } catch (CommunicationException e) {
        modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
        schemaResult.recordFatalError("Communication error: " + e.getMessage(), e);
        return;
    } catch (GenericFrameworkException e) {
        modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
        schemaResult.recordFatalError("Generic error: " + e.getMessage(), e);
        return;
    } catch (ConfigurationException e) {
        modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
        schemaResult.recordFatalError("Configuration error: " + e.getMessage(), e);
        return;
    } catch (ObjectNotFoundException e) {
        modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
        schemaResult.recordFatalError("Configuration error: " + e.getMessage(), e);
        return;
    } catch (SchemaException e) {
        modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
        schemaResult.recordFatalError("Configuration error: " + e.getMessage(), e);
        return;
    }
    if (schema == null || schema.isEmpty()) {
        // If there is a static schema in resource definition this may still be OK
        try {
            schema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
        } catch (SchemaException e) {
            modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
            schemaResult.recordFatalError(e);
            return;
        }
        if (schema == null || schema.isEmpty()) {
            modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
            schemaResult.recordFatalError("Connector does not support schema and no static schema available");
            return;
        }
    }
    // capability.
    try {
        resource = completeResource(resource, schema, true, capabilityMap, null, task, schemaResult);
    } catch (ObjectNotFoundException e) {
        modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
        schemaResult.recordFatalError("Object not found (unexpected error, probably a bug): " + e.getMessage(), e);
        return;
    } catch (SchemaException e) {
        modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
        schemaResult.recordFatalError("Schema processing error (probably connector bug): " + e.getMessage(), e);
        return;
    } catch (CommunicationException e) {
        modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
        schemaResult.recordFatalError("Communication error: " + e.getMessage(), e);
        return;
    } catch (ConfigurationException e) {
        modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
        schemaResult.recordFatalError("Configuration error: " + e.getMessage(), e);
        return;
    } catch (ExpressionEvaluationException e) {
        modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
        schemaResult.recordFatalError("Expression error: " + e.getMessage(), e);
        return;
    }
    schemaResult.recordSuccess();
// TODO: connector sanity (e.g. refined schema, at least one account type, identifiers
// in schema, etc.)
}
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) HashMap(java.util.HashMap) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Collection(java.util.Collection)

Aggregations

ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)120 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)93 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)92 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)71 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)71 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)69 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)59 Task (com.evolveum.midpoint.task.api.Task)35 SystemException (com.evolveum.midpoint.util.exception.SystemException)32 PrismObject (com.evolveum.midpoint.prism.PrismObject)29 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)28 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)26 QName (javax.xml.namespace.QName)23 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)21 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)21 ArrayList (java.util.ArrayList)19 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)17 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)13 Collection (java.util.Collection)13 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)12