Search in sources :

Example 96 with ObjectNotFoundException

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

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

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

the class ProvisioningServiceImpl method applyDefinition.

@Override
@SuppressWarnings("unchecked")
public <T extends ObjectType> void applyDefinition(PrismObject<T> object, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    OperationResult result = parentResult.createMinorSubresult(ProvisioningService.class.getName() + ".applyDefinition");
    result.addParam(OperationResult.PARAM_OBJECT, object);
    result.addContext(OperationResult.CONTEXT_IMPLEMENTATION_CLASS, ProvisioningServiceImpl.class);
    try {
        if (ShadowType.class.isAssignableFrom(object.getCompileTimeClass())) {
            getShadowCache(Mode.STANDARD).applyDefinition((PrismObject<ShadowType>) object, result);
        } else if (ResourceType.class.isAssignableFrom(object.getCompileTimeClass())) {
            resourceManager.applyDefinition((PrismObject<ResourceType>) object, task, result);
        } else {
            throw new IllegalArgumentException("Could not apply definition to object type: " + object.getCompileTimeClass());
        }
        result.computeStatus();
        result.recordSuccessIfUnknown();
    } catch (ObjectNotFoundException | CommunicationException | ConfigurationException | SchemaException | ExpressionEvaluationException | RuntimeException | Error e) {
        ProvisioningUtil.recordFatalError(LOGGER, result, null, e);
        throw e;
    } finally {
        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) 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) PrismObject(com.evolveum.midpoint.prism.PrismObject) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 99 with ObjectNotFoundException

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

the class OrgClosureConcurrencyTest method _test300AddRemoveNodesMT.

