Search in sources :

Example 21 with AsyncTaskCreationInfo

use of org.ovirt.engine.core.common.asynctasks.AsyncTaskCreationInfo in project ovirt-engine by oVirt.

the class ReduceImageVDSCommand method executeIrsBrokerCommand.

@Override
protected void executeIrsBrokerCommand() {
    log.info("Executing ReduceImageVDSCommand");
    uuidReturn = getIrsProxy().reduceVolume(getParameters().getStoragePoolId().toString(), getParameters().getStorageDomainId().toString(), getParameters().getImageGroupId().toString(), getParameters().getImageId().toString(), getParameters().isAllowActive());
    proceedProxyReturnValue();
    Guid taskID = new Guid(uuidReturn.uuid);
    getVDSReturnValue().setCreationInfo(new AsyncTaskCreationInfo(taskID, AsyncTaskType.reduceImage, getParameters().getStoragePoolId()));
}
Also used : AsyncTaskCreationInfo(org.ovirt.engine.core.common.asynctasks.AsyncTaskCreationInfo) Guid(org.ovirt.engine.core.compat.Guid)

Example 22 with AsyncTaskCreationInfo

use of org.ovirt.engine.core.common.asynctasks.AsyncTaskCreationInfo 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 23 with AsyncTaskCreationInfo

use of org.ovirt.engine.core.common.asynctasks.AsyncTaskCreationInfo in project ovirt-engine by oVirt.

the class AsyncTaskManager method addStoragePoolExistingTasks.

/**
 * Retrieves from the specified storage pool the tasks that exist on it and
 * adds them to the manager.
 *
 * @param sp the storage pool to retrieve running tasks from
 */
public void addStoragePoolExistingTasks(StoragePool sp) {
    List<AsyncTaskCreationInfo> currPoolTasks = null;
    try {
        currPoolTasks = coco.getAllTasksInfo(sp.getId());
    } catch (RuntimeException e) {
        log.error("Getting existing tasks on Storage Pool '{}' failed: {}", sp.getName(), e.getMessage());
        log.debug("Exception", e);
    }
    if (currPoolTasks != null && currPoolTasks.size() > 0) {
        synchronized (this) {
            final List<SPMTask> newlyAddedTasks = new ArrayList<>();
            for (AsyncTaskCreationInfo creationInfo : currPoolTasks) {
                creationInfo.setStoragePoolID(sp.getId());
                if (!tasks.containsKey(creationInfo.getVdsmTaskId())) {
                    try {
                        SPMTask task;
                        if (partiallyCompletedCommandTasks.containsKey(creationInfo.getVdsmTaskId())) {
                            AsyncTask asyncTaskInDb = partiallyCompletedCommandTasks.get(creationInfo.getVdsmTaskId());
                            task = coco.construct(creationInfo, asyncTaskInDb);
                            if (task.getEntitiesMap() == null) {
                                task.setEntitiesMap(new HashMap<>());
                            }
                            partiallyCompletedCommandTasks.remove(task.getVdsmTaskId());
                            // mark it as a task of a partially completed command
                            // Will result in failure of the command
                            task.setPartiallyCompletedCommandTask(true);
                        } else {
                            task = asyncTaskFactory.construct(creationInfo);
                        }
                        addTaskToManager(task);
                        newlyAddedTasks.add(task);
                    } catch (Exception e) {
                        log.error("Failed to load task of type '{}' with id '{}': {}.", creationInfo.getTaskType(), creationInfo.getVdsmTaskId(), ExceptionUtils.getRootCauseMessage(e));
                        log.debug("Exception", e);
                    }
                }
            }
            TransactionSupport.executeInNewTransaction(() -> {
                for (SPMTask task : newlyAddedTasks) {
                    AsyncTaskUtils.addOrUpdateTaskInDB(coco, task);
                }
                return null;
            });
            for (SPMTask task : newlyAddedTasks) {
                startPollingTask(task.getVdsmTaskId());
            }
            log.info("Discovered {} tasks on Storage Pool '{}', {} added to manager.", currPoolTasks.size(), sp.getName(), newlyAddedTasks.size());
        }
    } else {
        log.info("Discovered no tasks on Storage Pool '{}'", sp.getName());
    }
    List<AsyncTask> tasksInDForStoragePool = tasksInDbAfterRestart.get(sp.getId());
    if (tasksInDForStoragePool != null) {
        for (AsyncTask task : tasksInDForStoragePool) {
            if (!tasks.containsKey(task.getVdsmTaskId())) {
                coco.removeByVdsmTaskId(task.getVdsmTaskId());
            }
        }
    }
    // Either the tasks were only in DB - so they were removed from db, or they are polled -
    // in any case no need to hold them in the map that represents the tasksInDbAfterRestart
    tasksInDbAfterRestart.remove(sp.getId());
}
Also used : AsyncTaskCreationInfo(org.ovirt.engine.core.common.asynctasks.AsyncTaskCreationInfo) SPMTask(org.ovirt.engine.core.bll.tasks.interfaces.SPMTask) ArrayList(java.util.ArrayList) AsyncTask(org.ovirt.engine.core.common.businessentities.AsyncTask) EngineException(org.ovirt.engine.core.common.errors.EngineException)

