You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2018/02/06 17:17:46 UTC

[GitHub] DaanHoogland commented on a change in pull request #2447: Add retry logic to direct download and checksum, also refactoring

DaanHoogland commented on a change in pull request #2447: Add retry logic to direct download and checksum, also refactoring
URL: https://github.com/apache/cloudstack/pull/2447#discussion_r166377235
 
 

 ##########
 File path: agent/src/com/cloud/agent/direct/download/MetalinkDirectTemplateDownloader.java
 ##########
 @@ -18,32 +18,50 @@
 //
 package com.cloud.agent.direct.download;
 
-import com.cloud.utils.script.Script;
+import com.cloud.utils.UriUtils;
+import org.apache.commons.collections.CollectionUtils;
 
 import java.io.File;
+import java.util.List;
+import java.util.Map;
 
-public class MetalinkDirectTemplateDownloader extends DirectTemplateDownloaderImpl {
+public class MetalinkDirectTemplateDownloader extends HttpDirectTemplateDownloader {
 
-    private String downloadDir;
-
-    public MetalinkDirectTemplateDownloader(String url, String destPoolPath, Long templateId, String checksum) {
-        super(url, destPoolPath, templateId, checksum);
-        String relativeDir = getDirectDownloadTempPath(templateId);
-        downloadDir = getDestPoolPath() + File.separator + relativeDir;
-        createFolder(downloadDir);
+    public MetalinkDirectTemplateDownloader(String url, String destPoolPath, Long templateId, String checksum, Map<String, String> headers) {
+        super(url, templateId, destPoolPath, checksum, headers);
     }
 
     @Override
     public boolean downloadTemplate() {
-        String downloadCommand = "aria2c " + getUrl() + " -d " + downloadDir + " --check-integrity=true";
-        Script.runSimpleBashScript(downloadCommand);
-        //Remove .metalink file
-        Script.runSimpleBashScript("rm -f " + downloadDir + File.separator + getFileNameFromUrl());
-        String fileName = Script.runSimpleBashScript("ls " + downloadDir);
-        if (fileName == null) {
-            return false;
+        s_logger.debug("Retrieving metalink file from: " + getUrl() + " to file: " + getDownloadedFilePath());
+        List<String> metalinkUrls = UriUtils.getMetalinkUrls(getUrl());
+        if (CollectionUtils.isNotEmpty(metalinkUrls)) {
+            String downloadDir = getDirectDownloadTempPath(getTemplateId());
+            boolean downloaded = false;
+            int i = 0;
+            while (!downloaded && i < metalinkUrls.size()) {
 
 Review comment:
   do while would make this a little shorter, no? the complexity of this method warrant a refactor extracting a private method or so

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services