Merge branch '4.16'

This commit is contained in:
nvazquez 2022-04-23 01:21:51 -03:00
commit d0f918d8e6
No known key found for this signature in database
GPG Key ID: 656E1BCC8CB54F84

View File

@ -358,24 +358,40 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
Long zoneId = cmd.getZoneId(); Long zoneId = cmd.getZoneId();
String volumeName = cmd.getVolumeName(); String volumeName = cmd.getVolumeName();
String url = cmd.getUrl(); String url = cmd.getUrl();
String format = cmd.getFormat(); String format = sanitizeFormat(cmd.getFormat());
Long diskOfferingId = cmd.getDiskOfferingId(); Long diskOfferingId = cmd.getDiskOfferingId();
String imageStoreUuid = cmd.getImageStoreUuid(); String imageStoreUuid = cmd.getImageStoreUuid();
DataStore store = _tmpltMgr.getImageStore(imageStoreUuid, zoneId); DataStore store = _tmpltMgr.getImageStore(imageStoreUuid, zoneId);
validateVolume(caller, ownerId, zoneId, volumeName, url, format, diskOfferingId); validateVolume(caller, ownerId, zoneId, volumeName, url, format, diskOfferingId);
VolumeVO volume = persistVolume(owner, zoneId, volumeName, url, cmd.getFormat(), diskOfferingId, Volume.State.Allocated); VolumeVO volume = persistVolume(owner, zoneId, volumeName, url, format, diskOfferingId, Volume.State.Allocated);
VolumeInfo vol = volFactory.getVolume(volume.getId()); VolumeInfo vol = volFactory.getVolume(volume.getId());
RegisterVolumePayload payload = new RegisterVolumePayload(cmd.getUrl(), cmd.getChecksum(), cmd.getFormat()); RegisterVolumePayload payload = new RegisterVolumePayload(cmd.getUrl(), cmd.getChecksum(), format);
vol.addPayload(payload); vol.addPayload(payload);
volService.registerVolume(vol, store); volService.registerVolume(vol, store);
return volume; return volume;
} }
private String sanitizeFormat(String format) {
if (org.apache.commons.lang3.StringUtils.isBlank(format)) {
throw new CloudRuntimeException("Please provide a format");
}
String uppercase = format.toUpperCase();
try {
ImageFormat.valueOf(uppercase);
} catch (IllegalArgumentException e) {
String msg = "Image format: " + format + " is incorrect. Supported formats are " + EnumUtils.listValues(ImageFormat.values());
s_logger.error("ImageFormat IllegalArgumentException: " + e.getMessage(), e);
throw new IllegalArgumentException(msg);
}
return uppercase;
}
@Override @Override
@ActionEvent(eventType = EventTypes.EVENT_VOLUME_UPLOAD, eventDescription = "uploading volume for post upload", async = true) @ActionEvent(eventType = EventTypes.EVENT_VOLUME_UPLOAD, eventDescription = "uploading volume for post upload", async = true)
public GetUploadParamsResponse uploadVolume(final GetUploadParamsForVolumeCmd cmd) throws ResourceAllocationException, MalformedURLException { public GetUploadParamsResponse uploadVolume(final GetUploadParamsForVolumeCmd cmd) throws ResourceAllocationException, MalformedURLException {
@ -384,7 +400,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
final Account owner = _entityMgr.findById(Account.class, ownerId); final Account owner = _entityMgr.findById(Account.class, ownerId);
final Long zoneId = cmd.getZoneId(); final Long zoneId = cmd.getZoneId();
final String volumeName = cmd.getName(); final String volumeName = cmd.getName();
String format = cmd.getFormat(); String format = sanitizeFormat(cmd.getFormat());
final Long diskOfferingId = cmd.getDiskOfferingId(); final Long diskOfferingId = cmd.getDiskOfferingId();
String imageStoreUuid = cmd.getImageStoreUuid(); String imageStoreUuid = cmd.getImageStoreUuid();
final DataStore store = _tmpltMgr.getImageStore(imageStoreUuid, zoneId); final DataStore store = _tmpltMgr.getImageStore(imageStoreUuid, zoneId);
@ -395,11 +411,11 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
@Override @Override
public GetUploadParamsResponse doInTransaction(TransactionStatus status) throws MalformedURLException { public GetUploadParamsResponse doInTransaction(TransactionStatus status) throws MalformedURLException {
VolumeVO volume = persistVolume(owner, zoneId, volumeName, null, cmd.getFormat(), diskOfferingId, Volume.State.NotUploaded); VolumeVO volume = persistVolume(owner, zoneId, volumeName, null, format, diskOfferingId, Volume.State.NotUploaded);
VolumeInfo vol = volFactory.getVolume(volume.getId()); VolumeInfo vol = volFactory.getVolume(volume.getId());
RegisterVolumePayload payload = new RegisterVolumePayload(null, cmd.getChecksum(), cmd.getFormat()); RegisterVolumePayload payload = new RegisterVolumePayload(null, cmd.getChecksum(), format);
vol.addPayload(payload); vol.addPayload(payload);
Pair<EndPoint, DataObject> pair = volService.registerVolumeForPostUpload(vol, store); Pair<EndPoint, DataObject> pair = volService.registerVolumeForPostUpload(vol, store);
@ -487,12 +503,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
_resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(ownerId), ResourceType.secondary_storage); _resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(ownerId), ResourceType.secondary_storage);
} }
try { sanitizeFormat(format);
ImageFormat.valueOf(format.toUpperCase());
} catch (IllegalArgumentException e) {
s_logger.debug("ImageFormat IllegalArgumentException: " + e.getMessage());
throw new IllegalArgumentException("Image format: " + format + " is incorrect. Supported formats are " + EnumUtils.listValues(ImageFormat.values()));
}
// Check that the the disk offering specified is valid // Check that the the disk offering specified is valid
if (diskOfferingId != null) { if (diskOfferingId != null) {