nvazquez 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_r166802567
##########
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:
Sure, rebasing 4.11 now that java implementation for checksum is merged
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services