Search in sources :

Example 21 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)

Example 22 with TaskRunResult

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

the class MockTaskHandler method run.

@Override
public TaskRunResult run(@NotNull RunningTask task) {
    OperationResult result = task.getResult();
    TaskRunResult runResult = new TaskRunResult();
    PrismProperty<Integer> delayProp = task.getExtensionPropertyOrClone(ITEM_DELAY);
    PrismProperty<Integer> stepsProp = task.getExtensionPropertyOrClone(ITEM_STEPS);
    int delay = MoreObjects.firstNonNull(delayProp != null ? delayProp.getRealValue() : null, 0);
    int steps = MoreObjects.firstNonNull(stepsProp != null ? stepsProp.getRealValue() : null, 1);
    LOGGER.info("Run starting; progress = {}, steps to be executed = {}, delay for one step = {}, in task {}", task.getLegacyProgress(), steps, delay, task);
    for (int i = 0; i < steps; i++) {
        LOGGER.info("Executing step {} (numbered from one) of {} in task {}", i + 1, steps, task);
        MiscUtil.sleepNonInterruptibly(delay);
        try {
            task.incrementLegacyProgressAndStoreStatisticsIfTimePassed(result);
        } catch (SchemaException | ObjectNotFoundException e) {
            throw new SystemException(e);
        }
        if (!task.canRun()) {
            LOGGER.info("Got a shutdown request, finishing task {}", task);
            break;
        }
    }
    LOGGER.info("Run finishing; progress = {} in task {}", task.getLegacyProgress(), task);
    hasRun.set(true);
    result.computeStatusIfUnknown();
    runResult.setRunResultStatus(TaskRunResultStatus.FINISHED);
    return runResult;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) TaskRunResult(com.evolveum.midpoint.task.api.TaskRunResult) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 23 with TaskRunResult

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

the class TaskCycleExecutor method executeTaskCycleRun.

/**
 * Task is refreshed after returning from this method.
 */
private TaskRunResult executeTaskCycleRun(OperationResult result) throws StopTaskException {
    processCycleRunStart(result);
    TaskRunResult runResult = executeHandler(result);
    processCycleRunFinish(runResult, result);
    return runResult;
}
Also used : TaskRunResult(com.evolveum.midpoint.task.api.TaskRunResult)

Aggregations

TaskRunResult (com.evolveum.midpoint.task.api.TaskRunResult)23 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)18 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)9 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)7 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)3 SystemException (com.evolveum.midpoint.util.exception.SystemException)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 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