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