Search in sources :

Example 11 with RunningTask

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

the class ActivityState method getParentTask.

/**
 * @param fresh False if we are OK with the cached version of the parent task (if current task is RunningTask).
 * @param result Can be null if we are 100% sure it will not be used.
 */
@NotNull
private Task getParentTask(boolean fresh, @Nullable OperationResult result) throws SchemaException, ObjectNotFoundException {
    Task task = getTask();
    Task parentTask;
    if (!fresh && task instanceof RunningTask) {
        parentTask = ((RunningTask) task).getParentTask();
    } else {
        parentTask = task.getParentTask(result);
    }
    return java.util.Objects.requireNonNull(parentTask, () -> "No parent task for " + task);
}
Also used : RunningTask(com.evolveum.midpoint.task.api.RunningTask) Task(com.evolveum.midpoint.task.api.Task) RunningTask(com.evolveum.midpoint.task.api.RunningTask) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with RunningTask

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

the class ActivityBasedTaskRun method setupTaskArchetypeIfNeeded.

private void setupTaskArchetypeIfNeeded(OperationResult result) throws ActivityRunException {
    if (activityBasedTaskHandler.isAvoidAutoAssigningArchetypes()) {
        return;
    }
    try {
        RunningTask task = getRunningTask();
        String defaultArchetypeOid = activityTree.getRootActivity().getHandler().getDefaultArchetypeOid();
        if (defaultArchetypeOid != null) {
            task.addArchetypeInformationIfMissing(defaultArchetypeOid);
            task.flushPendingModifications(result);
        }
    } catch (CommonException e) {
        throw new ActivityRunException("Couldn't setup the task archetype", FATAL_ERROR, PERMANENT_ERROR, e);
    }
}
Also used : ActivityRunException(com.evolveum.midpoint.repo.common.activity.run.ActivityRunException) RunningTask(com.evolveum.midpoint.task.api.RunningTask) CommonException(com.evolveum.midpoint.util.exception.CommonException)

Example 13 with RunningTask

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

the class ClassicCollectionReportExportActivityRun method beforeRun.

@Override
public void beforeRun(OperationResult result) throws ActivityRunException, CommonException {
    RunningTask task = getRunningTask();
    support.beforeExecution(result);
    @NotNull ReportType report = support.getReport();
    support.stateCheck(result);
    searchSpecificationHolder = new ContainerableReportDataSource(support);
    dataWriter = ReportUtils.createDataWriter(report, FileFormatTypeType.CSV, getActivityHandler().reportService, support.getCompiledCollectionView(result));
    controller = new CollectionExportController<>(searchSpecificationHolder, dataWriter, report, reportService, support.getCompiledCollectionView(result), support.getReportParameters());
    controller.initialize(task, result);
    controller.beforeBucketExecution(1, result);
}
Also used : RunningTask(com.evolveum.midpoint.task.api.RunningTask) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with RunningTask

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

the class MockComponentActivityRun method runLocally.

@Override
@NotNull
protected ActivityRunResult runLocally(OperationResult result) throws CommonException {
    CompositeMockWorkDefinition workDef = activity.getWorkDefinition();
    int steps = workDef.getSteps();
    long delay = workDef.getDelay();
    LOGGER.info("Mock activity starting: id={}, steps={}, delay={}, sub-activity={}:\n{}", workDef.getMessage(), steps, delay, getMockSubActivity(), debugDumpLazily());
    String itemName = workDef.getMessage() + ":" + getMockSubActivity();
    Operation operation = activityState.getLiveItemProcessingStatistics().recordOperationStart(new IterativeOperationStartInfo(new IterationItemInformation(itemName, null, null, null)));
    RunningTask task = taskRun.getRunningTask();
    if (delay > 0) {
        LOGGER.trace("Sleeping for {} msecs", delay);
        MiscUtil.sleepWatchfully(System.currentTimeMillis() + delay, 100, task::canRun);
    }
    result.recordSuccess();
    getRecorder().recordExecution(itemName);
    QualifiedItemProcessingOutcomeType qualifiedOutcome = new QualifiedItemProcessingOutcomeType(getPrismContext()).outcome(ItemProcessingOutcomeType.SUCCESS);
    operation.done(qualifiedOutcome, null);
    incrementProgress(qualifiedOutcome);
    LOGGER.info("Mock activity finished: id={}, sub-activity={}:\n{}", workDef.getMessage(), getMockSubActivity(), debugDumpLazily());
    return standardRunResult();
}
Also used : QualifiedItemProcessingOutcomeType(com.evolveum.midpoint.xml.ns._public.common.common_3.QualifiedItemProcessingOutcomeType) RunningTask(com.evolveum.midpoint.task.api.RunningTask) IterativeOperationStartInfo(com.evolveum.midpoint.schema.statistics.IterativeOperationStartInfo) Operation(com.evolveum.midpoint.schema.statistics.Operation) IterationItemInformation(com.evolveum.midpoint.schema.statistics.IterationItemInformation) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with RunningTask

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

the class OperationExecutionRecorderForClockwork method createTaskRef.

private void createTaskRef(OperationExecutionType operation, Context<?> ctx) {
    Task task = ctx.task;
    String rootTaskOid;
    if (task instanceof RunningTask) {
        rootTaskOid = ((RunningTask) task).getRootTaskOid();
    } else if (task.getParent() == null) {
        // can be null
        rootTaskOid = task.getOid();
    } else {
        throw new IllegalStateException("Non-RunningTask with a parent? Impossible: " + task);
    }
    if (rootTaskOid != null) {
        operation.setTaskRef(ObjectTypeUtil.createObjectRef(rootTaskOid, ObjectTypes.TASK));
    }
}
Also used : RunningTask(com.evolveum.midpoint.task.api.RunningTask) Task(com.evolveum.midpoint.task.api.Task) RunningTask(com.evolveum.midpoint.task.api.RunningTask)

Aggregations

RunningTask (com.evolveum.midpoint.task.api.RunningTask)20 NotNull (org.jetbrains.annotations.NotNull)6 Task (com.evolveum.midpoint.task.api.Task)4 ActivityRunException (com.evolveum.midpoint.repo.common.activity.run.ActivityRunException)2 IterationItemInformation (com.evolveum.midpoint.schema.statistics.IterationItemInformation)2 IterativeOperationStartInfo (com.evolveum.midpoint.schema.statistics.IterativeOperationStartInfo)2 Operation (com.evolveum.midpoint.schema.statistics.Operation)2 CommonException (com.evolveum.midpoint.util.exception.CommonException)2 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 ModelBeans (com.evolveum.midpoint.model.impl.ModelBeans)1 ResourceObjectClass (com.evolveum.midpoint.model.impl.sync.tasks.ResourceObjectClass)1 SyncItemProcessingRequest (com.evolveum.midpoint.model.impl.sync.tasks.SyncItemProcessingRequest)1 ModelImplUtils (com.evolveum.midpoint.model.impl.util.ModelImplUtils)1 Containerable (com.evolveum.midpoint.prism.Containerable)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 AsyncUpdateEvent (com.evolveum.midpoint.provisioning.api.AsyncUpdateEvent)1 AsyncUpdateEventHandler (com.evolveum.midpoint.provisioning.api.AsyncUpdateEventHandler)1 ResourceObjectShadowChangeDescription (com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription)1