Search in sources :

Example 6 with VmBase

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

the class StorageDomainValidatorTest method invalidRunningVmsAndVmLeasesForBackupDomain.

@Test
public void invalidRunningVmsAndVmLeasesForBackupDomain() {
    QueryReturnValue ret = new QueryReturnValue();
    List<VmBase> vmLeases = new ArrayList<>();
    VM vmWithLease = new VM();
    vmWithLease.setName("firstVM");
    vmLeases.add(vmWithLease.getStaticData());
    ret.setReturnValue(vmLeases);
    ret.setSucceeded(true);
    // VM1
    VM vm1 = new VM();
    vm1.setName("firstVM");
    Map<Guid, Disk> attachedDisksForVm1 = new HashMap<>();
    DiskImage diskVm1 = new DiskImage();
    diskVm1.setStorageIds(new ArrayList<>(Collections.singletonList(domain.getId())));
    diskVm1.setPlugged(true);
    attachedDisksForVm1.put(Guid.newGuid(), diskVm1);
    vm1.setDiskMap(attachedDisksForVm1);
    // VM2
    VM vm2 = new VM();
    vm2.setName("secondVM");
    Map<Guid, Disk> attachedDisksForVm2 = new HashMap<>();
    DiskImage diskVm2 = new DiskImage();
    diskVm2.setStorageIds(new ArrayList<>(Collections.singletonList(domain.getId())));
    diskVm2.setPlugged(true);
    attachedDisksForVm2.put(Guid.newGuid(), diskVm2);
    vm2.setDiskMap(attachedDisksForVm2);
    List<VM> runningVMs = new ArrayList<>();
    runningVMs.add(vm1);
    runningVMs.add(vm2);
    when(vmDao.getAllActiveForStorageDomain(any())).thenReturn(runningVMs);
    doReturn(ret).when(validator).getEntitiesWithLeaseIdForStorageDomain(any());
    assertThat(validator.isRunningVmsOrVmLeasesForBackupDomain(vmHandler), failsWith(EngineMessage.ACTION_TYPE_FAILED_RUNNING_VM_OR_VM_LEASES_PRESENT_ON_STORAGE_DOMAIN));
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) HashMap(java.util.HashMap) VM(org.ovirt.engine.core.common.businessentities.VM) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Test(org.junit.Test)

Example 7 with VmBase

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

the class StorageDomainValidatorTest method validRunningVmsOrVmLeasesForBackupDomain.

@Test
public void validRunningVmsOrVmLeasesForBackupDomain() {
    when(vmDao.getAllActiveForStorageDomain(any())).thenReturn(Collections.EMPTY_LIST);
    QueryReturnValue ret = new QueryReturnValue();
    ret.setReturnValue(new ArrayList<VmBase>());
    ret.setSucceeded(true);
    doReturn(ret).when(validator).getEntitiesWithLeaseIdForStorageDomain(any());
    assertThat(validator.isRunningVmsOrVmLeasesForBackupDomain(vmHandler), isValid());
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) Test(org.junit.Test)

Example 8 with VmBase

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

the class StorageDomainValidatorTest method validRunningVmsWithUnpluggedDisksForBackupDomain.

@Test
public void validRunningVmsWithUnpluggedDisksForBackupDomain() {
    // VM1
    VM vm1 = new VM();
    vm1.setName("firstVM");
    Map<Guid, Disk> attachedDisksForVm1 = new HashMap<>();
    DiskImage diskVm1 = new DiskImage();
    diskVm1.setStorageIds(new ArrayList<>(Collections.singletonList(domain.getId())));
    diskVm1.setPlugged(false);
    attachedDisksForVm1.put(Guid.newGuid(), diskVm1);
    vm1.setDiskMap(attachedDisksForVm1);
    List<VM> runningVMs = new ArrayList<>();
    runningVMs.add(vm1);
    when(vmDao.getAllActiveForStorageDomain(any())).thenReturn(runningVMs);
    QueryReturnValue ret = new QueryReturnValue();
    ret.setReturnValue(new ArrayList<VmBase>());
    ret.setSucceeded(true);
    doReturn(ret).when(validator).getEntitiesWithLeaseIdForStorageDomain(any());
    assertThat(validator.isRunningVmsOrVmLeasesForBackupDomain(vmHandler), isValid());
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) HashMap(java.util.HashMap) VM(org.ovirt.engine.core.common.businessentities.VM) ArrayList(java.util.ArrayList) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) Guid(org.ovirt.engine.core.compat.Guid) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Test(org.junit.Test)

Example 9 with VmBase

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

the class StorageDomainValidatorTest method validVmLeasesForBackupDomain.

@Test
public void validVmLeasesForBackupDomain() {
    when(vmDao.getAllActiveForStorageDomain(any())).thenReturn(Collections.EMPTY_LIST);
    QueryReturnValue ret = new QueryReturnValue();
    List<VmBase> vmLeases = new ArrayList<>();
    VM vm1 = new VM();
    vm1.setName("firstVM");
    vm1.setStatus(VMStatus.Down);
    vmLeases.add(vm1.getStaticData());
    ret.setReturnValue(vmLeases);
    ret.setSucceeded(true);
    doReturn(ret).when(validator).getEntitiesWithLeaseIdForStorageDomain(any());
    when(vmDao.get(vm1.getId())).thenReturn(vm1);
    assertThat(validator.isRunningVmsOrVmLeasesForBackupDomain(vmHandler), isValid());
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) VM(org.ovirt.engine.core.common.businessentities.VM) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 10 with VmBase

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

Aggregations

VmBase (org.ovirt.engine.core.common.businessentities.VmBase)38 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)15 Guid (org.ovirt.engine.core.compat.Guid)11 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)9 VM (org.ovirt.engine.core.common.businessentities.VM)8 HashSet (java.util.HashSet)7 List (java.util.List)7 Set (java.util.Set)7 HashMap (java.util.HashMap)6 Collection (java.util.Collection)5 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)5 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)5 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)5 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)5 Collections (java.util.Collections)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)4 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)4