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


##########
server/src/main/java/com/cloud/resource/RollingMaintenanceManagerImpl.java:
##########
@@ -622,9 +628,35 @@ private Pair<Boolean, String> 
performCapacityChecksBeforeHostInMaintenance(Host
         for (VMInstanceVO runningVM : vmsRunning) {
             boolean canMigrateVm = false;
             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());
+                            }
+                            if (speed == null && 
VmDetailConstants.CPU_SPEED.equals(vmDetail.getName())) {
+                                speed = Integer.valueOf(vmDetail.getValue());
+                            }
+                            if (ramSize == null && 
VmDetailConstants.MEMORY.equals(vmDetail.getName())) {
+                                ramSize = Integer.valueOf(vmDetail.getValue());
+                            }
+                        }
+                    }
+                }
+            }
+            if (cpu == null || speed == null || ramSize == null) {

Review Comment:
   Could use `ObjectUtils.anyNull()`



##########
server/src/main/java/com/cloud/resource/RollingMaintenanceManagerImpl.java:
##########
@@ -622,9 +628,35 @@ private Pair<Boolean, String> 
performCapacityChecksBeforeHostInMaintenance(Host
         for (VMInstanceVO runningVM : vmsRunning) {
             boolean canMigrateVm = false;
             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) {

Review Comment:
   ```suggestion
                           if (vmDetail.getName() != null && 
vmDetail.getValue() != null) {
   ```



##########
server/src/main/java/com/cloud/resource/RollingMaintenanceManagerImpl.java:
##########
@@ -622,9 +628,35 @@ private Pair<Boolean, String> 
performCapacityChecksBeforeHostInMaintenance(Host
         for (VMInstanceVO runningVM : vmsRunning) {
             boolean canMigrateVm = false;
             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());
+                            }
+                            if (speed == null && 
VmDetailConstants.CPU_SPEED.equals(vmDetail.getName())) {
+                                speed = Integer.valueOf(vmDetail.getValue());
+                            }
+                            if (ramSize == null && 
VmDetailConstants.MEMORY.equals(vmDetail.getName())) {
+                                ramSize = Integer.valueOf(vmDetail.getValue());
+                            }
+                        }
+                    }
+                }
+            }
+            if (cpu == null || speed == null || ramSize == null) {
+                s_logger.warn(String.format("Cannot fetch compute resources 
for the VM %s, skipping it from the capacity check", runningVM));
+                continue;
+            }

Review Comment:
   Definitely, also, maybe add some unit tests for the created method?



##########
server/src/main/java/com/cloud/resource/RollingMaintenanceManagerImpl.java:
##########
@@ -622,9 +628,35 @@ private Pair<Boolean, String> 
performCapacityChecksBeforeHostInMaintenance(Host
         for (VMInstanceVO runningVM : vmsRunning) {
             boolean canMigrateVm = false;
             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());
+                            }
+                            if (speed == null && 
VmDetailConstants.CPU_SPEED.equals(vmDetail.getName())) {
+                                speed = Integer.valueOf(vmDetail.getValue());
+                            }
+                            if (ramSize == null && 
VmDetailConstants.MEMORY.equals(vmDetail.getName())) {
+                                ramSize = Integer.valueOf(vmDetail.getValue());
+                            }

Review Comment:
   these last two `if`s should be `else if`s



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