Search in sources :

Example 46 with ValidationResult

use of org.ovirt.engine.core.bll.ValidationResult 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 47 with ValidationResult

use of org.ovirt.engine.core.bll.ValidationResult in project ovirt-engine by oVirt.

the class StorageDomainValidator method isDomainWithinThresholds.

public ValidationResult isDomainWithinThresholds() {
    if (storageDomain.getStorageType().isCinderDomain()) {
        return ValidationResult.VALID;
    }
    StorageDomainDynamic dynamicData = storageDomain.getStorageDynamicData();
    StorageDomainStatic staticData = storageDomain.getStorageStaticData();
    if (dynamicData != null && staticData != null && dynamicData.getAvailableDiskSize() != null && staticData.getCriticalSpaceActionBlocker() != null && dynamicData.getAvailableDiskSize() < staticData.getCriticalSpaceActionBlocker()) {
        return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_DISK_SPACE_LOW_ON_STORAGE_DOMAIN, storageName());
    }
    return ValidationResult.VALID;
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) StorageDomainDynamic(org.ovirt.engine.core.common.businessentities.StorageDomainDynamic) ValidationResult(org.ovirt.engine.core.bll.ValidationResult)

Example 48 with ValidationResult

use of org.ovirt.engine.core.bll.ValidationResult in project ovirt-engine by oVirt.

the class VmValidator method checkPciAndIdeLimit.

/**
 * This method checks that with the given parameters, the max PCI and IDE limits defined are not passed.
 */
public static ValidationResult checkPciAndIdeLimit(int osId, Version clusterVersion, int monitorsNumber, List<? extends VmNic> interfaces, List<DiskVmElement> diskVmElements, boolean virtioScsiEnabled, boolean hasWatchdog, boolean isBalloonEnabled, boolean isSoundDeviceEnabled) {
    // this adds: monitors + 2 * (interfaces with type rtl_pv) + (all other
    // interfaces) + (all disks that are not IDE)
    int pciInUse = monitorsNumber;
    for (VmNic a : interfaces) {
        if (a.getType() != null && VmInterfaceType.forValue(a.getType()) == VmInterfaceType.rtl8139_pv) {
            pciInUse += 2;
        } else if (a.getType() != null && VmInterfaceType.forValue(a.getType()) == VmInterfaceType.spaprVlan) {
        // Do not count sPAPR VLAN devices since they are not PCI
        } else {
            pciInUse += 1;
        }
    }
    pciInUse += diskVmElements.stream().filter(dve -> dve.getDiskInterface() == DiskInterface.VirtIO).count();
    // VirtIO SCSI controller requires one PCI slot
    pciInUse += virtioScsiEnabled ? 1 : 0;
    // VmWatchdog controller requires one PCI slot
    pciInUse += hasWatchdog ? 1 : 0;
    // Balloon controller requires one PCI slot
    pciInUse += isBalloonEnabled ? 1 : 0;
    // Sound device controller requires one PCI slot
    pciInUse += isSoundDeviceEnabled ? 1 : 0;
    OsRepository osRepository = Injector.get(OsRepository.class);
    int maxPciSlots = osRepository.getMaxPciDevices(osId, clusterVersion);
    ArrayList<EngineMessage> messages = new ArrayList<>();
    if (pciInUse > maxPciSlots) {
        messages.add(EngineMessage.ACTION_TYPE_FAILED_EXCEEDED_MAX_PCI_SLOTS);
    } else if (VmCommand.MAX_IDE_SLOTS < diskVmElements.stream().filter(a -> a.getDiskInterface() == DiskInterface.IDE).count()) {
        messages.add(EngineMessage.ACTION_TYPE_FAILED_EXCEEDED_MAX_IDE_SLOTS);
    } else if (VmCommand.MAX_VIRTIO_SCSI_DISKS < diskVmElements.stream().filter(a -> a.getDiskInterface() == DiskInterface.VirtIO_SCSI).count()) {
        messages.add(EngineMessage.ACTION_TYPE_FAILED_EXCEEDED_MAX_VIRTIO_SCSI_DISKS);
    } else if (VmCommand.MAX_SPAPR_SCSI_DISKS < diskVmElements.stream().filter(a -> a.getDiskInterface() == DiskInterface.SPAPR_VSCSI).count()) {
        messages.add(EngineMessage.ACTION_TYPE_FAILED_EXCEEDED_MAX_SPAPR_VSCSI_DISKS);
    }
    if (!messages.isEmpty()) {
        return new ValidationResult(messages);
    }
    return ValidationResult.VALID;
}
Also used : Arrays(java.util.Arrays) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) VmInterfaceType(org.ovirt.engine.core.common.businessentities.network.VmInterfaceType) Guid(org.ovirt.engine.core.compat.Guid) ReplacementUtils(org.ovirt.engine.core.utils.ReplacementUtils) OsRepository(org.ovirt.engine.core.common.osinfo.OsRepository) DbFacade(org.ovirt.engine.core.dal.dbbroker.DbFacade) ArrayList(java.util.ArrayList) VmPropertiesUtils(org.ovirt.engine.core.common.utils.customprop.VmPropertiesUtils) ActionType(org.ovirt.engine.core.common.action.ActionType) DisksFilter(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter) Map(java.util.Map) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic) ONLY_ACTIVE(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter.ONLY_ACTIVE) Version(org.ovirt.engine.core.compat.Version) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) VmCommand(org.ovirt.engine.core.bll.VmCommand) Config(org.ovirt.engine.core.common.config.Config) ActionUtils(org.ovirt.engine.core.common.ActionUtils) DiskImagesValidator(org.ovirt.engine.core.bll.validator.storage.DiskImagesValidator) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) Predicate(java.util.function.Predicate) Collection(java.util.Collection) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) VnicProfile(org.ovirt.engine.core.common.businessentities.network.VnicProfile) HostDeviceManager(org.ovirt.engine.core.bll.hostdev.HostDeviceManager) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskVmElementDao(org.ovirt.engine.core.dao.DiskVmElementDao) Collectors(java.util.stream.Collectors) SnapshotType(org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType) ONLY_NOT_SHAREABLE(org.ovirt.engine.core.bll.storage.disk.image.DisksFilter.ONLY_NOT_SHAREABLE) List(java.util.List) VM(org.ovirt.engine.core.common.businessentities.VM) DiskDao(org.ovirt.engine.core.dao.DiskDao) Injector(org.ovirt.engine.core.di.Injector) DiskInterface(org.ovirt.engine.core.common.businessentities.storage.DiskInterface) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) MigrationSupport(org.ovirt.engine.core.common.businessentities.MigrationSupport) Collections(java.util.Collections) FeatureSupported(org.ovirt.engine.core.common.FeatureSupported) VMStatus(org.ovirt.engine.core.common.businessentities.VMStatus) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) ArrayList(java.util.ArrayList) OsRepository(org.ovirt.engine.core.common.osinfo.OsRepository) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 49 with ValidationResult

use of org.ovirt.engine.core.bll.ValidationResult in project ovirt-engine by oVirt.

the class VnicProfileValidator method vnicProfileNotUsed.

protected ValidationResult vnicProfileNotUsed(List<? extends Nameable> entities, EngineMessage entitiesReplacementPlural, EngineMessage entitiesReplacementSingular) {
    if (entities.isEmpty()) {
        return ValidationResult.VALID;
    }
    Collection<String> replacements = ReplacementUtils.replaceWithNameable("ENTITIES_USING_VNIC_PROFILE", entities);
    EngineMessage replacementMessageToUse = entities.size() == 1 ? entitiesReplacementSingular : entitiesReplacementPlural;
    replacements.add(replacementMessageToUse.name());
    return new ValidationResult(getVNicProfileInUseValidationMessage(entities.size()), replacements);
}
Also used : ValidationResult(org.ovirt.engine.core.bll.ValidationResult) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage)

Example 50 with ValidationResult

use of org.ovirt.engine.core.bll.ValidationResult in project ovirt-engine by oVirt.

the class GlusterBrickValidator method canRemoveBrick.

/**
 * Checks that all brick ids passed are valid, also updating the bricks with server name and brick directory using
 * the brick objects obtained from the volume.
 *
 * @param bricks
 *            The bricks to validate
 * @return true if all bricks have valid ids, else false
 */
public ValidationResult canRemoveBrick(List<GlusterBrickEntity> bricks, GlusterVolumeEntity volumeEntity, int replicaCount, boolean forceRemove) {
    if (replicaCount == 0) {
        replicaCount = volumeEntity.getReplicaCount();
    }
    if (bricks.isEmpty()) {
        return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_BRICKS_REQUIRED);
    }
    if (volumeEntity.getBricks().size() == 1 || volumeEntity.getBricks().size() <= bricks.size()) {
        return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_CAN_NOT_REMOVE_ALL_BRICKS_FROM_VOLUME);
    }
    if (volumeEntity.getVolumeType().isReplicatedType()) {
        if (replicaCount == volumeEntity.getReplicaCount() - 1 && !forceRemove) {
            return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_CAN_NOT_REDUCE_REPLICA_COUNT_WITH_DATA_MIGRATION);
        } else if (replicaCount < volumeEntity.getReplicaCount() - 1) {
            return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_CAN_NOT_REDUCE_REPLICA_COUNT_MORE_THAN_ONE);
        } else if (replicaCount > volumeEntity.getReplicaCount()) {
            return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_CAN_NOT_INCREASE_REPLICA_COUNT);
        }
    }
    for (GlusterBrickEntity brick : bricks) {
        if (brick.getId(false) == null && brick.getQualifiedName() == null) {
            return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_BRICKS_REQUIRED);
        }
        GlusterBrickEntity brickFromVolume = volumeEntity.getBrickWithId(brick.getId());
        if (brickFromVolume == null) {
            brickFromVolume = volumeEntity.getBrickWithQualifiedName(brick.getQualifiedName());
        }
        if (brickFromVolume == null) {
            return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_GLUSTER_BRICK_INVALID);
        } else {
            // Fill required details from volume data
            brick.setId(brickFromVolume.getId());
            brick.setServerName(brickFromVolume.getServerName());
            brick.setBrickDirectory(brickFromVolume.getBrickDirectory());
        }
    }
    if (!forceRemove) {
        return canRebalance(volumeEntity);
    } else {
        return ValidationResult.VALID;
    }
}
Also used : GlusterBrickEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity) ValidationResult(org.ovirt.engine.core.bll.ValidationResult)

Aggregations

ValidationResult (org.ovirt.engine.core.bll.ValidationResult)239 Test (org.junit.Test)132 BaseCommandTest (org.ovirt.engine.core.bll.BaseCommandTest)49 Guid (org.ovirt.engine.core.compat.Guid)40 ArrayList (java.util.ArrayList)31 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)31 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)30 Network (org.ovirt.engine.core.common.businessentities.network.Network)21 NetworkAttachment (org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)19 VdsNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)16 GlusterVolumeEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity)15 CreateOrUpdateBond (org.ovirt.engine.core.common.action.CreateOrUpdateBond)13 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)12 List (java.util.List)11 VM (org.ovirt.engine.core.common.businessentities.VM)11 HashSet (java.util.HashSet)10 FindActiveVmsUsingNetwork (org.ovirt.engine.core.bll.network.FindActiveVmsUsingNetwork)10 GlusterBrickEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity)9 StorageDomainValidator (org.ovirt.engine.core.bll.validator.storage.StorageDomainValidator)7 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)7