Skip to content

Commit d9a7b6e

Browse files
stephankrugggStephan KrugGabrielwinterhazel
authored
Rollback of changes with errors during the VM assign (#7061)
Co-authored-by: Stephan Krug <[email protected]> Co-authored-by: Gabriel <[email protected]> Co-authored-by: Fabricio Duarte <[email protected]>
1 parent e2cfddb commit d9a7b6e

File tree

5 files changed

+2203
-464
lines changed

5 files changed

+2203
-464
lines changed

api/src/main/java/com/cloud/vm/UserVmService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ VirtualMachine migrateVirtualMachine(Long vmId, Host destinationHost) throws Res
469469
VirtualMachine migrateVirtualMachineWithVolume(Long vmId, Host destinationHost, Map<String, String> volumeToPool) throws ResourceUnavailableException,
470470
ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException;
471471

472-
UserVm moveVMToUser(AssignVMCmd moveUserVMCmd) throws ResourceAllocationException, ConcurrentOperationException, ResourceUnavailableException,
472+
UserVm moveVmToUser(AssignVMCmd moveUserVMCmd) throws ResourceAllocationException, ConcurrentOperationException, ResourceUnavailableException,
473473
InsufficientCapacityException;
474474

475475
VirtualMachine vmStorageMigration(Long vmId, StoragePool destPool);

api/src/main/java/org/apache/cloudstack/api/command/admin/vm/AssignVMCmd.java

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -120,27 +120,16 @@ public List<Long> getSecurityGroupIdList() {
120120
@Override
121121
public void execute() {
122122
try {
123-
UserVm userVm = _userVmService.moveVMToUser(this);
124-
if (userVm == null) {
125-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm");
126-
}
123+
UserVm userVm = _userVmService.moveVmToUser(this);
127124
UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", userVm).get(0);
128125
response.setResponseName(getCommandName());
129126
setResponseObject(response);
130-
} catch (InvalidParameterValueException e){
131-
e.printStackTrace();
132-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
133127
} catch (Exception e) {
134-
logger.error("Failed to move vm due to: " + e.getStackTrace());
135-
if (e.getMessage() != null) {
136-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm due to " + e.getMessage());
137-
} else if (e.getCause() != null) {
138-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm due to " + e.getCause());
139-
} else {
140-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm");
141-
}
128+
ApiErrorCode errorCode = e instanceof InvalidParameterValueException ? ApiErrorCode.PARAM_ERROR : ApiErrorCode.INTERNAL_ERROR;
129+
String msg = String.format("Failed to move VM [%s].", getVmId());
130+
logger.error(msg, e);
131+
throw new ServerApiException(errorCode, msg);
142132
}
143-
144133
}
145134

146135
@Override

0 commit comments

Comments
 (0)