VmAllocationPolicyAbstract

public abstract class VmAllocationPolicyAbstract 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.

Author:Rodrigo N. Calheiros, Anton Beloglazov, Manoel Campos da Silva Filho

Constructors

VmAllocationPolicyAbstract

public VmAllocationPolicyAbstract()

Creates a VmAllocationPolicy.

VmAllocationPolicyAbstract

public VmAllocationPolicyAbstract(BiFunction<VmAllocationPolicy, Vm, Optional<Host>> findHostForVmFunction)

Creates a VmAllocationPolicy, changing the BiFunction to select a Host for a Vm.

Parameters:
  • findHostForVmFunction – a BiFunction to select a Host for a given Vm.

See also: VmAllocationPolicy.setFindHostForVmFunction(BiFunction)

Methods

addPesFromHost

public void addPesFromHost(Host host)

Gets the number of working PEs from a given Host and adds this number to the list of free PEs. Before the Host starts being used, the number of free PEs is the same as the number of working PEs.

addUsedPes

protected void addUsedPes(Vm vm)

Adds number used PEs for a Vm to the map between each VM and the number of PEs used.

Parameters:
  • vm – the VM to add the number of used PEs to the map

allocateHostForVm

public boolean allocateHostForVm(Vm vm)

Allocates the host with less PEs in use for a given VM.

Parameters:
Returns:

{@inheritDoc}

allocateHostForVm

public boolean allocateHostForVm(Vm vm, Host host)

deallocateHostForVm

public void deallocateHostForVm(Vm vm)

getDatacenter

public Datacenter getDatacenter()

getHostFreePesMap

protected final Map<Host, Long> getHostFreePesMap()

Gets a map with the number of free and working PEs for each host from getHostList().

Returns:a Map where each key is a host and each value is the number of free and working PEs of that host.

getHostList

public final <T extends Host> List<T> getHostList()

getOptimizedAllocationMap

public Map<Vm, Host> getOptimizedAllocationMap(List<? extends Vm> vmList)

{@inheritDoc}

This method implementation doesn’t perform any VM placement optimization and, in fact, has no effect. The class provides an actual implementation for this method that can be overridden by subclasses.

Parameters:
Returns:

{@inheritDoc}

removeUsedPes

protected long removeUsedPes(Vm vm)

Removes the used PEs for a Vm from the map between each VM and the number of PEs used.

Parameters:
  • vm
Returns:

the used PEs number

scaleVmVertically

public boolean scaleVmVertically(VerticalVmScaling scaling)

setDatacenter

public final void setDatacenter(Datacenter datacenter)

Sets the Datacenter associated to the Allocation Policy

Parameters:
  • datacenter – the Datacenter to set

setFindHostForVmFunction

public final void setFindHostForVmFunction(BiFunction<VmAllocationPolicy, Vm, Optional<Host>> findHostForVmFunction)

{@inheritDoc} The default implementation of such a Function is provided by the method findHostForVm(Vm).

Parameters:

setHostFreePesMap

protected final VmAllocationPolicy setHostFreePesMap(Map<Host, Long> hostFreePesMap)

Sets the Host free PEs Map.

Parameters:
  • hostFreePesMap – the new Host free PEs map

setUsedPes

protected final void setUsedPes(Map<Vm, Long> usedPes)

Sets the used pes.

Parameters:
  • usedPes – the used pes