Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ Common structure of an example (see `BasicFirstExample`):
1. `private static final` constants for host, VM and cloudlet sizes (MIPS, PEs, RAM in MB, BW in Mbps, storage in MB, length in MI).
2. Constructor: `new CloudSimPlus()`, then `createDatacenter()` (`DatacenterSimple` with `HostSimple`s built from `PeSimple`s), then `new DatacenterBrokerSimple(simulation)`.
3. `createVms()` (`VmSimple`) and `createCloudlets()` (`CloudletSimple` + a `UtilizationModel*`), then `broker.submitVmList(...)` and `broker.submitCloudletList(...)`.
4. Optionally register event listeners (e.g. `simulation.addOnClockTickListener`, `vm.addOnHostAllocationListener`) for dynamic behaviour.
4. Optionally register event listeners (e.g. `simulation.addOnClockTickListener`, `vm.addOnHostPlacementListener`) for dynamic behaviour.
5. `simulation.start()`, then print results with `new CloudletsTableBuilder(broker.getCloudletFinishedList()).build()`.

Default policies (VM allocation, VM/cloudlet schedulers, provisioners) apply unless an example sets them on purpose. Usually that choice is the point of the example.
Default policies (VM placement, VM/cloudlet schedulers, allocators) apply unless an example sets them on purpose. Usually that choice is the point of the example.

