Class VmAllocationPolicyAbstract
java.lang.Object
org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicyAbstract
- All Implemented Interfaces:
VmAllocationPolicy
- Direct Known Subclasses:
VmAllocationPolicyBestFit
,VmAllocationPolicyFirstFit
,VmAllocationPolicyMigrationAbstract
,VmAllocationPolicyRandom
,VmAllocationPolicyRoundRobin
,VmAllocationPolicySimple
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
-
Field Summary
Fields inherited from interface org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicy
DEF_HOST_COUNT_PARALLEL_SEARCH, LOGGER, NULL
-
Constructor Summary
ConstructorDescriptionCreates a VmAllocationPolicy.VmAllocationPolicyAbstract
(BiFunction<VmAllocationPolicy, Vm, Optional<Host>> findHostForVmFunction) Creates a VmAllocationPolicy, changing theBiFunction
to select a Host for a Vm. -
Method Summary
Modifier and TypeMethodDescriptionallocateHostForVm
(Collection<T> vmCollection) allocateHostForVm
(Vm vm) Allocates the host with less PEs in use for a given VM.allocateHostForVm
(Vm vm, Host host) void
Releases the host used by a VM.Provides the default implementation of the policy to find a suitable Host for a given VM.findHostForVm
(Vm vm) Finds a suitable host that has enough resources to place a given VM.Gets theDatacenter
associated to the VmAllocationPolicy.int
Gets the minimum number of Hosts to start using parallel search.Gets the list of Hosts available in aDatacenter
, that will be used by the Allocation Policy to place VMs.getOptimizedAllocationMap
(List<? extends Vm> vmList) Gets a map of optimized allocation for VMs according to current utilization and Hosts under and overloaded conditions.boolean
Checks if VM migrations are supported by this VmAllocationPolicy.boolean
scaleVmVertically
(VerticalVmScaling scaling) 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 givenVerticalVmScaling
object.void
setDatacenter
(Datacenter datacenter) Sets the Datacenter associated to the Allocation Policyfinal void
setFindHostForVmFunction
(BiFunction<VmAllocationPolicy, Vm, Optional<Host>> findHostForVmFunction) Sets aBiFunction
that selects a Host for a given Vm.void
setHostCountForParallelSearch
(int hostCountForParallelSearch) Sets the minimum number of Hosts to start using parallel search.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicy
isParallelHostSearchEnabled
-
Constructor Details
-
VmAllocationPolicyAbstract
public VmAllocationPolicyAbstract()Creates a VmAllocationPolicy. -
VmAllocationPolicyAbstract
public VmAllocationPolicyAbstract(BiFunction<VmAllocationPolicy, Vm, Optional<Host>> findHostForVmFunction) Creates a VmAllocationPolicy, changing theBiFunction
to select a Host for a Vm.- Parameters:
findHostForVmFunction
- aBiFunction
to select a Host for a given Vm.- See Also:
-
-
Method Details
-
getHostList
Description copied from interface:VmAllocationPolicy
Gets the list of Hosts available in aDatacenter
, that will be used by the Allocation Policy to place VMs.- Specified by:
getHostList
in interfaceVmAllocationPolicy
- Type Parameters:
T
- The generic type- Returns:
- the host list
-
getDatacenter
Description copied from interface:VmAllocationPolicy
Gets theDatacenter
associated to the VmAllocationPolicy.- Specified by:
getDatacenter
in interfaceVmAllocationPolicy
- Returns:
-
setDatacenter
Sets the Datacenter associated to the Allocation Policy- Specified by:
setDatacenter
in interfaceVmAllocationPolicy
- Parameters:
datacenter
- the Datacenter to set
-
scaleVmVertically
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
VerticalVmScaling
object.- Specified by:
scaleVmVertically
in interfaceVmAllocationPolicy
- Parameters:
scaling
- theVerticalVmScaling
object with information of which resource is being requested to be scaled- Returns:
- true if the requested resource was scaled, false otherwise
-
allocateHostForVm
Allocates the host with less PEs in use for a given VM.- Specified by:
allocateHostForVm
in interfaceVmAllocationPolicy
- Parameters:
vm
- theVm
orVmGroup
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
Description copied from interface:VmAllocationPolicy
- Specified by:
allocateHostForVm
in interfaceVmAllocationPolicy
- Parameters:
vmCollection
- theVm
orVmGroup
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
Description copied from interface:VmAllocationPolicy
- Specified by:
allocateHostForVm
in interfaceVmAllocationPolicy
- Parameters:
vm
- theVm
orVmGroup
to allocate a host tohost
- the host to allocate to the givenVm
orVmGroup
- 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
Description copied from interface:VmAllocationPolicy
Releases the host used by a VM.- Specified by:
deallocateHostForVm
in interfaceVmAllocationPolicy
- Parameters:
vm
- the vm to get its host released
-
setFindHostForVmFunction
public final void setFindHostForVmFunction(BiFunction<VmAllocationPolicy, Vm, Optional<Host>> findHostForVmFunction) Sets aBiFunction
that selects a Host for a given Vm. This Function receives the current VmAllocationPolicy and theVm
requesting to be place. It then returns anOptional<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 methodfindHostForVm(Vm)
.- Specified by:
setFindHostForVmFunction
in interfaceVmAllocationPolicy
- Parameters:
findHostForVmFunction
- theBiFunction
to set. Passing null makes the default method to find a Host for a VM to be used.
-
findHostForVm
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 interfaceVmAllocationPolicy
- Parameters:
vm
- the vm to find a host for it- Returns:
- an
Optional
containing a suitable Host to place the VM; or an emptyOptional
if no suitable Host was found - See Also:
-
defaultFindHostForVm
Provides the default implementation of the policy to find a suitable Host for a given VM. -
getOptimizedAllocationMap
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 interfaceVmAllocationPolicy
- 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 interfaceVmAllocationPolicy
- 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 interfaceVmAllocationPolicy
- Parameters:
hostCountForParallelSearch
- the value to set (useInteger.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 interfaceVmAllocationPolicy
- Returns:
- See Also:
-