Class CloudletSchedulerAbstract

java.lang.Object
org.cloudbus.cloudsim.schedulers.cloudlet.CloudletSchedulerAbstract
All Implemented Interfaces:
Serializable, CloudletScheduler
Direct Known Subclasses:
CloudletSchedulerSpaceShared, CloudletSchedulerTimeShared

public abstract class CloudletSchedulerAbstract
extends Object
implements CloudletScheduler
Implements the basic features of a CloudletScheduler, representing the policy of scheduling performed by a virtual machine to run its Cloudlets. So, classes extending this must execute Cloudlets. The interface for cloudlet management is also implemented in this class. Each VM has to have its own instance of a CloudletScheduler.
Since:
CloudSim Toolkit 1.0
Author:
Rodrigo N. Calheiros, Anton Beloglazov, Manoel Campos da Silva Filho
See Also:
Serialized Form
  • Constructor Details

    • CloudletSchedulerAbstract

      protected CloudletSchedulerAbstract()
      Creates a new CloudletScheduler object.
  • Method Details

    • getPreviousTime

      public double getPreviousTime()
      Description copied from interface: CloudletScheduler
      Gets the previous time when the scheduler updated the processing of cloudlets it is managing.
      Specified by:
      getPreviousTime in interface CloudletScheduler
      Returns:
      the previous time
    • setPreviousTime

      protected final void setPreviousTime​(double previousTime)
      Sets the previous time when the scheduler updated the processing of cloudlets it is managing.
      Parameters:
      previousTime - the new previous time
    • getCurrentMipsShare

      public MipsShare getCurrentMipsShare()
      Gets current MIPS capacity from the VM that will be made available to the scheduler. This MIPS share will be allocated to Cloudlets as requested.
      Returns:
      the current MIPS share, where each item represents the MIPS capacity of a Pe which is available to the scheduler.
    • setCurrentMipsShare

      protected void setCurrentMipsShare​(MipsShare currentMipsShare)
      Sets current MIPS share available for the VM using the scheduler.
      Parameters:
      currentMipsShare - the new current MIPS share
      See Also:
      getCurrentMipsShare()
    • getAvailableMipsByPe

      public double getAvailableMipsByPe()
      Gets the amount of MIPS available (free) for each Processor PE, considering the currently executing cloudlets in this processor and the number of PEs these cloudlets require. This is the amount of MIPS that each Cloudlet is allowed to used, considering that the processor is shared among all executing cloudlets.

      In the case of space shared schedulers, there is no concurrency for PEs because some cloudlets may wait in a queue until there is available PEs to be used exclusively by them.

      Returns:
      the amount of available MIPS for each Processor PE.
      To do something:
      Splitting the capacity of a CPU core among different applications is not in fact possible. This was just an oversimplification performed by the CloudletSchedulerTimeShared that may affect other schedulers such as the CloudletSchedulerCompletelyFair, which in fact performs task preemption.
    • getCloudletExecList

      public List<CloudletExecution> getCloudletExecList()
      Description copied from interface: CloudletScheduler
      Gets a read-only List of cloudlets being executed on the VM.
      Specified by:
      getCloudletExecList in interface CloudletScheduler
      Returns:
      the cloudlet execution list
    • addCloudletToWaitingList

      protected void addCloudletToWaitingList​(CloudletExecution cle)
    • getCloudletPausedList

      protected List<CloudletExecution> getCloudletPausedList()
      Gets the list of paused cloudlets.
      Returns:
      the cloudlet paused list
    • getCloudletFinishedList

      public List<CloudletExecution> getCloudletFinishedList()
      Description copied from interface: CloudletScheduler
      Gets a list of finished cloudlets.
      Specified by:
      getCloudletFinishedList in interface CloudletScheduler
      Returns:
      the cloudlet finished list
    • getCloudletFailedList

      protected List<CloudletExecution> getCloudletFailedList()
      Gets the list of failed cloudlets.
      Returns:
      the cloudlet failed list.
    • getCloudletWaitingList

      public List<CloudletExecution> getCloudletWaitingList()
      Description copied from interface: CloudletScheduler
      Gets a read-only List of cloudlet waiting to be executed on the VM.
      Specified by:
      getCloudletWaitingList in interface CloudletScheduler
      Returns:
      the cloudlet waiting list
    • sortCloudletWaitingList

      protected void sortCloudletWaitingList​(Comparator<CloudletExecution> comparator)
      Sorts the cloudletWaitingList using a given Comparator.
      Parameters:
      comparator - the Comparator to sort the Waiting Cloudlets List
    • cloudletSubmit

      public final double cloudletSubmit​(Cloudlet cloudlet)
      Description copied from interface: CloudletScheduler
      Receives an cloudlet to be executed in the VM managed by this scheduler.
      Specified by:
      cloudletSubmit in interface CloudletScheduler
      Parameters:
      cloudlet - the submitted cloudlet
      Returns:
      expected finish time of this cloudlet (considering the time to transfer required files from the Datacenter to the Vm), or 0 if it is in a waiting queue
    • cloudletSubmit

      public final double cloudletSubmit​(Cloudlet cloudlet, double fileTransferTime)
      Description copied from interface: CloudletScheduler
      Receives a cloudlet to be executed in the VM managed by this scheduler.
      Specified by:
      cloudletSubmit in interface CloudletScheduler
      Parameters:
      cloudlet - the submitted cloudlet
      fileTransferTime - time required to move the required files from the SAN to the VM
      Returns:
      expected finish time of this cloudlet (considering the time to transfer required files from the Datacenter to the Vm), or 0 if it is in a waiting queue
    • cloudletSubmitInternal

      protected double cloudletSubmitInternal​(CloudletExecution cle, double fileTransferTime)
      Receives the execution information of a Cloudlet to be executed in the VM managed by this scheduler.
      Parameters:
      cle - the submitted cloudlet
      fileTransferTime - time required to move the required files from the SAN to the VM
      Returns:
      expected finish time of this cloudlet (considering the time to transfer required files from the Datacenter to the Vm), or 0 if it is in a waiting queue
      See Also:
      cloudletSubmit(Cloudlet, double)
    • addCloudletToExecList

      protected void addCloudletToExecList​(CloudletExecution cle)
      Adds a Cloudlet to the list of cloudlets in execution.
      Parameters:
      cle - the Cloudlet to be added
    • hasFinishedCloudlets

      public boolean hasFinishedCloudlets()
      Description copied from interface: CloudletScheduler
      Informs if there is any cloudlet that finished to execute in the VM managed by this scheduler.
      Specified by:
      hasFinishedCloudlets in interface CloudletScheduler
      Returns:
      $true if there is at least one finished cloudlet; $false otherwise
    • findCloudletInAllLists

      protected Optional<CloudletExecution> findCloudletInAllLists​(double cloudletId)
      Search for a Cloudlet into all Cloudlet lists.
      Parameters:
      cloudletId - the id of the Cloudlet to search for
      Returns:
      an Optional value that is able to indicate if the Cloudlet was found or not
    • findCloudletInList

      protected Optional<CloudletExecution> findCloudletInList​(Cloudlet cloudlet, List<CloudletExecution> list)
      Search for a Cloudlet into a given list.
      Parameters:
      cloudlet - the Cloudlet to search for
      list - the list to search the Cloudlet into
      Returns:
      an Optional value that is able to indicate if the Cloudlet was found or not
    • cloudletFinish

      protected void cloudletFinish​(CloudletExecution cle)
      Processes a finished cloudlet.
      Parameters:
      cle - finished cloudlet
    • cloudletReady

      public boolean cloudletReady​(Cloudlet cloudlet)
      Description copied from interface: CloudletScheduler
      Sets the status of a Cloudlet to Cloudlet.Status.READY so that it can start executing as soon as possible.
      Specified by:
      cloudletReady in interface CloudletScheduler
      Parameters:
      cloudlet - the cloudlet to be started
      Returns:
      $true if cloudlet was set to ready, $false otherwise
    • cloudletPause

      public boolean cloudletPause​(Cloudlet cloudlet)
      Description copied from interface: CloudletScheduler
      Pauses execution of a cloudlet.
      Specified by:
      cloudletPause in interface CloudletScheduler
      Parameters:
      cloudlet - the cloudlet being paused
      Returns:
      $true if cloudlet was paused, $false otherwise
    • cloudletFail

      public Cloudlet cloudletFail​(Cloudlet cloudlet)
      Description copied from interface: CloudletScheduler
      Sets a cloudlet as failed.
      Specified by:
      cloudletFail in interface CloudletScheduler
      Parameters:
      cloudlet - ID of the cloudlet to set as failed
      Returns:
      the failed cloudlet or Cloudlet.NULL if not found
    • cloudletCancel

      public Cloudlet cloudletCancel​(Cloudlet cloudlet)
      Description copied from interface: CloudletScheduler
      Cancels execution of a cloudlet.
      Specified by:
      cloudletCancel in interface CloudletScheduler
      Parameters:
      cloudlet - the cloudlet being canceled
      Returns:
      the canceled cloudlet or Cloudlet.NULL if not found
    • updateProcessing

      public double updateProcessing​(double currentTime, MipsShare mipsShare)
      Description copied from interface: CloudletScheduler
      Updates the processing of cloudlets inside the Vm running under management of this scheduler.
      Specified by:
      updateProcessing in interface CloudletScheduler
      Parameters:
      currentTime - current simulation time
      mipsShare - list with MIPS share of each Pe available to the scheduler
      Returns:
      the predicted completion time of the earliest finishing cloudlet (which is a relative delay from the current simulation time), or Double.MAX_VALUE if there is no next Cloudlet to execute
    • updateCloudletProcessing

      protected long updateCloudletProcessing​(CloudletExecution cle, double currentTime)
      Updates the processing of a specific cloudlet of the Vm using this scheduler.
      Parameters:
      cle - The cloudlet to be its processing updated
      currentTime - current simulation time
      Returns:
      the executed length, in Million Instructions (MI), since the last time cloudlet was processed.
    • addOnCloudletResourceAllocationFail

      public CloudletScheduler addOnCloudletResourceAllocationFail​(EventListener<CloudletResourceAllocationFailEventInfo> listener)
      Description copied from interface: CloudletScheduler
      Adds a listener object that will be notified every time a CloudletScheduler is not able to allocated the amount of resource a Cloudlet is requesting due to lack of available capacity.
      Specified by:
      addOnCloudletResourceAllocationFail in interface CloudletScheduler
      Parameters:
      listener - the Listener to add
      Returns:
    • removeOnCloudletResourceAllocationFail

      public boolean removeOnCloudletResourceAllocationFail​(EventListener<CloudletResourceAllocationFailEventInfo> listener)
      Description copied from interface: CloudletScheduler
      Removes a Listener object from the registered List.
      Specified by:
      removeOnCloudletResourceAllocationFail in interface CloudletScheduler
      Parameters:
      listener - the Listener to remove
      Returns:
      true if the Listener was removed, false otherwise
    • timeSpan

      protected double timeSpan​(CloudletExecution cle, double currentTime)
      Computes the time span between the current simulation time and the last time the processing of a cloudlet was updated.
      Parameters:
      cle - the cloudlet to compute the execution time span
      currentTime - the current simulation time
      Returns:
    • removeCloudletFromExecList

      protected CloudletExecution removeCloudletFromExecList​(CloudletExecution cle)
      Removes a Cloudlet from the list of cloudlets in execution.
      Parameters:
      cle - the Cloudlet to be removed
      Returns:
      the removed Cloudlet or CloudletExecution.NULL if not found
    • cloudletEstimatedFinishTime

      protected double cloudletEstimatedFinishTime​(CloudletExecution cle, double currentTime)
      Gets the estimated time when a given cloudlet is supposed to finish executing. It considers the amount of Vm PES and the sum of PEs required by all VMs running inside the VM.
      Parameters:
      cle - cloudlet to get the estimated finish time
      currentTime - current simulation time
      Returns:
      the estimated finish time of the given cloudlet (which is a relative delay from the current simulation time)
    • moveNextCloudletsFromWaitingToExecList

      protected double moveNextCloudletsFromWaitingToExecList​(double currentTime)
      Selects the next Cloudlets in the waiting list to move to the execution list in order to start executing them. While there is enough free PEs, the method try to find a suitable Cloudlet in the list, until it reaches the end of such a list.

      The method might also exchange some cloudlets in the execution list with some in the waiting list. Thus, some running cloudlets may be preempted to give opportunity to previously waiting cloudlets to run. This is a process called context switch. However, each CloudletScheduler implementation decides how such a process is implemented. For instance, Space-Shared schedulers may perform context switch just after the currently running Cloudlets completely finish executing.

      This method is called internally by the CloudletScheduler.updateProcessing(double, MipsShare).

      Parameters:
      currentTime - current simulation time
      Returns:
      the predicted completion time of the earliest finishing cloudlet (which is a relative delay from the current simulation time), or Double.MAX_VALUE if there is no next Cloudlet to execute
    • findSuitableWaitingCloudlet

      protected Optional<CloudletExecution> findSuitableWaitingCloudlet()
      Try to find the first Cloudlet in the waiting list that the number of required PEs is not higher than the number of free PEs.
      Returns:
      an Optional containing the found Cloudlet or an empty Optional otherwise
    • isThereEnoughFreePesForCloudlet

      protected boolean isThereEnoughFreePesForCloudlet​(CloudletExecution cle)
      Checks if the amount of PEs required by a given Cloudlet is free to use.
      Parameters:
      cle - the Cloudlet to get the number of required PEs
      Returns:
      true if there is the amount of free PEs, false otherwise
    • addWaitingCloudletToExecList

      protected CloudletExecution addWaitingCloudletToExecList​(CloudletExecution cle)
      Removes a Cloudlet from waiting list and adds it to the exec list.
      Parameters:
      cle - the cloudlet to add to to exec list
      Returns:
      the given cloudlet
    • getVm

      public Vm getVm()
      Description copied from interface: CloudletScheduler
      Gets the Vm that uses the scheduler.
      Specified by:
      getVm in interface CloudletScheduler
      Returns:
    • setVm

      public void setVm​(Vm vm)
      Description copied from interface: CloudletScheduler
      Sets the Vm that will use the scheduler. It is not required to manually set a Vm for the scheduler, since a Vm sets itself to the scheduler when the scheduler is assigned to the Vm.
      Specified by:
      setVm in interface CloudletScheduler
      Parameters:
      vm - the Vm to set
    • getUsedPes

      public long getUsedPes()
      Description copied from interface: CloudletScheduler
      Gets the number of currently used Pe's.
      Specified by:
      getUsedPes in interface CloudletScheduler
      Returns:
    • getFreePes

      public long getFreePes()
      Gets the number of PEs currently not being used.
      Specified by:
      getFreePes in interface CloudletScheduler
      Returns:
    • getTaskScheduler

      public CloudletTaskScheduler getTaskScheduler()
      Description copied from interface: CloudletScheduler
      Gets the CloudletTaskScheduler that will be used by this CloudletScheduler to process VmPackets to be sent or received by the Vm that is assigned to the current CloudletScheduler.
      Specified by:
      getTaskScheduler in interface CloudletScheduler
      Returns:
      the CloudletTaskScheduler for this CloudletScheduler or CloudletTaskScheduler.NULL if this scheduler will not deal with packets transmission.
    • setTaskScheduler

      public void setTaskScheduler​(CloudletTaskScheduler taskScheduler)
      Description copied from interface: CloudletScheduler
      Sets the CloudletTaskScheduler that will be used by this CloudletScheduler to process VmPackets to be sent or received by the Vm that is assigned to the current CloudletScheduler. The Vm from the CloudletScheduler is also set to the CloudletTaskScheduler.

      This attribute usually doesn't need to be set manually. See the note at the CloudletTaskScheduler interface for more details.

      Specified by:
      setTaskScheduler in interface CloudletScheduler
      Parameters:
      taskScheduler - the CloudletTaskScheduler to set for this CloudletScheduler or CloudletTaskScheduler.NULL if this scheduler will not deal with packets transmission.
    • isThereTaskScheduler

      public boolean isThereTaskScheduler()
      Description copied from interface: CloudletScheduler
      Checks if there is a CloudletTaskScheduler assigned to this CloudletScheduler in order to enable tasks execution and dispatching packets from and to the Vm of this CloudletScheduler.
      Specified by:
      isThereTaskScheduler in interface CloudletScheduler
      Returns:
    • getRequestedCpuPercentUtilization

      public double getRequestedCpuPercentUtilization​(double time)
      Description copied from interface: CloudletScheduler
      Gets total CPU utilization percentage of all cloudlets, according to CPU UtilizationModel of each one (in scale from 0 to 1, where 1 is 100%).
      Specified by:
      getRequestedCpuPercentUtilization in interface CloudletScheduler
      Parameters:
      time - the time to get the current CPU utilization
      Returns:
      the total CPU utilization percentage
    • getRequestedMipsForCloudlet

      protected double getRequestedMipsForCloudlet​(CloudletExecution cle, double time)
      Gets the current requested MIPS for a given cloudlet.
      Parameters:
      cle - the ce
      time - the time
      Returns:
      the current requested mips for the given cloudlet
    • getAllocatedMipsForCloudlet

      public double getAllocatedMipsForCloudlet​(CloudletExecution cle, double time)
      Gets the current allocated MIPS for cloudlet.
      Parameters:
      cle - the ce
      time - the time
      Returns:
      the current allocated mips for cloudlet
    • getCurrentRequestedBwPercentUtilization

      public double getCurrentRequestedBwPercentUtilization()
      Description copied from interface: CloudletScheduler
      /** Gets the current utilization percentage of Bandwidth that the running Cloudlets are requesting (in scale from 0 to 1).
      Specified by:
      getCurrentRequestedBwPercentUtilization in interface CloudletScheduler
      Returns:
      the BW utilization percentage from 0 to 1 (where 1 is 100%)
    • getCurrentRequestedRamPercentUtilization

      public double getCurrentRequestedRamPercentUtilization()
      Description copied from interface: CloudletScheduler
      Gets the current utilization percentage of RAM that the running Cloudlets are requesting (in scale from 0 to 1).
      Specified by:
      getCurrentRequestedRamPercentUtilization in interface CloudletScheduler
      Returns:
      the RAM utilization percentage from 0 to 1 (where 1 is 100%)
    • getCloudletReturnedList

      protected Set<Cloudlet> getCloudletReturnedList()
      Gets a read-only list of Cloudlets that finished executing and were returned the their broker. A Cloudlet is returned to notify the broker about the end of its execution.
      Returns:
    • addCloudletToReturnedList

      public void addCloudletToReturnedList​(Cloudlet cloudlet)
      Description copied from interface: CloudletScheduler
      Adds a Cloudlet to the list of finished Cloudlets that have been returned to its DatacenterBroker.
      Specified by:
      addCloudletToReturnedList in interface CloudletScheduler
      Parameters:
      cloudlet - the Cloudlet to be added
    • deallocatePesFromVm

      public void deallocatePesFromVm​(long pesToRemove)
      Description copied from interface: CloudletScheduler
      Releases a given number of PEs from a VM.
      Specified by:
      deallocatePesFromVm in interface CloudletScheduler
      Parameters:
      pesToRemove - number of PEs to deallocate
    • getCloudletList

      public List<Cloudlet> getCloudletList()
      Description copied from interface: CloudletScheduler
      Gets a read-only List of all cloudlets which are either waiting or executing on the VM.
      Specified by:
      getCloudletList in interface CloudletScheduler
      Returns:
      the list of waiting and executing cloudlets
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: CloudletScheduler
      Checks if there aren't cloudlets waiting or executing inside the Vm.
      Specified by:
      isEmpty in interface CloudletScheduler
      Returns:
      true if there aren't waiting or executing Cloudlets, false otherwise.
    • canExecuteCloudletInternal

      protected abstract boolean canExecuteCloudletInternal​(CloudletExecution cle)
      See Also:
      canExecuteCloudlet(CloudletExecution)
    • clear

      public void clear()
      Description copied from interface: CloudletScheduler
      Clears the internal state of the scheduler
      Specified by:
      clear in interface CloudletScheduler