Skip to content

Commit d563218

Browse files
author
Likitha Shetty
committed
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
1 parent 3fd95fe commit d563218

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

vmware-base/src/com/cloud/hypervisor/vmware/mo/HttpNfcLeaseMO.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.vmware.vim25.HttpNfcLeaseInfo;
3232
import com.vmware.vim25.HttpNfcLeaseManifestEntry;
3333
import com.vmware.vim25.HttpNfcLeaseState;
34+
import com.vmware.vim25.LocalizedMethodFault;
3435
import com.vmware.vim25.ManagedObjectReference;
3536
import com.vmware.vim25.ObjectSpec;
3637
import com.vmware.vim25.OvfCreateImportSpecResult;
@@ -83,6 +84,10 @@ public HttpNfcLeaseInfo getLeaseInfo() throws Exception {
8384
return (HttpNfcLeaseInfo)_context.getVimClient().getDynamicProperty(_mor, "info");
8485
}
8586

87+
public LocalizedMethodFault getLeaseError() throws Exception {
88+
return (LocalizedMethodFault)_context.getVimClient().getDynamicProperty(_mor, "error");
89+
}
90+
8691
public List<HttpNfcLeaseManifestEntry> getLeaseManifest() throws Exception {
8792
return _context.getService().httpNfcLeaseGetManifest(_mor);
8893
}

vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
import com.vmware.vim25.HttpNfcLeaseInfo;
4646
import com.vmware.vim25.HttpNfcLeaseState;
4747
import com.vmware.vim25.LongPolicy;
48+
import com.vmware.vim25.LocalizedMethodFault;
4849
import com.vmware.vim25.ManagedObjectReference;
50+
import com.vmware.vim25.MethodFault;
4951
import com.vmware.vim25.ObjectContent;
5052
import com.vmware.vim25.OvfCreateImportSpecParams;
5153
import com.vmware.vim25.OvfCreateImportSpecResult;
@@ -1377,17 +1379,28 @@ public void action(Long param) {
13771379
}
13781380
}
13791381
} catch (Exception e) {
1380-
s_logger.error("Failed to complete file upload task. " + e.getMessage());
1381-
// Set flag to cleanup the stale template left due to failed import operation, if any
1382-
importSuccess = false;
1383-
throw e;
1382+
String erroMsg = "File upload task failed to complete due to: " + e.getMessage();
1383+
s_logger.error(erroMsg);
1384+
importSuccess = false; // Set flag to cleanup the stale template left due to failed import operation, if any
1385+
throw new Exception(erroMsg);
1386+
} catch (Throwable th) {
1387+
String errorMsg = "throwable caught during file upload task: " + th.getMessage();
1388+
s_logger.error(errorMsg);
1389+
importSuccess = false; // Set flag to cleanup the stale template left due to failed import operation, if any
1390+
throw new Exception(errorMsg, th);
13841391
} finally {
13851392
progressReporter.close();
13861393
}
13871394
if (bytesAlreadyWritten == totalBytes) {
13881395
leaseMo.updateLeaseProgress(100);
13891396
}
1390-
}
1397+
} else if(state == HttpNfcLeaseState.ERROR) {
1398+
LocalizedMethodFault error = leaseMo.getLeaseError();
1399+
MethodFault fault = error.getFault();
1400+
String erroMsg = "Object creation on vCenter failed due to: Exception: " + fault.getClass().getName() + ", message: " + error.getLocalizedMessage();
1401+
s_logger.error(erroMsg);
1402+
throw new Exception(erroMsg);
1403+
}
13911404
} finally {
13921405
if (!importSuccess) {
13931406
s_logger.error("Aborting the lease on " + vmName + " after import operation failed.");

0 commit comments

Comments
 (0)