Commit e724b50d authored by Eduardo Falcão's avatar Eduardo Falcão
Browse files

turning on again heaven hosts

parent 4fd3fdf9
......@@ -5,9 +5,11 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Queue;
import org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicy;
import org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicyAbstract;
......@@ -132,7 +134,7 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
List<Vm> sufferingVms = new ArrayList<Vm>();
//FIXME sort to prioritize the VMs that are suffering more
sufferingVms.addAll(getVmsAboutToViolateSla(tightSlaHosts));
//for each heaven host
for (Host h : looseSlaHosts) {
if (sufferingVms.isEmpty()) {
......@@ -152,6 +154,27 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
}
}
Queue<Host> inactiveHosts = getInactiveHosts(looseSlaHosts);
while(!sufferingVms.isEmpty() && !inactiveHosts.isEmpty()){
Host hostToBeTurnedOn = inactiveHosts.poll();
hostToBeTurnedOn.setActive(true);
Iterator<Vm> vmIterator = sufferingVms.iterator();
boolean keepHostOn = false;
for(Vm vm : sufferingVms){
if(hostToBeTurnedOn.isSuitableForVm(vm) && hostToBeTurnedOn.addMigratingInVm(vm)){
migrationMap.put(vm, hostToBeTurnedOn);
vmIterator.remove();
iopsScaling = VerticalVmScaling.NULL;
vm.setIopsVerticalScaling(iopsScaling);
iopsScaling.setVm(vm);
keepHostOn = true;
}
}
if(!keepHostOn){
hostToBeTurnedOn.setActive(false);
}
}
previousFragmentation.putAll(currentFragmentation);
return migrationMap;
......@@ -319,6 +342,15 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
return MIGRATION_TIME;
}
public Queue<Host> getInactiveHosts(List<Host> hosts){
Queue<Host> inactiveHosts = new LinkedList<>();
for(Host h : hosts){
if(!h.isActive())
inactiveHosts.offer(h);
}
return inactiveHosts;
}
/**
* Creates a {@link VerticalVmScaling} for scaling VM's IOPS when it's under or
* overloaded.
......
package org.cloudbus.cloudsim.allocationpolicies.migration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
......@@ -49,7 +50,7 @@ public class VmAllocationPolicyMigrationSlaDynamicTightHost extends VmAllocation
int numberCreditVms = getVmsWithEnoughCredit(getHostsWithLooseSla()).size();
System.out.println("Vms with credit in Heaven: "+numberCreditVms);
System.out.println("Vms (not migrating) with credit in Heaven: "+numberCreditVms);
// Check if the number of vms with credit also consider the vms with credit that are
// in the Tight hosts (Check vms that are current migrating)
......@@ -121,10 +122,15 @@ public class VmAllocationPolicyMigrationSlaDynamicTightHost extends VmAllocation
List<Host> orderedLooseHosts = getLooseHostsSortedAscendingByFragmentation();
for (int i = 0; i < orderedLooseHosts.size(); i++) {
for (int j = orderedLooseHosts.size() - 1; j >= 0; j--) {
if(i == j || orderedLooseHosts.get(i).getVmList().isEmpty())
for (int i = 0; i < orderedLooseHosts.size(); i++) {
for (int j = orderedLooseHosts.size() - 1; j >= 0; j--) {
if(i==j){
break;
}
else if(orderedLooseHosts.get(i).getVmList().isEmpty()){
orderedLooseHosts.get(i).setActive(false);
break;
}
for (Vm vm : orderedLooseHosts.get(i).getVmList()) {
if(orderedLooseHosts.get(j).isSuitableForVm(vm) && orderedLooseHosts.get(j).addMigratingInVm(vm)) {
actualMigrationMap.put(vm, orderedLooseHosts.get(j));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment