From 784a9d45d031bbc354996f85ba76347c360aac72 Mon Sep 17 00:00:00 2001 From: Edison Su Date: Thu, 8 Aug 2013 12:34:24 -0700 Subject: [PATCH] CLOUDSTACK-4106: fix volume related operations on vmware&s3 --- .../motion/AncientDataMotionStrategy.java | 19 ++++++++------- .../resource/VmwareStorageProcessor.java | 23 ++++++++++++------- .../cloud/template/TemplateManagerImpl.java | 2 +- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java b/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java index 5b791abb26a..f069ffa3fbd 100644 --- a/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java +++ b/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java @@ -437,19 +437,18 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { EndPoint ep = selector.select(srcData, destData); answer = ep.sendMessage(cmd); } - // clean up cache entry in case of failure - if (answer == null || !answer.getResult()) { - if (cacheData != null) { - cacheMgr.deleteCacheObject(cacheData); - } - } - return answer; - } catch (Exception e) { - s_logger.debug("copy snasphot failed: " + e.toString()); + if (cacheData != null) { cacheMgr.deleteCacheObject(cacheData); } - throw new CloudRuntimeException(e.toString()); + + return answer; + } catch (Exception e) { + s_logger.debug("copy snasphot failed: ", e); + if (cacheData != null) { + cacheMgr.deleteCacheObject(cacheData); + } + throw new CloudRuntimeException(e); } } diff --git a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java index c4d6119aba8..aed8f45cec6 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java +++ b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java @@ -1040,13 +1040,16 @@ public class VmwareStorageProcessor implements StorageProcessor { morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, primaryStore.getUuid()); try { - vmMo = hyperHost.findVmOnHyperHost(vmName); + if (vmName != null) { + vmMo = hyperHost.findVmOnHyperHost(vmName); + } if (vmMo == null) { if(s_logger.isDebugEnabled()) { s_logger.debug("Unable to find owner VM for BackupSnapshotCommand on host " + hyperHost.getHyperHostName() + ", will try within datacenter"); } - - vmMo = hyperHost.findVmOnPeerHyperHost(vmName); + if (vmName != null) { + vmMo = hyperHost.findVmOnPeerHyperHost(vmName); + } if(vmMo == null) { dsMo = new DatastoreMO(hyperHost.getContext(), morDs); @@ -1489,17 +1492,21 @@ public class VmwareStorageProcessor implements StorageProcessor { String secondaryMountPoint = mountService.getMountPoint(secStorageUrl); String srcOVAFileName = null; String srcOVFFileName = null; - - srcOVAFileName = secondaryMountPoint + "/" + secStorageDir + "/" + if (backupName.endsWith(".ova")) { + srcOVAFileName = secondaryMountPoint + "/" + secStorageDir + "/" + + backupName; + srcOVFFileName = secondaryMountPoint + "/" + secStorageDir + "/" + + backupName.replace(".ova", ".ovf"); + } else { + srcOVAFileName = secondaryMountPoint + "/" + secStorageDir + "/" + backupName + "." + ImageFormat.OVA.getFileExtension(); - srcOVFFileName = secondaryMountPoint + "/" + secStorageDir + "/" + srcOVFFileName = secondaryMountPoint + "/" + secStorageDir + "/" + backupName + ".ovf"; - + } String snapshotDir = ""; if (backupName.contains("/")){ snapshotDir = backupName.split("/")[0]; } - File ovafile = new File(srcOVAFileName); File ovfFile = new File(srcOVFFileName); diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java index a5f389de1a8..90d4b70f011 100755 --- a/server/src/com/cloud/template/TemplateManagerImpl.java +++ b/server/src/com/cloud/template/TemplateManagerImpl.java @@ -1386,7 +1386,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, //getting the prent volume long parentVolumeId=_snapshotDao.findById(snapshotId).getVolumeId(); VolumeVO parentVolume = _volumeDao.findById(parentVolumeId); - if (parentVolume.getIsoId() != null) { + if (parentVolume != null && parentVolume.getIsoId() != null) { privateTemplate.setSourceTemplateId(parentVolume.getIsoId()); _tmpltDao.update(privateTemplate.getId(), privateTemplate); }