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