Search in sources :

Example 31 with VolumeDataStoreVO

use of com.cloud.storage.datastore.db.VolumeDataStoreVO 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)

Example 32 with VolumeDataStoreVO

use of com.cloud.storage.datastore.db.VolumeDataStoreVO in project cosmic by MissionCriticalCloud.

the class DownloadMonitorImpl method downloadVolumeToStorage.

@Override
public void downloadVolumeToStorage(final DataObject volume, final AsyncCompletionCallback<DownloadAnswer> callback) {
    boolean downloadJobExists = false;
    VolumeDataStoreVO volumeHost = null;
    final DataStore store = volume.getDataStore();
    final VolumeInfo volInfo = (VolumeInfo) volume;
    final RegisterVolumePayload payload = (RegisterVolumePayload) volInfo.getpayload();
    final String url = payload.getUrl();
    final String checkSum = payload.getChecksum();
    final ImageFormat format = ImageFormat.valueOf(payload.getFormat());
    volumeHost = _volumeStoreDao.findByStoreVolume(store.getId(), volume.getId());
    if (volumeHost == null) {
        volumeHost = new VolumeDataStoreVO(store.getId(), volume.getId(), new Date(), 0, Status.NOT_DOWNLOADED, null, null, "jobid0000", null, url, checkSum);
        _volumeStoreDao.persist(volumeHost);
    } else if ((volumeHost.getJobId() != null) && (volumeHost.getJobId().length() > 2)) {
        downloadJobExists = true;
    } else {
        // persit url and checksum
        volumeHost.setDownloadUrl(url);
        volumeHost.setChecksum(checkSum);
        _volumeStoreDao.update(volumeHost.getId(), volumeHost);
    }
    final Long maxVolumeSizeInBytes = getMaxVolumeSizeInBytes();
    if (volumeHost != null) {
        start();
        final Volume vol = _volumeDao.findById(volume.getId());
        DownloadCommand dcmd = new DownloadCommand((VolumeObjectTO) (volume.getTO()), maxVolumeSizeInBytes, checkSum, url, format);
        dcmd.setProxy(getHttpProxy());
        if (downloadJobExists) {
            dcmd = new DownloadProgressCommand(dcmd, volumeHost.getJobId(), RequestType.GET_OR_RESTART);
            dcmd.setResourceType(ResourceType.VOLUME);
        }
        final EndPoint ep = _epSelector.select(volume);
        if (ep == null) {
            s_logger.warn("There is no secondary storage VM for image store " + store.getName());
            return;
        }
        final DownloadListener dl = new DownloadListener(ep, store, volume, _timer, this, dcmd, callback);
        // auto-wired those injected fields in DownloadListener
        ComponentContext.inject(dl);
        if (downloadJobExists) {
            dl.setCurrState(volumeHost.getDownloadState());
        }
        try {
            ep.sendMessageAsync(dcmd, new UploadListener.Callback(ep.getId(), dl));
        } catch (final Exception e) {
            s_logger.warn("Unable to start /resume download of volume " + volume.getId() + " to " + store.getName(), e);
            dl.setDisconnected();
            dl.scheduleStatusCheck(RequestType.GET_OR_RESTART);
        }
    }
}
Also used : DownloadCommand(com.cloud.storage.command.DownloadCommand) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) RegisterVolumePayload(com.cloud.storage.RegisterVolumePayload) UploadListener(com.cloud.storage.upload.UploadListener) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ImageFormat(com.cloud.storage.Storage.ImageFormat) DownloadProgressCommand(com.cloud.storage.command.DownloadProgressCommand) Volume(com.cloud.storage.Volume) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO)

Aggregations

VolumeDataStoreVO (com.cloud.storage.datastore.db.VolumeDataStoreVO)32 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)12 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)10 VolumeVO (com.cloud.storage.VolumeVO)9 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)8 SnapshotDataStoreVO (com.cloud.storage.datastore.db.SnapshotDataStoreVO)8 TemplateDataStoreVO (com.cloud.storage.datastore.db.TemplateDataStoreVO)7 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)7 Date (java.util.Date)7 ExecutionException (java.util.concurrent.ExecutionException)6 DataObject (com.cloud.engine.subsystem.api.storage.DataObject)5 CreateCmdResult (com.cloud.engine.subsystem.api.storage.CreateCmdResult)4 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)4 DownloadAnswer (com.cloud.agent.api.storage.DownloadAnswer)3 VolumeApiResult (com.cloud.engine.subsystem.api.storage.VolumeService.VolumeApiResult)3 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)3 AsyncCallFuture (com.cloud.framework.async.AsyncCallFuture)3 CopyCmdAnswer (com.cloud.storage.command.CopyCmdAnswer)3 VolumeObjectTO (com.cloud.storage.to.VolumeObjectTO)3 DB (com.cloud.utils.db.DB)3