Search in sources :

Example 1 with DownloadCommand

use of org.apache.cloudstack.storage.command.DownloadCommand in project cloudstack by apache.

the class RequestTest method testDownload.

public void testDownload() {
    s_logger.info("Testing Download answer");
    VirtualMachineTemplate template = Mockito.mock(VirtualMachineTemplate.class);
    Mockito.when(template.getId()).thenReturn(1L);
    Mockito.when(template.getFormat()).thenReturn(ImageFormat.QCOW2);
    Mockito.when(template.getName()).thenReturn("templatename");
    Mockito.when(template.getTemplateType()).thenReturn(TemplateType.USER);
    Mockito.when(template.getDisplayText()).thenReturn("displayText");
    Mockito.when(template.getHypervisorType()).thenReturn(HypervisorType.KVM);
    Mockito.when(template.getUrl()).thenReturn("url");
    NfsTO nfs = new NfsTO("secUrl", DataStoreRole.Image);
    TemplateObjectTO to = new TemplateObjectTO(template);
    to.setImageDataStore(nfs);
    DownloadCommand cmd = new DownloadCommand(to, 30000000l);
    Request req = new Request(1, 1, cmd, true);
    req.logD("Debug for Download");
    DownloadAnswer answer = new DownloadAnswer("jobId", 50, "errorString", Status.ABANDONED, "filesystempath", "installpath", 10000000, 20000000, "chksum");
    Response resp = new Response(req, answer);
    resp.logD("Debug for Download");
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) DownloadCommand(org.apache.cloudstack.storage.command.DownloadCommand) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) NfsTO(com.cloud.agent.api.to.NfsTO)

Example 2 with DownloadCommand

use of org.apache.cloudstack.storage.command.DownloadCommand in project cloudstack by apache.

the class DownloadMonitorImpl method downloadVolumeToStorage.

@Override
public void downloadVolumeToStorage(DataObject volume, AsyncCompletionCallback<DownloadAnswer> callback) {
    boolean downloadJobExists = false;
    VolumeDataStoreVO volumeHost = null;
    DataStore store = volume.getDataStore();
    VolumeInfo volInfo = (VolumeInfo) volume;
    RegisterVolumePayload payload = (RegisterVolumePayload) volInfo.getpayload();
    String url = payload.getUrl();
    String checkSum = payload.getChecksum();
    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);
    }
    Long maxVolumeSizeInBytes = getMaxVolumeSizeInBytes();
    if (volumeHost != null) {
        start();
        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);
        }
        EndPoint ep = _epSelector.select(volume);
        if (ep == null) {
            s_logger.warn("There is no secondary storage VM for image store " + store.getName());
            return;
        }
        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 (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(org.apache.cloudstack.storage.command.DownloadCommand) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) EndPoint(org.apache.cloudstack.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(org.apache.cloudstack.storage.command.DownloadProgressCommand) Volume(com.cloud.storage.Volume) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO)

Example 3 with DownloadCommand

use of org.apache.cloudstack.storage.command.DownloadCommand in project cloudstack by apache.

the class DownloadManagerImpl method handleDownloadProgressCmd.

private DownloadAnswer handleDownloadProgressCmd(SecondaryStorageResource resource, DownloadProgressCommand cmd) {
    String jobId = cmd.getJobId();
    DownloadAnswer answer;
    DownloadJob dj = null;
    if (jobId != null) {
        dj = jobs.get(jobId);
    }
    if (dj == null) {
        if (cmd.getRequest() == RequestType.GET_OR_RESTART) {
            DownloadCommand dcmd = new DownloadCommand(cmd);
            return handleDownloadCommand(resource, dcmd);
        } else {
            return new DownloadAnswer("Cannot find job", com.cloud.storage.VMTemplateStorageResourceAssoc.Status.UNKNOWN);
        }
    }
    TemplateDownloader td = dj.getTemplateDownloader();
    switch(cmd.getRequest()) {
        case GET_STATUS:
            break;
        case ABORT:
            td.stopDownload();
            sleep();
            break;
        case RESTART:
            td.stopDownload();
            sleep();
            threadPool.execute(td);
            break;
        case PURGE:
            td.stopDownload();
            answer = new DownloadAnswer(jobId, getDownloadPct(jobId), getDownloadError(jobId), getDownloadStatus2(jobId), getDownloadLocalPath(jobId), getInstallPath(jobId), getDownloadTemplateSize(jobId), getDownloadTemplatePhysicalSize(jobId), getDownloadCheckSum(jobId));
            jobs.remove(jobId);
            return answer;
        default:
            // TODO
            break;
    }
    return new DownloadAnswer(jobId, getDownloadPct(jobId), getDownloadError(jobId), getDownloadStatus2(jobId), getDownloadLocalPath(jobId), getInstallPath(jobId), getDownloadTemplateSize(jobId), getDownloadTemplatePhysicalSize(jobId), getDownloadCheckSum(jobId));
}
Also used : DownloadCommand(org.apache.cloudstack.storage.command.DownloadCommand) HttpTemplateDownloader(com.cloud.storage.template.HttpTemplateDownloader) ScpTemplateDownloader(com.cloud.storage.template.ScpTemplateDownloader) S3TemplateDownloader(com.cloud.storage.template.S3TemplateDownloader) TemplateDownloader(com.cloud.storage.template.TemplateDownloader) LocalTemplateDownloader(com.cloud.storage.template.LocalTemplateDownloader) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer)

