Skip to content

Commit e8ab0ae

Browse files
CPU to Memory weight based algorithm to order cluster (#10997)
* CPU to Memory weight based algorithm to order cluster host.capacityType.to.order.clusters config will support new algorithm: COMBINED which will work with host.capacityType.to.order.clusters.cputomemoryweight and capacity will be computed based on CPU and memory both and using weight factor * minor changes * add unit tests * update desc and add validation * handle copilot review comments * add log indicating chosen capacityType for ordering --------- Co-authored-by: Rohit Yadav <[email protected]>
1 parent fb6adac commit e8ab0ae

File tree

13 files changed

+661
-38
lines changed

13 files changed

+661
-38
lines changed

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,11 @@ public class ApiConstants {
9090
public static final String CONVERT_INSTANCE_HOST_ID = "convertinstancehostid";
9191
public static final String CONVERT_INSTANCE_STORAGE_POOL_ID = "convertinstancepoolid";
9292
public static final String ENABLED_REVOCATION_CHECK = "enabledrevocationcheck";
93+
public static final String COMBINED_CAPACITY_ORDERING = "COMBINED";
9394
public static final String CONTROLLER = "controller";
9495
public static final String CONTROLLER_UNIT = "controllerunit";
9596
public static final String COPY_IMAGE_TAGS = "copyimagetags";
97+
public static final String CPU_OVERCOMMIT_RATIO = "cpuOvercommitRatio";
9698
public static final String CSR = "csr";
9799
public static final String PRIVATE_KEY = "privatekey";
98100
public static final String DATASTORE_HOST = "datastorehost";
@@ -124,6 +126,7 @@ public class ApiConstants {
124126
public static final String CNI_CONFIG_DETAILS = "cniconfigdetails";
125127
public static final String CNI_CONFIG_NAME = "cniconfigname";
126128
public static final String COMPONENT = "component";
129+
public static final String CPU = "CPU";
127130
public static final String CPU_CORE_PER_SOCKET = "cpucorepersocket";
128131
public static final String CPU_NUMBER = "cpunumber";
129132
public static final String CPU_SPEED = "cpuspeed";
@@ -344,6 +347,7 @@ public class ApiConstants {
344347
public static final String MAX_BACKUPS = "maxbackups";
345348
public static final String MAX_CPU_NUMBER = "maxcpunumber";
346349
public static final String MAX_MEMORY = "maxmemory";
350+
public static final String MEMORY_OVERCOMMIT_RATIO = "memoryOvercommitRatio";
347351
public static final String MIN_CPU_NUMBER = "mincpunumber";
348352
public static final String MIN_MEMORY = "minmemory";
349353
public static final String MIGRATION_TYPE = "migrationtype";
@@ -441,6 +445,7 @@ public class ApiConstants {
441445
public static final String PUBLIC_END_PORT = "publicendport";
442446
public static final String PUBLIC_ZONE = "publiczone";
443447
public static final String PURGE_RESOURCES = "purgeresources";
448+
public static final String RAM = "RAM";
444449
public static final String REBALANCE = "rebalance";
445450
public static final String RECEIVED_BYTES = "receivedbytes";
446451
public static final String RECONNECT = "reconnect";

engine/components-api/src/main/java/com/cloud/configuration/ConfigurationManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ public interface ConfigurationManager {
6565
"allow.non.rfc1918.compliant.ips", "Advanced", "false",
6666
"Allows non-compliant RFC 1918 IPs for Shared, Isolated networks and VPCs", true, null);
6767

68+
ConfigKey<Float> HostCapacityTypeCpuMemoryWeight = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, Float.class,
69+
"host.capacityType.to.order.clusters.cputomemoryweight",
70+
"0.5",
71+
"Weight for CPU (as a value between 0 and 1) applied to compute capacity for Pods, Clusters and Hosts for COMBINED capacityType for ordering. Weight for RAM will be (1 - weight of CPU)",
72+
true, ConfigKey.Scope.Global);
73+
6874
/**
6975
* @param offering
7076
* @return

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public interface CapacityDao extends GenericDao<CapacityVO, Long> {
3030

3131
List<CapacityVO> listByHostIdTypes(Long hostId, List<Short> capacityTypes);
3232

33-
List<Long> listClustersInZoneOrPodByHostCapacities(long id, long vmId, int requiredCpu, long requiredRam, short capacityTypeForOrdering, boolean isZone);
33+
List<Long> listClustersInZoneOrPodByHostCapacities(long id, long vmId, int requiredCpu, long requiredRam, boolean isZone);
3434

3535
List<Long> listHostsWithEnoughCapacity(int requiredCpu, long requiredRam, Long clusterId, String hostType);
3636

@@ -48,7 +48,7 @@ public interface CapacityDao extends GenericDao<CapacityVO, Long> {
4848

4949
List<SummedCapacity> findFilteredCapacityBy(Integer capacityType, Long zoneId, Long podId, Long clusterId, List<Long> hostIds, List<Long> poolIds);
5050

51-
List<Long> listPodsByHostCapacities(long zoneId, int requiredCpu, long requiredRam, short capacityType);
51+
List<Long> listPodsByHostCapacities(long zoneId, int requiredCpu, long requiredRam);
5252

5353
Pair<List<Long>, Map<Long, Double>> orderPodsByAggregateCapacity(long zoneId, short capacityType);
5454

@@ -65,4 +65,10 @@ List<SummedCapacity> listCapacitiesGroupedByLevelAndType(Integer capacityType, L
6565
float findClusterConsumption(Long clusterId, short capacityType, long computeRequested);
6666

6767
Pair<List<Long>, Map<Long, Double>> orderHostsByFreeCapacity(Long zoneId, Long clusterId, short capacityType);
68+
69+
List<CapacityVO> listHostCapacityByCapacityTypes(Long zoneId, Long clusterId, List<Short> capacityTypes);
70+
71+
List<CapacityVO> listPodCapacityByCapacityTypes(Long zoneId, List<Short> capacityTypes);
72+
73+
List<CapacityVO> listClusterCapacityByCapacityTypes(Long zoneId, Long podId, List<Short> capacityTypes);
6874
}

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

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ public List<CapacityVO> listByHostIdTypes(Long hostId, List<Short> capacityTypes
684684
}
685685

686686
@Override
687-
public List<Long> listClustersInZoneOrPodByHostCapacities(long id, long vmId, int requiredCpu, long requiredRam, short capacityTypeForOrdering, boolean isZone) {
687+
public List<Long> listClustersInZoneOrPodByHostCapacities(long id, long vmId, int requiredCpu, long requiredRam, boolean isZone) {
688688
TransactionLegacy txn = TransactionLegacy.currentTxn();
689689
PreparedStatement pstmt = null;
690690
List<Long> result = new ArrayList<Long>();
@@ -1068,7 +1068,65 @@ public Pair<List<Long>, Map<Long, Double>> orderHostsByFreeCapacity(Long zoneId,
10681068
}
10691069

10701070
@Override
1071-
public List<Long> listPodsByHostCapacities(long zoneId, int requiredCpu, long requiredRam, short capacityType) {
1071+
public List<CapacityVO> listHostCapacityByCapacityTypes(Long zoneId, Long clusterId, List<Short> capacityTypes) {
1072+
SearchBuilder<CapacityVO> sb = createSearchBuilder();
1073+
sb.and("zoneId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
1074+
sb.and("clusterId", sb.entity().getClusterId(), SearchCriteria.Op.EQ);
1075+
sb.and("capacityTypes", sb.entity().getCapacityType(), SearchCriteria.Op.IN);
1076+
sb.and("capacityState", sb.entity().getCapacityState(), Op.EQ);
1077+
sb.done();
1078+
1079+
SearchCriteria<CapacityVO> sc = sb.create();
1080+
sc.setParameters("capacityState", "Enabled");
1081+
if (zoneId != null) {
1082+
sc.setParameters("zoneId", zoneId);
1083+
}
1084+
if (clusterId != null) {
1085+
sc.setParameters("clusterId", clusterId);
1086+
}
1087+
sc.setParameters("capacityTypes", capacityTypes.toArray());
1088+
return listBy(sc);
1089+
}
1090+
1091+
@Override
1092+
public List<CapacityVO> listPodCapacityByCapacityTypes(Long zoneId, List<Short> capacityTypes) {
1093+
SearchBuilder<CapacityVO> sb = createSearchBuilder();
1094+
sb.and("zoneId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
1095+
sb.and("capacityTypes", sb.entity().getCapacityType(), SearchCriteria.Op.IN);
1096+
sb.and("capacityState", sb.entity().getCapacityState(), Op.EQ);
1097+
sb.done();
1098+
SearchCriteria<CapacityVO> sc = sb.create();
1099+
sc.setParameters("capacityState", "Enabled");
1100+
if (zoneId != null) {
1101+
sc.setParameters("zoneId", zoneId);
1102+
}
1103+
sc.setParameters("capacityTypes", capacityTypes.toArray());
1104+
return listBy(sc);
1105+
}
1106+
1107+
@Override
1108+
public List<CapacityVO> listClusterCapacityByCapacityTypes(Long zoneId, Long podId, List<Short> capacityTypes) {
1109+
SearchBuilder<CapacityVO> sb = createSearchBuilder();
1110+
sb.and("zoneId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
1111+
sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);
1112+
sb.and("capacityTypes", sb.entity().getCapacityType(), SearchCriteria.Op.IN);
1113+
sb.and("capacityState", sb.entity().getCapacityState(), Op.EQ);
1114+
sb.done();
1115+
1116+
SearchCriteria<CapacityVO> sc = sb.create();
1117+
sc.setParameters("capacityState", "Enabled");
1118+
if (zoneId != null) {
1119+
sc.setParameters("zoneId", zoneId);
1120+
}
1121+
if (podId != null) {
1122+
sc.setParameters("podId", podId);
1123+
}
1124+
sc.setParameters("capacityTypes", capacityTypes.toArray());
1125+
return listBy(sc);
1126+
}
1127+
1128+
@Override
1129+
public List<Long> listPodsByHostCapacities(long zoneId, int requiredCpu, long requiredRam) {
10721130
TransactionLegacy txn = TransactionLegacy.currentTxn();
10731131
PreparedStatement pstmt = null;
10741132
List<Long> result = new ArrayList<Long>();

engine/schema/src/main/resources/META-INF/db/schema-42010to42100.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,12 @@ SET `sort_key` = CASE
204204
END;
205205
-- End: Changes for Guest OS category cleanup
206206

207+
-- Update description for configuration: host.capacityType.to.order.clusters
208+
UPDATE `cloud`.`configuration` SET
209+
`description` = 'The host capacity type (CPU, RAM or COMBINED) is used by deployment planner to order clusters during VM resource allocation'
210+
WHERE `name` = 'host.capacityType.to.order.clusters'
211+
AND `description` = 'The host capacity type (CPU or RAM) is used by deployment planner to order clusters during VM resource allocation';
212+
207213
-- Whitelabel GUI
208214
CREATE TABLE IF NOT EXISTS `cloud`.`gui_themes` (
209215
`id` bigint(20) unsigned NOT NULL auto_increment,

0 commit comments

Comments
 (0)