GabrielBrascher commented on a change in pull request #4878:
URL: https://github.com/apache/cloudstack/pull/4878#discussion_r609057901
##########
File path: server/src/main/java/com/cloud/hypervisor/KVMGuru.java
##########
@@ -112,32 +121,147 @@ public VirtualMachineTO implement(VirtualMachineProfile
vm) {
VirtualMachineTO to = toVirtualMachineTO(vm);
setVmQuotaPercentage(to, vm);
- if (dpdkHelper.isDpdkvHostUserModeSettingOnServiceOffering(vm)) {
- dpdkHelper.setDpdkVhostUserMode(to, vm);
+ enableDpdkIfNeeded(vm, to);
+
+ VirtualMachine virtualMachine = vm.getVirtualMachine();
+ Long hostId = virtualMachine.getHostId();
+ HostVO host = hostId == null ? null : _hostDao.findById(hostId);
+
+ // Determine the VM's OS description
+ configureVmOsDescription(virtualMachine, to, host);
+
+ configureVmMemoryAndCpuCores(to, host, virtualMachine, vm);
+ return to;
+ }
+
+ protected void configureVmOsDescription(VirtualMachine virtualMachine,
VirtualMachineTO virtualMachineTo, HostVO hostVo) {
+ GuestOSVO guestOS =
_guestOsDao.findByIdIncludingRemoved(virtualMachine.getGuestOSId());
+ String guestOsDisplayName = guestOS.getDisplayName();
+ virtualMachineTo.setOs(guestOsDisplayName);
+ GuestOSHypervisorVO guestOsMapping = null;
+
+ if (hostVo != null) {
+ guestOsMapping =
_guestOsHypervisorDao.findByOsIdAndHypervisor(guestOS.getId(),
getHypervisorType().toString(), hostVo.getHypervisorVersion());
}
- if (to.getType() == VirtualMachine.Type.User &&
MapUtils.isNotEmpty(to.getExtraConfig()) &&
- to.getExtraConfig().containsKey(DpdkHelper.DPDK_NUMA) &&
to.getExtraConfig().containsKey(DpdkHelper.DPDK_HUGE_PAGES)) {
- for (final NicTO nic : to.getNics()) {
+ if (guestOsMapping == null || hostVo == null) {
+ virtualMachineTo.setPlatformEmulator(guestOsDisplayName == null ?
"Other" : guestOsDisplayName);
+ } else {
+
virtualMachineTo.setPlatformEmulator(guestOsMapping.getGuestOsName());
+ }
+ }
+
+ protected void enableDpdkIfNeeded(VirtualMachineProfile
virtualMachineProfile, VirtualMachineTO virtualMachineTo) {
+ if
(dpdkHelper.isDpdkvHostUserModeSettingOnServiceOffering(virtualMachineProfile))
{
+ dpdkHelper.setDpdkVhostUserMode(virtualMachineTo,
virtualMachineProfile);
+ }
+
+ if (virtualMachineTo.getType() == VirtualMachine.Type.User &&
MapUtils.isNotEmpty(virtualMachineTo.getExtraConfig()) &&
+ virtualMachineTo.getExtraConfig().containsKey(DpdkHelper.DPDK_NUMA)
&& virtualMachineTo.getExtraConfig().containsKey(DpdkHelper.DPDK_HUGE_PAGES)) {
+ for (final NicTO nic : virtualMachineTo.getNics()) {
nic.setDpdkEnabled(true);
}
}
+ }
+
+ protected void configureVmMemoryAndCpuCores(VirtualMachineTO
virtualMachineTo, HostVO hostVo, VirtualMachine virtualMachine,
VirtualMachineProfile virtualMachineProfile) {
+ String vmDescription = virtualMachineTo.toString();
+
+ Pair<Long, Integer> max = getHostMaxMemoryAndCpuCores(hostVo,
virtualMachine, vmDescription);
+
+ Long maxHostMemory = max.first();
+ Integer maxHostCpuCore = max.second();
+
+ Long minMemory = virtualMachineTo.getMinRam();
+ Long maxMemory = minMemory;
+ Integer minCpuCores = virtualMachineTo.getCpus();
+ Integer maxCpuCores = minCpuCores;
+
+ ServiceOfferingVO serviceOfferingVO =
serviceOfferingDao.findById(virtualMachineProfile.getId(),
virtualMachineProfile.getServiceOfferingId());
+ if (serviceOfferingVO.isDynamic() &&
virtualMachineTo.isEnableDynamicallyScaleVm()) {
+ serviceOfferingDao.loadDetails(serviceOfferingVO);
+
+ maxMemory = getVmMaxMemory(serviceOfferingVO, vmDescription,
maxHostMemory);
+ maxCpuCores = getVmMaxCpuCores(serviceOfferingVO, vmDescription,
maxHostCpuCore);
+ }
+
+ virtualMachineTo.setRam(minMemory, maxMemory);
+ virtualMachineTo.setCpus(minCpuCores);
+ virtualMachineTo.setVcpuMaxLimit(maxCpuCores);
+ }
+
+ protected Pair<Long, Integer> getHostMaxMemoryAndCpuCores(HostVO host,
VirtualMachine virtualMachine, String vmDescription){
+ Long maxHostMemory = Long.MAX_VALUE;
+ Integer maxHostCpuCore = Integer.MAX_VALUE;
- // Determine the VM's OS description
- GuestOSVO guestOS =
_guestOsDao.findByIdIncludingRemoved(vm.getVirtualMachine().getGuestOSId());
- to.setOs(guestOS.getDisplayName());
- HostVO host = _hostDao.findById(vm.getVirtualMachine().getHostId());
- GuestOSHypervisorVO guestOsMapping = null;
if (host != null) {
- guestOsMapping =
_guestOsHypervisorDao.findByOsIdAndHypervisor(guestOS.getId(),
getHypervisorType().toString(), host.getHypervisorVersion());
+ return new Pair<>(host.getTotalMemory(), host.getCpus());
}
- if (guestOsMapping == null || host == null) {
- to.setPlatformEmulator(guestOS.getDisplayName() == null ? "Other"
: guestOS.getDisplayName());
+
+ Long lastHostId = virtualMachine.getLastHostId();
+ s_logger.info(String.format("%s is not running; therefore, we use the
last host [%s] that the VM was running on to derive the unconstrained service
offering max CPU and memory.", vmDescription, lastHostId));
+
+ HostVO lastHost = lastHostId == null ? null :
_hostDao.findById(lastHostId);
+ if (lastHost != null) {
+ maxHostMemory = lastHost.getTotalMemory();
+ maxHostCpuCore = lastHost.getCpus();
+ s_logger.debug(String.format("Retrieved memory and cpu max values
{\"memory\": %s, \"cpu\": %s} from %s last %s.", maxHostMemory, maxHostCpuCore,
vmDescription, lastHost.toString()));
} else {
- to.setPlatformEmulator(guestOsMapping.getGuestOsName());
+ s_logger.warn(String.format("%s host [%s] and last host [%s] are
null. Using 'Long.MAX_VALUE' [%s] and 'Integer.MAX_VALUE' [%s] as max memory
and cpu cores.", vmDescription, virtualMachine.getHostId(), lastHostId,
maxHostMemory, maxHostCpuCore));
}
- return to;
+ return new Pair<>(maxHostMemory, maxHostCpuCore);
+ }
+
+ protected Long getVmMaxMemory(ServiceOfferingVO serviceOfferingVO, String
vmDescription, Long maxHostMemory) {
+ String serviceOfferingDescription = serviceOfferingVO.toString();
+
+ Long maxMemory;
+ Integer customOfferingMaxMemory =
NumberUtils.createInteger(serviceOfferingVO.getDetail(ApiConstants.MAX_MEMORY));
+ Integer maxMemoryConfig =
ConfigurationManagerImpl.VM_SERVICE_OFFERING_MAX_RAM_SIZE.value();
+ if (customOfferingMaxMemory != null) {
+ s_logger.debug(String.format("Using 'Custom unconstrained' %s max
memory value [%sMb] as %s memory.", serviceOfferingDescription,
customOfferingMaxMemory, vmDescription));
Review comment:
Shouldn't it be _Custom constrained_?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]