Gilad Chaplik has uploaded a new change for review. Change subject: core: add disk profile to disk's commands ......................................................................
core: add disk profile to disk's commands * Allow null disk profile id, if there's a single disk profile in relevant storage domain (trivial case to avoid breaking current flow). * Replace null disk profile with trivial one. * Validate disk profile in all disk flows. * Permission for disk profiles will be handled in a later patch, currently we rely on storage domain permissions (no change in flow). Change-Id: Ie7b6d977243cffc0bde772665ebaca47340075c6 Signed-off-by: Gilad Chaplik <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddDiskCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmTemplateCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmTemplateCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RegisterDiskCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmDiskCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/lsm/LiveMigrateVmDisksCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/DiskProfileHelper.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/DiskProfileValidator.java M backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddDiskToVmCommandTest.java M backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommandTestAbstract.java M backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ImportVmCommandTest.java M backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ImportVmTemplateCommandTest.java M backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommandTest.java M backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmDiskCommandTest.java M backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/lsm/LiveMigrateVmDisksCommandTest.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties M frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java M frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties 23 files changed, 276 insertions(+), 21 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/14/31814/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddDiskCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddDiskCommand.java index fe2bb5a..2dcf6fc 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddDiskCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddDiskCommand.java @@ -7,6 +7,7 @@ import org.apache.commons.lang.StringUtils; import org.ovirt.engine.core.bll.context.CommandContext; +import org.ovirt.engine.core.bll.profiles.DiskProfileHelper; import org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter; import org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter; import org.ovirt.engine.core.bll.quota.QuotaStorageDependent; @@ -116,6 +117,10 @@ } if (DiskStorageType.IMAGE == getParameters().getDiskInfo().getDiskStorageType()) { + if (!setAndValidateDiskProfiles()) { + return false; + } + return checkIfImageDiskCanBeAdded(vm, diskValidator); } @@ -583,6 +588,11 @@ } } + protected boolean setAndValidateDiskProfiles() { + return validate(DiskProfileHelper.setAndValidateDiskProfiles(Collections.singletonMap(getDiskImageInfo(), + getStorageDomainId()), getStoragePool().getcompatibility_version())); + } + @Override public List<QuotaConsumptionParameter> getQuotaStorageConsumptionParameters() { List<QuotaConsumptionParameter> list = new ArrayList<QuotaConsumptionParameter>(); diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java index dc00dec..c61d0ce 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java @@ -14,6 +14,7 @@ import org.ovirt.engine.core.bll.network.MacPoolManager; import org.ovirt.engine.core.bll.network.VmInterfaceManager; import org.ovirt.engine.core.bll.network.cluster.NetworkHelper; +import org.ovirt.engine.core.bll.profiles.DiskProfileHelper; import org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter; import org.ovirt.engine.core.bll.quota.QuotaSanityParameter; import org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter; @@ -587,6 +588,22 @@ return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_MIN_MEMORY_CANNOT_EXCEED_MEMORY_SIZE); } + if (!setAndValidateDiskProfiles()) { + return false; + } + + return true; + } + + protected boolean setAndValidateDiskProfiles() { + if (diskInfoDestinationMap != null && !diskInfoDestinationMap.isEmpty()) { + Map<DiskImage, Guid> map = new HashMap<>(); + for (DiskImage diskImage : diskInfoDestinationMap.values()) { + map.put(diskImage, diskImage.getStorageIds().get(0)); + } + return validate(DiskProfileHelper.setAndValidateDiskProfiles(map, + getStoragePool().getcompatibility_version())); + } return true; } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmTemplateCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmTemplateCommand.java index 79b3602..f48313b 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmTemplateCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmTemplateCommand.java @@ -13,6 +13,7 @@ import org.apache.commons.lang.StringUtils; import org.ovirt.engine.core.bll.context.CommandContext; +import org.ovirt.engine.core.bll.profiles.DiskProfileHelper; import org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter; import org.ovirt.engine.core.bll.quota.QuotaSanityParameter; import org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter; @@ -397,6 +398,10 @@ } } + if (!setAndValidateDiskProfiles()) { + return false; + } + if (isInstanceType) { return true; } else { @@ -404,6 +409,18 @@ } } + protected boolean setAndValidateDiskProfiles() { + if (diskInfoDestinationMap != null && !diskInfoDestinationMap.isEmpty()) { + Map<DiskImage, Guid> map = new HashMap<>(); + for (DiskImage diskImage : diskInfoDestinationMap.values()) { + map.put(diskImage, diskImage.getStorageIds().get(0)); + } + return validate(DiskProfileHelper.setAndValidateDiskProfiles(map, + getStoragePool().getcompatibility_version())); + } + return true; + } + private VmTemplate getBaseTemplate() { if (cachedBaseTemplate == null) { cachedBaseTemplate = getVmTemplateDAO().get(getParameters().getBaseTemplateId()); diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommand.java index 963e287..cf57796 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommand.java @@ -8,6 +8,7 @@ import org.ovirt.engine.core.bll.context.CommandContext; import org.ovirt.engine.core.bll.job.ExecutionContext; import org.ovirt.engine.core.bll.job.ExecutionHandler; +import org.ovirt.engine.core.bll.profiles.DiskProfileHelper; import org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter; import org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter; import org.ovirt.engine.core.bll.quota.QuotaStorageDependent; @@ -297,7 +298,9 @@ !FeatureSupported.virtIoScsi(getVdsGroup().getcompatibility_version())) { return failCanDoAction(VdcBllMessages.VIRTIO_SCSI_INTERFACE_IS_NOT_AVAILABLE_FOR_CLUSTER_LEVEL); } - + if (!setAndValidateDiskProfiles()) { + return false; + } return checkFreeSpaceAndTypeOnDestDomains(); } @@ -394,6 +397,18 @@ return Integer.toString(getParameters().getVmsCount()); } + protected boolean setAndValidateDiskProfiles() { + if (diskInfoDestinationMap != null && !diskInfoDestinationMap.isEmpty()) { + Map<DiskImage, Guid> map = new HashMap<>(); + for (DiskImage diskImage : diskInfoDestinationMap.values()) { + map.put(diskImage, diskImage.getStorageIds().get(0)); + } + return validate(DiskProfileHelper.setAndValidateDiskProfiles(map, + getStoragePool().getcompatibility_version())); + } + return true; + } + @Override public List<QuotaConsumptionParameter> getQuotaStorageConsumptionParameters() { List<QuotaConsumptionParameter> list = new ArrayList<QuotaConsumptionParameter>(); diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java index 313b82f..b424d06 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java @@ -17,6 +17,7 @@ import org.ovirt.engine.core.bll.network.MacPoolManager; import org.ovirt.engine.core.bll.network.VmInterfaceManager; import org.ovirt.engine.core.bll.network.vm.VnicProfileHelper; +import org.ovirt.engine.core.bll.profiles.DiskProfileHelper; import org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter; import org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter; import org.ovirt.engine.core.bll.quota.QuotaStorageDependent; @@ -441,6 +442,10 @@ } if (!validateMacAddress(Entities.<VmNic, VmNetworkInterface> upcast(getVm().getInterfaces()))) { + return false; + } + + if (!setAndValidateDiskProfiles()) { return false; } @@ -1279,6 +1284,21 @@ return jobProperties; } + protected boolean setAndValidateDiskProfiles() { + if (getParameters().getVm().getDiskMap() != null) { + Map<DiskImage, Guid> map = new HashMap<>(); + for (Disk disk : getParameters().getVm().getDiskMap().values()) { + if (disk.getDiskStorageType() == DiskStorageType.IMAGE) { + DiskImage diskImage = (DiskImage) disk; + map.put(diskImage, imageToDestinationDomainMap.get(diskImage.getId())); + } + } + return validate(DiskProfileHelper.setAndValidateDiskProfiles(map, + getStoragePool().getcompatibility_version())); + } + return true; + } + @Override public List<QuotaConsumptionParameter> getQuotaStorageConsumptionParameters() { List<QuotaConsumptionParameter> list = new ArrayList<QuotaConsumptionParameter>(); diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmTemplateCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmTemplateCommand.java index 447b056..5dfb4a7 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmTemplateCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmTemplateCommand.java @@ -7,6 +7,7 @@ import java.util.Map; import org.ovirt.engine.core.bll.network.vm.VnicProfileHelper; +import org.ovirt.engine.core.bll.profiles.DiskProfileHelper; import org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter; import org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter; import org.ovirt.engine.core.bll.quota.QuotaStorageDependent; @@ -209,6 +210,11 @@ addCanDoActionMessage(VdcBllMessages.VMT_CANNOT_IMPORT_TEMPLATE_VERSION_MISSING_BASE); } } + + if (retVal && !setAndValidateDiskProfiles()) { + return false; + } + if (!retVal) { addCanDoActionMessage(VdcBllMessages.VAR__ACTION__IMPORT); addCanDoActionMessage(VdcBllMessages.VAR__TYPE__VM_TEMPLATE); @@ -541,6 +547,18 @@ return jobProperties; } + protected boolean setAndValidateDiskProfiles() { + if (getParameters().getVmTemplate().getDiskList() != null) { + Map<DiskImage, Guid> map = new HashMap<>(); + for (DiskImage diskImage : getParameters().getVmTemplate().getDiskList()) { + map.put(diskImage, imageToDestinationDomainMap.get(diskImage.getId())); + } + return validate(DiskProfileHelper.setAndValidateDiskProfiles(map, + getStoragePool().getcompatibility_version())); + } + return true; + } + @Override public List<QuotaConsumptionParameter> getQuotaStorageConsumptionParameters() { List<QuotaConsumptionParameter> list = new ArrayList<QuotaConsumptionParameter>(); diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java index eedc36b..56679d0 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommand.java @@ -9,6 +9,7 @@ import org.apache.commons.lang.StringUtils; import org.ovirt.engine.core.bll.context.CommandContext; +import org.ovirt.engine.core.bll.profiles.DiskProfileHelper; import org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter; import org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter; import org.ovirt.engine.core.bll.quota.QuotaStorageDependent; @@ -95,7 +96,8 @@ && checkTemplateInDestStorageDomain() && validateSpaceRequirements() && checkCanBeMoveInVm() - && checkIfNeedToBeOverride(); + && checkIfNeedToBeOverride() + && setAndValidateDiskProfiles(); } protected boolean isSourceAndDestTheSame() { @@ -328,6 +330,7 @@ getParameters().setCopyVolumeType(CopyVolumeType.SharedVol); getParameters().setParentCommand(getActionType()); getParameters().setParentParameters(getParameters()); + getParameters().setDiskProfileId(getImage().getDiskProfileId()); } /** @@ -386,6 +389,12 @@ return getImage().getDiskAlias(); } + protected boolean setAndValidateDiskProfiles() { + getImage().setDiskProfileId(getParameters().getDiskProfileId()); + return validate(DiskProfileHelper.setAndValidateDiskProfiles(Collections.singletonMap(getImage(), + getParameters().getStorageDomainId()), getStoragePool().getcompatibility_version())); + } + @Override public List<QuotaConsumptionParameter> getQuotaStorageConsumptionParameters() { List<QuotaConsumptionParameter> list = new ArrayList<QuotaConsumptionParameter>(); diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RegisterDiskCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RegisterDiskCommand.java index 755e483..07a8cf8 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RegisterDiskCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RegisterDiskCommand.java @@ -1,5 +1,11 @@ package org.ovirt.engine.core.bll; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; +import java.util.List; + +import org.ovirt.engine.core.bll.profiles.DiskProfileHelper; import org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter; import org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter; import org.ovirt.engine.core.bll.quota.QuotaStorageDependent; @@ -11,10 +17,6 @@ import org.ovirt.engine.core.common.businessentities.DiskImage; import org.ovirt.engine.core.common.errors.VdcBllMessages; import org.ovirt.engine.core.compat.Guid; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.List; public class RegisterDiskCommand <T extends RegisterDiskParameters> extends BaseImagesCommand<T> implements QuotaStorageDependent { @@ -54,6 +56,10 @@ return false; } + if (!setAndValidateDiskProfiles()) { + return false; + } + return true; } @@ -80,6 +86,11 @@ addCanDoActionMessage(VdcBllMessages.VAR__TYPE__VM_DISK); } + protected boolean setAndValidateDiskProfiles() { + return validate(DiskProfileHelper.setAndValidateDiskProfiles(Collections.singletonMap(getParameters().getDiskImage(), + getStorageDomainId()), getStoragePool().getcompatibility_version())); + } + @Override public List<QuotaConsumptionParameter> getQuotaStorageConsumptionParameters() { List<QuotaConsumptionParameter> list = new ArrayList<QuotaConsumptionParameter>(); diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmDiskCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmDiskCommand.java index f1206b3..032675c 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmDiskCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmDiskCommand.java @@ -10,6 +10,7 @@ import java.util.Objects; import org.apache.commons.lang.StringUtils; +import org.ovirt.engine.core.bll.profiles.DiskProfileHelper; import org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter; import org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter; import org.ovirt.engine.core.bll.quota.QuotaStorageDependent; @@ -168,7 +169,8 @@ return validateCanUpdateShareable() && validateCanUpdateReadOnly(diskValidator) && validate(diskValidator.isVirtIoScsiValid(getVm())) && (getOldDisk().getDiskInterface() == getNewDisk().getDiskInterface() - || validate(diskValidator.isDiskInterfaceSupported(getVm()))); + || validate(diskValidator.isDiskInterfaceSupported(getVm()))) && + setAndValidateDiskProfiles(); } @Override @@ -520,6 +522,17 @@ return null; } + protected boolean setAndValidateDiskProfiles() { + if (isDiskImage()) { + DiskImage diskImage = (DiskImage) getNewDisk(); + Map<DiskImage, Guid> map = new HashMap<>(); + map.put(diskImage, diskImage.getStorageIds().get(0)); + return validate(DiskProfileHelper.setAndValidateDiskProfiles(map, + getStoragePool().getcompatibility_version())); + } + return true; + } + @Override public List<QuotaConsumptionParameter> getQuotaStorageConsumptionParameters() { List<QuotaConsumptionParameter> list = new ArrayList<>(); diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/lsm/LiveMigrateVmDisksCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/lsm/LiveMigrateVmDisksCommand.java index dcead5b..1ef375a 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/lsm/LiveMigrateVmDisksCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/lsm/LiveMigrateVmDisksCommand.java @@ -14,6 +14,7 @@ import org.ovirt.engine.core.bll.InternalCommandAttribute; import org.ovirt.engine.core.bll.LockMessagesMatchUtil; import org.ovirt.engine.core.bll.NonTransactiveCommandAttribute; +import org.ovirt.engine.core.bll.profiles.DiskProfileHelper; import org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter; import org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter; import org.ovirt.engine.core.bll.quota.QuotaStorageDependent; @@ -256,6 +257,16 @@ addCanDoActionMessage(VdcBllMessages.VAR__TYPE__VM_DISK); } + protected boolean setAndValidateDiskProfiles() { + Map<DiskImage, Guid> map = new HashMap<>(); + for (LiveMigrateDiskParameters parameters : getParameters().getParametersList()) { + DiskImage diskImage = getDiskImageByImageId(parameters.getImageId()); + map.put(diskImage, diskImage.getStorageIds().get(0)); + } + return validate(DiskProfileHelper.setAndValidateDiskProfiles(map, + getStoragePool().getcompatibility_version())); + } + @Override public List<QuotaConsumptionParameter> getQuotaStorageConsumptionParameters() { List<QuotaConsumptionParameter> list = new ArrayList<QuotaConsumptionParameter>(); @@ -303,6 +314,10 @@ } } + if (!setAndValidateDiskProfiles()) { + return false; + } + return true; } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/DiskProfileHelper.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/DiskProfileHelper.java index d140057..1928c6d 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/DiskProfileHelper.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/DiskProfileHelper.java @@ -1,7 +1,19 @@ package org.ovirt.engine.core.bll.profiles; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.ovirt.engine.core.bll.ValidationResult; +import org.ovirt.engine.core.common.FeatureSupported; +import org.ovirt.engine.core.common.businessentities.DiskImage; import org.ovirt.engine.core.common.businessentities.profiles.DiskProfile; +import org.ovirt.engine.core.common.errors.VdcBllMessages; import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.compat.Version; +import org.ovirt.engine.core.dal.dbbroker.DbFacade; +import org.ovirt.engine.core.dao.profiles.DiskProfileDao; public class DiskProfileHelper { @@ -16,4 +28,40 @@ profile.setStorageDomainId(storageDomainId); return profile; } + + public static ValidationResult setAndValidateDiskProfiles(Map<DiskImage, Guid> map, Version version) { + if (map == null || !FeatureSupported.storageQoS(version)) { + return ValidationResult.VALID; + } + + Map<Guid, List<DiskProfile>> storageDiskProfilesMap = new HashMap<>(); + for (Entry<DiskImage, Guid> entry : map.entrySet()) { + DiskImage diskImage = entry.getKey(); + Guid storageDomainId = entry.getValue(); + if (diskImage.getDiskProfileId() == null && storageDomainId != null) { // set disk profile if there's only 1 for SD. + List<DiskProfile> diskProfilesList = storageDiskProfilesMap.get(storageDomainId); + if (diskProfilesList == null) { + diskProfilesList = getDiskProfileDao().getAllForStorageDomain(storageDomainId); + storageDiskProfilesMap.put(storageDomainId, diskProfilesList); + } + if (diskProfilesList.size() == 1) { + diskImage.setDiskProfileId(diskProfilesList.get(0).getId()); + } else { + return new ValidationResult(VdcBllMessages.ACTION_TYPE_DISK_PROFILE_EMPTY); + } + } else { + ValidationResult result = + new DiskProfileValidator(getDiskProfileDao().get(diskImage.getDiskProfileId())).isStorageDomainValid(storageDomainId); + if (result != ValidationResult.VALID) { + return result; + } + } + } + + return ValidationResult.VALID; + } + + private static DiskProfileDao getDiskProfileDao() { + return DbFacade.getInstance().getDiskProfileDao(); + } } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/DiskProfileValidator.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/DiskProfileValidator.java index d5a0e80..5cc370c 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/DiskProfileValidator.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/DiskProfileValidator.java @@ -10,18 +10,26 @@ import org.ovirt.engine.core.common.businessentities.StorageDomain; import org.ovirt.engine.core.common.businessentities.profiles.DiskProfile; import org.ovirt.engine.core.common.errors.VdcBllMessages; +import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.dal.dbbroker.DbFacade; +import org.ovirt.engine.core.dao.profiles.DiskProfileDao; import org.ovirt.engine.core.utils.ReplacementUtils; public class DiskProfileValidator { - private final DiskProfile diskProfile; + private final Guid diskProfileId; + private DiskProfile diskProfile; private DiskProfile diskProfileFromDb; private StorageDomain storageDomain; private List<DiskProfile> diskProfiles; public DiskProfileValidator(DiskProfile diskProfile) { + this(diskProfile != null ? diskProfile.getId() : null); this.diskProfile = diskProfile; + } + + public DiskProfileValidator(Guid diskProfileId) { + this.diskProfileId = diskProfileId; } protected DbFacade getDbFacade() { @@ -29,7 +37,7 @@ } public ValidationResult diskProfileIsSet() { - return diskProfile == null + return getDiskProfile() == null ? new ValidationResult(VdcBllMessages.ACTION_TYPE_FAILED_PROFILE_NOT_EXISTS) : ValidationResult.VALID; } @@ -45,15 +53,16 @@ } public ValidationResult qosExistsOrNull() { - return diskProfile.getQosId() == null - || getDbFacade().getStorageQosDao().get(diskProfile.getQosId()) != null + return getDiskProfile().getQosId() == null + || getDbFacade().getStorageQosDao().get(getDiskProfile().getQosId()) != null ? ValidationResult.VALID : new ValidationResult(VdcBllMessages.ACTION_TYPE_FAILED_QOS_NOT_FOUND); } public ValidationResult diskProfileNameNotUsed() { for (DiskProfile profile : getDiskProfiles()) { - if (profile.getName().equals(diskProfile.getName()) && !profile.getId().equals(diskProfile.getId())) { + if (profile.getName().equals(getDiskProfile().getName()) + && !profile.getId().equals(getDiskProfile().getId())) { return new ValidationResult(VdcBllMessages.ACTION_TYPE_FAILED_PROFILE_NAME_IN_USE); } } @@ -62,7 +71,7 @@ } public ValidationResult storageDomainNotChanged() { - if (ObjectUtils.equals(diskProfile.getStorageDomainId(), getDiskProfileFromDb().getStorageDomainId())) { + if (ObjectUtils.equals(getDiskProfile().getStorageDomainId(), getDiskProfileFromDb().getStorageDomainId())) { return ValidationResult.VALID; } @@ -81,15 +90,22 @@ protected StorageDomain getStorageDomain() { if (storageDomain == null) { - storageDomain = getDbFacade().getStorageDomainDao().get(diskProfile.getStorageDomainId()); + storageDomain = getDbFacade().getStorageDomainDao().get(getDiskProfile().getStorageDomainId()); } return storageDomain; } + public DiskProfile getDiskProfile() { + if (diskProfile == null) { + diskProfile = getDiskProfileDao().get(diskProfileId); + } + return diskProfile; + } + protected List<DiskProfile> getDiskProfiles() { if (diskProfiles == null) { - diskProfiles = getDbFacade().getDiskProfileDao().getAllForStorageDomain(diskProfile.getStorageDomainId()); + diskProfiles = getDiskProfileDao().getAllForStorageDomain(getDiskProfile().getStorageDomainId()); } return diskProfiles; @@ -102,4 +118,25 @@ return diskProfileFromDb; } + + public ValidationResult isStorageDomainValid(Guid storageDomainId) { + if (storageDomainId == null) { + return new ValidationResult(VdcBllMessages.ACTION_TYPE_DISK_PROFILE_STORAGE_DOMAIN_NOT_PROVIDED); + } + if (diskProfileId == null) { + return new ValidationResult(VdcBllMessages.ACTION_TYPE_DISK_PROFILE_EMPTY); + } + DiskProfile fetchedDiskProfile = getDiskProfileDao().get(diskProfileId); + if (fetchedDiskProfile == null) { + return new ValidationResult(VdcBllMessages.ACTION_TYPE_FAILED_DISK_PROFILE_NOT_FOUND); + } + if (!storageDomainId.equals(fetchedDiskProfile.getStorageDomainId())) { + return new ValidationResult(VdcBllMessages.ACTION_TYPE_DISK_PROFILE_NOT_MATCH_STORAGE_DOMAIN); + } + return ValidationResult.VALID; + } + + private DiskProfileDao getDiskProfileDao() { + return getDbFacade().getDiskProfileDao(); + } } diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddDiskToVmCommandTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddDiskToVmCommandTest.java index f14691b..3a04198 100644 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddDiskToVmCommandTest.java +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddDiskToVmCommandTest.java @@ -361,6 +361,7 @@ doReturn(false).when(command).hasWatchdog(any(Guid.class)); doReturn(false).when(command).isBalloonEnabled(any(Guid.class)); doReturn(false).when(command).isSoundDeviceEnabled(any(Guid.class)); + doReturn(true).when(command).setAndValidateDiskProfiles(); SimpleDependecyInjector.getInstance().bind(OsRepository.class, osRepository); } diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommandTestAbstract.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommandTestAbstract.java index 197b190..4f9d818 100644 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommandTestAbstract.java +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommandTestAbstract.java @@ -22,8 +22,10 @@ import org.ovirt.engine.core.common.action.AddVmPoolWithVmsParameters; import org.ovirt.engine.core.common.businessentities.ArchitectureType; import org.ovirt.engine.core.common.businessentities.DiskImage; +import org.ovirt.engine.core.common.businessentities.StorageDomain; import org.ovirt.engine.core.common.businessentities.StorageDomainStatus; import org.ovirt.engine.core.common.businessentities.StorageDomainType; +import org.ovirt.engine.core.common.businessentities.StoragePool; import org.ovirt.engine.core.common.businessentities.StoragePoolStatus; import org.ovirt.engine.core.common.businessentities.VDSGroup; import org.ovirt.engine.core.common.businessentities.VM; @@ -31,8 +33,6 @@ import org.ovirt.engine.core.common.businessentities.VmPool; import org.ovirt.engine.core.common.businessentities.VmStatic; import org.ovirt.engine.core.common.businessentities.VmTemplate; -import org.ovirt.engine.core.common.businessentities.StorageDomain; -import org.ovirt.engine.core.common.businessentities.StoragePool; import org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface; import org.ovirt.engine.core.common.config.ConfigValues; import org.ovirt.engine.core.common.interfaces.VDSBrokerFrontend; @@ -130,6 +130,7 @@ command = createCommand(); doReturn(true).when(command).areTemplateImagesInStorageReady(any(Guid.class)); doReturn(true).when(command).verifyAddVM(); + doReturn(true).when(command).setAndValidateDiskProfiles(); } private void mockVds() { diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ImportVmCommandTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ImportVmCommandTest.java index 352994f..8021bb3 100644 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ImportVmCommandTest.java +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ImportVmCommandTest.java @@ -110,6 +110,7 @@ doReturn(true).when(cmd).canAddVm(); doReturn(true).when(cmd).checkTemplateInStorageDomain(); doReturn(true).when(cmd).checkImagesGUIDsLegal(); + doReturn(true).when(cmd).setAndValidateDiskProfiles(); doReturn(true).when(cmd).validateNoDuplicateDiskImages(any(Iterable.class)); doReturn(createSourceDomain()).when(cmd).getSourceDomain(); doReturn(createStorageDomain()).when(cmd).getStorageDomain(any(Guid.class)); @@ -285,6 +286,7 @@ doReturn(true).when(cmd).canAddVm(); doReturn(true).when(cmd).checkTemplateInStorageDomain(); doReturn(true).when(cmd).checkImagesGUIDsLegal(); + doReturn(true).when(cmd).setAndValidateDiskProfiles(); doReturn(true).when(cmd).validateNoDuplicateDiskImages(any(Iterable.class)); doReturn(createSourceDomain()).when(cmd).getSourceDomain(); doReturn(createStorageDomain()).when(cmd).getStorageDomain(any(Guid.class)); diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ImportVmTemplateCommandTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ImportVmTemplateCommandTest.java index 096acb6..70f293a 100644 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ImportVmTemplateCommandTest.java +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/ImportVmTemplateCommandTest.java @@ -157,6 +157,7 @@ doReturn(mock(VmTemplateDAO.class)).when(command).getVmTemplateDAO(); mockStoragePool(command); mockStorageDomains(command); + doReturn(true).when(command).setAndValidateDiskProfiles(); return command; } diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommandTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommandTest.java index 9afc2b0..affdafc 100644 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommandTest.java +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/MoveOrCopyDiskCommandTest.java @@ -276,8 +276,8 @@ operation))); doReturn(mockStorageDomainValidatorWithSpace()).when(command).createStorageDomainValidator(); - doReturn(false).when(command).acquireLock(); + doReturn(true).when(command).setAndValidateDiskProfiles(); } private void initTemplateDiskImage() { diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmDiskCommandTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmDiskCommandTest.java index cc28c7a..2c591b4 100644 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmDiskCommandTest.java +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmDiskCommandTest.java @@ -5,9 +5,9 @@ import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyList; import static org.mockito.Mockito.atLeast; -import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -54,10 +54,10 @@ import org.ovirt.engine.core.common.businessentities.VolumeFormat; import org.ovirt.engine.core.common.config.ConfigValues; import org.ovirt.engine.core.common.errors.VdcBllMessages; -import org.ovirt.engine.core.common.utils.Pair; -import org.ovirt.engine.core.common.utils.VmDeviceType; import org.ovirt.engine.core.common.osinfo.OsRepository; +import org.ovirt.engine.core.common.utils.Pair; import org.ovirt.engine.core.common.utils.SimpleDependecyInjector; +import org.ovirt.engine.core.common.utils.VmDeviceType; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.compat.Version; import org.ovirt.engine.core.dal.dbbroker.DbFacade; @@ -600,6 +600,7 @@ doReturn(ValidationResult.VALID).when(snapshotsValidator).vmNotInPreview(any(Guid.class)); when(diskValidator.isVirtIoScsiValid(any(VM.class))).thenReturn(ValidationResult.VALID); when(diskValidator.isDiskUsedAsOvfStore()).thenReturn(ValidationResult.VALID); + doReturn(true).when(command).setAndValidateDiskProfiles(); SimpleDependecyInjector.getInstance().bind(OsRepository.class, osRepository); diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/lsm/LiveMigrateVmDisksCommandTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/lsm/LiveMigrateVmDisksCommandTest.java index 8fe4b6c..1e05022 100644 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/lsm/LiveMigrateVmDisksCommandTest.java +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/lsm/LiveMigrateVmDisksCommandTest.java @@ -101,6 +101,7 @@ doReturn(true).when(command).validateSpaceRequirements(); doReturn(true).when(command).checkImagesStatus(); + doReturn(true).when(command).setAndValidateDiskProfiles(); } private List<LiveMigrateDiskParameters> createLiveMigrateVmDisksParameters() { diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java index 3e028a7..e4a5e14 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java @@ -1012,6 +1012,9 @@ ACTION_TYPE_FAILED_CANNOT_CHANGE_PROFILE(ErrorType.BAD_PARAMETERS), ACTION_TYPE_FAILED_PROFILE_IN_USE(ErrorType.BAD_PARAMETERS), ACTION_TYPE_DISK_PROFILE_EMPTY(ErrorType.BAD_PARAMETERS), + ACTION_TYPE_FAILED_DISK_PROFILE_NOT_FOUND(ErrorType.BAD_PARAMETERS), + ACTION_TYPE_DISK_PROFILE_STORAGE_DOMAIN_NOT_PROVIDED(ErrorType.BAD_PARAMETERS), + ACTION_TYPE_DISK_PROFILE_NOT_MATCH_STORAGE_DOMAIN(ErrorType.BAD_PARAMETERS), // Affinity Groups AFFINITY_GROUP_NAME_TOO_LONG(ErrorType.BAD_PARAMETERS), diff --git a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties index f9f04bc..6ef497c 100644 --- a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties +++ b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties @@ -1139,6 +1139,9 @@ ACTION_TYPE_FAILED_PROFILE_NAME_IN_USE=Cannot ${action} ${type}. Profile name is in use. ACTION_TYPE_FAILED_CANNOT_CHANGE_PROFILE=Cannot ${action} ${type}. Cannot change profile. ACTION_TYPE_FAILED_PROFILE_IN_USE=Cannot ${action} ${type}. Profile is in use. +ACTION_TYPE_FAILED_DISK_PROFILE_NOT_FOUND=Cannot ${action} ${type}. Disk Profile wasn't found. +ACTION_TYPE_DISK_PROFILE_STORAGE_DOMAIN_NOT_PROVIDED=Cannot ${action} ${type}. Storage Domain wasn't provided. +ACTION_TYPE_DISK_PROFILE_NOT_MATCH_STORAGE_DOMAIN=Cannot ${action} ${type}. Disk Profile doesn't match provided Storage Domain. # cluster policy errors ACTION_TYPE_FAILED_CLUSTER_POLICY_PARAMETERS_INVALID=Cannot ${action} ${type}. Parameters are invalid. diff --git a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java index 6a242c0..63c2fc0 100644 --- a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java +++ b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java @@ -3093,6 +3093,15 @@ @DefaultStringValue("Cannot ${action} ${type}. Profile is in use.") String ACTION_TYPE_FAILED_PROFILE_IN_USE(); + @DefaultStringValue("Cannot ${action} ${type}. Disk Profile wasn't found.") + String ACTION_TYPE_FAILED_DISK_PROFILE_NOT_FOUND(); + + @DefaultStringValue("Cannot ${action} ${type}. Storage Domain wasn't provided.") + String ACTION_TYPE_DISK_PROFILE_STORAGE_DOMAIN_NOT_PROVIDED(); + + @DefaultStringValue("Cannot ${action} ${type}. Disk Profile doesn't match provided Storage Domain.") + String ACTION_TYPE_DISK_PROFILE_NOT_MATCH_STORAGE_DOMAIN(); + @DefaultStringValue("Cannot ${action}. New disk size cannot be smaller than the current.") String ACTION_TYPE_FAILED_REQUESTED_DISK_SIZE_IS_TOO_SMALL(); diff --git a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties index 3b183bc..915a8bf 100644 --- a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties +++ b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties @@ -1114,6 +1114,9 @@ ACTION_TYPE_FAILED_PROFILE_NAME_IN_USE=Cannot ${action} ${type}. Profile name is in use. ACTION_TYPE_FAILED_CANNOT_CHANGE_PROFILE=Cannot ${action} ${type}. Cannot change profile. ACTION_TYPE_FAILED_PROFILE_IN_USE=Cannot ${action} ${type}. Profile is in use. +ACTION_TYPE_FAILED_DISK_PROFILE_NOT_FOUND=Cannot ${action} ${type}. Disk Profile wasn't found. +ACTION_TYPE_DISK_PROFILE_STORAGE_DOMAIN_NOT_PROVIDED=Cannot ${action} ${type}. Storage Domain wasn't provided. +ACTION_TYPE_DISK_PROFILE_NOT_MATCH_STORAGE_DOMAIN=Cannot ${action} ${type}. Disk Profile doesn't match provided Storage Domain. # cluster policy errors ACTION_TYPE_FAILED_CLUSTER_POLICY_PARAMETERS_INVALID=Cannot ${action} ${type}. Parameters are invalid. -- To view, visit http://gerrit.ovirt.org/31814 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie7b6d977243cffc0bde772665ebaca47340075c6 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: ovirt-engine-3.5 Gerrit-Owner: Gilad Chaplik <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
