Skip to content

Commit 5da9945

Browse files
author
Gabriel
committed
allow deploy of VRs on dedicated resources
1 parent cd8442a commit 5da9945

File tree

5 files changed

+38
-9
lines changed

5 files changed

+38
-9
lines changed

engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDao.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@
2424
import com.cloud.utils.Pair;
2525
import com.cloud.utils.Ternary;
2626
import com.cloud.utils.db.GenericDao;
27+
import org.apache.cloudstack.framework.config.ConfigKey;
2728

2829
public interface CapacityDao extends GenericDao<CapacityVO, Long> {
30+
31+
ConfigKey<Boolean> allowRoutersOnDedicatedResources = new ConfigKey<>("Advanced", Boolean.class, "allow.routers.on.dedicated.resources", "false",
32+
"Allow deploying virtual routers on dedicated Hosts, Clusters, Pods, and Zones", true);
33+
2934
CapacityVO findByHostIdType(Long hostId, short capacityType);
3035

3136
List<Long> listClustersInZoneOrPodByHostCapacities(long id, long vmId, int requiredCpu, long requiredRam, short capacityTypeForOrdering, boolean isZone);
@@ -38,7 +43,7 @@ public interface CapacityDao extends GenericDao<CapacityVO, Long> {
3843

3944
List<SummedCapacity> findNonSharedStorageForClusterPodZone(Long zoneId, Long podId, Long clusterId);
4045

41-
Pair<List<Long>, Map<Long, Double>> orderClustersByAggregateCapacity(long id, long vmId, short capacityType, boolean isZone);
46+
Pair<List<Long>, Map<Long, Double>> orderClustersByAggregateCapacity(long id, long vmId, short capacityType, boolean isVr, boolean isZone);
4247

4348
Ternary<Long, Long, Long> findCapacityByZoneAndHostTag(Long zoneId, String hostTag);
4449

engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
import javax.inject.Inject;
2828

29+
import org.apache.cloudstack.framework.config.ConfigKey;
30+
import org.apache.cloudstack.framework.config.Configurable;
2931
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
3032
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
3133
import org.apache.commons.collections.CollectionUtils;
@@ -49,7 +51,7 @@
4951
import com.cloud.utils.exception.CloudRuntimeException;
5052

5153
@Component
52-
public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements CapacityDao {
54+
public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements CapacityDao, Configurable {
5355

5456
private static final String ADD_ALLOCATED_SQL = "UPDATE `cloud`.`op_host_capacity` SET used_capacity = used_capacity + ? WHERE host_id = ? AND capacity_type = ?";
5557
private static final String SUBTRACT_ALLOCATED_SQL =
@@ -87,6 +89,13 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
8789
"LEFT JOIN dedicated_resources dr_cluster ON dr_cluster.cluster_id IS NOT NULL AND dr_cluster.cluster_id = host.cluster_id " +
8890
"LEFT JOIN dedicated_resources dr_host ON dr_host.host_id IS NOT NULL AND dr_host.host_id = host.id ";
8991

92+
private static final String ORDER_CLUSTERS_BY_AGGREGATE_CAPACITY_INCLUDE_DEDICATED_TO_DOMAIN_JOIN_1 =
93+
"JOIN host ON capacity.host_id = host.id " +
94+
"LEFT JOIN (SELECT affinity_group.id, agvm.instance_id FROM affinity_group_vm_map agvm JOIN affinity_group ON agvm.affinity_group_id = affinity_group.id AND affinity_group.type='ExplicitDedication') AS ag ON ag.instance_id = ? " +
95+
"LEFT JOIN dedicated_resources dr_pod ON dr_pod.pod_id IS NOT NULL AND dr_pod.pod_id = host.pod_id AND dr_pod.account_id IS NOT NULL " +
96+
"LEFT JOIN dedicated_resources dr_cluster ON dr_cluster.cluster_id IS NOT NULL AND dr_cluster.cluster_id = host.cluster_id AND dr_cluster.account_id IS NOT NULL " +
97+
"LEFT JOIN dedicated_resources dr_host ON dr_host.host_id IS NOT NULL AND dr_host.host_id = host.id AND dr_host.account_id IS NOT NULL ";
98+
9099
private static final String ORDER_CLUSTERS_BY_AGGREGATE_CAPACITY_JOIN_2 =
91100
" AND ((ag.id IS NULL AND dr_pod.pod_id IS NULL AND dr_cluster.cluster_id IS NULL AND dr_host.host_id IS NULL) OR " +
92101
"(dr_pod.affinity_group_id = ag.id OR dr_cluster.affinity_group_id = ag.id OR dr_host.affinity_group_id = ag.id))";
@@ -963,7 +972,7 @@ public boolean removeBy(Short capacityType, Long zoneId, Long podId, Long cluste
963972
}
964973

965974
@Override
966-
public Pair<List<Long>, Map<Long, Double>> orderClustersByAggregateCapacity(long id, long vmId, short capacityTypeForOrdering, boolean isZone) {
975+
public Pair<List<Long>, Map<Long, Double>> orderClustersByAggregateCapacity(long id, long vmId, short capacityTypeForOrdering, boolean isVr, boolean isZone) {
967976
TransactionLegacy txn = TransactionLegacy.currentTxn();
968977
PreparedStatement pstmt = null;
969978
List<Long> result = new ArrayList<Long>();
@@ -975,7 +984,12 @@ public Pair<List<Long>, Map<Long, Double>> orderClustersByAggregateCapacity(long
975984
sql.append(ORDER_CLUSTERS_BY_AGGREGATE_OVERCOMMIT_CAPACITY_PART1);
976985
}
977986

978-
sql.append(ORDER_CLUSTERS_BY_AGGREGATE_CAPACITY_JOIN_1);
987+
if (isVr && allowRoutersOnDedicatedResources.value()) {
988+
sql.append(ORDER_CLUSTERS_BY_AGGREGATE_CAPACITY_INCLUDE_DEDICATED_TO_DOMAIN_JOIN_1);
989+
} else {
990+
sql.append(ORDER_CLUSTERS_BY_AGGREGATE_CAPACITY_JOIN_1);
991+
}
992+
979993
if (isZone) {
980994
sql.append("WHERE capacity.capacity_state = 'Enabled' AND capacity.data_center_id = ?");
981995
} else {
@@ -1207,4 +1221,13 @@ public float findClusterConsumption(Long clusterId, short capacityType, long com
12071221
return 0;
12081222
}
12091223

1224+
@Override
1225+
public ConfigKey<?>[] getConfigKeys() {
1226+
return new ConfigKey<?>[] {allowRoutersOnDedicatedResources};
1227+
}
1228+
1229+
@Override
1230+
public String getConfigComponentName() {
1231+
return CapacityDaoImpl.class.getSimpleName();
1232+
}
12101233
}

plugins/deployment-planners/implicit-dedication/src/test/java/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ private void initializeForTest(VirtualMachineProfileImpl vmProfile, DataCenterDe
368368
clusterCapacityMap.put(2L, 2048D);
369369
clusterCapacityMap.put(3L, 2048D);
370370
Pair<List<Long>, Map<Long, Double>> clustersOrderedByCapacity = new Pair<List<Long>, Map<Long, Double>>(clustersWithEnoughCapacity, clusterCapacityMap);
371-
when(capacityDao.orderClustersByAggregateCapacity(dataCenterId, 12L, Capacity.CAPACITY_TYPE_CPU, true)).thenReturn(clustersOrderedByCapacity);
371+
when(capacityDao.orderClustersByAggregateCapacity(dataCenterId, 12L, Capacity.CAPACITY_TYPE_CPU, false, true)).thenReturn(clustersOrderedByCapacity);
372372

373373
List<Long> disabledClusters = new ArrayList<Long>();
374374
List<Long> clustersWithDisabledPods = new ArrayList<Long>();

server/src/main/java/com/cloud/deploy/FirstFitPlanner.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,10 @@ private List<Long> scanClustersForDestinationInZoneOrPod(long id, boolean isZone
388388
DataCenter dc = dcDao.findById(vm.getDataCenterId());
389389
int requiredCpu = offering.getCpu() * offering.getSpeed();
390390
long requiredRam = offering.getRamSize() * 1024L * 1024L;
391+
boolean isVr = VirtualMachine.Type.DomainRouter.equals(vmProfile.getType());
391392

392393
//list clusters under this zone by cpu and ram capacity
393-
Pair<List<Long>, Map<Long, Double>> clusterCapacityInfo = listClustersByCapacity(id, vmProfile.getId(), requiredCpu, requiredRam, avoid, isZone);
394+
Pair<List<Long>, Map<Long, Double>> clusterCapacityInfo = listClustersByCapacity(id, vmProfile.getId(), requiredCpu, requiredRam, isVr, isZone);
394395
List<Long> prioritizedClusterIds = clusterCapacityInfo.first();
395396
if (!prioritizedClusterIds.isEmpty()) {
396397
if (avoid.getClustersToAvoid() != null) {
@@ -448,7 +449,7 @@ protected List<Long> reorderPods(Pair<List<Long>, Map<Long, Double>> podCapacity
448449
return podIdsByCapacity;
449450
}
450451

451-
protected Pair<List<Long>, Map<Long, Double>> listClustersByCapacity(long id, long vmId, int requiredCpu, long requiredRam, ExcludeList avoid, boolean isZone) {
452+
protected Pair<List<Long>, Map<Long, Double>> listClustersByCapacity(long id, long vmId, int requiredCpu, long requiredRam, boolean isVr, boolean isZone) {
452453
//look at the aggregate available cpu and ram per cluster
453454
//although an aggregate value may be false indicator that a cluster can host a vm, it will at the least eliminate those clusters which definitely cannot
454455

@@ -467,7 +468,7 @@ protected Pair<List<Long>, Map<Long, Double>> listClustersByCapacity(long id, lo
467468
if (logger.isTraceEnabled()) {
468469
logger.trace("ClusterId List having enough CPU and RAM capacity: " + clusterIdswithEnoughCapacity);
469470
}
470-
Pair<List<Long>, Map<Long, Double>> result = capacityDao.orderClustersByAggregateCapacity(id, vmId, capacityType, isZone);
471+
Pair<List<Long>, Map<Long, Double>> result = capacityDao.orderClustersByAggregateCapacity(id, vmId, capacityType, isVr, isZone);
471472
List<Long> clusterIdsOrderedByAggregateCapacity = result.first();
472473
//only keep the clusters that have enough capacity to host this VM
473474
if (logger.isTraceEnabled()) {

server/src/test/java/com/cloud/vm/FirstFitPlannerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ private void initializeForTest(VirtualMachineProfileImpl vmProfile, DataCenterDe
306306
clusterCapacityMap.put(6L, 2048D);
307307

308308
Pair<List<Long>, Map<Long, Double>> clustersOrderedByCapacity = new Pair<List<Long>, Map<Long, Double>>(clustersWithEnoughCapacity, clusterCapacityMap);
309-
when(capacityDao.orderClustersByAggregateCapacity(dataCenterId, 12L, Capacity.CAPACITY_TYPE_CPU, true)).thenReturn(clustersOrderedByCapacity);
309+
when(capacityDao.orderClustersByAggregateCapacity(dataCenterId, 12L, Capacity.CAPACITY_TYPE_CPU, false, true)).thenReturn(clustersOrderedByCapacity);
310310

311311
List<Long> disabledClusters = new ArrayList<Long>();
312312
List<Long> clustersWithDisabledPods = new ArrayList<Long>();

0 commit comments

Comments
 (0)