Interface DatacenterBroker

All Superinterfaces:
Comparable<SimEntity>, Identifiable, Nameable, Runnable, SimEntity
All Known Implementing Classes:
DatacenterBrokerAbstract, DatacenterBrokerBestFit, DatacenterBrokerFirstFit, DatacenterBrokerHeuristic, DatacenterBrokerSimple

public interface DatacenterBroker extends SimEntity
Represents a broker acting on behalf of a cloud customer. It hides VM management such as vm creation, submission of cloudlets to VMs and destruction of VMs.

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
  • Field Details

  • Method Details

    • bindCloudletToVm

      boolean bindCloudletToVm(Cloudlet cloudlet, Vm vm)
      Specifies that an already submitted cloudlet, which is in the waiting list, must run in a specific virtual machine.
      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)
    • getCloudletWaitingList

      <T extends Cloudlet> List<T> 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

      <T extends Cloudlet> List<T> 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

      Vm getWaitingVm(int index)
      Gets a VM from the waiting list.
      Parameters:
      index - the index of the VM to get
      Returns:
      the waiting VM
    • getVmWaitingList

      <T extends Vm> List<T> 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

      <T extends Vm> List<T> 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()
      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

      DatacenterBroker requestIdleVmDestruction(Vm vm)
      Checks if a VM is idle VM and request it to be destroyed at the time defined by the setVmDestructionDelayFunction(Function). The request will be sent if the given delay function returns a value greater than DEF_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

      <T extends Vm> List<T> 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

      DatacenterBroker submitVm(Vm vm)
      Submits a single Vm or VmGroup to the broker. When a VmGroup is given, it will try to place all VMs from the group into the same Host.
      Parameters:
      vm - the Vm or VmGroup to be submitted
      Returns:
      this broker instance
    • submitVmList

      DatacenterBroker submitVmList(List<? extends Vm> list)
      Submits a list of Vm or VmGroup where 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 setDatacenterMapper(BiFunction).

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

      Parameters:
      list - the list of Vm or VmGroup to request the creation
      Returns:
      this broker instance
      See Also:
    • submitVmList

      DatacenterBroker submitVmList(List<? extends Vm> list, double submissionDelay)
      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 getVmWaitingList().

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

      Parameters:
      list - the list of Vm or VmGroup to request the creation
      submissionDelay - the delay the broker has to include when requesting the creation of VMs
      Returns:
      this broker instance
      See Also:
    • submitCloudlet

      DatacenterBroker submitCloudlet(Cloudlet cloudlet)
      Submits a single Cloudlet to 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

      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 getCloudletWaitingList().
      Parameters:
      list - the list of Cloudlets to request the creation
      Returns:
      this broker instance
      See Also:
    • submitCloudletList

      DatacenterBroker 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. Just the Cloudlets that don't have a delay already assigned will have its submission delay changed. All cloudlets will be added to the getCloudletWaitingList(), setting their submission delay to the specified value.
      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:
      this broker instance
      See Also:
    • submitCloudletList

      DatacenterBroker 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). All cloudlets will be added to the getCloudletWaitingList().
      Parameters:
      list - the list of Cloudlets to request the creation
      vm - the VM to which all Cloudlets will be bound to
      Returns:
      this broker instance
      See Also:
    • submitCloudletList

      DatacenterBroker 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. Just the Cloudlets that don't have a delay already assigned will have its submission delay changed. All cloudlets will be added to the getCloudletWaitingList(), setting their submission delay to the specified value.
      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:
      this broker instance
      See Also:
    • setDatacenterMapper

      DatacenterBroker setDatacenterMapper(BiFunction<Datacenter, Vm, Datacenter> datacenterMapper)
      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. 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.NULL if no suitable Datacenter was found
      The provided BiFunction is accountable to define when the last Datacenter will be used for the 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: (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

      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.
      Parameters:
      comparator - the VM Comparator to set
      Returns:
      this broker instance
    • setCloudletComparator

      DatacenterBroker 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.
      Parameters:
      comparator - the Cloudlet Comparator to set
      Returns:
      this broker instance
    • setVmMapper

      DatacenterBroker setVmMapper(Function<Cloudlet,Vm> vmMapper)
      Sets a Function that 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 return Vm.NULL.
      Returns:
      this broker instance
    • setSelectClosestDatacenter

      DatacenterBroker setSelectClosestDatacenter(boolean select)
      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.
      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 closest Datacenter to place Vms, based on their timezone. The default behaviour is to ignore Datacenters and Vms timezones.
      Returns:
      true if the closest Datacenter selection is enabled, false if it's disabled
      See Also:
    • getCloudletCreatedList

      List<Cloudlet> getCloudletCreatedList()
      Returns a read-only list of cloudlets created inside some Vm.
      Returns:
      a read-only list of cloudlets created inside some Vm
    • addOnVmsCreatedListener

      DatacenterBroker addOnVmsCreatedListener(EventListener<DatacenterBrokerEventInfo> listener)
      Adds an EventListener that 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).
      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.

      Parameters:
      listener - the Listener that will be notified
      Returns:
      this broker instance
      See Also:
    • removeOnVmsCreatedListener

      DatacenterBroker removeOnVmsCreatedListener(EventListener<? extends EventInfo> listener)
      Removes an EventListener to 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

      DatacenterBroker setVmDestructionDelay(double delay)
      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 setVmDestructionDelayFunction(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

      DatacenterBroker setVmDestructionDelayFunction(@Nullable @Nullable 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 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 - the Function to set (if null is given, no idle VM will be automatically destroyed)
      Returns:
      this broker instance
      See Also:
    • getCloudletSubmittedList

      List<Cloudlet> getCloudletSubmittedList()
      Returns the list of all submitted Cloudlets.
      Returns:
      the list of all submitted Cloudlets
    • getVmFailedList

      <T extends Vm> List<T> 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 if VmCreation.isRetryFailedVms() is not enabled.
      Type Parameters:
      T - the class of VMs inside the list
      Returns:
      the list of failed VMs
      See Also:
      • invalid reference
        VmCreation#setRetryDelay(double)
    • 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

      DatacenterBroker setShutdownWhenIdle(boolean shutdownWhenIdle)
      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

      DatacenterBroker 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.
      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

      DatacenterBroker setBatchVmCreation(boolean enable)
      Enables or disables batch VM creation.
      Parameters:
      enable - true of false to enable or disable
      Returns:
      this broker instance
      See Also: