Copilot commented on code in PR #11971:
URL: https://github.com/apache/cloudstack/pull/11971#discussion_r2603127687


##########
server/src/main/java/com/cloud/capacity/CapacityManagerImpl.java:
##########
@@ -761,28 +751,28 @@ public void updateCapacityForHost(final Host host) {
                 }
                 if (so.isDynamic()) {
                     reservedMemory +=
-                        
((Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.memory.name())) 
* 1024L * 1024L) / ramOvercommitRatio) *
-                            clusterRamOvercommitRatio;
+                            (long) 
(((Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.memory.name()))
 * 1024L * 1024L) / ramOvercommitRatio) *
+                                                        
clusterRamOvercommitRatio);
                     
if(vmDetails.containsKey(UsageEventVO.DynamicParameters.cpuSpeed.name())) {
                         reservedCpu +=
-                                
((Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.cpuNumber.name()))
 * 
Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.cpuSpeed.name())))
 / cpuOvercommitRatio) *
-                                        clusterCpuOvercommitRatio;
+                                (long) 
(((Long.parseLong(vmDetails.get(UsageEventVO.DynamicParameters.cpuNumber.name()))
 * 
Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.cpuSpeed.name())))
 / cpuOvercommitRatio) *
+                                                                        
clusterCpuOvercommitRatio);
                     } else {
                         reservedCpu +=
-                                
((Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.cpuNumber.name()))
 * so.getSpeed()) / cpuOvercommitRatio) *
-                                        clusterCpuOvercommitRatio;
+                                (long) 
(((Long.parseLong(vmDetails.get(UsageEventVO.DynamicParameters.cpuNumber.name()))
 * so.getSpeed()) / cpuOvercommitRatio) *

Review Comment:
   Inconsistent parsing method used for cpuNumber parameter. This line uses 
`Long.parseLong()` while the similar code at line 718 (for used capacity 
calculation) uses `Integer.parseInt()` for the same parameter. For consistency 
and correctness, both should use the same parsing method, preferably 
`Integer.parseInt()` since cpuNumber is used as an integer elsewhere in the 
code (e.g., lines 721, 765).



##########
server/src/main/java/com/cloud/capacity/CapacityManagerImpl.java:
##########
@@ -761,28 +751,28 @@ public void updateCapacityForHost(final Host host) {
                 }
                 if (so.isDynamic()) {
                     reservedMemory +=
-                        
((Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.memory.name())) 
* 1024L * 1024L) / ramOvercommitRatio) *
-                            clusterRamOvercommitRatio;
+                            (long) 
(((Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.memory.name()))
 * 1024L * 1024L) / ramOvercommitRatio) *
+                                                        
clusterRamOvercommitRatio);
                     
if(vmDetails.containsKey(UsageEventVO.DynamicParameters.cpuSpeed.name())) {
                         reservedCpu +=
-                                
((Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.cpuNumber.name()))
 * 
Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.cpuSpeed.name())))
 / cpuOvercommitRatio) *
-                                        clusterCpuOvercommitRatio;
+                                (long) 
(((Long.parseLong(vmDetails.get(UsageEventVO.DynamicParameters.cpuNumber.name()))
 * 
Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.cpuSpeed.name())))
 / cpuOvercommitRatio) *

Review Comment:
   Inconsistent parsing method used for cpuNumber parameter. This line uses 
`Long.parseLong()` while the similar code at line 713 (for used capacity 
calculation) uses `Integer.parseInt()` for the same parameter. For consistency 
and correctness, both should use the same parsing method, preferably 
`Integer.parseInt()` since cpuNumber is used as an integer elsewhere in the 
code (e.g., lines 721, 765).



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