Search in sources :

Example 16 with ImageFormat

use of com.cloud.model.enumeration.ImageFormat 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 = this._volumeStoreDao.findByStoreVolume(store.getId(), volume.getId());
    if (volumeHost == null) {
        volumeHost = new VolumeDataStoreVO(store.getId(), volume.getId(), new Date(), 0, VMTemplateStatus.NOT_DOWNLOADED, null, null, "jobid0000", null, url, checkSum);
        this._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);
        this._volumeStoreDao.update(volumeHost.getId(), volumeHost);
    }
    final Long maxVolumeSizeInBytes = getMaxVolumeSizeInBytes();
    if (volumeHost != null) {
        start();
        final Volume vol = this._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 = this._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, this._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.legacymodel.communication.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.legacymodel.exceptions.CloudRuntimeException) ImageFormat(com.cloud.model.enumeration.ImageFormat) DownloadProgressCommand(com.cloud.legacymodel.communication.command.DownloadProgressCommand) Volume(com.cloud.legacymodel.storage.Volume) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO)

Aggregations

ImageFormat (com.cloud.model.enumeration.ImageFormat)16 Answer (com.cloud.legacymodel.communication.answer.Answer)5 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)5 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)5 NfsStoragePool (com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool)4 KvmPhysicalDisk (com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk)4 KvmStoragePool (com.cloud.agent.resource.kvm.storage.KvmStoragePool)4 KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)4 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)4 DiskControllerType (com.cloud.model.enumeration.DiskControllerType)4 ArrayList (java.util.ArrayList)4 LibvirtDiskDef (com.cloud.agent.resource.kvm.xml.LibvirtDiskDef)3 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)3 PrimaryStorageDownloadCommand (com.cloud.legacymodel.communication.command.PrimaryStorageDownloadCommand)3 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)3 PermissionDeniedException (com.cloud.legacymodel.exceptions.PermissionDeniedException)3 StoragePool (com.cloud.legacymodel.storage.StoragePool)3 Account (com.cloud.legacymodel.user.Account)3 VMTemplateVO (com.cloud.storage.VMTemplateVO)3 IOException (java.io.IOException)3