mirror of https://github.com/apache/cloudstack.git
server,engine-schema: use single query to to list host capacities while
host capacity update Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
parent
98b27a409d
commit
fe4ef05053
|
|
@ -28,6 +28,8 @@ import com.cloud.utils.db.GenericDao;
|
|||
public interface CapacityDao extends GenericDao<CapacityVO, Long> {
|
||||
CapacityVO findByHostIdType(Long hostId, short capacityType);
|
||||
|
||||
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> listHostsWithEnoughCapacity(int requiredCpu, long requiredRam, Long clusterId, String hostType);
|
||||
|
|
|
|||
|
|
@ -674,6 +674,18 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
|
|||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CapacityVO> listByHostIdTypes(Long hostId, List<Short> capacityTypes) {
|
||||
SearchBuilder<CapacityVO> sb = createSearchBuilder();
|
||||
sb.and("hostId", sb.entity().getHostOrPoolId(), SearchCriteria.Op.EQ);
|
||||
sb.and("type", sb.entity().getCapacityType(), SearchCriteria.Op.IN);
|
||||
sb.done();
|
||||
SearchCriteria<CapacityVO> sc = sb.create();
|
||||
sc.setParameters("hostId", hostId);
|
||||
sc.setParameters("type", capacityTypes.toArray());
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> listClustersInZoneOrPodByHostCapacities(long id, long vmId, int requiredCpu, long requiredRam, short capacityTypeForOrdering, boolean isZone) {
|
||||
TransactionLegacy txn = TransactionLegacy.currentTxn();
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ import org.apache.cloudstack.utils.cache.LazyCache;
|
|||
import org.apache.cloudstack.utils.cache.SingleCache;
|
||||
import org.apache.cloudstack.utils.executor.QueuedExecutor;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
|
|
@ -801,9 +802,24 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
|
|||
}
|
||||
}
|
||||
|
||||
CapacityVO cpuCap = _capacityDao.findByHostIdType(host.getId(), Capacity.CAPACITY_TYPE_CPU);
|
||||
CapacityVO memCap = _capacityDao.findByHostIdType(host.getId(), Capacity.CAPACITY_TYPE_MEMORY);
|
||||
CapacityVO cpuCoreCap = _capacityDao.findByHostIdType(host.getId(), CapacityVO.CAPACITY_TYPE_CPU_CORE);
|
||||
List<CapacityVO> capacities = _capacityDao.listByHostIdTypes(host.getId(), List.of(Capacity.CAPACITY_TYPE_CPU,
|
||||
Capacity.CAPACITY_TYPE_MEMORY,
|
||||
CapacityVO.CAPACITY_TYPE_CPU_CORE));
|
||||
CapacityVO cpuCap = null;
|
||||
CapacityVO memCap = null;
|
||||
CapacityVO cpuCoreCap = null;
|
||||
for (CapacityVO c : capacities) {
|
||||
if (c.getCapacityType() == Capacity.CAPACITY_TYPE_CPU) {
|
||||
cpuCap = c;
|
||||
} else if (c.getCapacityType() == Capacity.CAPACITY_TYPE_MEMORY) {
|
||||
memCap = c;
|
||||
} else if (c.getCapacityType() == Capacity.CAPACITY_TYPE_CPU_CORE) {
|
||||
cpuCoreCap = c;
|
||||
}
|
||||
if (ObjectUtils.allNotNull(cpuCap, memCap, cpuCoreCap)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (cpuCoreCap != null) {
|
||||
long hostTotalCpuCore = host.getCpus().longValue();
|
||||
|
|
|
|||
Loading…
Reference in New Issue