Search in sources :

Example 16 with TaskRunResult

use of com.evolveum.midpoint.task.api.TaskRunResult in project midpoint by Evolveum.

the class ModelOperationTaskHandler method run.

@Override
public TaskRunResult run(Task task) {
    OperationResult result = task.getResult().createSubresult(DOT_CLASS + "run");
    TaskRunResult runResult = new TaskRunResult();
    LensContextType contextType = task.getModelOperationContext();
    if (contextType == null) {
        LOGGER.trace("No model context found, skipping the model operation execution.");
        if (result.isUnknown()) {
            result.computeStatus();
        }
        runResult.setRunResultStatus(TaskRunResult.TaskRunResultStatus.FINISHED);
    } else {
        LensContext context;
        try {
            context = LensContext.fromLensContextType(contextType, prismContext, provisioningService, task, result);
        } catch (SchemaException e) {
            throw new SystemException("Cannot recover model context from task " + task + " due to schema exception", e);
        } catch (ObjectNotFoundException | ConfigurationException | ExpressionEvaluationException e) {
            throw new SystemException("Cannot recover model context from task " + task, e);
        } catch (CommunicationException e) {
            // todo wait and retry
            throw new SystemException("Cannot recover model context from task " + task, e);
        }
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Context to be executed = {}", context.debugDump());
        }
        try {
            // here we brutally remove all the projection contexts -- because if we are continuing after rejection of a role/resource assignment
            // that resulted in such projection contexts, we DO NOT want them to appear in the context any more
            context.rot();
            Iterator<LensProjectionContext> projectionIterator = context.getProjectionContextsIterator();
            while (projectionIterator.hasNext()) {
                LensProjectionContext projectionContext = projectionIterator.next();
                if (projectionContext.getPrimaryDelta() != null && !projectionContext.getPrimaryDelta().isEmpty()) {
                    // don't remove client requested actions!
                    continue;
                }
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Removing projection context {}", projectionContext.getHumanReadableName());
                }
                projectionIterator.remove();
            }
            if (task.getChannel() == null) {
                task.setChannel(context.getChannel());
            }
            clockwork.run(context, task, result);
            task.setModelOperationContext(context.toLensContextType());
            task.savePendingModifications(result);
            if (result.isUnknown()) {
                result.computeStatus();
            }
            runResult.setRunResultStatus(TaskRunResult.TaskRunResultStatus.FINISHED);
        } catch (RuntimeException | CommonException e) {
            String message = "An exception occurred within model operation, in task " + task;
            LoggingUtils.logUnexpectedException(LOGGER, message, e);
            result.recordPartialError(message, e);
            // TODO: here we do not know whether the error is temporary or permanent (in the future we could discriminate on the basis of particular exception caught)
            runResult.setRunResultStatus(TaskRunResult.TaskRunResultStatus.TEMPORARY_ERROR);
        }
    }
    task.getResult().recomputeStatus();
    runResult.setOperationResult(task.getResult());
    return runResult;
}
Also used : LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) LensContextType(com.evolveum.midpoint.xml.ns._public.common.common_3.LensContextType) TaskRunResult(com.evolveum.midpoint.task.api.TaskRunResult)

Example 17 with TaskRunResult

use of com.evolveum.midpoint.task.api.TaskRunResult in project midpoint by Evolveum.

the class ImportAccountsFromResourceTaskHandler method importSingleShadow.

/**
     * Imports a single shadow. Synchronously. The task is NOT switched to background by default. 
     */
public boolean importSingleShadow(String shadowOid, Task task, OperationResult parentResult) throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    PrismObject<ShadowType> shadow = provisioningService.getObject(ShadowType.class, shadowOid, null, task, parentResult);
    PrismObject<ResourceType> resource = provisioningService.getObject(ResourceType.class, ShadowUtil.getResourceOid(shadow), null, task, parentResult);
    // Create a result handler just for one object. Invoke the handle() method manually.
    TaskRunResult runResult = new TaskRunResult();
    SynchronizeAccountResultHandler resultHandler = createHandler(resource.asObjectable(), shadow, runResult, task, parentResult);
    if (resultHandler == null) {
        return false;
    }
    // This is required for proper error reporting
    resultHandler.setStopOnError(true);
    boolean cont = initializeRun(resultHandler, runResult, task, parentResult);
    if (!cont) {
        return false;
    }
    cont = resultHandler.handle(shadow, parentResult);
    if (!cont) {
        return false;
    }
    finish(resultHandler, runResult, task, parentResult);
    return true;
}
Also used : TaskRunResult(com.evolveum.midpoint.task.api.TaskRunResult) SynchronizeAccountResultHandler(com.evolveum.midpoint.model.impl.sync.SynchronizeAccountResultHandler) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)

Aggregations

TaskRunResult (com.evolveum.midpoint.task.api.TaskRunResult)17 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)16 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)8 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)6 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)3 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)2 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)2 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)2 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)2 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)2 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)2 SystemException (com.evolveum.midpoint.util.exception.SystemException)2 AccessCertificationCampaignType (com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType)2 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)2 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)2 SystemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)2 AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)1 AuditResultHandler (com.evolveum.midpoint.audit.api.AuditResultHandler)1 CertificationHandler (com.evolveum.midpoint.certification.impl.handlers.CertificationHandler)1