Class DatacenterSimple

java.lang.Object
org.cloudsimplus.core.CloudSimEntity
org.cloudsimplus.datacenters.DatacenterSimple
All Implemented Interfaces:
Comparable<SimEntity>, Runnable, Identifiable, Nameable, SimEntity, Sizeable, Datacenter, TimeZoned, PowerAware<PowerModelDatacenter>
Direct Known Subclasses:
NetworkDatacenter

public class DatacenterSimple extends CloudSimEntity implements Datacenter
Implements the basic features of a Virtualized Cloud Datacenter, processing VM queries (i.e., handling of VMs).
Since:
CloudSim Toolkit 1.0
Author:
Rodrigo N. Calheiros, Anton Beloglazov
  • Constructor Details

  • Method Details

    • setupHost

      protected long setupHost(Host host, long nextId)
    • 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 CloudSimPlus class, whenever there is an event in the deferred queue that needs to be processed by the entity.
      Specified by:
      processEvent in interface SimEntity
      Parameters:
      evt - information about the event just happened
    • processPingRequest

      protected void processPingRequest(SimEvent evt)
      Processes a ping request.
      Parameters:
      evt - information about the event just happened
    • processCloudlet

      protected boolean processCloudlet(SimEvent evt, int tag)
      Processes a Cloudlet based on the event type.
      Parameters:
      evt - information about the event just happened
      tag - event tag
      Returns:
      true if the event was processed, false otherwise
    • processCloudletSubmit

      protected boolean processCloudletSubmit(SimEvent evt, boolean ack)
      Processes the submission of a Cloudlet by a DatacenterBroker.
      Parameters:
      evt - information about the event just happened
      ack - indicates if the event's sender expects to receive an acknowledgement
      Returns:
      true if the event was processed, false otherwise
    • getCloudletProcessingUpdateInterval

      protected double getCloudletProcessingUpdateInterval(double nextFinishingCloudletTime)
      Returns the next time Cloudlets processing will be updated (a relative delay from the current simulation time). This is the minimum value between the Datacenter.getSchedulingInterval() and the given time (if the scheduling interval is enabled, i.e., if it's greater than 0), which indicates when the next update of Cloudlets processing has to be performed.
      Parameters:
      nextFinishingCloudletTime - 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
      Returns:
      the next time Cloudlets processing will be updated (a relative delay from the current simulation time)
      See Also:
    • processCloudletResume

      protected boolean processCloudletResume(Cloudlet cloudlet, boolean ack)
      Processes a Cloudlet resume request.
      Parameters:
      cloudlet - cloudlet to be resumed
      ack - indicates if the event's sender expects to receive a confirmation (ack) message
      Returns:
      true to indicate the event was processed
    • processCloudletPause

      protected boolean processCloudletPause(Cloudlet cloudlet, boolean ack)
      Processes a Cloudlet pause request.
      Parameters:
      cloudlet - cloudlet to be paused
      ack - indicates if the event's sender expects to receive a confirmation (ack) message
      Returns:
      true to indicate the event was processed
    • processCloudletCancel

      protected boolean processCloudletCancel(Cloudlet cloudlet)
      Processes a Cloudlet cancel request.
      Parameters:
      cloudlet - cloudlet to be canceled
      Returns:
      true to indicate the event was processed
    • processVmDestroy

      protected boolean processVmDestroy(SimEvent evt)
      Process the event sent by a Broker, requesting the destruction of a given VM created in this Datacenter. This Datacenter may send, upon request, the status back to the Broker.
      Parameters:
      evt - information about the event just happened
      Returns:
      true or false to indicate the event was processed or not
    • finishVmMigration

      protected boolean finishVmMigration(SimEvent evt, boolean ack)
      Finishes the process of migrating a VM.
      Parameters:
      evt - information about the event just happened
      ack - indicates if the event's sender expects to receive a confirmation (ack) message
      Returns:
      true or false to indicate the event was processed or not
      See Also:
    • updateHostsProcessing

      protected double updateHostsProcessing()
      Updates the processing of all Hosts, meaning it makes the processing of VMs running inside such hosts to be updated. Finally, the processing of Cloudlets, running inside such VMs, is updated too.
      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 double updateCloudletProcessing()
      Updates the processing of each Host, that fires the update of VMs, which in turn updates cloudlets running in this Datacenter. After that, the method schedules the next processing update. That is necessary because Hosts and VMs are simple objects, not entities. So, they don't receive events, therefore, updating cloudlets inside them must be called from the outside.
      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: (i) there is no next Cloudlet to execute, or (ii) it isn't time to update the cloudlets.
    • requestVmMigration

      public void requestVmMigration(Vm sourceVm)
      Description copied from interface: Datacenter
      Sends an event to request the migration of a Vm to some suitable Host on this Datacenter. A suitable Host will try to be found when the Datacenter processes the migration request message. If you want VM migrations to be performed automatically, use a VmAllocationPolicyMigration.
      Specified by:
      requestVmMigration in interface Datacenter
      Parameters:
      sourceVm - the VM to be migrated
      See Also:
    • requestVmMigration

      public void requestVmMigration(Vm sourceVm, Host targetHost)
      Description copied from interface: Datacenter
      Sends an event to request the migration of a Vm to a given target Host on this Datacenter. If you want VM migrations to be performed automatically, use a VmAllocationPolicyMigration.
      Specified by:
      requestVmMigration in interface Datacenter
      Parameters:
      sourceVm - the VM to be migrated
      targetHost - the target Host to migrate the VM to
      See Also:
    • shutdown

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

      protected 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
    • getHostList

      public <T extends Host> List<T> getHostList()
      Description copied from interface: Datacenter
      Returns an unmodifiable host list.
      Specified by:
      getHostList in interface Datacenter
      Type Parameters:
      T - The generic type
      Returns:
      an unmodifiable host list
    • getActiveHostStream

      public Stream<? extends Host> getActiveHostStream()
      Specified by:
      getActiveHostStream in interface Datacenter
      Returns:
      a Stream containing the active Hosts inside the Datacenter.
    • setVmAllocationPolicy

      public final Datacenter setVmAllocationPolicy(VmAllocationPolicy vmAllocationPolicy)
      Sets the policy to be used by the Datacenter to allocate Vms into Hosts.
      Parameters:
      vmAllocationPolicy - the new vm allocation policy
      Returns:
      this Datacenter
    • setDatacenterStorage

      public final void setDatacenterStorage(DatacenterStorage datacenterStorage)
      Description copied from interface: Datacenter
      Sets the storage device of the Datacenter.
      Specified by:
      setDatacenterStorage in interface Datacenter
      Parameters:
      datacenterStorage - the new storage
    • setSchedulingInterval

      public final Datacenter setSchedulingInterval(double schedulingInterval)
      Description copied from interface: Datacenter
      Sets the scheduling delay to process each event received by the Datacenter.
      Specified by:
      setSchedulingInterval in interface Datacenter
      Parameters:
      schedulingInterval - the new scheduling interval (in seconds)
      Returns:
      this Datacenter
      See Also:
    • setTimeZone

      public final Datacenter setTimeZone(double timeZone)
      Description copied from interface: TimeZoned
      Sets the time zone offset between [TimeZoned.MIN_TIME_ZONE_OFFSET and TimeZoned.MAX_TIME_ZONE_OFFSET].
      Specified by:
      setTimeZone in interface TimeZoned
      Parameters:
      timeZone - the new time zone offset
      Returns:
      this instance
    • getHost

      public Host getHost(int index)
      Description copied from interface: Datacenter
      Returns a Host in a given position inside the Host List.
      Specified by:
      getHost in interface Datacenter
      Parameters:
      index - the position of the List to get the Host
      Returns:
      a Host in a given position inside the Host List
    • updateActiveHostsNumber

      public void updateActiveHostsNumber(Host host)
      Update the number of active Hosts inside the datacenter
    • size

      public long size()
      Specified by:
      size in interface Datacenter
      Specified by:
      size in interface Sizeable
      Returns:
      the total number of existing Hosts in this Datacenter, which indicates the Datacenter's size.
    • getHostById

      public Host getHostById(long id)
      Description copied from interface: Datacenter
      Gets a Host from its id.
      Specified by:
      getHostById in interface Datacenter
      Parameters:
      id - the ID of the Host to get from the List.
      Returns:
      the Host if found or Host.NULL otherwise
    • addHostList

      public <T extends Host> Datacenter addHostList(List<T> hostList)
      Description copied from interface: Datacenter
      Physically expands the Datacenter by adding a List of new Hosts (physical machines) to it. Hosts can be added before or after the simulation has started. If a Host is added during simulation execution, in case VMs are added dynamically too, they may be allocated to this new Host, depending on the VmAllocationPolicy.

      If an ID is not assigned to a Host, the method assigns one.

      Specified by:
      addHostList in interface Datacenter
      Parameters:
      hostList - the List of new hosts to be added
      Returns:
      this Datacenter
      See Also:
    • addHost

      public <T extends Host> Datacenter addHost(T host)
      Description copied from interface: Datacenter
      Physically expands the Datacenter by adding a new Host (physical machine) to it. Hosts can be added before or after the simulation has started. If a Host is added during simulation execution, in case VMs are added dynamically too, they may be allocated to this new Host, depending on the VmAllocationPolicy.

      If an ID is not assigned to the given Host, the method assigns one.

      Specified by:
      addHost in interface Datacenter
      Parameters:
      host - the new host to be added
      Returns:
      this Datacenter
      See Also:
    • removeHost

      public <T extends Host> Datacenter removeHost(T host)
      Description copied from interface: Datacenter
      Removes a Host from its Datacenter.
      Specified by:
      removeHost in interface Datacenter
      Parameters:
      host - the new host to be removed from its assigned Datacenter
      Returns:
      this Datacenter
    • toString

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

      public void setBandwidthPercentForMigration(double bandwidthPercentForMigration)
      Description copied from interface: Datacenter
      Sets the percentage of the bandwidth allocated to a Host to migrate VMs. It's a value between [0 and 1] (where 1 is 100%). The default value is 0.5, meaning only 50% of the bandwidth will be allowed for migration, while the remaining will be used for VM services.
      Specified by:
      setBandwidthPercentForMigration in interface Datacenter
      Parameters:
      bandwidthPercentForMigration - the bandwidth migration percentage to set
    • addOnHostAvailableListener

      public Datacenter addOnHostAvailableListener(EventListener<HostEventInfo> listener)
      Description copied from interface: Datacenter
      Adds a EventListener object that will be notified every time a new Host is available for the Datacenter during simulation runtime. If the Datacenter.addHost(Host) or Datacenter.addHostList(List) is called before the simulation starts, the listeners will not be notified.
      Specified by:
      addOnHostAvailableListener in interface Datacenter
      Parameters:
      listener - the event listener to add
      Returns:
      this Datacenter
    • addOnVmMigrationFinishListener

      public Datacenter addOnVmMigrationFinishListener(EventListener<DatacenterVmMigrationEventInfo> listener)
      Description copied from interface: Datacenter
      Adds a EventListener object that will be notified every time a VM migration is finished either successfully or not.
      Specified by:
      addOnVmMigrationFinishListener in interface Datacenter
      Parameters:
      listener - the event listener to add
      Returns:
      this Datacenter
    • isMigrationsEnabled

      public boolean isMigrationsEnabled()
      Specified by:
      isMigrationsEnabled in interface Datacenter
      Returns:
      true, if migrations are enabled; false otherwise
    • enableMigrations

      public final Datacenter enableMigrations()
      Description copied from interface: Datacenter
      Enable VM migrations.
      Specified by:
      enableMigrations in interface Datacenter
      Returns:
      this Datacenter
      See Also:
    • disableMigrations

      public final Datacenter disableMigrations()
      Description copied from interface: Datacenter
      Disable VM migrations.
      Specified by:
      disableMigrations in interface Datacenter
      Returns:
      this Datacenter
      See Also:
    • setPowerModel

      public final Datacenter setPowerModel(PowerModelDatacenter powerModel)
      Description copied from interface: PowerAware
      Sets the model defining how the entity consumes power.
      Specified by:
      setPowerModel in interface PowerAware<PowerModelDatacenter>
      Parameters:
      powerModel - the model to set
    • setHostSearchRetryDelay

      public Datacenter setHostSearchRetryDelay(double delay)
      Description copied from interface: Datacenter
      Sets the time interval before trying to find suitable Hosts to migrate VMs from an under or overload Host again.
      Specified by:
      setHostSearchRetryDelay in interface Datacenter
      Parameters:
      delay - the new delay to set (in seconds). Give a positive value to define an actual delay or a negative value to indicate a new Host search for VM migration must be tried as soon as possible
      Returns:
      this Datacenter
    • setCharacteristics

      public Datacenter setCharacteristics(@NonNull @NonNull DatacenterCharacteristics c)
      Description copied from interface: Datacenter
      Sets the Datacenter characteristics.
      Specified by:
      setCharacteristics in interface Datacenter
      Parameters:
      c - the characteristics to set