Search in sources :

Example 6 with AsyncTask

use of org.ovirt.engine.core.common.businessentities.AsyncTask in project ovirt-engine by oVirt.

the class AsyncTaskFactory method construct.

/**
 * Constructs a task based on creation info (task type and task parameters
 * as retrieved from the vdsm). Use in order to construct tasks when service
 * is initializing.
 * @param creationInfo
 *          The Asyc Task Creation info
 */
public SPMAsyncTask construct(AsyncTaskCreationInfo creationInfo) {
    CommandCoordinator coco = cocoInstance.get();
    AsyncTask asyncTask = coco.getByVdsmTaskId(creationInfo.getVdsmTaskId());
    if (asyncTask == null || asyncTask.getActionParameters() == null) {
        asyncTask = new AsyncTask(AsyncTaskResultEnum.success, AsyncTaskStatusEnum.running, Guid.Empty, creationInfo.getVdsmTaskId(), creationInfo.getStepId(), creationInfo.getStoragePoolID(), creationInfo.getTaskType(), getCommandEntity(coco, asyncTask == null ? Guid.newGuid() : asyncTask.getRootCommandId()), getCommandEntity(coco, asyncTask == null ? Guid.newGuid() : asyncTask.getCommandId()));
        creationInfo.setTaskType(AsyncTaskType.unknown);
    }
    AsyncTaskParameters asyncTaskParams = new AsyncTaskParameters(creationInfo, asyncTask);
    return construct(creationInfo.getTaskType(), asyncTaskParams, true);
}
Also used : CommandCoordinator(org.ovirt.engine.core.bll.tasks.interfaces.CommandCoordinator) AsyncTask(org.ovirt.engine.core.common.businessentities.AsyncTask) AsyncTaskParameters(org.ovirt.engine.core.common.asynctasks.AsyncTaskParameters)

Example 7 with AsyncTask

use of org.ovirt.engine.core.common.businessentities.AsyncTask in project ovirt-engine by oVirt.

the class CoCoAsyncTaskHelper method getAllAsyncTasksFromDb.

public List<AsyncTask> getAllAsyncTasksFromDb() {
    List<AsyncTask> asyncTasks = DbFacade.getInstance().getAsyncTaskDao().getAll();
    for (AsyncTask asyncTask : asyncTasks) {
        asyncTask.setRootCmdEntity(getCommandEntity(asyncTask.getRootCommandId()));
        asyncTask.setChildCmdEntity(getCommandEntity(asyncTask.getCommandId()));
    }
    return asyncTasks;
}
Also used : AsyncTask(org.ovirt.engine.core.common.businessentities.AsyncTask)

Example 8 with AsyncTask

use of org.ovirt.engine.core.common.businessentities.AsyncTask in project ovirt-engine by oVirt.

the class CoCoAsyncTaskHelper method getAsyncTask.

public AsyncTask getAsyncTask(Guid taskId, CommandBase<?> command, AsyncTaskCreationInfo asyncTaskCreationInfo, ActionType parentCommand) {
    AsyncTask asyncTask = null;
    if (!taskId.equals(Guid.Empty)) {
        asyncTask = getAsyncTaskFromDb(taskId);
    }
    if (asyncTask != null) {
        ActionParametersBase parentParameters = command.getParentParameters() == null ? command.getParentParameters(parentCommand) : command.getParentParameters();
        Guid parentCommandId = parentParameters == null ? Guid.Empty : parentParameters.getCommandId();
        if (ActionType.Unknown.equals(command.getParameters().getCommandType())) {
            command.getParameters().setCommandType(command.getActionType());
        }
        asyncTask.setActionType(parentCommand);
        asyncTask.setVdsmTaskId(asyncTaskCreationInfo.getVdsmTaskId());
        asyncTask.setActionParameters(parentParameters);
        asyncTask.setTaskParameters(command.getParameters());
        asyncTask.setStepId(asyncTaskCreationInfo.getStepId());
        asyncTask.setCommandId(command.getCommandId());
        asyncTask.setRootCmdEntity(getParentCommandEntity(parentCommandId, parentCommand, parentParameters));
        asyncTask.setChildCmdEntity(getChildCommandEntity(command, parentCommand));
        asyncTask.setStoragePoolId(asyncTaskCreationInfo.getStoragePoolID());
        asyncTask.setTaskType(asyncTaskCreationInfo.getTaskType());
        asyncTask.setCommandStatus(command.getCommandStatus());
        asyncTask.setCommandType(command.getParameters().getCommandType());
    } else {
        asyncTask = createAsyncTask(command, asyncTaskCreationInfo, parentCommand);
    }
    return asyncTask;
}
Also used : AsyncTask(org.ovirt.engine.core.common.businessentities.AsyncTask) Guid(org.ovirt.engine.core.compat.Guid) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase)

Example 9 with AsyncTask

use of org.ovirt.engine.core.common.businessentities.AsyncTask in project ovirt-engine by oVirt.

the class CoCoAsyncTaskHelper method removeByVdsmTaskId.

public int removeByVdsmTaskId(final Guid vdsmTaskId) {
    return TransactionSupport.executeInScope(TransactionScopeOption.Required, () -> {
        AsyncTask asyncTask = DbFacade.getInstance().getAsyncTaskDao().getByVdsmTaskId(vdsmTaskId);
        int retVal = DbFacade.getInstance().getAsyncTaskDao().removeByVdsmTaskId(vdsmTaskId);
        if (shouldRemoveCommand(asyncTask)) {
            coco.get().removeCommand(asyncTask.getCommandId());
            if (!coco.get().hasCommandEntitiesWithRootCommandId(asyncTask.getRootCommandId())) {
                coco.get().removeCommand(asyncTask.getRootCommandId());
            }
        }
        return retVal;
    });
}
Also used : AsyncTask(org.ovirt.engine.core.common.businessentities.AsyncTask)

Example 10 with AsyncTask

use of org.ovirt.engine.core.common.businessentities.AsyncTask in project ovirt-engine by oVirt.

the class CoCoAsyncTaskHelper method endAction.

public ActionReturnValue endAction(SPMTask task) {
    AsyncTask dbAsyncTask = task.getParameters().getDbAsyncTask();
    ActionType actionType = getEndActionType(dbAsyncTask);
    ActionParametersBase parameters = dbAsyncTask.getActionParameters();
    CommandBase<?> command = CommandHelper.buildCommand(actionType, parameters, coco.get().retrieveCommandContext(dbAsyncTask.getRootCommandId()).getExecutionContext(), coco.get().getCommandStatus(dbAsyncTask.getCommandId()));
    return new DecoratedCommand<>(command).endAction();
}
Also used : ActionType(org.ovirt.engine.core.common.action.ActionType) AsyncTask(org.ovirt.engine.core.common.businessentities.AsyncTask) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase)

Aggregations

AsyncTask (org.ovirt.engine.core.common.businessentities.AsyncTask)24 Test (org.junit.Test)8 Guid (org.ovirt.engine.core.compat.Guid)7 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)5 ArrayList (java.util.ArrayList)4 AsyncTaskCreationInfo (org.ovirt.engine.core.common.asynctasks.AsyncTaskCreationInfo)2 EngineException (org.ovirt.engine.core.common.errors.EngineException)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Before (org.junit.Before)1 CommandMultiAsyncTasks (org.ovirt.engine.core.bll.CommandMultiAsyncTasks)1 ExecutionContext (org.ovirt.engine.core.bll.job.ExecutionContext)1 CommandCoordinator (org.ovirt.engine.core.bll.tasks.interfaces.CommandCoordinator)1 SPMTask (org.ovirt.engine.core.bll.tasks.interfaces.SPMTask)1 MultipleVmsValidator (org.ovirt.engine.core.bll.validator.MultipleVmsValidator)1 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)1 ActionType (org.ovirt.engine.core.common.action.ActionType)1