Search in sources :

Example 16 with CommandEntity

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

the class HostJobCallback method childCommandsExecutionEnded.

@Override
protected void childCommandsExecutionEnded(CommandBase<?> command, boolean anyFailed, List<Guid> childCmdIds, CommandExecutionStatus status, int completedChildren) {
    Guid cmdId = command.getCommandId();
    CommandEntity commandEntity = commandCoordinatorUtil.getCommandEntity(cmdId);
    ActionParametersBase cmdParams = commandEntity.getCommandParameters();
    Guid job = ((HostJobCommandParameters) cmdParams).getHostJobId();
    HostJobStatus jobStatus = null;
    Guid vdsId = cmdParams.getVdsRunningOn();
    VDS vds = getVdsDao().get(vdsId);
    if (vds != null) {
        boolean jobsReportedByHost = false;
        if (vds.getStatus() == VDSStatus.Up) {
            HostJobInfo jobInfo;
            try {
                jobInfo = pollStorageJob(job, vdsId);
            } catch (Exception e) {
                // We shouldn't get an error when polling the host job (as it access the local storage only).
                // If we got an error, it will usually be a network error - so the host will either move
                // to Non Responsive or the polling will succeed on the next attempt.
                log.warn("Command {} id: '{}': Failed to poll the job '{}' on host '{}' (id: '{}'), will retry soon", commandEntity.getCommandType(), cmdId, job, vds.getName(), vdsId);
                return;
            }
            if (jobInfo != null) {
                handlePolledJobInfo(getCommand(cmdId), jobInfo);
                jobStatus = jobInfo.getStatus();
                updateStepProgress(commandEntity.getCommandContext().getStepId(), jobInfo.getProgress());
            }
            jobsReportedByHost = true;
        } else {
            log.warn("Command {} id: '{}': can't poll the job '{}' as host '{}' (id: '{}') isn't in status UP", commandEntity.getCommandType(), cmdId, job, vds.getName(), vdsId);
        }
        // If we couldn't determine job status by polling the host, we can try to determine it using different methods.
        if (jobStatus == null) {
            jobStatus = handleUndeterminedJobStatus(getCommand(cmdId), jobsReportedByHost);
        }
        if (jobStatus == null) {
            log.info("Command {} id: '{}': couldn't get the status of job '{}' on host '{}' (id: '{}'), assuming it's " + "still running", commandEntity.getCommandType(), cmdId, job, vds.getName(), vdsId);
            return;
        }
        if (jobStatus.isAlive()) {
            log.info("Command {} id: '{}': waiting for job '{}' on host '{}' (id: '{}') to complete", commandEntity.getCommandType(), cmdId, job, vds.getName(), vdsId);
            return;
        }
        log.info("Command {} id: '{}': job '{}' execution was completed with VDSM job status '{}'", commandEntity.getCommandType(), cmdId, job, jobStatus);
        if (command.shouldUpdateStepProgress() && jobStatus == HostJobStatus.done) {
            updateStepProgress(commandEntity.getCommandContext().getStepId(), MAX_PROGRESS);
        }
    } else {
        jobStatus = HostJobStatus.failed;
        log.info("Command {} id: '{}': job '{}' wasn't executed on any host, considering the job status as failed", commandEntity.getCommandType(), cmdId, job);
    }
    command.getParameters().setTaskGroupSuccess(status == CommandExecutionStatus.EXECUTED && jobStatus == HostJobStatus.done);
    command.setCommandStatus(command.getParameters().getTaskGroupSuccess() ? CommandStatus.SUCCEEDED : CommandStatus.FAILED);
    log.info("Command {} id: '{}': execution was completed, the command status is '{}'", command.getActionType(), command.getCommandId(), command.getCommandStatus());
}
Also used : HostJobStatus(org.ovirt.engine.core.common.businessentities.HostJobInfo.HostJobStatus) VDS(org.ovirt.engine.core.common.businessentities.VDS) CommandEntity(org.ovirt.engine.core.common.businessentities.CommandEntity) Guid(org.ovirt.engine.core.compat.Guid) HostJobInfo(org.ovirt.engine.core.common.businessentities.HostJobInfo) HostJobCommandParameters(org.ovirt.engine.core.common.action.HostJobCommandParameters) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase)

Example 17 with CommandEntity

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

the class CommandEntityDaoTest method testGetCommandIdsByEntity.

@Test
public void testGetCommandIdsByEntity() {
    Guid storageId = Guid.newGuid();
    CommandEntity cmdEntity1 = generateNewEntity();
    dao.save(cmdEntity1);
    Set<CommandAssociatedEntity> cocoCmdEntities1 = new HashSet<>();
    cocoCmdEntities1.add(new CommandAssociatedEntity(cmdEntity1.getId(), VdcObjectType.Storage, storageId));
    cocoCmdEntities1.add(new CommandAssociatedEntity(cmdEntity1.getId(), VdcObjectType.Disk, Guid.newGuid()));
    dao.insertCommandAssociatedEntities(cocoCmdEntities1);
    CommandEntity cmdEntity2 = generateNewEntity();
    dao.save(cmdEntity2);
    Set<CommandAssociatedEntity> cocoCmdEntities2 = new HashSet<>();
    cocoCmdEntities2.add(new CommandAssociatedEntity(cmdEntity2.getId(), VdcObjectType.Storage, storageId));
    cocoCmdEntities2.add(new CommandAssociatedEntity(cmdEntity2.getId(), VdcObjectType.Disk, Guid.newGuid()));
    dao.insertCommandAssociatedEntities(cocoCmdEntities2);
    List<Guid> cmIds = dao.getCommandIdsByEntity(storageId);
    assertNotNull(cmIds);
    assertThat(cmIds, hasSize(2));
    assertThat(cmIds, hasItems(cmdEntity1.getId(), cmdEntity2.getId()));
}
Also used : CommandAssociatedEntity(org.ovirt.engine.core.common.businessentities.CommandAssociatedEntity) CommandEntity(org.ovirt.engine.core.common.businessentities.CommandEntity) Guid(org.ovirt.engine.core.compat.Guid) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 18 with CommandEntity

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

the class CommandEntityDaoTest method generateNewEntity.

@Override
protected CommandEntity generateNewEntity() {
    Map<String, Serializable> data = new HashMap<>();
    data.put("NEXT_COMMAND_TYPE", ActionType.DestroyImage);
    CommandEntity commandEntity = new CommandEntity();
    commandEntity.setCommandType(ActionType.AddCluster);
    commandEntity.setCreatedAt(new Date(System.currentTimeMillis()));
    commandEntity.setId(Guid.newGuid());
    commandEntity.setCommandStatus(CommandStatus.ACTIVE);
    commandEntity.setData(data);
    ActionParametersBase params = new ActionParametersBase();
    commandEntity.setCommandParameters(params);
    return commandEntity;
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) CommandEntity(org.ovirt.engine.core.common.businessentities.CommandEntity) Date(java.util.Date) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase)

Example 19 with CommandEntity

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

the class CoCoAsyncTaskHelper method getParentCommandEntity.

private CommandEntity getParentCommandEntity(Guid cmdId, ActionType actionType, ActionParametersBase parameters) {
    CommandEntity cmdEntity = coco.get().getCommandEntity(cmdId);
    if (cmdEntity == null) {
        cmdEntity = createCommandEntity(cmdId, actionType, parameters);
        if (!Guid.isNullOrEmpty(cmdId)) {
            cmdEntity.setCommandStatus(CommandStatus.ACTIVE);
            coco.get().persistCommand(cmdEntity);
        }
    }
    return cmdEntity;
}
Also used : CommandEntity(org.ovirt.engine.core.common.businessentities.CommandEntity)

Example 20 with CommandEntity

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

the class CoCoAsyncTaskHelper method createCommandEntity.

public CommandEntity createCommandEntity(Guid cmdId, ActionType actionType, ActionParametersBase params) {
    CommandEntity cmdEntity = new CommandEntity();
    cmdEntity.setId(cmdId);
    cmdEntity.setCommandType(actionType);
    cmdEntity.setCommandParameters(params);
    return cmdEntity;
}
Also used : 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