Class DatacenterBrokerAbstract

java.lang.Object
org.cloudbus.cloudsim.core.CloudSimEntity
org.cloudbus.cloudsim.brokers.DatacenterBrokerAbstract
All Implemented Interfaces:
Cloneable, Comparable<SimEntity>, Runnable, DatacenterBroker, Identifiable, Nameable, SimEntity
Direct Known Subclasses:
DatacenterBrokerSimple

public abstract class DatacenterBrokerAbstract extends CloudSimEntity implements DatacenterBroker
An abstract class for implementing DatacenterBrokers.
Author:
Rodrigo N. Calheiros, Anton Beloglazov, Manoel Campos da Silva Filho
  • Constructor Details

    • DatacenterBrokerAbstract

      public DatacenterBrokerAbstract(CloudSim simulation, String name)
      Creates a DatacenterBroker giving a specific name. Subclasses usually should provide this constructor and and overloaded version that just requires the CloudSim parameter.
      Parameters:
      simulation - the CloudSim instance that represents the simulation the Entity is related to
      name - the DatacenterBroker name
  • Method Details

    • setSelectClosestDatacenter

      public final DatacenterBroker setSelectClosestDatacenter(boolean select)
      Description copied from interface: DatacenterBroker
      Defines if the broker has to try selecting the closest Datacenter to place Vms, based on their timezone. The default behaviour is to ignore Datacenters and Vms timezones.
      Specified by:
      setSelectClosestDatacenter in interface DatacenterBroker
      Parameters:
      select - true to try selecting the closest Datacenter to be selected, false to ignore distance
      Returns:
    • isSelectClosestDatacenter

      public boolean isSelectClosestDatacenter()
      Description copied from interface: DatacenterBroker
      Checks if the broker has to try selecting the closest Datacenter to place Vms, based on their timezone. The default behaviour is to ignore Datacenters and Vms timezones.
      Specified by:
      isSelectClosestDatacenter in interface DatacenterBroker
      Returns:
      true if the closest Datacenter selection is enabled, false if it's disabled
      See Also:
    • submitVmList

      public DatacenterBroker submitVmList(List<? extends Vm> list, double submissionDelay)
      Description copied from interface: DatacenterBroker
      Submits a list of Vm or VmGroup 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 the DatacenterBroker.getVmWaitingList().

      When a list of VmGroup is given, it will try to place all VMs from the same group into the same Host.

      Specified by:
      submitVmList in interface DatacenterBroker
      Parameters:
      list - the list of VMs to request the creation
      submissionDelay - the delay the broker has to include when requesting the creation of VMs
      Returns:
      See Also:
    • submitVmList

      public DatacenterBroker submitVmList(List<? extends Vm> list)
      Submits a list of Vm or VmGroup that their creation inside a Host will be requested to some Datacenter. The Datacenter that will be chosen to place a VM is determined by the DatacenterBroker.setDatacenterMapper(BiFunction).

      When a list of VmGroup is given, it will try to place all VMs from the same group into the same Host.

      The individual submission delay of VMs inside the group will be ignored. Only the submission delay set for the VmGroup will be considered.

      If the entity already started (the simulation is running), the creation of previously submitted VMs already was requested by the CloudSimEntity.start() method that is called just once. By this way, this method will immediately request the creation of these just submitted VMs in order to allow VM creation after the simulation has started. This avoid the developer to dynamically create brokers just to create VMs or Cloudlets during simulation execution.

      Specified by:
      submitVmList in interface DatacenterBroker
      Parameters:
      list - the list of VMs to request the creation
      Returns:
      See Also:
    • submitVm

      public DatacenterBroker submitVm(Vm vm)
      Description copied from interface: DatacenterBroker
      Submits a single Vm or VmGroup to the broker. When a VmGroup is given, it will try to place all VMs inside it into the same Host.
      Specified by:
      submitVm in interface DatacenterBroker
      Parameters:
      vm - the Vm to be submitted
      Returns:
      See Also:
    • submitCloudlet

      public DatacenterBroker submitCloudlet(Cloudlet cloudlet)
      Description copied from interface: DatacenterBroker
      Submits a single Cloudlet to the broker.
      Specified by:
      submitCloudlet in interface DatacenterBroker
      Parameters:
      cloudlet - the Cloudlet to be submitted
      Returns:
    • submitCloudletList

      public DatacenterBroker submitCloudletList(List<? extends Cloudlet> list, double submissionDelay)
      Description copied from interface: DatacenterBroker
      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 the DatacenterBroker.getCloudletWaitingList(), setting their submission delay to the specified value.
      Specified by:
      submitCloudletList in interface DatacenterBroker
      Parameters:
      list - the list of Cloudlets to request the creation
      submissionDelay - the delay the broker has to include when requesting the creation of Cloudlets
      Returns:
      See Also:
    • submitCloudletList

      public DatacenterBroker submitCloudletList(List<? extends Cloudlet> list, Vm vm)
      Description copied from interface: DatacenterBroker
      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 the DatacenterBroker.getCloudletWaitingList().
      Specified by:
      submitCloudletList in interface DatacenterBroker
      Parameters:
      list - the list of Cloudlets to request the creation
      vm - the VM to which all Cloudlets will be bound to
      Returns:
      See Also:
    • submitCloudletList

      public DatacenterBroker submitCloudletList(List<? extends Cloudlet> list, Vm vm, double submissionDelay)
      Description copied from interface: DatacenterBroker
      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 the DatacenterBroker.getCloudletWaitingList(), setting their submission delay to the specified value.
      Specified by:
      submitCloudletList in interface DatacenterBroker
      Parameters:
      list - the list of Cloudlets to request the creation
      vm - the VM to which all Cloudlets will be bound to
      submissionDelay - the delay the broker has to include when requesting the creation of Cloudlets
      Returns:
      See Also:
    • submitCloudletList

      public DatacenterBroker 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). All cloudlets will be added to the DatacenterBroker.getCloudletWaitingList().

      If the entity already started (the simulation is running), the creation of previously submitted Cloudlets already was requested by the CloudSimEntity.start() method that is called just once. By this way, this method will immediately request the creation of these just submitted Cloudlets if all submitted VMs were already created, in order to allow Cloudlet creation after the simulation has started. This avoid the developer to dynamically create brokers just to create VMs or Cloudlets during simulation execution.

      Specified by:
      submitCloudletList in interface DatacenterBroker
      Parameters:
      list - the list of Cloudlets to request the creation
      Returns:
      See Also:
    • bindCloudletToVm

      public boolean bindCloudletToVm(Cloudlet cloudlet, Vm vm)
      Description copied from interface: DatacenterBroker
      Specifies that an already submitted cloudlet, which is in the waiting list, must run in a specific virtual machine.
      Specified by:
      bindCloudletToVm in interface DatacenterBroker
      Parameters:
      cloudlet - the cloudlet to be bind to a given Vm
      vm - 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)
    • processEvent

      public void processEvent(SimEvent evt)
      Description copied from interface: SimEntity
      Processes events or services that are available for the entity. This method is invoked by the CloudSim class whenever there is an event in the deferred queue, which needs to be processed by the entity.
      Specified by:
      processEvent in interface SimEntity
      Parameters:
      evt - information about the event just happened
    • getVmsNumber

      public int getVmsNumber()
      Description copied from interface: DatacenterBroker
      Gets the total number of VMs submitted to the broker, including created, waiting and failed VMs.
      Specified by:
      getVmsNumber in interface DatacenterBroker
      Returns:
    • requestIdleVmDestruction

      public DatacenterBroker requestIdleVmDestruction(Vm vm)
      Description copied from interface: DatacenterBroker
      Checks if a VM is idle VM and request it to be destroyed at the time defined by the DatacenterBroker.getVmDestructionDelayFunction(). The request will be sent if the given delay function returns a value greater than DatacenterBroker.DEF_VM_DESTRUCTION_DELAY. Otherwise, it doesn't send the request, meaning the VM should not be destroyed according to a specific delay.
      Specified by:
      requestIdleVmDestruction in interface DatacenterBroker
      Parameters:
      vm - the VM to destroy
      Returns:
      See Also:
    • requestShutdownWhenIdle

      public void requestShutdownWhenIdle()
      Description copied from interface: DatacenterBroker
      Requests the broker shutdown if it's idle.
      Specified by:
      requestShutdownWhenIdle in interface DatacenterBroker
    • destroyVm

      public List<Cloudlet> destroyVm(Vm vm)
      Description copied from interface: DatacenterBroker
      Destroys the passed VM.
      Specified by:
      destroyVm in interface DatacenterBroker
      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.
    • requestDatacentersToCreateWaitingCloudlets

      protected void requestDatacentersToCreateWaitingCloudlets()
      Request Datacenters to create the Cloudlets in the Cloudlets waiting list. If there aren't available VMs to host all cloudlets, the creation of some ones will be postponed.

      This method is called after all submitted VMs are created in some Datacenter.

      See Also:
    • shutdown

      public void shutdown()
      Description copied from interface: SimEntity
      Shuts down the entity. This method is invoked by the CloudSim before the simulation finishes. If you want to save data in log files this is the method in which the corresponding code would be placed.
      Specified by:
      shutdown in interface SimEntity
      Overrides:
      shutdown in class CloudSimEntity
    • startInternal

      public void startInternal()
      Description copied from class: CloudSimEntity
      Defines the logic to be performed by the entity when the simulation starts.
      Specified by:
      startInternal in class CloudSimEntity
    • getVmCreatedList

      public <T extends Vm> List<T> getVmCreatedList()
      Description copied from interface: DatacenterBroker
      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.
      Specified by:
      getVmCreatedList in interface DatacenterBroker
      Type Parameters:
      T - the class of VMs inside the list
      Returns:
      the list of created VMs
      See Also:
    • getVmExecList

      public <T extends Vm> List<T> getVmExecList()
      Description copied from interface: DatacenterBroker
      Gets the list of VMs in execution, if they are running Cloudlets or not. These VMs can receive new submitted Cloudlets.
      Specified by:
      getVmExecList in interface DatacenterBroker
      Type Parameters:
      T - the class of VMs inside the list
      Returns:
      the list of running VMs
      See Also:
    • getVmWaitingList

      public <T extends Vm> List<T> getVmWaitingList()
      Description copied from interface: DatacenterBroker
      Gets a List of VMs submitted to the broker that are waiting to be created inside some Datacenter yet.
      Specified by:
      getVmWaitingList in interface DatacenterBroker
      Type Parameters:
      T - the class of VMs inside the list
      Returns:
      the list of waiting VMs
    • getWaitingVm

      public Vm getWaitingVm(int index)
      Description copied from interface: DatacenterBroker
      Gets a VM from the waiting list.
      Specified by:
      getWaitingVm in interface DatacenterBroker
      Parameters:
      index - the index of the VM to get
      Returns:
      the waiting VM
    • getCloudletCreatedList

      public List<Cloudlet> getCloudletCreatedList()
      Description copied from interface: DatacenterBroker
      Gets a read-only list of cloudlets created inside some Vm.
      Specified by:
      getCloudletCreatedList in interface DatacenterBroker
      Returns:
      the list of created Cloudlets
    • getCloudletWaitingList

      public <T extends Cloudlet> List<T> getCloudletWaitingList()
      Description copied from interface: DatacenterBroker
      Gets the list of cloudlets submitted to the broker that are waiting to be created inside some Vm yet.
      Specified by:
      getCloudletWaitingList in interface DatacenterBroker
      Type Parameters:
      T - the class of Cloudlets inside the list
      Returns:
      the cloudlet waiting list
    • getCloudletFinishedList

      public <T extends Cloudlet> List<T> getCloudletFinishedList()
      Description copied from interface: DatacenterBroker
      Gets a copy of the list of cloudlets that have finished executing, to avoid the original list to be changed.
      Specified by:
      getCloudletFinishedList in interface DatacenterBroker
      Type Parameters:
      T - the class of Cloudlets inside the list
      Returns:
      the list of finished cloudlets
    • getVmFromCreatedList

      protected Vm getVmFromCreatedList(int vmIndex)
      Gets a Vm at a given index from the list of created VMs.
      Parameters:
      vmIndex - the index where a VM has to be got from the created VM list
      Returns:
      the VM at the given index or Vm.NULL if the index is invalid
    • getVmCreationRequests

      protected int getVmCreationRequests()
      Gets the number of VM creation requests.
      Returns:
      the number of VM creation requests
    • getDatacenterList

      protected List<Datacenter> getDatacenterList()
      Gets the list of available datacenters.
      Returns:
      the dc list
    • getDatacenter

      protected Datacenter getDatacenter(Vm vm)
      Gets the Datacenter where a VM is placed.
      Parameters:
      vm - the VM to get its Datacenter
      Returns:
    • setDatacenterMapper

      public final DatacenterBroker setDatacenterMapper(BiFunction<Datacenter,Vm,Datacenter> datacenterMapper)
      Description copied from interface: DatacenterBroker
      Sets the BiFunction 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
      The provided BiFunction is accountable to define when the last used Datacenter will be used for waiting VMs or a next one will be tried.

      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.

      Specified by:
      setDatacenterMapper in interface DatacenterBroker
      Parameters:
      datacenterMapper - the datacenterMapper to set
      Returns:
    • setVmMapper

      public final DatacenterBroker setVmMapper(Function<Cloudlet,Vm> vmMapper)
      Description copied from interface: DatacenterBroker
      Sets a Function 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.
      Specified by:
      setVmMapper in interface DatacenterBroker
      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 return Vm.NULL.
      Returns:
    • setVmComparator

      public DatacenterBroker setVmComparator(Comparator<Vm> comparator)
      Sets a Comparator 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.

      If null is given, VMs won't be sorted and follow submission order.

      Specified by:
      setVmComparator in interface DatacenterBroker
      Parameters:
      comparator - the VM Comparator to set
      Returns:
    • setCloudletComparator

      public void setCloudletComparator(Comparator<Cloudlet> comparator)
      Sets a Comparator 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.

      If null is given, Cloudlets won't be sorted and follow submission order.

      Specified by:
      setCloudletComparator in interface DatacenterBroker
      Parameters:
      comparator - the Cloudlet Comparator to set
    • addOnVmsCreatedListener

      public DatacenterBroker addOnVmsCreatedListener(EventListener<DatacenterBrokerEventInfo> listener)
      Description copied from interface: DatacenterBroker
      Adds an EventListener 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).
      If all VMs submitted at a given time cannot be created due to lack of suitable Hosts, the event will not be fired for that submission.

      Specified by:
      addOnVmsCreatedListener in interface DatacenterBroker
      Parameters:
      listener - the Listener that will be notified
      Returns:
      See Also:
    • removeOnVmsCreatedListener

      public DatacenterBroker removeOnVmsCreatedListener(EventListener<? extends EventInfo> listener)
      Description copied from interface: DatacenterBroker
      Removes an EventListener to stop it to be notified when VMs in the waiting list are all created.
      Specified by:
      removeOnVmsCreatedListener in interface DatacenterBroker
      Parameters:
      listener - the Listener that will be removed
      Returns:
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getVmDestructionDelayFunction

      public Function<Vm,Double> getVmDestructionDelayFunction()
      Description copied from interface: DatacenterBroker
      Gets a Function which defines when an idle VM should be destroyed. The Function receives a Vm and returns the delay to wait (in seconds), after the VM becomes idle, to destroy it.
      Specified by:
      getVmDestructionDelayFunction in interface DatacenterBroker
      Returns:
      See Also:
    • setVmDestructionDelay

      public DatacenterBroker setVmDestructionDelay(double delay)
      Description copied from interface: DatacenterBroker
      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 the DatacenterBroker.setVmDestructionDelayFunction(Function) method.
      Specified by:
      setVmDestructionDelay in interface DatacenterBroker
      Parameters:
      delay - the time (in seconds) to wait before destroying idle VMs
      Returns:
      See Also:
    • setVmDestructionDelayFunction

      public DatacenterBroker setVmDestructionDelayFunction(Function<Vm,Double> function)
      Sets a Function to define the delay after which an idle VM should be destroyed. The Function must receive a Vm 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.

      If null is given, the default VM destruction delay function will be used.

      Specified by:
      setVmDestructionDelayFunction in interface DatacenterBroker
      Parameters:
      function - the Function to set (if null is given, no idle VM will be automatically destroyed)
      Returns:
      See Also:
    • getCloudletSubmittedList

      public List<Cloudlet> getCloudletSubmittedList()
      Specified by:
      getCloudletSubmittedList in interface DatacenterBroker
    • closestDatacenterMapper

      protected Datacenter closestDatacenterMapper(Datacenter lastDatacenter, Vm vm)
      The policy used to select the closest Datacenter to run each waiting VM, according to their timezone offset. This policy is just used if selection of the closest datacenter is enabled.
      Parameters:
      lastDatacenter - the last selected Datacenter
      vm - the VM trying to be created
      Returns:
      the Datacenter selected to request the creating of waiting VMs or Datacenter.NULL if no suitable Datacenter was found
      See Also:
    • defaultDatacenterMapper

      protected abstract Datacenter defaultDatacenterMapper(Datacenter lastDatacenter, Vm vm)
      The default policy used to select a Datacenter to run waiting VMs.
      Parameters:
      lastDatacenter - the last selected Datacenter
      vm - the VM trying to be created
      Returns:
      the Datacenter selected to request the creating of waiting VMs or Datacenter.NULL if no suitable Datacenter was found
      See Also:
    • defaultVmMapper

      protected abstract Vm defaultVmMapper(Cloudlet cloudlet)
      The default policy used to select a VM to execute a given Cloudlet. The method defines the default policy used to map VMs for Cloudlets that are waiting to be created.

      Since this policy can be dynamically changed by calling setVmMapper(Function), this method will always return the default policy provided by the subclass where the method is being called.

      Parameters:
      cloudlet - the cloudlet that needs a VM to execute
      Returns:
      the selected Vm for the cloudlet or Vm.NULL if no suitable VM was found
      See Also:
    • getVmFailedList

      public <T extends Vm> List<T> getVmFailedList()
      Description copied from interface: DatacenterBroker
      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 if retryFailedVms is not enabled.
      Specified by:
      getVmFailedList in interface DatacenterBroker
      Type Parameters:
      T - the class of VMs inside the list
      Returns:
      the list of failed VMs
      See Also:
    • isRetryFailedVms

      public boolean isRetryFailedVms()
      Description copied from interface: DatacenterBroker
      Checks if the broker has to retry allocating VMs that couldn't be placed due to lack of suitable Hosts.
      Specified by:
      isRetryFailedVms in interface DatacenterBroker
      Returns:
    • getFailedVmsRetryDelay

      public double getFailedVmsRetryDelay()
      Description copied from interface: DatacenterBroker
      Gets a delay (in seconds) for the broker to retry allocating VMs that couldn't be placed due to lack of suitable active Hosts.
      Specified by:
      getFailedVmsRetryDelay in interface DatacenterBroker
      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 DatacenterBroker.getVmFailedList() and the user simulation have to deal with it. If the VM has an OnCreationFailureListener, it will be notified about the failure.
    • setFailedVmsRetryDelay

      public void setFailedVmsRetryDelay(double failedVmsRetryDelay)
      Description copied from interface: DatacenterBroker
      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 DatacenterBroker.getVmFailedList() and the user simulation have to deal with it. If the VM has an OnCreationFailureListener, it will be notified about the failure.
      Specified by:
      setFailedVmsRetryDelay in interface DatacenterBroker
    • isShutdownWhenIdle

      public boolean isShutdownWhenIdle()
      Description copied from interface: DatacenterBroker
      Checks if the broker must be shut down after becoming idle.
      Specified by:
      isShutdownWhenIdle in interface DatacenterBroker
      Returns:
    • setShutdownWhenIdle

      public DatacenterBroker setShutdownWhenIdle(boolean shutdownWhenIdle)
      Description copied from interface: DatacenterBroker
      Indicates if the broker must be shut down after becoming idle.
      Specified by:
      setShutdownWhenIdle in interface DatacenterBroker
      Returns: