mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
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:
parent
e2cfddb1b6
commit
d9a7b6e511
@ -469,7 +469,7 @@ public interface UserVmService {
|
|||||||
VirtualMachine migrateVirtualMachineWithVolume(Long vmId, Host destinationHost, Map<String, String> volumeToPool) throws ResourceUnavailableException,
|
VirtualMachine migrateVirtualMachineWithVolume(Long vmId, Host destinationHost, Map<String, String> volumeToPool) throws ResourceUnavailableException,
|
||||||
ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException;
|
ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException;
|
||||||
|
|
||||||
UserVm moveVMToUser(AssignVMCmd moveUserVMCmd) throws ResourceAllocationException, ConcurrentOperationException, ResourceUnavailableException,
|
UserVm moveVmToUser(AssignVMCmd moveUserVMCmd) throws ResourceAllocationException, ConcurrentOperationException, ResourceUnavailableException,
|
||||||
InsufficientCapacityException;
|
InsufficientCapacityException;
|
||||||
|
|
||||||
VirtualMachine vmStorageMigration(Long vmId, StoragePool destPool);
|
VirtualMachine vmStorageMigration(Long vmId, StoragePool destPool);
|
||||||
|
|||||||
@ -120,29 +120,18 @@ public class AssignVMCmd extends BaseCmd {
|
|||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
try {
|
try {
|
||||||
UserVm userVm = _userVmService.moveVMToUser(this);
|
UserVm userVm = _userVmService.moveVmToUser(this);
|
||||||
if (userVm == null) {
|
|
||||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm");
|
|
||||||
}
|
|
||||||
UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", userVm).get(0);
|
UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", userVm).get(0);
|
||||||
response.setResponseName(getCommandName());
|
response.setResponseName(getCommandName());
|
||||||
setResponseObject(response);
|
setResponseObject(response);
|
||||||
} catch (InvalidParameterValueException e){
|
|
||||||
e.printStackTrace();
|
|
||||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Failed to move vm due to: " + e.getStackTrace());
|
ApiErrorCode errorCode = e instanceof InvalidParameterValueException ? ApiErrorCode.PARAM_ERROR : ApiErrorCode.INTERNAL_ERROR;
|
||||||
if (e.getMessage() != null) {
|
String msg = String.format("Failed to move VM [%s].", getVmId());
|
||||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm due to " + e.getMessage());
|
logger.error(msg, e);
|
||||||
} else if (e.getCause() != null) {
|
throw new ServerApiException(errorCode, msg);
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getEntityOwnerId() {
|
public long getEntityOwnerId() {
|
||||||
UserVm vm = _responseGenerator.findUserVmById(getVmId());
|
UserVm vm = _responseGenerator.findUserVmById(getVmId());
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -477,7 +477,7 @@ public class UserVmManagerTest {
|
|||||||
CallContext.register(user, caller);
|
CallContext.register(user, caller);
|
||||||
try {
|
try {
|
||||||
|
|
||||||
_userVmMgr.moveVMToUser(cmd);
|
_userVmMgr.moveVmToUser(cmd);
|
||||||
} finally {
|
} finally {
|
||||||
CallContext.unregister();
|
CallContext.unregister();
|
||||||
}
|
}
|
||||||
@ -527,7 +527,7 @@ public class UserVmManagerTest {
|
|||||||
when(_accountMgr.isRootAdmin(anyLong())).thenReturn(true);
|
when(_accountMgr.isRootAdmin(anyLong())).thenReturn(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
_userVmMgr.moveVMToUser(cmd);
|
_userVmMgr.moveVmToUser(cmd);
|
||||||
} finally {
|
} finally {
|
||||||
CallContext.unregister();
|
CallContext.unregister();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user