JoaoJandre commented on code in PR #8234:
URL: https://github.com/apache/cloudstack/pull/8234#discussion_r1483100238
##########
server/src/main/java/com/cloud/vm/UserVmManagerImpl.java:
##########
@@ -1227,6 +1227,39 @@ public UserVm upgradeVirtualMachine(UpgradeVMCmd cmd)
throws ResourceAllocationE
return userVm;
}
+ /**
+ Updates the instance details map with the current values of the instance
for the CPU speed, memory, and CPU number if they have not been specified.
+ @param details Map containing the instance details.
+ @param vmInstance The virtual machine instance.
+ @param newServiceOfferingId The ID of the new service offering.
+ */
+
+ protected void updateInstanceDetails (Map<String, String> details,
VirtualMachine vmInstance, Long newServiceOfferingId) {
+ ServiceOfferingVO currentServiceOffering =
serviceOfferingDao.findByIdIncludingRemoved(vmInstance.getId(),
vmInstance.getServiceOfferingId());
+ ServiceOfferingVO newServiceOffering =
serviceOfferingDao.findById(newServiceOfferingId);
+
updateInstanceDetailsKeepCurrentValueIfNull(newServiceOffering.getSpeed(),
details, VmDetailConstants.CPU_SPEED, currentServiceOffering.getSpeed());
+
updateInstanceDetailsKeepCurrentValueIfNull(newServiceOffering.getRamSize(),
details, VmDetailConstants.MEMORY, currentServiceOffering.getRamSize());
+
updateInstanceDetailsKeepCurrentValueIfNull(newServiceOffering.getCpu(),
details, VmDetailConstants.CPU_NUMBER, currentServiceOffering.getCpu());
+ }
+
+ /**
+ * Updates a specific instance detail with the current instance value if
the new value is null.
+ *
+ * @param newValue the new value to be set
+ * @param details a map of instance details
+ * @param detailsConstant the name of the detail constant to be updated
+ * @param currentValue the current value of the detail constant
+ */
+
+ protected void updateInstanceDetailsKeepCurrentValueIfNull(Integer
newValue, Map<String, String> details, String detailsConstant, Integer
currentValue) {
+ if (newValue == null && details.get(detailsConstant) == null) {
+ String currentValueString = String.valueOf(currentValue);
+ s_logger.debug(String.format("[%s] was not specified, keeping the
current value: [%s].", detailsConstant, currentValueString));
Review Comment:
```suggestion
logger.debug("{} was not specified, keeping the current value:
{}.", detailsConstant, currentValueString);
```
--
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]