Updated Branches:
  refs/heads/object_store 792fc471a -> 8d29cdf80

Remove SnapshotVO.getSecHostId and SnapshotVO.setSecHostId references
from codebase to use SnapshotDataStoreVO.

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

Branch: refs/heads/object_store
Commit: 8d29cdf804e0c4fe9fa1e9ed6d00bc2f6117b6e5
Parents: 792fc47
Author: Min Chen <[email protected]>
Authored: Wed Apr 24 11:54:42 2013 -0700
Committer: Min Chen <[email protected]>
Committed: Wed Apr 24 11:54:42 2013 -0700

----------------------------------------------------------------------
 core/src/com/cloud/storage/SnapshotVO.java         |   11 --
 .../storage/motion/AncientDataMotionStrategy.java  |   30 +++---
 .../storage/snapshot/SnapshotServiceImpl.java      |    2 -
 .../src/com/cloud/storage/StorageManagerImpl.java  |    2 +-
 server/src/com/cloud/storage/dao/SnapshotDao.java  |    2 -
 .../src/com/cloud/storage/dao/SnapshotDaoImpl.java |   74 ++++++---------
 .../storage/snapshot/SnapshotManagerImpl.java      |   27 +++---
 7 files changed, 56 insertions(+), 92 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d29cdf8/core/src/com/cloud/storage/SnapshotVO.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/storage/SnapshotVO.java 
