AutonomiccsSystemVmDeploymentService implements InitializingBean { protected boolean canHostSupportVm(ServiceOfferingVO vmServiceOffering, HostResources hostResources) { if (vmServiceOffering.getCpu() > hostResources.getCpus()) { return false; } double hostTotalCpu = hostResources.getCpuOverprovisioning() * hostResources.getCpus() * hostResources.getSpeed(); double hostUsedCpu = hostResources.getUsedCpu(); if ((vmServiceOffering.getSpeed() * vmServiceOffering.getCpu()) > hostTotalCpu - hostUsedCpu) { return false; } double hostTotalMemoryInMegaBytes = (hostResources.getMemoryOverprovisioning() * hostResources.getTotalMemoryInBytes()) / ONE_MEGABYTE_IN_BYTES; long usedMemoryInMegabytes = hostResources.getUsedMemoryInMegaBytes(); if (vmServiceOffering.getRamSize() > hostTotalMemoryInMegaBytes - usedMemoryInMegabytes) { return false; } return true; }  HostVO searchForRandomHostInCloudToDeployAutonomiccsSystemVm(); HostVO searchForRandomHostInPodToDeployAutonomiccsSystemVm(HostPodVO pod); HostVO searchForAnotherRandomHostToStartSystemVm(VMInstanceVO vmInstance); AutonomiccsSystemVm deploySystemVmWithJava(Long hostId, SystemVmType systemVmType); @Override void afterPropertiesSet();  }
@Test public void canHostSupportVmTest() { ServiceOfferingVO vmServiceOffering = createVmServiceOffering(1, 1000, 1000); HostResources hostResources = createHostResources(2, 2.0f, 1000, 1000, 3.0f, 4000 * (long) ONE_MEGABYTE_IN_BYTES, 2000); boolean result = spy.canHostSupportVm(vmServiceOffering, hostResources); verifyCanHostSupportVmTest(vmServiceOffering, hostResources, 1, 1, true, result); }
@Test public void canHostSupportVmTestNotEnoughtRam() { ServiceOfferingVO vmServiceOffering = createVmServiceOffering(1, 1000, 1000); HostResources hostResources = createHostResources(2, 2.0f, 1000, 1000, 2.0f, 1000 * (long) ONE_MEGABYTE_IN_BYTES, 1200); boolean result = spy.canHostSupportVm(vmServiceOffering, hostResources); verifyCanHostSupportVmTest(vmServiceOffering, hostResources, 1, 1, false, result); }
@Test public void canHostSupportVmTestNotEnoughtCpu() { ServiceOfferingVO vmServiceOffering = createVmServiceOffering(2, 1000, 1000); HostResources hostResources = createHostResources(2, 1.0f, 1000, 1000, 2.0f, 2000 * (long) ONE_MEGABYTE_IN_BYTES, 1000); boolean result = spy.canHostSupportVm(vmServiceOffering, hostResources); verifyCanHostSupportVmTest(vmServiceOffering, hostResources, 1, 0, false, result); }
@Test public void canHostSupportVmTestNotEnoughtNumberOfCpus() { ServiceOfferingVO vmServiceOffering = createVmServiceOffering(2, 1000, 1000); HostResources hostResources = createHostResources(1, 2.0f, 900, 1000, 2.0f, 2000 * (long) ONE_MEGABYTE_IN_BYTES, 1000); boolean result = spy.canHostSupportVm(vmServiceOffering, hostResources); verifyCanHostSupportVmTest(vmServiceOffering, hostResources, 0, 0, false, result); }