Commit 2d127d23 authored by Lucas Cavalcante's avatar Lucas Cavalcante
Browse files

Merge branch 'sla-simulation' of...

Merge branch 'sla-simulation' of git.lsd.ufcg.edu.br:lenovo-autonomic/cloudsimplus into sla-simulation
parents 40781046 bbe1814b
......@@ -33,6 +33,7 @@ import org.cloudbus.cloudsim.vms.Vm;
* @author Kaio Kassiano Moura Oliveira (@kaiokmo)
* @author Eduardo de Lucena Falcao (@eduardolfalcao)
*/
public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
private static final String LOOSE = "LOOSE";
......@@ -116,6 +117,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
......@@ -192,6 +194,7 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
* @param h the host
* @return a list of VMs
*/
//TODO This method needs to get the looseSlaHosts as a parameter?
protected List<Vm> getVmsWithEnoughCredit(List<Host> looseSlaHosts){
List<Vm> candidateVmsToMigrate = new ArrayList<Vm>();
......@@ -199,7 +202,7 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
for (Host h : looseSlaHosts) {
for (Vm vm : h.getVmList()) {
// TODO (IF) Create method with code bellow
if (vm.getMonitor().getCumulativeVmViolationTime(clock) + MIGRATION_TIME <=
vm.getMonitor().getMaximumAllowedSlaViolationTime()) {
candidateVmsToMigrate.add(vm);
......@@ -285,6 +288,7 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
return allocationPolicy.findHostForVm(vm);
}
//TODO Rename method name
public int getMIGRATION_TIME() {
return MIGRATION_TIME;
}
......
package org.cloudbus.cloudsim.allocationpolicies.migration;
import java.util.List;
import java.util.Map;
import org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicy;
import org.cloudbus.cloudsim.hosts.Host;
import org.cloudbus.cloudsim.provisioners.ResourceProvisionerShared;
import org.cloudbus.cloudsim.vms.Vm;
/**
* A VM allocation policy that tries to exploit a VM's SLA to
* better use the resources of a host, reducing fragmentation.
*
* To accomplish this task, the allocation policy continually
* keeps track of all VMs and migrate them from hosts in which
* the SLA contracted is delivered (SL Loose) to hosts in which
* the instantaneous SLA may de be violated (SL Tight), or vice-
* versa.
*
* The creation of the 'Tight' hosts is dynamic. Although,
* the maximum number of 'Tight' hosts is static
*
* For more information, please refer to this paper:
*
* @author Rafael Vieira Falcao (@rafaelvfalc)
*/
public class VmAllocationPolicyMigrationSlaFixedTightHost extends VmAllocationPolicyMigrationSla {
private int vmsThreshold = 0;
public VmAllocationPolicyMigrationSlaFixedTightHost(VmAllocationPolicy allocationPolicy, int migrationTime, int vmTresshold) {
super(allocationPolicy, migrationTime);
setVmsThreshold(vmTresshold);
}
@Override
public Map<Vm, Host> getOptimizedAllocationMap(
final List<? extends Vm> vmList) {
int numberCreditVms = getVmsWithEnoughCredit(getHostsWithLooseSla()).size();
if(numberCreditVms >= getVmsThreshold()) {
// The Tight host can be created
// Select the Loose host with more credit Vms
Host bestCandidateHost = getHostCandidate();
// Make it a Tight host
bestCandidateHost.setIopsProvisioner(new ResourceProvisionerShared());
}
// Run Migration Sla Algorithm
return super.getOptimizedAllocationMap(vmList);
}
/*
* Gets the best candidate host to be the new Tight host
* in order to optimize the number of migrations to consolidate all
* Credit Vms in the Tight host.
*/
public Host getHostCandidate() {
List<Host> looseHosts = getHostsWithLooseSla();
final double clock = getDatacenter().getSimulation().clock();
int actualHighestCreditVms = 0;
Host bestCandidateHost = null;
for (Host host : looseHosts) {
int creditVms = 0;
for (Vm vm : host.getVmList()) {
if (vm.getMonitor().getVmCredit(clock) - getMIGRATION_TIME() > 0) {
creditVms++;
}
}
if(creditVms > actualHighestCreditVms) {
actualHighestCreditVms = creditVms;
bestCandidateHost = host;
}
}
return bestCandidateHost;
}
private int getVmsThreshold() {
return vmsThreshold;
}
private void setVmsThreshold(int newThreshold) {
this.vmsThreshold = newThreshold;
}
}
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