Fix NPE when Volume exists on secondary store but doesn't have a download URL (#4530)

Co-authored-by: Pearl Dsilva <pearl.dsilva@shapeblue.com>
This commit is contained in:
Pearl Dsilva 2020-12-11 13:12:39 +05:30 committed by GitHub
parent e5b7733498
commit edd5f23e8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2881,8 +2881,12 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
} else if (volumeStoreRef != null) {
s_logger.debug("volume " + volumeId + " is already installed on secondary storage, install path is " +
volumeStoreRef.getInstallPath());
VolumeInfo destVol = volFactory.getVolume(volumeId, DataStoreRole.Image);
if (destVol == null) {
throw new CloudRuntimeException("Failed to find the volume on a secondary store");
}
ImageStoreEntity secStore = (ImageStoreEntity) dataStoreMgr.getDataStore(volumeStoreRef.getDataStoreId(), DataStoreRole.Image);
String extractUrl = secStore.createEntityExtractUrl(volumeStoreRef.getInstallPath(), volume.getFormat(), null);
String extractUrl = secStore.createEntityExtractUrl(volumeStoreRef.getInstallPath(), volume.getFormat(), destVol);
volumeStoreRef = _volumeStoreDao.findByVolume(volumeId);
volumeStoreRef.setExtractUrl(extractUrl);
volumeStoreRef.setExtractUrlCreated(DateUtil.now());