VmsDispersionAlgorithmForHomogeneousEnvironment extends ConsolidationScoredPreferenceForSmallHosts { @Override public Map<Long, HostResources> mapVMsToHost(List<HostResources> rankedHosts) { if (MathUtils.equals(standardDeviationHostsUsage, 0)) { return new HashMap<>(); } List<HostResources> rankedHostsStdVms = cloneListOfHosts(rankedHosts); List<HostResources> rankedHostsStdHosts = cloneListOfHosts(rankedHosts); List<HostResources> rankedHostsStdAverage = cloneListOfHosts(rankedHosts); logger.debug("Simulating migration mapping with VMs resource standard deviation"); Map<Long, HostResources> vmsToHostStdVms = simulateVmsMigrations(rankedHostsStdVms, standardDeviationVmsConfiguration); logger.debug("Simulating migration mapping with hosts resource standard deviation"); Map<Long, HostResources> vmsToHostStdHosts = simulateVmsMigrations(rankedHostsStdHosts, standardDeviationHostsUsage); logger.debug("Simulating migration mapping with the average of hosts resource and VMs resource standard deviation"); Map<Long, HostResources> vmsToHostStdAverage = simulateVmsMigrations(rankedHostsStdAverage, standardDeviationAverage); double usedMemoryHostsWithStdVms[] = new double[rankedHosts.size()]; for (int i = 0; i < rankedHostsStdVms.size(); i++) { usedMemoryHostsWithStdVms[i] = rankedHostsStdVms.get(i).getUsedMemoryInMegaBytes(); } double stdWithStdVms = std.evaluate(usedMemoryHostsWithStdVms); logger.debug(String.format("The Std. achieved using the VMs resource standard deviation as parameter for the simulation was [%f]", stdWithStdVms)); double usedMemoryHostsWithStdHost[] = new double[rankedHosts.size()]; for (int i = 0; i < rankedHostsStdHosts.size(); i++) { usedMemoryHostsWithStdHost[i] = rankedHostsStdHosts.get(i).getUsedMemoryInMegaBytes(); } double stdWithStdHosts = std.evaluate(usedMemoryHostsWithStdHost); logger.debug(String.format("The Std. achieved using the hosts resource standard deviation as parameter for the simulation was [%f]", stdWithStdHosts)); double usedMemoryHostsWithStdAverage[] = new double[rankedHosts.size()]; for (int i = 0; i < rankedHostsStdAverage.size(); i++) { usedMemoryHostsWithStdAverage[i] = rankedHostsStdAverage.get(i).getUsedMemoryInMegaBytes(); } double stdWithStdAverage = std.evaluate(usedMemoryHostsWithStdAverage); logger.debug(String.format("The Std. achieved using the average between hosts resource and VMs resource standard deviation as parameter for the simulation was [%f]", stdWithStdAverage)); if (stdWithStdAverage <= stdWithStdHosts && stdWithStdAverage <= stdWithStdVms) { logger.debug("The simulation that won the competition was the one executed with alpha as the average of host resource and VMs resource standard deviation."); logger.debug(String.format("The number of migrations that will be executed is[%d].", vmsToHostStdAverage.size())); return vmsToHostStdAverage; } if (stdWithStdHosts <= stdWithStdVms) { logger.debug("The simulation that won the competition was the one executed with alpha as the host resource standard deviation."); logger.debug(String.format("The number of migrations that will be executed is[%d].", vmsToHostStdHosts.size())); return vmsToHostStdHosts; } logger.debug("The simulation that won the competition was the one executed with alpha as the VMs resource standard deviation."); logger.debug(String.format("The number of migrations that will be executed is[%d].", vmsToHostStdVms.size())); return vmsToHostStdVms; } VmsDispersionAlgorithmForHomogeneousEnvironment(); @Override List<HostResources> rankHosts(List<HostResources> hostsList); @Override List<HostResources> rankHostToPowerOff(List<HostResources> idleHosts); @Override boolean internalCanPowerOffHost(HostResources hostToPowerOff, CloudResources cloudResources); @Override Map<Long, HostResources> mapVMsToHost(List<HostResources> rankedHosts);  }
@Test public void mapVMsToHostTest() { HostResources h0 = createHostWithSmallVms(2); HostResources h1 = createHostWithSmallVms(1); HostResources h2 = createHostWithMediumVms(2); List<HostResources> hostsList = new ArrayList<HostResources>(); hostsList.add(h0); hostsList.add(h1); hostsList.add(h2); List<HostResources> rankedHosts = vmsDistributionAlgorithm.rankHosts(hostsList); Map<Long, HostResources> mapTest = vmsDistributionAlgorithm.mapVMsToHost(rankedHosts); Assert.assertEquals(1, mapTest.size()); long mapValues[] = new long[mapTest.size()]; for (HostResources host : mapTest.values()) { mapValues[0] = host.getUsedMemoryInMegaBytes(); } Assert.assertEquals(1536, mapValues[0]); verifyMapVmsToHostCalledMethods(rankedHosts, 3); }