Search in sources :

Example 6 with WfTask

use of com.evolveum.midpoint.wf.impl.tasks.WfTask in project midpoint by Evolveum.

the class BaseModelInvocationProcessingHelper method submitRootTask.

/**
     * Creates a root job, based on provided job start instruction.
     * Puts a reference to the workflow root task to the model task.
     *
     * @param rootInstruction instruction to use
     * @param taskFromModel (potential) parent task
     * @param wfConfigurationType
	 * @param result
	 * @return reference to a newly created job
     * @throws SchemaException
     * @throws ObjectNotFoundException
     */
public WfTask submitRootTask(WfTaskCreationInstruction rootInstruction, Task taskFromModel, WfConfigurationType wfConfigurationType, OperationResult result) throws SchemaException, ObjectNotFoundException, ObjectAlreadyExistsException {
    WfTask rootWfTask = wfTaskController.submitWfTask(rootInstruction, determineParentTaskForRoot(taskFromModel), wfConfigurationType, taskFromModel.getChannel(), result);
    result.setBackgroundTaskOid(rootWfTask.getTask().getOid());
    wfTaskUtil.setRootTaskOidImmediate(taskFromModel, rootWfTask.getTask().getOid(), result);
    return rootWfTask;
}
Also used : WfTask(com.evolveum.midpoint.wf.impl.tasks.WfTask)

Example 7 with WfTask

use of com.evolveum.midpoint.wf.impl.tasks.WfTask in project midpoint by Evolveum.

the class GeneralChangeProcessor method onProcessEnd.

//endregion
//region Finalizing the processing
@Override
public void onProcessEnd(ProcessEvent event, WfTask wfTask, OperationResult result) throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException {
    Task task = wfTask.getTask();
    // we simply put model context back into parent task
    // (or if it is null, we set the task to skip model context processing)
    // it is safe to directly access the parent, because (1) it is in waiting state, (2) we are its only child
    Task rootTask = task.getParentTask(result);
    SerializationSafeContainer<LensContextType> contextContainer = event.getVariable(GcpProcessVariableNames.VARIABLE_MODEL_CONTEXT, SerializationSafeContainer.class);
    LensContextType lensContextType = null;
    if (contextContainer != null) {
        contextContainer.setPrismContext(prismContext);
        lensContextType = contextContainer.getValue();
    }
    if (lensContextType == null) {
        LOGGER.debug(GcpProcessVariableNames.VARIABLE_MODEL_CONTEXT + " not present in process, this means we should stop processing. Task = {}", rootTask);
        wfTaskUtil.storeModelContext(rootTask, (ModelContext) null);
    } else {
        LOGGER.debug("Putting (changed or unchanged) value of {} into the task {}", GcpProcessVariableNames.VARIABLE_MODEL_CONTEXT, rootTask);
        wfTaskUtil.storeModelContext(rootTask, lensContextType);
    }
    rootTask.savePendingModifications(result);
    LOGGER.trace("onProcessEnd ending for task {}", task);
}
Also used : WfTask(com.evolveum.midpoint.wf.impl.tasks.WfTask) Task(com.evolveum.midpoint.task.api.Task)

Example 8 with WfTask

use of com.evolveum.midpoint.wf.impl.tasks.WfTask in project midpoint by Evolveum.

the class PrimaryChangeProcessor method submitTasks.

private HookOperationMode submitTasks(List<PcpChildWfTaskCreationInstruction> instructions, final ModelContext context, final ObjectTreeDeltas changesWithoutApproval, Task taskFromModel, WfConfigurationType wfConfigurationType, OperationResult result) {
    try {
        ExecutionMode executionMode = determineExecutionMode(instructions);
        // prepare root task and task0
        WfTask rootWfTask = submitRootTask(context, changesWithoutApproval, taskFromModel, executionMode, wfConfigurationType, result);
        WfTask wfTask0 = submitTask0(context, changesWithoutApproval, rootWfTask, executionMode, wfConfigurationType, result);
        // start the jobs
        List<WfTask> wfTasks = new ArrayList<>(instructions.size());
        for (PcpChildWfTaskCreationInstruction instruction : instructions) {
            if (instruction.startsWorkflowProcess() && instruction.isExecuteApprovedChangeImmediately()) {
                // if we want to execute approved changes immediately in this instruction, we have to wait for
                // task0 (if there is any) and then to update our model context with the results (if there are any)
                // TODO CONSIDER THIS... when OID is no longer transferred
                instruction.addHandlersAfterWfProcessAtEnd(WfTaskUtil.WAIT_FOR_TASKS_HANDLER_URI, WfPrepareChildOperationTaskHandler.HANDLER_URI);
            }
            WfTask wfTask = wfTaskController.submitWfTask(instruction, rootWfTask.getTask(), wfConfigurationType, null, result);
            wfTasks.add(wfTask);
        }
        // all jobs depend on job0 (if there is one)
        if (wfTask0 != null) {
            for (WfTask wfTask : wfTasks) {
                wfTask0.addDependent(wfTask);
            }
            wfTask0.commitChanges(result);
        }
        baseModelInvocationProcessingHelper.logJobsBeforeStart(rootWfTask, result);
        rootWfTask.startWaitingForSubtasks(result);
        return HookOperationMode.BACKGROUND;
    } catch (SchemaException | ObjectNotFoundException | ObjectAlreadyExistsException | CommunicationException | ConfigurationException | RuntimeException | ExpressionEvaluationException e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Workflow process(es) could not be started", e);
        result.recordFatalError("Workflow process(es) could not be started: " + e, e);
        return HookOperationMode.ERROR;
    // todo rollback - at least close open tasks, maybe stop workflow process instances
    }
}
Also used : ExecutionMode(com.evolveum.midpoint.wf.impl.processors.primary.PrimaryChangeProcessor.ExecutionMode) WfTask(com.evolveum.midpoint.wf.impl.tasks.WfTask)

Aggregations

WfTask (com.evolveum.midpoint.wf.impl.tasks.WfTask)8 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)2 ObjectTreeDeltas (com.evolveum.midpoint.schema.ObjectTreeDeltas)2 ResourceShadowDiscriminator (com.evolveum.midpoint.schema.ResourceShadowDiscriminator)2 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)2 Map (java.util.Map)2 ModelContext (com.evolveum.midpoint.model.api.context.ModelContext)1 ModelProjectionContext (com.evolveum.midpoint.model.api.context.ModelProjectionContext)1 LensContext (com.evolveum.midpoint.model.impl.lens.LensContext)1 LensFocusContext (com.evolveum.midpoint.model.impl.lens.LensFocusContext)1 Task (com.evolveum.midpoint.task.api.Task)1 TaskRunResultStatus (com.evolveum.midpoint.task.api.TaskRunResult.TaskRunResultStatus)1 ExecutionMode (com.evolveum.midpoint.wf.impl.processors.primary.PrimaryChangeProcessor.ExecutionMode)1 WfTaskCreationInstruction (com.evolveum.midpoint.wf.impl.tasks.WfTaskCreationInstruction)1 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)1 QName (javax.xml.namespace.QName)1