From c0128e2f9a4cade8b9129de99916970c72bc212c Mon Sep 17 00:00:00 2001 From: Oscar Sandoval Date: Mon, 9 Oct 2023 01:20:13 -0700 Subject: [PATCH] Improve template download error message (#8029) --- .../direct/download/DirectDownloadManagerImpl.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/apache/cloudstack/direct/download/DirectDownloadManagerImpl.java b/server/src/main/java/org/apache/cloudstack/direct/download/DirectDownloadManagerImpl.java index 17cb96931ec8..af543c6c7989 100644 --- a/server/src/main/java/org/apache/cloudstack/direct/download/DirectDownloadManagerImpl.java +++ b/server/src/main/java/org/apache/cloudstack/direct/download/DirectDownloadManagerImpl.java @@ -42,6 +42,7 @@ import javax.naming.ConfigurationException; import com.cloud.exception.InvalidParameterValueException; +import com.cloud.user.Account; import com.cloud.utils.Pair; import org.apache.cloudstack.agent.directdownload.DirectDownloadAnswer; import org.apache.cloudstack.agent.directdownload.DirectDownloadCommand; @@ -329,6 +330,8 @@ private Answer sendDirectDownloadCommand(DirectDownloadCommand cmd, VMTemplateVO Long[] hostsToRetry = getHostsToRetryOn(host, storagePoolVO); int hostIndex = 0; Answer answer = null; + String answerDetails = ""; + String errorDetails = ""; Long hostToSendDownloadCmd = hostsToRetry[hostIndex]; boolean continueRetrying = true; while (!downloaded && retry > 0 && continueRetrying) { @@ -349,6 +352,7 @@ private Answer sendDirectDownloadCommand(DirectDownloadCommand cmd, VMTemplateVO if (answer != null) { DirectDownloadAnswer ans = (DirectDownloadAnswer)answer; downloaded = answer.getResult(); + answerDetails = answer.getDetails(); continueRetrying = ans.isRetryOnOtherHosts(); } hostToSendDownloadCmd = hostsToRetry[(hostIndex + 1) % hostsToRetry.length]; @@ -362,7 +366,13 @@ private Answer sendDirectDownloadCommand(DirectDownloadCommand cmd, VMTemplateVO } if (!downloaded) { logUsageEvent(template, poolId); - throw new CloudRuntimeException("Template " + template.getId() + " could not be downloaded on pool " + poolId + ", failing after trying on several hosts"); + if (!answerDetails.isEmpty()){ + Account caller = CallContext.current().getCallingAccount(); + if (caller != null && caller.getType() == Account.Type.ADMIN){ + errorDetails = String.format(" Details: %s", answerDetails); + } + } + throw new CloudRuntimeException(String.format("Template %d could not be downloaded on pool %d, failing after trying on several hosts%s", template.getId(), poolId, errorDetails)); } return answer; }