Package com.cloud.agent.api.storage

Examples of com.cloud.agent.api.storage.DownloadAnswer


    @Override
    public void onEntry(String prevState, DownloadEvent event, Object evtObj) {
        super.onEntry(prevState, event, evtObj);
        if (!prevState.equalsIgnoreCase(getName())) {
            DownloadAnswer answer = new DownloadAnswer("Download canceled", Status.ABANDONED);
            getDownloadListener().callback(answer);
            getDownloadListener().cancelStatusTask();
            getDownloadListener().cancelTimeoutTask();
            getDownloadListener().sendCommand(RequestType.ABORT);
        }
View Full Code Here


    Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
    try {
      txn.start();
      ssvo = _mockSecStorageDao.findByUrl(cmd.getSecUrl());
      if (ssvo == null) {
        return new DownloadAnswer("can't find secondary storage",
            VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
      }
      txn.commit();
    } catch (Exception ex) {
      txn.rollback();
      throw new CloudRuntimeException("Error accessing secondary storage " + cmd.getSecUrl(), ex);
    } finally {
      txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
    }

    MockVolumeVO volume = new MockVolumeVO();
    volume.setPoolId(ssvo.getId());
    volume.setName(cmd.getName());
    volume.setPath(ssvo.getMountPoint() + cmd.getName());
    volume.setSize(0);
    volume.setType(MockVolumeType.TEMPLATE);
    volume.setStatus(Status.DOWNLOAD_IN_PROGRESS);
    txn = Transaction.open(Transaction.SIMULATOR_DB);
    try {
      txn.start();
      volume = _mockVolumeDao.persist(volume);
      txn.commit();
    } catch (Exception ex) {
      txn.rollback();
      throw new CloudRuntimeException("Error when saving volume " + volume, ex);
    } finally {
      txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
    }
    return new DownloadAnswer(String.valueOf(volume.getId()), 0, "Downloading", Status.DOWNLOAD_IN_PROGRESS,
        cmd.getName(), cmd.getName(), volume.getSize(), volume.getSize(), null);
  }
View Full Code Here

    try {
      txn.start();
      String volumeId = cmd.getJobId();
      MockVolumeVO volume = _mockVolumeDao.findById(Long.parseLong(volumeId));
      if (volume == null) {
        return new DownloadAnswer("Can't find the downloading volume", Status.ABANDONED);
      }

      long size = Math.min(volume.getSize() + DEFAULT_TEMPLATE_SIZE / 5, DEFAULT_TEMPLATE_SIZE);
      volume.setSize(size);

      double volumeSize = volume.getSize();
      double pct = volumeSize / DEFAULT_TEMPLATE_SIZE;
      if (pct >= 1.0) {
        volume.setStatus(Status.DOWNLOADED);
        _mockVolumeDao.update(volume.getId(), volume);
        txn.commit();
        return new DownloadAnswer(cmd.getJobId(), 100, cmd,
            com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED, volume.getPath(),
            volume.getName());
      } else {
        _mockVolumeDao.update(volume.getId(), volume);
        txn.commit();
        return new DownloadAnswer(cmd.getJobId(), (int) (pct * 100.0), cmd,
            com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS, volume.getPath(),
            volume.getName());
      }
    } catch (Exception ex) {
      txn.rollback();
View Full Code Here

        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
        try {
            txn.start();
            ssvo = _mockSecStorageDao.findByUrl(cmd.getSecUrl());
            if (ssvo == null) {
                return new DownloadAnswer("can't find secondary storage",
                        VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
            }
            txn.commit();
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Error accessing secondary storage " + cmd.getSecUrl(), ex);
        } finally {
            txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
        }

        MockVolumeVO volume = new MockVolumeVO();
        volume.setPoolId(ssvo.getId());
        volume.setName(cmd.getName());
        volume.setPath(ssvo.getMountPoint() + cmd.getName());
        volume.setSize(0);
        volume.setType(MockVolumeType.TEMPLATE);
        volume.setStatus(Status.DOWNLOAD_IN_PROGRESS);
        txn = Transaction.open(Transaction.SIMULATOR_DB);
        try {
            txn.start();
            volume = _mockVolumeDao.persist(volume);
            txn.commit();
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Error when saving volume " + volume, ex);
        } finally {
            txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
        }
        return new DownloadAnswer(String.valueOf(volume.getId()), 0, "Downloading", Status.DOWNLOAD_IN_PROGRESS,
                cmd.getName(), cmd.getName(), volume.getSize(), volume.getSize(), null);
    }
View Full Code Here

        try {
            txn.start();
            String volumeId = cmd.getJobId();
            MockVolumeVO volume = _mockVolumeDao.findById(Long.parseLong(volumeId));
            if (volume == null) {
                return new DownloadAnswer("Can't find the downloading volume", Status.ABANDONED);
            }

            long size = Math.min(volume.getSize() + DEFAULT_TEMPLATE_SIZE / 5, DEFAULT_TEMPLATE_SIZE);
            volume.setSize(size);

            double volumeSize = volume.getSize();
            double pct = volumeSize / DEFAULT_TEMPLATE_SIZE;
            if (pct >= 1.0) {
                volume.setStatus(Status.DOWNLOADED);
                _mockVolumeDao.update(volume.getId(), volume);
                txn.commit();
                return new DownloadAnswer(cmd.getJobId(), 100, cmd,
                        com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED, volume.getPath(),
                        volume.getName());
            } else {
                _mockVolumeDao.update(volume.getId(), volume);
                txn.commit();
                return new DownloadAnswer(cmd.getJobId(), (int) (pct * 100.0), cmd,
                        com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS, volume.getPath(),
                        volume.getName());
            }
        } catch (Exception ex) {
            txn.rollback();
View Full Code Here

        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");

    }
View Full Code Here

    protected Void createTemplateAsyncCallback(AsyncCallbackDispatcher<? extends BaseImageStoreDriverImpl, DownloadAnswer> callback,
            CreateContext<CreateCmdResult> context) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Performing image store createTemplate async callback");
        }
        DownloadAnswer answer = callback.getResult();
        DataObject obj = context.data;
        DataStore store = obj.getDataStore();

        TemplateDataStoreVO tmpltStoreVO = _templateStoreDao.findByStoreTemplate(store.getId(), obj.getId());
        if (tmpltStoreVO != null) {
            if (tmpltStoreVO.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Template is already in DOWNLOADED state, ignore further incoming DownloadAnswer");
                }
                return null;
            }
            TemplateDataStoreVO updateBuilder = _templateStoreDao.createForUpdate();
            updateBuilder.setDownloadPercent(answer.getDownloadPct());
            updateBuilder.setDownloadState(answer.getDownloadStatus());
            updateBuilder.setLastUpdated(new Date());
            updateBuilder.setErrorString(answer.getErrorString());
            updateBuilder.setJobId(answer.getJobId());
            updateBuilder.setLocalDownloadPath(answer.getDownloadPath());
            updateBuilder.setInstallPath(answer.getInstallPath());
            updateBuilder.setSize(answer.getTemplateSize());
            updateBuilder.setPhysicalSize(answer.getTemplatePhySicalSize());
            _templateStoreDao.update(tmpltStoreVO.getId(), updateBuilder);
            // update size in vm_template table
            VMTemplateVO tmlptUpdater = _templateDao.createForUpdate();
            tmlptUpdater.setSize(answer.getTemplateSize());
            _templateDao.update(obj.getId(), tmlptUpdater);
        }

        AsyncCompletionCallback<CreateCmdResult> caller = context.getParentCallback();

        if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR
                || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.ABANDONED
                || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.UNKNOWN) {
            CreateCmdResult result = new CreateCmdResult(null, null);
            result.setSuccess(false);
            result.setResult(answer.getErrorString());
            caller.complete(result);
        } else if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
            if (answer.getCheckSum() != null) {
                VMTemplateVO templateDaoBuilder = _templateDao.createForUpdate();
                templateDaoBuilder.setChecksum(answer.getCheckSum());
                _templateDao.update(obj.getId(), templateDaoBuilder);
            }

            CreateCmdResult result = new CreateCmdResult(null, null);
            caller.complete(result);
