cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] DaanHoogland commented on a change in pull request #2447: Add retry logic to direct download and checksum, also refactoring
Date Thu, 01 Jan 1970 00:00:00 GMT
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_r166377557
 
 

 ##########
 File path: agent/src/com/cloud/agent/direct/download/DirectTemplateDownloaderImpl.java
 ##########
 @@ -170,15 +177,45 @@ private String getChecksumCommandFromAlgorithm(String algorithm) {
         }
     }
 
+    /**
+     * Delete and create download file
+     */
+    private void resetDownloadFile() {
+        File f = new File(getDownloadedFilePath());
+        s_logger.debug("Resetting download file: " + getDownloadedFilePath() + ", in order
to re-download and persist template " + templateId + " on it");
+        try {
+            if (f.exists()) {
+                f.delete();
+            }
+            f.createNewFile();
+        } catch (IOException e) {
+            s_logger.error("Error creating file to download on: " + getDownloadedFilePath()
+ " due to: " + e.getMessage());
+            throw new CloudRuntimeException("Failed to create download file for direct download");
+        }
+    }
+
     @Override
     public boolean validateChecksum() {
         if (StringUtils.isNotBlank(checksum)) {
+            int retry = 3;
+            boolean valid = false;
             ChecksumValue providedChecksum = new ChecksumValue(checksum);
             String algorithm = providedChecksum.getAlgorithm();
             String checksumCommand = "echo '%s %s' | %s -c --quiet";
             String cmd = String.format(checksumCommand, providedChecksum.getChecksum(), downloadedFilePath,
getChecksumCommandFromAlgorithm(algorithm));
-            int result = Script.runSimpleBashScriptForExitValue(cmd);
-            return result == 0;
+            int result;
+            while (!valid && retry > 0) {
+                s_logger.debug("Performing checksum validation for downloaded template "
+ templateId + ", retries left: " + retry);
+                result = Script.runSimpleBashScriptForExitValue(cmd);
 
 Review comment:
   please refactor touse the java implementation of the checksum code

----------------------------------------------------------------
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

Mime
View raw message