Skip to content

Commit 68e16c5

Browse files
GabrielNicole Schmidt
authored andcommitted
allow deploy of VRs on dedicated resources
1 parent 39c5641 commit 68e16c5

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<CapacityVO> listByHostIdTypes(Long hostId, List<Short> capacityTypes);
@@ -40,7 +45,7 @@ public interface CapacityDao extends GenericDao<CapacityVO, Long> {
4045

4146
List<SummedCapacity> findNonSharedStorageForClusterPodZone(Long zoneId, Long podId, Long clusterId);
4247

43-
Pair<List<Long>, Map<Long, Double>> orderClustersByAggregateCapacity(long id, long vmId, short capacityType, boolean isZone);
48+
Pair<List<Long>, Map<Long, Double>> orderClustersByAggregateCapacity(long id, long vmId, short capacityType, boolean isVr, boolean isZone);
4449

4550
Ternary<Long, Long, Long> findCapacityByZoneAndHostTag(Long zoneId, String hostTag);
4651

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))";
@@ -975,7 +984,7 @@ public boolean removeBy(Short capacityType, Long zoneId, Long podId, Long cluste
975984
}
976985

977986
@Override
978-
public Pair<List<Long>, Map<Long, Double>> orderClustersByAggregateCapacity(long id, long vmId, short capacityTypeForOrdering, boolean isZone) {
987+
public Pair<List<Long>, Map<Long, Double>> orderClustersByAggregateCapacity(long id, long vmId, short capacityTypeForOrdering, boolean isVr, boolean isZone) {
979988
TransactionLegacy txn = TransactionLegacy.currentTxn();
980989
PreparedStatement pstmt = null;
981990
List<Long> result = new ArrayList<Long>();
@@ -987,7 +996,12 @@ public Pair<List<Long>, Map<Long, Double>> orderClustersByAggregateCapacity(long
987996
sql.append(ORDER_CLUSTERS_BY_AGGREGATE_OVERCOMMIT_CAPACITY_PART1);
988997
}
989998

990-
sql.append(ORDER_CLUSTERS_BY_AGGREGATE_CAPACITY_JOIN_1);
999+
if (isVr && allowRoutersOnDedicatedResources.value()) {
1000+
sql.append(ORDER_CLUSTERS_BY_AGGREGATE_CAPACITY_INCLUDE_DEDICATED_TO_DOMAIN_JOIN_1);
1001+
} else {
1002+
sql.append(ORDER_CLUSTERS_BY_AGGREGATE_CAPACITY_JOIN_1);
1003+
}
1004+
9911005
if (isZone) {
9921006
sql.append("WHERE capacity.capacity_state = 'Enabled' AND capacity.data_center_id = ?");
9931007
} else {
@@ -1219,4 +1233,13 @@ public float findClusterConsumption(Long clusterId, short capacityType, long com
12191233
return 0;
12201234
}
12211235

1236+
@Override
1237+
public ConfigKey<?>[] getConfigKeys() {
1238+
return new ConfigKey<?>[] {allowRoutersOnDedicatedResources};
1239+
}
1240+
1241+
@Override
1242+
public String getConfigComponentName() {
1243+
return CapacityDaoImpl.class.getSimpleName();
1244+
}
12221245
}

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
@@ -366,7 +366,7 @@ private void initializeForTest(VirtualMachineProfileImpl vmProfile, DataCenterDe
366366
clusterCapacityMap.put(2L, 2048D);
367367
clusterCapacityMap.put(3L, 2048D);
368368
Pair<List<Long>, Map<Long, Double>> clustersOrderedByCapacity = new Pair<List<Long>, Map<Long, Double>>(clustersWithEnoughCapacity, clusterCapacityMap);
369-
when(capacityDao.orderClustersByAggregateCapacity(dataCenterId, 12L, Capacity.CAPACITY_TYPE_CPU, true)).thenReturn(clustersOrderedByCapacity);
369+
when(capacityDao.orderClustersByAggregateCapacity(dataCenterId, 12L, Capacity.CAPACITY_TYPE_CPU, false, true)).thenReturn(clustersOrderedByCapacity);
370370

371371
List<Long> disabledClusters = new ArrayList<Long>();
372372
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
@@ -304,7 +304,7 @@ private void initializeForTest(VirtualMachineProfileImpl vmProfile, DataCenterDe
304304
clusterCapacityMap.put(6L, 2048D);
305305

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

309309
List<Long> disabledClusters = new ArrayList<Long>();
310310
List<Long> clustersWithDisabledPods = new ArrayList<Long>();

0 commit comments

Comments
 (0)