mirror of https://github.com/apache/cloudstack.git
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
This commit is contained in:
parent
3fd95fe231
commit
d5632189dc
|
|
@ -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<HttpNfcLeaseManifestEntry> getLeaseManifest() throws Exception {
|
||||
return _context.getService().httpNfcLeaseGetManifest(_mor);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.");
|
||||
|
|
|
|||
Loading…
Reference in New Issue