Example 24 with AsyncTaskCreationInfo

use of org.ovirt.engine.core.common.asynctasks.AsyncTaskCreationInfo in project ovirt-engine by oVirt.

the class CommandBase method persistAsyncTaskPlaceHolder.

public Guid persistAsyncTaskPlaceHolder(ActionType parentCommand, final String taskKey) {
    Guid taskId = Guid.Empty;
    try {
        AsyncTaskCreationInfo creationInfo = new AsyncTaskCreationInfo();
        creationInfo.setTaskType(getTaskType());
        final AsyncTask task = createAsyncTask(creationInfo, parentCommand);
        taskId = task.getTaskId();
        TransactionScopeOption scopeOption = getTransactive() ? TransactionScopeOption.RequiresNew : TransactionScopeOption.Required;
        TransactionSupport.executeInScope(scopeOption, () -> {
            saveTaskAndPutInMap(taskKey, task);
            return null;
        });
        addToReturnValueTaskPlaceHolderIdList(taskId);
    } catch (RuntimeException ex) {
        log.error("Error during persistAsyncTaskPlaceHolder for command '{}': {}", getClass().getName(), ex.getMessage());
        log.error("Exception", ex);
    }
    return taskId;
}
Also used : TransactionScopeOption(org.ovirt.engine.core.compat.TransactionScopeOption) AsyncTaskCreationInfo(org.ovirt.engine.core.common.asynctasks.AsyncTaskCreationInfo) AsyncTask(org.ovirt.engine.core.common.businessentities.AsyncTask) Guid(org.ovirt.engine.core.compat.Guid)

Aggregations

AsyncTaskCreationInfo (org.ovirt.engine.core.common.asynctasks.AsyncTaskCreationInfo)24 Guid (org.ovirt.engine.core.compat.Guid)20 ArrayList (java.util.ArrayList)2 SPMTask (org.ovirt.engine.core.bll.tasks.interfaces.SPMTask)2 AsyncTask (org.ovirt.engine.core.common.businessentities.AsyncTask)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 FutureTask (java.util.concurrent.FutureTask)1 HttpClient (org.apache.commons.httpclient.HttpClient)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 CopyImageGroupWithDataCommandParameters (org.ovirt.engine.core.common.action.CopyImageGroupWithDataCommandParameters)1 AsyncTaskType (org.ovirt.engine.core.common.asynctasks.AsyncTaskType)1 AsyncTaskStatus (org.ovirt.engine.core.common.businessentities.AsyncTaskStatus)1 EngineException (org.ovirt.engine.core.common.errors.EngineException)1 CopyImageVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.CopyImageVDSCommandParameters)1 DestroyImageVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.DestroyImageVDSCommandParameters)1 MoveImageGroupVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.MoveImageGroupVDSCommandParameters)1 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)1 TransactionScopeOption (org.ovirt.engine.core.compat.TransactionScopeOption)1 VdsManager (org.ovirt.engine.core.vdsbroker.VdsManager)1