From d5632189dcec9885cd50a45b990383efb92182cb Mon Sep 17 00:00:00 2001 From: Likitha Shetty Date: Sun, 10 Nov 2013 10:55:16 +0530 Subject: [PATCH] CLOUDSTACK-5096. Corrupt template is left behind after the copy of a template from secondary to primary fails. If HttpNfcLease initialization fails throw appropriate error Catch throwable in addition to exceptions during file upload task while importing the OVA into vCenter --- .../hypervisor/vmware/mo/HttpNfcLeaseMO.java | 5 ++++ .../vmware/mo/HypervisorHostHelper.java | 23 +++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HttpNfcLeaseMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HttpNfcLeaseMO.java index ca362809f3a..72424524074 100755 --- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HttpNfcLeaseMO.java +++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HttpNfcLeaseMO.java @@ -31,6 +31,7 @@ import com.cloud.hypervisor.vmware.util.VmwareContext; import com.vmware.vim25.HttpNfcLeaseInfo; import com.vmware.vim25.HttpNfcLeaseManifestEntry; import com.vmware.vim25.HttpNfcLeaseState; +import com.vmware.vim25.LocalizedMethodFault; import com.vmware.vim25.ManagedObjectReference; import com.vmware.vim25.ObjectSpec; import com.vmware.vim25.OvfCreateImportSpecResult; @@ -83,6 +84,10 @@ public class HttpNfcLeaseMO extends BaseMO { return (HttpNfcLeaseInfo)_context.getVimClient().getDynamicProperty(_mor, "info"); } + public LocalizedMethodFault getLeaseError() throws Exception { + return (LocalizedMethodFault)_context.getVimClient().getDynamicProperty(_mor, "error"); + } + public List getLeaseManifest() throws Exception { return _context.getService().httpNfcLeaseGetManifest(_mor); } diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java index cd2c3e8746c..0882e22b8c0 100755 --- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java +++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java @@ -45,7 +45,9 @@ import com.vmware.vim25.HttpNfcLeaseDeviceUrl; import com.vmware.vim25.HttpNfcLeaseInfo; import com.vmware.vim25.HttpNfcLeaseState; import com.vmware.vim25.LongPolicy; +import com.vmware.vim25.LocalizedMethodFault; import com.vmware.vim25.ManagedObjectReference; +import com.vmware.vim25.MethodFault; import com.vmware.vim25.ObjectContent; import com.vmware.vim25.OvfCreateImportSpecParams; import com.vmware.vim25.OvfCreateImportSpecResult; @@ -1377,17 +1379,28 @@ public class HypervisorHostHelper { } } } catch (Exception e) { - s_logger.error("Failed to complete file upload task. " + e.getMessage()); - // Set flag to cleanup the stale template left due to failed import operation, if any - importSuccess = false; - throw e; + String erroMsg = "File upload task failed to complete due to: " + e.getMessage(); + s_logger.error(erroMsg); + importSuccess = false; // Set flag to cleanup the stale template left due to failed import operation, if any + throw new Exception(erroMsg); + } catch (Throwable th) { + String errorMsg = "throwable caught during file upload task: " + th.getMessage(); + s_logger.error(errorMsg); + importSuccess = false; // Set flag to cleanup the stale template left due to failed import operation, if any + throw new Exception(errorMsg, th); } finally { progressReporter.close(); } if (bytesAlreadyWritten == totalBytes) { leaseMo.updateLeaseProgress(100); } - } + } else if(state == HttpNfcLeaseState.ERROR) { + LocalizedMethodFault error = leaseMo.getLeaseError(); + MethodFault fault = error.getFault(); + String erroMsg = "Object creation on vCenter failed due to: Exception: " + fault.getClass().getName() + ", message: " + error.getLocalizedMessage(); + s_logger.error(erroMsg); + throw new Exception(erroMsg); + } } finally { if (!importSuccess) { s_logger.error("Aborting the lease on " + vmName + " after import operation failed.");