b/core/src/com/cloud/storage/SnapshotVO.java
index 78b96ec..dbfd7ba 100644
--- a/core/src/com/cloud/storage/SnapshotVO.java
+++ b/core/src/com/cloud/storage/SnapshotVO.java
@@ -85,9 +85,6 @@ public class SnapshotVO implements Snapshot {
     @Column(name="s3_id")
     Long s3Id;
 
-    @Column(name="sechost_id")
-    Long secHostId;
-
     @Column(name="prev_snap_id")
     long prevSnapshotId;
 
@@ -190,14 +187,6 @@ public class SnapshotVO implements Snapshot {
         this.swiftId = swiftId;
     }
 
-    public Long getSecHostId() {
-        return secHostId;
-    }
-
-    public void setSecHostId(Long secHostId) {
-        this.secHostId = secHostId;
-    }
-
     @Override
     public HypervisorType getHypervisorType() {
         return hypervisorType;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d29cdf8/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 affe030..84d2b16 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
@@ -38,6 +38,8 @@ import 
org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
 import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
 import org.apache.cloudstack.storage.command.CopyCommand;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
+import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
+import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
 import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
@@ -113,6 +115,8 @@ public class AncientDataMotionStrategy implements 
DataMotionStrategy {
     @Inject
     SnapshotDao snapshotDao;
     @Inject
+    SnapshotDataStoreDao _snapshotStoreDao;
+    @Inject
     PrimaryDataStoreDao primaryDataStoreDao;
     @Inject
     DataStoreManager dataStoreMgr;
@@ -622,12 +626,12 @@ public class AncientDataMotionStrategy implements 
DataMotionStrategy {
         return sendCommand(cmd, pool, template.getId(), zoneId, secStore);
     }
 
-    private HostVO getSecHost(long volumeId, long dcId) {
+    private DataStore getSecHost(long volumeId, long dcId) {
         Long id = snapshotDao.getSecHostId(volumeId);
         if ( id != null) {
-            return hostDao.findById(id);
+            return this.dataStoreMgr.getDataStore(id, DataStoreRole.Image);
         }
-        return this.templateMgr.getSecondaryStorageHost(dcId);
+        return this.dataStoreMgr.getImageStore(dcId);
     }
 
     protected Answer copySnapshot(DataObject srcObject, DataObject destObject) 
{
@@ -636,9 +640,9 @@ public class AncientDataMotionStrategy implements 
DataMotionStrategy {
         Long dcId = baseVolume.getDataCenterId();
          Long accountId = baseVolume.getAccountId();
 
-         HostVO secHost = getSecHost(baseVolume.getId(), 
baseVolume.getDataCenterId());
-         Long secHostId = secHost.getId();
-         String secondaryStoragePoolUrl = secHost.getStorageUrl();
+         DataStore secStore = getSecHost(baseVolume.getId(), 
baseVolume.getDataCenterId());
+         Long secHostId = secStore.getId();
+         String secondaryStoragePoolUrl = secStore.getUri();
          String snapshotUuid = srcSnapshot.getPath();
          // In order to verify that the snapshot is not empty,
          // we check if the parent of the snapshot is not the same as the 
parent of the previous snapshot.
@@ -681,16 +685,10 @@ public class AncientDataMotionStrategy implements 
DataMotionStrategy {
          BackupSnapshotAnswer answer = (BackupSnapshotAnswer) 
this.snapshotMgr.sendToPool(baseVolume, backupSnapshotCommand);
          if (answer != null && answer.getResult()) {
                 SnapshotVO snapshotVO = 
this.snapshotDao.findById(srcSnapshot.getId());
-                if (backupSnapshotCommand.getSwift() != null ) {
-                        snapshotVO.setSwiftId(swift.getId());
-                        
snapshotVO.setBackupSnapshotId(answer.getBackupSnapshotName());
-                } else if (backupSnapshotCommand.getS3() != null) {
-                        snapshotVO.setS3Id(s3.getId());
-                        
snapshotVO.setBackupSnapshotId(answer.getBackupSnapshotName());
-                } else {
-                        snapshotVO.setSecHostId(secHost.getId());
-                        
snapshotVO.setBackupSnapshotId(answer.getBackupSnapshotName());
-                }
+                snapshotVO.setBackupSnapshotId(answer.getBackupSnapshotName());
+                // persist an entry in snapshot_store_ref
+                SnapshotDataStoreVO snapshotStore = new 
SnapshotDataStoreVO(secStore.getId(), snapshotVO.getId());
+                this._snapshotStoreDao.persist(snapshotStore);
                        if (answer.isFull()) {
                                snapshotVO.setPrevSnapshotId(0L);
                        }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d29cdf8/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java
 
b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java
index 7eee772..633e193 100644
--- 
a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java
+++ 
b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java
@@ -191,9 +191,7 @@ public class SnapshotServiceImpl implements SnapshotService 
{
 
                                snapshotVO.setPath(preSnapshotPath);
                                
snapshotVO.setBackupSnapshotId(preSnapshotVO.getBackupSnapshotId());
-                               
snapshotVO.setSwiftId(preSnapshotVO.getSwiftId());
                                
snapshotVO.setPrevSnapshotId(preSnapshotVO.getId());
-                               
snapshotVO.setSecHostId(preSnapshotVO.getSecHostId());
                                
snapshot.processEvent(Snapshot.Event.OperationNotPerformed);
                        } else {
                                long preSnapshotId = 0;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d29cdf8/server/src/com/cloud/storage/StorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java 
b/server/src/com/cloud/storage/StorageManagerImpl.java
index ac9c6f4..37fb376 100755
--- a/server/src/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/com/cloud/storage/StorageManagerImpl.java
@@ -1169,7 +1169,7 @@ public class StorageManagerImpl extends ManagerBase 
implements StorageManager, C
 
     @DB
     List<Long> findAllVolumeIdInSnapshotTable(Long storeId) {
-        String sql = "SELECT volume_id from snapshots, snapshot_store_ref 
WHERE store_id=? GROUP BY volume_id";
+        String sql = "SELECT volume_id from snapshots, snapshot_store_ref 
WHERE snapshots.id = snapshot_store_ref.snapshot_id and store_id=? GROUP BY 
volume_id";
         List<Long> list = new ArrayList<Long>();
         try {
             Transaction txn = Transaction.currentTxn();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d29cdf8/server/src/com/cloud/storage/dao/SnapshotDao.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/dao/SnapshotDao.java 
b/server/src/com/cloud/storage/dao/SnapshotDao.java
index 3ac9e77..e6aecc7 100644
--- a/server/src/com/cloud/storage/dao/SnapshotDao.java
+++ b/server/src/com/cloud/storage/dao/SnapshotDao.java
@@ -37,8 +37,6 @@ public interface SnapshotDao extends GenericDao<SnapshotVO, 
Long>, StateDao<Snap
     List<SnapshotVO> listByVolumeIdVersion(long volumeId, String version);
     Long getSecHostId(long volumeId);
     long updateSnapshotSecHost(long dcId, long secHostId);
-    List<SnapshotVO> listByHostId(Filter filter, long hostId);
-    List<SnapshotVO> listByHostId(long hostId);
     public Long countSnapshotsForAccount(long accountId);
     List<SnapshotVO> listByInstanceId(long instanceId, Snapshot.State... 
status);
     List<SnapshotVO> listByStatus(long volumeId, Snapshot.State... status);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d29cdf8/server/src/com/cloud/storage/dao/SnapshotDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/dao/SnapshotDaoImpl.java 
b/server/src/com/cloud/storage/dao/SnapshotDaoImpl.java
index f55663f..2dd5da1 100644
--- a/server/src/com/cloud/storage/dao/SnapshotDaoImpl.java
+++ b/server/src/com/cloud/storage/dao/SnapshotDaoImpl.java
@@ -54,9 +54,10 @@ import com.cloud.vm.dao.VMInstanceDao;
 @Local (value={SnapshotDao.class})
 public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> 
implements SnapshotDao {
     public static final Logger s_logger = 
Logger.getLogger(SnapshotDaoImpl.class.getName());
+    //TODO: we should remove these direct sqls
     private static final String GET_LAST_SNAPSHOT = "SELECT id FROM snapshots 
where volume_id = ? AND id != ? AND path IS NOT NULL ORDER BY created DESC";
     private static final String UPDATE_SNAPSHOT_VERSION = "UPDATE snapshots 
SET version = ? WHERE volume_id = ? AND version = ?";
-    private static final String GET_SECHOST_ID = "SELECT sechost_id FROM 
snapshots where volume_id = ? AND backup_snap_id IS NOT NULL AND sechost_id IS 
NOT NULL LIMIT 1";
+    private static final String GET_SECHOST_ID = "SELECT store_id FROM 
snapshots, snapshot_store_ref where snapshots.id = 
snapshot_store_ref.snapshot_id AND volume_id = ? AND backup_snap_id IS NOT NULL 
AND sechost_id IS NOT NULL LIMIT 1";
     private static final String UPDATE_SECHOST_ID = "UPDATE snapshots SET 
sechost_id = ? WHERE data_center_id = ?";
 
     private SearchBuilder<SnapshotVO> VolumeIdSearch;
@@ -64,7 +65,6 @@ public class SnapshotDaoImpl extends 
GenericDaoBase<SnapshotVO, Long> implements
     private SearchBuilder<SnapshotVO> ParentIdSearch;
     private SearchBuilder<SnapshotVO> backupUuidSearch;
     private SearchBuilder<SnapshotVO> VolumeIdVersionSearch;
-    private SearchBuilder<SnapshotVO> HostIdSearch;
     private SearchBuilder<SnapshotVO> AccountIdSearch;
     private SearchBuilder<SnapshotVO> InstanceIdSearch;
     private SearchBuilder<SnapshotVO> StatusSearch;
@@ -80,20 +80,20 @@ public class SnapshotDaoImpl extends 
GenericDaoBase<SnapshotVO, Long> implements
         sc.setParameters("prevSnapshotId", snapshotId);
         return findOneIncludingRemovedBy(sc);
     }
-    
+
     @Override
      public List<SnapshotVO> listByBackupUuid(long volumeId, String 
backupUuid) {
         SearchCriteria<SnapshotVO> sc = backupUuidSearch.create();
         sc.setParameters("backupUuid", backupUuid);
         return listBy(sc, null);
     }
-    
+
     @Override
     public List<SnapshotVO> listByVolumeIdType(long volumeId, Type type ) {
         return listByVolumeIdType(null, volumeId, type);
     }
-    
-    
+
+
     @Override
     public List<SnapshotVO> listByVolumeIdVersion(long volumeId, String 
version ) {
         return listByVolumeIdVersion(null, volumeId, version);
@@ -103,41 +103,28 @@ public class SnapshotDaoImpl extends 
GenericDaoBase<SnapshotVO, Long> implements
     public List<SnapshotVO> listByVolumeId(long volumeId) {
         return listByVolumeId(null, volumeId);
     }
-    
+
     @Override
     public List<SnapshotVO> listByVolumeId(Filter filter, long volumeId ) {
         SearchCriteria<SnapshotVO> sc = VolumeIdSearch.create();
         sc.setParameters("volumeId", volumeId);
         return listBy(sc, filter);
     }
-    
-    @Override
-    public List<SnapshotVO> listByHostId(long hostId) {
-        return listByHostId(null, hostId);
-    }
-    
-    @Override
-    public List<SnapshotVO> listByHostId(Filter filter, long hostId ) {
-        SearchCriteria<SnapshotVO> sc = HostIdSearch.create();
-        sc.setParameters("hostId", hostId);
-        sc.setParameters("status", Snapshot.State.BackedUp);
-        return listBy(sc, filter);
-    }
-        
-    @Override
+
+   @Override
     public List<SnapshotVO> listByVolumeIdIncludingRemoved(long volumeId) {
         SearchCriteria<SnapshotVO> sc = VolumeIdSearch.create();
         sc.setParameters("volumeId", volumeId);
         return listIncludingRemovedBy(sc, null);
     }
-    
+
     public List<SnapshotVO> listByVolumeIdType(Filter filter, long volumeId, 
Type type ) {
         SearchCriteria<SnapshotVO> sc = VolumeIdTypeSearch.create();
         sc.setParameters("volumeId", volumeId);
         sc.setParameters("type", type.ordinal());
         return listBy(sc, filter);
     }
-    
+
     public List<SnapshotVO> listByVolumeIdVersion(Filter filter, long 
volumeId, String version ) {
         SearchCriteria<SnapshotVO> sc = VolumeIdVersionSearch.create();
         sc.setParameters("volumeId", volumeId);
@@ -147,32 +134,27 @@ public class SnapshotDaoImpl extends 
GenericDaoBase<SnapshotVO, Long> implements
 
     public SnapshotDaoImpl() {
     }
-    
+
     @PostConstruct
     protected void init() {
         VolumeIdSearch = createSearchBuilder();
         VolumeIdSearch.and("volumeId", VolumeIdSearch.entity().getVolumeId(), 
SearchCriteria.Op.EQ);
         VolumeIdSearch.done();
-        
-        HostIdSearch = createSearchBuilder();
-        HostIdSearch.and("hostId", HostIdSearch.entity().getSecHostId(), 
SearchCriteria.Op.EQ);
-        HostIdSearch.and("status", HostIdSearch.entity().getState(), 
SearchCriteria.Op.EQ);
-        HostIdSearch.done();
-        
+
         VolumeIdTypeSearch = createSearchBuilder();
         VolumeIdTypeSearch.and("volumeId", 
VolumeIdTypeSearch.entity().getVolumeId(), SearchCriteria.Op.EQ);
         VolumeIdTypeSearch.and("type", 
VolumeIdTypeSearch.entity().getsnapshotType(), SearchCriteria.Op.EQ);
         VolumeIdTypeSearch.done();
-        
+
         VolumeIdVersionSearch = createSearchBuilder();
         VolumeIdVersionSearch.and("volumeId", 
VolumeIdVersionSearch.entity().getVolumeId(), SearchCriteria.Op.EQ);
         VolumeIdVersionSearch.and("version", 
VolumeIdVersionSearch.entity().getVersion(), SearchCriteria.Op.EQ);
         VolumeIdVersionSearch.done();
-        
+
         ParentIdSearch = createSearchBuilder();
         ParentIdSearch.and("prevSnapshotId", 
ParentIdSearch.entity().getPrevSnapshotId(), SearchCriteria.Op.EQ);
         ParentIdSearch.done();
-        
+
         backupUuidSearch = createSearchBuilder();
         backupUuidSearch.and("backupUuid", 
backupUuidSearch.entity().getBackupSnapshotId(), SearchCriteria.Op.EQ);
         backupUuidSearch.done();
@@ -180,18 +162,18 @@ public class SnapshotDaoImpl extends 
GenericDaoBase<SnapshotVO, Long> implements
         AccountIdSearch = createSearchBuilder();
         AccountIdSearch.and("accountId", 
AccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
         AccountIdSearch.done();
-        
+
         StatusSearch = createSearchBuilder();
         StatusSearch.and("volumeId", StatusSearch.entity().getVolumeId(), 
SearchCriteria.Op.EQ);
         StatusSearch.and("status", StatusSearch.entity().getState(), 
SearchCriteria.Op.IN);
         StatusSearch.done();
-        
+
         CountSnapshotsByAccount = createSearchBuilder(Long.class);
-        CountSnapshotsByAccount.select(null, Func.COUNT, null);        
+        CountSnapshotsByAccount.select(null, Func.COUNT, null);
         CountSnapshotsByAccount.and("account", 
CountSnapshotsByAccount.entity().getAccountId(), SearchCriteria.Op.EQ);
         CountSnapshotsByAccount.and("removed", 
CountSnapshotsByAccount.entity().getRemoved(), SearchCriteria.Op.NULL);
         CountSnapshotsByAccount.done();
-        
+
         InstanceIdSearch = createSearchBuilder();
         InstanceIdSearch.and("status", InstanceIdSearch.entity().getState(), 
SearchCriteria.Op.IN);
 
@@ -227,7 +209,7 @@ public class SnapshotDaoImpl extends 
GenericDaoBase<SnapshotVO, Long> implements
             }
         } catch (Exception ex) {
         }
-        return null;      
+        return null;
     }
     @Override
     public long getLastSnapshot(long volumeId, long snapId) {
@@ -265,7 +247,7 @@ public class SnapshotDaoImpl extends 
GenericDaoBase<SnapshotVO, Long> implements
         }
         return 0;
     }
-    
+
     @Override
     public long updateSnapshotSecHost(long dcId, long secHostId) {
         Transaction txn = Transaction.currentTxn();
@@ -289,20 +271,20 @@ public class SnapshotDaoImpl extends 
GenericDaoBase<SnapshotVO, Long> implements
         sc.setParameters("account", accountId);
         return customSearch(sc, null).get(0);
     }
-    
+
     @Override
        public List<SnapshotVO> listByInstanceId(long instanceId, 
Snapshot.State... status) {
        SearchCriteria<SnapshotVO> sc = this.InstanceIdSearch.create();
-       
+
        if (status != null && status.length != 0) {
            sc.setParameters("status", (Object[])status);
        }
-       
+
        sc.setJoinParameters("instanceSnapshots", "state", Volume.State.Ready);
        sc.setJoinParameters("instanceVolumes", "instanceId", instanceId);
         return listBy(sc, null);
     }
-    
+
     @Override
     public List<SnapshotVO> listByStatus(long volumeId, Snapshot.State... 
status) {
        SearchCriteria<SnapshotVO> sc = this.StatusSearch.create();
@@ -310,7 +292,7 @@ public class SnapshotDaoImpl extends 
GenericDaoBase<SnapshotVO, Long> implements
        sc.setParameters("status", (Object[])status);
        return listBy(sc, null);
     }
-    
+
     @Override
     @DB
     public boolean remove(Long id) {
@@ -324,7 +306,7 @@ public class SnapshotDaoImpl extends 
GenericDaoBase<SnapshotVO, Long> implements
         txn.commit();
         return result;
     }
-    
+
     @Override
     public List<SnapshotVO> listAllByStatus(Snapshot.State... status) {
         SearchCriteria<SnapshotVO> sc = this.StatusSearch.create();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8d29cdf8/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java 
b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
index 88bcc6a..a7842fa 100755
--- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
+++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
@@ -31,6 +31,7 @@ import 
org.apache.cloudstack.api.command.user.snapshot.CreateSnapshotPolicyCmd;
 import 
org.apache.cloudstack.api.command.user.snapshot.DeleteSnapshotPoliciesCmd;
 import org.apache.cloudstack.api.command.user.snapshot.ListSnapshotPoliciesCmd;
 import org.apache.cloudstack.api.command.user.snapshot.ListSnapshotsCmd;
+import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
 import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
 import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
@@ -38,6 +39,8 @@ import 
org.apache.cloudstack.engine.subsystem.api.storage.SnapshotService;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
+import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
+import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
@@ -79,6 +82,7 @@ import 
com.cloud.projects.Project.ListProjectResourcesCriteria;
 import com.cloud.server.ResourceTag.TaggedResourceType;
 import com.cloud.storage.Snapshot;
 import com.cloud.storage.Snapshot.Type;
+import com.cloud.storage.DataStoreRole;
 import com.cloud.storage.SnapshotPolicyVO;
 import com.cloud.storage.SnapshotScheduleVO;
 import com.cloud.storage.SnapshotVO;
@@ -146,6 +150,8 @@ public class SnapshotManagerImpl extends ManagerBase 
implements SnapshotManager,
     @Inject
     protected SnapshotDao _snapshotDao;
     @Inject
+    protected SnapshotDataStoreDao _snapshotStoreDao;
+    @Inject
     protected PrimaryDataStoreDao _storagePoolDao;
     @Inject
     protected EventDao _eventDao;
@@ -523,24 +529,17 @@ public class SnapshotManagerImpl extends ManagerBase 
implements SnapshotManager,
         }
     }
 
-    private HostVO getSecondaryStorageHost(SnapshotVO snapshot) {
-        HostVO secHost = null;
-        if( snapshot.getSwiftId() == null || snapshot.getSwiftId() == 0) {
-            secHost = _hostDao.findById(snapshot.getSecHostId());
-        } else {
-            Long dcId = snapshot.getDataCenterId();
-            secHost = this.templateMgr.getSecondaryStorageHost(dcId);
-        }
-        return secHost;
-    }
 
     @Override
     public String getSecondaryStorageURL(SnapshotVO snapshot) {
-        HostVO secHost = getSecondaryStorageHost(snapshot);
-        if (secHost != null) {
-            return secHost.getStorageUrl();
+        SnapshotDataStoreVO snapshotStore = 
this._snapshotStoreDao.findBySnapshot(snapshot.getId());
+        if (snapshotStore != null){
+            DataStore store = 
this.dataStoreMgr.getDataStore(snapshotStore.getDataStoreId(), 
DataStoreRole.Image);
+            if ( store != null ){
+                return store.getUri();
+            }
         }
-        throw new CloudRuntimeException("Can not find secondary storage");
+        throw new CloudRuntimeException("Can not find secondary storage 
hosting the snapshot");
     }
 
     @Override

Reply via email to