cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mc...@apache.org
Subject git commit: updated refs/heads/object_store to f23f341
Date Wed, 22 May 2013 05:16:11 GMT
Updated Branches:
  refs/heads/object_store 383be568b -> f23f34192


Handle CopyCmdAnswer in VolumeObject.processEvent for image and
imageCache, and fix a bug in selecting endpoint.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/f23f3419
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/f23f3419
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/f23f3419

Branch: refs/heads/object_store
Commit: f23f341922c951655a6dd0c3577f224456e70eb8
Parents: 383be56
Author: Min Chen <min.chen@citrix.com>
Authored: Tue May 21 22:11:54 2013 -0700
Committer: Min Chen <min.chen@citrix.com>
Committed: Tue May 21 22:15:36 2013 -0700

----------------------------------------------------------------------
 .../storage/motion/AncientDataMotionStrategy.java  |   88 +++++++++------
 .../storage/endpoint/DefaultEndPointSelector.java  |    5 +-
 .../cloudstack/storage/volume/VolumeObject.java    |   10 ++-
 3 files changed, 67 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f23f3419/engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
----------------------------------------------------------------------
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 c0a3ec6..1e99e9e 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
@@ -140,28 +140,44 @@ public class AncientDataMotionStrategy implements DataMotionStrategy
{
     protected Answer copyObject(DataObject srcData, DataObject destData) {
         String value = configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
         int _primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
-        if (needCacheStorage(srcData, destData)) {
-            //need to copy it to image cache store
-            Scope destScope = destData.getDataStore().getScope();
-            if (destScope instanceof ClusterScope){
-                ClusterScope clusterScope = (ClusterScope)destScope;
-                destScope = new ZoneScope(clusterScope.getZoneId());
-            } else if (destScope instanceof HostScope){
-                HostScope hostScope = (HostScope)destScope;
-                destScope = new ZoneScope(hostScope.getZoneId());
+        Answer answer = null;
+        DataObject cacheData = null;
+        try {
+            if (needCacheStorage(srcData, destData)) {
+                // need to copy it to image cache store
+                Scope destScope = destData.getDataStore().getScope();
+                if (destScope instanceof ClusterScope) {
+                    ClusterScope clusterScope = (ClusterScope) destScope;
+                    destScope = new ZoneScope(clusterScope.getZoneId());
+                } else if (destScope instanceof HostScope) {
+                    HostScope hostScope = (HostScope) destScope;
+                    destScope = new ZoneScope(hostScope.getZoneId());
+                }
+                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);
+            }
+            // clean up cache entry in case of failure
+            if (answer == null || !answer.getResult()) {
+                if (cacheData != null) {
+                    cacheMgr.deleteCacheObject(cacheData);
+                }
             }
-            DataObject cacheData = cacheMgr.createCacheObject(srcData, destScope);
-            CopyCommand cmd = new CopyCommand(cacheData.getTO(), destData.getTO(), _primaryStorageDownloadWait);
-            EndPoint ep = selector.select(cacheData, destData);
-            Answer answer = ep.sendMessage(cmd);
-            return answer;
-        } else {
-            //handle copy it to/from cache store
-            CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _primaryStorageDownloadWait);
-            EndPoint ep = selector.select(srcData, destData);
-            Answer answer = ep.sendMessage(cmd);
             return answer;
+        } catch (Exception e) {
+            s_logger.debug("copy object failed: " + e.toString());
+            if (cacheData != null) {
+                cacheMgr.deleteCacheObject(cacheData);
+            }
+            throw new CloudRuntimeException(e.toString());
         }
+
     }
 
     protected DataObject cacheSnapshotChain(SnapshotInfo snapshot) {
@@ -203,7 +219,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
             CopyCommand cmd = new CopyCommand(srcData.getTO(), volObj.getTO(), _createVolumeFromSnapshotWait);
             EndPoint ep = selector.select(snapObj, volObj);
             Answer answer = ep.sendMessage(cmd);
-           
+
            return answer;
         } catch (Exception e) {
             s_logger.error(basicErrMsg, e);
@@ -245,7 +261,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
         Answer answer = null;
         String errMsg = null;
         try {
-           
+
             if (srcData.getType() == DataObjectType.SNAPSHOT
                     && destData.getType() == DataObjectType.VOLUME) {
             	answer = copyVolumeFromSnapshot(srcData, destData);
@@ -306,21 +322,27 @@ public class AncientDataMotionStrategy implements DataMotionStrategy
{
         int _backupsnapshotwait = NumbersUtil.parseInt(value, Integer.parseInt(Config.BackupSnapshotWait.getDefaultValue()));
 
         DataObject cacheData = null;
+        Answer answer = null;
         try {
-        if (needCacheStorage(srcData, destData)) {
-            cacheData = cacheMgr.getCacheObject(srcData, destData.getDataStore().getScope());
+            if (needCacheStorage(srcData, destData)) {
+                cacheData = cacheMgr.getCacheObject(srcData, destData.getDataStore().getScope());
 
-            CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _backupsnapshotwait);
-            cmd.setCacheTO(cacheData.getTO());
-            EndPoint ep = selector.select(srcData, destData);
-            Answer answer = ep.sendMessage(cmd);
-            return answer;
-        } else {
-            CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _backupsnapshotwait);
-            EndPoint ep = selector.select(srcData, destData);
-            Answer answer = ep.sendMessage(cmd);
+                CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _backupsnapshotwait);
+                cmd.setCacheTO(cacheData.getTO());
+                EndPoint ep = selector.select(srcData, destData);
+                answer = ep.sendMessage(cmd);
+            } else {
+                CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _backupsnapshotwait);
+                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) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f23f3419/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
b/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
index de57dd7..2b698fb 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
@@ -77,13 +77,14 @@ public class DefaultEndPointSelector implements EndPointSelector {
     protected boolean moveBetweenCacheAndImage(DataStore srcStore, DataStore destStore) {
     	  DataStoreRole srcRole = srcStore.getRole();
           DataStoreRole destRole = destStore.getRole();
-          if (srcRole == DataStoreRole.Image && destRole == DataStoreRole.ImageCache)
{
+          if (srcRole == DataStoreRole.Image && destRole == DataStoreRole.ImageCache
 ||
+                  srcRole == DataStoreRole.ImageCache && destRole == DataStoreRole.Image)
{
         	  return true;
           } else {
         	  return false;
           }
     }
-    
+
     protected boolean moveBetweenImages(DataStore srcStore, DataStore destStore) {
         DataStoreRole srcRole = srcStore.getRole();
         DataStoreRole destRole = destStore.getRole();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f23f3419/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java
----------------------------------------------------------------------
diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java
b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java
index a2a9045..4a3fd3f 100644
--- a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java
+++ b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeObject.java
@@ -403,13 +403,21 @@ public class VolumeObject implements VolumeInfo {
                     vol.setPoolId(this.getDataStore().getId());
                     volumeDao.update(vol.getId(), vol);
                 }
-            } else if (this.dataStore.getRole() == DataStoreRole.Image) {
+            } else {
+                // image store or imageCache store
                 if (answer instanceof DownloadAnswer) {
                     DownloadAnswer dwdAnswer = (DownloadAnswer) answer;
                     VolumeDataStoreVO volStore = this.volumeStoreDao.findByStoreVolume(this.dataStore.getId(),
this.getId());
                     volStore.setInstallPath(dwdAnswer.getInstallPath());
                     volStore.setChecksum(dwdAnswer.getCheckSum());
                     this.volumeStoreDao.update(volStore.getId(), volStore);
+                } else if (answer instanceof CopyCmdAnswer ){
+                    CopyCmdAnswer cpyAnswer = (CopyCmdAnswer) answer;
+                    VolumeDataStoreVO volStore = this.volumeStoreDao.findByStoreVolume(this.dataStore.getId(),
this.getId());
+                    VolumeObjectTO newVol = (VolumeObjectTO) cpyAnswer.getNewData();
+                    volStore.setInstallPath(newVol.getPath());
+                    volStore.setSize(newVol.getSize());
+                    this.volumeStoreDao.update(volStore.getId(), volStore);
                 }
             }
         } catch (RuntimeException ex) {


Mime
View raw message