Repository: cloudstack Updated Branches: refs/heads/4.4 9be404a93 -> 53fbe8401
CLOUDSTACK-8109. Extract Template is failing. Fix the OVA path that is returned once an OVA is packaged using a META file. (cherry picked from commit 507d9d337d2e80f7f6e5d665708c0687c387c5fc) Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/53fbe840 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/53fbe840 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/53fbe840 Branch: refs/heads/4.4 Commit: 53fbe840147ab5ffe6f02be155d0fbc836000e92 Parents: 9be404a Author: Likitha Shetty <likitha.she...@citrix.com> Authored: Mon Oct 27 16:56:29 2014 +0530 Committer: Daan Hoogland <d...@onecht.net> Committed: Tue Dec 23 16:29:09 2014 +0100 ---------------------------------------------------------------------- .../manager/VmwareStorageManagerImpl.java | 40 +++++++++----------- 1 file changed, 17 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/53fbe840/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java index fbba322..4437f1a 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java @@ -148,37 +148,32 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager { public String createOvaForTemplate(TemplateObjectTO template) { DataStoreTO storeTO = template.getDataStore(); if (!(storeTO instanceof NfsTO)) { - s_logger.debug("can only handle nfs storage, when create ova from volume"); + s_logger.debug("Can only handle NFS storage, while creating OVA from template"); return null; } NfsTO nfsStore = (NfsTO)storeTO; String secStorageUrl = nfsStore.getUrl(); assert (secStorageUrl != null); String installPath = template.getPath(); - String ovafileName = ""; String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl); String installFullPath = secondaryMountPoint + "/" + installPath; - - String templateName = installFullPath; // should be a file ending .ova; try { - if (templateName.endsWith(".ova")) { - if (new File(templateName).exists()) { - s_logger.debug("OVA files exists. succeed. "); - return installPath; + if (installFullPath.endsWith(".ova")) { + if (new File(installFullPath).exists()) { + s_logger.debug("OVA file found at: " + installFullPath); } else { - if (new File(templateName + ".meta").exists()) { - ovafileName = getOVAFromMetafile(templateName + ".meta"); - s_logger.debug("OVA file in meta file is " + ovafileName); - return ovafileName; + if (new File(installFullPath + ".meta").exists()) { + createOVAFromMetafile(installFullPath + ".meta"); } else { - String msg = "Unable to find ova meta or ova file to prepare template (vmware)"; + String msg = "Unable to find OVA or OVA MetaFile to prepare template."; s_logger.error(msg); throw new Exception(msg); } } + return installPath; } } catch (Throwable e) { - s_logger.debug("Failed to create ova: " + e.toString()); + s_logger.debug("Failed to create OVA: " + e.toString()); } return null; } @@ -1042,12 +1037,12 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager { // here we use a method to return the ovf and vmdk file names; Another way to do it: // create a new class, and like TemplateLocation.java and create templateOvfInfo.java to handle it; - private String getOVAFromMetafile(String metafileName) throws Exception { + private String createOVAFromMetafile(String metafileName) throws Exception { File ova_metafile = new File(metafileName); Properties props = null; FileInputStream strm = null; String ovaFileName = ""; - s_logger.info("getOVAfromMetaFile: " + metafileName); + s_logger.info("Creating OVA using MetaFile: " + metafileName); try { strm = new FileInputStream(ova_metafile); @@ -1088,18 +1083,17 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager { command.execute(); s_logger.info("Package OVA for template in dir: " + exportDir + "cmd: " + command.toString()); // to be safe, physically test existence of the target OVA file - if ((new File(exportDir + ovaFileName)).exists()) { - s_logger.info("ova file is created and ready to extract "); - return (ovaFileName); + if ((new File(exportDir + File.separator + ovaFileName)).exists()) { + s_logger.info("OVA file: " + ovaFileName +" is created and ready to extract."); + return ovaFileName; } else { - String msg = exportDir + File.separator + ovaFileName + ".ova is not created as expected"; + String msg = exportDir + File.separator + ovaFileName + " is not created as expected"; s_logger.error(msg); throw new Exception(msg); } } catch (Exception e) { - s_logger.error("Exception in getOVAFromMetafile", e); - return null; - // Do something, re-throw the exception + s_logger.error("Exception while creating OVA using Metafile", e); + throw e; } finally { if (strm != null) { try {