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