You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ro...@apache.org on 2018/02/10 17:29:02 UTC
[cloudstack] branch 4.11 updated: CLOUDSTACK-10251: HTTPS
downloader for Direct Download templates failure (#2424)
This is an automated email from the ASF dual-hosted git repository.
rohit pushed a commit to branch 4.11
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/4.11 by this push:
new 6e09529 CLOUDSTACK-10251: HTTPS downloader for Direct Download templates failure (#2424)
6e09529 is described below
commit 6e09529bdee0be84cb435beef0735444b3f6f692
Author: Nicolas Vazquez <ni...@gmail.com>
AuthorDate: Sat Feb 10 14:28:59 2018 -0300
CLOUDSTACK-10251: HTTPS downloader for Direct Download templates failure (#2424)
Failure on HTTPS downloader for Direct Download templates on KVM.
Reason: Incorrect request caused NullPointerException getting the response InputStream
---
.../download/HttpsDirectTemplateDownloader.java | 31 ++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/agent/src/com/cloud/agent/direct/download/HttpsDirectTemplateDownloader.java b/agent/src/com/cloud/agent/direct/download/HttpsDirectTemplateDownloader.java
index 436303f..664181f 100644
--- a/agent/src/com/cloud/agent/direct/download/HttpsDirectTemplateDownloader.java
+++ b/agent/src/com/cloud/agent/direct/download/HttpsDirectTemplateDownloader.java
@@ -21,6 +21,9 @@ package com.cloud.agent.direct.download;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;
+import org.apache.commons.io.IOUtils;
+import org.apache.http.HttpEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
@@ -33,6 +36,9 @@ import javax.net.ssl.SSLContext;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.FileOutputStream;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
@@ -79,11 +85,32 @@ public class HttpsDirectTemplateDownloader extends HttpDirectTemplateDownloader
@Override
public boolean downloadTemplate() {
+ CloseableHttpResponse response;
try {
- httpsClient.execute(req);
+ response = httpsClient.execute(req);
} catch (IOException e) {
throw new CloudRuntimeException("Error on HTTPS request: " + e.getMessage());
}
- return performDownload();
+ return consumeResponse(response);
}
+
+ /**
+ * Consume response and persist it on getDownloadedFilePath() file
+ */
+ protected boolean consumeResponse(CloseableHttpResponse response) {
+ if (response.getStatusLine().getStatusCode() != 200) {
+ throw new CloudRuntimeException("Error on HTTPS response");
+ }
+ try {
+ HttpEntity entity = response.getEntity();
+ InputStream in = entity.getContent();
+ OutputStream out = new FileOutputStream(getDownloadedFilePath());
+ IOUtils.copy(in, out);
+ } catch (Exception e) {
+ s_logger.error("Error parsing response for template " + getTemplateId() + " due to: " + e.getMessage());
+ return false;
+ }
+ return true;
+ }
+
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
rohit@apache.org.