## Resources

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.cloudsimplus.hosts.Host;
import org.cloudsimplus.hosts.HostSimple;
import org.cloudsimplus.network.topologies.BriteNetworkTopology;
import org.cloudsimplus.provisioners.ResourceProvisionerSimple;
import org.cloudsimplus.allocators.ResourceAllocatorSimple;
import org.cloudsimplus.resources.CoreCapacity;
import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared;
import org.cloudsimplus.utilizationmodels.UtilizationModelFull;
Expand Down Expand Up @@ -130,8 +130,8 @@ private Datacenter createDatacenter() {
long bw = 10000; //Megabits/s

final Host host = new HostSimple(ram, bw, storage, cpuCapacity)
.setRamProvisioner(new ResourceProvisionerSimple())
.setBwProvisioner(new ResourceProvisionerSimple())
.setRamAllocator(new ResourceAllocatorSimple())
.setBwAllocator(new ResourceAllocatorSimple())
.setVmScheduler(new VmSchedulerTimeShared());
hostList.add(host);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.cloudsimplus.network.switches.AggregateSwitch;
import org.cloudsimplus.network.switches.EdgeSwitch;
import org.cloudsimplus.network.switches.RootSwitch;
import org.cloudsimplus.provisioners.ResourceProvisionerSimple;
import org.cloudsimplus.allocators.ResourceAllocatorSimple;
import org.cloudsimplus.resources.CoreCapacity;
import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared;
import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared;
Expand Down Expand Up @@ -171,8 +171,8 @@ protected final NetworkDatacenter createDatacenter() {
final CoreCapacity cpuCapacity = HOST_CAPACITY;
final var host = new NetworkHost(HOST_RAM, HOST_BW, HOST_STORAGE, cpuCapacity);
host
.setRamProvisioner(new ResourceProvisionerSimple())
.setBwProvisioner(new ResourceProvisionerSimple())
.setRamAllocator(new ResourceAllocatorSimple())
.setBwAllocator(new ResourceAllocatorSimple())
.setVmScheduler(new VmSchedulerTimeShared());
netHostList.add(host);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.cloudsimplus.datacenters.network.NetworkDatacenter;
import org.cloudsimplus.hosts.network.NetworkHost;
import org.cloudsimplus.network.switches.EdgeSwitch;
import org.cloudsimplus.provisioners.ResourceProvisionerSimple;
import org.cloudsimplus.allocators.ResourceAllocatorSimple;
import org.cloudsimplus.resources.CoreCapacity;
import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared;
import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared;
Expand Down Expand Up @@ -116,8 +116,8 @@ private NetworkDatacenter createDatacenter() {
private NetworkHost createHost() {
final var host = new NetworkHost(HOST_RAM, HOST_BW, HOST_STORAGE, HOST_CAPACITY);
host
.setRamProvisioner(new ResourceProvisionerSimple())
.setBwProvisioner(new ResourceProvisionerSimple())
.setRamAllocator(new ResourceAllocatorSimple())
.setBwAllocator(new ResourceAllocatorSimple())
.setVmScheduler(new VmSchedulerTimeShared());

return host;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ private Datacenter createDatacenter() {
hostList.add(host);
}

//Uses a VmAllocationPolicySimple by default to allocate VMs
//Uses a VmPlacementPolicySimple by default to place VMs
return new DatacenterSimple(simulation, hostList);
}

private Host createHost() {
/*
Uses ResourceProvisionerSimple by default for RAM and BW provisioning
Uses ResourceAllocatorSimple by default for RAM and BW allocation
and VmSchedulerSpaceShared for VM scheduling.
*/
return new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, HOST_CAPACITY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.cloudsimplus.hosts.Host;
import org.cloudsimplus.hosts.HostSimple;
import org.cloudsimplus.listeners.CloudletVmEventInfo;
import org.cloudsimplus.provisioners.ResourceProvisionerSimple;
import org.cloudsimplus.allocators.ResourceAllocatorSimple;
import org.cloudsimplus.resources.CoreCapacity;
import org.cloudsimplus.schedulers.cloudlet.CloudletScheduler;
import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared;
Expand Down Expand Up @@ -157,13 +157,13 @@ private Host createHost() {
final long ram = 2048; //in Megabytes
final long bw = 10000; //in Megabits/s
final long storage = 1000000; //in Megabytes
final var ramProvisioner = new ResourceProvisionerSimple();
final var bwProvisioner = new ResourceProvisionerSimple();
final var ramAllocator = new ResourceAllocatorSimple();
final var bwAllocator = new ResourceAllocatorSimple();
final var vmScheduler = new VmSchedulerTimeShared();
final var host = new HostSimple(ram, bw, storage, HOST_CAPACITY);
host
.setRamProvisioner(ramProvisioner)
.setBwProvisioner(bwProvisioner)
.setRamAllocator(ramAllocator)
.setBwAllocator(bwAllocator)
.setVmScheduler(vmScheduler);
return host;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ private Datacenter createDatacenter() {
hostList.add(host);
}

//Uses a VmAllocationPolicySimple by default to allocate VMs
//Uses a VmPlacementPolicySimple by default to place VMs
return new DatacenterSimple(simulation, hostList);
}

private Host createHost() {
/*
Uses ResourceProvisionerSimple by default for RAM and BW provisioning
Uses ResourceAllocatorSimple by default for RAM and BW allocation
and VmSchedulerSpaceShared for VM scheduling.
*/
return new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, HOST_CAPACITY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.cloudsimplus.faultinjection.VmClonerSimple;
import org.cloudsimplus.hosts.Host;
import org.cloudsimplus.hosts.HostSimple;
import org.cloudsimplus.provisioners.ResourceProvisionerSimple;
import org.cloudsimplus.allocators.ResourceAllocatorSimple;
import org.cloudsimplus.resources.CoreCapacity;
import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared;
import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared;
Expand Down Expand Up @@ -234,13 +234,13 @@ private Datacenter createDatacenter() {
}

public Host createHost(final int id) {
final var ramProvisioner = new ResourceProvisionerSimple();
final var bwProvisioner = new ResourceProvisionerSimple();
final var ramAllocator = new ResourceAllocatorSimple();
final var bwAllocator = new ResourceAllocatorSimple();
final var vmScheduler = new VmSchedulerTimeShared();
final var host = new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, HOST_CAPACITY);
host
.setRamProvisioner(ramProvisioner)
.setBwProvisioner(bwProvisioner)
.setRamAllocator(ramAllocator)
.setBwAllocator(bwAllocator)
.setVmScheduler(vmScheduler)
.setId(id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
package org.cloudsimplus.examples;

import ch.qos.logback.classic.Level;
import org.cloudsimplus.allocationpolicies.VmAllocationPolicyFirstFit;
import org.cloudsimplus.placementpolicies.VmPlacementPolicyFirstFit;
import org.cloudsimplus.brokers.DatacenterBroker;
import org.cloudsimplus.brokers.DatacenterBrokerSimple;
import org.cloudsimplus.cloudlets.Cloudlet;
Expand Down Expand Up @@ -165,14 +165,14 @@ private Datacenter createDatacenter() {
hostList.add(host);
}

var dc = new DatacenterSimple(simulation, hostList, new VmAllocationPolicyFirstFit());
var dc = new DatacenterSimple(simulation, hostList, new VmPlacementPolicyFirstFit());
dc.setSchedulingInterval(SCHEDULING_INTERVAL);
return dc;
}

private Host createHost() {
/*
Uses ResourceProvisionerSimple by default for RAM and BW provisioning
Uses ResourceAllocatorSimple by default for RAM and BW allocation
and VmSchedulerSpaceShared for VM scheduling.
*/
return new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, HOST_CAPACITY);
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/org/cloudsimplus/examples/LoggingExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
package org.cloudsimplus.examples;

import ch.qos.logback.classic.Level;
import org.cloudsimplus.allocationpolicies.VmAllocationPolicy;
import org.cloudsimplus.allocationpolicies.migration.VmAllocationPolicyMigrationStaticThreshold;
import org.cloudsimplus.placementpolicies.VmPlacementPolicy;
import org.cloudsimplus.placementpolicies.migration.VmPlacementPolicyMigrationStaticThreshold;
import org.cloudsimplus.brokers.DatacenterBroker;
import org.cloudsimplus.brokers.DatacenterBrokerSimple;
import org.cloudsimplus.builders.tables.CloudletsTableBuilder;
Expand Down Expand Up @@ -137,7 +137,7 @@ private void configureLogs() {
//Enable different log levels for specific classes of objects
Log.setLevel(DatacenterBroker.LOGGER, Level.ERROR);
Log.setLevel(Datacenter.LOGGER, Level.WARN);
Log.setLevel(VmAllocationPolicy.LOGGER, Level.OFF);
Log.setLevel(VmPlacementPolicy.LOGGER, Level.OFF);
Log.setLevel(CloudletScheduler.LOGGER, Level.WARN);
}

Expand All @@ -157,12 +157,12 @@ private Datacenter createDatacenter() {
hostList.add(host);
}

/*Creates a VmAllocationPolicy that migrates VMs from under/overloaded hosts,
/*Creates a VmPlacementPolicy that migrates VMs from under/overloaded hosts,
selecting migrating VMs randomly.*/
final var vmAllocationPolicy =
new VmAllocationPolicyMigrationStaticThreshold(
final var vmPlacementPolicy =
new VmPlacementPolicyMigrationStaticThreshold(
new VmSelectionPolicyRandomSelection(), HOST_OVER_UTILIZATION_MIGRATION_THRESHOLD);
final var dc = new DatacenterSimple(simulation, hostList, vmAllocationPolicy);
final var dc = new DatacenterSimple(simulation, hostList, vmPlacementPolicy);
dc.setSchedulingInterval(SCHEDULING_INTERVAL_SECS);
if(DISABLE_MIGRATIONS) {
dc.disableMigrations();
Expand All @@ -175,7 +175,7 @@ private Host createHost(final int pes) {
final var cpuCapacity = new CoreCapacity(pes, HOST_MIPS);

/*
Uses ResourceProvisionerSimple by default for RAM and BW provisioning
Uses ResourceAllocatorSimple by default for RAM and BW allocation
and VmSchedulerSpaceShared for VM scheduling.
*/
return new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, cpuCapacity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import org.cloudsimplus.distributions.UniformDistr;
import org.cloudsimplus.hosts.Host;
import org.cloudsimplus.hosts.HostSimple;
import org.cloudsimplus.provisioners.ResourceProvisionerSimple;
import org.cloudsimplus.allocators.ResourceAllocatorSimple;
import org.cloudsimplus.resources.CoreCapacity;
import org.cloudsimplus.schedulers.vm.VmSchedulerSpaceShared;
import org.cloudsimplus.util.Log;
Expand Down Expand Up @@ -151,8 +151,8 @@ private Host createHost() {
final long bw = 10000; //Megabits/s

return new HostSimple(ram, bw, storage, HOST_CAPACITY)
.setRamProvisioner(new ResourceProvisionerSimple())
.setBwProvisioner(new ResourceProvisionerSimple())
.setRamAllocator(new ResourceAllocatorSimple())
.setBwAllocator(new ResourceAllocatorSimple())
.setVmScheduler(new VmSchedulerSpaceShared());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.cloudsimplus.datacenters.DatacenterSimple;
import org.cloudsimplus.hosts.Host;
import org.cloudsimplus.hosts.HostSimple;
import org.cloudsimplus.provisioners.ResourceProvisionerSimple;
import org.cloudsimplus.allocators.ResourceAllocatorSimple;
import org.cloudsimplus.resources.CoreCapacity;
import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared;
import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared;
Expand Down Expand Up @@ -144,7 +144,7 @@ private List<Host> createHosts() {
return hostList;
}

/// Creates a Hosts using a [ResourceProvisionerSimple]
/// Creates a Hosts using a [ResourceAllocatorSimple]
/// for RAM and BW.
/// @return
private Host createHost() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
*/
package org.cloudsimplus.examples;

import org.cloudsimplus.allocationpolicies.VmAllocationPolicy;
import org.cloudsimplus.allocationpolicies.VmAllocationPolicySimple;
import org.cloudsimplus.placementpolicies.VmPlacementPolicy;
import org.cloudsimplus.placementpolicies.VmPlacementPolicySimple;
import org.cloudsimplus.brokers.DatacenterBroker;
import org.cloudsimplus.brokers.DatacenterBrokerSimple;
import org.cloudsimplus.builders.tables.CloudletsTableBuilder;
Expand All @@ -37,7 +37,7 @@
import org.cloudsimplus.distributions.UniformDistr;
import org.cloudsimplus.hosts.Host;
import org.cloudsimplus.hosts.HostSimple;
import org.cloudsimplus.provisioners.ResourceProvisionerSimple;
import org.cloudsimplus.allocators.ResourceAllocatorSimple;
import org.cloudsimplus.resources.CoreCapacity;
import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared;
import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared;
Expand All @@ -54,18 +54,18 @@
import java.util.Optional;

/// An example showing how to implement a custom
/// [VmAllocationPolicy] that randomly
/// [VmPlacementPolicy] that randomly
/// selects suitable Hosts to place submitted VMs.
/// Check the [#createDatacenter()] method for details.
///
/// Since CloudSim Plus provides functional
/// VmAllocationPolicy implementations, you don't
/// VmPlacementPolicy implementations, you don't
/// even need to create a new class to implement your own policy,
/// unless you really want to (to make reuse easy).
///
/// @author Manoel Campos da Silva Filho
/// @since CloudSim Plus 4.0.5
public class RandomVmAllocationPolicyExample {
public class RandomVmPlacementPolicyExample {
private static final int HOSTS = 10;
private static final int HOST_CORES = 8;

Expand Down Expand Up @@ -102,10 +102,10 @@ public class RandomVmAllocationPolicyExample {
private final ContinuousDistribution random;

public static void main(String[] args) {
new RandomVmAllocationPolicyExample();
new RandomVmPlacementPolicyExample();
}

private RandomVmAllocationPolicyExample() {
private RandomVmPlacementPolicyExample() {
final double startSecs = TimeUtil.currentTimeSecs();
//Enables just some level of log messages.
Log.setLevel(ch.qos.logback.classic.Level.WARN);
Expand All @@ -132,7 +132,7 @@ private RandomVmAllocationPolicyExample() {
}

/// Creates a Datacenter and its Hosts, defining
/// a [VmAllocationPolicy] that randomly selects suitable Hosts
/// a [VmPlacementPolicy] that randomly selects suitable Hosts
/// to place submitted VMs.
private Datacenter createDatacenter() {
final var hostList = new ArrayList<Host>(HOSTS);
Expand All @@ -141,24 +141,24 @@ private Datacenter createDatacenter() {
hostList.add(host);
}

final var vmAllocationPolicy = new VmAllocationPolicySimple();
final var vmPlacementPolicy = new VmPlacementPolicySimple();

//Replaces the default method that allocates Hosts to VMs by our own implementation
vmAllocationPolicy.setFindHostForVmFunction(this::findRandomSuitableHostForVm);
vmPlacementPolicy.setFindHostForVmFunction(this::findRandomSuitableHostForVm);

return new DatacenterSimple(simulation, hostList, vmAllocationPolicy);
return new DatacenterSimple(simulation, hostList, vmPlacementPolicy);
}

/// Define a specific policy to randomly select a suitable Host to place a given VM.
/// It's a very efficient policy since it doesn't perform sorting
/// in order to find a suitable Host.
///
/// @param vmAllocationPolicy the [VmAllocationPolicy] containing Host allocation information
/// @param vmPlacementPolicy the [VmPlacementPolicy] containing VM placement information
/// @param vm the [Vm] to find a host to be placed
/// @return an [Optional] that may contain a Host in which to place a Vm, or an [Optional#empty()]
/// [Optional] if not suitable Host was found.
private Optional<Host> findRandomSuitableHostForVm(final VmAllocationPolicy vmAllocationPolicy, final Vm vm) {
final var hostList = vmAllocationPolicy.getHostList();
private Optional<Host> findRandomSuitableHostForVm(final VmPlacementPolicy vmPlacementPolicy, final Vm vm) {
final var hostList = vmPlacementPolicy.getHostList();
/* Despite the loop is bound to the number of Hosts inside the List,
* the index "i" is not used to get a Host at that position,
* but just to define that the maximum number of tries to find a
Expand All @@ -180,8 +180,8 @@ private Host createHost() {
final long storage = 1000000; //in Megabytes
final var host = new HostSimple(ram, bw, storage, HOST_CAPACITY);
host
.setRamProvisioner(new ResourceProvisionerSimple())
.setBwProvisioner(new ResourceProvisionerSimple())
.setRamAllocator(new ResourceAllocatorSimple())
.setBwAllocator(new ResourceAllocatorSimple())
.setVmScheduler(new VmSchedulerTimeShared());
return host;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/cloudsimplus/examples/ReducedExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ void main() {
final long bw = 100000; //in Megabits/s

//Creates one Hosts with a specific list of CPU cores (PEs).
//Uses ResourceProvisionerSimple by default for RAM and BW provisioning
//Uses ResourceAllocatorSimple by default for RAM and BW allocation
//Uses VmSchedulerSpaceShared by default for VM scheduling
final var host0 = new HostSimple(ram, bw, storage, new CoreCapacity(20000));

//Creates one Datacenter with a list of Hosts
//Uses a VmAllocationPolicySimple by default to allocate VMs
//Uses a VmPlacementPolicySimple by default to place VMs
final var dc0 = new DatacenterSimple(simulation, List.of(host0));

//Creates one Vm to run applications (Cloudlets).
Expand Down
Loading
Loading