Search in sources :

Example 6 with ImageStoreEntity

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;
}
Also used : InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO) ImageStoreEntity(com.cloud.storage.image.datastore.ImageStoreEntity) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) VolumeApiResult(com.cloud.engine.subsystem.api.storage.VolumeService.VolumeApiResult) ExecutionException(java.util.concurrent.ExecutionException)

Example 7 with ImageStoreEntity

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);
    }
}
Also used : VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO) ImageStoreEntity(com.cloud.storage.image.datastore.ImageStoreEntity) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO)

Aggregations

ImageStoreEntity (com.cloud.storage.image.datastore.ImageStoreEntity)7 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)4 TemplateDataStoreVO (com.cloud.storage.datastore.db.TemplateDataStoreVO)4 TemplateInfo (com.cloud.engine.subsystem.api.storage.TemplateInfo)3 VMTemplateVO (com.cloud.storage.VMTemplateVO)3 TemplateApiResult (com.cloud.engine.subsystem.api.storage.TemplateService.TemplateApiResult)2 ZoneScope (com.cloud.engine.subsystem.api.storage.ZoneScope)2 VolumeDataStoreVO (com.cloud.storage.datastore.db.VolumeDataStoreVO)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)2 ExecutionException (java.util.concurrent.ExecutionException)2 Answer (com.cloud.agent.api.Answer)1 MigrateVolumeAnswer (com.cloud.agent.api.storage.MigrateVolumeAnswer)1 ClusterScope (com.cloud.engine.subsystem.api.storage.ClusterScope)1 DataObject (com.cloud.engine.subsystem.api.storage.DataObject)1 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)1 HostScope (com.cloud.engine.subsystem.api.storage.HostScope)1 ImageStoreProvider (com.cloud.engine.subsystem.api.storage.ImageStoreProvider)1 Scope (com.cloud.engine.subsystem.api.storage.Scope)1 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)1