Skip to content

Commit 2bc25d1

Browse files
committed
allow deploy when resource is dedicated to account
1 parent 42c5625 commit 2bc25d1

6 files changed

Lines changed: 16 additions & 15 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public interface CapacityDao extends GenericDao<CapacityVO, Long> {
4141

4242
List<SummedCapacity> findNonSharedStorageForClusterPodZone(Long zoneId, Long podId, Long clusterId);
4343

44-
Pair<List<Long>, Map<Long, Double>> orderClustersByAggregateCapacity(long id, long vmId, short capacityType, boolean isVr, boolean allowRoutersOnDedicatedResources, boolean isZone);
44+
Pair<List<Long>, Map<Long, Double>> orderClustersByAggregateCapacity(long id, long vmId, Long ownerId, short capacityType, boolean isVr, boolean allowRoutersOnDedicatedResources, boolean isZone);
4545

4646
Ternary<Long, Long, Long> findCapacityByZoneAndHostTag(Long zoneId, String hostTag);
4747

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
8787
"LEFT JOIN dedicated_resources dr_cluster ON dr_cluster.cluster_id IS NOT NULL AND dr_cluster.cluster_id = host.cluster_id " +
8888
"LEFT JOIN dedicated_resources dr_host ON dr_host.host_id IS NOT NULL AND dr_host.host_id = host.id ";
8989

90-
private static final String ORDER_CLUSTERS_BY_AGGREGATE_CAPACITY_INCLUDE_DEDICATED_TO_DOMAIN_JOIN_1 =
90+
private static final String ORDER_CLUSTERS_BY_AGGREGATE_CAPACITY_INCLUDE_DEDICATED_JOIN_1 =
9191
"JOIN host ON capacity.host_id = host.id " +
9292
"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 = ? " +
93-
"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 " +
94-
"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 " +
95-
"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 ";
93+
"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 AND dr_pod.account_id != ownerId " +
94+
"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 AND dr_cluster.account_id != ownerId " +
95+
"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 AND dr_host.account_id != ownerId ";
9696

9797
private static final String ORDER_CLUSTERS_BY_AGGREGATE_CAPACITY_JOIN_2 =
9898
" 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 " +
@@ -993,7 +993,7 @@ public boolean removeBy(Short capacityType, Long zoneId, Long podId, Long cluste
993993
}
994994

995995
@Override
996-
public Pair<List<Long>, Map<Long, Double>> orderClustersByAggregateCapacity(long id, long vmId, short capacityTypeForOrdering, boolean isVr, boolean allowRoutersOnDedicatedResources, boolean isZone) {
996+
public Pair<List<Long>, Map<Long, Double>> orderClustersByAggregateCapacity(long id, long vmId, Long ownerId, short capacityTypeForOrdering, boolean isVr, boolean allowRoutersOnDedicatedResources, boolean isZone) {
997997
TransactionLegacy txn = TransactionLegacy.currentTxn();
998998
PreparedStatement pstmt = null;
999999
List<Long> result = new ArrayList<Long>();
@@ -1006,7 +1006,7 @@ public Pair<List<Long>, Map<Long, Double>> orderClustersByAggregateCapacity(long
10061006
}
10071007

10081008
if (isVr && allowRoutersOnDedicatedResources) {
1009-
sql.append(ORDER_CLUSTERS_BY_AGGREGATE_CAPACITY_INCLUDE_DEDICATED_TO_DOMAIN_JOIN_1);
1009+
sql.append(ORDER_CLUSTERS_BY_AGGREGATE_CAPACITY_INCLUDE_DEDICATED_JOIN_1.replace("ownerId", ownerId.toString()));
10101010
} else {
10111011
sql.append(ORDER_CLUSTERS_BY_AGGREGATE_CAPACITY_JOIN_1);
10121012
}

engine/schema/src/test/java/com/cloud/capacity/dao/CapacityDaoImplTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public void testOrderClustersByAggregateCapacityEmptyResult() throws Exception {
250250
when(pstmt.executeQuery()).thenReturn(resultSet);
251251
when(resultSet.next()).thenReturn(false);
252252

253-
Pair<List<Long>, Map<Long, Double>> result = capacityDao.orderClustersByAggregateCapacity(1L, 1L, (short) 1, false,true);
253+
Pair<List<Long>, Map<Long, Double>> result = capacityDao.orderClustersByAggregateCapacity(1L, 1L, 1L, (short) 1, false, false, true);
254254
assertNotNull(result);
255255
assertTrue(result.first().isEmpty());
256256
assertTrue(result.second().isEmpty());

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, false, false, true)).thenReturn(clustersOrderedByCapacity);
369+
when(capacityDao.orderClustersByAggregateCapacity(dataCenterId, 12L, 1L, Capacity.CAPACITY_TYPE_CPU, false, 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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,10 @@ private List<Long> scanClustersForDestinationInZoneOrPod(long id, boolean isZone
399399
int requiredCpu = offering.getCpu() * offering.getSpeed();
400400
long requiredRam = offering.getRamSize() * 1024L * 1024L;
401401
boolean isVr = VirtualMachine.Type.DomainRouter.equals(vmProfile.getType());
402+
Long ownerId = vm.getAccountId();
402403

403404
//list clusters under this zone by cpu and ram capacity
404-
Pair<List<Long>, Map<Long, Double>> clusterCapacityInfo = listClustersByCapacity(id, vmProfile.getId(), requiredCpu, requiredRam, isVr, isZone);
405+
Pair<List<Long>, Map<Long, Double>> clusterCapacityInfo = listClustersByCapacity(id, vmProfile.getId(), ownerId, requiredCpu, requiredRam, isVr, isZone);
405406
List<Long> prioritizedClusterIds = clusterCapacityInfo.first();
406407
if (!prioritizedClusterIds.isEmpty()) {
407408
if (avoid.getClustersToAvoid() != null) {
@@ -459,7 +460,7 @@ protected List<Long> reorderPods(Pair<List<Long>, Map<Long, Double>> podCapacity
459460
return podIdsByCapacity;
460461
}
461462

462-
protected Pair<List<Long>, Map<Long, Double>> listClustersByCapacity(long id, long vmId, int requiredCpu, long requiredRam, boolean isVr, boolean isZone) {
463+
protected Pair<List<Long>, Map<Long, Double>> listClustersByCapacity(long id, long vmId, Long ownerId, int requiredCpu, long requiredRam, boolean isVr, boolean isZone) {
463464
//look at the aggregate available cpu and ram per cluster
464465
//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
465466

@@ -475,7 +476,7 @@ protected Pair<List<Long>, Map<Long, Double>> listClustersByCapacity(long id, lo
475476
}
476477

477478

478-
Pair<List<Long>, Map<Long, Double>> result = getOrderedClustersByCapacity(id, vmId, isVr, isZone);
479+
Pair<List<Long>, Map<Long, Double>> result = getOrderedClustersByCapacity(id, vmId, ownerId, isVr, isZone);
479480
List<Long> clusterIdsOrderedByAggregateCapacity = result.first();
480481
//only keep the clusters that have enough capacity to host this VM
481482
if (logger.isTraceEnabled()) {
@@ -555,14 +556,14 @@ public Map<Long, Double> getPodByCombinedCapacities(List<CapacityVO> capacities,
555556
}
556557

557558

558-
private Pair<List<Long>, Map<Long, Double>> getOrderedClustersByCapacity(long id, long vmId, boolean isVr, boolean isZone) {
559+
private Pair<List<Long>, Map<Long, Double>> getOrderedClustersByCapacity(long id, long vmId, Long ownerId, boolean isVr, boolean isZone) {
559560
double cpuToMemoryWeight = ConfigurationManager.HostCapacityTypeCpuMemoryWeight.value();
560561
short capacityType = getHostCapacityTypeToOrderCluster(
561562
configDao.getValue(Config.HostCapacityTypeToOrderClusters.key()), cpuToMemoryWeight);
562563

563564
logger.debug("CapacityType: {} is used for Cluster ordering", getCapacityTypeName(capacityType));
564565
if (capacityType >= 0) { // for capacityType other than COMBINED
565-
return capacityDao.orderClustersByAggregateCapacity(id, vmId, capacityType, isVr, allowRoutersOnDedicatedResources.value(), isZone);
566+
return capacityDao.orderClustersByAggregateCapacity(id, vmId, ownerId, capacityType, isVr, allowRoutersOnDedicatedResources.value(), isZone);
566567
}
567568

568569
Long zoneId = isZone ? id : null;

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

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

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

378378
List<Long> disabledClusters = new ArrayList<Long>();
379379
List<Long> clustersWithDisabledPods = new ArrayList<Long>();

0 commit comments

Comments
 (0)