Example 4 with DownloadCommand

use of org.apache.cloudstack.storage.command.DownloadCommand in project cloudstack by apache.

the class SwiftImageStoreDriverImpl method createAsync.

@Override
public void createAsync(DataStore dataStore, DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
    Long maxTemplateSizeInBytes = getMaxTemplateSizeInBytes();
    VirtualMachineTemplate tmpl = _templateDao.findById(data.getId());
    DataStore cacheStore = cacheManager.getCacheStorage(dataStore.getScope());
    DownloadCommand dcmd = new DownloadCommand((TemplateObjectTO) (data.getTO()), maxTemplateSizeInBytes);
    dcmd.setCacheStore(cacheStore.getTO());
    dcmd.setProxy(getHttpProxy());
    EndPoint ep = _epSelector.select(data);
    if (ep == null) {
        String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
        s_logger.error(errMsg);
        throw new CloudRuntimeException(errMsg);
    }
    CreateContext<CreateCmdResult> context = new CreateContext<CreateCmdResult>(callback, data);
    AsyncCallbackDispatcher<SwiftImageStoreDriverImpl, DownloadAnswer> caller = AsyncCallbackDispatcher.create(this);
    caller.setContext(context);
    if (data.getType() == DataObjectType.TEMPLATE) {
        caller.setCallback(caller.getTarget().createTemplateAsyncCallback(null, null));
    } else if (data.getType() == DataObjectType.VOLUME) {
        caller.setCallback(caller.getTarget().createVolumeAsyncCallback(null, null));
    }
    ep.sendMessageAsync(dcmd, caller);
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) DownloadCommand(org.apache.cloudstack.storage.command.DownloadCommand) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore)

Example 5 with DownloadCommand

use of org.apache.cloudstack.storage.command.DownloadCommand in project cloudstack by apache.

the class DownloadMonitorImpl method initiateTemplateDownload.

private void initiateTemplateDownload(DataObject template, AsyncCompletionCallback<DownloadAnswer> callback) {
    boolean downloadJobExists = false;
    TemplateDataStoreVO vmTemplateStore = null;
    DataStore store = template.getDataStore();
    vmTemplateStore = _vmTemplateStoreDao.findByStoreTemplate(store.getId(), template.getId());
    if (vmTemplateStore == null) {
        vmTemplateStore = new TemplateDataStoreVO(store.getId(), template.getId(), new Date(), 0, Status.NOT_DOWNLOADED, null, null, "jobid0000", null, template.getUri());
        vmTemplateStore.setDataStoreRole(store.getRole());
        vmTemplateStore = _vmTemplateStoreDao.persist(vmTemplateStore);
    } else if ((vmTemplateStore.getJobId() != null) && (vmTemplateStore.getJobId().length() > 2)) {
        downloadJobExists = true;
    }
    Long maxTemplateSizeInBytes = getMaxTemplateSizeInBytes();
    if (vmTemplateStore != null) {
        start();
        VirtualMachineTemplate tmpl = _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, _copyAuthPasswd);
        }
        EndPoint ep = _epSelector.select(template);
        if (ep == null) {
            String errMsg = "There is no secondary storage VM for downloading template to image store " + store.getName();
            s_logger.warn(errMsg);
            throw new CloudRuntimeException(errMsg);
        }
        DownloadListener dl = new DownloadListener(ep, store, template, _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 (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.template.VirtualMachineTemplate) DownloadCommand(org.apache.cloudstack.storage.command.DownloadCommand) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) TemplateDataStoreVO(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO) UploadListener(com.cloud.storage.upload.UploadListener) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DownloadProgressCommand(org.apache.cloudstack.storage.command.DownloadProgressCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore)

Aggregations

DownloadCommand (org.apache.cloudstack.storage.command.DownloadCommand)7 DownloadAnswer (com.cloud.agent.api.storage.DownloadAnswer)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)3 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)3 EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)3 DownloadProgressCommand (org.apache.cloudstack.storage.command.DownloadProgressCommand)3 ListTemplateCommand (com.cloud.agent.api.storage.ListTemplateCommand)2 Answer (com.cloud.agent.api.Answer)1 AttachIsoCommand (com.cloud.agent.api.AttachIsoCommand)1 BackupSnapshotCommand (com.cloud.agent.api.BackupSnapshotCommand)1 CheckHealthCommand (com.cloud.agent.api.CheckHealthCommand)1 CheckNetworkCommand (com.cloud.agent.api.CheckNetworkCommand)1 CheckRouterCommand (com.cloud.agent.api.CheckRouterCommand)1 CheckS2SVpnConnectionsCommand (com.cloud.agent.api.CheckS2SVpnConnectionsCommand)1 CheckVirtualMachineCommand (com.cloud.agent.api.CheckVirtualMachineCommand)1 CleanupNetworkRulesCmd (com.cloud.agent.api.CleanupNetworkRulesCmd)1 ComputeChecksumCommand (com.cloud.agent.api.ComputeChecksumCommand)1 CreatePrivateTemplateFromSnapshotCommand (com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand)1 CreatePrivateTemplateFromVolumeCommand (com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand)1