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;
}
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;
}
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;
}
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);
}
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;
}
}
Aggregations