DaanHoogland commented on code in PR #9844:
URL: https://github.com/apache/cloudstack/pull/9844#discussion_r1869652795


##########
server/src/main/java/com/cloud/resource/RollingMaintenanceManagerImpl.java:
##########
@@ -666,11 +682,36 @@ private Pair<Boolean, String> 
performCapacityChecksBeforeHostInMaintenance(Host
         return new Pair<>(true, "OK");
     }
 
+    protected Ternary<Integer, Integer, Integer> 
getComputeResourcesCpuSpeedAndRamSize(VMInstanceVO runningVM) {
+        ServiceOfferingVO serviceOffering = 
serviceOfferingDao.findById(runningVM.getServiceOfferingId());
+        Integer cpu = serviceOffering.getCpu();
+        Integer speed = serviceOffering.getSpeed();
+        Integer ramSize = serviceOffering.getRamSize();
+        if (serviceOffering.isDynamic()) {
+            List<UserVmDetailVO> vmDetails = 
userVmDetailsDao.listDetails(runningVM.getId());
+            if (CollectionUtils.isNotEmpty(vmDetails)) {
+                for (UserVmDetailVO vmDetail : vmDetails) {
+                    if (vmDetail.getName() != null && vmDetail.getValue() != 
null) {
+                        if (cpu == null && 
VmDetailConstants.CPU_NUMBER.equals(vmDetail.getName())) {
+                            cpu = Integer.valueOf(vmDetail.getValue());
+                        } else if (speed == null && 
VmDetailConstants.CPU_SPEED.equals(vmDetail.getName())) {
+                            speed = Integer.valueOf(vmDetail.getValue());
+                        } else if (ramSize == null && 
VmDetailConstants.MEMORY.equals(vmDetail.getName())) {
+                            ramSize = Integer.valueOf(vmDetail.getValue());
+                        }
+                    }
+                }
+            }
+        }

Review Comment:
   @JoaoJandre @BryanMLima , I think this version is actually less readable as 
it contains multiple exit points. I prefer leaving this as is, maybe 
re-factoring out an extra method. The cyclic complexity of this method is high 
and the extra exits does not reduce it. (and yes, I think 7 is high and I am 
not counting the `== null &&`) 
   @sureshanaparti I won't minus one if you apply this but I do not agree with 
this suggestion.



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

Reply via email to