View Full Code Here

        return null;
    }

    protected Void createVolumeAsyncCallback(AsyncCallbackDispatcher<? extends BaseImageStoreDriverImpl, DownloadAnswer> callback,
            CreateContext<CreateCmdResult> context) {
        DownloadAnswer answer = callback.getResult();
        DataObject obj = context.data;
        DataStore store = obj.getDataStore();

        VolumeDataStoreVO volStoreVO = _volumeStoreDao.findByStoreVolume(store.getId(), obj.getId());
        if (volStoreVO != null) {
            if (volStoreVO.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Volume is already in DOWNLOADED state, ignore further incoming DownloadAnswer");
                }
                return null;
            }
            VolumeDataStoreVO updateBuilder = _volumeStoreDao.createForUpdate();
            updateBuilder.setDownloadPercent(answer.getDownloadPct());
            updateBuilder.setDownloadState(answer.getDownloadStatus());
            updateBuilder.setLastUpdated(new Date());
            updateBuilder.setErrorString(answer.getErrorString());
            updateBuilder.setJobId(answer.getJobId());
            updateBuilder.setLocalDownloadPath(answer.getDownloadPath());
            updateBuilder.setInstallPath(answer.getInstallPath());
            updateBuilder.setSize(answer.getTemplateSize());
            updateBuilder.setPhysicalSize(answer.getTemplatePhySicalSize());
            _volumeStoreDao.update(volStoreVO.getId(), updateBuilder);
            // update size in volume table
            VolumeVO volUpdater = volumeDao.createForUpdate();
            volUpdater.setSize(answer.getTemplateSize());
            volumeDao.update(obj.getId(), volUpdater);
        }

        AsyncCompletionCallback<CreateCmdResult> caller = context.getParentCallback();

        if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR
                || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.ABANDONED
                || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.UNKNOWN) {
            CreateCmdResult result = new CreateCmdResult(null, null);
            result.setSuccess(false);
            result.setResult(answer.getErrorString());
            caller.complete(result);
        } else if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
            CreateCmdResult result = new CreateCmdResult(null, null);
            caller.complete(result);
        }
        return null;
    }
