mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Externalize config to set min memory/cpu with division by overprovisi… (#4722)
Co-authored-by: Daniel Augusto Veronezi Salvador <daniel@scclouds.com.br> Co-authored-by: dahn <daan.hoogland@gmail.com>
This commit is contained in:
parent
f1c83a0b05
commit
6531ee5871
@ -171,6 +171,7 @@ import com.cloud.host.Status;
|
|||||||
import com.cloud.host.dao.HostDao;
|
import com.cloud.host.dao.HostDao;
|
||||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||||
import com.cloud.hypervisor.HypervisorGuru;
|
import com.cloud.hypervisor.HypervisorGuru;
|
||||||
|
import com.cloud.hypervisor.HypervisorGuruBase;
|
||||||
import com.cloud.hypervisor.HypervisorGuruManager;
|
import com.cloud.hypervisor.HypervisorGuruManager;
|
||||||
import com.cloud.network.Network;
|
import com.cloud.network.Network;
|
||||||
import com.cloud.network.NetworkModel;
|
import com.cloud.network.NetworkModel;
|
||||||
@ -4659,34 +4660,43 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private VMInstanceVO orchestrateReConfigureVm(final String vmUuid, final ServiceOffering oldServiceOffering, final ServiceOffering newServiceOffering,
|
private VMInstanceVO orchestrateReConfigureVm(String vmUuid, ServiceOffering oldServiceOffering, ServiceOffering newServiceOffering,
|
||||||
final boolean reconfiguringOnExistingHost) throws ResourceUnavailableException, ConcurrentOperationException {
|
boolean reconfiguringOnExistingHost) throws ResourceUnavailableException, ConcurrentOperationException {
|
||||||
final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
|
VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
|
||||||
upgradeVmDb(vm.getId(), newServiceOffering, oldServiceOffering);
|
upgradeVmDb(vm.getId(), newServiceOffering, oldServiceOffering);
|
||||||
|
|
||||||
final HostVO hostVo = _hostDao.findById(vm.getHostId());
|
HostVO hostVo = _hostDao.findById(vm.getHostId());
|
||||||
final Float memoryOvercommitRatio = CapacityManager.MemOverprovisioningFactor.valueIn(hostVo.getClusterId());
|
|
||||||
final Float cpuOvercommitRatio = CapacityManager.CpuOverprovisioningFactor.valueIn(hostVo.getClusterId());
|
Long clustedId = hostVo.getClusterId();
|
||||||
final long minMemory = (long)(newServiceOffering.getRamSize() / memoryOvercommitRatio);
|
Float memoryOvercommitRatio = CapacityManager.MemOverprovisioningFactor.valueIn(clustedId);
|
||||||
final ScaleVmCommand reconfigureCmd =
|
Float cpuOvercommitRatio = CapacityManager.CpuOverprovisioningFactor.valueIn(clustedId);
|
||||||
new ScaleVmCommand(vm.getInstanceName(), newServiceOffering.getCpu(), (int)(newServiceOffering.getSpeed() / cpuOvercommitRatio),
|
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));
|
||||||
|
|
||||||
|
ScaleVmCommand scaleVmCommand =
|
||||||
|
new ScaleVmCommand(vm.getInstanceName(), newServiceOffering.getCpu(), minSpeed,
|
||||||
newServiceOffering.getSpeed(), minMemory * 1024L * 1024L, newServiceOffering.getRamSize() * 1024L * 1024L, newServiceOffering.getLimitCpuUse());
|
newServiceOffering.getSpeed(), minMemory * 1024L * 1024L, newServiceOffering.getRamSize() * 1024L * 1024L, newServiceOffering.getLimitCpuUse());
|
||||||
|
|
||||||
final Long dstHostId = vm.getHostId();
|
Long dstHostId = vm.getHostId();
|
||||||
if(vm.getHypervisorType().equals(HypervisorType.VMware)) {
|
|
||||||
final HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vm.getHypervisorType());
|
if (vm.getHypervisorType().equals(HypervisorType.VMware)) {
|
||||||
Map<String, String> details = null;
|
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vm.getHypervisorType());
|
||||||
details = hvGuru.getClusterSettings(vm.getId());
|
Map<String, String> details = hvGuru.getClusterSettings(vm.getId());
|
||||||
reconfigureCmd.getVirtualMachine().setDetails(details);
|
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.setStep(Step.Prepare);
|
||||||
work.setResourceType(ItWorkVO.ResourceType.Host);
|
work.setResourceType(ItWorkVO.ResourceType.Host);
|
||||||
work.setResourceId(vm.getHostId());
|
work.setResourceId(vm.getHostId());
|
||||||
_workDao.persist(work);
|
_workDao.persist(work);
|
||||||
|
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (reconfiguringOnExistingHost) {
|
if (reconfiguringOnExistingHost) {
|
||||||
vm.setServiceOfferingId(oldServiceOffering.getId());
|
vm.setServiceOfferingId(oldServiceOffering.getId());
|
||||||
@ -4695,17 +4705,18 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
|||||||
_capacityMgr.allocateVmCapacity(vm, false); // lock the new capacity
|
_capacityMgr.allocateVmCapacity(vm, false); // lock the new capacity
|
||||||
}
|
}
|
||||||
|
|
||||||
final Answer reconfigureAnswer = _agentMgr.send(vm.getHostId(), reconfigureCmd);
|
Answer scaleVmAnswer = _agentMgr.send(vm.getHostId(), scaleVmCommand);
|
||||||
if (reconfigureAnswer == null || !reconfigureAnswer.getResult()) {
|
if (scaleVmAnswer == null || !scaleVmAnswer.getResult()) {
|
||||||
s_logger.error("Unable to scale vm due to " + (reconfigureAnswer == null ? "" : reconfigureAnswer.getDetails()));
|
String msg = String.format("Unable to scale %s due to [%s].", vm.toString(), (scaleVmAnswer == null ? "" : scaleVmAnswer.getDetails()));
|
||||||
throw new CloudRuntimeException("Unable to scale vm due to " + (reconfigureAnswer == null ? "" : reconfigureAnswer.getDetails()));
|
s_logger.error(msg);
|
||||||
|
throw new CloudRuntimeException(msg);
|
||||||
}
|
}
|
||||||
if (vm.getType().equals(VirtualMachine.Type.User)) {
|
if (vm.getType().equals(VirtualMachine.Type.User)) {
|
||||||
_userVmMgr.generateUsageEvent(vm, vm.isDisplayVm(), EventTypes.EVENT_VM_DYNAMIC_SCALE);
|
_userVmMgr.generateUsageEvent(vm, vm.isDisplayVm(), EventTypes.EVENT_VM_DYNAMIC_SCALE);
|
||||||
}
|
}
|
||||||
success = true;
|
success = true;
|
||||||
} catch (final OperationTimedoutException e) {
|
} catch (OperationTimedoutException e) {
|
||||||
throw new AgentUnavailableException("Operation timed out on reconfiguring " + vm, dstHostId);
|
throw new AgentUnavailableException(String.format("Unable to scale %s due to [%s].", vm.toString(), e.getMessage()), dstHostId, e);
|
||||||
} catch (final AgentUnavailableException e) {
|
} catch (final AgentUnavailableException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@ -34,6 +34,8 @@ import com.cloud.agent.api.to.DiskTO;
|
|||||||
import com.cloud.agent.api.to.NicTO;
|
import com.cloud.agent.api.to.NicTO;
|
||||||
import com.cloud.agent.api.to.VirtualMachineTO;
|
import com.cloud.agent.api.to.VirtualMachineTO;
|
||||||
import com.cloud.gpu.GPU;
|
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.Networks.BroadcastDomainType;
|
||||||
import com.cloud.network.dao.NetworkDao;
|
import com.cloud.network.dao.NetworkDao;
|
||||||
import com.cloud.network.dao.NetworkDetailVO;
|
import com.cloud.network.dao.NetworkDetailVO;
|
||||||
@ -49,7 +51,6 @@ import com.cloud.service.dao.ServiceOfferingDetailsDao;
|
|||||||
import com.cloud.storage.StoragePool;
|
import com.cloud.storage.StoragePool;
|
||||||
import com.cloud.storage.Volume;
|
import com.cloud.storage.Volume;
|
||||||
import com.cloud.utils.Pair;
|
import com.cloud.utils.Pair;
|
||||||
import com.cloud.utils.StringUtils;
|
|
||||||
import com.cloud.utils.component.AdapterBase;
|
import com.cloud.utils.component.AdapterBase;
|
||||||
import com.cloud.vm.NicProfile;
|
import com.cloud.vm.NicProfile;
|
||||||
import com.cloud.vm.NicVO;
|
import com.cloud.vm.NicVO;
|
||||||
@ -61,8 +62,11 @@ import com.cloud.vm.dao.NicDao;
|
|||||||
import com.cloud.vm.dao.NicSecondaryIpDao;
|
import com.cloud.vm.dao.NicSecondaryIpDao;
|
||||||
import com.cloud.vm.dao.UserVmDetailsDao;
|
import com.cloud.vm.dao.UserVmDetailsDao;
|
||||||
import com.cloud.vm.dao.VMInstanceDao;
|
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);
|
public static final Logger s_logger = Logger.getLogger(HypervisorGuruBase.class);
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@ -85,6 +89,14 @@ public abstract class HypervisorGuruBase extends AdapterBase implements Hypervis
|
|||||||
private ServiceOfferingDao _serviceOfferingDao;
|
private ServiceOfferingDao _serviceOfferingDao;
|
||||||
@Inject
|
@Inject
|
||||||
private NetworkDetailsDao networkDetailsDao;
|
private NetworkDetailsDao networkDetailsDao;
|
||||||
|
@Inject
|
||||||
|
private HostDao hostDao;
|
||||||
|
|
||||||
|
public static ConfigKey<Boolean> VmMinMemoryEqualsMemoryDividedByMemOverprovisioningFactor = new ConfigKey<Boolean>("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<Boolean> VmMinCpuSpeedEqualsCpuSpeedDividedByCpuOverprovisioningFactor = new ConfigKey<Boolean>("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
|
@Override
|
||||||
public NicTO toNicTO(NicProfile profile) {
|
public NicTO toNicTO(NicProfile profile) {
|
||||||
@ -167,8 +179,13 @@ public abstract class HypervisorGuruBase extends AdapterBase implements Hypervis
|
|||||||
protected VirtualMachineTO toVirtualMachineTO(VirtualMachineProfile vmProfile) {
|
protected VirtualMachineTO toVirtualMachineTO(VirtualMachineProfile vmProfile) {
|
||||||
ServiceOffering offering = _serviceOfferingDao.findById(vmProfile.getId(), vmProfile.getServiceOfferingId());
|
ServiceOffering offering = _serviceOfferingDao.findById(vmProfile.getId(), vmProfile.getServiceOfferingId());
|
||||||
VirtualMachine vm = vmProfile.getVirtualMachine();
|
VirtualMachine vm = vmProfile.getVirtualMachine();
|
||||||
Long minMemory = (long)(offering.getRamSize() / vmProfile.getMemoryOvercommitRatio());
|
HostVO host = hostDao.findById(vm.getHostId());
|
||||||
int minspeed = (int)(offering.getSpeed() / vmProfile.getCpuOvercommitRatio());
|
|
||||||
|
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());
|
int maxspeed = (offering.getSpeed());
|
||||||
VirtualMachineTO to = new VirtualMachineTO(vm.getId(), vm.getInstanceName(), vm.getType(), offering.getCpu(), minspeed, maxspeed, minMemory * 1024l * 1024l,
|
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());
|
offering.getRamSize() * 1024l * 1024l, null, null, vm.isHaEnabled(), vm.limitCpuUse(), vm.getVncPassword());
|
||||||
@ -302,4 +319,15 @@ public abstract class HypervisorGuruBase extends AdapterBase implements Hypervis
|
|||||||
public List<Command> finalizeMigrate(VirtualMachine vm, Map<Volume, StoragePool> volumeToPool) {
|
public List<Command> finalizeMigrate(VirtualMachine vm, Map<Volume, StoragePool> volumeToPool) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getConfigComponentName() {
|
||||||
|
return HypervisorGuruBase.class.getSimpleName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConfigKey<?>[] getConfigKeys() {
|
||||||
|
return new ConfigKey<?>[] {VmMinMemoryEqualsMemoryDividedByMemOverprovisioningFactor, VmMinCpuSpeedEqualsCpuSpeedDividedByCpuOverprovisioningFactor };
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,7 +30,7 @@
|
|||||||
<property name="format" value="^[a-zA-Z][a-zA-Z0-9_]*$" />
|
<property name="format" value="^[a-zA-Z][a-zA-Z0-9_]*$" />
|
||||||
</module>
|
</module>
|
||||||
<module name="StaticVariableName">
|
<module name="StaticVariableName">
|
||||||
<property name="format" value="^(s_)?[a-z][a-zA-Z0-9]*$"/>
|
<property name="format" value="^(s_)?[a-zA-Z][a-zA-Z0-9_]*$"/>
|
||||||
</module>
|
</module>
|
||||||
<module name="ConstantName">
|
<module name="ConstantName">
|
||||||
<property name="format" value="^[a-zA-Z][a-zA-Z0-9_]*$"/>
|
<property name="format" value="^[a-zA-Z][a-zA-Z0-9_]*$"/>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user