@Override public DownloadAnswer handleDownloadCommand(SecondaryStorageResource resource, DownloadCommand cmd) { int timeout = NumbersUtil.parseInt(cmd.getContextParam("vmware.package.ova.timeout"), 3600000); this._processTimeout = timeout; 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", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR); if (cmd.getName() == null) { return new DownloadAnswer("Invalid Name", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR); if(! DigestHelper.isAlgorithmSupported(cmd.getChecksum())) { return new DownloadAnswer("invalid algorithm: " + cmd.getChecksum(), VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED); DataStoreTO dstore = cmd.getDataStore(); String installPathPrefix = cmd.getInstallPath(); if (cmd.getAuth() != null) { user = cmd.getAuth().getUserName(); password = cmd.getAuth().getPassword(); (cmd.getMaxDownloadSizeInBytes() == null) ? TemplateDownloader.DEFAULT_MAX_TEMPLATE_SIZE_IN_BYTES : (cmd.getMaxDownloadSizeInBytes()); String jobId = null; if (dstore instanceof S3TO) { jobId = downloadS3Template((S3TO)dstore, cmd.getId(), cmd.getUrl(), cmd.getName(), cmd.getFormat(), cmd.isHvm(), cmd.getAccountId(), cmd.getDescription(),
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); 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); String uniqueName = cmd.getName();
public DownloadCommand(DownloadCommand that) { super(that); hvm = that.hvm; checksum = that.checksum; id = that.id; description = that.description; auth = that.getAuth(); setSecUrl(that.getSecUrl()); maxDownloadSizeInBytes = that.getMaxDownloadSizeInBytes(); resourceType = that.resourceType; installPath = that.installPath; _store = that._store; _proxy = that._proxy; }
@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); }
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); dcmd.setCreds(TemplateConstants.DEFAULT_HTTP_AUTH_USER, _copyAuthPasswd);
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);
DownloadCommand dcmd = new DownloadCommand(cmd); return handleDownloadCommand(resource, dcmd); } else {
URL url = new URL("file:///" + dir + "/reports.csv"); FileURLConnection urlConn = (FileURLConnection) url.openConnection(); String contentType = "text/csv"; ApplicationInstance.getActive().enqueueCommand(new DownloadCommand( new FileDownload(contentType,"inline", filename.toString(), urlConn.getInputStream())));