Search in sources :

Example 11 with CommandEntity

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

the class CommandsCacheImpl method initializeCache.

private void initializeCache() {
    if (!cacheInitialized) {
        synchronized (LOCK) {
            if (!cacheInitialized) {
                List<CommandEntity> cmdEntities = commandEntityDao.getAll();
                for (CommandEntity cmdEntity : cmdEntities) {
                    commandMap.put(cmdEntity.getId(), cmdEntity);
                }
                cacheInitialized = true;
            }
        }
    }
}
Also used : CommandEntity(org.ovirt.engine.core.common.businessentities.CommandEntity)

Example 12 with CommandEntity

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

the class CommandsCacheImpl method updateCallbackNotified.

@Override
public void updateCallbackNotified(final Guid commandId) {
    CommandEntity cmdEntity = get(commandId);
    if (cmdEntity != null) {
        cmdEntity.setCallbackNotified(true);
        commandEntityDao.updateNotified(commandId);
    }
}
Also used : CommandEntity(org.ovirt.engine.core.common.businessentities.CommandEntity)

Example 13 with CommandEntity

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

the class CommandsRepository method markExpiredCommandAsFailure.

private void markExpiredCommandAsFailure(Guid cmdId) {
    CommandEntity cmdEntity = getCommandEntity(cmdId);
    if (cmdEntity != null && cmdEntity.getCommandStatus() == CommandStatus.ACTIVE) {
        Calendar cal = Calendar.getInstance();
        Integer cmdLifeTimeInMin = cmdEntity.getCommandParameters().getLifeInMinutes();
        cal.add(Calendar.MINUTE, -1 * (cmdLifeTimeInMin == null ? Config.<Integer>getValue(ConfigValues.CoCoLifeInMinutes) : cmdLifeTimeInMin));
        if (cmdEntity.getCreatedAt().getTime() < cal.getTime().getTime()) {
            log.warn("Marking expired command as Failed: command '{} ({})' that started at '{}' has been marked as Failed.", cmdEntity.getCommandType(), cmdEntity.getId(), cmdEntity.getCreatedAt());
            updateCommandStatus(cmdId, CommandStatus.FAILED);
        }
    }
}
Also used : Calendar(java.util.Calendar) CommandEntity(org.ovirt.engine.core.common.businessentities.CommandEntity)

Example 14 with CommandEntity

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

the class CommandsRepository method getCommandIdsBySessionSeqId.

public List<Guid> getCommandIdsBySessionSeqId(long engineSessionSeqId) {
    List<Guid> cmdIds = new ArrayList<>();
    CommandEntity cmdEntity;
    for (Guid cmdId : commandsCache.keySet()) {
        cmdEntity = commandsCache.get(cmdId);
        if (cmdEntity != null && cmdEntity.getEngineSessionSeqId() != SsoSessionUtils.EMPTY_SESSION_SEQ_ID && cmdEntity.getEngineSessionSeqId() == engineSessionSeqId) {
            cmdIds.add(cmdId);
        }
    }
    return cmdIds;
}
Also used : ArrayList(java.util.ArrayList) CommandEntity(org.ovirt.engine.core.common.businessentities.CommandEntity) Guid(org.ovirt.engine.core.compat.Guid)

Example 15 with CommandEntity

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

the class SPMAsyncTask method handleEndedTask.

/**
 * Handle ended task operation. Change task state to Ended ,Cleared or
 * Cleared Failed , and log appropriate message.
 */
private void handleEndedTask() {
    AsyncTask asyncTask = getParameters().getDbAsyncTask();
    log.debug("Task of command {} with id '{}' has ended.", asyncTask.getActionType(), getCommandId());
    // last access time to now.
    if (getState() != AsyncTaskState.Ended) {
        setState(AsyncTaskState.Ended);
        setLastStatusAccessTime();
    }
    CommandEntity rootCmdEntity = coco.getCommandEntity(asyncTask.getRootCommandId());
    // if the task's root command has failed
    if (rootCmdEntity != null && !rootCmdEntity.isExecuted()) {
        // mark it as a task of a partially completed command
        // Will result in failure of the command
        setPartiallyCompletedCommandTask(true);
        log.debug("Marking task of command {} with id '{}' as partially completed.", asyncTask.getActionType(), getCommandId());
    }
    // Fail zombie task and task that belongs to a partially submitted command
    if (isZombieTask() || isPartiallyCompletedCommandTask()) {
        log.debug("Task of command {} with id '{}' is a zombie or is partially completed, executing failure logic.", asyncTask.getActionType(), getCommandId());
        getParameters().getDbAsyncTask().getTaskParameters().setTaskGroupSuccess(false);
        ExecutionHandler.getInstance().endTaskStep(parameters.getDbAsyncTask().getStepId(), JobExecutionStatus.FAILED);
        onTaskEndFailure();
    }
    if (hasTaskEndedSuccessfully()) {
        log.debug("Task of command {} with id '{}' has succeeded, executing success logic.", asyncTask.getActionType(), getCommandId());
        ExecutionHandler.getInstance().endTaskStep(parameters.getDbAsyncTask().getStepId(), JobExecutionStatus.FINISHED);
        onTaskEndSuccess();
    } else if (hasTaskEndedInFailure()) {
        log.debug("Task of command {} with id '{}' has failed, executing failure logic.", asyncTask.getActionType(), getCommandId());
        ExecutionHandler.getInstance().endTaskStep(parameters.getDbAsyncTask().getStepId(), JobExecutionStatus.FAILED);
        onTaskEndFailure();
    } else if (!doesTaskExist()) {
        log.debug("Task of command {} with id '{}' does not exist, executing cleanup logic.", asyncTask.getActionType(), getCommandId());
        ExecutionHandler.getInstance().endTaskStep(parameters.getDbAsyncTask().getStepId(), JobExecutionStatus.UNKNOWN);
        onTaskDoesNotExist();
    }
}
Also used : AsyncTask(org.ovirt.engine.core.common.businessentities.AsyncTask) CommandEntity(org.ovirt.engine.core.common.businessentities.CommandEntity)

Aggregations

CommandEntity (org.ovirt.engine.core.common.businessentities.CommandEntity)25 Guid (org.ovirt.engine.core.compat.Guid)7 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Transaction (javax.transaction.Transaction)2 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)2 CommandAssociatedEntity (org.ovirt.engine.core.common.businessentities.CommandAssociatedEntity)2 Serializable (java.io.Serializable)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 CommandCallback (org.ovirt.engine.core.bll.tasks.interfaces.CommandCallback)1 HostJobCommandParameters (org.ovirt.engine.core.common.action.HostJobCommandParameters)1 AsyncTask (org.ovirt.engine.core.common.businessentities.AsyncTask)1 HostJobInfo (org.ovirt.engine.core.common.businessentities.HostJobInfo)1 HostJobStatus (org.ovirt.engine.core.common.businessentities.HostJobInfo.HostJobStatus)1 VDS (org.ovirt.engine.core.common.businessentities.VDS)1 CommandStatus (org.ovirt.engine.core.compat.CommandStatus)1