DaanHoogland commented on a change in pull request #4884:
URL: https://github.com/apache/cloudstack/pull/4884#discussion_r608419781



##########
File path: 
plugins/host-allocators/random/src/main/java/com/cloud/agent/manager/allocator/impl/RandomAllocator.java
##########
@@ -146,14 +165,23 @@
             if (suitableHosts.size() == returnUpTo) {
                 break;
             }
-
-            if (!avoid.shouldAvoid(host)) {
-                suitableHosts.add(host);
-            } else {
+            if (avoid.shouldAvoid(host)) {
                 if (s_logger.isDebugEnabled()) {
                     s_logger.debug("Host name: " + host.getName() + ", hostId: 
" + host.getId() + " is in avoid set, skipping this and trying other available 
hosts");
                 }
+                continue;
+            }
+            Pair<Boolean, Boolean> cpuCapabilityAndCapacity = 
capacityManager.checkIfHostHasCpuCapabilityAndCapacity(host, offering, 
considerReservedCapacity);
+            if (!cpuCapabilityAndCapacity.first() || 
!cpuCapabilityAndCapacity.second()) {
+                if (s_logger.isDebugEnabled()) {
+                    s_logger.debug("Not using host " + host.getId() + "; host 
has cpu capability? " + cpuCapabilityAndCapacity.first() + ", host has 
capacity?" + cpuCapabilityAndCapacity.second());
+                }
+                continue;
+            }
+            if (s_logger.isDebugEnabled()) {
+                s_logger.debug("Found a suitable host, adding to list: " + 
host.getId());
             }
+            suitableHosts.add(host);

Review comment:
       this bit is exactly the same as above. it should go in a method. also 
the exact same log message being logged at two different points in the code is 
a suspect pattern. please unite the bits or make them truly different, for 
easier debugging.




-- 
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to