weizhouapache commented on a change in pull request #5428:
URL: https://github.com/apache/cloudstack/pull/5428#discussion_r710924262
##########
File path: server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
##########
@@ -2584,6 +2585,52 @@ protected void runInContext() {
}
}
+ private void verifyVmLimits(UserVmVO vmInstance, Map<String,String>
details) {
+ if (VirtualMachineManager.ResoureCountRunningVMsonly.value()) {
+ return;
+ }
+
+ long newCpu =
NumberUtils.toLong(details.get(VmDetailConstants.CPU_NUMBER));
+ long newMemory =
NumberUtils.toLong(details.get(VmDetailConstants.MEMORY));
+ ServiceOfferingVO currentServiceOffering =
_serviceOfferingDao.findByIdIncludingRemoved(vmInstance.getId(),
vmInstance.getServiceOfferingId());
+ ServiceOfferingVO svcOffering =
_serviceOfferingDao.findById(vmInstance.getServiceOfferingId());
+ boolean isDynamic = currentServiceOffering.isDynamic();
+ if (isDynamic) {
+ Map<String, String> customParameters = new HashMap<>();
+ customParameters.put(VmDetailConstants.CPU_NUMBER,
String.valueOf(newCpu));
+ customParameters.put(VmDetailConstants.MEMORY,
String.valueOf(newMemory));
+ validateCustomParameters(svcOffering, customParameters);
+ }
+ long currentCpu = currentServiceOffering.getCpu();
+ long currentMemory = currentServiceOffering.getRamSize();
+
+ Account owner = _accountDao.findById(vmInstance.getAccountId());
+ if (owner == null) {
+ throw new InvalidParameterValueException("The owner of " +
vmInstance + " does not exist: " + vmInstance.getAccountId());
+ }
+ try {
+ if (newCpu > currentCpu) {
+ _resourceLimitMgr.checkResourceLimit(owner, ResourceType.cpu,
newCpu - currentCpu);
+ }
+ if (newMemory > currentMemory) {
+ _resourceLimitMgr.checkResourceLimit(owner,
ResourceType.memory, newMemory - currentMemory);
+ }
+ } catch (ResourceAllocationException e) {
+ throw new CloudRuntimeException("Failed to update VM settings", e);
Review comment:
@Pearl1594 use InvalidParameterValueException instead of
CloudRuntimeException ?
this can be improved

##########
File path:
api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java
##########
@@ -263,8 +264,13 @@ public long getEntityOwnerId() {
@Override
public void execute() throws ResourceUnavailableException,
InsufficientCapacityException, ServerApiException {
CallContext.current().setEventDetails("Vm Id: " +
this._uuidMgr.getUuid(VirtualMachine.class, getId()));
- UserVm result = _userVmService.updateVirtualMachine(this);
- if (result != null){
+ UserVm result = null;
+ try {
+ result = _userVmService.updateVirtualMachine(this);
+ } catch (CloudRuntimeException e) {
+ throw new CloudRuntimeException(String.format("Failed to update
VM, due to %s: ", e.getLocalizedMessage()));
Review comment:
@Pearl1594
maybe move "%s" after ":" ?
--
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]