Search in sources :

Example 1 with SPMTask

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);
    }
}
Also used : SPMTask(org.ovirt.engine.core.bll.tasks.interfaces.SPMTask) Guid(org.ovirt.engine.core.compat.Guid) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashSet(java.util.HashSet)

Example 2 with SPMTask

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);
            }
        }
    }
}
Also used : SPMTask(org.ovirt.engine.core.bll.tasks.interfaces.SPMTask)

Example 3 with SPMTask

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());
        }
    }
}
Also used : AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus) SPMTask(org.ovirt.engine.core.bll.tasks.interfaces.SPMTask) Guid(org.ovirt.engine.core.compat.Guid)

Example 4 with SPMTask

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);
}
Also used : AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus) AsyncTaskCreationInfo(org.ovirt.engine.core.common.asynctasks.AsyncTaskCreationInfo) SPMTask(org.ovirt.engine.core.bll.tasks.interfaces.SPMTask)

Example 5 with SPMTask

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);
            }
        }
    }
}
Also used : AuditLogable(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogable) SPMTask(org.ovirt.engine.core.bll.tasks.interfaces.SPMTask) AuditLogableImpl(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableImpl)

Aggregations

SPMTask (org.ovirt.engine.core.bll.tasks.interfaces.SPMTask)6 AsyncTaskCreationInfo (org.ovirt.engine.core.common.asynctasks.AsyncTaskCreationInfo)2 AsyncTaskStatus (org.ovirt.engine.core.common.businessentities.AsyncTaskStatus)2 Guid (org.ovirt.engine.core.compat.Guid)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AsyncTask (org.ovirt.engine.core.common.businessentities.AsyncTask)1 EngineException (org.ovirt.engine.core.common.errors.EngineException)1 AuditLogable (org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogable)1 AuditLogableImpl (org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableImpl)1