api: correct error on resize volume resource allocation failure (#7687)

This PR resource throws exception with the correct error code and logs the error message when a resource allocation failure is encountered during resize volume operation.

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
Abhishek Kumar 2023-07-03 12:57:14 +05:30 committed by GitHub
parent f3ad9e6743
commit de6ce503dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View File

@ -184,7 +184,7 @@ public class ResizeVolumeCmd extends BaseAsyncCmd implements UserCmd {
}
@Override
public void execute() throws ResourceAllocationException {
public void execute() {
Volume volume = null;
try {
if (size != null) {
@ -194,6 +194,9 @@ public class ResizeVolumeCmd extends BaseAsyncCmd implements UserCmd {
}
volume = _volumeService.resizeVolume(this);
} catch (ResourceAllocationException ex) {
s_logger.error(ex.getMessage());
throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage());
} catch (InvalidParameterValueException ex) {
s_logger.info(ex.getMessage());
throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, ex.getMessage());

View File

@ -129,9 +129,7 @@ public class ApiAsyncJobDispatcher extends AdapterBase implements AsyncJobDispat
response.setErrorText(errorMsg);
response.setResponseName((cmdObj == null) ? "unknowncommandresponse" : cmdObj.getCommandName());
// FIXME: setting resultCode to ApiErrorCode.INTERNAL_ERROR is not right, usually executors have their exception handling
// and we need to preserve that as much as possible here
_asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.FAILED, ApiErrorCode.INTERNAL_ERROR.getHttpCode(), ApiSerializerHelper.toSerializedString(response));
_asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.FAILED, errorCode, ApiSerializerHelper.toSerializedString(response));
}
}
}