@Override protected void runInContext() { // Start the download! download(resume, downloadCompleteCallback); }
/** * Post remote download activity (install and cleanup). Executed in context of the downloader thread. */ private String postRemoteDownload(String jobId) { String result = null; DownloadJob dnld = jobs.get(jobId); S3TemplateDownloader td = (S3TemplateDownloader)dnld.getTemplateDownloader(); if (td.getFileExtension().equalsIgnoreCase("QCOW2")) { // The QCOW2 is the only format with a header, // and as such can be easily read. try (InputStream inputStream = td.getS3ObjectInputStream();) { dnld.setTemplatesize(QCOW2Utils.getVirtualSize(inputStream)); } catch (IOException e) { result = "Couldn't read QCOW2 virtual size. Error: " + e.getMessage(); } } else { // For the other formats, both the virtual // and actual file size are set the same. dnld.setTemplatesize(td.getTotalBytes()); } dnld.setTemplatePhysicalSize(td.getTotalBytes()); dnld.setTmpltPath(td.getDownloadLocalPath()); return result; }
@Override public String downloadS3Template(S3TO s3, long id, String url, String name, ImageFormat format, boolean hvm, Long accountId, String descr, String cksum, String installPathPrefix, String user, String password, long maxTemplateSizeInBytes, Proxy proxy, ResourceType resourceType) { UUID uuid = UUID.randomUUID(); String jobId = uuid.toString(); URI uri; try { uri = new URI(url); } catch (URISyntaxException e) { throw new CloudRuntimeException("URI is incorrect: " + url); } TemplateDownloader td; if ((uri != null) && (uri.getScheme() != null)) { if (uri.getScheme().equalsIgnoreCase("http") || uri.getScheme().equalsIgnoreCase("https")) { td = new S3TemplateDownloader(s3, url, installPathPrefix, new Completion(jobId), maxTemplateSizeInBytes, user, password, proxy, resourceType); } else { throw new CloudRuntimeException("Scheme is not supported " + url); } } else { throw new CloudRuntimeException("Unable to download from URL: " + url); } DownloadJob dj = new DownloadJob(td, jobId, id, name, format, hvm, accountId, descr, cksum, installPathPrefix, resourceType); dj.setTmpltPath(installPathPrefix); jobs.put(jobId, dj); threadPool.execute(td); return jobId; }
td.setStatus(Status.UNRECOVERABLE_ERROR); td.setDownloadError("Failed post download install: " + result); ((S3TemplateDownloader) td).cleanupAfterError(); } else { td.setStatus(Status.POST_DOWNLOAD_FINISHED);