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 507d9d337d)
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Likitha Shetty 2014-10-27 16:56:29 +05:30 committed by Rohit Yadav
parent 43a9eb40b8
commit 271dae9750
1 changed files with 17 additions and 23 deletions

View File

@ -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 {