View Full Code Here

                    volumeDao.update(vol.getId(), vol);
                }
            } else {
                // image store or imageCache store
                if (answer instanceof DownloadAnswer) {
                    DownloadAnswer dwdAnswer = (DownloadAnswer) answer;
                    VolumeDataStoreVO volStore = this.volumeStoreDao.findByStoreVolume(this.dataStore.getId(),
                            this.getId());
                    volStore.setInstallPath(dwdAnswer.getInstallPath());
                    volStore.setChecksum(dwdAnswer.getCheckSum());
                    this.volumeStoreDao.update(volStore.getId(), volStore);
                } else if (answer instanceof CopyCmdAnswer) {
                    CopyCmdAnswer cpyAnswer = (CopyCmdAnswer) answer;
                    VolumeDataStoreVO volStore = this.volumeStoreDao.findByStoreVolume(this.dataStore.getId(),
                            this.getId());
View Full Code Here

                    volumeDao.update(vol.getId(), vol);
                }
            } else {
                // image store or imageCache store
                if (answer instanceof DownloadAnswer) {
                    DownloadAnswer dwdAnswer = (DownloadAnswer) answer;
                    VolumeDataStoreVO volStore = this.volumeStoreDao.findByStoreVolume(this.dataStore.getId(),
                            this.getId());
                    volStore.setInstallPath(dwdAnswer.getInstallPath());
                    volStore.setChecksum(dwdAnswer.getCheckSum());
                    this.volumeStoreDao.update(volStore.getId(), volStore);
                } else if (answer instanceof CopyCmdAnswer) {
                    CopyCmdAnswer cpyAnswer = (CopyCmdAnswer) answer;
                    VolumeDataStoreVO volStore = this.volumeStoreDao.findByStoreVolume(this.dataStore.getId(),
                            this.getId());
View Full Code Here

TOP

Related Classes of com.cloud.agent.api.storage.DownloadAnswer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.