protected void _test300AddRemoveNodesMT(final boolean random) throws Exception {
    OperationResult opResult = new OperationResult("===[ test300AddRemoveNodesMT ]===");
    info("test300AddRemoveNodes starting with random = " + random);
    final Set<ObjectType> nodesToRemove = Collections.synchronizedSet(new HashSet<ObjectType>());
    final Set<ObjectType> nodesToAdd = Collections.synchronizedSet(new HashSet<ObjectType>());
    final List<Throwable> exceptions = Collections.synchronizedList(new ArrayList<Throwable>());
    for (int level = 0; level < getConfiguration().getNodeRoundsForLevel().length; level++) {
        int rounds = getConfiguration().getNodeRoundsForLevel()[level];
        List<String> levelOids = orgsByLevels.get(level);
        generateNodesAtOneLevel(nodesToRemove, nodesToAdd, OrgType.class, rounds, levelOids, opResult);
    }
    int numberOfRunners = THREADS;
    final List<Thread> runners = Collections.synchronizedList(new ArrayList<Thread>());
    for (int i = 0; i < numberOfRunners; i++) {
        Runnable runnable = new Runnable() {

            @Override
            public void run() {
                try {
                    while (true) {
                        ObjectType objectType = getNext(nodesToRemove, random);
                        if (objectType == null) {
                            break;
                        }
                        LOGGER.info("Removing {}", objectType);
                        int remaining;
                        try {
                            removeObject(objectType);
                            synchronized (OrgClosureConcurrencyTest.this) {
                                nodesToRemove.remove(objectType);
                                remaining = nodesToRemove.size();
                            }
                            info(Thread.currentThread().getName() + " removed " + objectType + "; remaining: " + remaining);
                        } catch (ObjectNotFoundException e) {
                            // this is OK
                            info(Thread.currentThread().getName() + ": " + objectType + " already deleted");
                            // give other threads a chance
                            Thread.sleep(300);
                        }
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                    exceptions.add(e);
                } finally {
                    runners.remove(Thread.currentThread());
                }
            }
        };
        Thread t = new Thread(runnable);
        runners.add(t);
        t.start();
    }
    waitForRunnersCompletion(runners);
    if (!nodesToRemove.isEmpty()) {
        throw new AssertionError("Nodes to remove is not empty, see the console or log: " + nodesToRemove);
    }
    if (!exceptions.isEmpty()) {
        throw new AssertionError("Found exceptions: " + exceptions);
    }
    rebuildGraph();
    checkClosure(orgGraph.vertexSet());
    info("Consistency after removing OK");
    numberOfRunners = THREADS;
    for (int i = 0; i < numberOfRunners; i++) {
        Runnable runnable = new Runnable() {

            @Override
            public void run() {
                try {
                    while (true) {
                        ObjectType objectType = getNext(nodesToAdd, random);
                        if (objectType == null) {
                            break;
                        }
                        LOGGER.info("Adding {}", objectType);
                        try {
                            addObject(objectType.clone());
                            //                                rebuildGraph();
                            //                                checkClosure(orgGraph.vertexSet());
                            int remaining;
                            synchronized (OrgClosureConcurrencyTest.this) {
                                nodesToAdd.remove(objectType);
                                remaining = nodesToAdd.size();
                            }
                            info(Thread.currentThread().getName() + " re-added " + objectType + "; remaining: " + remaining);
                        } catch (ObjectAlreadyExistsException e) {
                            // this is OK
                            info(Thread.currentThread().getName() + ": " + objectType + " already exists");
                            // give other threads a chance
                            Thread.sleep(300);
                        }
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                    exceptions.add(e);
                } finally {
                    runners.remove(Thread.currentThread());
                }
            }
        };
        Thread t = new Thread(runnable);
        runners.add(t);
        t.start();
    }
    waitForRunnersCompletion(runners);
    if (!nodesToAdd.isEmpty()) {
        throw new AssertionError("Nodes to add is not empty, see the console or log: " + nodesToAdd);
    }
    if (!exceptions.isEmpty()) {
        throw new AssertionError("Found exceptions: " + exceptions);
    }
    rebuildGraph();
    checkClosure(orgGraph.vertexSet());
    info("Consistency after re-adding OK");
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 100 with ObjectNotFoundException

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

the class SqlRepositoryServiceImpl method postInit.

@Override
public void postInit(OperationResult result) throws SchemaException {
    SystemConfigurationType systemConfiguration;
    try {
        systemConfiguration = getObject(SystemConfigurationType.class, SystemObjectsType.SYSTEM_CONFIGURATION.value(), null, result).asObjectable();
    } catch (ObjectNotFoundException e) {
        // ok, no problem e.g. for tests or initial startup
        LOGGER.debug("System configuration not found, exiting postInit method.");
        return;
    }
    SystemConfigurationHolder.setCurrentConfiguration(systemConfiguration);
    Configuration systemConfigFromFile = midpointConfiguration.getConfiguration(MidpointConfiguration.SYSTEM_CONFIGURATION_SECTION);
    if (systemConfigFromFile != null && systemConfigFromFile.getBoolean(LoggingConfigurationManager.SYSTEM_CONFIGURATION_SKIP_REPOSITORY_LOGGING_SETTINGS, false)) {
        LOGGER.warn("Skipping application of repository logging configuration because {}=true", LoggingConfigurationManager.SYSTEM_CONFIGURATION_SKIP_REPOSITORY_LOGGING_SETTINGS);
    } else {
        LoggingConfigurationType loggingConfig = ProfilingConfigurationManager.checkSystemProfilingConfiguration(systemConfiguration.asPrismObject());
        if (loggingConfig != null) {
            LoggingConfigurationManager.configure(loggingConfig, systemConfiguration.getVersion(), result);
        }
    }
    applyFullTextSearchConfiguration(systemConfiguration.getFullTextSearch());
}
Also used : MidpointConfiguration(com.evolveum.midpoint.common.configuration.api.MidpointConfiguration) Configuration(org.apache.commons.configuration.Configuration) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Aggregations

ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)291 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)214 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)200 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)100 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)93 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)90 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)88 Task (com.evolveum.midpoint.task.api.Task)75 SystemException (com.evolveum.midpoint.util.exception.SystemException)71 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)64 PrismObject (com.evolveum.midpoint.prism.PrismObject)52 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)42 Test (org.testng.annotations.Test)40 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)38 ArrayList (java.util.ArrayList)35 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)33 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)32 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)30 QName (javax.xml.namespace.QName)29 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)28