Arik Hadas has uploaded a new change for review. Change subject: core: share common import validations ......................................................................
core: share common import validations Before adding import-from-external-provider, the common validations for all import-vm operations are moved to ImportVmCommandBase. Change-Id: Ic0b7930d130192688d904c2e11ec839d8478ac78 Signed-off-by: Arik Hadas <aha...@redhat.com> --- 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/ImportVmCommandBase.java 2 files changed, 93 insertions(+), 98 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/40/42040/1 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 932592a..2b028227 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 @@ -18,7 +18,6 @@ import org.ovirt.engine.core.bll.memory.MemoryStorageHandler; import org.ovirt.engine.core.bll.memory.MemoryUtils; import org.ovirt.engine.core.bll.network.VmInterfaceManager; -import org.ovirt.engine.core.bll.profiles.CpuProfileHelper; import org.ovirt.engine.core.bll.profiles.DiskProfileHelper; import org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter; import org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter; @@ -42,20 +41,14 @@ import org.ovirt.engine.core.common.asynctasks.AsyncTaskCreationInfo; import org.ovirt.engine.core.common.asynctasks.EntityInfo; import org.ovirt.engine.core.common.businessentities.ActionGroup; -import org.ovirt.engine.core.common.businessentities.ArchitectureType; import org.ovirt.engine.core.common.businessentities.Entities; -import org.ovirt.engine.core.common.businessentities.GraphicsType; import org.ovirt.engine.core.common.businessentities.Snapshot; import org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotStatus; import org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType; import org.ovirt.engine.core.common.businessentities.StorageDomain; import org.ovirt.engine.core.common.businessentities.StorageDomainStatic; import org.ovirt.engine.core.common.businessentities.StorageDomainType; -import org.ovirt.engine.core.common.businessentities.VDSGroup; import org.ovirt.engine.core.common.businessentities.VM; -import org.ovirt.engine.core.common.businessentities.VmDevice; -import org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType; -import org.ovirt.engine.core.common.businessentities.VmStatic; import org.ovirt.engine.core.common.businessentities.VmTemplate; import org.ovirt.engine.core.common.businessentities.VmTemplateStatus; import org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface; @@ -79,7 +72,6 @@ import org.ovirt.engine.core.common.queries.VdcQueryReturnValue; import org.ovirt.engine.core.common.queries.VdcQueryType; import org.ovirt.engine.core.common.utils.Pair; -import org.ovirt.engine.core.common.utils.VmDeviceType; import org.ovirt.engine.core.common.validation.group.ImportClonedEntity; import org.ovirt.engine.core.common.validation.group.ImportEntity; import org.ovirt.engine.core.common.vdscommands.GetImageInfoVDSCommandParameters; @@ -131,19 +123,6 @@ ImportUtils.updateGraphicsDevices( getVm() != null ? getVm().getStaticData() : null, getVdsGroup() != null ? getVdsGroup().getCompatibilityVersion() : null); - } - - private List<VmDevice> getDevicesOfType(VmDeviceGeneralType type) { - List<VmDevice> devices = new ArrayList<>(); - - if (getVm() != null && getVm().getStaticData() != null && getVm().getStaticData().getManagedDeviceMap() != null) { - for (VmDevice vmDevice : getVm().getStaticData().getManagedDeviceMap().values()) { - if (vmDevice.getType() == type) { - devices.add(vmDevice); - } - } - } - return devices; } @Override @@ -443,12 +422,7 @@ return false; } - // Check if the display type is supported - if (!VmHandler.isGraphicsAndDisplaySupported(vmFromParams.getOs(), - getGraphicsTypesForVm(), - vmFromParams.getDefaultDisplayType(), - getReturnValue().getCanDoActionMessages(), - getVdsGroup().getCompatibilityVersion())) { + if (!validateGraphicsAndDisplay()) { return false; } @@ -465,16 +439,6 @@ } return true; - } - - Set<GraphicsType> getGraphicsTypesForVm() { - Set<GraphicsType> graphicsTypes = new HashSet<>(); - - for (VmDevice graphics : getDevicesOfType(VmDeviceGeneralType.GRAPHICS)) { - graphicsTypes.add(GraphicsType.fromVmDeviceType(VmDeviceType.getByName(graphics.getDevice()))); - } - - return graphicsTypes; } protected boolean handleDestStorageDomains() { @@ -548,19 +512,6 @@ return disksDummies; } - /** - * Validates that there is no duplicate VM. - * @return <code>true</code> if the validation passes, <code>false</code> otherwise. - */ - protected boolean validateNoDuplicateVm() { - VmStatic duplicateVm = getVmStaticDAO().get(getVm().getId()); - if (duplicateVm != null) { - return failCanDoAction(VdcBllMessages.VM_CANNOT_IMPORT_VM_EXISTS, - String.format("$VmName %1$s", duplicateVm.getName())); - } - return true; - } - protected boolean validateDiskInterface(Iterable<DiskImage> images) { for (DiskImage diskImage : images) { if (diskImage.getDiskInterface() == DiskInterface.VirtIO_SCSI && @@ -579,47 +530,6 @@ } return true; - } - - /** - * Validates that that the required cluster exists and is compatible - * @return <code>true</code> if the validation passes, <code>false</code> otherwise. - */ - protected boolean validateVdsCluster() { - List<VDSGroup> groups = getVdsGroupDAO().getAllForStoragePool(getParameters().getStoragePoolId()); - for (VDSGroup group : groups) { - if (group.getId().equals(getParameters().getVdsGroupId())) { - if (group.getArchitecture() != getVm().getClusterArch()) { - return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_VM_CANNOT_IMPORT_VM_ARCHITECTURE_NOT_SUPPORTED_BY_CLUSTER); - } - return true; - } - } - return failCanDoAction(VdcBllMessages.VDS_CLUSTER_IS_NOT_VALID); - } - - /** - * Validates if the VM being imported has a valid architecture. - * @return - */ - protected boolean validateVmArchitecture () { - if (getVm().getClusterArch() == ArchitectureType.undefined) { - return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_VM_CANNOT_IMPORT_VM_WITH_NOT_SUPPORTED_ARCHITECTURE); - } - return true; - } - - /** - * Validates the USB policy. - * @return <code>true</code> if the validation passes, <code>false</code> otherwise. - */ - protected boolean validateUsbPolicy() { - VM vm = getParameters().getVm(); - VmHandler.updateImportedVmUsbPolicy(vm.getStaticData()); - return VmHandler.isUsbPolicyLegal(vm.getUsbPolicy(), - vm.getOs(), - getVdsGroup(), - getReturnValue().getCanDoActionMessages()); } private boolean isTemplateExistsOnExportDomain() { @@ -1184,13 +1094,6 @@ getStoragePool().getCompatibilityVersion(), getCurrentUser())); } return true; - } - - protected boolean setAndValidateCpuProfile() { - getVm().getStaticData().setVdsGroupId(getVdsGroupId()); - getVm().getStaticData().setCpuProfileId(getParameters().getCpuProfileId()); - return validate(CpuProfileHelper.setAndValidateCpuProfile(getVm().getStaticData(), - getVdsGroup().getCompatibilityVersion())); } @Override diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommandBase.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommandBase.java index 4706e8c..695691e 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommandBase.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommandBase.java @@ -4,21 +4,28 @@ import java.util.Collection; import java.util.Date; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import org.apache.commons.lang.StringUtils; import org.ovirt.engine.core.bll.context.CommandContext; import org.ovirt.engine.core.bll.network.VmInterfaceManager; import org.ovirt.engine.core.bll.network.vm.VnicProfileHelper; +import org.ovirt.engine.core.bll.profiles.CpuProfileHelper; import org.ovirt.engine.core.common.AuditLogType; import org.ovirt.engine.core.common.action.ImportVmParameters; import org.ovirt.engine.core.common.action.LockProperties; import org.ovirt.engine.core.common.action.LockProperties.Scope; +import org.ovirt.engine.core.common.businessentities.ArchitectureType; +import org.ovirt.engine.core.common.businessentities.GraphicsType; import org.ovirt.engine.core.common.businessentities.StorageDomain; import org.ovirt.engine.core.common.businessentities.VDSGroup; +import org.ovirt.engine.core.common.businessentities.VM; import org.ovirt.engine.core.common.businessentities.VMStatus; import org.ovirt.engine.core.common.businessentities.VmDevice; +import org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType; import org.ovirt.engine.core.common.businessentities.VmDynamic; import org.ovirt.engine.core.common.businessentities.VmStatic; import org.ovirt.engine.core.common.businessentities.VmStatistics; @@ -32,6 +39,7 @@ import org.ovirt.engine.core.common.utils.Pair; import org.ovirt.engine.core.common.utils.SimpleDependecyInjector; import org.ovirt.engine.core.common.utils.VmDeviceCommonUtils; +import org.ovirt.engine.core.common.utils.VmDeviceType; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase; import org.ovirt.engine.core.dao.BaseDiskDao; @@ -70,6 +78,90 @@ return true; } + /** + * Validates that there is no duplicate VM. + * @return <code>true</code> if the validation passes, <code>false</code> otherwise. + */ + protected boolean validateNoDuplicateVm() { + VmStatic duplicateVm = getVmStaticDAO().get(getVm().getId()); + return duplicateVm == null ? true : + failCanDoAction(VdcBllMessages.VM_CANNOT_IMPORT_VM_EXISTS, String.format("$VmName %1$s", duplicateVm.getName())); + } + + /** + * Validates if the VM being imported has a valid architecture. + * @return + */ + protected boolean validateVmArchitecture () { + return getVm().getClusterArch() == ArchitectureType.undefined ? + failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_VM_CANNOT_IMPORT_VM_WITH_NOT_SUPPORTED_ARCHITECTURE) + : true; + } + + /** + * Validates that that the required cluster exists and is compatible + * @return <code>true</code> if the validation passes, <code>false</code> otherwise. + */ + protected boolean validateVdsCluster() { + VDSGroup vdsGroup = getVdsGroupDAO().get(getVdsGroupId()); + return vdsGroup == null ? + failCanDoAction(VdcBllMessages.VDS_CLUSTER_IS_NOT_VALID) + : vdsGroup.getArchitecture() != getVm().getClusterArch() ? + failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_VM_CANNOT_IMPORT_VM_ARCHITECTURE_NOT_SUPPORTED_BY_CLUSTER) + : true; + } + + /** + * Validates the USB policy. + * @return <code>true</code> if the validation passes, <code>false</code> otherwise. + */ + protected boolean validateUsbPolicy() { + VM vm = getParameters().getVm(); + VmHandler.updateImportedVmUsbPolicy(vm.getStaticData()); + return VmHandler.isUsbPolicyLegal(vm.getUsbPolicy(), + vm.getOs(), + getVdsGroup(), + getReturnValue().getCanDoActionMessages()); + } + + protected boolean validateGraphicsAndDisplay() { + return VmHandler.isGraphicsAndDisplaySupported(getParameters().getVm().getOs(), + getGraphicsTypesForVm(), + getParameters().getVm().getDefaultDisplayType(), + getReturnValue().getCanDoActionMessages(), + getVdsGroup().getCompatibilityVersion()); + } + + Set<GraphicsType> getGraphicsTypesForVm() { + Set<GraphicsType> graphicsTypes = new HashSet<>(); + + for (VmDevice graphics : getDevicesOfType(VmDeviceGeneralType.GRAPHICS)) { + graphicsTypes.add(GraphicsType.fromVmDeviceType(VmDeviceType.getByName(graphics.getDevice()))); + } + + return graphicsTypes; + } + + private List<VmDevice> getDevicesOfType(VmDeviceGeneralType type) { + List<VmDevice> devices = new ArrayList<>(); + + if (getVm() != null && getVm().getStaticData() != null && getVm().getStaticData().getManagedDeviceMap() != null) { + for (VmDevice vmDevice : getVm().getStaticData().getManagedDeviceMap().values()) { + if (vmDevice.getType() == type) { + devices.add(vmDevice); + } + } + } + return devices; + } + + protected boolean setAndValidateCpuProfile() { + getVm().getStaticData().setVdsGroupId(getVdsGroupId()); + getVm().getStaticData().setCpuProfileId(getParameters().getCpuProfileId()); + return validate(CpuProfileHelper.setAndValidateCpuProfile(getVm().getStaticData(), + getVdsGroup().getCompatibilityVersion())); + } + protected boolean validateBallonDevice() { if (!VmDeviceCommonUtils.isBalloonDeviceExists(getVm().getManagedVmDeviceMap().values())) { return true; -- To view, visit https://gerrit.ovirt.org/42040 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic0b7930d130192688d904c2e11ec839d8478ac78 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Arik Hadas <aha...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches