shwstppr commented on code in PR #9840:
URL: https://github.com/apache/cloudstack/pull/9840#discussion_r1828947089


##########
server/src/main/java/com/cloud/alert/AlertManagerImpl.java:
##########
@@ -257,6 +259,64 @@ public void sendAlert(AlertType alertType, long 
dataCenterId, Long podId, String
         }
     }
 
+    protected void recalculateHostCapacities() {
+        // Calculate CPU and RAM capacities
+        List<Long> hostIds = hostDao.listIdsByType(Host.Type.Routing);
+        if (hostIds.isEmpty()) {
+            return;
+        }
+        ConcurrentHashMap<Long, Future<Void>> futures = new 
ConcurrentHashMap<>();
+        ExecutorService executorService = 
Executors.newFixedThreadPool(Math.max(1,
+                Math.min(CapacityManager.CapacityCalculateWorkers.value(), 
hostIds.size())));
+        for (Long hostId : hostIds) {
+            futures.put(hostId, executorService.submit(() -> {
+                final HostVO host = hostDao.findById(hostId);
+                _capacityMgr.updateCapacityForHost(host);
+                return null;
+            }));
+        }
+        for (Map.Entry<Long, Future<Void>> entry: futures.entrySet()) {
+            try {
+                entry.getValue().get();
+            } catch (InterruptedException | ExecutionException e) {
+                logger.error(String.format("Error during capacity calculation 
for host: %d due to : %s",
+                        entry.getKey(), e.getMessage()), e);
+            }
+        }
+        executorService.shutdown();
+    }
+
+    protected void recalculateStorageCapacities() {
+        List<Long> storagePoolIds = _storagePoolDao.listAllIds();
+        if (storagePoolIds.isEmpty()) {
+            return;
+        }
+        ConcurrentHashMap<Long, Future<Void>> futures = new 
ConcurrentHashMap<>();
+        ExecutorService executorService = 
Executors.newFixedThreadPool(Math.max(1,

Review Comment:
   It uses Math.min(value of `capacity.calculate.workers` and size of 
hosts/pools). Config can be set a negative value (though edge case and operator 
error) and when Executors.newFixedThreadPool is instantiated with <1 it may 
produce exception



-- 
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: commits-unsubscr...@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to