From 58f9202818ffe78f3cd6748fc8710433d11bd5a2 Mon Sep 17 00:00:00 2001 From: Donal Lafferty Date: Fri, 28 Jun 2013 16:51:44 -0700 Subject: [PATCH] CLOUDSTACK-3215: Cannot Deploy VM when using S3 object store without NFS Cache Signed-off-by: Edison Su --- .../manager/StorageCacheManagerImpl.java | 8 ++- .../motion/AncientDataMotionStrategy.java | 53 ++++++++++++------- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java b/engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java index 4b4e52106ff..a8107727692 100644 --- a/engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java +++ b/engine/storage/cache/src/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java @@ -147,7 +147,7 @@ public class StorageCacheManagerImpl implements StorageCacheManager, Manager { object = cacheReplacementAlgorithm.chooseOneToBeReplaced(store); findAStore = store; if (object != null) { - break; + break; } } @@ -230,6 +230,12 @@ public class StorageCacheManagerImpl implements StorageCacheManager, Manager { @Override public DataObject createCacheObject(DataObject data, Scope scope) { DataStore cacheStore = this.getCacheStorage(scope); + + if (cacheStore == null) + { + String errMsg = "No cache DataStore in scope id " + scope.getScopeId() + " type " + scope.getScopeType().toString(); + throw new CloudRuntimeException(errMsg); + } return this.createCacheObject(data, cacheStore); } 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 631de6a47a3..04d04363a37 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 @@ -35,6 +35,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreState import org.apache.cloudstack.engine.subsystem.api.storage.Scope; import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo; import org.apache.cloudstack.engine.subsystem.api.storage.StorageCacheManager; +import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo; import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope; import org.apache.cloudstack.framework.async.AsyncCompletionCallback; @@ -57,6 +58,7 @@ import com.cloud.configuration.Config; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.host.Host; import com.cloud.host.dao.HostDao; +import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.storage.DataStoreRole; import com.cloud.storage.StorageManager; import com.cloud.storage.StoragePool; @@ -135,6 +137,22 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { if (destStoreTO instanceof NfsTO || destStoreTO.getRole() == DataStoreRole.ImageCache) { return false; } + + if (srcData.getType() == DataObjectType.TEMPLATE) { + TemplateInfo template = (TemplateInfo)srcData; + if (template.getHypervisorType() == HypervisorType.Hyperv) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("needCacheStorage false due to src TemplateInfo, which is DataObjectType.TEMPLATE of HypervisorType.Hyperv"); + } + return false; + } + } + + if (s_logger.isDebugEnabled()) { + s_logger.debug("needCacheStorage true, dest at " + + destTO.getPath() + " dest role " + destStoreTO.getRole().toString() + + srcTO.getPath() + " src role " + srcStoreTO.getRole().toString() ); + } return true; } @@ -157,26 +175,24 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { int _primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue())); Answer answer = null; + boolean usingCache = false; DataObject cacheData = null; + DataObject srcForCopy = srcData; try { if (needCacheStorage(srcData, destData)) { - // need to copy it to image cache store Scope destScope = getZoneScope(destData.getDataStore().getScope()); - cacheData = cacheMgr.createCacheObject(srcData, destScope); - CopyCommand cmd = new CopyCommand(cacheData.getTO(), destData.getTO(), _primaryStorageDownloadWait); - EndPoint ep = selector.select(cacheData, destData); - answer = ep.sendMessage(cmd); - } else { - // handle copy it to/from cache store - CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _primaryStorageDownloadWait); - EndPoint ep = selector.select(srcData, destData); - answer = ep.sendMessage(cmd); + srcForCopy = cacheData = cacheMgr.createCacheObject(srcData, destScope); } + + CopyCommand cmd = new CopyCommand(srcForCopy.getTO(), destData.getTO(), _primaryStorageDownloadWait); + EndPoint ep = selector.select(srcForCopy, destData); + answer = ep.sendMessage(cmd); + if (cacheData != null) { if (answer == null || !answer.getResult()) { - cacheMgr.deleteCacheObject(cacheData); + cacheMgr.deleteCacheObject(srcForCopy); } else { - cacheMgr.releaseCacheObject(cacheData); + cacheMgr.releaseCacheObject(srcForCopy); } } return answer; @@ -187,7 +203,6 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { } throw new CloudRuntimeException(e.toString()); } - } protected DataObject cacheSnapshotChain(SnapshotInfo snapshot) { @@ -204,10 +219,10 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { } protected void deleteSnapshotCacheChain(SnapshotInfo snapshot) { - while (snapshot != null) { - cacheMgr.deleteCacheObject(snapshot); - snapshot = snapshot.getParent(); - } + while (snapshot != null) { + cacheMgr.deleteCacheObject(snapshot); + snapshot = snapshot.getParent(); + } } protected Answer copyVolumeFromSnapshot(DataObject snapObj, DataObject volObj) { @@ -317,6 +332,8 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { Answer answer = null; String errMsg = null; try { + s_logger.debug("copyAsync inspecting src type " + srcData.getType().toString() + + " copyAsync inspecting dest type " + destData.getType().toString()); if (srcData.getType() == DataObjectType.SNAPSHOT && destData.getType() == DataObjectType.VOLUME) { answer = copyVolumeFromSnapshot(srcData, destData); @@ -404,7 +421,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { @Override public Void copyAsync(Map volumeMap, VirtualMachineTO vmTo, Host srcHost, Host destHost, - AsyncCompletionCallback callback) { + AsyncCompletionCallback callback) { CopyCommandResult result = new CopyCommandResult(null, null); result.setResult("Unsupported operation requested for copying data."); callback.complete(result);