Rollback of changes with errors during the VM assign (#7061)

Co-authored-by: Stephan Krug <stephan.krug@scclouds.com.br>
Co-authored-by: Gabriel <gabriel.fernandes@scclouds.com.br>
Co-authored-by: Fabricio Duarte <fabricio.duarte.jr@gmail.com>
This commit is contained in:
Stephan Krug 2025-01-15 12:10:49 -03:00 committed by GitHub
parent e2cfddb1b6
commit d9a7b6e511
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 2249 additions and 510 deletions

View File

@ -469,7 +469,7 @@ public interface UserVmService {
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);

View File

@ -120,27 +120,16 @@ public class AssignVMCmd extends BaseCmd {
@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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -477,7 +477,7 @@ public class UserVmManagerTest {
CallContext.register(user, caller);
try {
_userVmMgr.moveVMToUser(cmd);
_userVmMgr.moveVmToUser(cmd);
} finally {
CallContext.unregister();
}
@ -527,7 +527,7 @@ public class UserVmManagerTest {
when(_accountMgr.isRootAdmin(anyLong())).thenReturn(true);
try {
_userVmMgr.moveVMToUser(cmd);
_userVmMgr.moveVmToUser(cmd);
} finally {
CallContext.unregister();
}