Search in sources :

Example 1 with DownloadProgressCommand

use of com.cloud.legacymodel.communication.command.DownloadProgressCommand in project cosmic by MissionCriticalCloud.

the class DownloadListener method sendCommand.

public void sendCommand(final RequestType reqType) {
    if (getJobId() != null) {
        if (s_logger.isTraceEnabled()) {
            logTrace("Sending progress command ");
        }
        try {
            final DownloadProgressCommand dcmd = new DownloadProgressCommand(getCommand(), getJobId(), reqType);
            if (this.object.getType() == DataObjectType.VOLUME) {
                dcmd.setResourceType(ResourceType.VOLUME);
            }
            this._ssAgent.sendMessageAsync(dcmd, new UploadListener.Callback(this._ssAgent.getId(), this));
        } catch (final Exception e) {
            s_logger.debug("Send command failed", e);
            setDisconnected();
        }
    }
}
Also used : UploadListener(com.cloud.storage.upload.UploadListener) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) DownloadProgressCommand(com.cloud.legacymodel.communication.command.DownloadProgressCommand)

Example 2 with DownloadProgressCommand

use of com.cloud.legacymodel.communication.command.DownloadProgressCommand in project cosmic by MissionCriticalCloud.

the class DownloadManagerImpl method handleDownloadCommand.

@Override
public DownloadAnswer handleDownloadCommand(final SecondaryStorageResource resource, final DownloadCommand cmd) {
    final ResourceType resourceType = cmd.getResourceType();
    if (cmd instanceof DownloadProgressCommand) {
        return handleDownloadProgressCmd(resource, (DownloadProgressCommand) cmd);
    }
    if (cmd.getUrl() == null) {
        return new DownloadAnswer(resourceType.toString() + " is corrupted on storage due to an invalid url , cannot download", VMTemplateStatus.DOWNLOAD_ERROR);
    }
    if (cmd.getName() == null) {
        return new DownloadAnswer("Invalid Name", VMTemplateStatus.DOWNLOAD_ERROR);
    }
    final DataStoreTO dstore = cmd.getDataStore();
    String installPathPrefix = cmd.getInstallPath();
    // for NFS, we need to get mounted path
    if (dstore instanceof NfsTO) {
        installPathPrefix = resource.getRootDir(((NfsTO) dstore).getUrl()) + File.separator + installPathPrefix;
    }
    String user = null;
    String password = null;
    if (cmd.getAuth() != null) {
        user = cmd.getAuth().getUserName();
        password = cmd.getAuth().getPassword();
    }
    // TO DO - Define Volume max size as well
    final long maxDownloadSizeInBytes = cmd.getMaxDownloadSizeInBytes() == null ? TemplateDownloader.DEFAULT_MAX_TEMPLATE_SIZE_IN_BYTES : cmd.getMaxDownloadSizeInBytes();
    String jobId = null;
    jobId = downloadPublicTemplate(cmd.getId(), cmd.getUrl(), cmd.getName(), cmd.getFormat(), cmd.getAccountId(), cmd.getDescription(), cmd.getChecksum(), installPathPrefix, cmd.getInstallPath(), user, password, maxDownloadSizeInBytes, cmd.getProxy(), resourceType);
    sleep();
    if (jobId == null) {
        return new DownloadAnswer("Internal Error", VMTemplateStatus.DOWNLOAD_ERROR);
    }
    return new DownloadAnswer(jobId, getDownloadPct(jobId), getDownloadError(jobId), getDownloadStatus2(jobId), getDownloadLocalPath(jobId), getInstallPath(jobId), getDownloadTemplateSize(jobId), getDownloadTemplateSize(jobId), getDownloadCheckSum(jobId));
}
Also used : DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) ResourceType(com.cloud.legacymodel.communication.command.DownloadCommand.ResourceType) DownloadAnswer(com.cloud.legacymodel.communication.answer.DownloadAnswer) NfsTO(com.cloud.legacymodel.to.NfsTO) DownloadProgressCommand(com.cloud.legacymodel.communication.command.DownloadProgressCommand)

Example 3 with DownloadProgressCommand

use of com.cloud.legacymodel.communication.command.DownloadProgressCommand in project cosmic by MissionCriticalCloud.

the class DownloadMonitorImpl method initiateTemplateDownload.

