Search in sources :

Example 76 with SystemException

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

the class ProvisioningServiceImpl method deleteObject.

@Override
public <T extends ObjectType> void deleteObject(Class<T> type, String oid, ProvisioningOperationOptions options, OperationProvisioningScriptsType scripts, Task task, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    Validate.notNull(oid, "Oid of object to delete must not be null.");
    Validate.notNull(parentResult, "Operation result must not be null.");
    LOGGER.trace("**PROVISIONING: Start to delete object with oid {}", oid);
    OperationResult result = parentResult.createSubresult(ProvisioningService.class.getName() + ".deleteObject");
    result.addParam("oid", oid);
    result.addParam("scripts", scripts);
    result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, ProvisioningServiceImpl.class);
    //TODO: is critical when shadow does not exits anymore?? do we need to log it?? if not, change null to allowNotFound options
    PrismObject<T> object = getRepoObject(type, oid, null, result);
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("**PROVISIONING: Object from repository to delete:\n{}", object.debugDump());
    }
    if (object.canRepresent(ShadowType.class) && !ProvisioningOperationOptions.isRaw(options)) {
        try {
            getShadowCache(Mode.STANDARD).deleteShadow((PrismObject<ShadowType>) object, options, scripts, task, result);
        } catch (CommunicationException e) {
            ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't delete object: communication problem: " + e.getMessage(), e);
            throw new CommunicationException(e.getMessage(), e);
        } catch (GenericFrameworkException e) {
            ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't delete object: generic error in the connector: " + e.getMessage(), e);
            throw new CommunicationException(e.getMessage(), e);
        } catch (SchemaException e) {
            ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't delete object: schema problem: " + e.getMessage(), e);
            throw new SchemaException(e.getMessage(), e);
        } catch (ConfigurationException e) {
            ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't delete object: configuration problem: " + e.getMessage(), e);
            throw e;
        } catch (SecurityViolationException e) {
            ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't delete object: security violation: " + e.getMessage(), e);
            throw e;
        } catch (ExpressionEvaluationException e) {
            ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't delete object: expression errror: " + e.getMessage(), e);
            throw e;
        } catch (RuntimeException e) {
            ProvisioningUtil.recordFatalError(LOGGER, result, "Couldn't delete object: " + e.getMessage(), e);
            throw new SystemException(e);
        }
    } else if (object.canRepresent(ResourceType.class)) {
        resourceManager.deleteResource(oid, options, task, result);
    } else {
        try {
            getCacheRepositoryService().deleteObject(type, oid, result);
        } catch (ObjectNotFoundException ex) {
            result.recordFatalError(ex);
            result.cleanupResult(ex);
            throw ex;
        }
    }
    LOGGER.trace("**PROVISIONING: Finished deleting object.");
    result.computeStatus();
    result.cleanupResult();
}
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) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 77 with SystemException

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

the class ProvisioningServiceImpl method getObject.

