Interface DatacenterBroker
- All Superinterfaces:
Comparable<SimEntity>
,Identifiable
,Nameable
,Runnable
,SimEntity
- All Known Implementing Classes:
DatacenterBrokerAbstract
,DatacenterBrokerBestFit
,DatacenterBrokerFirstFit
,DatacenterBrokerHeuristic
,DatacenterBrokerSimple
A broker implements the policies for selecting a VM to run a Cloudlet and a Datacenter to run the submitted VMs.
- Since:
- CloudSim Plus 1.0
- Author:
- Rodrigo N. Calheiros, Anton Beloglazov, Manoel Campos da Silva Filho
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.cloudbus.cloudsim.core.SimEntity
SimEntity.State
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final double
A default delay value to indicate that NO VM should be immediately destroyed after becoming idle.static final org.slf4j.Logger
static final DatacenterBroker
An attribute that implements the Null Object Design Pattern forDatacenterBroker
objects. -
Method Summary
Modifier and TypeMethodDescriptionAdds anEventListener
that will be notified every time VMs in the waiting list are all created (placed) in some Host.boolean
bindCloudletToVm
(Cloudlet cloudlet, Vm vm) Specifies that an already submitted cloudlet, which is in thewaiting list
, must run in a specific virtual machine.Destroys the passed VM.Gets a read-only list of cloudlets created inside some Vm.Gets a copy of the list of cloudlets that have finished executing, to avoid the original list to be changed.Gets the list of cloudlets submitted to the broker that are waiting to be created inside some Vm yet.double
Gets a delay (in seconds) for the broker to retry allocating VMs that couldn't be placed due to lack of suitable active Hosts.Gets the list of all VMs created so far, independently if they are running yet or were already destroyed.Gets aFunction
which defines when an idle VM should be destroyed.Gets the list of VMs in execution, if they are running Cloudlets or not.Gets a List of VMs submitted to the broker that have failed to be created inside some Datacenter due to lack of suitable Hosts.int
Gets the total number of VMs submitted to the broker, including created, waiting and failed VMs.Gets a List of VMs submitted to the broker that are waiting to be created inside some Datacenter yet.getWaitingVm
(int index) Gets a VM from the waiting list.boolean
Checks if the broker has to retry allocating VMs that couldn't be placed due to lack of suitable Hosts.boolean
Checks if the broker has to try selecting the closestDatacenter
to placeVm
s, based on their timezone.boolean
Checks if the broker must be shut down after becoming idle.removeOnVmsCreatedListener
(EventListener<? extends EventInfo> listener) Removes anEventListener
to stop it to be notified when VMs in the waiting list are all created.Checks if a VM is idle VM and request it to be destroyed at the time defined by thegetVmDestructionDelayFunction()
.void
Requests the broker shutdown if it's idle.void
setCloudletComparator
(Comparator<Cloudlet> comparator) Sets aComparator
that will be used to sort every list of submitted Cloudlets before mapping each Cloudlet to a Vm.setDatacenterMapper
(BiFunction<Datacenter, Vm, Datacenter> datacenterMapper) Sets theBiFunction
that selects and returns a Datacenter to place submitted VMs.void
setFailedVmsRetryDelay
(double failedVmsRetryDelay) Sets a delay (in seconds) for the broker to retry allocating VMs that couldn't be placed due to lack of suitable active Hosts.setSelectClosestDatacenter
(boolean select) Defines if the broker has to try selecting the closestDatacenter
to placeVm
s, based on their timezone.setShutdownWhenIdle
(boolean shutdownWhenIdle) Indicates if the broker must be shut down after becoming idle.setVmComparator
(Comparator<Vm> comparator) Sets aComparator
that will be used to sort every list of submitted VMs before requesting the creation of such VMs in some Datacenter.setVmDestructionDelay
(double delay) Sets the delay after which an idle VM should be destroyed.setVmDestructionDelayFunction
(Function<Vm, Double> function) Sets aFunction
to define the delay after which an idle VM should be destroyed.setVmMapper
(Function<Cloudlet, Vm> vmMapper) Sets aFunction
that maps a given Cloudlet to a Vm.submitCloudlet
(Cloudlet cloudlet) Submits a singleCloudlet
to the broker.submitCloudletList
(List<? extends Cloudlet> list) Sends a list of cloudlets to the broker so that it requests their creation inside some VM, following the submission delay specified in each cloudlet (if any).submitCloudletList
(List<? extends Cloudlet> list, double submissionDelay) Sends a list of cloudlets to the broker so that it requests their creation inside some VM just after a given delay.submitCloudletList
(List<? extends Cloudlet> list, Vm vm) Sends a list of cloudlets to the broker so that it requests their creation inside a specific VM, following the submission delay specified in each cloudlet (if any).submitCloudletList
(List<? extends Cloudlet> list, Vm vm, double submissionDelay) Sends a list of cloudlets to the broker so that it requests their creation inside a specific VM just after a given delay.submitVmList
(List<? extends Vm> list) Submits a list ofVm
orVmGroup
that their creation inside a Host will be requested to someDatacenter
.submitVmList
(List<? extends Vm> list, double submissionDelay) Methods inherited from interface java.lang.Comparable
compareTo
Methods inherited from interface org.cloudbus.cloudsim.core.Identifiable
getId
Methods inherited from interface org.cloudbus.cloudsim.core.SimEntity
getShutdownTime, getSimulation, getStartTime, getState, isAlive, isFinished, isStarted, processEvent, run, schedule, schedule, schedule, schedule, schedule, schedule, schedule, setName, setSimulation, setState, shutdown, start
-
Field Details
-
LOGGER
static final org.slf4j.Logger LOGGER -
NULL
An attribute that implements the Null Object Design Pattern forDatacenterBroker
objects. -
DEF_VM_DESTRUCTION_DELAY
static final double DEF_VM_DESTRUCTION_DELAYA default delay value to indicate that NO VM should be immediately destroyed after becoming idle.This is used as the value returned by the
getVmDestructionDelayFunction()
if aFunction
is not set.
-
-
Method Details
-
bindCloudletToVm
Specifies that an already submitted cloudlet, which is in thewaiting list
, must run in a specific virtual machine.- Parameters:
cloudlet
- the cloudlet to be bind to a given Vmvm
- the vm to bind the Cloudlet to- Returns:
- true if the Cloudlet was found in the waiting list and was bind to the given Vm; false if the Cloudlet was not found in such a list (that may mean it wasn't submitted yet or was already created)
-
getCloudletWaitingList
Gets the list of cloudlets submitted to the broker that are waiting to be created inside some Vm yet.- Type Parameters:
T
- the class of Cloudlets inside the list- Returns:
- the cloudlet waiting list
-
getCloudletFinishedList
Gets a copy of the list of cloudlets that have finished executing, to avoid the original list to be changed.- Type Parameters:
T
- the class of Cloudlets inside the list- Returns:
- the list of finished cloudlets
-
getWaitingVm
Gets a VM from the waiting list.- Parameters:
index
- the index of the VM to get- Returns:
- the waiting VM
-
getVmWaitingList
Gets a List of VMs submitted to the broker that are waiting to be created inside some Datacenter yet.- Type Parameters:
T
- the class of VMs inside the list- Returns:
- the list of waiting VMs
-
getVmExecList
Gets the list of VMs in execution, if they are running Cloudlets or not. These VMs can receive new submitted Cloudlets.- Type Parameters:
T
- the class of VMs inside the list- Returns:
- the list of running VMs
- See Also:
-
getVmsNumber
int getVmsNumber()Gets the total number of VMs submitted to the broker, including created, waiting and failed VMs.- Returns:
-
requestIdleVmDestruction
Checks if a VM is idle VM and request it to be destroyed at the time defined by thegetVmDestructionDelayFunction()
. The request will be sent if the given delay function returns a value greater thanDEF_VM_DESTRUCTION_DELAY
. Otherwise, it doesn't send the request, meaning the VM should not be destroyed according to a specific delay.- Parameters:
vm
- the VM to destroy- Returns:
- See Also:
-
requestShutdownWhenIdle
void requestShutdownWhenIdle()Requests the broker shutdown if it's idle. -
destroyVm
Destroys the passed VM.- Parameters:
vm
- Virtual machine to be destroyed- Returns:
- Cloudlets which were being queued or running on the target VM. Such cloudlets have their state reset.
-
getVmCreatedList
Gets the list of all VMs created so far, independently if they are running yet or were already destroyed. This can be used at the end of the simulation to know which VMs have executed.- Type Parameters:
T
- the class of VMs inside the list- Returns:
- the list of created VMs
- See Also:
-
submitVm
Submits a singleVm
orVmGroup
to the broker. When aVmGroup
is given, it will try to place all VMs inside it into the same Host.- Parameters:
vm
- the Vm to be submitted- Returns:
- See Also:
-
submitVmList
Submits a list ofVm
orVmGroup
that their creation inside a Host will be requested to someDatacenter
. The Datacenter that will be chosen to place a VM is determined by thesetDatacenterMapper(BiFunction)
.When a list of
VmGroup
is given, it will try to place all VMs from the same group into the same Host.- Parameters:
list
- the list of VMs to request the creation- Returns:
- See Also:
-
submitVmList
Submits a list ofVm
orVmGroup
to the broker so that their creation inside some Host will be requested just after a given delay. Just the VMs that don't have a delay already assigned will have its submission delay changed. All VMs will be added to thegetVmWaitingList()
.When a list of
VmGroup
is given, it will try to place all VMs from the same group into the same Host.- Parameters:
list
- the list of VMs to request the creationsubmissionDelay
- the delay the broker has to include when requesting the creation of VMs- Returns:
- See Also:
-
submitCloudlet
Submits a singleCloudlet
to the broker.- Parameters:
cloudlet
- the Cloudlet to be submitted- Returns:
-
submitCloudletList
Sends a list of cloudlets to the broker so that it requests their creation inside some VM, following the submission delay specified in each cloudlet (if any). All cloudlets will be added to thegetCloudletWaitingList()
.- Parameters:
list
- the list of Cloudlets to request the creation- Returns:
- See Also:
-
submitCloudletList
Sends a list of cloudlets to the broker so that it requests their creation inside some VM just after a given delay. Just the Cloudlets that don't have a delay already assigned will have its submission delay changed. All cloudlets will be added to thegetCloudletWaitingList()
, setting their submission delay to the specified value.- Parameters:
list
- the list of Cloudlets to request the creationsubmissionDelay
- the delay the broker has to include when requesting the creation of Cloudlets- Returns:
- See Also:
-
submitCloudletList
Sends a list of cloudlets to the broker so that it requests their creation inside a specific VM, following the submission delay specified in each cloudlet (if any). All cloudlets will be added to thegetCloudletWaitingList()
.- Parameters:
list
- the list of Cloudlets to request the creationvm
- the VM to which all Cloudlets will be bound to- Returns:
- See Also:
-
submitCloudletList
Sends a list of cloudlets to the broker so that it requests their creation inside a specific VM just after a given delay. Just the Cloudlets that don't have a delay already assigned will have its submission delay changed. All cloudlets will be added to thegetCloudletWaitingList()
, setting their submission delay to the specified value.- Parameters:
list
- the list of Cloudlets to request the creationvm
- the VM to which all Cloudlets will be bound tosubmissionDelay
- the delay the broker has to include when requesting the creation of Cloudlets- Returns:
- See Also:
-
setDatacenterMapper
Sets theBiFunction
that selects and returns a Datacenter to place submitted VMs.It defines the policy to select a Datacenter to host a VM that is waiting to be created. It receives as parameter the last selected Datacenter, the VM trying to be created and should return:
- the Datacenter for the next VMs in the waiting list
- or
Datacenter.NULL
if no suitable Datacenter was found
When there are VMs in the waiting list, the provided Function will be called. If it receives
Datacenter.NULL
it indicates that a Datacenter was never selected to place VMs or the previous selected Datacenter has not enough resources for all the waiting VMs. The Function you provide here should consider that when returning the Datacenter where the creation of waiting VMs will be tried.- Parameters:
datacenterMapper
- the datacenterMapper to set- Returns:
-
setVmComparator
Sets aComparator
that will be used to sort every list of submitted VMs before requesting the creation of such VMs in some Datacenter. After sorting, the VM creation requests will be sent in the order of the sorted VM list.- Parameters:
comparator
- the VM Comparator to set- Returns:
-
setCloudletComparator
Sets aComparator
that will be used to sort every list of submitted Cloudlets before mapping each Cloudlet to a Vm. After sorting, the Cloudlet mapping will follow the order of the sorted Cloudlet list.- Parameters:
comparator
- the Cloudlet Comparator to set
-
setVmMapper
Sets aFunction
that maps a given Cloudlet to a Vm. It defines the policy used to select a Vm to host a Cloudlet that is waiting to be created.- Parameters:
vmMapper
- the Vm mapper Function to set. Such a Function must receive a Cloudlet and return the Vm where it will be placed into. If the Function is unable to find a VM for a Cloudlet, it should returnVm.NULL
.- Returns:
-
setSelectClosestDatacenter
Defines if the broker has to try selecting the closestDatacenter
to placeVm
s, based on their timezone. The default behaviour is to ignoreDatacenter
s andVm
s timezones.- Parameters:
select
- true to try selecting the closest Datacenter to be selected, false to ignore distance- Returns:
-
isSelectClosestDatacenter
boolean isSelectClosestDatacenter()Checks if the broker has to try selecting the closestDatacenter
to placeVm
s, based on their timezone. The default behaviour is to ignoreDatacenter
s andVm
s timezones.- Returns:
- true if the closest Datacenter selection is enabled, false if it's disabled
- See Also:
-
getCloudletCreatedList
Gets a read-only list of cloudlets created inside some Vm.- Returns:
- the list of created Cloudlets
-
addOnVmsCreatedListener
Adds anEventListener
that will be notified every time VMs in the waiting list are all created (placed) in some Host.Events are fired according to the following conditions:
- if all VMs are submitted before the simulation start and all those VMs are created after starting, then the event will be fired just once, in the entire simulation execution time, for every registered Listener;
- if new VMs are submitted during simulation execution, the event may be fired multiple times. For instance, consider new VMs are submitted during simulation execution at times 10 and 20. If for every submission time, all VMs could be created, then every Listener will be notified 2 times (one for VMs submitted at time 10 and other for those at time 20).
- Parameters:
listener
- the Listener that will be notified- Returns:
- See Also:
-
removeOnVmsCreatedListener
Removes anEventListener
to stop it to be notified when VMs in the waiting list are all created.- Parameters:
listener
- the Listener that will be removed- Returns:
- See Also:
-
getVmDestructionDelayFunction
Gets aFunction
which defines when an idle VM should be destroyed. The Function receives aVm
and returns the delay to wait (in seconds), after the VM becomes idle, to destroy it.- Returns:
- See Also:
-
setVmDestructionDelay
Sets the delay after which an idle VM should be destroyed. Using such a method, it defines the same delay for any VM that becomes idle. If you need to define different delays for distinct VMs use thesetVmDestructionDelayFunction(Function)
method.- Parameters:
delay
- the time (in seconds) to wait before destroying idle VMs- Returns:
- See Also:
-
setVmDestructionDelayFunction
Sets aFunction
to define the delay after which an idle VM should be destroyed. The Function must receive aVm
and return the delay to wait (in seconds), after the VM becomes idle, to destroy it.By providing a
Function
to define when idle VMs should be destroyed enables you to define different delays for every VM that becomes idle, according to desired conditions.WARNING: The delay returned by the given function should be larger then the simulation minTimeBetweenEvents to ensure VMs are gracefully shutdown.
- Parameters:
function
- theFunction
to set (if null is given, no idle VM will be automatically destroyed)- Returns:
- See Also:
-
getCloudletSubmittedList
-
getVmFailedList
Gets a List of VMs submitted to the broker that have failed to be created inside some Datacenter due to lack of suitable Hosts. VMs are just moved to that list ifretryFailedVms
is not enabled.- Type Parameters:
T
- the class of VMs inside the list- Returns:
- the list of failed VMs
- See Also:
-
isRetryFailedVms
boolean isRetryFailedVms()Checks if the broker has to retry allocating VMs that couldn't be placed due to lack of suitable Hosts.- Returns:
-
getFailedVmsRetryDelay
double getFailedVmsRetryDelay()Gets a delay (in seconds) for the broker to retry allocating VMs that couldn't be placed due to lack of suitable active Hosts.- Returns:
- a value larger than zero to indicate the broker will retry to place failed VM as soon as new VMs or Cloudlets are submitted or after the given delay.
- otherwise, to indicate failed VMs will be just added to the
getVmFailedList()
and the user simulation have to deal with it. If the VM has anOnCreationFailureListener
, it will be notified about the failure.
-
setFailedVmsRetryDelay
void setFailedVmsRetryDelay(double failedVmsRetryDelay) Sets a delay (in seconds) for the broker to retry allocating VMs that couldn't be placed due to lack of suitable active Hosts. Setting the attribute as:- larger than zero, the broker will retry to place failed VM as soon as new VMs or Cloudlets are submitted or after the given delay.
- otherwise, failed VMs will be just added to the
getVmFailedList()
and the user simulation have to deal with it. If the VM has anOnCreationFailureListener
, it will be notified about the failure.
- Parameters:
failedVmsRetryDelay
-
-
isShutdownWhenIdle
boolean isShutdownWhenIdle()Checks if the broker must be shut down after becoming idle.- Returns:
-
setShutdownWhenIdle
Indicates if the broker must be shut down after becoming idle.- Returns:
-