Class VmAllocationPolicyAbstract

java.lang.Object
org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicyAbstract
All Implemented Interfaces:
VmAllocationPolicy
Direct Known Subclasses:
VmAllocationPolicyBestFit, VmAllocationPolicyFirstFit, VmAllocationPolicyMigrationAbstract, VmAllocationPolicyRandom, VmAllocationPolicyRoundRobin, VmAllocationPolicySimple

public abstract class VmAllocationPolicyAbstract extends Object implements VmAllocationPolicy
An abstract class that represents the policy used by a Datacenter to choose a Host to place or migrate a given Vm. It supports two-stage commit of reservation of hosts: first, we reserve the Host and, once committed by the customer, the VM is effectively allocated to that Host.

Each Datacenter must to have its own instance of a VmAllocationPolicy.

Since:
CloudSim Toolkit 1.0
Author:
Rodrigo N. Calheiros, Anton Beloglazov, Manoel Campos da Silva Filho
  • Constructor Details

  • Method Details

    • getHostList

      public final <T extends Host> List<T> getHostList()
      Description copied from interface: VmAllocationPolicy
      Gets the list of Hosts available in a Datacenter, that will be used by the Allocation Policy to place VMs.
      Specified by:
      getHostList in interface VmAllocationPolicy
      Type Parameters:
      T - The generic type
      Returns:
      the host list
    • getDatacenter

      public Datacenter getDatacenter()
      Description copied from interface: VmAllocationPolicy
      Gets the Datacenter associated to the VmAllocationPolicy.
      Specified by:
      getDatacenter in interface VmAllocationPolicy
      Returns:
    • setDatacenter

      public void setDatacenter(Datacenter datacenter)
      Sets the Datacenter associated to the Allocation Policy
      Specified by:
      setDatacenter in interface VmAllocationPolicy
      Parameters:
      datacenter - the Datacenter to set
    • scaleVmVertically

      public boolean scaleVmVertically(VerticalVmScaling scaling)
      Description copied from interface: VmAllocationPolicy
      Try to scale some Vm's resource vertically up or down, respectively if:
      • the Vm is overloaded and the Host where the Vm is placed has enough capacity
      • the Vm is underloaded
      The resource to be scaled is defined by the given VerticalVmScaling object.
      Specified by:
      scaleVmVertically in interface VmAllocationPolicy
      Parameters:
      scaling - the VerticalVmScaling object with information of which resource is being requested to be scaled
      Returns:
      true if the requested resource was scaled, false otherwise
    • allocateHostForVm

      public HostSuitability allocateHostForVm(Vm vm)
      Allocates the host with less PEs in use for a given VM.
      Specified by:
      allocateHostForVm in interface VmAllocationPolicy
      Parameters:
      vm - the Vm or VmGroup to allocate a host to
      Returns:
      a HostSuitability to indicate if the Vm was placed into the host or not (if the Host doesn't have enough resources to allocate the Vm)
      See Also:
    • allocateHostForVm

      public <T extends Vm> List<T> allocateHostForVm(Collection<T> vmCollection)
      Description copied from interface: VmAllocationPolicy
      Tries to allocate hosts for a collection of Vms or VmGroups.
      Specified by:
      allocateHostForVm in interface VmAllocationPolicy
      Parameters:
      vmCollection - the Vm or VmGroup collection to allocate hosts to
      Returns:
      an empty list if hosts were allocated to all VMs or a list of Vms that a suitable host couldn't be found.
      See Also:
    • allocateHostForVm

      public HostSuitability allocateHostForVm(Vm vm, Host host)
      Description copied from interface: VmAllocationPolicy
      Tries to allocate a specified host for a given Vm or VmGroup.
      Specified by:
      allocateHostForVm in interface VmAllocationPolicy
      Parameters:
      vm - the Vm or VmGroup to allocate a host to
      host - the host to allocate to the given Vm or VmGroup
      Returns:
      a HostSuitability to indicate if the Vm was placed into the host or not (if the Host doesn't have enough resources to allocate the Vm)
      See Also:
    • deallocateHostForVm

      public void deallocateHostForVm(Vm vm)
      Description copied from interface: VmAllocationPolicy
      Releases the host used by a VM.
      Specified by:
      deallocateHostForVm in interface VmAllocationPolicy
      Parameters:
      vm - the vm to get its host released
    • setFindHostForVmFunction

      public final void setFindHostForVmFunction(BiFunction<VmAllocationPolicy,Vm,Optional<Host>> findHostForVmFunction)
      Sets a BiFunction that selects a Host for a given Vm. This Function receives the current VmAllocationPolicy and the Vm requesting to be place. It then returns an Optional<Host> that may contain a suitable Host for that Vm or not.

      If not Function is set, the default VM selection method provided by implementing classes will be used.

      The default implementation of such a Function is provided by the method findHostForVm(Vm).
      Specified by:
      setFindHostForVmFunction in interface VmAllocationPolicy
      Parameters:
      findHostForVmFunction - the BiFunction to set. Passing null makes the default method to find a Host for a VM to be used.
    • findHostForVm

      public final Optional<Host> findHostForVm(Vm vm)
      Description copied from interface: VmAllocationPolicy
      Finds a suitable host that has enough resources to place a given VM. Internally it may use a default implementation or one set in runtime.
      Specified by:
      findHostForVm in interface VmAllocationPolicy
      Parameters:
      vm - the vm to find a host for it
      Returns:
      an Optional containing a suitable Host to place the VM; or an empty Optional if no suitable Host was found
      See Also:
    • defaultFindHostForVm

      protected abstract Optional<Host> defaultFindHostForVm(Vm vm)
      Provides the default implementation of the policy to find a suitable Host for a given VM.
      Parameters:
      vm - the VM to find a suitable Host to
      Returns:
      an Optional containing a suitable Host to place the VM or an empty Optional if no suitable Host was found
      See Also:
    • getOptimizedAllocationMap

      public Map<Vm,Host> getOptimizedAllocationMap(List<? extends Vm> vmList)
      Description copied from interface: VmAllocationPolicy
      Gets a map of optimized allocation for VMs according to current utilization and Hosts under and overloaded conditions. The conditions that will make a new VM placement map to be proposed and returned is defined by each implementing class.
      Specified by:
      getOptimizedAllocationMap in interface VmAllocationPolicy
      Parameters:
      vmList - the list of VMs to be reallocated
      Returns:
      the new vm placement map, where each key is a VM and each value is the host where such a Vm has to be placed
    • getHostCountForParallelSearch

      public int getHostCountForParallelSearch()
      Description copied from interface: VmAllocationPolicy
      Gets the minimum number of Hosts to start using parallel search.
      Specified by:
      getHostCountForParallelSearch in interface VmAllocationPolicy
      Returns:
    • setHostCountForParallelSearch

      public void setHostCountForParallelSearch(int hostCountForParallelSearch)
      Description copied from interface: VmAllocationPolicy
      Sets the minimum number of Hosts to start using parallel search.
      Specified by:
      setHostCountForParallelSearch in interface VmAllocationPolicy
      Parameters:
      hostCountForParallelSearch - the value to set (use Integer.MAX_VALUE to disable parallel search)
    • isVmMigrationSupported

      public boolean isVmMigrationSupported()
      Description copied from interface: VmAllocationPolicy
      Checks if VM migrations are supported by this VmAllocationPolicy. Realize that even if the policy allows VM migration, such operations can be dynamically enabled/disabled by the Datacenter.
      Specified by:
      isVmMigrationSupported in interface VmAllocationPolicy
      Returns:
      See Also: