CLOUDSTACK-9560 Root volume of deleted VM left unremoved

(cherry picked from commit 5568ee93ad08f998822dc0428e511dc8e8609014)
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
subhash yedugundla 2016-05-31 17:15:04 +05:30 committed by Rohit Yadav
parent 26bcb9afd8
commit b70879cbac

View File

@ -27,6 +27,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -2253,27 +2254,41 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
// Cleanup expired volume URLs
List<VolumeDataStoreVO> volumesOnImageStoreList = _volumeStoreDao.listVolumeDownloadUrls();
HashSet<Long> expiredVolumeIds = new HashSet<Long>();
HashSet<Long> activeVolumeIds = new HashSet<Long>();
for(VolumeDataStoreVO volumeOnImageStore : volumesOnImageStoreList){
long volumeId = volumeOnImageStore.getVolumeId();
try {
long downloadUrlCurrentAgeInSecs = DateUtil.getTimeDifference(DateUtil.now(), volumeOnImageStore.getExtractUrlCreated());
if(downloadUrlCurrentAgeInSecs < _downloadUrlExpirationInterval){ // URL hasnt expired yet
activeVolumeIds.add(volumeId);
continue;
}
s_logger.debug("Removing download url " + volumeOnImageStore.getExtractUrl() + " for volume id " + volumeOnImageStore.getVolumeId());
expiredVolumeIds.add(volumeId);
s_logger.debug("Removing download url " + volumeOnImageStore.getExtractUrl() + " for volume id " + volumeId);
// Remove it from image store
ImageStoreEntity secStore = (ImageStoreEntity) _dataStoreMgr.getDataStore(volumeOnImageStore.getDataStoreId(), DataStoreRole.Image);
secStore.deleteExtractUrl(volumeOnImageStore.getInstallPath(), volumeOnImageStore.getExtractUrl(), Upload.Type.VOLUME);
// Now expunge it from DB since this entry was created only for download purpose
// Now expunge it from DB since this entry was created only for download purpose
_volumeStoreDao.expunge(volumeOnImageStore.getId());
}catch(Throwable th){
s_logger.warn("Caught exception while deleting download url " +volumeOnImageStore.getExtractUrl() +
" for volume id " + volumeOnImageStore.getVolumeId(), th);
}
}
for(Long volumeId : expiredVolumeIds)
{
if(activeVolumeIds.contains(volumeId)) {
continue;
}
Volume volume = _volumeDao.findById(volumeId);
if (volume != null && volume.getState() == Volume.State.Expunged) {
_volumeDao.remove(volumeId);
}
}
// Cleanup expired template URLs
List<TemplateDataStoreVO> templatesOnImageStoreList = _templateStoreDao.listTemplateDownloadUrls();