use of com.cloud.storage.image.datastore.ImageStoreEntity in project cosmic by MissionCriticalCloud.
the class VolumeApiServiceImpl method orchestrateExtractVolume.
private String orchestrateExtractVolume(final long volumeId, final long zoneId) {
// get latest volume state to make sure that it is not updated by other parallel operations
final VolumeVO volume = _volsDao.findById(volumeId);
if (volume == null || volume.getState() != Volume.State.Ready) {
throw new InvalidParameterValueException("Volume to be extracted has been removed or not in right state!");
}
// perform extraction
final ImageStoreEntity secStore = (ImageStoreEntity) dataStoreMgr.getImageStore(zoneId);
final String value = _configDao.getValue(Config.CopyVolumeWait.toString());
NumbersUtil.parseInt(value, Integer.parseInt(Config.CopyVolumeWait.getDefaultValue()));
// Copy volume from primary to secondary storage
final VolumeInfo srcVol = volFactory.getVolume(volumeId);
final AsyncCallFuture<VolumeApiResult> cvAnswer = volService.copyVolume(srcVol, secStore);
// Check if you got a valid answer.
final VolumeApiResult cvResult;
try {
cvResult = cvAnswer.get();
} catch (final InterruptedException e1) {
s_logger.debug("failed copy volume", e1);
throw new CloudRuntimeException("Failed to copy volume", e1);
} catch (final ExecutionException e1) {
s_logger.debug("failed copy volume", e1);
throw new CloudRuntimeException("Failed to copy volume", e1);
}
if (cvResult == null || cvResult.isFailed()) {
final String errorString = "Failed to copy the volume from the source primary storage pool to secondary storage.";
throw new CloudRuntimeException(errorString);
}
final VolumeInfo vol = cvResult.getVolume();
final String extractUrl = secStore.createEntityExtractUrl(vol.getPath(), vol.getFormat(), vol);
final VolumeDataStoreVO volumeStoreRef = _volumeStoreDao.findByVolume(volumeId);
volumeStoreRef.setExtractUrl(extractUrl);
volumeStoreRef.setExtractUrlCreated(DateUtil.now());
_volumeStoreDao.update(volumeStoreRef.getId(), volumeStoreRef);
return extractUrl;
}
use of com.cloud.storage.image.datastore.ImageStoreEntity in project cosmic by MissionCriticalCloud.
the class StorageManagerImpl method cleanupDownloadUrls.
@Override
public void cleanupDownloadUrls() {
// Cleanup expired volume URLs
final List<VolumeDataStoreVO> volumesOnImageStoreList = _volumeStoreDao.listVolumeDownloadUrls();
for (final VolumeDataStoreVO volumeOnImageStore : volumesOnImageStoreList) {
final long downloadUrlCurrentAgeInSecs = DateUtil.getTimeDifference(DateUtil.now(), volumeOnImageStore.getExtractUrlCreated());
if (downloadUrlCurrentAgeInSecs < _downloadUrlExpirationInterval) {
// URL hasnt expired yet
continue;
}
final long volumeId = volumeOnImageStore.getVolumeId();
s_logger.debug("Removing download url " + volumeOnImageStore.getExtractUrl() + " for volume id " + volumeId);
// Remove it from image store
final 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
_volumeStoreDao.expunge(volumeOnImageStore.getId());
final Volume volume = _volumeDao.findById(volumeId);
if (volume != null && volume.getState() == Volume.State.Expunged) {
_volumeDao.remove(volumeId);
}
}
// Cleanup expired template URLs
final List<TemplateDataStoreVO> templatesOnImageStoreList = _templateStoreDao.listTemplateDownloadUrls();
for (final TemplateDataStoreVO templateOnImageStore : templatesOnImageStoreList) {
final long downloadUrlCurrentAgeInSecs = DateUtil.getTimeDifference(DateUtil.now(), templateOnImageStore.getExtractUrlCreated());
if (downloadUrlCurrentAgeInSecs < _downloadUrlExpirationInterval) {
// URL hasnt expired yet
continue;
}
s_logger.debug("Removing download url " + templateOnImageStore.getExtractUrl() + " for template id " + templateOnImageStore.getTemplateId());
// Remove it from image store
final ImageStoreEntity secStore = (ImageStoreEntity) _dataStoreMgr.getDataStore(templateOnImageStore.getDataStoreId(), DataStoreRole.Image);
secStore.deleteExtractUrl(templateOnImageStore.getInstallPath(), templateOnImageStore.getExtractUrl(), Upload.Type.TEMPLATE);
// Now remove download details from DB.
templateOnImageStore.setExtractUrl(null);
templateOnImageStore.setExtractUrlCreated(null);
_templateStoreDao.update(templateOnImageStore.getId(), templateOnImageStore);
}
}
Aggregations