private void initiateTemplateDownload(final DataObject template, final AsyncCompletionCallback<DownloadAnswer> callback) {
    boolean downloadJobExists = false;
    TemplateDataStoreVO vmTemplateStore = null;
    final DataStore store = template.getDataStore();
    vmTemplateStore = this._vmTemplateStoreDao.findByStoreTemplate(store.getId(), template.getId());
    if (vmTemplateStore == null) {
        vmTemplateStore = new TemplateDataStoreVO(store.getId(), template.getId(), new Date(), 0, VMTemplateStatus.NOT_DOWNLOADED, null, null, "jobid0000", null, template.getUri());
        vmTemplateStore.setDataStoreRole(store.getRole());
        vmTemplateStore = this._vmTemplateStoreDao.persist(vmTemplateStore);
    } else if ((vmTemplateStore.getJobId() != null) && (vmTemplateStore.getJobId().length() > 2)) {
        downloadJobExists = true;
    }
    final Long maxTemplateSizeInBytes = getMaxTemplateSizeInBytes();
    if (vmTemplateStore != null) {
        start();
        final VirtualMachineTemplate tmpl = this._templateDao.findById(template.getId());
        DownloadCommand dcmd = new DownloadCommand((TemplateObjectTO) (template.getTO()), maxTemplateSizeInBytes);
        dcmd.setProxy(getHttpProxy());
        if (downloadJobExists) {
            dcmd = new DownloadProgressCommand(dcmd, vmTemplateStore.getJobId(), RequestType.GET_OR_RESTART);
        }
        if (vmTemplateStore.isCopy()) {
            dcmd.setCreds(TemplateConstants.DEFAULT_HTTP_AUTH_USER, this._copyAuthPasswd);
        }
        final EndPoint ep = this._epSelector.select(template);
        if (ep == null) {
            final String errMsg = "There is no secondary storage VM for downloading template to image store " + store.getName();
            s_logger.warn(errMsg);
            throw new CloudRuntimeException(errMsg);
        }
        final DownloadListener dl = new DownloadListener(ep, store, template, this._timer, this, dcmd, callback);
        // initialize those auto-wired field in download listener.
        ComponentContext.inject(dl);
        if (downloadJobExists) {
            // due to handling existing download job issues, we still keep
            // downloadState in template_store_ref to avoid big change in
            // DownloadListener to use
            // new ObjectInDataStore.State transition. TODO: fix this later
            // to be able to remove downloadState from template_store_ref.
            s_logger.info("found existing download job");
            dl.setCurrState(vmTemplateStore.getDownloadState());
        }
        try {
            ep.sendMessageAsync(dcmd, new UploadListener.Callback(ep.getId(), dl));
        } catch (final Exception e) {
            s_logger.warn("Unable to start /resume download of template " + template.getId() + " to " + store.getName(), e);
            dl.setDisconnected();
            dl.scheduleStatusCheck(RequestType.GET_OR_RESTART);
        }
    }
}
Also used : VirtualMachineTemplate(com.cloud.legacymodel.storage.VirtualMachineTemplate) DownloadCommand(com.cloud.legacymodel.communication.command.DownloadCommand) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO) UploadListener(com.cloud.storage.upload.UploadListener) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) DownloadProgressCommand(com.cloud.legacymodel.communication.command.DownloadProgressCommand) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore)

Example 4 with DownloadProgressCommand

use of com.cloud.legacymodel.communication.command.DownloadProgressCommand 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

DownloadProgressCommand (com.cloud.legacymodel.communication.command.DownloadProgressCommand)4 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)3 UploadListener (com.cloud.storage.upload.UploadListener)3 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)2 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)2 DownloadCommand (com.cloud.legacymodel.communication.command.DownloadCommand)2 URISyntaxException (java.net.URISyntaxException)2 Date (java.util.Date)2 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)1 DownloadAnswer (com.cloud.legacymodel.communication.answer.DownloadAnswer)1 ResourceType (com.cloud.legacymodel.communication.command.DownloadCommand.ResourceType)1 VirtualMachineTemplate (com.cloud.legacymodel.storage.VirtualMachineTemplate)1 Volume (com.cloud.legacymodel.storage.Volume)1 DataStoreTO (com.cloud.legacymodel.to.DataStoreTO)1 NfsTO (com.cloud.legacymodel.to.NfsTO)1 ImageFormat (com.cloud.model.enumeration.ImageFormat)1 RegisterVolumePayload (com.cloud.storage.RegisterVolumePayload)1 TemplateDataStoreVO (com.cloud.storage.datastore.db.TemplateDataStoreVO)1 VolumeDataStoreVO (com.cloud.storage.datastore.db.VolumeDataStoreVO)1