Package com.cloud.agent.api.storage

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


        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


        if (isTemplateUpdateable(templateId, store.getId())) {
            if (template != null && template.getUri() != null) {
                initiateTemplateDownload(template, callback);
            } else {
                s_logger.info("Template url is null, cannot download");
                DownloadAnswer ans = new DownloadAnswer("Template url is null", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR.UNKNOWN);
                callback.complete(ans);
            }
        } else {
            s_logger.info("Template download is already in progress or already downloaded");
            DownloadAnswer ans = new DownloadAnswer("Template download is already in progress or already downloaded", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR.UNKNOWN);
            callback.complete(ans);
        }
    }
View Full Code Here

    if (s_logger.isTraceEnabled()) {
      getDownloadListener().log("handleEvent, event type=" + event + ", curr state=" + getName(), Level.TRACE);
    }
    switch (event) {
    case DOWNLOAD_ANSWER:
      DownloadAnswer answer=(DownloadAnswer)eventObj;
      return handleAnswer(answer);
    case ABANDON_DOWNLOAD:
      return handleAbort();
    case TIMEOUT_CHECK:
      Date now = new Date();
View Full Code Here

        _currState=getState(Status.NOT_DOWNLOADED.toString());
        this._timer = _timer;
        _timeoutTask = new TimeoutTask(this);
        this._timer.schedule(_timeoutTask, 3*STATUS_POLL_INTERVAL);
        _callback = callback;
        DownloadAnswer answer = new DownloadAnswer("", Status.NOT_DOWNLOADED);
        callback(answer);
    }
View Full Code Here

  @Override
  public boolean processAnswers(long agentId, long seq, Answer[] answers) {
    boolean processed = false;
      if(answers != null & answers.length > 0) {
        if(answers[0] instanceof DownloadAnswer) {
          final DownloadAnswer answer = (DownloadAnswer)answers[0];
          if (getJobId() == null) {
            setJobId(answer.getJobId());
          } else if (!getJobId().equalsIgnoreCase(answer.getJobId())){
            return false;//TODO
          }
          transition(DownloadEvent.DOWNLOAD_ANSWER, answer);
          processed = true;
        }
View Full Code Here

    super.onEntry(prevState, event, evtObj);
    if (event==DownloadEvent.DISCONNECT){
      getDownloadListener().logDisconnect();
      getDownloadListener().cancelStatusTask();
      getDownloadListener().cancelTimeoutTask();
      DownloadAnswer answer = new DownloadAnswer("Storage agent or storage VM disconnected", Status.DOWNLOAD_ERROR);
      getDownloadListener().callback(answer)
      getDownloadListener().log("Entering download error state because the storage host disconnected", Level.WARN);
    } else if (event==DownloadEvent.TIMEOUT_CHECK){
      DownloadAnswer answer = new DownloadAnswer("Timeout waiting for response from storage host", Status.DOWNLOAD_ERROR);
      getDownloadListener().callback(answer);
      getDownloadListener().log("Entering download error state: timeout waiting for response from storage host", Level.WARN);
    }
    getDownloadListener().setDownloadInactive(Status.DOWNLOAD_ERROR);
  }
View Full Code Here

  @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

                .create(this);
        caller.setContext(context);
        caller.setCallback(caller.getTarget().createTemplateAsyncCallback(null, null));
        String path =  UUID.randomUUID().toString();
        Long size = new Long(5 * 1024L * 1024L);
        DownloadAnswer answer = new DownloadAnswer(null, 100, null, VMTemplateStorageResourceAssoc.Status.DOWNLOADED,
                path, path, size, size, null);
        caller.complete(answer);
        return;
    }
View Full Code Here

                .create(this);
        caller.setContext(context);
        caller.setCallback(caller.getTarget().createVolumeAsyncCallback(null, null));
        String path =  UUID.randomUUID().toString();
        Long size = new Long(5 * 1024L * 1024L);
        DownloadAnswer answer = new DownloadAnswer(null, 100, null, VMTemplateStorageResourceAssoc.Status.DOWNLOADED,
                path, path, size, size, null);
        caller.complete(answer);
        return;
    }
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

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.