Skip to content

Commit 734ce3c

Browse files
authored
Revert "Rollback of changes with errors during the VM assign (#7061)"
This reverts commit d9a7b6e.
1 parent 011fced commit 734ce3c

File tree

5 files changed

+466
-2205
lines changed

5 files changed

+466
-2205
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: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,27 @@ public List<Long> getSecurityGroupIdList() {
120120
@Override
121121
public void execute() {
122122
try {
123-
UserVm userVm = _userVmService.moveVmToUser(this);
123+
UserVm userVm = _userVmService.moveVMToUser(this);
124+
if (userVm == null) {
125+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm");
126+
}
124127
UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", userVm).get(0);
125128
response.setResponseName(getCommandName());
126129
setResponseObject(response);
130+
} catch (InvalidParameterValueException e){
131+
e.printStackTrace();
132+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
127133
} catch (Exception e) {
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);
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+
}
132142
}
143+
133144
}
134145

135146
@Override

0 commit comments

Comments
 (0)