Skip to content

Commit a723101

Browse files
author
Prachi Damle
committed
CLOUDSTACK-1604: deploy VM failed when global setting "vm.allocation.algorithm" is set to "userdispersing"
Changes: - DeployPlannerSelector was newly introduced for BareMetal feature. It had the planner name hardcoded. - Change it to decide the planner by referring to the global config vm.allocation.algorithm value
1 parent e6d46d7 commit a723101

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

‎server/src/com/cloud/deploy/AbstractDeployPlannerSelector.java‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,23 @@
1818

1919
import java.util.Map;
2020

21+
import javax.inject.Inject;
2122
import javax.naming.ConfigurationException;
2223

24+
import com.cloud.configuration.Config;
25+
import com.cloud.configuration.dao.ConfigurationDao;
26+
import com.cloud.utils.component.AdapterBase;
2327
import com.cloud.vm.UserVmVO;
2428

25-
public abstract class AbstractDeployPlannerSelector implements DeployPlannerSelector {
29+
public abstract class AbstractDeployPlannerSelector extends AdapterBase implements DeployPlannerSelector {
2630
protected Map<String, Object> params;
2731
protected String name;
2832
protected int runLevel;
29-
33+
34+
@Inject
35+
protected ConfigurationDao _configDao;
36+
protected String _allocationAlgorithm = "random";
37+
3038
@Override
3139
public String getName() {
3240
return name;
@@ -59,6 +67,8 @@ public void setRunLevel(int level) {
5967

6068
@Override
6169
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
70+
super.configure(name, params);
71+
_allocationAlgorithm = _configDao.getValue(Config.VmAllocationAlgorithm.key());
6272
return true;
6373
}
6474

‎server/src/com/cloud/deploy/HypervisorVmPlannerSelector.java‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import javax.ejb.Local;
2020

21+
import com.cloud.deploy.DeploymentPlanner.AllocationAlgorithm;
2122
import com.cloud.hypervisor.Hypervisor.HypervisorType;
2223
import com.cloud.vm.UserVmVO;
2324

@@ -26,8 +27,20 @@ public class HypervisorVmPlannerSelector extends AbstractDeployPlannerSelector {
2627
@Override
2728
public String selectPlanner(UserVmVO vm) {
2829
if (vm.getHypervisorType() != HypervisorType.BareMetal) {
29-
return "FirstFitPlanner";
30+
//check the allocation strategy
31+
if (_allocationAlgorithm != null) {
32+
if (_allocationAlgorithm.equals(AllocationAlgorithm.random.toString())
33+
|| _allocationAlgorithm.equals(AllocationAlgorithm.firstfit.toString())) {
34+
return "FirstFitPlanner";
35+
} else if (_allocationAlgorithm.equals(AllocationAlgorithm.userdispersing.toString())) {
36+
return "UserDispersingPlanner";
37+
} else if (_allocationAlgorithm.equals(AllocationAlgorithm.userconcentratedpod_random.toString())
38+
|| _allocationAlgorithm.equals(AllocationAlgorithm.userconcentratedpod_firstfit.toString())) {
39+
return "UserConcentratedPodPlanner";
40+
}
41+
}
3042
}
43+
3144
return null;
3245
}
3346
}

0 commit comments

Comments
 (0)