Package com.cloud.agent.api.storage

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


    protected Answer registerTemplateOnSwift(DownloadCommand cmd) {
        SwiftTO swiftTO = (SwiftTO)cmd.getDataStore();
        String path = cmd.getInstallPath();
        DataStoreTO cacheStore = cmd.getCacheStore();
        if (cacheStore == null || !(cacheStore instanceof NfsTO)) {
            return new DownloadAnswer("cache store can't be null", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
        }

        File file = null;
        try {
            NfsTO nfsCacheStore = (NfsTO)cacheStore;
            String fileName = cmd.getName() + "." + cmd.getFormat().getFileExtension();
            file = downloadFromUrlToNfs(cmd.getUrl(), nfsCacheStore, path, fileName);
            String container = "T-" + cmd.getId();
            String swiftPath = SwiftUtil.putObject(swiftTO, file, container, null);

            //put metda file
            File uniqDir = _storage.createUniqDir();
            String metaFileName = uniqDir.getAbsolutePath() + File.separator + "template.properties";
            _storage.create(uniqDir.getAbsolutePath(), "template.properties");
            File metaFile = new File(metaFileName);
            FileWriter writer = new FileWriter(metaFile);
            BufferedWriter bufferWriter = new BufferedWriter(writer);
            bufferWriter.write("uniquename=" + cmd.getName());
            bufferWriter.write("\n");
            bufferWriter.write("filename=" + fileName);
            bufferWriter.write("\n");
            bufferWriter.write("size=" + file.length());
            bufferWriter.close();
            writer.close();

            SwiftUtil.putObject(swiftTO, metaFile, container, "template.properties");
            metaFile.delete();
            uniqDir.delete();
            String md5sum = null;
            try {
                md5sum = DigestUtils.md5Hex(new FileInputStream(file));
            } catch (IOException e) {
                s_logger.debug("Failed to get md5sum: " + file.getAbsoluteFile());
            }

            DownloadAnswer answer =
                    new DownloadAnswer(null, 100, null, VMTemplateStorageResourceAssoc.Status.DOWNLOADED, swiftPath, swiftPath, file.length(), file.length(), md5sum);
            return answer;
        } catch (IOException e) {
            s_logger.debug("Failed to register template into swift", e);
            return new DownloadAnswer(e.toString(), VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
        } finally {
            if (file != null) {
                file.delete();
            }
        }
View Full Code Here


        AsyncCallbackDispatcher<SimulatorImageStoreDriverImpl, DownloadAnswer> caller = AsyncCallbackDispatcher.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

        AsyncCallbackDispatcher<SimulatorImageStoreDriverImpl, DownloadAnswer> caller = AsyncCallbackDispatcher.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

                    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

  }

  @Override
  public Answer executeRequest(Command cmd) {
        if (cmd instanceof DownloadProgressCommand) {
            return new DownloadAnswer(null, 100, cmd,
                com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED,
                "dummyFS",
                "/dummy");
        } else if (cmd instanceof DownloadCommand) {
            return new DownloadAnswer(null, 100, cmd,
                com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED,
                "dummyFS",
                "/dummy");
        } else if (cmd instanceof GetStorageStatsCommand) {
          return execute((GetStorageStatsCommand)cmd);
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

        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", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
        }

        if (cmd.getName() == null) {
            return new DownloadAnswer("Invalid Name", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
        }

        String installPathPrefix = null;
        if (ResourceType.TEMPLATE == resourceType){
          installPathPrefix = resource.getRootDir(cmd) + File.separator + _templateDir;
        }else {
          installPathPrefix = resource.getRootDir(cmd) + File.separator + _volumeDir;
        }

        String user = null;
        String password = null;
        if (cmd.getAuth() != null) {
            user = cmd.getAuth().getUserName();
            password = new String(cmd.getAuth().getPassword());
        }
        //TO DO - Define Volume max size as well
        long maxDownloadSizeInBytes = (cmd.getMaxDownloadSizeInBytes() == null) ? TemplateDownloader.DEFAULT_MAX_TEMPLATE_SIZE_IN_BYTES : (cmd.getMaxDownloadSizeInBytes());
        String jobId = downloadPublicTemplate(cmd.getId(), cmd.getUrl(), cmd.getName(), cmd.getFormat(), cmd.isHvm(), cmd.getAccountId(), cmd.getDescription(), cmd.getChecksum(), installPathPrefix, user, password, maxDownloadSizeInBytes, cmd.getProxy(), resourceType);
        sleep();
        if (jobId == null) {
            return new DownloadAnswer("Internal Error", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
        }
        return new DownloadAnswer(jobId, getDownloadPct(jobId), getDownloadError(jobId), getDownloadStatus2(jobId), getDownloadLocalPath(jobId), getInstallPath(jobId),
                getDownloadTemplateSize(jobId), getDownloadTemplateSize(jobId), getDownloadCheckSum(jobId));
    }
View Full Code Here

        }
    }

    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", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR.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:
            break; // TODO
        }
        return new DownloadAnswer(jobId, getDownloadPct(jobId), getDownloadError(jobId), getDownloadStatus2(jobId), getDownloadLocalPath(jobId),
                getInstallPath(jobId), getDownloadTemplateSize(jobId), getDownloadTemplatePhysicalSize(jobId), getDownloadCheckSum(jobId));
    }
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

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.