ConsolidationAlgorithmBase extends ClusterManagementDummyAlgorithm { public boolean canMigrateVmToHost(VmResources vm, HostResources host) { if (host.getCpus() < vm.getNumberOfCpus()) { return false; } long vmCpuNeeds = vm.getNumberOfCpus() * vm.getCpuSpeed(); if (getHostAvailableCpu(host) < vmCpuNeeds) { return false; } long vmMemory = vm.getMemoryInMegaBytes(); long hostAvailableMemory = getHostAvailableMemory(host); if (hostAvailableMemory < vmMemory) { return false; } return true; }  @Override int getClusterIntervalBetweenConsolidation(); @Override Map<Long, HostResources> mapVMsToHost(List<HostResources> rankedHosts); boolean canMigrateVmToHost(VmResources vm, HostResources host); void updateHostUsedResources(VmResources vm, HostResources host); @Override final boolean canPowerOffHost(HostResources hostToPowerOff, CloudResources cloudResources); @Override final boolean canPowerOffAnotherHostInCloud(CloudResources cloudResources); @Override boolean canHeuristicShutdownHosts();  }
@Test public void canMigrateVmToHostTestHostLessAmountOfCpusThanVm() { HostResources host = createHost(1, 1000l, 0l, 1000l, 500l); VmResources vm = new VmResources(0, 2, 1000l, 10l); Assert.assertFalse(spyAlgorithm.canMigrateVmToHost(vm, host)); checkGetHostAvailableCpuAndMemoryExecution(host, 0, 0); }
@Test public void canMigrateVmToHostTestHostLessCpusAndCpuSpeedThanVm() { HostResources host = createHost(2, 1l, 0l, 1000l, 500l); VmResources vm = new VmResources(0, 2, 1000l, 10l); Assert.assertFalse(spyAlgorithm.canMigrateVmToHost(vm, host)); checkGetHostAvailableCpuAndMemoryExecution(host, 1, 0); }
@Test public void canMigrateVmToHostTestHostLessMemoryThanVm() { HostResources host = createHost(2, 1000l, 0l, 1000l, 500l); VmResources vm = new VmResources(0, 1, 1000l, 1000l); Assert.assertFalse(spyAlgorithm.canMigrateVmToHost(vm, host)); checkGetHostAvailableCpuAndMemoryExecution(host, 1, 1); }
@Test public void canMigrateVmToHostTestHostHasResourcesToAllocateVm() { HostResources host = createHost(2, 1000l, 0l, 1000l, 0l); VmResources vm = new VmResources(0, 1, 1000l, 500l); Assert.assertTrue(spyAlgorithm.canMigrateVmToHost(vm, host)); checkGetHostAvailableCpuAndMemoryExecution(host, 1, 1); }