Skip to content

Commit

Permalink
Cosmetic changes and double implementation fix
Browse files Browse the repository at this point in the history
  • Loading branch information
benj-n committed Jun 25, 2024
1 parent 5222343 commit b1719c5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1905,12 +1905,12 @@ private void sendCommandToAgents(Map<Long, List<Long>> hostsPerZone, LongFunctio
}
}

private long calculateAvailableMemoryOfHost(HostVO host){
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){
private void updateMemoriesInDb(HostVO host, long newMemoryValue) {
host.setTotalMemory(newMemoryValue);

// Update "dom0_memory" in host table
Expand All @@ -1923,7 +1923,7 @@ private void updateMemoriesInDb(HostVO host, long newMemoryValue){
capacityDao.update(memCap.getId(), memCap);
}

private boolean updateHostMemory(HostVO host){
private boolean updateHostMemory(HostVO host) {
try {
// Update the "ram" for all hosts
long newMemoryValue = calculateAvailableMemoryOfHost(host);
Expand Down Expand Up @@ -1957,43 +1957,9 @@ public void updateCapacityOfHosts() {
}

for (HostVO host : allHosts) {
boolean updateWasSuccessful = updateHostMemory(host);

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() {
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){
if (!updateWasSuccessful) {
allHostMemoryValuesAreValid = false;
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@
import com.cloud.vm.VmDetailConstants;
import com.google.gson.Gson;


/**
* LibvirtComputingResource execute requests on the computing/routing host using
* the libvirt API
Expand Down Expand Up @@ -1455,7 +1454,7 @@ private void validateLocalStorageUUID(String localStorageUUID) throws Configurat
}
}

private void updateDom0MinMem(PropertiesStorage storage, final Map<String, String> params){
private void updateDom0MinMem(PropertiesStorage storage, final Map<String, String> params) {
long value = Long.parseLong(params.get(ConfigurationManagerImpl.HOST_RESERVED_MEM_MB.key()));
s_logger.info("Reserved memory for host is " + value + "MB");
dom0MinMem = ByteScaleUtils.mebibytesToBytes(value);
Expand Down

0 comments on commit b1719c5

Please sign in to comment.