Skip to content
5 changes: 5 additions & 0 deletions api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ public class ApiConstants {
public static final String CONVERT_INSTANCE_HOST_ID = "convertinstancehostid";
public static final String CONVERT_INSTANCE_STORAGE_POOL_ID = "convertinstancepoolid";
public static final String ENABLED_REVOCATION_CHECK = "enabledrevocationcheck";
public static final String COMBINED_CAPACITY_ORDERING = "COMBINED";
public static final String CONTROLLER = "controller";
public static final String CONTROLLER_UNIT = "controllerunit";
public static final String COPY_IMAGE_TAGS = "copyimagetags";
public static final String CPU_OVERCOMMIT_RATIO = "cpuOvercommitRatio";
public static final String CSR = "csr";
public static final String PRIVATE_KEY = "privatekey";
public static final String DATASTORE_HOST = "datastorehost";
Expand Down Expand Up @@ -120,6 +122,7 @@ public class ApiConstants {
public static final String COMMAND = "command";
public static final String CMD_EVENT_TYPE = "cmdeventtype";
public static final String COMPONENT = "component";
public static final String CPU = "CPU";
public static final String CPU_CORE_PER_SOCKET = "cpucorepersocket";
public static final String CPU_NUMBER = "cpunumber";
public static final String CPU_SPEED = "cpuspeed";
Expand Down Expand Up @@ -338,6 +341,7 @@ public class ApiConstants {
public static final String MAX_BACKUPS = "maxbackups";
public static final String MAX_CPU_NUMBER = "maxcpunumber";
public static final String MAX_MEMORY = "maxmemory";
public static final String MEMORY_OVERCOMMIT_RATIO = "memoryOvercommitRatio";
public static final String MIN_CPU_NUMBER = "mincpunumber";
public static final String MIN_MEMORY = "minmemory";
public static final String MIGRATION_TYPE = "migrationtype";
Expand Down Expand Up @@ -433,6 +437,7 @@ public class ApiConstants {
public static final String PUBLIC_END_PORT = "publicendport";
public static final String PUBLIC_ZONE = "publiczone";
public static final String PURGE_RESOURCES = "purgeresources";
public static final String RAM = "RAM";
public static final String RECEIVED_BYTES = "receivedbytes";
public static final String RECONNECT = "reconnect";
public static final String RECOVER = "recover";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public interface ConfigurationManager {
"allow.non.rfc1918.compliant.ips", "Advanced", "false",
"Allows non-compliant RFC 1918 IPs for Shared, Isolated networks and VPCs", true, null);

ConfigKey<Float> HostCapacityTypeCpuMemoryWeight = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, Float.class, "host.capacityType.to.order.clusters.cputomemoryweight",
"0.5",
"CPU to Memory weight used for COMBINED capacityTye to order cluster and host",
true, ConfigKey.Scope.Global);

/**
* @param offering
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface CapacityDao extends GenericDao<CapacityVO, Long> {

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

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

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

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

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

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

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

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

Pair<List<Long>, Map<Long, Double>> orderHostsByFreeCapacity(Long zoneId, Long clusterId, short capacityType);

List<CapacityVO> listHostCapacityByCapacityTypes(Long zoneId, Long clusterId, List<Short> capacityTypes);

List<CapacityVO> listPodCapacityByCapacityTypes(Long zoneId, List<Short> capacityTypes);

List<CapacityVO> listClusterCapacityByCapacityTypes(Long zoneId, Long podId, long vmId, List<Short> capacityTypes);
}
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@
}

@Override
public List<Long> listClustersInZoneOrPodByHostCapacities(long id, long vmId, int requiredCpu, long requiredRam, short capacityTypeForOrdering, boolean isZone) {
public List<Long> listClustersInZoneOrPodByHostCapacities(long id, long vmId, int requiredCpu, long requiredRam, boolean isZone) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = null;
List<Long> result = new ArrayList<Long>();
Expand Down Expand Up @@ -1068,7 +1068,65 @@
}

@Override
public List<Long> listPodsByHostCapacities(long zoneId, int requiredCpu, long requiredRam, short capacityType) {
public List<CapacityVO> listHostCapacityByCapacityTypes(Long zoneId, Long clusterId, List<Short> capacityTypes) {
SearchBuilder<CapacityVO> sb = createSearchBuilder();
sb.and("zoneId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
sb.and("clusterId", sb.entity().getClusterId(), SearchCriteria.Op.EQ);
sb.and("capacityTypes", sb.entity().getCapacityType(), SearchCriteria.Op.IN);
sb.and("capacityState", sb.entity().getCapacityState(), Op.EQ);
sb.done();

Check warning on line 1077 in engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java#L1071-L1077

Added lines #L1071 - L1077 were not covered by tests

SearchCriteria<CapacityVO> sc = sb.create();
sc.setParameters("capacityState", "Enabled");

Check warning on line 1080 in engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java#L1079-L1080

Added lines #L1079 - L1080 were not covered by tests
if (zoneId != null) {
sc.setParameters("zoneId", zoneId);

Check warning on line 1082 in engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1082 was not covered by tests
}
if (clusterId != null) {
sc.setParameters("clusterId", clusterId);

Check warning on line 1085 in engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1085 was not covered by tests
}
sc.setParameters("capacityTypes", capacityTypes.toArray());
return listBy(sc);
}

Check warning on line 1089 in engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java#L1087-L1089

Added lines #L1087 - L1089 were not covered by tests

@Override
public List<CapacityVO> listPodCapacityByCapacityTypes(Long zoneId, List<Short> capacityTypes) {
SearchBuilder<CapacityVO> sb = createSearchBuilder();
sb.and("zoneId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
sb.and("capacityTypes", sb.entity().getCapacityType(), SearchCriteria.Op.IN);
sb.and("capacityState", sb.entity().getCapacityState(), Op.EQ);
sb.done();
SearchCriteria<CapacityVO> sc = sb.create();
sc.setParameters("capacityState", "Enabled");

Check warning on line 1099 in engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java#L1092-L1099

Added lines #L1092 - L1099 were not covered by tests
if (zoneId != null) {
sc.setParameters("zoneId", zoneId);

Check warning on line 1101 in engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1101 was not covered by tests
}
sc.setParameters("capacityTypes", capacityTypes.toArray());
return listBy(sc);
}

Check warning on line 1105 in engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java#L1103-L1105

Added lines #L1103 - L1105 were not covered by tests

@Override
public List<CapacityVO> listClusterCapacityByCapacityTypes(Long zoneId, Long podId, long vmId, List<Short> capacityTypes) {
SearchBuilder<CapacityVO> sb = createSearchBuilder();
sb.and("zoneId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);
sb.and("capacityTypes", sb.entity().getCapacityType(), SearchCriteria.Op.IN);
sb.and("capacityState", sb.entity().getCapacityState(), Op.EQ);
sb.done();

Check warning on line 1114 in engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java#L1108-L1114

Added lines #L1108 - L1114 were not covered by tests

SearchCriteria<CapacityVO> sc = sb.create();
sc.setParameters("capacityState", "Enabled");

Check warning on line 1117 in engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java#L1116-L1117

Added lines #L1116 - L1117 were not covered by tests
if (zoneId != null) {
sc.setParameters("zoneId", zoneId);

Check warning on line 1119 in engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1119 was not covered by tests
}
if (podId != null) {
sc.setParameters("podId", podId);

Check warning on line 1122 in engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1122 was not covered by tests
}
sc.setParameters("capacityTypes", capacityTypes.toArray());
return listBy(sc);
}

Check warning on line 1126 in engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java#L1124-L1126

Added lines #L1124 - L1126 were not covered by tests

@Override
public List<Long> listPodsByHostCapacities(long zoneId, int requiredCpu, long requiredRam) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = null;
List<Long> result = new ArrayList<Long>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,9 @@ SET `sort_key` = CASE
ELSE `sort_key`
END;
-- End: Changes for Guest OS category cleanup

-- Update description for configuration: host.capacityType.to.order.clusters
UPDATE `cloud`.`configuration` SET
`description` = 'The host capacity type (CPU, RAM or COMBINED) is used by deployment planner to order clusters during VM resource allocation'
WHERE `name` = 'host.capacityType.to.order.clusters'
AND `description` = 'The host capacity type (CPU or RAM) is used by deployment planner to order clusters during VM resource allocation';
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,11 @@ public void testListClustersInZoneOrPodByHostCapacitiesEmpty() throws Exception
when(pstmt.executeQuery()).thenReturn(resultSet);
when(resultSet.next()).thenReturn(false);

List<Long> resultZone = capacityDao.listClustersInZoneOrPodByHostCapacities(1L, 123L, 2, 2048L, (short)0, true);
List<Long> resultZone = capacityDao.listClustersInZoneOrPodByHostCapacities(1L, 123L, 2, 2048L, true);
assertNotNull(resultZone);
assertTrue(resultZone.isEmpty());

List<Long> resultPod = capacityDao.listClustersInZoneOrPodByHostCapacities(1L, 123L, 2, 2048L, (short)0, false);
List<Long> resultPod = capacityDao.listClustersInZoneOrPodByHostCapacities(1L, 123L, 2, 2048L, false);
assertNotNull(resultPod);
assertTrue(resultPod.isEmpty());
}
Expand Down Expand Up @@ -281,7 +281,7 @@ public void testListPodsByHostCapacitiesEmptyResult() throws Exception {
when(pstmt.executeQuery()).thenReturn(resultSet);
when(resultSet.next()).thenReturn(false);

List<Long> result = capacityDao.listPodsByHostCapacities(1L, 2, 1024L, (short)0);
List<Long> result = capacityDao.listPodsByHostCapacities(1L, 2, 1024L);
assertNotNull(result);
assertTrue(result.isEmpty());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ private void initializeForTest(VirtualMachineProfileImpl vmProfile, DataCenterDe
clustersWithEnoughCapacity.add(3L);
when(
capacityDao.listClustersInZoneOrPodByHostCapacities(dataCenterId, 12L, noOfCpusInOffering * cpuSpeedInOffering, ramInOffering * 1024L * 1024L,
Capacity.CAPACITY_TYPE_CPU, true)).thenReturn(clustersWithEnoughCapacity);
true)).thenReturn(clustersWithEnoughCapacity);

Map<Long, Double> clusterCapacityMap = new HashMap<Long, Double>();
clusterCapacityMap.put(1L, 2048D);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
import javax.naming.ConfigurationException;

import com.cloud.agent.manager.allocator.HostAllocator;
import com.cloud.capacity.Capacity;
import com.cloud.capacity.CapacityManager;
import com.cloud.capacity.CapacityVO;
import com.cloud.capacity.dao.CapacityDao;
import com.cloud.configuration.Config;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.dc.ClusterDetailsDao;
import com.cloud.dc.dao.ClusterDao;
import com.cloud.deploy.DeploymentPlan;
Expand Down Expand Up @@ -64,9 +66,11 @@
import com.cloud.vm.dao.UserVmDetailsDao;
import com.cloud.vm.dao.VMInstanceDao;

import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;

import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;

/**
Expand Down Expand Up @@ -295,7 +299,7 @@
Collections.shuffle(hosts);
} else if (vmAllocationAlgorithm.equals("userdispersing")) {
hosts = reorderHostsByNumberOfVms(plan, hosts, account);
}else if(vmAllocationAlgorithm.equals("firstfitleastconsumed")){
} else if(vmAllocationAlgorithm.equals("firstfitleastconsumed")){
hosts = reorderHostsByCapacity(plan, hosts);
}

Expand Down Expand Up @@ -372,13 +376,7 @@
private List<? extends Host> reorderHostsByCapacity(DeploymentPlan plan, List<? extends Host> hosts) {
Long zoneId = plan.getDataCenterId();
Long clusterId = plan.getClusterId();
//Get capacity by which we should reorder
String capacityTypeToOrder = _configDao.getValue(Config.HostCapacityTypeToOrderClusters.key());
short capacityType = CapacityVO.CAPACITY_TYPE_CPU;
if("RAM".equalsIgnoreCase(capacityTypeToOrder)){
capacityType = CapacityVO.CAPACITY_TYPE_MEMORY;
}
Pair<List<Long>, Map<Long, Double>> result = _capacityDao.orderHostsByFreeCapacity(zoneId, clusterId, capacityType);
Pair<List<Long>, Map<Long, Double>> result = getOrderedHostsByCapacity(zoneId, clusterId);

Check warning on line 379 in server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java#L379

Added line #L379 was not covered by tests
List<Long> hostIdsByFreeCapacity = result.first();
Map<Long, String> sortedHostByCapacity = result.second().entrySet()
.stream()
Expand Down Expand Up @@ -407,6 +405,54 @@
return reorderedHosts;
}

private Pair<List<Long>, Map<Long, Double>> getOrderedHostsByCapacity(Long zoneId, Long clusterId) {
double cpuToMemoryWeight = ConfigurationManager.HostCapacityTypeCpuMemoryWeight.value();

Check warning on line 409 in server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java#L408-L409

Added lines #L408 - L409 were not covered by tests
// Get capacity by which we should reorder
short capacityType = getCapacityType(cpuToMemoryWeight);

Check warning on line 411 in server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java#L411

Added line #L411 was not covered by tests
if (capacityType >= 0) { // for CPU or RAM
return _capacityDao.orderHostsByFreeCapacity(zoneId, clusterId, capacityType);

Check warning on line 413 in server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java#L413

Added line #L413 was not covered by tests
}
List<CapacityVO> capacities = _capacityDao.listHostCapacityByCapacityTypes(zoneId, clusterId,
List.of(Capacity.CAPACITY_TYPE_CPU, Capacity.CAPACITY_TYPE_MEMORY));
Map<Long, Double> hostByComputedCapacity = getHostByCombinedCapacities(capacities, cpuToMemoryWeight);
return new Pair<>(new ArrayList<>(hostByComputedCapacity.keySet()), hostByComputedCapacity);
}

Check warning on line 419 in server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java#L415-L419

Added lines #L415 - L419 were not covered by tests

short getCapacityType(double cpuToMemoryWeight) {
String capacityTypeToOrder = _configDao.getValue(Config.HostCapacityTypeToOrderClusters.key());
short capacityType = CapacityVO.CAPACITY_TYPE_CPU;

Check warning on line 423 in server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java#L421-L423

Added lines #L421 - L423 were not covered by tests
if (ApiConstants.RAM.equalsIgnoreCase(capacityTypeToOrder)){
capacityType = CapacityVO.CAPACITY_TYPE_MEMORY;

Check warning on line 425 in server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java#L425

Added line #L425 was not covered by tests
} else if (ApiConstants.COMBINED_CAPACITY_ORDERING.equalsIgnoreCase(capacityTypeToOrder)) {
capacityType = -1;

Check warning on line 427 in server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java#L427

Added line #L427 was not covered by tests
}

if (cpuToMemoryWeight == 1) {
capacityType = CapacityVO.CAPACITY_TYPE_CPU;

Check warning on line 431 in server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java#L431

Added line #L431 was not covered by tests
}
if (cpuToMemoryWeight == 0) {
capacityType = CapacityVO.CAPACITY_TYPE_MEMORY;

Check warning on line 434 in server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java#L434

Added line #L434 was not covered by tests
}
return capacityType;
}

Check warning on line 437 in server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java#L436-L437

Added lines #L436 - L437 were not covered by tests


@NotNull
private static Map<Long, Double> getHostByCombinedCapacities(List<CapacityVO> capacities, double cpuToMemoryWeight) {
Map<Long, Double> hostByComputedCapacity = new HashMap<>();

Check warning on line 442 in server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java#L441-L442

Added lines #L441 - L442 were not covered by tests
for (CapacityVO capacityVO : capacities) {
long hostId = capacityVO.getHostOrPoolId();

Check warning on line 444 in server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java#L444

Added line #L444 was not covered by tests
double applicableWeight = capacityVO.getCapacityType() == Capacity.CAPACITY_TYPE_CPU ? cpuToMemoryWeight : 1 - cpuToMemoryWeight;
double capacityMetric = applicableWeight * (capacityVO.getTotalCapacity() - (capacityVO.getUsedCapacity() + capacityVO.getReservedCapacity()))/capacityVO.getTotalCapacity();
hostByComputedCapacity.merge(hostId, capacityMetric, Double::sum);
}

Check warning on line 448 in server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java#L446-L448

Added lines #L446 - L448 were not covered by tests

return hostByComputedCapacity.entrySet()
.stream()
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
}

Check warning on line 454 in server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java#L450-L454

Added lines #L450 - L454 were not covered by tests

private List<? extends Host> reorderHostsByNumberOfVms(DeploymentPlan plan, List<? extends Host> hosts, Account account) {
if (account == null) {
return hosts;
Expand Down
5 changes: 3 additions & 2 deletions server/src/main/java/com/cloud/configuration/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -897,8 +897,9 @@ public enum Config {
String.class,
"host.capacityType.to.order.clusters",
"CPU",
"The host capacity type (CPU or RAM) is used by deployment planner to order clusters during VM resource allocation",
"CPU,RAM"),
"The host capacity type (CPU, RAM, COMBINED) is used by deployment planner to order clusters during VM resource allocation",
"CPU,RAM,COMBINED"),

ApplyAllocationAlgorithmToPods(
"Advanced",
ManagementServer.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8252,7 +8252,7 @@ public ConfigKey<?>[] getConfigKeys() {
BYTES_MAX_READ_LENGTH, BYTES_MAX_WRITE_LENGTH, ADD_HOST_ON_SERVICE_RESTART_KVM, SET_HOST_DOWN_TO_MAINTENANCE,
VM_SERVICE_OFFERING_MAX_CPU_CORES, VM_SERVICE_OFFERING_MAX_RAM_SIZE, MIGRATE_VM_ACROSS_CLUSTERS,
ENABLE_ACCOUNT_SETTINGS_FOR_DOMAIN, ENABLE_DOMAIN_SETTINGS_FOR_CHILD_DOMAIN,
ALLOW_DOMAIN_ADMINS_TO_CREATE_TAGGED_OFFERINGS, DELETE_QUERY_BATCH_SIZE, AllowNonRFC1918CompliantIPs
ALLOW_DOMAIN_ADMINS_TO_CREATE_TAGGED_OFFERINGS, DELETE_QUERY_BATCH_SIZE, AllowNonRFC1918CompliantIPs, HostCapacityTypeCpuMemoryWeight
};
}

Expand Down
Loading
Loading