mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Merge remote-tracking branch 'origin/4.14'
This commit is contained in:
commit
d76caa74ce
17
core/src/main/java/com/cloud/storage/template/HttpTemplateDownloader.java
Normal file → Executable file
17
core/src/main/java/com/cloud/storage/template/HttpTemplateDownloader.java
Normal file → Executable file
@ -27,6 +27,7 @@ import java.net.URI;
|
|||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import com.cloud.utils.exception.CloudRuntimeException;
|
||||||
import org.apache.cloudstack.utils.imagestore.ImageStoreUtil;
|
import org.apache.cloudstack.utils.imagestore.ImageStoreUtil;
|
||||||
import org.apache.commons.httpclient.Credentials;
|
import org.apache.commons.httpclient.Credentials;
|
||||||
import org.apache.commons.httpclient.Header;
|
import org.apache.commons.httpclient.Header;
|
||||||
@ -63,7 +64,7 @@ public class HttpTemplateDownloader extends ManagedContextRunnable implements Te
|
|||||||
private String downloadUrl;
|
private String downloadUrl;
|
||||||
private String toFile;
|
private String toFile;
|
||||||
public TemplateDownloader.Status status;
|
public TemplateDownloader.Status status;
|
||||||
public String errorString = " ";
|
private String errorString = null;
|
||||||
private long remoteSize = 0;
|
private long remoteSize = 0;
|
||||||
public long downloadTime = 0;
|
public long downloadTime = 0;
|
||||||
public long totalBytes;
|
public long totalBytes;
|
||||||
@ -218,7 +219,10 @@ public class HttpTemplateDownloader extends ManagedContextRunnable implements Te
|
|||||||
errorString = hte.getMessage();
|
errorString = hte.getMessage();
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
status = TemplateDownloader.Status.UNRECOVERABLE_ERROR; //probably a file write error?
|
status = TemplateDownloader.Status.UNRECOVERABLE_ERROR; //probably a file write error?
|
||||||
|
// Let's not overwrite the original error message.
|
||||||
|
if (errorString == null) {
|
||||||
errorString = ioe.getMessage();
|
errorString = ioe.getMessage();
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (status == Status.UNRECOVERABLE_ERROR && file.exists() && !file.isDirectory()) {
|
if (status == Status.UNRECOVERABLE_ERROR && file.exists() && !file.isDirectory()) {
|
||||||
file.delete();
|
file.delete();
|
||||||
@ -243,7 +247,6 @@ public class HttpTemplateDownloader extends ManagedContextRunnable implements Te
|
|||||||
offset = writeBlock(bytes, out, block, offset);
|
offset = writeBlock(bytes, out, block, offset);
|
||||||
if (!verifyFormat.isVerifiedFormat() && (offset >= 1048576 || offset >= remoteSize)) { //let's check format after we get 1MB or full file
|
if (!verifyFormat.isVerifiedFormat() && (offset >= 1048576 || offset >= remoteSize)) { //let's check format after we get 1MB or full file
|
||||||
verifyFormat.invoke();
|
verifyFormat.invoke();
|
||||||
if (verifyFormat.isInvalid()) return true;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
done = true;
|
done = true;
|
||||||
@ -443,7 +446,7 @@ public class HttpTemplateDownloader extends ManagedContextRunnable implements Te
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDownloadError() {
|
public String getDownloadError() {
|
||||||
return errorString;
|
return errorString == null ? " " : errorString;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -495,7 +498,6 @@ public class HttpTemplateDownloader extends ManagedContextRunnable implements Te
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class VerifyFormat {
|
private class VerifyFormat {
|
||||||
private boolean invalidFormat;
|
|
||||||
private File file;
|
private File file;
|
||||||
private boolean verifiedFormat;
|
private boolean verifiedFormat;
|
||||||
|
|
||||||
@ -504,10 +506,6 @@ public class HttpTemplateDownloader extends ManagedContextRunnable implements Te
|
|||||||
this.verifiedFormat = false;
|
this.verifiedFormat = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isInvalid() {
|
|
||||||
return invalidFormat;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isVerifiedFormat() {
|
public boolean isVerifiedFormat() {
|
||||||
return verifiedFormat;
|
return verifiedFormat;
|
||||||
}
|
}
|
||||||
@ -529,11 +527,10 @@ public class HttpTemplateDownloader extends ManagedContextRunnable implements Te
|
|||||||
}
|
}
|
||||||
status = Status.UNRECOVERABLE_ERROR;
|
status = Status.UNRECOVERABLE_ERROR;
|
||||||
errorString = "Template content is unsupported, or mismatch between selected format and template content. Found : " + unsupportedFormat;
|
errorString = "Template content is unsupported, or mismatch between selected format and template content. Found : " + unsupportedFormat;
|
||||||
invalidFormat = true;
|
throw new CloudRuntimeException(errorString);
|
||||||
} else {
|
} else {
|
||||||
s_logger.debug("Verified format of downloading file " + file.getAbsolutePath() + " is supported");
|
s_logger.debug("Verified format of downloading file " + file.getAbsolutePath() + " is supported");
|
||||||
verifiedFormat = true;
|
verifiedFormat = true;
|
||||||
invalidFormat = false;
|
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user