sureshanaparti commented on code in PR #6809:
URL: https://github.com/apache/cloudstack/pull/6809#discussion_r1650092327
##########
engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java:
##########
@@ -1883,25 +1894,121 @@ protected Map<Long, List<Long>> getHostsPerZone() {
return hostsByZone;
}
- private void sendCommandToAgents(Map<Long, List<Long>> hostsPerZone,
Map<String, String> params) {
- SetHostParamsCommand cmds = new SetHostParamsCommand(params);
- for (Long zoneId : hostsPerZone.keySet()) {
- List<Long> hostIds = hostsPerZone.get(zoneId);
+ private void sendCommandToAgents(Map<Long, List<Long>> hostsPerZone,
LongFunction<Map<String, String>> paramsGenerator ) {
+ for (List<Long> hostIds : hostsPerZone.values()) {
for (Long hostId : hostIds) {
- Answer answer = easySend(hostId, cmds);
+ Answer answer = easySend(hostId, new
SetHostParamsCommand(paramsGenerator.apply(hostId)));
if (answer == null || !answer.getResult()) {
logger.error("Error sending parameters to agent {}",
hostId);
}
}
}
}
+ private long calculateAvailableMemoryOfHost(HostVO host){
+ long reservedMemory =
ByteScaleUtils.mebibytesToBytes(ConfigurationManagerImpl.HOST_RESERVED_MEM_MB.valueIn(host.getClusterId()));
+ return host.getTotalMemory() + host.getDom0MinMemory() -
reservedMemory;
+ }
+
+ private void updateMemoriesInDb(HostVO host, long newMemoryValue){
+ host.setTotalMemory(newMemoryValue);
+
+ // Update "dom0_memory" in host table
+
host.setDom0MinMemory(ByteScaleUtils.mebibytesToBytes(ConfigurationManagerImpl.HOST_RESERVED_MEM_MB.valueIn(host.getClusterId())));
+ _hostDao.update(host.getId(), host);
+
+ // Update the "total_capacity" for all hosts in op_host_capacity
+ CapacityVO memCap = capacityDao.findByHostIdType(host.getId(),
Capacity.CAPACITY_TYPE_MEMORY);
+ memCap.setTotalCapacity(host.getTotalMemory());
+ capacityDao.update(memCap.getId(), memCap);
+ }
+
+ private boolean updateHostMemory(HostVO host){
+ try {
+ // Update the "ram" for all hosts
+ long newMemoryValue = calculateAvailableMemoryOfHost(host);
+ if (newMemoryValue > 0) {
+ updateMemoriesInDb(host, newMemoryValue);
+ return true;
+ }
+ } catch (Exception e) {
+ s_logger.error("Unable to update the reserved memory capacity for
host id " + host.getId() + " : " + e.getMessage());
+ }
+ return false;
+ }
+
@Override
public void propagateChangeToAgents(Map<String, String> params) {
if (params != null && ! params.isEmpty()) {
logger.debug("Propagating changes on host parameters to the
agents");
Map<Long, List<Long>> hostsPerZone = getHostsPerZone();
- sendCommandToAgents(hostsPerZone, params);
+ sendCommandToAgents(hostsPerZone, id -> params);
+ }
+ }
+
+ @Override
+ public void updateCapacityOfHosts() {
+ Map<Long, List<Long>> hostsByZone = new HashMap<>();
+ boolean allHostMemoryValuesAreValid = true;
+
+ List<HostVO> allHosts =
_resourceMgr.listAllHostsInAllZonesByType(Host.Type.Routing);
+ if (CollectionUtils.isEmpty(allHosts)) {
+ return;
+ }
+
+ for (HostVO host : allHosts) {
+
+ boolean updateWasSuccessFull = updateHostMemory(host);
+
+ if (! updateWasSuccessFull){
+ allHostMemoryValuesAreValid = false;
+ continue;
+ }
+
+ Long zoneId = host.getDataCenterId();
+ List<Long> hostIds = hostsByZone.getOrDefault(zoneId, new
ArrayList<>());
+ hostIds.add(host.getId());
+ hostsByZone.put(zoneId, hostIds);
+ }
+
+ if (allHostMemoryValuesAreValid) {
+ sendCommandToAgents(hostsByZone,
+ hostId -> Collections.singletonMap(
+
ConfigurationManagerImpl.HOST_RESERVED_MEM_MB.key(),
+
ConfigurationManagerImpl.HOST_RESERVED_MEM_MB.valueIn(_hostDao.findById(hostId).getClusterId()).toString()));
+ }
+ }
+
+ @Override
+ public void updateCapacityOfHosts() {
Review Comment:
@benj-n this method implementation already exists, check above method.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]