Search in sources :

Example 26 with AsyncTaskStatus

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

the class BackendCreationResourceTest method getTaskStatus.

protected AsyncTaskStatus getTaskStatus() {
    AsyncTaskStatus status = new AsyncTaskStatus();
    status.setStatus(AsyncTaskStatusEnum.finished);
    status.setResult(AsyncTaskResultEnum.success);
    return status;
}
Also used : AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus)

Example 27 with AsyncTaskStatus

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

the class SpmStopVDSCommand method executeVdsBrokerCommand.

@Override
protected void executeVdsBrokerCommand() {
    boolean lockAcquired = false;
    try {
        if (canVdsBeReached()) {
            lockAcquired = lockManager.acquireLock(retrieveVdsExecutionLock()).getFirst();
            if (!lockAcquired) {
                getVDSReturnValue().setVdsError(new VDSError(EngineError.ENGINE, "Failed to acquire vds execution lock - related operation is under execution"));
                getVDSReturnValue().setSucceeded(false);
                return;
            }
            boolean performSpmStop = true;
            Map<Guid, AsyncTaskStatus> unclearedTasks = null;
            try {
                VDSReturnValue vdsReturnValue = resourceManager.runVdsCommand(VDSCommandType.HSMGetAllTasksStatuses, new VdsIdVDSCommandParametersBase(getVds().getId()));
                if (isNotSPM(vdsReturnValue)) {
                    return;
                }
                getVDSReturnValue().setSucceeded(vdsReturnValue.getSucceeded());
                getVDSReturnValue().setVdsError(vdsReturnValue.getVdsError());
                if (vdsReturnValue.getReturnValue() != null) {
                    unclearedTasks = (HashMap<Guid, AsyncTaskStatus>) vdsReturnValue.getReturnValue();
                    performSpmStop = unclearedTasks.isEmpty();
                }
            } catch (Exception e) {
                performSpmStop = false;
                log.info("SpmStopVDSCommand::Could not get tasks on vds '{}': {}", getVds().getName(), e.getMessage());
                log.debug("Exception", e);
            }
            if (performSpmStop) {
                log.info("SpmStopVDSCommand::Stopping SPM on vds '{}', pool id '{}'", getVds().getName(), getParameters().getStoragePoolId());
                status = getBroker().spmStop(getParameters().getStoragePoolId().toString());
                proceedProxyReturnValue();
            } else {
                getVDSReturnValue().setSucceeded(false);
                if (getVDSReturnValue().getVdsError() == null) {
                    String unclearedTasksDetails = unclearedTasks.entrySet().stream().map(entry -> String.format("Task '%s', status '%s'", entry.getKey(), entry.getValue().getStatus())).collect(Collectors.joining("\n"));
                    log.error("SpmStopVDSCommand::Not stopping SPM on vds '{}', pool id '{}' as there are uncleared tasks '{}'", getVds().getName(), getParameters().getStoragePoolId(), unclearedTasksDetails);
                    VDSError error = new VDSError(EngineError.TaskInProgress, unclearedTasksDetails);
                    getVDSReturnValue().setVdsError(error);
                } else if (getVDSReturnValue().getVdsError().getCode() == EngineError.VDS_NETWORK_ERROR) {
                    log.info("SpmStopVDSCommand::Could not get tasks on vds '{}' - network exception, not stopping spm! pool id '{}'", getVds().getName(), getParameters().getStoragePoolId());
                }
            }
        } else {
            log.info("SpmStopVDSCommand:: vds '{}' is in '{}' status - not performing spm stop, pool id '{}'", getVds().getName(), getVds().getStatus(), getParameters().getStoragePoolId());
            getVDSReturnValue().setVdsError(new VDSError(EngineError.VDS_NETWORK_ERROR, "Vds is in incorrect status"));
            getVDSReturnValue().setSucceeded(false);
        }
    } catch (RuntimeException exp) {
        log.warn("Could not stop spm of pool '{}' on vds '{}': {}", getParameters().getStoragePoolId(), getParameters().getVdsId(), exp.getMessage());
        log.debug("Exception", exp);
        getVDSReturnValue().setExceptionObject(exp);
        getVDSReturnValue().setSucceeded(false);
    } finally {
        if (lockAcquired) {
            lockManager.releaseLock(retrieveVdsExecutionLock());
        }
    }
}
Also used : VdsIdVDSCommandParametersBase(org.ovirt.engine.core.common.vdscommands.VdsIdVDSCommandParametersBase) LockingGroup(org.ovirt.engine.core.common.locks.LockingGroup) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) Guid(org.ovirt.engine.core.compat.Guid) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) LockManager(org.ovirt.engine.core.utils.lock.LockManager) AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus) DbFacade(org.ovirt.engine.core.dal.dbbroker.DbFacade) EngineError(org.ovirt.engine.core.common.errors.EngineError) Inject(javax.inject.Inject) VDSStatus(org.ovirt.engine.core.common.businessentities.VDSStatus) Map(java.util.Map) VDSCommandType(org.ovirt.engine.core.common.vdscommands.VDSCommandType) Collections(java.util.Collections) VDSError(org.ovirt.engine.core.common.errors.VDSError) Pair(org.ovirt.engine.core.common.utils.Pair) SpmStopVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.SpmStopVDSCommandParameters) VdsIdVDSCommandParametersBase(org.ovirt.engine.core.common.vdscommands.VdsIdVDSCommandParametersBase) VDSError(org.ovirt.engine.core.common.errors.VDSError) AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus) Guid(org.ovirt.engine.core.compat.Guid) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 28 with AsyncTaskStatus

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

the class BackendHostResourceTest method doTestActivateAsync.

private void doTestActivateAsync(AsyncTaskStatusEnum asyncStatus, CreationStatus actionStatus) throws Exception {
    setUriInfo(setUpActionExpectations(ActionType.ActivateVds, VdsActionParameters.class, new String[] { "VdsId" }, new Object[] { GUIDS[0] }, asList(GUIDS[1]), asList(new AsyncTaskStatus(asyncStatus))));
    Response response = resource.activate(new Action());
    verifyActionResponse(response, "hosts/" + GUIDS[0], true, null);
    Action action = (Action) response.getEntity();
    assertTrue(action.isSetStatus());
    assertEquals(actionStatus.value(), action.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) Action(org.ovirt.engine.api.model.Action) AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus) VdsActionParameters(org.ovirt.engine.core.common.action.VdsActionParameters) UpdateVdsActionParameters(org.ovirt.engine.core.common.action.hostdeploy.UpdateVdsActionParameters) FenceVdsActionParameters(org.ovirt.engine.core.common.action.FenceVdsActionParameters)

Example 29 with AsyncTaskStatus

use of org.ovirt.engine.core.common.businessentities.AsyncTaskStatus 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 30 with AsyncTaskStatus

use of org.ovirt.engine.core.common.businessentities.AsyncTaskStatus 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)

Aggregations

AsyncTaskStatus (org.ovirt.engine.core.common.businessentities.AsyncTaskStatus)41 Response (javax.ws.rs.core.Response)26 Test (org.junit.Test)15 Template (org.ovirt.engine.api.model.Template)12 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)9 Action (org.ovirt.engine.api.model.Action)7 Disk (org.ovirt.engine.api.model.Disk)7 Guid (org.ovirt.engine.core.compat.Guid)7 StorageDomain (org.ovirt.engine.api.model.StorageDomain)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 CreationStatus (org.ovirt.engine.api.model.CreationStatus)3 Vm (org.ovirt.engine.api.model.Vm)3 Collections (java.util.Collections)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 Fault (org.ovirt.engine.api.model.Fault)2 SPMTask (org.ovirt.engine.core.bll.tasks.interfaces.SPMTask)2 SpmStatusResult (org.ovirt.engine.core.common.businessentities.SpmStatusResult)2