Skip to content

Commit

Permalink
Rollback of changes with errors during the VM assign (apache#7061)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephan Krug <[email protected]>
Co-authored-by: Gabriel <[email protected]>
Co-authored-by: Fabricio Duarte <[email protected]>
  • Loading branch information
4 people authored and dhslove committed Jan 16, 2025
1 parent 512f0d8 commit 553c7f3
Show file tree
Hide file tree
Showing 5 changed files with 2,203 additions and 464 deletions.
2 changes: 1 addition & 1 deletion api/src/main/java/com/cloud/vm/UserVmService.java
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ VirtualMachine migrateVirtualMachine(Long vmId, Host destinationHost) throws Res
VirtualMachine migrateVirtualMachineWithVolume(Long vmId, Host destinationHost, Map<String, String> volumeToPool) throws ResourceUnavailableException,
ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException;

UserVm moveVMToUser(AssignVMCmd moveUserVMCmd) throws ResourceAllocationException, ConcurrentOperationException, ResourceUnavailableException,
UserVm moveVmToUser(AssignVMCmd moveUserVMCmd) throws ResourceAllocationException, ConcurrentOperationException, ResourceUnavailableException,
InsufficientCapacityException;

VirtualMachine vmStorageMigration(Long vmId, StoragePool destPool);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,27 +120,16 @@ public List<Long> getSecurityGroupIdList() {
@Override
public void execute() {
try {
UserVm userVm = _userVmService.moveVMToUser(this);
if (userVm == null) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm");
}
UserVm userVm = _userVmService.moveVmToUser(this);
UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", userVm).get(0);
response.setResponseName(getCommandName());
setResponseObject(response);
} catch (InvalidParameterValueException e){
e.printStackTrace();
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
} catch (Exception e) {
logger.error("Failed to move vm due to: " + e.getStackTrace());
if (e.getMessage() != null) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm due to " + e.getMessage());
} else if (e.getCause() != null) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm due to " + e.getCause());
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm");
}
ApiErrorCode errorCode = e instanceof InvalidParameterValueException ? ApiErrorCode.PARAM_ERROR : ApiErrorCode.INTERNAL_ERROR;
String msg = String.format("Failed to move VM [%s].", getVmId());
logger.error(msg, e);
throw new ServerApiException(errorCode, msg);
}

}

@Override
Expand Down
Loading

0 comments on commit 553c7f3

Please sign in to comment.