-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fixed incorrect error message on invalid template type download #4138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9775dd5
dabb83e
4db5f19
c6ccb52
fdfe7e8
977335e
b77a929
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |
| import java.net.URISyntaxException; | ||
| import java.util.Date; | ||
|
|
||
| import com.cloud.utils.exception.CloudRuntimeException; | ||
| import org.apache.cloudstack.utils.imagestore.ImageStoreUtil; | ||
| import org.apache.commons.httpclient.Credentials; | ||
| import org.apache.commons.httpclient.Header; | ||
|
|
@@ -63,7 +64,7 @@ public class HttpTemplateDownloader extends ManagedContextRunnable implements Te | |
| private String downloadUrl; | ||
| private String toFile; | ||
| public TemplateDownloader.Status status; | ||
| public String errorString = " "; | ||
| private String errorString = null; | ||
| private long remoteSize = 0; | ||
| public long downloadTime = 0; | ||
| public long totalBytes; | ||
|
|
@@ -218,7 +219,10 @@ public long download(boolean resume, DownloadCompleteCallback callback) { | |
| errorString = hte.getMessage(); | ||
| } catch (IOException ioe) { | ||
| status = TemplateDownloader.Status.UNRECOVERABLE_ERROR; //probably a file write error? | ||
| errorString = ioe.getMessage(); | ||
| // Let's not overwrite the original error message. | ||
| if (errorString == null) { | ||
| errorString = ioe.getMessage(); | ||
| } | ||
| } finally { | ||
| if (status == Status.UNRECOVERABLE_ERROR && file.exists() && !file.isDirectory()) { | ||
| file.delete(); | ||
|
|
@@ -243,7 +247,6 @@ private boolean copyBytes(File file, InputStream in, RandomAccessFile out) throw | |
| offset = writeBlock(bytes, out, block, offset); | ||
| if (!verifyFormat.isVerifiedFormat() && (offset >= 1048576 || offset >= remoteSize)) { //let's check format after we get 1MB or full file | ||
| verifyFormat.invoke(); | ||
| if (verifyFormat.isInvalid()) return true; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Spaceman1984 cc @nvazquez why are we not validating format now?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rhtyd If validation fails, an exception is thrown, so there is no setting of an invalid state that has to be checked. Validation happens inside verifyFormat.invoke();
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In short, prior to these changes the invoke() method only set the boolean variable retrieved in case of valid/invalid. After these changes, if it is invalid invoke() throws an exception, so no need to check isInvalid() in this line |
||
| } | ||
| } else { | ||
| done = true; | ||
|
|
@@ -443,7 +446,7 @@ public boolean isResume() { | |
|
|
||
| @Override | ||
| public String getDownloadError() { | ||
| return errorString; | ||
| return errorString == null ? " " : errorString; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -495,7 +498,6 @@ public ResourceType getResourceType() { | |
| } | ||
|
|
||
| private class VerifyFormat { | ||
| private boolean invalidFormat; | ||
| private File file; | ||
| private boolean verifiedFormat; | ||
|
|
||
|
|
@@ -504,10 +506,6 @@ public VerifyFormat(File file) { | |
| this.verifiedFormat = false; | ||
| } | ||
|
|
||
| boolean isInvalid() { | ||
| return invalidFormat; | ||
| } | ||
|
|
||
| public boolean isVerifiedFormat() { | ||
| return verifiedFormat; | ||
| } | ||
|
|
@@ -529,11 +527,10 @@ public VerifyFormat invoke() { | |
| } | ||
| status = Status.UNRECOVERABLE_ERROR; | ||
| errorString = "Template content is unsupported, or mismatch between selected format and template content. Found : " + unsupportedFormat; | ||
| invalidFormat = true; | ||
| throw new CloudRuntimeException(errorString); | ||
| } else { | ||
| s_logger.debug("Verified format of downloading file " + file.getAbsolutePath() + " is supported"); | ||
| verifiedFormat = true; | ||
| invalidFormat = false; | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.