Skip to content

Commit c45596c

Browse files
BryanMLimaFabricio Duartewinterhazel
authored
Refactor of Allocator classes (#9074)
* Refactoring Allocator classes * Break into smaller methods random and firfit allocators. * Added unit tests for random and firstfit allocators * Move random allocator from cloud-plugins to cloud-server * Add BaseAllocator abstract class for duplicate code * Add missing license * Add missing license to unit test file * Remove host allocator random dependency * Change exception message on smoke tests * Remove conditional as it was never actually reached in the original flow * Fix tests * Fix flipped parameters * Fix NPE while listing hosts for migration when suitableHosts is null * Remove unnecessary stubbings * Fix checkstyle * Remove unnecessary file * Rename exception error messages * Apply suggestions from code review Co-authored-by: Fabricio Duarte <fabricio.duarte.jr@gmail.com> * Rename UserVmDetailVO references to VMInstanceDetailVO * Remove unused imports * Add new line at EOF * Remove unnecessary random allocator pom * Fix GPU allocation mistake * Fix failing tests --------- Co-authored-by: Fabricio Duarte <fabricio.duarte@scclouds.com.br> Co-authored-by: Fabricio Duarte <fabricio.duarte.jr@gmail.com>
1 parent a73cc9a commit c45596c

26 files changed

Lines changed: 1593 additions & 981 deletions

File tree

api/src/main/java/com/cloud/agent/manager/allocator/HostAllocator.java

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,11 @@
2222
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
2323
import com.cloud.host.Host;
2424
import com.cloud.host.Host.Type;
25-
import com.cloud.offering.ServiceOffering;
2625
import com.cloud.utils.component.Adapter;
27-
import com.cloud.vm.VirtualMachine;
2826
import com.cloud.vm.VirtualMachineProfile;
2927

3028
public interface HostAllocator extends Adapter {
3129

32-
/**
33-
* @param UserVm vm
34-
* @param ServiceOffering offering
35-
**/
36-
boolean isVirtualMachineUpgradable(final VirtualMachine vm, final ServiceOffering offering);
37-
3830
/**
3931
* Determines which physical hosts are suitable to
4032
* allocate the guest virtual machines on
@@ -49,31 +41,6 @@ public interface HostAllocator extends Adapter {
4941

5042
public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo);
5143

52-
/**
53-
* Determines which physical hosts are suitable to allocate the guest
54-
* virtual machines on
55-
*
56-
* Allocators must set any other hosts not considered for allocation in the
57-
* ExcludeList avoid. Thus the avoid set and the list of hosts suitable,
58-
* together must cover the entire host set in the cluster.
59-
*
60-
* @param VirtualMachineProfile
61-
* vmProfile
62-
* @param DeploymentPlan
63-
* plan
64-
* @param GuestType
65-
* type
66-
* @param ExcludeList
67-
* avoid
68-
* @param int returnUpTo (use -1 to return all possible hosts)
69-
* @param boolean considerReservedCapacity (default should be true, set to
70-
* false if host capacity calculation should not look at reserved
71-
* capacity)
72-
* @return List<Host> List of hosts that are suitable for VM allocation
73-
**/
74-
75-
public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo, boolean considerReservedCapacity);
76-
7744
/**
7845
* Determines which physical hosts are suitable to allocate the guest
7946
* virtual machines on

api/src/main/java/com/cloud/deploy/DeploymentPlanner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public interface DeploymentPlanner extends Adapter {
7070
boolean canHandle(VirtualMachineProfile vm, DeploymentPlan plan, ExcludeList avoid);
7171

7272
public enum AllocationAlgorithm {
73-
random, firstfit, userdispersing;
73+
random, firstfit, userdispersing, firstfitleastconsumed;
7474
}
7575

7676
public enum PlannerResourceUsage {

api/src/main/java/org/apache/cloudstack/api/command/admin/host/FindHostsForMigrationCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void execute() {
7878
for (Host host : result.first()) {
7979
HostForMigrationResponse hostResponse = _responseGenerator.createHostForMigrationResponse(host);
8080
Boolean suitableForMigration = false;
81-
if (hostsWithCapacity.contains(host)) {
81+
if (hostsWithCapacity != null && hostsWithCapacity.contains(host)) {
8282
suitableForMigration = true;
8383
}
8484
hostResponse.setSuitableForMigration(suitableForMigration);

api/src/main/java/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ protected ListResponse<HostResponse> getHostResponses() {
252252
for (Host host : result.first()) {
253253
HostResponse hostResponse = _responseGenerator.createHostResponse(host, getDetails());
254254
Boolean suitableForMigration = false;
255-
if (hostsWithCapacity.contains(host)) {
255+
if (hostsWithCapacity != null && hostsWithCapacity.contains(host)) {
256256
suitableForMigration = true;
257257
}
258258
hostResponse.setSuitableForMigration(suitableForMigration);

client/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,6 @@
377377
<artifactId>cloud-plugin-explicit-dedication</artifactId>
378378
<version>${project.version}</version>
379379
</dependency>
380-
<dependency>
381-
<groupId>org.apache.cloudstack</groupId>
382-
<artifactId>cloud-plugin-host-allocator-random</artifactId>
383-
<version>${project.version}</version>
384-
</dependency>
385380
<dependency>
386381
<groupId>org.apache.cloudstack</groupId>
387382
<artifactId>cloud-plugin-outofbandmanagement-driver-ipmitool</artifactId>

engine/api/src/main/java/com/cloud/vm/VirtualMachineManager.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,6 @@ void orchestrateStart(String vmUuid, Map<VirtualMachineProfile.Param, Object> pa
181181
void advanceReboot(String vmUuid, Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ResourceUnavailableException,
182182
ConcurrentOperationException, OperationTimedoutException;
183183

184-
/**
185-
* Check to see if a virtual machine can be upgraded to the given service offering
186-
*
187-
* @param vm
188-
* @param offering
189-
* @return true if the host can handle the upgrade, false otherwise
190-
*/
191-
boolean isVirtualMachineUpgradable(final VirtualMachine vm, final ServiceOffering offering);
192-
193184
VirtualMachine findById(long vmId);
194185

195186
void storageMigration(String vmUuid, Map<Long, Long> volumeToPool);

engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4017,19 +4017,6 @@ protected void runInContext() {
40174017
}
40184018
}
40194019

