Search in sources :

Example 31 with EntityInfo

use of org.ovirt.engine.core.common.asynctasks.EntityInfo in project ovirt-engine by oVirt.

the class StopVmCommandBase method executeVmCommand.

@Override
protected void executeVmCommand() {
    getParameters().setEntityInfo(new EntityInfo(VdcObjectType.VM, getVm().getId()));
    suspendedVm = getVm().getStatus() == VMStatus.Suspended;
    if (suspendedVm) {
        endVmCommand();
        setCommandShouldBeLogged(true);
    } else {
        super.executeVmCommand();
    }
    vmStaticDao.incrementDbGeneration(getVm().getId());
    removeMemoryDisksIfNeeded(getActiveSnapshot());
}
Also used : EntityInfo(org.ovirt.engine.core.common.asynctasks.EntityInfo)

Example 32 with EntityInfo

use of org.ovirt.engine.core.common.asynctasks.EntityInfo in project ovirt-engine by oVirt.

the class ReduceImageCommand method executeCommand.

@Override
protected void executeCommand() {
    if (getStorageDomain().getStorageType().isFileDomain()) {
        log.info("Reduce image isn't required for file based domains");
        setSucceeded(true);
        return;
    }
    if (!isReduceVolumeSupported()) {
        log.info("Reduce image isn't supported in {}", getStoragePool().getCompatibilityVersion());
        setSucceeded(true);
        return;
    }
    if (!isInternalMerge()) {
        log.info("Reduce image isn't supported for active image merge");
        setSucceeded(true);
        return;
    }
    getParameters().setEntityInfo(new EntityInfo(VdcObjectType.Disk, getParameters().getImageGroupId()));
    boolean prepareImageSucceeded = false;
    boolean reduceImageSucceeded = false;
    if (!getParameters().isVmRunningOnSpm()) {
        // The VM isn't running on the SPM but the reduce command is performed on the SPM, hence
        // we have to prepare the image on the SPM
        log.debug("Preparing image {}/{} on the SPM", getParameters().getImageGroupId(), getParameters().getImageId());
        try {
            prepareImage();
            prepareImageSucceeded = true;
        } catch (EngineException e) {
            log.error("Failed to prepare image {}/{} on the SPM", getParameters().getImageGroupId(), getParameters().getImageId());
        }
    }
    if (!getParameters().isVmRunningOnSpm() && !prepareImageSucceeded) {
        // As we don't want to fail the live merge because of a failure to reduce the image, we still mark the
        // command as succeeded.
        setSucceeded(true);
        return;
    }
    try {
        VDSReturnValue vdsReturnValue = runVdsCommand(VDSCommandType.ReduceImage, creaeteReduceImageVDSCommandParameters());
        if (vdsReturnValue.getSucceeded()) {
            Guid taskId = persistAsyncTaskPlaceHolder(getParameters().getParentCommand());
            getTaskIdList().add(createTask(taskId, vdsReturnValue.getCreationInfo(), getParameters().getParentCommand(), VdcObjectType.Storage, getParameters().getStorageDomainId()));
            reduceImageSucceeded = true;
        }
    } catch (EngineException e) {
        log.error("Reducing image {}/{} failed", getParameters().getImageGroupId(), getParameters().getImageId());
    }
    if (prepareImageSucceeded && !reduceImageSucceeded) {
        try {
            teardownImage();
        } catch (EngineException e) {
            log.error("Failed to teardown image {}/{} on the SPM", getParameters().getImageGroupId(), getParameters().getImageId());
        }
    }
    setSucceeded(true);
}
Also used : EntityInfo(org.ovirt.engine.core.common.asynctasks.EntityInfo) EngineException(org.ovirt.engine.core.common.errors.EngineException) Guid(org.ovirt.engine.core.compat.Guid) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 33 with EntityInfo

use of org.ovirt.engine.core.common.asynctasks.EntityInfo in project ovirt-engine by oVirt.

the class AddVmTemplateCommand method init.

@Override
protected void init() {
    if (Guid.isNullOrEmpty(getParameters().getVmTemplateId())) {
        getParameters().setVmTemplateId(Guid.newGuid());
    }
    setVmTemplateId(getParameters().getVmTemplateId());
    getParameters().setEntityInfo(new EntityInfo(VdcObjectType.VmTemplate, getVmTemplateId()));
    setVmTemplateName(getParameters().getName());
    VmStatic masterVm = getParameters().getMasterVm();
    if (masterVm != null) {
        setVmId(masterVm.getId());
        setClusterId(masterVm.getClusterId());
        // API backward compatibility
        if (getVmDeviceUtils().shouldOverrideSoundDevice(masterVm, getMasterVmCompatibilityVersion(), getParameters().isSoundDeviceEnabled())) {
            getParameters().setSoundDeviceEnabled(true);
        }
        if (getParameters().isSoundDeviceEnabled() == null) {
            getParameters().setSoundDeviceEnabled(false);
        }
        if (getParameters().isConsoleEnabled() == null) {
            getParameters().setConsoleEnabled(false);
        }
        vmHandler.updateDefaultTimeZone(masterVm);
        vmHandler.autoSelectUsbPolicy(masterVm);
        vmHandler.autoSelectDefaultDisplayType(getVmId(), masterVm, getCluster(), getParameters().getGraphicsDevices());
        vmHandler.autoSelectGraphicsDevice(getVmId(), masterVm, getCluster(), getParameters().getGraphicsDevices(), getMasterVmCompatibilityVersion());
        vmHandler.autoSelectResumeBehavior(masterVm, getCluster());
        separateCustomProperties(masterVm);
    }
    if (getVm() != null) {
        updateVmDevices();
        images.addAll(getVmDisksFromDB());
        setStoragePoolId(getVm().getStoragePoolId());
        isVmInDb = true;
    } else if (getCluster() != null && masterVm != null) {
        VM vm = new VM(masterVm, new VmDynamic(), null);
        vm.setClusterCompatibilityVersion(getCluster().getCompatibilityVersion());
        setVm(vm);
        setStoragePoolId(getCluster().getStoragePoolId());
    }
    updateDiskInfoDestinationMap();
    generateTargetDiskIds();
    getParameters().setUseCinderCommandCallback(!getCinderDisks().isEmpty());
}
Also used : VmDynamic(org.ovirt.engine.core.common.businessentities.VmDynamic) EntityInfo(org.ovirt.engine.core.common.asynctasks.EntityInfo) VM(org.ovirt.engine.core.common.businessentities.VM) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic)

Aggregations

EntityInfo (org.ovirt.engine.core.common.asynctasks.EntityInfo)33 Guid (org.ovirt.engine.core.compat.Guid)14 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)9 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)6 MoveOrCopyImageGroupParameters (org.ovirt.engine.core.common.action.MoveOrCopyImageGroupParameters)5 RemoveImageParameters (org.ovirt.engine.core.common.action.RemoveImageParameters)5 EngineException (org.ovirt.engine.core.common.errors.EngineException)4 Test (org.junit.Test)3 RunVmParams (org.ovirt.engine.core.common.action.RunVmParams)3 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)3 ArrayList (java.util.ArrayList)2 Response (javax.ws.rs.core.Response)2 Disk (org.ovirt.engine.api.model.Disk)2 ExecutionContext (org.ovirt.engine.core.bll.job.ExecutionContext)2 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Instance (javax.enterprise.inject.Instance)1 Typed (javax.enterprise.inject.Typed)1