Commit 5a18050d authored by Kaio Oliveira's avatar Kaio Oliveira
Browse files

Merge branch 'sla-monitor' of...

Merge branch 'sla-monitor' of https://git.lsd.ufcg.edu.br/lenovo-autonomic/cloudsimplus into sla-monitor
parents 64e2baa6 cccaf223
......@@ -82,7 +82,7 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
}
//filter heaven hosts
List<Host> looseSlaHosts = getHostsWithLooseSla(getDatacenter());
List<Host> looseSlaHosts = getHostsWithLooseSla();
//get all vms from heaven hosts and sort vms from higher to lower fragmentation
List<Vm> vmsDescendingFragmentation = new ArrayList<Vm>();
......@@ -90,7 +90,7 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
sort(vmsDescendingFragmentation);
//filter hell hosts and sort hell hosts ascending by fragmentation
List<Host> tightSlaHosts = getHostsWithTightSla(getDatacenter());
List<Host> tightSlaHosts = getHostsWithTightSla();
sort(tightSlaHosts);
//update current fragmentation
......@@ -231,8 +231,8 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
* Get hosts in which the SLA are delivered with no performance degradation.
* @return a set of hosts
*/
protected List<Host> getHostsWithTightSla(Datacenter dc){
return getHostsFromSlaExploitationPolicy(dc, TIGHT);
protected List<Host> getHostsWithTightSla(){
return getHostsFromSlaExploitationPolicy(getDatacenter(), TIGHT);
}
/**
......@@ -240,8 +240,8 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
* (may have (or not) performance degradation)
* @return a set of hosts
*/
protected List<Host> getHostsWithLooseSla(Datacenter dc){
return getHostsFromSlaExploitationPolicy(dc, LOOSE);
protected List<Host> getHostsWithLooseSla(){
return getHostsFromSlaExploitationPolicy(getDatacenter(), LOOSE);
}
/**
......@@ -251,22 +251,18 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
* @return a set of hosts
*/
protected List<Host> getHostsFromSlaExploitationPolicy(Datacenter dc, String policyType) {
List<Host> exploitationHosts = new ArrayList<Host>();
List<Host> hosts = new ArrayList<Host>();
for (Host host : dc.getHostList()) {
if (policyType.toUpperCase().equals(LOOSE) &&
host.getIopsProvisioner() instanceof ResourceProvisionerSimple) {
exploitationHosts.add(host);
hosts.add(host);
}
else if (policyType.toUpperCase().equals(TIGHT) &&
host.getIopsProvisioner() instanceof ResourceProvisionerShared) {
exploitationHosts.add(host);
}
else {
Log.print("This host is neither heaven nor hell: "+host.getIopsProvisioner().toString());
System.exit(0);
hosts.add(host);
}
}
return exploitationHosts;
return hosts;
}
@Override
......
......@@ -793,7 +793,7 @@ public class HostSimple implements Host {
@Override
public List<ResourceManageable> getResources() {
if(simulation.isRunning() && resources.isEmpty()){
resources = Arrays.asList(ramProvisioner.getResource(), bwProvisioner.getResource());
resources = Arrays.asList(ramProvisioner.getResource(), bwProvisioner.getResource(), iopsProvisioner.getResource());
}
return Collections.unmodifiableList(resources);
}
......@@ -801,7 +801,7 @@ public class HostSimple implements Host {
@Override
public ResourceProvisioner getProvisioner(final Class<? extends ResourceManageable> resourceClass) {
if(simulation.isRunning() && provisioners.isEmpty()){
provisioners = Arrays.asList(ramProvisioner, bwProvisioner);
provisioners = Arrays.asList(ramProvisioner, bwProvisioner, iopsProvisioner);
}
return provisioners
......
......@@ -10,12 +10,18 @@ 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;
import org.cloudbus.cloudsim.provisioners.ResourceProvisionerShared;
import org.cloudbus.cloudsim.provisioners.ResourceProvisionerSimple;
import org.cloudbus.cloudsim.resources.Bandwidth;
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.VmSimple;
import org.easymock.EasyMock;
import org.easymock.internal.matchers.InstanceOf;
import org.hamcrest.core.AnyOf;
import org.junit.Before;
import org.junit.Test;
......@@ -65,10 +71,10 @@ public class VmAllocationPolicyMigrationSlaTest {
Vm vm3 = createMockedVmWithIops(3, 0.1, 0.1, 1.0, 0.5, 0, 1000);
Vm vm4 = createMockedVmWithIops(4, 0.1, 0.1, 0.0, 0.5, 1000, 1000);
Host h1 = createMockedHostWithIops(1, 2, vm1, 900, 1000, 0.1);
Host h2 = createMockedHostWithIops(2, 2, vm2, 500, 1000, 0.5);
Host h3 = createMockedHostWithIops(3, 2, vm3, 0, 1000, 1.0);
Host h4 = createMockedHostWithIops(4, 2, vm4, 1000, 1000, 0.0);
Host h1 = createMockedHostWithIops(1, 2, vm1, 900, 1000, 0.1, null);
Host h2 = createMockedHostWithIops(2, 2, vm2, 500, 1000, 0.5, null);
Host h3 = createMockedHostWithIops(3, 2, vm3, 0, 1000, 1.0, null);
Host h4 = createMockedHostWithIops(4, 2, vm4, 1000, 1000, 0.0, null);
double hostFragmentation1 = policy.getHostFragmentation(h1);
double hostFragmentation2 = policy.getHostFragmentation(h2);
......@@ -103,9 +109,8 @@ public class VmAllocationPolicyMigrationSlaTest {
return vm;
}
private Host createMockedHostWithIops(int id, int pesNumber, Vm vm, long availableResource, long iopsCapacity, double iopsUsage) {
private Host createMockedHostWithIops(int id, int pesNumber, Vm vm, long availableResource, long iopsCapacity, double iopsUsage, ResourceProvisioner provisioner) {
Host host = EasyMock.createMock(Host.class);
Iops iops = EasyMock.createMock(Iops.class);
EasyMock.expect(host.getId()).andReturn(id).anyTimes();
EasyMock.expect(host.getNumberOfPes()).andReturn((long) pesNumber).anyTimes();
......@@ -119,6 +124,7 @@ public class VmAllocationPolicyMigrationSlaTest {
EasyMock.expect(host.getIops()).andReturn(iops).anyTimes();
EasyMock.expect(host.getBw()).andReturn(new Bandwidth(HOST_BW)).anyTimes();
EasyMock.expect(host.getNumberOfWorkingPes()).andReturn((long) 2).anyTimes();
EasyMock.expect(host.getIopsProvisioner()).andReturn(provisioner).anyTimes();
List<Vm> vms = new ArrayList<Vm>();
vms.add(vm);
......@@ -139,13 +145,25 @@ public class VmAllocationPolicyMigrationSlaTest {
return datacenter;
}
private Iops createMockedIopsResource(long capacity) {
Iops iops = EasyMock.createMock(Iops.class);
EasyMock.expect(iops).andReturn(new Iops(capacity)).anyTimes();
EasyMock.replay(iops);
return iops;
@Test
public void getHostsWithTightSla_test(){
List<Host> hosts = new ArrayList<Host>();
final int NUM_HEAVEN_HOSTS = 50;
for(int i = 0; i < NUM_HEAVEN_HOSTS; i++){
hosts.add(createMockedHost(i, 0, null, new ResourceProvisionerSimple()));
System.out.println("#"+i);
}
final int NUM_HELL_HOSTS = 150;
for(int i = NUM_HEAVEN_HOSTS; i < NUM_HEAVEN_HOSTS+NUM_HELL_HOSTS; i++){
hosts.add(createMockedHost(i, 0, null, new ResourceProvisionerShared()));
System.out.println("*"+i);
}
Datacenter dc = createMockedDatacenter(hosts);
policy.setDatacenter(dc);
assertEquals(NUM_HEAVEN_HOSTS, policy.getHostsWithLooseSla().size());
assertEquals(NUM_HELL_HOSTS, policy.getHostsWithTightSla().size());
}
}
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