Search in sources :

Example 11 with TaskQuartzImpl

use of com.evolveum.midpoint.task.quartzimpl.TaskQuartzImpl in project midpoint by Evolveum.

the class TaskRetriever method addTransientTaskInformation.

// task is Task or PrismObject<TaskType>
private void addTransientTaskInformation(Object task, ClusterStatusInformation csi, boolean retrieveNextRunStartTime, boolean retrieveRetryTime, boolean retrieveNodeAsObserved, OperationResult result) {
    if (!isPersistent(task)) {
        throw new IllegalStateException("Task " + task + " is not persistent");
    }
    if (task instanceof RunningTask) {
        throw new UnsupportedOperationException("addTransientTaskInformation is not available for running tasks");
    }
    TaskType taskBean;
    if (task instanceof TaskQuartzImpl) {
        taskBean = ((TaskQuartzImpl) task).getRawTaskObject().asObjectable();
    } else if (task instanceof PrismObject<?>) {
        // noinspection unchecked
        taskBean = ((PrismObject<TaskType>) task).asObjectable();
    } else {
        throw new IllegalArgumentException("task: " + task);
    }
    if (csi != null && retrieveNodeAsObserved) {
        NodeType runsAt = csi.findNodeInfoForTask(taskBean.getOid());
        if (runsAt != null) {
            taskBean.setNodeAsObserved(runsAt.getNodeIdentifier());
        }
    }
    if (retrieveNextRunStartTime || retrieveRetryTime) {
        NextStartTimes times = localScheduler.getNextStartTimes(taskBean.getOid(), retrieveNextRunStartTime, retrieveRetryTime, result);
        if (retrieveNextRunStartTime && times.getNextScheduledRun() != null) {
            taskBean.setNextRunStartTimestamp(XmlTypeConverter.createXMLGregorianCalendar(times.getNextScheduledRun()));
        }
        if (retrieveRetryTime && times.getNextRetry() != null) {
            taskBean.setNextRetryTimestamp(XmlTypeConverter.createXMLGregorianCalendar(times.getNextRetry()));
        }
    }
    Long stalledSince = stalledTasksWatcher.getStalledSinceForTask(taskBean);
    if (stalledSince != null) {
        taskBean.setStalledSince(XmlTypeConverter.createXMLGregorianCalendar(stalledSince));
    }
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) TaskQuartzImpl(com.evolveum.midpoint.task.quartzimpl.TaskQuartzImpl) NextStartTimes(com.evolveum.midpoint.task.quartzimpl.quartz.NextStartTimes)

Example 12 with TaskQuartzImpl

use of com.evolveum.midpoint.task.quartzimpl.TaskQuartzImpl in project midpoint by Evolveum.

the class TaskRetriever method addSubtasks.

private void addSubtasks(List<TaskQuartzImpl> tasks, TaskQuartzImpl taskToProcess, boolean persistentOnly, OperationResult result) throws SchemaException {
    List<TaskQuartzImpl> subtasks = listSubtasks(taskToProcess, persistentOnly, result);
    for (TaskQuartzImpl task : subtasks) {
        tasks.add(task);
        addSubtasks(tasks, task, persistentOnly, result);
    }
}
Also used : TaskQuartzImpl(com.evolveum.midpoint.task.quartzimpl.TaskQuartzImpl)

Example 13 with TaskQuartzImpl

use of com.evolveum.midpoint.task.quartzimpl.TaskQuartzImpl in project midpoint by Evolveum.

the class UnpauseHelper method unpauseDependentsIfPossible.

/**
 * Caller must ensure that the task is closed or deleted!
 */
void unpauseDependentsIfPossible(TaskQuartzImpl task, OperationResult result) throws SchemaException, ObjectNotFoundException {
    LOGGER.debug("unpauseDependentsIfPossible starting for {}", task);
    int unpaused = 0;
    List<Task> dependents = task.listDependents(result);
    LOGGER.debug("dependents: {}", dependents);
    for (Task dependent : dependents) {
        if (unpauseTaskIfPossible((TaskQuartzImpl) dependent, result)) {
            unpaused++;
        }
    }
    TaskQuartzImpl parentTask = task.getParentTask(result);
    LOGGER.debug("parent: {}", parentTask);
    if (parentTask != null) {
        if (unpauseTaskIfPossible(parentTask, result)) {
            unpaused++;
        }
    }
    LOGGER.debug("unpauseDependentsIfPossible finished for {}; unpaused {} task(s)", task, unpaused);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) TaskQuartzImpl(com.evolveum.midpoint.task.quartzimpl.TaskQuartzImpl)

Example 14 with TaskQuartzImpl

use of com.evolveum.midpoint.task.quartzimpl.TaskQuartzImpl in project midpoint by Evolveum.

the class UnpauseHelper method unpauseTaskIfPossible.

/**
 * @return true if unpaused
 */
boolean unpauseTaskIfPossible(TaskQuartzImpl task, OperationResult result) throws SchemaException, ObjectNotFoundException {
    if (task.getSchedulingState() != TaskSchedulingStateType.WAITING || task.getWaitingReason() != TaskWaitingReasonType.OTHER_TASKS) {
        LOGGER.debug("Not considering task for unpausing {} because the state does not match: {}/{}", task, task.getSchedulingState(), task.getWaitingReason());
        return false;
    }
    List<TaskQuartzImpl> allPrerequisites = task.listSubtasks(result);
    allPrerequisites.addAll(taskRetriever.listPrerequisiteTasks(task, result));
    LOGGER.trace("Checking {} prerequisites for waiting task {}", allPrerequisites.size(), task);
    for (Task prerequisite : allPrerequisites) {
        if (!prerequisite.isClosed()) {
            LOGGER.debug("Prerequisite {} of {} is not closed (scheduling state = {})", prerequisite, task, prerequisite.getSchedulingState());
            return false;
        }
    }
    LOGGER.debug("All prerequisites of {} are closed, unpausing the task", task);
    try {
        return unpauseTask(task, result);
    } catch (PreconditionViolationException e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Task cannot be unpaused because it is no longer in WAITING state -- ignoring", e, this);
        return false;
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) TaskQuartzImpl(com.evolveum.midpoint.task.quartzimpl.TaskQuartzImpl) PreconditionViolationException(com.evolveum.midpoint.repo.api.PreconditionViolationException)

Example 15 with TaskQuartzImpl

use of com.evolveum.midpoint.task.quartzimpl.TaskQuartzImpl in project midpoint by Evolveum.

the class JobExecutor method interrupt.

@Override
public void interrupt() throws UnableToInterruptJobException {
    LOGGER.trace("Trying to shut down the task " + task + ", executing in thread " + executingThread);
    boolean interruptsAlways = taskManagerImpl.getConfiguration().getUseThreadInterrupt() == UseThreadInterrupt.ALWAYS;
    boolean interruptsMaybe = taskManagerImpl.getConfiguration().getUseThreadInterrupt() != UseThreadInterrupt.NEVER;
    if (task != null) {
        task.unsetCanRun();
        for (Task subtask : task.getRunningLightweightAsynchronousSubtasks()) {
            TaskQuartzImpl subtaskq = (TaskQuartzImpl) subtask;
            subtaskq.unsetCanRun();
            // if we want to cancel the Future using interrupts, we have to do it now
            // because after calling cancel(false) subsequent calls to cancel(true) have no effect whatsoever
            subtaskq.getLightweightHandlerFuture().cancel(interruptsMaybe);
        }
    }
    if (interruptsAlways) {
        // subtasks were interrupted by their futures
        sendThreadInterrupt(false);
    }
}
Also used : TaskQuartzImpl(com.evolveum.midpoint.task.quartzimpl.TaskQuartzImpl)

Aggregations

TaskQuartzImpl (com.evolveum.midpoint.task.quartzimpl.TaskQuartzImpl)24 ArrayList (java.util.ArrayList)5 PrismObject (com.evolveum.midpoint.prism.PrismObject)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 Task (com.evolveum.midpoint.task.api.Task)4 NotNull (org.jetbrains.annotations.NotNull)4 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 TaskType (com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType)3 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)2 HashSet (java.util.HashSet)2 JobKey (org.quartz.JobKey)2 Scheduler (org.quartz.Scheduler)2 SchedulerException (org.quartz.SchedulerException)2 PreconditionViolationException (com.evolveum.midpoint.repo.api.PreconditionViolationException)1 IterationItemInformation (com.evolveum.midpoint.schema.statistics.IterationItemInformation)1 IterativeOperationStartInfo (com.evolveum.midpoint.schema.statistics.IterativeOperationStartInfo)1 Operation (com.evolveum.midpoint.schema.statistics.Operation)1 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)1 RunningTask (com.evolveum.midpoint.task.api.RunningTask)1