Commit cbdf2342 authored by Kaio Oliveira's avatar Kaio Oliveira
Browse files

Update VmAllocationPolicyMigrationSla example

parent 970ef331
...@@ -16,11 +16,13 @@ import org.cloudbus.cloudsim.hosts.Host; ...@@ -16,11 +16,13 @@ import org.cloudbus.cloudsim.hosts.Host;
import org.cloudbus.cloudsim.hosts.HostSimple; import org.cloudbus.cloudsim.hosts.HostSimple;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple; import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.ResourceProvisioner; import org.cloudbus.cloudsim.provisioners.ResourceProvisioner;
import org.cloudbus.cloudsim.provisioners.ResourceProvisionerShared;
import org.cloudbus.cloudsim.provisioners.ResourceProvisionerSimple; import org.cloudbus.cloudsim.provisioners.ResourceProvisionerSimple;
import org.cloudbus.cloudsim.resources.Pe; import org.cloudbus.cloudsim.resources.Pe;
import org.cloudbus.cloudsim.resources.PeSimple; import org.cloudbus.cloudsim.resources.PeSimple;
import org.cloudbus.cloudsim.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudbus.cloudsim.schedulers.cloudlet.CloudletSchedulerTimeShared;
import org.cloudbus.cloudsim.schedulers.vm.VmScheduler; import org.cloudbus.cloudsim.schedulers.vm.VmScheduler;
import org.cloudbus.cloudsim.schedulers.vm.VmSchedulerSpaceShared;
import org.cloudbus.cloudsim.schedulers.vm.VmSchedulerTimeShared; import org.cloudbus.cloudsim.schedulers.vm.VmSchedulerTimeShared;
import org.cloudbus.cloudsim.utilizationmodels.UtilizationModel; import org.cloudbus.cloudsim.utilizationmodels.UtilizationModel;
import org.cloudbus.cloudsim.utilizationmodels.UtilizationModelFull; import org.cloudbus.cloudsim.utilizationmodels.UtilizationModelFull;
...@@ -42,20 +44,20 @@ public class VmAllocationPolicyMigrationSlaExample { ...@@ -42,20 +44,20 @@ public class VmAllocationPolicyMigrationSlaExample {
private static final Double IMPRECISION = 0.001; private static final Double IMPRECISION = 0.001;
private static final int HOSTS = 1; private static final int HOSTS = 1;
private static final int HOST_PES = 8; private static final int HOST_PES = 8;
private static final int VMS = 2; private static final int VMS = 2;
private static final int VM_PES = 4; private static final int VM_PES = 4;
private static final int CLOUDLETS = 4; private static final int CLOUDLETS = 4;
private static final int CLOUDLET_PES = 10; private static final int CLOUDLET_PES = 10;
private static final int CLOUDLET_LENGTH = 10000; private static final int CLOUDLET_LENGTH = 10000;
private final CloudSim simulation; private final CloudSim simulation;
private DatacenterBroker broker0; private DatacenterBroker broker0;
private List<Vm> vmList; private List<Vm> vmList;
private List<Cloudlet> cloudletList; private List<Cloudlet> cloudletList;
private Datacenter datacenter0; private Datacenter datacenter0;
public static void main(String[] args) { public static void main(String[] args) {
new VmAllocationPolicyMigrationSlaExample(); new VmAllocationPolicyMigrationSlaExample();
...@@ -63,91 +65,107 @@ public class VmAllocationPolicyMigrationSlaExample { ...@@ -63,91 +65,107 @@ public class VmAllocationPolicyMigrationSlaExample {
public VmAllocationPolicyMigrationSlaExample() { public VmAllocationPolicyMigrationSlaExample() {
simulation = new CloudSim(); simulation = new CloudSim();
datacenter0 = createDatacenter(); datacenter0 = createDatacenter();
//Creates a broker that is a software acting on behalf a cloud customer to manage his/her VMs and Cloudlets // Creates a broker that is a software acting on behalf a cloud customer to
broker0 = new DatacenterBrokerSimple(simulation); // manage his/her VMs and Cloudlets
broker0 = new DatacenterBrokerSimple(simulation);
vmList = createVms(); vmList = createVms();
cloudletList = createCloudlets(); cloudletList = createCloudlets();
broker0.submitVmList(vmList); broker0.submitVmList(vmList);
broker0.submitCloudletList(cloudletList); broker0.submitCloudletList(cloudletList);
simulation.start(); simulation.start();
final List<Cloudlet> finishedCloudlets = broker0.getCloudletFinishedList(); final List<Cloudlet> finishedCloudlets = broker0.getCloudletFinishedList();
new CloudletsTableBuilder(finishedCloudlets).build(); new CloudletsTableBuilder(finishedCloudlets).build();
} }
/** /**
* Creates a Datacenter and its Hosts. * Creates a Datacenter and its Hosts.
*/ */
private Datacenter createDatacenter() { private Datacenter createDatacenter() {
final List<Host> hostList = new ArrayList<>(HOSTS); final List<Host> hostList = new ArrayList<>(HOSTS);
for(int i = 0; i < HOSTS; i++) { final int hostId = 0;
Host host = createHost();
hostList.add(host); createHosts(LOOSE, HOSTS, hostList, hostId);
} createHosts(TIGHT, HOSTS, hostList, hostId);
final Datacenter dc = new DatacenterSimple(simulation, hostList, new VmAllocationPolicyFirstFit()); final Datacenter dc = new DatacenterSimple(simulation, hostList, new VmAllocationPolicyFirstFit());
return dc; return dc;
} }
private Host createHost() { private void createHosts(String slaExploitationPolicy, int numberOfHeavenHosts, List<Host> hostList, int hostId) {
List<Pe> peList = new ArrayList<>(HOST_PES); for (int i = 0; i < numberOfHeavenHosts; i++) {
//List of Host's CPUs (Processing Elements, PEs) Host host = createHost(slaExploitationPolicy);
for (int i = 0; i < HOST_PES; i++) { hostList.add(host);
peList.add(new PeSimple(1000, new PeProvisionerSimple())); host.setId(i);
} }
}
final long ram = 2048; //in Megabytes
final long bw = 10000; //in Megabits/s private Host createHost(String slaExploitationPolicy) {
final long storage = 1000000; //in Megabytes List<Pe> peList = new ArrayList<>(HOST_PES);
ResourceProvisioner ramProvisioner = new ResourceProvisionerSimple(); // List of Host's CPUs (Processing Elements, PEs)
ResourceProvisioner bwProvisioner = new ResourceProvisionerSimple(); for (int i = 0; i < HOST_PES; i++) {
VmScheduler vmScheduler = new VmSchedulerTimeShared(); peList.add(new PeSimple(1000, new PeProvisionerSimple()));
Host host = new HostSimple(ram, bw, storage, peList); }
host.setRamProvisioner(ramProvisioner).setBwProvisioner(bwProvisioner).setVmScheduler(vmScheduler); final long ram = 2048; // in Megabytes
final long bw = 10000; // in Megabits/s
return host; final long storage = 1000000; // in Megabytes
} final long iops = 20000;
/** ResourceProvisioner ramProvisioner = new ResourceProvisionerSimple();
* Creates a list of VMs. ResourceProvisioner bwProvisioner = new ResourceProvisionerSimple();
*/ VmScheduler vmScheduler = new VmSchedulerSpaceShared();
private List<Vm> createVms() {
final List<Vm> list = new ArrayList<>(VMS); Host host = new HostSimple(ram, iops, bw, storage, peList).setRamProvisioner(ramProvisioner)
for (int i = 0; i < VMS; i++) { .setBwProvisioner(bwProvisioner).setVmScheduler(vmScheduler);
Vm vm =
new VmSimple(i, 1000, VM_PES) switch (slaExploitationPolicy) {
.setRam(512).setBw(1000).setSize(10000) case LOOSE:
.setCloudletScheduler(new CloudletSchedulerTimeShared()); host.setIopsProvisioner(new ResourceProvisionerSimple());
break;
list.add(vm);
} case TIGHT:
host.setIopsProvisioner(new ResourceProvisionerShared());
return list; break;
} }
/** return host;
* Creates a list of Cloudlets. }
*/
private List<Cloudlet> createCloudlets() { /**
final List<Cloudlet> list = new ArrayList<>(CLOUDLETS); * Creates a list of VMs.
UtilizationModel utilization = new UtilizationModelFull(); */
for (int i = 0; i < CLOUDLETS; i++) { private List<Vm> createVms() {
Cloudlet cloudlet = final List<Vm> list = new ArrayList<>(VMS);
new CloudletSimple(i, CLOUDLET_LENGTH, CLOUDLET_PES) for (int i = 0; i < VMS; i++) {
.setFileSize(1024) Vm vm = new VmSimple(i, 1000, VM_PES).setRam(512).setBw(1000).setSize(10000)
.setOutputSize(1024) .setCloudletScheduler(new CloudletSchedulerTimeShared());
.setUtilizationModel(utilization);
list.add(cloudlet); list.add(vm);
} }
return list; return list;
} }
/**
* Creates a list of Cloudlets.
*/
private List<Cloudlet> createCloudlets() {
final List<Cloudlet> list = new ArrayList<>(CLOUDLETS);
UtilizationModel utilization = new UtilizationModelFull();
for (int i = 0; i < CLOUDLETS; i++) {
Cloudlet cloudlet = new CloudletSimple(i, CLOUDLET_LENGTH, CLOUDLET_PES).setFileSize(1024)
.setOutputSize(1024).setUtilizationModel(utilization);
list.add(cloudlet);
}
return list;
}
} }
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