Gilad Chaplik has uploaded a new change for review. Change subject: engine: add cpu profile to vm flow ......................................................................
engine: add cpu profile to vm flow * added to VmBase (vm/template) * added to db layer (vm_static.cpu_profile_base) * Added support to the follwing vm related commands: add/update vm (and derivatives), add/update template, import vm/template. * Backward compatibility: prior to 3.5 (cpu qos supported)- no check, posterior to 3.5, no cpu-profile will be replaced iff there is a single cpu profile in the cluster. Change-Id: Ib01e4ab9e6d471d56fb972c8a4ee3e8dd8616db7 Signed-off-by: Gilad Chaplik <gchap...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsGroupCommand.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/UpdateVdsGroupCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmTemplateCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmManagementCommandBase.java A backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/CpuProfileHelper.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/UpdateVmCommandTest.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmTemplateParametersBase.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmTemplate.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmBaseDaoDbFacade.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAO.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAODbFacadeImpl.java M backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmStaticDAOTest.java M backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmTemplateDAOTest.java M backend/manager/modules/dal/src/test/resources/fixtures.xml M packaging/dbscripts/create_views.sql R packaging/dbscripts/upgrade/03_06_0260_add_cpu_limit_to_qos_table.sql A packaging/dbscripts/upgrade/03_06_0270_add_cpu_profile_id_to_vm_static.sql M packaging/dbscripts/vm_templates_sp.sql M packaging/dbscripts/vms_sp.sql 30 files changed, 353 insertions(+), 68 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/28/31628/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsGroupCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsGroupCommand.java index 2d1feae..eb3f1fc 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsGroupCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsGroupCommand.java @@ -3,6 +3,7 @@ import java.util.Collections; import java.util.List; +import org.ovirt.engine.core.bll.profiles.CpuProfileHelper; import org.ovirt.engine.core.bll.utils.PermissionSubject; import org.ovirt.engine.core.bll.utils.VersionSupport; import org.ovirt.engine.core.common.AuditLogType; @@ -14,6 +15,8 @@ import org.ovirt.engine.core.common.businessentities.network.Network; import org.ovirt.engine.core.common.businessentities.network.NetworkCluster; import org.ovirt.engine.core.common.businessentities.network.NetworkStatus; +import org.ovirt.engine.core.common.config.Config; +import org.ovirt.engine.core.common.config.ConfigValues; import org.ovirt.engine.core.common.errors.VdcBllMessages; import org.ovirt.engine.core.common.gluster.GlusterFeatureSupported; import org.ovirt.engine.core.common.validation.group.CreateEntity; @@ -22,8 +25,6 @@ import org.ovirt.engine.core.utils.NetworkUtils; import org.ovirt.engine.core.utils.linq.LinqUtils; import org.ovirt.engine.core.utils.linq.Predicate; -import org.ovirt.engine.core.common.config.Config; -import org.ovirt.engine.core.common.config.ConfigValues; public class AddVdsGroupCommand<T extends VdsGroupOperationParameters> extends VdsGroupOperationCommandBase<T> { @@ -62,6 +63,13 @@ NetworkStatus.OPERATIONAL, true, true, true)); } } + + // create default CPU profile for supported clusters. + if (FeatureSupported.cpuQoS(getParameters().getVdsGroup().getcompatibility_version())) { + getCpuProfileDao().save(CpuProfileHelper.createCpuProfile(getParameters().getVdsGroup().getId(), + getParameters().getVdsGroup().getName())); + } + setActionReturnValue(getVdsGroup().getId()); setSucceeded(true); } 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 672bb2c..a5e491f 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 @@ -591,6 +591,10 @@ return false; } + if (!setAndValidateCpuProfile()) { + return false; + } + 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 f48313b..64b56cd 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.CpuProfileHelper; import org.ovirt.engine.core.bll.profiles.DiskProfileHelper; import org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter; import org.ovirt.engine.core.bll.quota.QuotaSanityParameter; @@ -402,6 +403,10 @@ return false; } + if(!setAndValidateCpuProfile()) { + return false; + } + if (isInstanceType) { return true; } else { @@ -571,7 +576,8 @@ getParameters().getMasterVm().getCustomSerialNumber(), getParameters().getMasterVm().isBootMenuEnabled(), getParameters().getMasterVm().isSpiceFileTransferEnabled(), - getParameters().getMasterVm().isSpiceCopyPasteEnabled())); + getParameters().getMasterVm().isSpiceCopyPasteEnabled(), + getParameters().getMasterVm().getCpuProfileId())); DbFacade.getInstance().getVmTemplateDao().save(getVmTemplate()); getCompensationContext().snapshotNewEntity(getVmTemplate()); setActionReturnValue(getVmTemplate().getId()); @@ -855,4 +861,9 @@ return super.isQuotaDependant(); } + + protected boolean setAndValidateCpuProfile() { + return validate(CpuProfileHelper.setAndValidateCpuProfile(getParameters().getMasterVm(), + getVdsGroup().getcompatibility_version())); + } } 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 0ae6f24..91d0baa 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.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; @@ -301,6 +302,9 @@ if (!setAndValidateDiskProfiles()) { return false; } + if (!setAndValidateCpuProfile()) { + return false; + } return checkFreeSpaceAndTypeOnDestDomains(); } @@ -411,6 +415,11 @@ return true; } + protected boolean setAndValidateCpuProfile() { + return validate(CpuProfileHelper.setAndValidateCpuProfile(getParameters().getVmStaticData(), + getVdsGroup().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/ImportVmCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java index a3ce77a..80f2100 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 @@ -16,6 +16,7 @@ import org.ovirt.engine.core.bll.memory.MemoryUtils; 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.bll.profiles.DiskProfileHelper; import org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter; import org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter; @@ -445,6 +446,10 @@ } if (!setAndValidateDiskProfiles()) { + return false; + } + + if (!setAndValidateCpuProfile()) { return false; } @@ -1298,6 +1303,11 @@ return true; } + protected boolean setAndValidateCpuProfile() { + return validate(CpuProfileHelper.setAndValidateCpuProfile(getVm().getStaticData(), + getVdsGroup().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/ImportVmTemplateCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmTemplateCommand.java index 5dfb4a7..9b6d1c3 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.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; @@ -212,6 +213,10 @@ } if (retVal && !setAndValidateDiskProfiles()) { + return false; + } + + if(retVal && !setAndValidateCpuProfile()) { return false; } @@ -559,6 +564,11 @@ return true; } + protected boolean setAndValidateCpuProfile() { + return validate(CpuProfileHelper.setAndValidateCpuProfile(getVmTemplate(), + getVdsGroup().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/UpdateVdsGroupCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVdsGroupCommand.java index c75cb0b..74d859e 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVdsGroupCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVdsGroupCommand.java @@ -6,6 +6,7 @@ import org.apache.commons.lang.StringUtils; import org.ovirt.engine.core.bll.context.CommandContext; +import org.ovirt.engine.core.bll.profiles.CpuProfileHelper; import org.ovirt.engine.core.bll.utils.VersionSupport; import org.ovirt.engine.core.common.AuditLogType; import org.ovirt.engine.core.common.FeatureSupported; @@ -26,6 +27,7 @@ import org.ovirt.engine.core.common.businessentities.network.Network; import org.ovirt.engine.core.common.businessentities.network.NetworkCluster; import org.ovirt.engine.core.common.businessentities.network.NetworkStatus; +import org.ovirt.engine.core.common.businessentities.profiles.CpuProfile; import org.ovirt.engine.core.common.config.Config; import org.ovirt.engine.core.common.config.ConfigValues; import org.ovirt.engine.core.common.errors.VdcBllMessages; @@ -81,6 +83,17 @@ } else { getParameters().getVdsGroup().setEmulatedMachine(emulatedMachine); } + // create default CPU profile for cluster that is being upgraded. + // and set all attached vms and templates with cpu profile + Guid clusterId = getParameters().getVdsGroupId(); + if (!FeatureSupported.cpuQoS(oldGroup.getcompatibility_version()) && + FeatureSupported.cpuQoS(getParameters().getVdsGroup().getcompatibility_version()) && + getCpuProfileDao().getAllForCluster(clusterId).isEmpty()) { + CpuProfile cpuProfile = CpuProfileHelper.createCpuProfile(clusterId, + getParameters().getVdsGroup().getName()); + getCpuProfileDao().save(cpuProfile); + getVmStaticDAO().updateVmCpuProfileIdForClusterId(clusterId, cpuProfile.getId()); + } } else if (oldGroup.getArchitecture() != getVdsGroup().getArchitecture()) { // if architecture was changed, emulated machines must be updated when adding new host. diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java index b244906..ede5e36 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java @@ -552,6 +552,10 @@ return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_MIN_MEMORY_CANNOT_EXCEED_MEMORY_SIZE); } + if (!setAndValidateCpuProfile()) { + return false; + } + return true; } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmTemplateCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmTemplateCommand.java index b2c99a4..05bea78 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmTemplateCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmTemplateCommand.java @@ -7,6 +7,7 @@ import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang.StringUtils; +import org.ovirt.engine.core.bll.profiles.CpuProfileHelper; import org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter; import org.ovirt.engine.core.bll.quota.QuotaSanityParameter; import org.ovirt.engine.core.bll.quota.QuotaVdsDependent; @@ -83,6 +84,10 @@ if (!returnValue) { addCanDoActionMessage(VdcBllMessages.VMT_CANNOT_UPDATE_ILLEGAL_FIELD); } + } + + if(!setAndValidateCpuProfile()) { + return false; } if (!isInstanceType && returnValue) { @@ -318,4 +323,9 @@ return super.isQuotaDependant(); } + protected boolean setAndValidateCpuProfile() { + return validate(CpuProfileHelper.setAndValidateCpuProfile(getVmTemplate(), + getVdsGroup().getcompatibility_version())); + } + } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmManagementCommandBase.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmManagementCommandBase.java index ba578c9..00ae03b 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmManagementCommandBase.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmManagementCommandBase.java @@ -10,6 +10,7 @@ import org.apache.commons.lang.StringUtils; import org.ovirt.engine.core.bll.context.CommandContext; +import org.ovirt.engine.core.bll.profiles.CpuProfileHelper; import org.ovirt.engine.core.common.action.VmManagementParametersBase; import org.ovirt.engine.core.common.businessentities.MigrationSupport; import org.ovirt.engine.core.common.businessentities.VDS; @@ -218,4 +219,9 @@ protected boolean isCpuSharesValid(VM vmData) { return (vmData.getCpuShares() >= 0 && vmData.getCpuShares() <= MAXIMUM_CPU_SHARES); } + + protected boolean setAndValidateCpuProfile() { + return validate(CpuProfileHelper.setAndValidateCpuProfile(getParameters().getVm().getStaticData(), + getVdsGroup().getcompatibility_version())); + } } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/CpuProfileHelper.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/CpuProfileHelper.java new file mode 100644 index 0000000..5f8ff15 --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/profiles/CpuProfileHelper.java @@ -0,0 +1,45 @@ +package org.ovirt.engine.core.bll.profiles; + +import java.util.List; + +import org.ovirt.engine.core.bll.ValidationResult; +import org.ovirt.engine.core.common.FeatureSupported; +import org.ovirt.engine.core.common.businessentities.VmBase; +import org.ovirt.engine.core.common.businessentities.profiles.CpuProfile; +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.CpuProfileDao; + +public class CpuProfileHelper { + + public static CpuProfile createCpuProfile(Guid vdsGroupId, String name) { + CpuProfile cpuProfile = new CpuProfile(); + cpuProfile.setId(Guid.newGuid()); + cpuProfile.setName(name); + cpuProfile.setClusterId(vdsGroupId); + + return cpuProfile; + } + + public static ValidationResult setAndValidateCpuProfile(VmBase vmBase, Version version) { + if (!FeatureSupported.cpuQoS(version)) + return ValidationResult.VALID; + if (vmBase.getCpuProfileId() == null) { + List<CpuProfile> cpuProfiles = getCpuProfileDao().getAllForCluster(vmBase.getVdsGroupId()); + if (cpuProfiles.size() == 1) { + vmBase.setCpuProfileId(cpuProfiles.get(0).getId()); + return ValidationResult.VALID; + } else { + return new ValidationResult(VdcBllMessages.ACTION_TYPE_CPU_PROFILE_EMPTY); + } + } else { + return new CpuProfileValidator(vmBase.getCpuProfileId()).isParentEntityValid(vmBase.getVdsGroupId()); + } + } + + private static CpuProfileDao getCpuProfileDao() { + return DbFacade.getInstance().getCpuProfileDao(); + } +} 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 4f9d818..400b58e 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 @@ -131,6 +131,7 @@ doReturn(true).when(command).areTemplateImagesInStorageReady(any(Guid.class)); doReturn(true).when(command).verifyAddVM(); doReturn(true).when(command).setAndValidateDiskProfiles(); + doReturn(true).when(command).setAndValidateCpuProfile(); } 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 b284162..32c11ef 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 @@ -114,6 +114,7 @@ doReturn(true).when(cmd).checkTemplateInStorageDomain(); doReturn(true).when(cmd).checkImagesGUIDsLegal(); doReturn(true).when(cmd).setAndValidateDiskProfiles(); + doReturn(true).when(cmd).setAndValidateCpuProfile(); 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 2021e21..1edae65 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 @@ -161,6 +161,7 @@ mockStoragePool(command); mockStorageDomains(command); doReturn(true).when(command).setAndValidateDiskProfiles(); + doReturn(true).when(command).setAndValidateCpuProfile(); return command; } diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmCommandTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmCommandTest.java index c4bd8f2..71f0292 100644 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmCommandTest.java +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmCommandTest.java @@ -319,6 +319,7 @@ mockSameNameQuery(false); mockValidateCustomProperties(); mockValidatePciAndIdeLimit(); + doReturn(true).when(command).setAndValidateCpuProfile(); } private void assertCanDoActionMessage(VdcBllMessages msg) { diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmTemplateParametersBase.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmTemplateParametersBase.java index 36ab0c6..8b78e3b 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmTemplateParametersBase.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VmTemplateParametersBase.java @@ -28,6 +28,7 @@ */ private boolean updateRngDevice; + private Guid cpuProfileId; public boolean getCheckDisksExists() { return privateCheckDisksExists; @@ -123,4 +124,12 @@ public void setRngDevice(VmRngDevice rngDevice) { this.rngDevice = rngDevice; } + + public Guid getCpuProfileId() { + return cpuProfileId; + } + + public void setCpuProfileId(Guid cpuProfileId) { + this.cpuProfileId = cpuProfileId; + } } diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java index 6ca95b7..69af45a 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VM.java @@ -1842,4 +1842,12 @@ public void setSpiceCopyPasteEnabled(boolean enabled) { vmStatic.setSpiceCopyPasteEnabled(enabled); } + + public Guid getCpuProfileId() { + return vmStatic.getCpuProfileId(); + } + + public void setCpuProfileId(Guid cpuProfileId) { + vmStatic.setCpuProfileId(cpuProfileId); + } } diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java index f4e4356..f6afc3c 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmBase.java @@ -325,6 +325,11 @@ @EditableOnTemplate private boolean spiceCopyPasteEnabled; + @CopyOnNewVersion + @EditableOnVmStatusField + @EditableOnTemplate + private Guid cpuProfileId; + public VmBase(VmBase vmBase) { this(vmBase.getName(), vmBase.getId(), @@ -372,7 +377,8 @@ vmBase.getCustomSerialNumber(), vmBase.isBootMenuEnabled(), vmBase.isSpiceFileTransferEnabled(), - vmBase.isSpiceCopyPasteEnabled()); + vmBase.isSpiceCopyPasteEnabled(), + vmBase.getCpuProfileId()); } public VmBase( @@ -422,7 +428,8 @@ String customSerialNumber, boolean bootMenuEnabled, boolean spiceFileTransferEnabled, - boolean spiceCopyPasteEnabled) { + boolean spiceCopyPasteEnabled, + Guid cpuProfileId) { this(); this.name = name; this.id = id; @@ -471,6 +478,7 @@ this.bootMenuEnabled = bootMenuEnabled; this.spiceFileTransferEnabled = spiceFileTransferEnabled; this.spiceCopyPasteEnabled = spiceCopyPasteEnabled; + this.cpuProfileId = cpuProfileId; } public long getDbGeneration() { @@ -811,6 +819,7 @@ result = prime * result + (bootMenuEnabled ? 1231 : 1237); result = prime * result + (spiceFileTransferEnabled ? 1231 : 1237); result = prime * result + (spiceCopyPasteEnabled ? 1231 : 1237); + result = prime * result + ((cpuProfileId == null) ? 0 : cpuProfileId.hashCode()); return result; } @@ -865,7 +874,8 @@ && ObjectUtils.objectsEqual(customSerialNumber, other.customSerialNumber) && bootMenuEnabled == other.bootMenuEnabled && spiceFileTransferEnabled == other.spiceFileTransferEnabled - && spiceCopyPasteEnabled == other.spiceCopyPasteEnabled; + && spiceCopyPasteEnabled == other.spiceCopyPasteEnabled + && ObjectUtils.objectsEqual(cpuProfileId, other.cpuProfileId); } public Guid getQuotaId() { @@ -1036,4 +1046,12 @@ public boolean isSpiceCopyPasteEnabled() { return spiceCopyPasteEnabled; } public void setSpiceCopyPasteEnabled(boolean spiceCopyPasteEnabled) { this.spiceCopyPasteEnabled = spiceCopyPasteEnabled; } + + public Guid getCpuProfileId() { + return cpuProfileId; + } + + public void setCpuProfileId(Guid cpuProfileId) { + this.cpuProfileId = cpuProfileId; + } } diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmTemplate.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmTemplate.java index a380f06..d226fe4 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmTemplate.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmTemplate.java @@ -77,7 +77,8 @@ boolean allowConsoleReconnect, String isoPath, Integer migrationDowntime, Guid baseTemplateId, String templateVersionName, SerialNumberPolicy serialNumberPolicy, String customSerialNumber, - boolean bootMenuEnabled, boolean spiceFIleTransferEnabled, boolean spiceCopyPasteEnabled) { + boolean bootMenuEnabled, boolean spiceFIleTransferEnabled, boolean spiceCopyPasteEnabled, + Guid cpuProfileId) { super(name, vmtGuid, vdsGroupId, @@ -124,7 +125,8 @@ customSerialNumber, bootMenuEnabled, spiceFIleTransferEnabled, - spiceCopyPasteEnabled); + spiceCopyPasteEnabled, + cpuProfileId); diskTemplateMap = new HashMap<Guid, DiskImage>(); diskImageMap = new HashMap<Guid, DiskImage>(); diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmBaseDaoDbFacade.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmBaseDaoDbFacade.java index fdb7f73..063efed 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmBaseDaoDbFacade.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmBaseDaoDbFacade.java @@ -1,5 +1,8 @@ package org.ovirt.engine.core.dao; +import java.sql.ResultSet; +import java.sql.SQLException; + import org.ovirt.engine.core.common.businessentities.BootSequence; import org.ovirt.engine.core.common.businessentities.DisplayType; import org.ovirt.engine.core.common.businessentities.MigrationSupport; @@ -13,9 +16,6 @@ import org.ovirt.engine.core.dal.dbbroker.DbFacadeUtils; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; - -import java.sql.ResultSet; -import java.sql.SQLException; public abstract class VmBaseDaoDbFacade<T extends VmBase> extends DefaultGenericDaoDbFacade<T, Guid> { public VmBaseDaoDbFacade(String entityStoredProcedureName) { @@ -67,7 +67,8 @@ .addValue("custom_serial_number", entity.getCustomSerialNumber()) .addValue("is_boot_menu_enabled", entity.isBootMenuEnabled()) .addValue("is_spice_file_transfer_enabled", entity.isSpiceFileTransferEnabled()) - .addValue("is_spice_copy_paste_enabled", entity.isSpiceCopyPasteEnabled()); + .addValue("is_spice_copy_paste_enabled", entity.isSpiceCopyPasteEnabled()) + .addValue("cpu_profile_id", entity.getCpuProfileId()); } /** @@ -121,6 +122,7 @@ entity.setDedicatedVmForVds(getGuid(rs, "dedicated_vm_for_vds")); entity.setMinAllocatedMem(rs.getInt("min_allocated_mem")); entity.setQuotaId(getGuid(rs, "quota_id")); + entity.setCpuProfileId(getGuid(rs, "cpu_profile_id")); } } } diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAO.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAO.java index 9dfa337..b2726ed 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAO.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAO.java @@ -92,4 +92,12 @@ * @param removePermissions flag to indicate if to remove the permissions or keep them */ public void remove(Guid id, boolean removePermissions); + + /** + * update vm_static.cpu_profile_id for cluster + * + * @param clusterId + * @param cpuProfileId + */ + void updateVmCpuProfileIdForClusterId(Guid clusterId, Guid cpuProfileId); } diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAODbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAODbFacadeImpl.java index d6f0f44..4011b2f 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAODbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStaticDAODbFacadeImpl.java @@ -150,6 +150,14 @@ .toString())); } + @Override + public void updateVmCpuProfileIdForClusterId(Guid clusterId, Guid cpuProfileId) { + getCallsHandler().executeModification("UpdateVmCpuProfileIdForClusterId", + getCustomMapSqlParameterSource() + .addValue("cluster_id", clusterId) + .addValue("cpu_profile_id", cpuProfileId)); + } + /** * JDBC row mapper for VM static */ diff --git a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmStaticDAOTest.java b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmStaticDAOTest.java index 0d27169..933119d 100644 --- a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmStaticDAOTest.java +++ b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmStaticDAOTest.java @@ -19,6 +19,7 @@ import org.ovirt.engine.core.common.businessentities.Snapshot; import org.ovirt.engine.core.common.businessentities.VmStatic; import org.ovirt.engine.core.common.businessentities.VmTemplate; +import org.ovirt.engine.core.common.utils.ObjectUtils; import org.ovirt.engine.core.compat.Guid; /** @@ -54,6 +55,7 @@ newVmStatic.setVmtGuid(vmtemplate.getId()); newVmStatic.setOrigin(OriginType.OVIRT); newVmStatic.setQuotaId(QUOTA_ID); + newVmStatic.setCpuProfileId(FixturesTool.CPU_PROFILE_1); } /** @@ -166,6 +168,7 @@ @Test public void testUpdate() { existingVmStatic.setDescription("updated"); + existingVmStatic.setCpuProfileId(FixturesTool.CPU_PROFILE_2); dao.update(existingVmStatic); VmStatic result = dao.get(EXISTING_VM_ID); assertNotNull(result); @@ -416,4 +419,31 @@ return returnValue; } + + @Test + public void testUpdateVmCpuProfileIdForClusterId() { + updateCpuProfile(FixturesTool.VDS_GROUP_RHEL6_ISCSI, FixturesTool.CPU_PROFILE_2); + } + + @Test + public void testUpdateNullVmCpuProfileIdForClusterId() { + updateCpuProfile(FixturesTool.VDS_GROUP_RHEL6_ISCSI, null); + } + + private void updateCpuProfile(Guid clusterId, Guid cpuProfileId) { + testAllCpuProfileValuesEqualTo(clusterId, cpuProfileId, false); + dao.updateVmCpuProfileIdForClusterId(clusterId, cpuProfileId); + testAllCpuProfileValuesEqualTo(clusterId, cpuProfileId, true); + } + + private void testAllCpuProfileValuesEqualTo(Guid clusterId, Guid cpuProfileId, boolean isAllNull) { + List<VmStatic> allByVdsGroup = dao.getAllByVdsGroup(clusterId); + assertNotNull(allByVdsGroup); + assertFalse(allByVdsGroup.isEmpty()); + boolean allValues = true; + for (VmStatic vmStatic : allByVdsGroup) { + allValues &= ObjectUtils.objectsEqual(vmStatic.getCpuProfileId(), cpuProfileId); + } + assertEquals(isAllNull, allValues); + } } diff --git a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmTemplateDAOTest.java b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmTemplateDAOTest.java index 29af8e0..af6bf50 100644 --- a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmTemplateDAOTest.java +++ b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmTemplateDAOTest.java @@ -56,6 +56,7 @@ newVmTemplate.setName("NewVmTemplate"); newVmTemplate.setVdsGroupId(VDS_GROUP_ID); newVmTemplate.setClusterArch(ArchitectureType.x86_64); + newVmTemplate.setCpuProfileId(FixturesTool.CPU_PROFILE_2); } /** diff --git a/backend/manager/modules/dal/src/test/resources/fixtures.xml b/backend/manager/modules/dal/src/test/resources/fixtures.xml index 34eacaf..47f12a4 100644 --- a/backend/manager/modules/dal/src/test/resources/fixtures.xml +++ b/backend/manager/modules/dal/src/test/resources/fixtures.xml @@ -1363,6 +1363,46 @@ </row> </table> + <table name="cpu_profiles"> + <column>id</column> + <column>name</column> + <column>cluster_id</column> + <column>qos_id</column> + <column>description</column> + <row> + <value>fd81f1e1-785b-4579-ab75-1419ebb87052</value> + <value>engine_profile</value> + <value>b399944a-81ab-4ec5-8266-e19ba7c3c9d1</value> + <value>ae956031-6be2-43d6-bb90-5191c9253317</value> + <value>cpu profile description</value> + </row> + <row> + <value>a667da39-27b0-47ec-a5fa-d4293a62b222</value> + <value>engine_profile_pm</value> + <value>b399944a-81ab-4ec5-8266-e19ba7c3c9d1</value> + <value>ae956031-6be2-43d6-bb90-5191c9253318</value> + <null /> + </row> + <row> + <value>d0f2ca62-f564-447c-aa55-ce2aa12ea798</value> + <value>engine2_profile</value> + <value>0e57070e-2469-4b38-84a2-f111aaabd49d</value> + <null /> + </row> + <row> + <value>471b199e-9454-47a1-85dd-4461f665abc5</value> + <value>engine3_profile</value> + <value>0e57070e-2469-4b38-84a2-f111aaabd49d</value> + <null /> + </row> + <row> + <value>fd81f1e1-785b-4579-ab75-1419ebb87053</value> + <value>engine4_profile</value> + <value>0e57070e-2469-4b38-84a2-f111aaabd49d</value> + <value>ae956031-6be2-43d6-bb90-5191c9253317</value> + </row> + </table> + <table name="network_cluster"> <column>network_id</column> <column>cluster_id</column> @@ -1833,7 +1873,7 @@ <column>numatune_mode</column> <column>is_spice_file_transfer_enabled</column> <column>is_spice_copy_paste_enabled</column> - + <column>cpu_profile_id</column> <!-- Templates --> <row> <value>00000000-0000-0000-0000-000000000000</value> @@ -1893,6 +1933,7 @@ <value>preferred</value> <value>true</value> <value>true</value> + <null /> </row> <row> <value>1b85420c-b84c-4f29-997e-0eb674b40b79</value> @@ -1952,6 +1993,7 @@ <value>preferred</value> <value>true</value> <value>true</value> + <value>fd81f1e1-785b-4579-ab75-1419ebb87052</value> </row> <row> <value>1b85420c-b84c-4f29-997e-0eb674b40b80</value> @@ -2011,6 +2053,7 @@ <value>preferred</value> <value>true</value> <value>true</value> + <null /> </row> <row> <value>1b85420c-b84c-4f29-997e-0eb674b40b81</value> @@ -2070,6 +2113,7 @@ <value>preferred</value> <value>true</value> <value>true</value> + <null /> </row> <row> <value>1b85420c-b84c-4f29-997e-0eb674b40b82</value> @@ -2129,6 +2173,7 @@ <value>preferred</value> <value>true</value> <value>true</value> + <null /> </row> <row> <value>99408929-82cf-4dc7-a532-9d998063fa95</value> @@ -2188,6 +2233,7 @@ <value>preferred</value> <value>true</value> <value>true</value> + <null /> </row> <row> <value>5849b030-626e-47cb-ad90-3ce782d831b3</value> @@ -2247,6 +2293,7 @@ <value>preferred</value> <value>true</value> <value>true</value> + <null /> </row> <row> <value>1b85420c-b84c-4f29-997e-0eb674b40b83</value> @@ -2306,6 +2353,7 @@ <value>preferred</value> <value>true</value> <value>true</value> + <null /> </row> <!-- VMS --> @@ -2367,6 +2415,7 @@ <value>preferred</value> <value>true</value> <value>true</value> + <value>fd81f1e1-785b-4579-ab75-1419ebb87052</value> </row> <row> <value>77296e00-0cad-4e5a-9299-008a7b6f4355</value> @@ -2426,6 +2475,7 @@ <value>preferred</value> <value>true</value> <value>true</value> + <null /> </row> <row> <value>77296e00-0cad-4e5a-9299-008a7b6f4356</value> @@ -2485,6 +2535,7 @@ <value>preferred</value> <value>true</value> <value>true</value> + <null /> </row> <row> <value>77296e00-0cad-4e5a-9299-008a7b6f4357</value> @@ -2544,6 +2595,7 @@ <value>preferred</value> <value>true</value> <value>true</value> + <null /> </row> <row> <value>77296e00-0cad-4e5a-9299-008a7b6f4359</value> @@ -2603,6 +2655,7 @@ <value>preferred</value> <value>true</value> <value>true</value> + <null /> </row> <row> <value>77296e00-0cad-4e5a-9299-008a7b6f4360</value> @@ -2662,6 +2715,7 @@ <value>preferred</value> <value>true</value> <value>true</value> + <null /> </row> <row> <value>77296e00-0cad-4e5a-9299-008a7b6f5001</value> @@ -2721,6 +2775,7 @@ <value>preferred</value> <value>true</value> <value>true</value> + <null /> </row> <row> <value>77296e00-0cad-4e5a-9299-008a7b6f5002</value> @@ -2780,6 +2835,7 @@ <value>preferred</value> <value>true</value> <value>true</value> + <null /> </row> <row> <value>77296e00-0cad-4e5a-9299-008a7b6f5003</value> @@ -2839,6 +2895,7 @@ <value>preferred</value> <value>true</value> <value>true</value> + <null /> </row> </table> @@ -5182,46 +5239,6 @@ <value>engine4_profile</value> <value>c2211b56-8869-41cd-84e1-78d7cb96f31d</value> <value>ae956031-6be2-43d6-bb90-5191c9253314</value> - </row> - </table> - - <table name="cpu_profiles"> - <column>id</column> - <column>name</column> - <column>cluster_id</column> - <column>qos_id</column> - <column>description</column> - <row> - <value>fd81f1e1-785b-4579-ab75-1419ebb87052</value> - <value>engine_profile</value> - <value>b399944a-81ab-4ec5-8266-e19ba7c3c9d1</value> - <value>ae956031-6be2-43d6-bb90-5191c9253317</value> - <value>cpu profile description</value> - </row> - <row> - <value>a667da39-27b0-47ec-a5fa-d4293a62b222</value> - <value>engine_profile_pm</value> - <value>b399944a-81ab-4ec5-8266-e19ba7c3c9d1</value> - <value>ae956031-6be2-43d6-bb90-5191c9253318</value> - <null /> - </row> - <row> - <value>d0f2ca62-f564-447c-aa55-ce2aa12ea798</value> - <value>engine2_profile</value> - <value>0e57070e-2469-4b38-84a2-f111aaabd49d</value> - <null /> - </row> - <row> - <value>471b199e-9454-47a1-85dd-4461f665abc5</value> - <value>engine3_profile</value> - <value>0e57070e-2469-4b38-84a2-f111aaabd49d</value> - <null /> - </row> - <row> - <value>fd81f1e1-785b-4579-ab75-1419ebb87053</value> - <value>engine4_profile</value> - <value>0e57070e-2469-4b38-84a2-f111aaabd49d</value> - <value>ae956031-6be2-43d6-bb90-5191c9253317</value> </row> </table> diff --git a/packaging/dbscripts/create_views.sql b/packaging/dbscripts/create_views.sql index 482aff7..8726340 100644 --- a/packaging/dbscripts/create_views.sql +++ b/packaging/dbscripts/create_views.sql @@ -445,7 +445,8 @@ vm_templates.custom_serial_number as custom_serial_number, vm_templates.is_boot_menu_enabled as is_boot_menu_enabled, vm_templates.is_spice_file_transfer_enabled as is_spice_file_transfer_enabled, - vm_templates.is_spice_copy_paste_enabled as is_spice_copy_paste_enabled + vm_templates.is_spice_copy_paste_enabled as is_spice_copy_paste_enabled, + vm_templates.cpu_profile_id as cpu_profile_id FROM vm_static AS vm_templates LEFT OUTER JOIN vds_groups ON vm_templates.vds_group_id = vds_groups.vds_group_id left outer JOIN @@ -483,7 +484,8 @@ vm_templates.template_version_name as template_version_name, vm_templates.serial_number_policy as serial_number_policy, vm_templates.custom_serial_number as custom_serial_number, vm_templates.is_boot_menu_enabled as is_boot_menu_enabled, - vm_templates.is_spice_file_transfer_enabled as is_spice_file_transfer_enabled, vm_templates.is_spice_copy_paste_enabled as is_spice_copy_paste_enabled + vm_templates.is_spice_file_transfer_enabled as is_spice_file_transfer_enabled, vm_templates.is_spice_copy_paste_enabled as is_spice_copy_paste_enabled, + vm_templates.cpu_profile_id as cpu_profile_id FROM vm_static AS vm_templates LEFT OUTER JOIN vds_groups ON vm_templates.vds_group_id = vds_groups.vds_group_id LEFT OUTER JOIN storage_pool ON storage_pool.id = vds_groups.storage_pool_id INNER JOIN @@ -512,7 +514,8 @@ vm_templates_1.custom_serial_number as custom_serial_number, vm_templates_1.is_boot_menu_enabled as is_boot_menu_enabled, vm_templates_1.is_spice_file_transfer_enabled as is_spice_file_transfer_enabled, - vm_templates_1.is_spice_copy_paste_enabled as is_spice_copy_paste_enabled + vm_templates_1.is_spice_copy_paste_enabled as is_spice_copy_paste_enabled, + vm_templates_1.cpu_profile_id as cpu_profile_id FROM vm_static AS vm_templates_1 LEFT OUTER JOIN vds_groups AS vds_groups_1 ON vm_templates_1.vds_group_id = vds_groups_1.vds_group_id LEFT OUTER JOIN storage_pool AS storage_pool_1 ON storage_pool_1.id = vds_groups_1.storage_pool_id INNER JOIN @@ -661,7 +664,8 @@ vm_static.is_boot_menu_enabled as is_boot_menu_enabled, vm_dynamic.guest_cpu_count as guest_cpu_count, (snapshots.snapshot_id is not null) as next_run_config_exists, vm_static.numatune_mode as numatune_mode, - vm_static.is_spice_file_transfer_enabled as is_spice_file_transfer_enabled, vm_static.is_spice_copy_paste_enabled as is_spice_copy_paste_enabled + vm_static.is_spice_file_transfer_enabled as is_spice_file_transfer_enabled, vm_static.is_spice_copy_paste_enabled as is_spice_copy_paste_enabled, + vm_static.cpu_profile_id as cpu_profile_id FROM vm_static INNER JOIN vm_dynamic ON vm_static.vm_guid = vm_dynamic.vm_guid INNER JOIN vm_static AS vm_templates ON vm_static.vmt_guid = vm_templates.vm_guid INNER JOIN @@ -708,7 +712,8 @@ vms.is_boot_menu_enabled as is_boot_menu_enabled, vms.guest_cpu_count as guest_cpu_count, (snapshots.snapshot_id is not null) as next_run_config_exists, vms.numatune_mode, - vms.is_spice_file_transfer_enabled, vms.is_spice_copy_paste_enabled + vms.is_spice_file_transfer_enabled, vms.is_spice_copy_paste_enabled, + vms.cpu_profile_id FROM vms LEFT OUTER JOIN tags_vm_map_view ON vms.vm_guid = tags_vm_map_view.vm_id LEFT OUTER JOIN vm_device ON vm_device.vm_id = vms.vm_guid LEFT OUTER JOIN diff --git a/packaging/dbscripts/upgrade/03_06_0230_add_cpu_limit_to_qos_table.sql b/packaging/dbscripts/upgrade/03_06_0260_add_cpu_limit_to_qos_table.sql similarity index 100% rename from packaging/dbscripts/upgrade/03_06_0230_add_cpu_limit_to_qos_table.sql rename to packaging/dbscripts/upgrade/03_06_0260_add_cpu_limit_to_qos_table.sql diff --git a/packaging/dbscripts/upgrade/03_06_0270_add_cpu_profile_id_to_vm_static.sql b/packaging/dbscripts/upgrade/03_06_0270_add_cpu_profile_id_to_vm_static.sql new file mode 100644 index 0000000..03b74b0 --- /dev/null +++ b/packaging/dbscripts/upgrade/03_06_0270_add_cpu_profile_id_to_vm_static.sql @@ -0,0 +1,25 @@ +-- add cpu profile id filed to vm_static +SELECT fn_db_add_column('vm_static', 'cpu_profile_id', 'UUID NULL'); + +-- Create index for cpu profile +DROP INDEX IF EXISTS IDX_vm_static_cpu_profile_id; +CREATE INDEX IDX_vm_static_cpu_profile_id ON vm_static(cpu_profile_id); + +-- Add FK an handle cascade +ALTER TABLE vm_static ADD CONSTRAINT FK_vm_static_cpu_profile_id FOREIGN KEY(cpu_profile_id) +REFERENCES cpu_profiles(id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE SET NULL; + +--- Create cpu profile for every cluster greater than 3.5 +INSERT INTO cpu_profiles(id, name, cluster_id) + SELECT uuid_generate_v1(), + vds_groups.name, + vds_groups.vds_group_id + FROM vds_groups + WHERE cast(compatibility_version as float) >= 3.5; + +--- Add correct profile id foreach VM/Template. +UPDATE vm_static + SET cpu_profile_id = cpu_profiles.id + FROM cpu_profiles + WHERE vm_static.vds_group_id = cpu_profiles.cluster_id; + diff --git a/packaging/dbscripts/vm_templates_sp.sql b/packaging/dbscripts/vm_templates_sp.sql index be69e9c..7f81570 100644 --- a/packaging/dbscripts/vm_templates_sp.sql +++ b/packaging/dbscripts/vm_templates_sp.sql @@ -58,7 +58,8 @@ v_custom_serial_number VARCHAR(255), v_is_boot_menu_enabled BOOLEAN, v_is_spice_file_transfer_enabled BOOLEAN, - v_is_spice_copy_paste_enabled BOOLEAN) + v_is_spice_copy_paste_enabled BOOLEAN, + v_cpu_profile_id UUID) RETURNS VOID AS $procedure$ @@ -130,7 +131,8 @@ custom_serial_number, is_boot_menu_enabled, is_spice_file_transfer_enabled, - is_spice_copy_paste_enabled) + is_spice_copy_paste_enabled, + cpu_profile_id) VALUES( v_child_count, v_creation_date, @@ -184,7 +186,8 @@ v_custom_serial_number, v_is_boot_menu_enabled, v_is_spice_file_transfer_enabled, - v_is_spice_copy_paste_enabled); + v_is_spice_copy_paste_enabled, + v_cpu_profile_id); -- perform deletion from vm_ovf_generations to ensure that no record exists when performing insert to avoid PK violation. DELETE FROM vm_ovf_generations gen WHERE gen.vm_guid = v_vmt_guid; INSERT INTO vm_ovf_generations(vm_guid, storage_pool_id) @@ -248,7 +251,8 @@ v_custom_serial_number VARCHAR(255), v_is_boot_menu_enabled BOOLEAN, v_is_spice_file_transfer_enabled BOOLEAN, - v_is_spice_copy_paste_enabled BOOLEAN) + v_is_spice_copy_paste_enabled BOOLEAN, + v_cpu_profile_id UUID) RETURNS VOID --The [vm_templates] table doesn't have a timestamp column. Optimistic concurrency logic cannot be generated @@ -276,7 +280,7 @@ template_version_name = v_template_version_name, serial_number_policy = v_serial_number_policy, custom_serial_number = v_custom_serial_number, is_boot_menu_enabled = v_is_boot_menu_enabled, - is_spice_file_transfer_enabled = v_is_spice_file_transfer_enabled, is_spice_copy_paste_enabled = v_is_spice_copy_paste_enabled + is_spice_file_transfer_enabled = v_is_spice_file_transfer_enabled, is_spice_copy_paste_enabled = v_is_spice_copy_paste_enabled, cpu_profile_id = v_cpu_profile_id WHERE vm_guid = v_vmt_guid AND entity_type = v_template_type; diff --git a/packaging/dbscripts/vms_sp.sql b/packaging/dbscripts/vms_sp.sql index 5b29c28..9892e54 100644 --- a/packaging/dbscripts/vms_sp.sql +++ b/packaging/dbscripts/vms_sp.sql @@ -509,7 +509,8 @@ v_is_boot_menu_enabled BOOLEAN, v_numatune_mode VARCHAR(20), v_is_spice_file_transfer_enabled BOOLEAN, - v_is_spice_copy_paste_enabled BOOLEAN) + v_is_spice_copy_paste_enabled BOOLEAN, + v_cpu_profile_id UUID) RETURNS VOID AS $procedure$ DECLARE @@ -517,8 +518,8 @@ BEGIN -- lock template for child count update select vm_guid into v_val FROM vm_static WHERE vm_guid = v_vmt_guid for update; -INSERT INTO vm_static(description, free_text_comment, mem_size_mb, os, vds_group_id, vm_guid, VM_NAME, vmt_guid,creation_date,num_of_monitors, single_qxl_pci, allow_console_reconnect,is_initialized,num_of_sockets,cpu_per_socket,usb_policy, time_zone,auto_startup,is_stateless,dedicated_vm_for_vds, fail_back, default_boot_sequence, vm_type, nice_level, cpu_shares, default_display_type, priority,iso_path,origin,initrd_url,kernel_url,kernel_params,migration_support,predefined_properties,userdefined_properties,min_allocated_mem, entity_type, quota_id, cpu_pinning, is_smartcard_enabled,is_delete_protected, sso_method, host_cpu_flags, tunnel_migration, vnc_keyboard_layout, is_run_and_pause, created_by_user_id, instance_type_id, image_type_id, original_template_id, original_template_name, migration_downtime, template_version_number, serial_number_policy, custom_serial_number, is_boot_menu_enabled, numatune_mode, is_spice_file_transfer_enabled, is_spice_copy_paste_enabled) - VALUES(v_description, v_free_text_comment, v_mem_size_mb, v_os, v_vds_group_id, v_vm_guid, v_vm_name, v_vmt_guid, v_creation_date, v_num_of_monitors,v_single_qxl_pci, v_allow_console_reconnect, v_is_initialized, v_num_of_sockets, v_cpu_per_socket, v_usb_policy, v_time_zone, v_auto_startup,v_is_stateless,v_dedicated_vm_for_vds,v_fail_back, v_default_boot_sequence, v_vm_type, v_nice_level, v_cpu_shares, v_default_display_type, v_priority,v_iso_path,v_origin,v_initrd_url,v_kernel_url,v_kernel_params,v_migration_support,v_predefined_properties,v_userdefined_properties,v_min_allocated_mem, 'VM', v_quota_id, v_cpu_pinning, v_is_smartcard_enabled,v_is_delete_protected, v_sso_method, v_host_cpu_flags, v_tunnel_migration, v_vnc_keyboard_layout, v_is_run_and_pause, v_created_by_user_id, v_instance_type_id, v_image_type_id, v_original_template_id, v_original_template_name, v_migration_downtime, v_template_version_number, v_serial_number_policy, v_custom_serial_number, v_is_boot_menu_! enabled, v_numatune_mode, v_is_spice_file_transfer_enabled, v_is_spice_copy_paste_enabled); +INSERT INTO vm_static(description, free_text_comment, mem_size_mb, os, vds_group_id, vm_guid, VM_NAME, vmt_guid,creation_date,num_of_monitors, single_qxl_pci, allow_console_reconnect,is_initialized,num_of_sockets,cpu_per_socket,usb_policy, time_zone,auto_startup,is_stateless,dedicated_vm_for_vds, fail_back, default_boot_sequence, vm_type, nice_level, cpu_shares, default_display_type, priority,iso_path,origin,initrd_url,kernel_url,kernel_params,migration_support,predefined_properties,userdefined_properties,min_allocated_mem, entity_type, quota_id, cpu_pinning, is_smartcard_enabled,is_delete_protected, sso_method, host_cpu_flags, tunnel_migration, vnc_keyboard_layout, is_run_and_pause, created_by_user_id, instance_type_id, image_type_id, original_template_id, original_template_name, migration_downtime, template_version_number, serial_number_policy, custom_serial_number, is_boot_menu_enabled, numatune_mode, is_spice_file_transfer_enabled, is_spice_copy_paste_enabled, cpu_profi! le_id) + VALUES(v_description, v_free_text_comment, v_mem_size_mb, v_os, v_vds_group_id, v_vm_guid, v_vm_name, v_vmt_guid, v_creation_date, v_num_of_monitors,v_single_qxl_pci, v_allow_console_reconnect, v_is_initialized, v_num_of_sockets, v_cpu_per_socket, v_usb_policy, v_time_zone, v_auto_startup,v_is_stateless,v_dedicated_vm_for_vds,v_fail_back, v_default_boot_sequence, v_vm_type, v_nice_level, v_cpu_shares, v_default_display_type, v_priority,v_iso_path,v_origin,v_initrd_url,v_kernel_url,v_kernel_params,v_migration_support,v_predefined_properties,v_userdefined_properties,v_min_allocated_mem, 'VM', v_quota_id, v_cpu_pinning, v_is_smartcard_enabled,v_is_delete_protected, v_sso_method, v_host_cpu_flags, v_tunnel_migration, v_vnc_keyboard_layout, v_is_run_and_pause, v_created_by_user_id, v_instance_type_id, v_image_type_id, v_original_template_id, v_original_template_name, v_migration_downtime, v_template_version_number, v_serial_number_policy, v_custom_serial_number, v_is_boot_menu_! enabled, v_numatune_mode, v_is_spice_file_transfer_enabled, v_is_spice_copy_paste_enabled, v_cpu_profile_id); -- perform deletion from vm_ovf_generations to ensure that no record exists when performing insert to avoid PK violation. DELETE FROM vm_ovf_generations gen WHERE gen.vm_guid = v_vm_guid; @@ -649,7 +650,8 @@ v_is_boot_menu_enabled BOOLEAN, v_numatune_mode VARCHAR(20), v_is_spice_file_transfer_enabled BOOLEAN, -v_is_spice_copy_paste_enabled BOOLEAN) +v_is_spice_copy_paste_enabled BOOLEAN, +v_cpu_profile_id UUID) RETURNS VOID @@ -683,7 +685,8 @@ serial_number_policy = v_serial_number_policy, custom_serial_number = v_custom_serial_number, is_boot_menu_enabled = v_is_boot_menu_enabled, numatune_mode = v_numatune_mode, - is_spice_file_transfer_enabled = v_is_spice_file_transfer_enabled, is_spice_copy_paste_enabled = v_is_spice_copy_paste_enabled + is_spice_file_transfer_enabled = v_is_spice_file_transfer_enabled, is_spice_copy_paste_enabled = v_is_spice_copy_paste_enabled, + cpu_profile_id = v_cpu_profile_id WHERE vm_guid = v_vm_guid AND entity_type = 'VM'; END; $procedure$ @@ -1385,3 +1388,14 @@ AND snapshot_type = 'STATELESS'))); END; $procedure$ LANGUAGE plpgsql; + + +Create or replace FUNCTION UpdateVmCpuProfileIdForClusterId(v_cluster_id UUID, v_cpu_profile_id UUID) +RETURNS VOID + AS $procedure$ +BEGIN +UPDATE vm_static + SET cpu_profile_id = v_cpu_profile_id + WHERE vds_group_id = v_cluster_id; +END; $procedure$ +LANGUAGE plpgsql; -- To view, visit http://gerrit.ovirt.org/31628 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib01e4ab9e6d471d56fb972c8a4ee3e8dd8616db7 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Gilad Chaplik <gchap...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches