Commit 0d6fdfb2 authored by Rafael Vieira Falcão's avatar Rafael Vieira Falcão
Browse files

Adding modification that check if a vm should be counted as a vm with credit

parent 7c0cab28
......@@ -316,6 +316,8 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
for (Host h : looseSlaHosts) {
for (Vm vm : h.getVmList()) {
// TODO (IF) Create method with code bellow
if(vm.isInMigration() && !isLooseHost(vm.gethostInMigration()))
continue;
if (vm.getMonitor().getCumulativeCredit(clock) - MIGRATION_TIME >= 0) {
candidateVmsToMigrate.add(vm);
}
......@@ -393,6 +395,10 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
}
return hosts;
}
private boolean isLooseHost(Host host) {
return host.getIopsProvisioner() instanceof ResourceProvisionerSimple;
}
@Override
public Optional<Host> findHostForVm(Vm vm) {
......
......@@ -101,34 +101,15 @@ public class VmAllocationPolicyMigrationSlaFixedTightHost extends VmAllocationPo
private Map<Vm, Host> optimisticConsolidation(Map<Vm, Host> actualMigrationMap) {
List<Host> sortedLooseHosts = getLooseHostsSortedAscendingByFragmentation();
for (int j = sortedLooseHosts.size() - 1; j >= 0; j--) {
for (int i = 0; i < sortedLooseHosts.size(); i++) {
if(i == j || sortedLooseHosts.get(i).getVmList().isEmpty())
continue;
for (Vm vm : sortedLooseHosts.get(i).getVmList()) {
if(sortedLooseHosts.get(j).isSuitableForVm(vm) && sortedLooseHosts.get(j).addMigratingInVm(vm)) {
actualMigrationMap.put(vm, sortedLooseHosts.get(j));
}
}
}
}
return actualMigrationMap;
}
private Map<Vm, Host> optimisticConsolidation2(Map<Vm, Host> actualMigrationMap) {
List<Host> orderedLooseHosts = getLooseHostsSortedAscendingByFragmentation();
List<Host> sortedLooseHosts = getLooseHostsSortedAscendingByFragmentation();
Iterator<Host> hostIt = sortedLooseHosts.listIterator();
for (int j = sortedLooseHosts.size() - 1; j >= 0; j--) {
for (int i = 0; i < sortedLooseHosts.size(); i++) {
if(i == j || sortedLooseHosts.get(i).getVmList().isEmpty())
continue;
for (Vm vm : sortedLooseHosts.get(i).getVmList()) {
if(sortedLooseHosts.get(j).isSuitableForVm(vm) && sortedLooseHosts.get(j).addMigratingInVm(vm)) {
actualMigrationMap.put(vm, sortedLooseHosts.get(j));
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())
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));
}
}
}
......@@ -136,6 +117,26 @@ public class VmAllocationPolicyMigrationSlaFixedTightHost extends VmAllocationPo
return actualMigrationMap;
}
// private Map<Vm, Host> optimisticConsolidation2(Map<Vm, Host> actualMigrationMap) {
//
// List<Host> sortedLooseHosts = getLooseHostsSortedAscendingByFragmentation();
// Iterator<Host> hostIt = sortedLooseHosts.listIterator();
//
// for (int j = sortedLooseHosts.size() - 1; j >= 0; j--) {
// for (int i = 0; i < sortedLooseHosts.size(); i++) {
// if(i == j || sortedLooseHosts.get(i).getVmList().isEmpty())
// continue;
// for (Vm vm : sortedLooseHosts.get(i).getVmList()) {
// if(sortedLooseHosts.get(j).isSuitableForVm(vm) && sortedLooseHosts.get(j).addMigratingInVm(vm)) {
// actualMigrationMap.put(vm, sortedLooseHosts.get(j));
// }
// }
// }
// }
//
// return actualMigrationMap;
// }
// Returns the list of loose hosts ordered (increase order) by the number of Vm
private List<Host> getLooseHostsSortedAscendingByFragmentation() {
......
......@@ -342,6 +342,10 @@ public class HostSimple implements Host {
}
vm.setInMigration(inMigration);
if(inMigration)
vm.setHostInMigration(this);
storage.allocateResource(vm.getStorage());
ramProvisioner.allocateResourceForVm(vm, vm.getCurrentRequestedRam());
bwProvisioner.allocateResourceForVm(vm, vm.getCurrentRequestedBw());
......
......@@ -413,6 +413,16 @@ public interface Vm extends Machine, UniquelyIdentificable, Comparable<Vm>, Cust
* @return
*/
boolean isInMigration();
/**
* Sets host that the Vm is migrating into
*/
void setHostInMigration(Host host);
/**
* Gets host that the Vm is migrating into
*/
Host gethostInMigration();
/**
* Defines if the VM is in migration process or not.
......
......@@ -258,4 +258,14 @@ final class VmNull implements Vm {
public void setIOPSUtilization(double time, double value) {
return;
}
@Override
public void setHostInMigration(Host host) {
// TODO Auto-generated method stub
}
@Override
public Host gethostInMigration() {
// TODO Auto-generated method stub
return null;
}
}
......@@ -123,6 +123,8 @@ public class VmSimple implements Vm {
*/
private Iops iops;
private Host hostMigratingIn;
/**
* The SLA regarding this VM.
*/
......@@ -934,4 +936,17 @@ public class VmSimple implements Vm {
public UtilizationHistory getUtilizationHistory() {
return utilizationHistory;
}
@Override
public void setHostInMigration(Host host) {
this.hostMigratingIn = host;
}
@Override
public Host gethostInMigration() {
return this.hostMigratingIn;
}
}
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