use of org.ovirt.engine.core.bll.tasks.interfaces.SPMTask in project ovirt-engine by oVirt.
the class AsyncTaskManager method removeClearedAndOldTasks.
/**
* get list of pools that have only cleared and old tasks (which don't exist
* anymore in the manager):
*/
private synchronized void removeClearedAndOldTasks() {
Set<Guid> poolsOfActiveTasks = new HashSet<>();
Set<Guid> poolsOfClearedAndOldTasks = new HashSet<>();
ConcurrentMap<Guid, SPMTask> activeTaskMap = new ConcurrentHashMap<>();
for (SPMTask task : tasks.values()) {
if (!cachingOver(task)) {
activeTaskMap.put(task.getVdsmTaskId(), task);
poolsOfActiveTasks.add(task.getStoragePoolID());
} else {
poolsOfClearedAndOldTasks.add(task.getStoragePoolID());
}
}
// Check if tasks need to be updated with less tasks (activated tasks).
if (poolsOfClearedAndOldTasks.size() > 0) {
setNewMap(activeTaskMap);
poolsOfClearedAndOldTasks.removeAll(poolsOfActiveTasks);
}
for (Guid storagePoolID : poolsOfClearedAndOldTasks) {
log.info("Cleared all tasks of pool '{}'.", storagePoolID);
}
}
use of org.ovirt.engine.core.bll.tasks.interfaces.SPMTask in project ovirt-engine by oVirt.
the class AsyncTaskManager method addTaskToManager.
private void addTaskToManager(SPMTask task) {
if (task == null) {
log.error("Cannot add a null task.");
} else {
if (!tasks.containsKey(task.getVdsmTaskId())) {
log.info("Adding task '{}' (Parent Command '{}', Parameters Type '{}'), {}.", task.getVdsmTaskId(), task.getParameters().getDbAsyncTask().getActionType(), task.getParameters().getClass().getName(), task.getShouldPoll() ? "polling started." : "polling hasn't started yet.");
// Set the indication to true for logging tasks status on next
// execution.
addTaskToMap(task.getVdsmTaskId(), task);
} else {
SPMTask existingTask = tasks.get(task.getVdsmTaskId());
if (existingTask.getParameters().getDbAsyncTask().getActionType() == ActionType.Unknown && task.getParameters().getDbAsyncTask().getActionType() != ActionType.Unknown) {
log.info("Task '{}' already exists with action type 'Unknown', now overriding it with action type '{}'", task.getVdsmTaskId(), task.getParameters().getDbAsyncTask().getActionType());
// Set the indication to true for logging tasks status on
// next execution.
addTaskToMap(task.getVdsmTaskId(), task);
}
}
}
}
use of org.ovirt.engine.core.bll.tasks.interfaces.SPMTask in project ovirt-engine by oVirt.
the class AsyncTaskManager method updateTaskStatuses.
/**
* Update task status based on asyncTaskMap.
*
* @param poolsAllTasksMap Task statuses Map fetched from VDSM.
*/
private void updateTaskStatuses(Map<Guid, Map<Guid, AsyncTaskStatus>> poolsAllTasksMap) {
for (SPMTask task : tasks.values()) {
if (task.getShouldPoll()) {
Map<Guid, AsyncTaskStatus> asyncTasksForPoolMap = poolsAllTasksMap.get(task.getStoragePoolID());
// If the storage pool id exists
if (asyncTasksForPoolMap != null) {
AsyncTaskStatus cachedAsyncTaskStatus = asyncTasksForPoolMap.get(task.getVdsmTaskId());
log.debug("Updating task of command {} with id '{}' to status '{}'.", task.getParameters().getDbAsyncTask().getActionType(), task.getCommandId(), cachedAsyncTaskStatus);
// task found in VDSM.
task.updateTask(cachedAsyncTaskStatus);
}
} else {
log.debug("Not updating task of command {} with id '{}' and status '{}'.", task.getParameters().getDbAsyncTask().getActionType(), task.getCommandId(), task.getLastTaskStatus());
}
}
}
use of org.ovirt.engine.core.bll.tasks.interfaces.SPMTask in project ovirt-engine by oVirt.
the class AsyncTaskManager method logAndFailPartiallySubmittedTaskOfCommand.
public void logAndFailPartiallySubmittedTaskOfCommand(final AsyncTask task, String message) {
log.info("Failing partially submitted task AsyncTaskType '{}': Task '{}' Parent Command '{}'", task.getTaskType(), task.getTaskId(), task.getActionType());
task.getTaskParameters().setTaskGroupSuccess(false);
if (task.getActionType() == ActionType.Unknown) {
removeTaskFromDbByTaskId(task.getTaskId());
log.info("Not calling endAction for partially submitted task and AsyncTaskType '{}': Task '{}' Parent Command '{}'", task.getTaskType(), task.getTaskId(), task.getActionType());
return;
}
log.info("Calling updateTask for partially submitted task and AsyncTaskType '{}': Task '{}' Parent Command" + " '{}' Parameters class '{}'", task.getTaskType(), task.getTaskId(), task.getActionType());
AsyncTaskCreationInfo creationInfo = new AsyncTaskCreationInfo(Guid.Empty, task.getTaskType(), task.getStoragePoolId());
SPMTask spmTask = coco.construct(creationInfo, task);
AsyncTaskStatus failureStatus = new AsyncTaskStatus();
failureStatus.setStatus(AsyncTaskStatusEnum.finished);
failureStatus.setResult(AsyncTaskResultEnum.failure);
failureStatus.setMessage(message);
spmTask.setState(AsyncTaskState.Ended);
spmTask.setLastTaskStatus(failureStatus);
spmTask.updateTask(failureStatus);
}
use of org.ovirt.engine.core.bll.tasks.interfaces.SPMTask in project ovirt-engine by oVirt.
the class AsyncTaskManager method cleanZombieTasks.
private void cleanZombieTasks() {
long maxTime = DateTime.getNow().addMinutes(-1 * Config.<Integer>getValue(ConfigValues.AsyncTaskZombieTaskLifeInMinutes)).getTime();
for (SPMTask task : tasks.values()) {
if (task.getParameters().getDbAsyncTask().getStartTime().getTime() < maxTime) {
AuditLogable logable = new AuditLogableImpl();
logable.addCustomValue("CommandName", task.getParameters().getDbAsyncTask().getActionType().toString());
logable.addCustomValue("Date", task.getParameters().getDbAsyncTask().getStartTime().toString());
// status
if (task.getLastTaskStatus().getStatus() != AsyncTaskStatusEnum.finished && task.getLastTaskStatus().getStatus() != AsyncTaskStatusEnum.unknown) {
// mark it as a zombie task, Will result in failure of the command
task.setZombieTask(true);
auditLogDirector.log(logable, AuditLogType.TASK_STOPPING_ASYNC_TASK);
log.info("Cleaning zombie tasks: Stopping async task '{}' that started at '{}'", task.getParameters().getDbAsyncTask().getActionType(), task.getParameters().getDbAsyncTask().getStartTime());
task.stopTask(true);
} else {
auditLogDirector.log(logable, AuditLogType.TASK_CLEARING_ASYNC_TASK);
log.info("Cleaning zombie tasks: Clearing async task '{}' that started at '{}'", task.getParameters().getDbAsyncTask().getActionType(), task.getParameters().getDbAsyncTask().getStartTime());
task.clearAsyncTask(true);
}
}
}
}
Aggregations