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.cloudsimplus.core.SimEntity
SimEntity.State -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleA default delay value to indicate that NO VM should be immediately destroyed after becoming idle.static final org.slf4j.Loggerstatic final DatacenterBrokerAn attribute that implements the Null Object Design Pattern forDatacenterBrokerobjects. -
Method Summary
Modifier and TypeMethodDescriptionAdds anEventListenerthat will be notified every time all VMs in the waiting list are created (placed) in some Host.booleanbindCloudletToVm(Cloudlet cloudlet, Vm vm) Specifies that an already submitted cloudlet, which is in thewaiting list, must run in a specific virtual machine.Returns 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.Returns the list of all submitted Cloudlets.Gets the list of cloudlets submitted to the broker that are waiting to be created inside some Vm yet.Returns the last selected datacenter attempted to place arriving VMs.Gets the list of all VMs created so far, independently if they are running yet or were already destroyed.Returns the object that keeps track of the number of VM creation retries sent by the broker and enables configuring creation retries.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.intReturns 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.booleanReturns true if batch VM creation is enabled; false otherwise.booleanChecks if the broker has to try selecting the closestDatacenterto placeVms, based on their timezone.booleanReturns true if the broker must be shut down after becoming idle, false otherwise.removeOnVmsCreatedListener(EventListener<? extends EventInfo> listener) Removes anEventListenerto stop it from being 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 thesetVmDestructionDelayFunction(Function).voidRequests the broker shutdown if it's idle.setBatchVmCreation(boolean enable) Enables or disables batch VM creation.setCloudletComparator(Comparator<Cloudlet> comparator) Sets aComparatorthat will be used to sort every list of submitted Cloudlets before mapping each Cloudlet to a Vm.setDatacenterMapper(BiFunction<Datacenter, Vm, Datacenter> datacenterMapper) Sets theBiFunctionthat selects and returns a Datacenter to place submitted VMs.setLastSelectedDc(Datacenter lastSelectedDc) Changes the last selected datacenter so that new VMs will be attempted to be placed in the given Datacenter instead of the previous one.setSelectClosestDatacenter(boolean select) Defines if the broker has to try selecting the closestDatacenterto placeVms, based on their timezone.setShutdownWhenIdle(boolean shutdownWhenIdle) Indicates if the broker must be shut down after becoming idle.setVmComparator(Comparator<Vm> comparator) Sets aComparatorthat 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(@Nullable Function<Vm, Double> function) Sets aFunctionto define the delay after which an idle VM should be destroyed.setVmMapper(Function<Cloudlet, Vm> vmMapper) Sets aFunctionthat maps a given Cloudlet to a Vm.submitCloudlet(Cloudlet cloudlet) Submits a singleCloudletto the broker so that it requests their creation inside some VM.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 ofVmorVmGroupwhere their creation inside a Host will be requested to someDatacenter.submitVmList(List<? extends Vm> list, double submissionDelay) Methods inherited from interface java.lang.Comparable
compareToMethods inherited from interface org.cloudsimplus.core.Identifiable
getIdMethods inherited from interface org.cloudsimplus.core.SimEntity
getShutdownTime, getSimulation, getStartTime, getState, isAlive, isFinished, isStarted, processEvent, run, schedule, schedule, schedule, schedule, schedule, schedule, schedule, setName, setState, shutdown, start
-
Field Details
-
LOGGER
static final org.slf4j.Logger LOGGER -
NULL
An attribute that implements the Null Object Design Pattern forDatacenterBrokerobjects. -
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.- See Also:
-
-
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
-
getCloudletFinishedList
-
getWaitingVm
Gets a VM from the waiting list.- Parameters:
index- the index of the VM to get- Returns:
- the waiting VM
-
getVmWaitingList
-
getVmExecList
-
getVmsNumber
int getVmsNumber()Returns the total number of VMs submitted to the broker, including created, waiting and failed VMs.- Returns:
- the total number of VMs submitted to the broker, including created, waiting and failed VMs
-
requestIdleVmDestruction
Checks if a VM is idle VM and request it to be destroyed at the time defined by thesetVmDestructionDelayFunction(Function). 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:
- this broker instance
- See Also:
-
requestShutdownWhenIdle
void requestShutdownWhenIdle()Requests the broker shutdown if it's idle. -
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
-
submitVmList
Submits a list ofVmorVmGroupwhere 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
VmGroupis given, it will try to place all VMs from the group into the same Host. -
submitVmList
Submits a list ofVmorVmGroupto 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
VmGroupis given, it will try to place all VMs from the group into the same Host. -
submitCloudlet
Submits a singleCloudletto the broker so that it requests their creation inside some VM.- Parameters:
cloudlet- the Cloudlet to be submitted- Returns:
- this broker instance
- See Also:
-
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:
- this broker instance
- 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:
- this broker instance
- 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:
- this broker instance
- 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:
- this broker instance
- See Also:
-
setDatacenterMapper
Sets theBiFunctionthat 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. That Function receives as parameter the last selected Datacenter and the VM trying to be created, then it should return either:
- the Datacenter for the next VMs in the waiting list
- or
Datacenter.NULLif 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: (i) a Datacenter was never selected to place VMs or (ii) the previous selected Datacenter has not enough resources for all the waiting VMs. The Function you provide here should consider it when returning the Datacenter where the creation of waiting VMs will be tried.- Parameters:
datacenterMapper- the datacenterMapper to set- Returns:
- this broker instance
-
setVmComparator
Sets aComparatorthat 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:
- this broker instance
-
setCloudletComparator
Sets aComparatorthat 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- Returns:
- this broker instance
-
setVmMapper
Sets aFunctionthat maps a given Cloudlet to a Vm. It defines the policy used to select a Vm to run 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 run. If the Function is unable to find a VM for a Cloudlet, it must returnVm.NULL.- Returns:
- this broker instance
-
setSelectClosestDatacenter
Defines if the broker has to try selecting the closestDatacenterto placeVms, based on their timezone. The default behaviour is to ignoreDatacenters andVms timezones.- Parameters:
select- true to try selecting the closest Datacenter, false to ignore distance- Returns:
- this broker instance
-
isSelectClosestDatacenter
boolean isSelectClosestDatacenter()Checks if the broker has to try selecting the closestDatacenterto placeVms, based on their timezone. The default behaviour is to ignoreDatacenters andVms timezones.- Returns:
- true if the closest Datacenter selection is enabled, false if it's disabled
- See Also:
-
getCloudletCreatedList
-
addOnVmsCreatedListener
Adds anEventListenerthat will be notified every time all VMs in the waiting list are 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:
- this broker instance
- See Also:
-
removeOnVmsCreatedListener
Removes anEventListenerto stop it from being notified when VMs in the waiting list are all created.- Parameters:
listener- the Listener that will be removed- Returns:
- this broker instance
- 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. A negative value indicates that NO VM should be immediately destroyed after becoming idle- Returns:
- this broker instance
- See Also:
-
setVmDestructionDelayFunction
Sets aFunctionto define the delay after which an idle VM should be destroyed. The Function must receive aVmand return the delay to wait (in seconds), after the VM becomes idle, to destroy it.By providing a
Functionto indicate 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 than the
Simulation.getMinTimeBetweenEvents()to ensure VMs are gracefully shutdown.- Parameters:
function- theFunctionto set (if null is given, no idle VM will be automatically destroyed)- Returns:
- this broker instance
- 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 ifVmCreation.isRetryFailedVms()is not enabled.- Type Parameters:
T- the class of VMs inside the list- Returns:
- the list of failed VMs
- See Also:
-
isShutdownWhenIdle
boolean isShutdownWhenIdle()Returns true if the broker must be shut down after becoming idle, false otherwise.- Returns:
- true if the broker must be shut down after becoming idle, false otherwise
-
setShutdownWhenIdle
Indicates if the broker must be shut down after becoming idle.- Parameters:
shutdownWhenIdle- true to enable shutdown when idle, false to disable- Returns:
- this broker instance
-
getVmCreation
VmCreation getVmCreation()Returns the object that keeps track of the number of VM creation retries sent by the broker and enables configuring creation retries.- Returns:
- the object that keeps track of the number of VM creation retries sent by the broker and enables configuring creation retries
-
setLastSelectedDc
Changes the last selected datacenter so that new VMs will be attempted to be placed in the given Datacenter instead of the previous one.- Parameters:
lastSelectedDc- the new Datacenter to try to place next arriving VMs- Returns:
- this broker instance
-
getLastSelectedDc
Datacenter getLastSelectedDc()Returns the last selected datacenter attempted to place arriving VMs.- Returns:
- the last selected datacenter attempted to place arriving VMs
-
isBatchVmCreation
boolean isBatchVmCreation()Returns true if batch VM creation is enabled; false otherwise. That indicates if VM creation will be requested to a Datacenter one-by-one or in batch (in a single VM creation request).- Returns:
- true if batch VM creation is enabled; false otherwise
-
setBatchVmCreation
Enables or disables batch VM creation.- Parameters:
enable- true of false to enable or disable- Returns:
- this broker instance
- See Also:
-