[ https://issues.apache.org/jira/browse/CLOUDSTACK-10238?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16368755#comment-16368755 ]
ASF GitHub Bot commented on CLOUDSTACK-10238: --------------------------------------------- nvazquez closed pull request #2411: CLOUDSTACK-10238: Fix for metalink support on SSVM agents URL: https://github.com/apache/cloudstack/pull/2411 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/core/src/com/cloud/storage/template/MetalinkTemplateDownloader.java b/core/src/com/cloud/storage/template/MetalinkTemplateDownloader.java index 149c6a1e826..bf898c52cd9 100644 --- a/core/src/com/cloud/storage/template/MetalinkTemplateDownloader.java +++ b/core/src/com/cloud/storage/template/MetalinkTemplateDownloader.java @@ -34,22 +34,41 @@ public MetalinkTemplateDownloader(StorageLayer storageLayer, String downloadUrl, super(storageLayer, downloadUrl, toDir, maxTemplateSize, callback); String[] parts = _downloadUrl.split("/"); String filename = parts[parts.length - 1]; + _callback = callback; _toFile = toDir + File.separator + filename; } @Override public long download(boolean resume, DownloadCompleteCallback callback) { - if (!status.equals(Status.NOT_STARTED)) { - // Only start downloading if we haven't started yet. - LOGGER.debug("Template download is already started, not starting again. Template: " + _downloadUrl); + if (_status == Status.ABORTED || _status == Status.UNRECOVERABLE_ERROR || _status == Status.DOWNLOAD_FINISHED) { return 0; } + + LOGGER.info("Starting metalink download from: " + _downloadUrl); + _start = System.currentTimeMillis(); + status = Status.IN_PROGRESS; Script.runSimpleBashScript("aria2c " + _downloadUrl + " -d " + _toDir); + String metalinkFile = _toFile; + Script.runSimpleBashScript("rm -f " + metalinkFile); + String templateFileName = Script.runSimpleBashScript("ls " + _toDir); + String downloadedFile = _toDir + File.separator + templateFileName; + _toFile = _toDir + File.separator + "tmpdownld_"; + Script.runSimpleBashScript("mv " + downloadedFile + " " + _toFile); + + File file = new File(_toFile); + if (!file.exists()) { + _status = Status.UNRECOVERABLE_ERROR; + LOGGER.error("Error downloading template from: " + _downloadUrl); + return 0; + } + _totalBytes = file.length(); status = Status.DOWNLOAD_FINISHED; - String sizeResult = Script.runSimpleBashScript("ls -als " + _toFile + " | awk '{print $1}'"); - long size = Long.parseLong(sizeResult); - return size; + _downloadTime = System.currentTimeMillis() - _start; + if (_callback != null) { + _callback.downloadComplete(status); + } + return _totalBytes; } @Override @@ -63,4 +82,13 @@ public int getDownloadPercent() { } } + @Override + public Status getStatus() { + return status; + } + + @Override + public void setStatus(Status status) { + this.status = status; + } } diff --git a/utils/src/main/java/com/cloud/utils/UriUtils.java b/utils/src/main/java/com/cloud/utils/UriUtils.java index d7fbb89e47e..c91c9cc307c 100644 --- a/utils/src/main/java/com/cloud/utils/UriUtils.java +++ b/utils/src/main/java/com/cloud/utils/UriUtils.java @@ -444,7 +444,8 @@ private static void checkFormat(String format, String uripath) { && (!uripath.toLowerCase().endsWith("ova") && !uripath.toLowerCase().endsWith("ova.zip") && !uripath.toLowerCase().endsWith("ova.bz2") - && !uripath.toLowerCase().endsWith("ova.gz"))) + && !uripath.toLowerCase().endsWith("ova.gz") + && !uripath.toLowerCase().endsWith("metalink"))) || (format.equalsIgnoreCase("tar") && (!uripath.toLowerCase().endsWith("tar") && !uripath.toLowerCase().endsWith("tar.zip") @@ -468,7 +469,8 @@ private static void checkFormat(String format, String uripath) { && (!uripath.toLowerCase().endsWith("iso") && !uripath.toLowerCase().endsWith("iso.zip") && !uripath.toLowerCase().endsWith("iso.bz2") - && !uripath.toLowerCase().endsWith("iso.gz")))) { + && !uripath.toLowerCase().endsWith("iso.gz")) + && !uripath.toLowerCase().endsWith("metalink"))) { throw new IllegalArgumentException("Please specify a valid URL. URL:" + uripath + " is an invalid for the format " + format.toLowerCase()); } ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Fix for metalink support on SSVM agents > --------------------------------------- > > Key: CLOUDSTACK-10238 > URL: https://issues.apache.org/jira/browse/CLOUDSTACK-10238 > Project: CloudStack > Issue Type: Bug > Security Level: Public(Anyone can view this level - this is the > default.) > Reporter: Nicolas Vazquez > Assignee: Nicolas Vazquez > Priority: Major > > Fix for metalink support -- This message was sent by Atlassian JIRA (v7.6.3#76005)