Class VmAllocationPolicyAbstract
java.lang.Object
org.cloudsimplus.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.
Each Datacenter must 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.cloudsimplus.allocationpolicies.VmAllocationPolicy
DEF_HOST_COUNT_PARALLEL_SEARCH, LOGGER, NULL -
Constructor Summary
ConstructorsConstructorDescriptionCreates a VmAllocationPolicy.VmAllocationPolicyAbstract(BiFunction<VmAllocationPolicy, Vm, Optional<Host>> findHostForVmFunction) Creates a VmAllocationPolicy, changing theBiFunctionto select a Host for a Vm. -
Method Summary
Modifier and TypeMethodDescriptionfinal Set<HostSuitability> allocateHostForVm(@NonNull List<Vm> vmList) allocateHostForVm(Vm vm) Allocates the host with less PEs in use for a given VM.allocateHostForVm(Vm vm, Host host) protected Set<HostSuitability> allocateHostForVmInternal(@NonNull List<Vm> vmList) If you override this method, you must callallocateHostForVm(Vm, Host)for each suitable Host you have found that want to create a VM.voidReleases 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 the list of Hosts available in theDatacenterlinked to this VmAllocationPolicy, which will be used 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.booleanChecks if VM migrations are supported by this VmAllocationPolicy.booleanscaleVmVertically(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 givenVerticalVmScalingobject.final VmAllocationPolicysetFindHostForVmFunction(BiFunction<VmAllocationPolicy, Vm, Optional<Host>> findHostForVmFunction) Sets aBiFunctionthat selects a Host for a given Vm.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.cloudsimplus.allocationpolicies.VmAllocationPolicy
getDatacenter, getHostCountForParallelSearch, isParallelHostSearchEnabled, setDatacenter, setHostCountForParallelSearch
-
Constructor Details
-
VmAllocationPolicyAbstract
public VmAllocationPolicyAbstract()Creates a VmAllocationPolicy. -
VmAllocationPolicyAbstract
public VmAllocationPolicyAbstract(BiFunction<VmAllocationPolicy, Vm, Optional<Host>> findHostForVmFunction) Creates a VmAllocationPolicy, changing theBiFunctionto select a Host for a Vm.- Parameters:
findHostForVmFunction- aBiFunctionto select a Host for a given Vm.- See Also:
-
-
Method Details
-
getHostList
Description copied from interface:VmAllocationPolicyGets the list of Hosts available in theDatacenterlinked to this VmAllocationPolicy, which will be used to place VMs.- Specified by:
getHostListin interfaceVmAllocationPolicy- Type Parameters:
T- the host type- Returns:
- datacenter the host list
-
scaleVmVertically
Description copied from interface:VmAllocationPolicyTry 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
VerticalVmScalingobject.- Specified by:
scaleVmVerticallyin interfaceVmAllocationPolicy- Parameters:
scaling- theVerticalVmScalingobject with information of which resource is being requested to be scaled- Returns:
- true if the requested resource was scaled, false otherwise
-
allocateHostForVm
Description copied from interface:VmAllocationPolicyTries to allocate a host for a eachVmorVmGroupinto a given List. The method should define how it will find asuitable Hostfor each Vm and then callVmAllocationPolicy.allocateHostForVm(Vm, Host)to actually create the VM inside the selected Host.- Specified by:
allocateHostForVmin interfaceVmAllocationPolicy- Parameters:
vmList- the List ofVms orVmGroups to allocate a host to- Returns:
- a Set of
HostSuitabilityto indicate if a Vm was placed into the host or not, containing a HostSuitability object for the last Host where each VM was tried to be created; or an empty set if the Datacenter has no hosts. - See Also:
-
allocateHostForVmInternal
If you override this method, you must callallocateHostForVm(Vm, Host)for each suitable Host you have found that want to create a VM.- See Also:
-
allocateHostForVm
Allocates the host with less PEs in use for a given VM. Tries to allocate a host for a givenVmorVmGroup.- Specified by:
allocateHostForVmin interfaceVmAllocationPolicy- Parameters:
vm- theVmorVmGroupto allocate a host to- Returns:
- a
HostSuitabilityto 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:
allocateHostForVmin interfaceVmAllocationPolicy- Parameters:
vm- theVmorVmGroupto allocate a host tohost- the host to allocate to the givenVmorVmGroup- Returns:
- a
HostSuitabilityto 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:VmAllocationPolicyReleases the host used by a VM.- Specified by:
deallocateHostForVmin interfaceVmAllocationPolicy- Parameters:
vm- the vm to get its host released
-
setFindHostForVmFunction
public final VmAllocationPolicy setFindHostForVmFunction(BiFunction<VmAllocationPolicy, Vm, Optional<Host>> findHostForVmFunction) Sets aBiFunctionthat selects a Host for a given Vm. This Function receives the current VmAllocationPolicy and theVmrequesting to be placed. It then returns anOptional<Host>that may contain a suitable Host for that Vm or not.If no Function is set, the default VM selection method provided by implementing classes will be used instead.
The default implementation of such a Function is provided by the methodfindHostForVm(Vm).- Specified by:
setFindHostForVmFunctionin interfaceVmAllocationPolicy- Parameters:
findHostForVmFunction- theBiFunctionto set. Passing null will cause the usage of the default method to find a Host for a VM.- See Also:
-
findHostForVm
Description copied from interface:VmAllocationPolicyFinds a suitable Host that has enough resources to place a given VM. Internally it may use a default implementation or oneset in runtime.- Specified by:
findHostForVmin interfaceVmAllocationPolicy- Parameters:
vm- the vm to find a host for it- Returns:
- an
Optionalcontaining a suitable Host to place the VM; or an emptyOptionalif no suitable Host was found
-
defaultFindHostForVm
Provides the default implementation of the policy to find a suitable Host for a given VM. -
getOptimizedAllocationMap
Description copied from interface:VmAllocationPolicyGets 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:
getOptimizedAllocationMapin 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
-
isVmMigrationSupported
public boolean isVmMigrationSupported()Description copied from interface:VmAllocationPolicyChecks 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:
isVmMigrationSupportedin interfaceVmAllocationPolicy- Returns:
- true if VM migration is supported; false otherwise.
- See Also:
-