@SuppressWarnings("unchecked")
@Override
public <T extends ObjectType> PrismObject<T> getObject(Class<T> type, String oid, Collection<SelectorOptions<GetOperationOptions>> options, Task task, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    Validate.notNull(oid, "Oid of object to get must not be null.");
    Validate.notNull(parentResult, "Operation result must not be null.");
    // Result type for this operation
    OperationResult result = parentResult.createMinorSubresult(ProvisioningService.class.getName() + ".getObject");
    result.addParam(OperationResult.PARAM_OID, oid);
    result.addParam(OperationResult.PARAM_TYPE, type);
    result.addCollectionOfSerializablesAsParam("options", options);
    result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, ProvisioningServiceImpl.class);
    GetOperationOptions rootOptions = SelectorOptions.findRootOptions(options);
    PrismObject<T> resultingObject = null;
    if (ResourceType.class.isAssignableFrom(type)) {
        if (GetOperationOptions.isRaw(rootOptions)) {
            try {
                resultingObject = (PrismObject<T>) cacheRepositoryService.getObject(ResourceType.class, oid, null, result);
            } catch (ObjectNotFoundException | SchemaException ex) {
                // catching an exception is important because otherwise the result is UNKNOWN
                result.recordFatalError(ex);
                throw ex;
            }
            try {
                applyDefinition(resultingObject, task, result);
            } catch (ObjectNotFoundException ex) {
                // this is almost OK, we use raw for debug pages, so we want
                // to return resource and it can be fixed
                result.muteLastSubresultError();
                ProvisioningUtil.logWarning(LOGGER, result, "Bad connector reference defined for resource:  " + ex.getMessage(), ex);
            } catch (SchemaException ex) {
                result.muteLastSubresultError();
                ProvisioningUtil.logWarning(LOGGER, result, "Schema violation:  " + ex.getMessage(), ex);
            } catch (ConfigurationException ex) {
                result.muteLastSubresultError();
                ProvisioningUtil.logWarning(LOGGER, result, "Configuration problem:  " + ex.getMessage(), ex);
            }
        } else {
            // schema
            try {
                resultingObject = (PrismObject<T>) resourceManager.getResource(oid, SelectorOptions.findRootOptions(options), task, result);
            } catch (ObjectNotFoundException ex) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Resource object not found", ex);
                throw ex;
            } catch (SchemaException ex) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Schema violation", ex);
                throw ex;
            } catch (CommunicationException ex) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Error communicating with resource", ex);
                throw ex;
            } catch (ConfigurationException ex) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Bad resource configuration", ex);
                throw ex;
            } catch (ExpressionEvaluationException ex) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Expression error", ex);
                throw ex;
            }
        }
    } else {
        // Not resource
        PrismObject<T> repositoryObject = getRepoObject(type, oid, rootOptions, result);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Retrieved repository object:\n{}", repositoryObject.debugDump());
        }
        if (repositoryObject.canRepresent(ShadowType.class)) {
            try {
                resultingObject = (PrismObject<T>) getShadowCache(Mode.STANDARD).getShadow(oid, (PrismObject<ShadowType>) (repositoryObject), options, task, result);
            } catch (ObjectNotFoundException e) {
                if (!GetOperationOptions.isAllowNotFound(rootOptions)) {
                    ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
                } else {
                    result.muteLastSubresultError();
                    result.computeStatus();
                }
                throw e;
            } catch (CommunicationException e) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
                throw e;
            } catch (SchemaException e) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
                throw e;
            } catch (ConfigurationException e) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
                throw e;
            } catch (SecurityViolationException e) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
                throw e;
            } catch (SystemException e) {
                // Do NOT wrap this into SystemException again
                ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
                throw e;
            } catch (RuntimeException e) {
                ProvisioningUtil.recordFatalError(LOGGER, result, "Error getting object OID=" + oid + ": " + e.getMessage(), e);
                throw new SystemException(e);
            }
        } else {
            resultingObject = repositoryObject;
        }
    }
    result.computeStatus();
    if (!GetOperationOptions.isRaw(rootOptions)) {
        resultingObject = resultingObject.cloneIfImmutable();
        resultingObject.asObjectable().setFetchResult(result.createOperationResultType());
    }
    result.cleanupResult();
    validateObject(resultingObject);
    return resultingObject;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 78 with SystemException

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

the class ConnectorManager method discoverConnectors.

/**
	 * Lists local connectors and makes sure that appropriate ConnectorType
	 * objects for them exist in repository.
	 * 
	 * It will never delete any repository object, even if the corresponding
	 * connector cannot be found. The connector may temporarily removed, may be
	 * present on a different node, manual upgrade may be needed etc.
	 * 
	 * @return set of discovered connectors (new connectors found)
	 * @throws CommunicationException
	 */
//	@SuppressWarnings("unchecked")
public Set<ConnectorType> discoverConnectors(ConnectorHostType hostType, OperationResult parentResult) throws CommunicationException {
    OperationResult result = parentResult.createSubresult(ConnectorManager.class.getName() + ".discoverConnectors");
    result.addParam("host", hostType);
    // it
    if (hostType != null && hostType.getOid() == null) {
        throw new SystemException("Discovery attempt with non-persistent " + hostType);
    }
    Set<ConnectorType> discoveredConnectors = new HashSet<ConnectorType>();
    for (ConnectorFactory connectorFactory : getConnectorFactories()) {
        Set<ConnectorType> foundConnectors;
        try {
            foundConnectors = connectorFactory.listConnectors(hostType, result);
        } catch (CommunicationException ex) {
            result.recordFatalError("Discovery failed: " + ex.getMessage(), ex);
            throw new CommunicationException("Discovery failed: " + ex.getMessage(), ex);
        }
        if (foundConnectors == null) {
            LOGGER.trace("Connector factory {} discovered null connectors, skipping", connectorFactory);
            continue;
        }
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Got {} connectors from {}: {}", new Object[] { foundConnectors.size(), hostType, foundConnectors });
        }
        for (ConnectorType foundConnector : foundConnectors) {
            LOGGER.trace("Found connector {}", foundConnector);
            boolean inRepo = true;
            try {
                inRepo = isInRepo(foundConnector, result);
            } catch (SchemaException e1) {
                LOGGER.error("Unexpected schema problem while checking existence of " + ObjectTypeUtil.toShortString(foundConnector), e1);
                result.recordPartialError("Unexpected schema problem while checking existence of " + ObjectTypeUtil.toShortString(foundConnector), e1);
            // But continue otherwise ...
            }
            if (!inRepo) {
                LOGGER.trace("Connector {} not in the repository, \"dicovering\" it", foundConnector);
                // itself
                if (hostType != null && foundConnector.getConnectorHost() == null) {
                    foundConnector.setConnectorHost(hostType);
                }
                if (foundConnector.getSchema() == null) {
                    LOGGER.warn("Connector {} haven't provided configuration schema", foundConnector);
                }
                // Sanitize framework-supplied OID
                if (StringUtils.isNotEmpty(foundConnector.getOid())) {
                    LOGGER.warn("Provisioning framework " + foundConnector.getFramework() + " supplied OID for connector " + ObjectTypeUtil.toShortString(foundConnector));
                    foundConnector.setOid(null);
                }
                // Store the connector object
                String oid;
                try {
                    prismContext.adopt(foundConnector);
                    oid = repositoryService.addObject(foundConnector.asPrismObject(), null, result);
                } catch (ObjectAlreadyExistsException e) {
                    // We don't specify the OID, therefore this should never
                    // happen
                    // Convert to runtime exception
                    LOGGER.error("Got ObjectAlreadyExistsException while not expecting it: " + e.getMessage(), e);
                    result.recordFatalError("Got ObjectAlreadyExistsException while not expecting it: " + e.getMessage(), e);
                    throw new SystemException("Got ObjectAlreadyExistsException while not expecting it: " + e.getMessage(), e);
                } catch (SchemaException e) {
                    // If there is a schema error it must be a bug. Convert to
                    // runtime exception
                    LOGGER.error("Got SchemaException while not expecting it: " + e.getMessage(), e);
                    result.recordFatalError("Got SchemaException while not expecting it: " + e.getMessage(), e);
                    throw new SystemException("Got SchemaException while not expecting it: " + e.getMessage(), e);
                }
                foundConnector.setOid(oid);
                discoveredConnectors.add(foundConnector);
                LOGGER.info("Discovered new connector " + foundConnector);
            }
        }
    }
    result.recordSuccess();
    return discoveredConnectors;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) ConnectorFactory(com.evolveum.midpoint.provisioning.ucf.api.ConnectorFactory) SystemException(com.evolveum.midpoint.util.exception.SystemException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) HashSet(java.util.HashSet)

Example 79 with SystemException

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

the class ConsistencyTest method test999Shutdown.

@Test
public void test999Shutdown() throws Exception {
    taskManager.shutdown();
    waitFor("waiting for task manager shutdown", new Checker() {

        @Override
        public boolean check() throws CommonException {
            try {
                return taskManager.getLocallyRunningTasks(new OperationResult("dummy")).isEmpty();
            } catch (TaskManagerException e) {
                throw new SystemException(e);
            }
        }

        @Override
        public void timeout() {
        // No reaction, the test will fail right after return from this
        }
    }, 10000);
    AssertJUnit.assertEquals("Some tasks left running after shutdown", new HashSet<Task>(), taskManager.getLocallyRunningTasks(new OperationResult("dummy")));
}
Also used : Checker(com.evolveum.midpoint.test.Checker) Task(com.evolveum.midpoint.task.api.Task) SystemException(com.evolveum.midpoint.util.exception.SystemException) TaskManagerException(com.evolveum.midpoint.task.api.TaskManagerException) CommonException(com.evolveum.midpoint.util.exception.CommonException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) AbstractModelIntegrationTest(com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)

Example 80 with SystemException

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

the class SimpleSmsTransport method evaluateExpression.

private String evaluateExpression(ExpressionType expressionType, ExpressionVariables expressionVariables, String shortDesc, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException {
    QName resultName = new QName(SchemaConstants.NS_C, "result");
    PrismPropertyDefinition<String> resultDef = new PrismPropertyDefinitionImpl(resultName, DOMUtil.XSD_STRING, prismContext);
    Expression<PrismPropertyValue<String>, PrismPropertyDefinition<String>> expression = expressionFactory.makeExpression(expressionType, resultDef, shortDesc, task, result);
    ExpressionEvaluationContext params = new ExpressionEvaluationContext(null, expressionVariables, shortDesc, task, result);
    PrismValueDeltaSetTriple<PrismPropertyValue<String>> exprResult = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, params, task, result);
    if (exprResult.getZeroSet().size() != 1) {
        throw new SystemException("Invalid number of return values (" + exprResult.getZeroSet().size() + "), expected 1.");
    }
    return exprResult.getZeroSet().iterator().next().getValue();
}
Also used : PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) SystemException(com.evolveum.midpoint.util.exception.SystemException) QName(javax.xml.namespace.QName) PrismPropertyDefinitionImpl(com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Aggregations

SystemException (com.evolveum.midpoint.util.exception.SystemException)201 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)113 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)76 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)65 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)35 PrismObject (com.evolveum.midpoint.prism.PrismObject)32 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)32 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)31 QName (javax.xml.namespace.QName)28 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)26 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)26 Task (com.evolveum.midpoint.task.api.Task)23 ArrayList (java.util.ArrayList)21 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)16 GenericFrameworkException (com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException)16 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)14 Test (org.testng.annotations.Test)14 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)12 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)12 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)12