From 2e8180a6b29f19f264676f31e0c17755e41f0829 Mon Sep 17 00:00:00 2001 From: Daniel Augusto Veronezi Salvador Date: Fri, 19 Feb 2021 16:39:58 -0300 Subject: [PATCH 1/9] Externalize config to set min memory/cpu with division by overprovisioning --- .../cloud/hypervisor/HypervisorGuruBase.java | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java b/server/src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java index c320a7a55377..a522b86d7cb3 100644 --- a/server/src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java +++ b/server/src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java @@ -34,6 +34,8 @@ import com.cloud.agent.api.to.NicTO; import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.gpu.GPU; +import com.cloud.host.HostVO; +import com.cloud.host.dao.HostDao; import com.cloud.network.Networks.BroadcastDomainType; import com.cloud.network.dao.NetworkDao; import com.cloud.network.dao.NetworkDetailVO; @@ -49,7 +51,6 @@ import com.cloud.storage.StoragePool; import com.cloud.storage.Volume; import com.cloud.utils.Pair; -import com.cloud.utils.StringUtils; import com.cloud.utils.component.AdapterBase; import com.cloud.vm.NicProfile; import com.cloud.vm.NicVO; @@ -61,8 +62,11 @@ import com.cloud.vm.dao.NicSecondaryIpDao; import com.cloud.vm.dao.UserVmDetailsDao; import com.cloud.vm.dao.VMInstanceDao; +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.Configurable; +import org.apache.commons.lang3.StringUtils; -public abstract class HypervisorGuruBase extends AdapterBase implements HypervisorGuru { +public abstract class HypervisorGuruBase extends AdapterBase implements HypervisorGuru, Configurable { public static final Logger s_logger = Logger.getLogger(HypervisorGuruBase.class); @Inject @@ -85,6 +89,14 @@ public abstract class HypervisorGuruBase extends AdapterBase implements Hypervis private ServiceOfferingDao _serviceOfferingDao; @Inject private NetworkDetailsDao networkDetailsDao; + @Inject + private HostDao hostDao; + + static final ConfigKey VmMinMemoryEqualsMemoryDividedByMemOverprovisioningFactor = new ConfigKey("Advanced", Boolean.class, "vm.min.memory.equals.memory.divided.by.mem.overprovisioning.factor", "true", + "If we set this to 'true', a minimum memory (memory/ mem.overprovisioning.factor) will be setted to the VM, independent of using a scalable service offering or not.", true, ConfigKey.Scope.Cluster); + + static final ConfigKey VmMinCpuSpeedEqualsCpuSpeedDividedByCpuOverprovisioningFactor = new ConfigKey("Advanced", Boolean.class, "vm.min.cpu.speed.equals.cpu.speed.divided.by.cpu.overprovisioning.factor", "true", + "If we set this to 'true', a minimum cpu speed (cpu speed/ cpu.overprovisioning.factor) will be setted to the VM, independent of using a scalable service offering or not.", true, ConfigKey.Scope.Cluster); @Override public NicTO toNicTO(NicProfile profile) { @@ -167,8 +179,13 @@ protected void addServiceOfferingExtraConfiguration(ServiceOffering offering, Vi protected VirtualMachineTO toVirtualMachineTO(VirtualMachineProfile vmProfile) { ServiceOffering offering = _serviceOfferingDao.findById(vmProfile.getId(), vmProfile.getServiceOfferingId()); VirtualMachine vm = vmProfile.getVirtualMachine(); - Long minMemory = (long)(offering.getRamSize() / vmProfile.getMemoryOvercommitRatio()); - int minspeed = (int)(offering.getSpeed() / vmProfile.getCpuOvercommitRatio()); + HostVO host = hostDao.findById(vm.getHostId()); + + boolean divideMemoryByOverprovisioning = VmMinMemoryEqualsMemoryDividedByMemOverprovisioningFactor.valueIn(host.getClusterId()); + boolean divideCpuByOverprovisioning = VmMinCpuSpeedEqualsCpuSpeedDividedByCpuOverprovisioningFactor.valueIn(host.getClusterId()); + + Long minMemory = (long)(offering.getRamSize() / (divideMemoryByOverprovisioning ? vmProfile.getMemoryOvercommitRatio() : 1)); + int minspeed = (int)(offering.getSpeed() / (divideCpuByOverprovisioning ? vmProfile.getCpuOvercommitRatio() : 1)); int maxspeed = (offering.getSpeed()); VirtualMachineTO to = new VirtualMachineTO(vm.getId(), vm.getInstanceName(), vm.getType(), offering.getCpu(), minspeed, maxspeed, minMemory * 1024l * 1024l, offering.getRamSize() * 1024l * 1024l, null, null, vm.isHaEnabled(), vm.limitCpuUse(), vm.getVncPassword()); @@ -301,4 +318,15 @@ public boolean attachRestoredVolumeToVirtualMachine(long zoneId, String location public List finalizeMigrate(VirtualMachine vm, Map volumeToPool) { return null; } + + @Override + public String getConfigComponentName() { + return HypervisorGuruBase.class.getSimpleName(); + } + + @Override + public ConfigKey[] getConfigKeys() { + return new ConfigKey[] {VmMinMemoryEqualsMemoryDividedByMemOverprovisioningFactor, VmMinCpuSpeedEqualsCpuSpeedDividedByCpuOverprovisioningFactor }; + } + } From 38a4feb90795a902bc7b6c47c01b28f68e606755 Mon Sep 17 00:00:00 2001 From: dahn Date: Wed, 24 Feb 2021 11:22:22 +0000 Subject: [PATCH 2/9] Update server/src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java --- .../src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java b/server/src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java index a522b86d7cb3..910ae5377598 100644 --- a/server/src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java +++ b/server/src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java @@ -93,7 +93,7 @@ public abstract class HypervisorGuruBase extends AdapterBase implements Hypervis private HostDao hostDao; static final ConfigKey VmMinMemoryEqualsMemoryDividedByMemOverprovisioningFactor = new ConfigKey("Advanced", Boolean.class, "vm.min.memory.equals.memory.divided.by.mem.overprovisioning.factor", "true", - "If we set this to 'true', a minimum memory (memory/ mem.overprovisioning.factor) will be setted to the VM, independent of using a scalable service offering or not.", true, ConfigKey.Scope.Cluster); + "If we set this to 'true', a minimum memory (memory/ mem.overprovisioning.factor) will be set to the VM, independent of using a scalable service offering or not.", true, ConfigKey.Scope.Cluster); static final ConfigKey VmMinCpuSpeedEqualsCpuSpeedDividedByCpuOverprovisioningFactor = new ConfigKey("Advanced", Boolean.class, "vm.min.cpu.speed.equals.cpu.speed.divided.by.cpu.overprovisioning.factor", "true", "If we set this to 'true', a minimum cpu speed (cpu speed/ cpu.overprovisioning.factor) will be setted to the VM, independent of using a scalable service offering or not.", true, ConfigKey.Scope.Cluster); From 63c0edf756db3d4188aae78839ce01ecfe0b0f9b Mon Sep 17 00:00:00 2001 From: dahn Date: Wed, 24 Feb 2021 11:22:30 +0000 Subject: [PATCH 3/9] Update server/src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java --- .../src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java b/server/src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java index 910ae5377598..b9298bc4714f 100644 --- a/server/src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java +++ b/server/src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java @@ -96,7 +96,7 @@ public abstract class HypervisorGuruBase extends AdapterBase implements Hypervis "If we set this to 'true', a minimum memory (memory/ mem.overprovisioning.factor) will be set to the VM, independent of using a scalable service offering or not.", true, ConfigKey.Scope.Cluster); static final ConfigKey VmMinCpuSpeedEqualsCpuSpeedDividedByCpuOverprovisioningFactor = new ConfigKey("Advanced", Boolean.class, "vm.min.cpu.speed.equals.cpu.speed.divided.by.cpu.overprovisioning.factor", "true", - "If we set this to 'true', a minimum cpu speed (cpu speed/ cpu.overprovisioning.factor) will be setted to the VM, independent of using a scalable service offering or not.", true, ConfigKey.Scope.Cluster); + "If we set this to 'true', a minimum CPU speed (cpu speed/ cpu.overprovisioning.factor) will be set on the VM, independent of using a scalable service offering or not.", true, ConfigKey.Scope.Cluster); @Override public NicTO toNicTO(NicProfile profile) { From a2c17fe92093fc9a9acf70dac3e66a18870d593f Mon Sep 17 00:00:00 2001 From: Daniel Augusto Veronezi Salvador Date: Fri, 26 Mar 2021 12:56:41 -0300 Subject: [PATCH 4/9] Allow full uppercase and underscore in static var --- tools/checkstyle/src/main/resources/cloud-style.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/checkstyle/src/main/resources/cloud-style.xml b/tools/checkstyle/src/main/resources/cloud-style.xml index 6aaef17b926c..4fad942fff0a 100644 --- a/tools/checkstyle/src/main/resources/cloud-style.xml +++ b/tools/checkstyle/src/main/resources/cloud-style.xml @@ -30,7 +30,7 @@ - + From b019d5f8513167cd0302c3cef7b16a7d26524543 Mon Sep 17 00:00:00 2001 From: Daniel Augusto Veronezi Salvador Date: Fri, 26 Mar 2021 12:57:56 -0300 Subject: [PATCH 5/9] Rename variable --- .../java/com/cloud/hypervisor/HypervisorGuruBase.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/server/src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java b/server/src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java index b9298bc4714f..c68bb7422f7b 100644 --- a/server/src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java +++ b/server/src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java @@ -92,10 +92,10 @@ public abstract class HypervisorGuruBase extends AdapterBase implements Hypervis @Inject private HostDao hostDao; - static final ConfigKey VmMinMemoryEqualsMemoryDividedByMemOverprovisioningFactor = new ConfigKey("Advanced", Boolean.class, "vm.min.memory.equals.memory.divided.by.mem.overprovisioning.factor", "true", + public static ConfigKey VM_MIN_MEMORY_EQUALS_MEMORY_DIVIDED_BY_MEM_OVERPROVISIONING_FACTOR = new ConfigKey("Advanced", Boolean.class, "vm.min.memory.equals.memory.divided.by.mem.overprovisioning.factor", "true", "If we set this to 'true', a minimum memory (memory/ mem.overprovisioning.factor) will be set to the VM, independent of using a scalable service offering or not.", true, ConfigKey.Scope.Cluster); - static final ConfigKey VmMinCpuSpeedEqualsCpuSpeedDividedByCpuOverprovisioningFactor = new ConfigKey("Advanced", Boolean.class, "vm.min.cpu.speed.equals.cpu.speed.divided.by.cpu.overprovisioning.factor", "true", + public static ConfigKey VM_MIN_CPU_SPEED_EQUALS_CPU_SPEED_DIVIDED_BY_CPU_OVERPROVISIONING_FACTOR = new ConfigKey("Advanced", Boolean.class, "vm.min.cpu.speed.equals.cpu.speed.divided.by.cpu.overprovisioning.factor", "true", "If we set this to 'true', a minimum CPU speed (cpu speed/ cpu.overprovisioning.factor) will be set on the VM, independent of using a scalable service offering or not.", true, ConfigKey.Scope.Cluster); @Override @@ -181,8 +181,8 @@ protected VirtualMachineTO toVirtualMachineTO(VirtualMachineProfile vmProfile) { VirtualMachine vm = vmProfile.getVirtualMachine(); HostVO host = hostDao.findById(vm.getHostId()); - boolean divideMemoryByOverprovisioning = VmMinMemoryEqualsMemoryDividedByMemOverprovisioningFactor.valueIn(host.getClusterId()); - boolean divideCpuByOverprovisioning = VmMinCpuSpeedEqualsCpuSpeedDividedByCpuOverprovisioningFactor.valueIn(host.getClusterId()); + boolean divideMemoryByOverprovisioning = VM_MIN_MEMORY_EQUALS_MEMORY_DIVIDED_BY_MEM_OVERPROVISIONING_FACTOR.valueIn(host.getClusterId()); + boolean divideCpuByOverprovisioning = VM_MIN_CPU_SPEED_EQUALS_CPU_SPEED_DIVIDED_BY_CPU_OVERPROVISIONING_FACTOR.valueIn(host.getClusterId()); Long minMemory = (long)(offering.getRamSize() / (divideMemoryByOverprovisioning ? vmProfile.getMemoryOvercommitRatio() : 1)); int minspeed = (int)(offering.getSpeed() / (divideCpuByOverprovisioning ? vmProfile.getCpuOvercommitRatio() : 1)); @@ -326,7 +326,7 @@ public String getConfigComponentName() { @Override public ConfigKey[] getConfigKeys() { - return new ConfigKey[] {VmMinMemoryEqualsMemoryDividedByMemOverprovisioningFactor, VmMinCpuSpeedEqualsCpuSpeedDividedByCpuOverprovisioningFactor }; + return new ConfigKey[] {VM_MIN_MEMORY_EQUALS_MEMORY_DIVIDED_BY_MEM_OVERPROVISIONING_FACTOR, VM_MIN_CPU_SPEED_EQUALS_CPU_SPEED_DIVIDED_BY_CPU_OVERPROVISIONING_FACTOR }; } } From 4d9d864a5d6afdeac3cef0abcc3605c11a43a368 Mon Sep 17 00:00:00 2001 From: Daniel Augusto Veronezi Salvador Date: Fri, 26 Mar 2021 13:00:24 -0300 Subject: [PATCH 6/9] Add division logic to orchestrateReConfigureVm --- .../java/com/cloud/vm/VirtualMachineManagerImpl.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java index de1ef20f883e..b6b42e98c5ef 100755 --- a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java @@ -165,6 +165,7 @@ import com.cloud.host.dao.HostDao; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.hypervisor.HypervisorGuru; +import com.cloud.hypervisor.HypervisorGuruBase; import com.cloud.hypervisor.HypervisorGuruManager; import com.cloud.network.Network; import com.cloud.network.NetworkModel; @@ -4534,11 +4535,17 @@ private VMInstanceVO orchestrateReConfigureVm(final String vmUuid, final Service upgradeVmDb(vm.getId(), newServiceOffering, oldServiceOffering); final HostVO hostVo = _hostDao.findById(vm.getHostId()); + Long clustedId = hostVo.getClusterId(); final Float memoryOvercommitRatio = CapacityManager.MemOverprovisioningFactor.valueIn(hostVo.getClusterId()); final Float cpuOvercommitRatio = CapacityManager.CpuOverprovisioningFactor.valueIn(hostVo.getClusterId()); - final long minMemory = (long)(newServiceOffering.getRamSize() / memoryOvercommitRatio); + boolean divideMemoryByOverprovisioning = HypervisorGuruBase.VM_MIN_MEMORY_EQUALS_MEMORY_DIVIDED_BY_MEM_OVERPROVISIONING_FACTOR.valueIn(clustedId); + boolean divideCpuByOverprovisioning = HypervisorGuruBase.VM_MIN_CPU_SPEED_EQUALS_CPU_SPEED_DIVIDED_BY_CPU_OVERPROVISIONING_FACTOR.valueIn(clustedId); + + int minMemory = (int)(newServiceOffering.getRamSize() / (divideMemoryByOverprovisioning ? memoryOvercommitRatio : 1)); + int minSpeed = (int)(newServiceOffering.getSpeed() / (divideCpuByOverprovisioning ? cpuOvercommitRatio : 1)); + final ScaleVmCommand reconfigureCmd = - new ScaleVmCommand(vm.getInstanceName(), newServiceOffering.getCpu(), (int)(newServiceOffering.getSpeed() / cpuOvercommitRatio), + new ScaleVmCommand(vm.getInstanceName(), newServiceOffering.getCpu(), minSpeed, newServiceOffering.getSpeed(), minMemory * 1024L * 1024L, newServiceOffering.getRamSize() * 1024L * 1024L, newServiceOffering.getLimitCpuUse()); final Long dstHostId = vm.getHostId(); From 73924134f47cf72ee8c44f93da83dd2b0fb6aa8b Mon Sep 17 00:00:00 2001 From: Daniel Augusto Veronezi Salvador Date: Fri, 26 Mar 2021 13:14:31 -0300 Subject: [PATCH 7/9] Refactor orchestrateReConfigureVm --- .../cloud/vm/VirtualMachineManagerImpl.java | 50 +++++++++++-------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java index b6b42e98c5ef..25f6c3b554ec 100755 --- a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java @@ -4529,40 +4529,43 @@ public VMInstanceVO reConfigureVm(final String vmUuid, final ServiceOffering old } } - private VMInstanceVO orchestrateReConfigureVm(final String vmUuid, final ServiceOffering oldServiceOffering, final ServiceOffering newServiceOffering, - final boolean reconfiguringOnExistingHost) throws ResourceUnavailableException, ConcurrentOperationException { - final VMInstanceVO vm = _vmDao.findByUuid(vmUuid); + private VMInstanceVO orchestrateReConfigureVm(String vmUuid, ServiceOffering oldServiceOffering, ServiceOffering newServiceOffering, + boolean reconfiguringOnExistingHost) throws ResourceUnavailableException, ConcurrentOperationException { + VMInstanceVO vm = _vmDao.findByUuid(vmUuid); upgradeVmDb(vm.getId(), newServiceOffering, oldServiceOffering); - final HostVO hostVo = _hostDao.findById(vm.getHostId()); + HostVO hostVo = _hostDao.findById(vm.getHostId()); + Long clustedId = hostVo.getClusterId(); - final Float memoryOvercommitRatio = CapacityManager.MemOverprovisioningFactor.valueIn(hostVo.getClusterId()); - final Float cpuOvercommitRatio = CapacityManager.CpuOverprovisioningFactor.valueIn(hostVo.getClusterId()); + Float memoryOvercommitRatio = CapacityManager.MemOverprovisioningFactor.valueIn(clustedId); + Float cpuOvercommitRatio = CapacityManager.CpuOverprovisioningFactor.valueIn(clustedId); boolean divideMemoryByOverprovisioning = HypervisorGuruBase.VM_MIN_MEMORY_EQUALS_MEMORY_DIVIDED_BY_MEM_OVERPROVISIONING_FACTOR.valueIn(clustedId); boolean divideCpuByOverprovisioning = HypervisorGuruBase.VM_MIN_CPU_SPEED_EQUALS_CPU_SPEED_DIVIDED_BY_CPU_OVERPROVISIONING_FACTOR.valueIn(clustedId); int minMemory = (int)(newServiceOffering.getRamSize() / (divideMemoryByOverprovisioning ? memoryOvercommitRatio : 1)); int minSpeed = (int)(newServiceOffering.getSpeed() / (divideCpuByOverprovisioning ? cpuOvercommitRatio : 1)); - final ScaleVmCommand reconfigureCmd = + ScaleVmCommand scaleVmCommand = new ScaleVmCommand(vm.getInstanceName(), newServiceOffering.getCpu(), minSpeed, newServiceOffering.getSpeed(), minMemory * 1024L * 1024L, newServiceOffering.getRamSize() * 1024L * 1024L, newServiceOffering.getLimitCpuUse()); - final Long dstHostId = vm.getHostId(); - if(vm.getHypervisorType().equals(HypervisorType.VMware)) { - final HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vm.getHypervisorType()); - Map details = null; - details = hvGuru.getClusterSettings(vm.getId()); - reconfigureCmd.getVirtualMachine().setDetails(details); + Long dstHostId = vm.getHostId(); + + if (vm.getHypervisorType().equals(HypervisorType.VMware)) { + HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vm.getHypervisorType()); + Map details = hvGuru.getClusterSettings(vm.getId()); + scaleVmCommand.getVirtualMachine().setDetails(details); } - final ItWorkVO work = new ItWorkVO(UUID.randomUUID().toString(), _nodeId, State.Running, vm.getType(), vm.getId()); + ItWorkVO work = new ItWorkVO(UUID.randomUUID().toString(), _nodeId, State.Running, vm.getType(), vm.getId()); work.setStep(Step.Prepare); work.setResourceType(ItWorkVO.ResourceType.Host); work.setResourceId(vm.getHostId()); _workDao.persist(work); + boolean success = false; + try { if (reconfiguringOnExistingHost) { vm.setServiceOfferingId(oldServiceOffering.getId()); @@ -4571,18 +4574,23 @@ private VMInstanceVO orchestrateReConfigureVm(final String vmUuid, final Service _capacityMgr.allocateVmCapacity(vm, false); // lock the new capacity } - final Answer reconfigureAnswer = _agentMgr.send(vm.getHostId(), reconfigureCmd); - if (reconfigureAnswer == null || !reconfigureAnswer.getResult()) { - s_logger.error("Unable to scale vm due to " + (reconfigureAnswer == null ? "" : reconfigureAnswer.getDetails())); - throw new CloudRuntimeException("Unable to scale vm due to " + (reconfigureAnswer == null ? "" : reconfigureAnswer.getDetails())); + Answer scaleVmAnswer = _agentMgr.send(vm.getHostId(), scaleVmCommand); + if (scaleVmAnswer == null || !scaleVmAnswer.getResult()) { + String msg = String.format("Unable to scale %s due to [%s].", vm.toString(), (scaleVmAnswer == null ? "" : scaleVmAnswer.getDetails())); + s_logger.error(msg); + throw new CloudRuntimeException(msg); } if (vm.getType().equals(VirtualMachine.Type.User)) { _userVmMgr.generateUsageEvent(vm, vm.isDisplayVm(), EventTypes.EVENT_VM_DYNAMIC_SCALE); } success = true; - } catch (final OperationTimedoutException e) { - throw new AgentUnavailableException("Operation timed out on reconfiguring " + vm, dstHostId); - } catch (final AgentUnavailableException e) { + } catch (OperationTimedoutException e) { + String msg = String.format("Unable to scale %s due to [%s].", vm.toString(), e.getMessage()); + s_logger.error(msg, e); + throw new AgentUnavailableException(msg, dstHostId); + } catch (AgentUnavailableException e) { + String msg = String.format("Unable to scale %s due to [%s].", vm.toString(), e.getMessage()); + s_logger.error(msg, e); throw e; } finally { if (!success) { From 915830a1db413329d019ac8298f2907691062564 Mon Sep 17 00:00:00 2001 From: Daniel Augusto Veronezi Salvador Date: Fri, 23 Apr 2021 17:20:57 -0300 Subject: [PATCH 8/9] Rename configurations variables --- .../java/com/cloud/vm/VirtualMachineManagerImpl.java | 4 ++-- .../java/com/cloud/hypervisor/HypervisorGuruBase.java | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java index 25f6c3b554ec..d42675ebcef7 100755 --- a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java @@ -4539,8 +4539,8 @@ private VMInstanceVO orchestrateReConfigureVm(String vmUuid, ServiceOffering old Long clustedId = hostVo.getClusterId(); Float memoryOvercommitRatio = CapacityManager.MemOverprovisioningFactor.valueIn(clustedId); Float cpuOvercommitRatio = CapacityManager.CpuOverprovisioningFactor.valueIn(clustedId); - boolean divideMemoryByOverprovisioning = HypervisorGuruBase.VM_MIN_MEMORY_EQUALS_MEMORY_DIVIDED_BY_MEM_OVERPROVISIONING_FACTOR.valueIn(clustedId); - boolean divideCpuByOverprovisioning = HypervisorGuruBase.VM_MIN_CPU_SPEED_EQUALS_CPU_SPEED_DIVIDED_BY_CPU_OVERPROVISIONING_FACTOR.valueIn(clustedId); + boolean divideMemoryByOverprovisioning = HypervisorGuruBase.VmMinMemoryEqualsMemoryDividedByMemOverprovisioningFactor.valueIn(clustedId); + boolean divideCpuByOverprovisioning = HypervisorGuruBase.VmMinCpuSpeedEqualsCpuSpeedDividedByCpuOverprovisioningFactor.valueIn(clustedId); int minMemory = (int)(newServiceOffering.getRamSize() / (divideMemoryByOverprovisioning ? memoryOvercommitRatio : 1)); int minSpeed = (int)(newServiceOffering.getSpeed() / (divideCpuByOverprovisioning ? cpuOvercommitRatio : 1)); diff --git a/server/src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java b/server/src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java index c68bb7422f7b..3517a2990ae4 100644 --- a/server/src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java +++ b/server/src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java @@ -92,10 +92,10 @@ public abstract class HypervisorGuruBase extends AdapterBase implements Hypervis @Inject private HostDao hostDao; - public static ConfigKey VM_MIN_MEMORY_EQUALS_MEMORY_DIVIDED_BY_MEM_OVERPROVISIONING_FACTOR = new ConfigKey("Advanced", Boolean.class, "vm.min.memory.equals.memory.divided.by.mem.overprovisioning.factor", "true", + public static ConfigKey VmMinMemoryEqualsMemoryDividedByMemOverprovisioningFactor = new ConfigKey("Advanced", Boolean.class, "vm.min.memory.equals.memory.divided.by.mem.overprovisioning.factor", "true", "If we set this to 'true', a minimum memory (memory/ mem.overprovisioning.factor) will be set to the VM, independent of using a scalable service offering or not.", true, ConfigKey.Scope.Cluster); - public static ConfigKey VM_MIN_CPU_SPEED_EQUALS_CPU_SPEED_DIVIDED_BY_CPU_OVERPROVISIONING_FACTOR = new ConfigKey("Advanced", Boolean.class, "vm.min.cpu.speed.equals.cpu.speed.divided.by.cpu.overprovisioning.factor", "true", + public static ConfigKey VmMinCpuSpeedEqualsCpuSpeedDividedByCpuOverprovisioningFactor = new ConfigKey("Advanced", Boolean.class, "vm.min.cpu.speed.equals.cpu.speed.divided.by.cpu.overprovisioning.factor", "true", "If we set this to 'true', a minimum CPU speed (cpu speed/ cpu.overprovisioning.factor) will be set on the VM, independent of using a scalable service offering or not.", true, ConfigKey.Scope.Cluster); @Override @@ -181,8 +181,8 @@ protected VirtualMachineTO toVirtualMachineTO(VirtualMachineProfile vmProfile) { VirtualMachine vm = vmProfile.getVirtualMachine(); HostVO host = hostDao.findById(vm.getHostId()); - boolean divideMemoryByOverprovisioning = VM_MIN_MEMORY_EQUALS_MEMORY_DIVIDED_BY_MEM_OVERPROVISIONING_FACTOR.valueIn(host.getClusterId()); - boolean divideCpuByOverprovisioning = VM_MIN_CPU_SPEED_EQUALS_CPU_SPEED_DIVIDED_BY_CPU_OVERPROVISIONING_FACTOR.valueIn(host.getClusterId()); + boolean divideMemoryByOverprovisioning = VmMinMemoryEqualsMemoryDividedByMemOverprovisioningFactor.valueIn(host.getClusterId()); + boolean divideCpuByOverprovisioning = VmMinCpuSpeedEqualsCpuSpeedDividedByCpuOverprovisioningFactor.valueIn(host.getClusterId()); Long minMemory = (long)(offering.getRamSize() / (divideMemoryByOverprovisioning ? vmProfile.getMemoryOvercommitRatio() : 1)); int minspeed = (int)(offering.getSpeed() / (divideCpuByOverprovisioning ? vmProfile.getCpuOvercommitRatio() : 1)); @@ -326,7 +326,7 @@ public String getConfigComponentName() { @Override public ConfigKey[] getConfigKeys() { - return new ConfigKey[] {VM_MIN_MEMORY_EQUALS_MEMORY_DIVIDED_BY_MEM_OVERPROVISIONING_FACTOR, VM_MIN_CPU_SPEED_EQUALS_CPU_SPEED_DIVIDED_BY_CPU_OVERPROVISIONING_FACTOR }; + return new ConfigKey[] {VmMinMemoryEqualsMemoryDividedByMemOverprovisioningFactor, VmMinCpuSpeedEqualsCpuSpeedDividedByCpuOverprovisioningFactor }; } } From f1a4db32eb21336ebd0882f582b178a925a50e82 Mon Sep 17 00:00:00 2001 From: Daniel Augusto Veronezi Salvador Date: Fri, 23 Apr 2021 17:26:49 -0300 Subject: [PATCH 9/9] Fix exception handling --- .../main/java/com/cloud/vm/VirtualMachineManagerImpl.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java index d42675ebcef7..0e5a54a826f0 100755 --- a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java @@ -4585,12 +4585,8 @@ private VMInstanceVO orchestrateReConfigureVm(String vmUuid, ServiceOffering old } success = true; } catch (OperationTimedoutException e) { - String msg = String.format("Unable to scale %s due to [%s].", vm.toString(), e.getMessage()); - s_logger.error(msg, e); - throw new AgentUnavailableException(msg, dstHostId); - } catch (AgentUnavailableException e) { - String msg = String.format("Unable to scale %s due to [%s].", vm.toString(), e.getMessage()); - s_logger.error(msg, e); + throw new AgentUnavailableException(String.format("Unable to scale %s due to [%s].", vm.toString(), e.getMessage()), dstHostId, e); + } catch (final AgentUnavailableException e) { throw e; } finally { if (!success) {