Search in sources :

Example 96 with QueryReturnValue

use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.

the class UpdateVmCommand method updateWatchdog.

private void updateWatchdog() {
    // do not update if this flag is not set
    if (getParameters().isUpdateWatchdog()) {
        QueryReturnValue query = runInternalQuery(QueryType.GetWatchdog, new IdQueryParameters(getParameters().getVmId()));
        List<VmWatchdog> watchdogs = query.getReturnValue();
        if (watchdogs.isEmpty()) {
            if (getParameters().getWatchdog() == null) {
            // nothing to do, no watchdog and no watchdog to create
            } else {
                WatchdogParameters parameters = new WatchdogParameters();
                parameters.setId(getParameters().getVmId());
                parameters.setAction(getParameters().getWatchdog().getAction());
                parameters.setModel(getParameters().getWatchdog().getModel());
                runInternalAction(ActionType.AddWatchdog, parameters, cloneContextAndDetachFromParent());
            }
        } else {
            WatchdogParameters watchdogParameters = new WatchdogParameters();
            watchdogParameters.setId(getParameters().getVmId());
            if (getParameters().getWatchdog() == null) {
                // there is a watchdog in the vm, there should not be any, so let's delete
                runInternalAction(ActionType.RemoveWatchdog, watchdogParameters, cloneContextAndDetachFromParent());
            } else {
                // there is a watchdog in the vm, we have to update.
                watchdogParameters.setAction(getParameters().getWatchdog().getAction());
                watchdogParameters.setModel(getParameters().getWatchdog().getModel());
                runInternalAction(ActionType.UpdateWatchdog, watchdogParameters, cloneContextAndDetachFromParent());
            }
        }
    }
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) WatchdogParameters(org.ovirt.engine.core.common.action.WatchdogParameters) VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog)

Example 97 with QueryReturnValue

use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.

the class UpdateVmCommand method updateRngDevice.

private void updateRngDevice() {
    if (!getParameters().isUpdateRngDevice()) {
        return;
    }
    QueryReturnValue query = runInternalQuery(QueryType.GetRngDevice, new IdQueryParameters(getParameters().getVmId()));
    List<VmRngDevice> rngDevs = query.getReturnValue();
    ActionReturnValue rngCommandResult = null;
    if (rngDevs.isEmpty()) {
        if (getParameters().getRngDevice() != null) {
            RngDeviceParameters params = new RngDeviceParameters(getParameters().getRngDevice(), true);
            rngCommandResult = runInternalAction(ActionType.AddRngDevice, params, cloneContextAndDetachFromParent());
        }
    } else {
        if (getParameters().getRngDevice() == null) {
            RngDeviceParameters params = new RngDeviceParameters(rngDevs.get(0), true);
            rngCommandResult = runInternalAction(ActionType.RemoveRngDevice, params, cloneContextAndDetachFromParent());
        } else {
            RngDeviceParameters params = new RngDeviceParameters(getParameters().getRngDevice(), true);
            params.getRngDevice().setDeviceId(rngDevs.get(0).getDeviceId());
            rngCommandResult = runInternalAction(ActionType.UpdateRngDevice, params, cloneContextAndDetachFromParent());
        }
    }
    if (rngCommandResult != null && !rngCommandResult.getSucceeded()) {
        log.error("Updating RNG device of VM {} ({}) failed. Old RNG device = {}. New RNG device = {}.", getVm().getName(), getVm().getId(), rngDevs.isEmpty() ? null : rngDevs.get(0), getParameters().getRngDevice());
    }
}
Also used : RngDeviceParameters(org.ovirt.engine.core.common.action.RngDeviceParameters) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice)

Example 98 with QueryReturnValue

use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.

the class UpdateVmPoolCommand method isUpdateVmRequired.

private boolean isUpdateVmRequired(List<VM> vmsInPool) {
    if (vmsInPool == null || vmsInPool.isEmpty()) {
        return false;
    }
    // Check one VM in order to decide if template version was changed
    VM poolVm = vmsInPool.get(0);
    // old template version (based on current vm data)
    Guid currentTemplateVersion = null;
    // old latest status
    boolean isCurrentLatest = false;
    if (poolVm.isNextRunConfigurationExists()) {
        QueryReturnValue qRetNextRun = backend.runInternalQuery(QueryType.GetVmNextRunConfiguration, new IdQueryParameters(poolVm.getId()));
        if (qRetNextRun.getSucceeded()) {
            final VM nextRunVm = qRetNextRun.getReturnValue();
            if (nextRunVm != null) {
                // template version was changed, the cause still needs to be checked
                currentTemplateVersion = nextRunVm.getVmtGuid();
                isCurrentLatest = nextRunVm.isUseLatestVersion();
            }
        }
    } else {
        currentTemplateVersion = poolVm.getVmtGuid();
        isCurrentLatest = poolVm.isUseLatestVersion();
    }
    boolean isLatestPropertyChanged = isCurrentLatest != getParameters().getVmStaticData().isUseLatestVersion();
    // template ID changed but latest is not set, as it would cause false-positives
    boolean isTemplateIdChanged = false;
    Guid newPoolTemplateVersion = getParameters().getVmStaticData().getVmtGuid();
    if (newPoolTemplateVersion != null) {
        isTemplateIdChanged = !newPoolTemplateVersion.equals(currentTemplateVersion) && !isCurrentLatest;
    }
    return isLatestPropertyChanged || isTemplateIdChanged;
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) VM(org.ovirt.engine.core.common.businessentities.VM) Guid(org.ovirt.engine.core.compat.Guid)

Example 99 with QueryReturnValue

use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.

the class StorageDomainValidator method isRunningVmsOrVmLeasesForBackupDomain.

public ValidationResult isRunningVmsOrVmLeasesForBackupDomain(VmHandler vmHandler) {
    Set<String> invalidVmsForBackupStorageDomain = new HashSet<>();
    QueryReturnValue ret = getEntitiesWithLeaseIdForStorageDomain(storageDomain.getId());
    if (!ret.getSucceeded()) {
        return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_RETRIEVE_VMS_FOR_WITH_LEASES);
    }
    getRetVal(ret).forEach(vmBase -> {
        VmDynamic vm = getVmDynamicDao().get(vmBase.getId());
        if (vm != null && vm.getStatus() != VMStatus.Down) {
            invalidVmsForBackupStorageDomain.add(vmBase.getName());
        }
    });
    List<VM> vms = getVmDao().getAllActiveForStorageDomain(storageDomain.getId());
    vms.forEach(vmHandler::updateDisksFromDb);
    invalidVmsForBackupStorageDomain.addAll(vms.stream().filter(vm -> vm.getDiskMap().values().stream().filter(DisksFilter.ONLY_IMAGES).filter(DisksFilter.ONLY_PLUGGED).map(DiskImage.class::cast).anyMatch(vmDisk -> vmDisk.getStorageIds().get(0).equals(storageDomain.getId()))).map(VM::getName).collect(Collectors.toList()));
    if (!invalidVmsForBackupStorageDomain.isEmpty()) {
        log.warn("Can't update the backup property of the storage domain since it contains VMs with " + "leases or active disks which are attached to running VMs." + "The following VMs list are: '{}'", invalidVmsForBackupStorageDomain);
        return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_RUNNING_VM_OR_VM_LEASES_PRESENT_ON_STORAGE_DOMAIN);
    }
    return ValidationResult.VALID;
}
Also used : QueryType(org.ovirt.engine.core.common.queries.QueryType) Backend(org.ovirt.engine.core.bll.Backend) Guid(org.ovirt.engine.core.compat.Guid) VmDynamicDao(org.ovirt.engine.core.dao.VmDynamicDao) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) LoggerFactory(org.slf4j.LoggerFactory) StorageDomainStatus(org.ovirt.engine.core.common.businessentities.StorageDomainStatus) Supplier(java.util.function.Supplier) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) DbFacade(org.ovirt.engine.core.dal.dbbroker.DbFacade) HashSet(java.util.HashSet) ActionType(org.ovirt.engine.core.common.action.ActionType) DisksFilter(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter) BackendInternal(org.ovirt.engine.core.bll.interfaces.BackendInternal) StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) VolumeFormat(org.ovirt.engine.core.common.businessentities.storage.VolumeFormat) StorageDomainDynamic(org.ovirt.engine.core.common.businessentities.StorageDomainDynamic) Version(org.ovirt.engine.core.compat.Version) StorageFormatType(org.ovirt.engine.core.common.businessentities.StorageFormatType) StorageType(org.ovirt.engine.core.common.businessentities.storage.StorageType) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) ImagesHandler(org.ovirt.engine.core.bll.storage.disk.image.ImagesHandler) Logger(org.slf4j.Logger) VmHandler(org.ovirt.engine.core.bll.VmHandler) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) Collection(java.util.Collection) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) StorageConstants(org.ovirt.engine.core.common.constants.StorageConstants) Set(java.util.Set) BlockStorageDiscardFunctionalityHelper(org.ovirt.engine.core.bll.storage.utils.BlockStorageDiscardFunctionalityHelper) VolumeType(org.ovirt.engine.core.common.businessentities.storage.VolumeType) Collectors(java.util.stream.Collectors) VmDao(org.ovirt.engine.core.dao.VmDao) List(java.util.List) VM(org.ovirt.engine.core.common.businessentities.VM) Injector(org.ovirt.engine.core.di.Injector) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) StorageDomainType(org.ovirt.engine.core.common.businessentities.StorageDomainType) SubchainInfo(org.ovirt.engine.core.common.businessentities.SubchainInfo) Collections(java.util.Collections) VmDynamic(org.ovirt.engine.core.common.businessentities.VmDynamic) FeatureSupported(org.ovirt.engine.core.common.FeatureSupported) VMStatus(org.ovirt.engine.core.common.businessentities.VMStatus) StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) LUNs(org.ovirt.engine.core.common.businessentities.storage.LUNs) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) VmDynamic(org.ovirt.engine.core.common.businessentities.VmDynamic) VM(org.ovirt.engine.core.common.businessentities.VM) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) HashSet(java.util.HashSet)

Example 100 with QueryReturnValue

use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.

the class GetUnregisteredDisksQueryTest method prepareMocks.

/**
 * Mock the VDSBroker and the Daos
 */
private void prepareMocks() {
    DiskImage existingDiskImage = mock(DiskImage.class);
    when(existingDiskImage.getId()).thenReturn(existingDiskId);
    List<DiskImage> existingDiskImages = Collections.singletonList(existingDiskImage);
    // Mock the get images List VDS command
    VDSReturnValue volListReturnValue = new VDSReturnValue();
    volListReturnValue.setSucceeded(true);
    volListReturnValue.setReturnValue(importDiskIds);
    doReturn(volListReturnValue).when(vdsBroker).runVdsCommand(eq(VDSCommandType.GetImagesList), any());
    // Mock the get unregistered disk query
    when(backendMock.runInternalQuery(eq(QueryType.GetUnregisteredDisk), any(), any())).thenAnswer(invocation -> {
        GetUnregisteredDiskQueryParameters p = (GetUnregisteredDiskQueryParameters) invocation.getArguments()[1];
        QueryReturnValue unregDiskReturnValue = new QueryReturnValue();
        unregDiskReturnValue.setSucceeded(true);
        DiskImage newDiskImage = mock(DiskImage.class);
        when(newDiskImage.getId()).thenReturn(p.getDiskId());
        unregDiskReturnValue.setReturnValue(newDiskImage);
        return unregDiskReturnValue;
    });
    doReturn(storagePoolId).when(getQuery()).getStoragePoolId();
    doReturn(storageDomainId).when(getQuery()).getStorageDomainId();
    when(diskImageDaoMock.getAllSnapshotsForStorageDomain(eq(storageDomainId))).thenReturn(existingDiskImages);
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) GetUnregisteredDiskQueryParameters(org.ovirt.engine.core.common.queries.GetUnregisteredDiskQueryParameters) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Aggregations

QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)265 ArrayList (java.util.ArrayList)123 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)97 QueryType (org.ovirt.engine.core.common.queries.QueryType)85 List (java.util.List)74 Guid (org.ovirt.engine.core.compat.Guid)66 Frontend (org.ovirt.engine.ui.frontend.Frontend)64 ConstantsManager (org.ovirt.engine.ui.uicompat.ConstantsManager)54 VM (org.ovirt.engine.core.common.businessentities.VM)49 QueryParametersBase (org.ovirt.engine.core.common.queries.QueryParametersBase)47 HelpTag (org.ovirt.engine.ui.uicommonweb.help.HelpTag)42 HashMap (java.util.HashMap)40 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)39 AsyncDataProvider (org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider)39 Test (org.junit.Test)38 Collection (java.util.Collection)34 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)33 Map (java.util.Map)31 ActionType (org.ovirt.engine.core.common.action.ActionType)31 VDS (org.ovirt.engine.core.common.businessentities.VDS)31