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;
}
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);
}
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
}
}
Aggregations