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

Merge branch 'sla-monitor' of git.lsd.ufcg.edu.br:lenovo-autonomic/cloudsimplus into sla-monitor

parents 6af1a126 7972b7f6
......@@ -132,7 +132,7 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
* or a list of hosts from low to high fragmentation
* @param list a list of Machines (vms or hosts)
*/
private void sort(List<? extends Machine> list){
protected void sort(List<? extends Machine> list){
if(list.isEmpty())
return;
......@@ -179,7 +179,7 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
* @param h the host
* @return a list of VMs
*/
private List<Vm> getVmsWithEnoughCredit(List<Host> looseSlaHosts){
protected List<Vm> getVmsWithEnoughCredit(List<Host> looseSlaHosts){
List<Vm> candidateVmsToMigrate = new ArrayList<Vm>();
final double clock = getDatacenter().getSimulation().clock();
......@@ -196,11 +196,11 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
return candidateVmsToMigrate;
}
private double getVmFragmentation(Vm vm){
protected double getVmFragmentation(Vm vm){
return vm.getIops().getAvailableResource();
}
private double getHostFragmentation(Host h){
protected double getHostFragmentation(Host h){
return h.getIops().getAvailableResource();
}
......@@ -210,7 +210,7 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
* @param host a tight SLA host
* @return a set of VMs
*/
private Set<Vm> getSufferingVms(Set<Host> tightSlaHosts){
protected Set<Vm> getSufferingVms(Set<Host> tightSlaHosts){
Set<Vm> sufferingVms = new HashSet<Vm>();
final double clock = getDatacenter().getSimulation().clock();
......
......@@ -4,10 +4,10 @@ import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.apache.commons.lang3.NotImplementedException;
import org.cloudbus.cloudsim.allocationpolicies.migration.VmAllocationPolicyMigrationSla;
import org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicy;
import org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicySimple;
import org.cloudbus.cloudsim.datacenters.Datacenter;
import org.cloudbus.cloudsim.hosts.Host;
import org.cloudbus.cloudsim.provisioners.ResourceProvisioner;
......@@ -18,9 +18,7 @@ import org.cloudbus.cloudsim.resources.Iops;
import org.cloudbus.cloudsim.resources.Ram;
import org.cloudbus.cloudsim.resources.ResourceManageable;
import org.cloudbus.cloudsim.vms.Vm;
import org.cloudbus.cloudsim.vms.VmWithMetadata;
import org.cloudbus.cloudsim.vms.VmWithMetadata.VmData;
import org.cloudbus.cloudsim.vms.VmWithMetadata.VmLabel;
import org.cloudbus.cloudsim.vms.VmSimple;
import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Test;
......@@ -36,6 +34,8 @@ public class VmAllocationPolicyMigrationSlaTest {
public static final int HOST_BW = 100000;
public static final int HOST_BASE_STORAGE = 1000;
public static final int MIGRATION_TIME = 60;
private VmAllocationPolicyMigrationSla policy;
@Before
......@@ -52,9 +52,22 @@ public class VmAllocationPolicyMigrationSlaTest {
Datacenter datacenter = createMockedDatacenter(hosts);
policy = new VmAllocationPolicyMigrationSla();
VmAllocationPolicy ap = new VmAllocationPolicySimple();
policy = new VmAllocationPolicyMigrationSla(ap, MIGRATION_TIME);
policy.setDatacenter(datacenter);
}
@Test
public void getVmsFragmentationTest() {
Vm vm1 = createMockedVm(1, 0.1, 0.1, 0.9, 0.5);
Vm vm2 = createMockedVm(2, 0.1, 0.1, 0.5, 0.5);
double vmFragmentation1 = policy.getVmFragmentation(vm1);
double vmFragmentation2 = policy.getVmFragmentation(vm2);
assertEquals(vm1.getIopsPercentUsage() - vm1.getIops().getCapacity(), vmFragmentation1, 2);
assertEquals(vm2.getIopsPercentUsage() - vm2.getIops().getCapacity(), vmFragmentation2, 2);
}
@Test
public void migrateVmFromHeavenToHell() {
......@@ -67,7 +80,7 @@ public class VmAllocationPolicyMigrationSlaTest {
}
private Vm createMockedVm(int id, double cpuUsage, double ramUsage, double iopsUsage, double bwUsage) {
VmWithMetadata vm = EasyMock.createMock(VmWithMetadata.class);
VmSimple vm = EasyMock.createMock(VmSimple.class);
EasyMock.expect(vm.getId()).andReturn(id).anyTimes();
EasyMock.expect(vm.getCpuPercentUsage()).andReturn(cpuUsage).anyTimes();
......
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