4020-
@Override
4021-
public boolean isVirtualMachineUpgradable(final VirtualMachine vm, final ServiceOffering offering) {
4022-
boolean isMachineUpgradable = true;
4023-
for (final HostAllocator allocator : hostAllocators) {
4024-
isMachineUpgradable = allocator.isVirtualMachineUpgradable(vm, offering);
4025-
if (!isMachineUpgradable) {
4026-
break;
4027-
}
4028-
}
4029-
4030-
return isMachineUpgradable;
4031-
}
4032-
40334020
@Override
40344021
public void reboot(final String vmUuid, final Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ResourceUnavailableException {
40354022
try {
@@ -4469,11 +4456,6 @@ public void checkIfCanUpgrade(final VirtualMachine vmInstance, final ServiceOffe
44694456
throw new InvalidParameterValueException("isSystem property is different for current service offering and new service offering");
44704457
}
44714458

4472-
if (!isVirtualMachineUpgradable(vmInstance, newServiceOffering)) {
4473-
throw new InvalidParameterValueException("Unable to upgrade virtual machine, not enough resources available " + "for an offering of " +
4474-
newServiceOffering.getCpu() + " cpu(s) at " + newServiceOffering.getSpeed() + " Mhz, and " + newServiceOffering.getRamSize() + " MB of memory");
4475-
}
4476-
44774459
final List<String> currentTags = StringUtils.csvTagsToList(currentDiskOffering.getTags());
44784460
final List<String> newTags = StringUtils.csvTagsToList(newDiskOffering.getTags());
44794461
if (VolumeApiServiceImpl.MatchStoragePoolTagsWithDiskOffering.valueIn(vmInstance.getDataCenterId())) {

engine/schema/src/main/java/com/cloud/host/dao/HostDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ int countHostsByMsResourceStateTypeAndHypervisorType(long msId, List<ResourceSta
218218
*/
219219
List<String> listOrderedHostsHypervisorVersionsInDatacenter(long datacenterId, HypervisorType hypervisorType);
220220

221-
List<HostVO> findHostsWithTagRuleThatMatchComputeOferringTags(String computeOfferingTags);
221+
List<HostVO> findHostsWithTagRuleThatMatchComputeOfferingTags(String computeOfferingTags);
222222

223223
List<Long> findClustersThatMatchHostTagRule(String computeOfferingTags);
224224

engine/schema/src/main/java/com/cloud/host/dao/HostDaoImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,7 +1520,7 @@ private List<Long> findHostIdsByHostTags(String hostTags){
15201520
}
15211521
}
15221522

1523-
public List<HostVO> findHostsWithTagRuleThatMatchComputeOferringTags(String computeOfferingTags) {
1523+
public List<HostVO> findHostsWithTagRuleThatMatchComputeOfferingTags(String computeOfferingTags) {
15241524
List<HostTagVO> hostTagVOList = _hostTagsDao.findHostRuleTags();
15251525
List<HostVO> result = new ArrayList<>();
15261526
for (HostTagVO rule: hostTagVOList) {
@@ -1534,7 +1534,7 @@ public List<HostVO> findHostsWithTagRuleThatMatchComputeOferringTags(String comp
15341534

15351535
public List<Long> findClustersThatMatchHostTagRule(String computeOfferingTags) {
15361536
Set<Long> result = new HashSet<>();
1537-
List<HostVO> hosts = findHostsWithTagRuleThatMatchComputeOferringTags(computeOfferingTags);
1537+
List<HostVO> hosts = findHostsWithTagRuleThatMatchComputeOfferingTags(computeOfferingTags);
15381538
for (HostVO host: hosts) {
15391539
result.add(host.getClusterId());
15401540
}

plugins/host-allocators/random/pom.xml

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)