use of org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator in project ovirt-engine by oVirt.
the class CommonVmPoolCommand method validateSpaceRequirements.
private boolean validateSpaceRequirements() {
int numOfVms = getParameters().getVmsCount();
Collection<DiskImage> diskDummies = ImagesHandler.getDisksDummiesForStorageAllocations(diskInfoDestinationMap.values());
Collection<DiskImage> disks = new ArrayList<>(numOfVms * diskDummies.size());
// Number of added disks multiplies by the vms number
for (int i = 0; i < numOfVms; ++i) {
disks.addAll(diskDummies);
}
Guid spId = getVmTemplate().getStoragePoolId();
Set<Guid> sdIds = destStorages.keySet();
MultipleStorageDomainsValidator storageDomainsValidator = getStorageDomainsValidator(spId, sdIds);
return validate(storageDomainsValidator.allDomainsWithinThresholds()) && validate(storageDomainsValidator.allDomainsHaveSpaceForNewDisks(disks));
}
use of org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator in project ovirt-engine by oVirt.
the class ExportVmCommand method validate.
@Override
protected boolean validate() {
if (getVm() == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
}
setDescription(getVmName());
setStoragePoolId(getVm().getStoragePoolId());
// check that target domain exists
StorageDomainValidator targetstorageDomainValidator = new StorageDomainValidator(getStorageDomain());
if (!validate(targetstorageDomainValidator.isDomainExistAndActive())) {
return false;
}
// load the disks of vm from database
vmHandler.updateDisksFromDb(getVm());
List<DiskImage> disksForExport = getDisksBasedOnImage();
DiskImagesValidator diskImagesValidator = new DiskImagesValidator(disksForExport);
if (!validate(diskImagesValidator.diskImagesNotIllegal()) || !validate(diskImagesValidator.diskImagesNotLocked())) {
return false;
}
// update vm snapshots for storage free space check
imagesHandler.fillImagesBySnapshots(getVm());
// check that the target and source domain are in the same storage_pool
if (storagePoolIsoMapDao.get(new StoragePoolIsoMapId(getStorageDomain().getId(), getVm().getStoragePoolId())) == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_POOL_NOT_MATCH);
}
// check if template exists only if asked for
if (getParameters().getTemplateMustExists()) {
if (!checkTemplateInStorageDomain(getVm().getStoragePoolId(), getParameters().getStorageDomainId(), getVm().getVmtGuid(), getContext().getEngineContext())) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_TEMPLATE_NOT_FOUND_ON_EXPORT_DOMAIN, String.format("$TemplateName %1$s", getVm().getVmtName()));
}
}
Map<Guid, ? extends Disk> images = getVm().getDiskMap();
if (getParameters().getCopyCollapse()) {
for (DiskImage img : disksForExport) {
if (images.containsKey(img.getId())) {
// check that no RAW format exists (we are in collapse mode)
if (((DiskImage) images.get(img.getId())).getVolumeFormat() == VolumeFormat.RAW && img.getVolumeFormat() != VolumeFormat.RAW) {
return failValidation(EngineMessage.VM_CANNOT_EXPORT_RAW_FORMAT);
}
}
}
}
// check destination storage is Export domain
if (getStorageDomain().getStorageDomainType() != StorageDomainType.ImportExport) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_SPECIFY_DOMAIN_IS_NOT_EXPORT_DOMAIN, String.format("$storageDomainName %1$s", getStorageDomainName()));
}
// get the snapshots that are going to be exported and have memory
snapshotsWithMemory = getSnapshotsToBeExportedWithMemory();
// check destination storage have free space
if (!handleDestStorageDomain(disksForExport)) {
return false;
}
if (!(checkVmInStorageDomain() && validate(new StoragePoolValidator(getStoragePool()).existsAndUp()) && validate(snapshotsValidator.vmNotDuringSnapshot(getVmId())) && validate(snapshotsValidator.vmNotInPreview(getVmId())) && validate(new VmValidator(getVm()).vmDown()) && validate(new MultipleStorageDomainsValidator(getVm().getStoragePoolId(), ImagesHandler.getAllStorageIdsForImageIds(disksForExport)).allDomainsExistAndActive()))) {
return false;
}
return true;
}
use of org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator in project ovirt-engine by oVirt.
the class CreateSnapshotForVmCommand method validateStorage.
private boolean validateStorage() {
List<DiskImage> vmDisksList = getDisksListForChecks();
vmDisksList = ImagesHandler.getDisksDummiesForStorageAllocations(vmDisksList);
List<DiskImage> allDisks = new ArrayList<>(vmDisksList);
List<DiskImage> memoryDisksList = null;
if (getParameters().isSaveMemory()) {
memoryDisksList = MemoryUtils.createDiskDummies(vmOverheadCalculator.getSnapshotMemorySizeInBytes(getVm()), MemoryUtils.METADATA_SIZE_IN_BYTES);
if (Guid.Empty.equals(getStorageDomainIdForVmMemory(memoryDisksList))) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_NO_SUITABLE_DOMAIN_FOUND);
}
allDisks.addAll(memoryDisksList);
}
MultipleStorageDomainsValidator sdValidator = createMultipleStorageDomainsValidator(allDisks);
if (!validate(sdValidator.allDomainsExistAndActive()) || !validate(sdValidator.allDomainsWithinThresholds()) || !validateCinder()) {
return false;
}
if (memoryDisksList == null) {
// no memory volumes
return validate(sdValidator.allDomainsHaveSpaceForNewDisks(vmDisksList));
}
return validate(sdValidator.allDomainsHaveSpaceForAllDisks(vmDisksList, memoryDisksList));
}
use of org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator in project ovirt-engine by oVirt.
the class TryBackToAllSnapshotsOfVmCommand method validate.
@Override
protected boolean validate() {
if (Guid.Empty.equals(getParameters().getDstSnapshotId())) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_CORRUPTED_VM_SNAPSHOT_ID);
}
// verify that the destination lease domain ID belongs to one of the VM's snapshots
if (getParameters().getDstLeaseDomainId() != null) {
if (!validate(snapshotsValidator.isLeaseDomainIdBelongsToSnapshot(getVmId(), getParameters().getDstLeaseDomainId())) && !getParameters().getDstLeaseDomainId().equals(getVm().getLeaseStorageDomainId())) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_LEASE_DOMAIN_ID_IS_NOT_VALID);
}
}
VmValidator vmValidator = new VmValidator(getVm());
if (!validate(vmValidator.isVmExists()) || !validate(vmValidator.vmDown()) || !validate(snapshotsValidator.snapshotExists(getVmId(), getParameters().getDstSnapshotId())) || !validate(snapshotsValidator.vmNotDuringSnapshot(getVmId())) || !validate(snapshotsValidator.vmNotInPreview(getVmId())) || !validate(snapshotsValidator.snapshotVmConfigurationBroken(getDstSnapshot(), getVmName()))) {
return false;
}
updateVmDisksFromDb();
List<DiskImage> diskImages = DisksFilter.filterImageDisks(getVm().getDiskMap().values(), ONLY_NOT_SHAREABLE, ONLY_SNAPABLE, ONLY_ACTIVE);
diskImages.addAll(DisksFilter.filterCinderDisks(getVm().getDiskMap().values(), ONLY_PLUGGED));
if (!diskImages.isEmpty()) {
if (!validate(new StoragePoolValidator(getStoragePool()).existsAndUp())) {
return false;
}
DiskImagesValidator diskImagesValidator = new DiskImagesValidator(diskImages);
if (!validate(diskImagesValidator.diskImagesNotIllegal()) || !validate(diskImagesValidator.diskImagesNotLocked())) {
return false;
}
List<DiskImage> images = getImagesToPreview();
DiskImagesValidator diskImagesToPreviewValidator = new DiskImagesValidator(images);
if (!validate(diskImagesToPreviewValidator.noDuplicatedIds()) || !validate(diskImagesToPreviewValidator.diskImagesSnapshotsAttachedToVm(getVmId())) || !validate(diskImagesToPreviewValidator.diskImagesNotIllegal()) || !validate(diskImagesToPreviewValidator.diskImagesNotLocked())) {
return false;
}
Set<Guid> storageIds = ImagesHandler.getAllStorageIdsForImageIds(diskImages);
// verify lease storage domain status
if (getParameters().getDstLeaseDomainId() != null) {
storageIds.add(getParameters().getDstLeaseDomainId());
} else if (getDstSnapshot().getVmConfiguration() != null) {
Guid leaseDomainId = OvfUtils.fetchLeaseDomainId(getDstSnapshot().getVmConfiguration());
if (leaseDomainId != null) {
storageIds.add(leaseDomainId);
}
}
MultipleStorageDomainsValidator storageValidator = new MultipleStorageDomainsValidator(getVm().getStoragePoolId(), storageIds);
if (!validate(storageValidator.allDomainsExistAndActive()) || !validate(storageValidator.allDomainsWithinThresholds()) || !validateCinder()) {
return false;
}
}
DiskSnapshotsValidator diskSnapshotsValidator = new DiskSnapshotsValidator(getParameters().getDisks());
if (!validate(diskSnapshotsValidator.canDiskSnapshotsBePreviewed(getParameters().getDstSnapshotId()))) {
return false;
}
if (isRestoreMemory() && !validateMemoryTakenInSupportedVersion()) {
return false;
}
if (!canRestoreVmConfigFromSnapshot()) {
return failValidation(EngineMessage.MAC_POOL_NOT_ENOUGH_MAC_ADDRESSES);
}
return true;
}
use of org.ovirt.engine.core.bll.validator.storage.MultipleStorageDomainsValidator in project ovirt-engine by oVirt.
the class AddVmTemplateCommand method validateImages.
protected boolean validateImages() {
// images related checks
if (!images.isEmpty()) {
if (!validateVmNotDuringSnapshot()) {
return false;
}
if (!validate(new StoragePoolValidator(getStoragePool()).existsAndUp())) {
return false;
}
List<CinderDisk> cinderDisks = getCinderDisks();
CinderDisksValidator cinderDisksValidator = new CinderDisksValidator(cinderDisks);
if (!validate(cinderDisksValidator.validateCinderDiskLimits())) {
return false;
}
if (!validate(isPassDiscardSupportedForImagesDestSds())) {
return false;
}
List<DiskImage> diskImagesToCheck = DisksFilter.filterImageDisks(images, ONLY_NOT_SHAREABLE, ONLY_ACTIVE);
diskImagesToCheck.addAll(cinderDisks);
DiskImagesValidator diskImagesValidator = new DiskImagesValidator(diskImagesToCheck);
if (!validate(diskImagesValidator.diskImagesNotIllegal()) || !validate(diskImagesValidator.diskImagesNotLocked())) {
return false;
}
MultipleStorageDomainsValidator storageDomainsValidator = getStorageDomainsValidator(getStoragePoolId(), sourceImageDomainsImageMap.keySet());
if (!validate(storageDomainsValidator.allDomainsExistAndActive())) {
return false;
}
Set<Guid> destImageDomains = getStorageGuidSet();
destImageDomains.removeAll(sourceImageDomainsImageMap.keySet());
for (Guid destImageDomain : destImageDomains) {
StorageDomain storage = storageDomainDao.getForStoragePool(destImageDomain, getVm().getStoragePoolId());
if (storage == null) {
// domain is not in the same storage pool as the vm
if (storageDomainStaticDao.get(destImageDomain) == null) {
addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_NOT_EXIST);
} else {
addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_NOT_IN_STORAGE_POOL);
}
return false;
}
if (storage.getStatus() == null || storage.getStatus() != StorageDomainStatus.Active) {
addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_STATUS_ILLEGAL);
return false;
}
if (storage.getStorageDomainType().isIsoOrImportExportDomain()) {
addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_TYPE_ILLEGAL);
return false;
}
}
return validateSpaceRequirements();
}
return true;
}
Aggregations