Remove SnapshotVO.getSecHostId and SnapshotVO.setSecHostId references

from codebase to use SnapshotDataStoreVO.
This commit is contained in:
Min Chen 2013-04-24 11:54:42 -07:00
parent 792fc471a2
commit 8d29cdf804
7 changed files with 56 additions and 92 deletions

View File

@ -85,9 +85,6 @@ public class SnapshotVO implements Snapshot {
@Column(name="s3_id") @Column(name="s3_id")
Long s3Id; Long s3Id;
@Column(name="sechost_id")
Long secHostId;
@Column(name="prev_snap_id") @Column(name="prev_snap_id")
long prevSnapshotId; long prevSnapshotId;
@ -190,14 +187,6 @@ public class SnapshotVO implements Snapshot {
this.swiftId = swiftId; this.swiftId = swiftId;
} }
public Long getSecHostId() {
return secHostId;
}
public void setSecHostId(Long secHostId) {
this.secHostId = secHostId;
}
@Override @Override
public HypervisorType getHypervisorType() { public HypervisorType getHypervisorType() {
return hypervisorType; return hypervisorType;

View File

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

View File

@ -191,9 +191,7 @@ public class SnapshotServiceImpl implements SnapshotService {
snapshotVO.setPath(preSnapshotPath); snapshotVO.setPath(preSnapshotPath);
snapshotVO.setBackupSnapshotId(preSnapshotVO.getBackupSnapshotId()); snapshotVO.setBackupSnapshotId(preSnapshotVO.getBackupSnapshotId());
snapshotVO.setSwiftId(preSnapshotVO.getSwiftId());
snapshotVO.setPrevSnapshotId(preSnapshotVO.getId()); snapshotVO.setPrevSnapshotId(preSnapshotVO.getId());
snapshotVO.setSecHostId(preSnapshotVO.getSecHostId());
snapshot.processEvent(Snapshot.Event.OperationNotPerformed); snapshot.processEvent(Snapshot.Event.OperationNotPerformed);
} else { } else {
long preSnapshotId = 0; long preSnapshotId = 0;

View File

@ -1169,7 +1169,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
@DB @DB
List<Long> findAllVolumeIdInSnapshotTable(Long storeId) { 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>(); List<Long> list = new ArrayList<Long>();
try { try {
Transaction txn = Transaction.currentTxn(); Transaction txn = Transaction.currentTxn();

View File

@ -37,8 +37,6 @@ public interface SnapshotDao extends GenericDao<SnapshotVO, Long>, StateDao<Snap
List<SnapshotVO> listByVolumeIdVersion(long volumeId, String version); List<SnapshotVO> listByVolumeIdVersion(long volumeId, String version);
Long getSecHostId(long volumeId); Long getSecHostId(long volumeId);
long updateSnapshotSecHost(long dcId, long secHostId); long updateSnapshotSecHost(long dcId, long secHostId);
List<SnapshotVO> listByHostId(Filter filter, long hostId);
List<SnapshotVO> listByHostId(long hostId);
public Long countSnapshotsForAccount(long accountId); public Long countSnapshotsForAccount(long accountId);
List<SnapshotVO> listByInstanceId(long instanceId, Snapshot.State... status); List<SnapshotVO> listByInstanceId(long instanceId, Snapshot.State... status);
List<SnapshotVO> listByStatus(long volumeId, Snapshot.State... status); List<SnapshotVO> listByStatus(long volumeId, Snapshot.State... status);

View File

@ -54,9 +54,10 @@ import com.cloud.vm.dao.VMInstanceDao;
@Local (value={SnapshotDao.class}) @Local (value={SnapshotDao.class})
public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements SnapshotDao { public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements SnapshotDao {
public static final Logger s_logger = Logger.getLogger(SnapshotDaoImpl.class.getName()); 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 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 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 static final String UPDATE_SECHOST_ID = "UPDATE snapshots SET sechost_id = ? WHERE data_center_id = ?";
private SearchBuilder<SnapshotVO> VolumeIdSearch; private SearchBuilder<SnapshotVO> VolumeIdSearch;
@ -64,7 +65,6 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements
private SearchBuilder<SnapshotVO> ParentIdSearch; private SearchBuilder<SnapshotVO> ParentIdSearch;
private SearchBuilder<SnapshotVO> backupUuidSearch; private SearchBuilder<SnapshotVO> backupUuidSearch;
private SearchBuilder<SnapshotVO> VolumeIdVersionSearch; private SearchBuilder<SnapshotVO> VolumeIdVersionSearch;
private SearchBuilder<SnapshotVO> HostIdSearch;
private SearchBuilder<SnapshotVO> AccountIdSearch; private SearchBuilder<SnapshotVO> AccountIdSearch;
private SearchBuilder<SnapshotVO> InstanceIdSearch; private SearchBuilder<SnapshotVO> InstanceIdSearch;
private SearchBuilder<SnapshotVO> StatusSearch; private SearchBuilder<SnapshotVO> StatusSearch;
@ -80,20 +80,20 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements
sc.setParameters("prevSnapshotId", snapshotId); sc.setParameters("prevSnapshotId", snapshotId);
return findOneIncludingRemovedBy(sc); return findOneIncludingRemovedBy(sc);
} }
@Override @Override
public List<SnapshotVO> listByBackupUuid(long volumeId, String backupUuid) { public List<SnapshotVO> listByBackupUuid(long volumeId, String backupUuid) {
SearchCriteria<SnapshotVO> sc = backupUuidSearch.create(); SearchCriteria<SnapshotVO> sc = backupUuidSearch.create();
sc.setParameters("backupUuid", backupUuid); sc.setParameters("backupUuid", backupUuid);
return listBy(sc, null); return listBy(sc, null);
} }
@Override @Override
public List<SnapshotVO> listByVolumeIdType(long volumeId, Type type ) { public List<SnapshotVO> listByVolumeIdType(long volumeId, Type type ) {
return listByVolumeIdType(null, volumeId, type); return listByVolumeIdType(null, volumeId, type);
} }
@Override @Override
public List<SnapshotVO> listByVolumeIdVersion(long volumeId, String version ) { public List<SnapshotVO> listByVolumeIdVersion(long volumeId, String version ) {
return listByVolumeIdVersion(null, volumeId, version); return listByVolumeIdVersion(null, volumeId, version);
@ -103,41 +103,28 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements
public List<SnapshotVO> listByVolumeId(long volumeId) { public List<SnapshotVO> listByVolumeId(long volumeId) {
return listByVolumeId(null, volumeId); return listByVolumeId(null, volumeId);
} }
@Override @Override
public List<SnapshotVO> listByVolumeId(Filter filter, long volumeId ) { public List<SnapshotVO> listByVolumeId(Filter filter, long volumeId ) {
SearchCriteria<SnapshotVO> sc = VolumeIdSearch.create(); SearchCriteria<SnapshotVO> sc = VolumeIdSearch.create();
sc.setParameters("volumeId", volumeId); sc.setParameters("volumeId", volumeId);
return listBy(sc, filter); return listBy(sc, filter);
} }
@Override @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
public List<SnapshotVO> listByVolumeIdIncludingRemoved(long volumeId) { public List<SnapshotVO> listByVolumeIdIncludingRemoved(long volumeId) {
SearchCriteria<SnapshotVO> sc = VolumeIdSearch.create(); SearchCriteria<SnapshotVO> sc = VolumeIdSearch.create();
sc.setParameters("volumeId", volumeId); sc.setParameters("volumeId", volumeId);
return listIncludingRemovedBy(sc, null); return listIncludingRemovedBy(sc, null);
} }
public List<SnapshotVO> listByVolumeIdType(Filter filter, long volumeId, Type type ) { public List<SnapshotVO> listByVolumeIdType(Filter filter, long volumeId, Type type ) {
SearchCriteria<SnapshotVO> sc = VolumeIdTypeSearch.create(); SearchCriteria<SnapshotVO> sc = VolumeIdTypeSearch.create();
sc.setParameters("volumeId", volumeId); sc.setParameters("volumeId", volumeId);
sc.setParameters("type", type.ordinal()); sc.setParameters("type", type.ordinal());
return listBy(sc, filter); return listBy(sc, filter);
} }
public List<SnapshotVO> listByVolumeIdVersion(Filter filter, long volumeId, String version ) { public List<SnapshotVO> listByVolumeIdVersion(Filter filter, long volumeId, String version ) {
SearchCriteria<SnapshotVO> sc = VolumeIdVersionSearch.create(); SearchCriteria<SnapshotVO> sc = VolumeIdVersionSearch.create();
sc.setParameters("volumeId", volumeId); sc.setParameters("volumeId", volumeId);
@ -147,32 +134,27 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements
public SnapshotDaoImpl() { public SnapshotDaoImpl() {
} }
@PostConstruct @PostConstruct
protected void init() { protected void init() {
VolumeIdSearch = createSearchBuilder(); VolumeIdSearch = createSearchBuilder();
VolumeIdSearch.and("volumeId", VolumeIdSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); VolumeIdSearch.and("volumeId", VolumeIdSearch.entity().getVolumeId(), SearchCriteria.Op.EQ);
VolumeIdSearch.done(); 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 = createSearchBuilder();
VolumeIdTypeSearch.and("volumeId", VolumeIdTypeSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); VolumeIdTypeSearch.and("volumeId", VolumeIdTypeSearch.entity().getVolumeId(), SearchCriteria.Op.EQ);
VolumeIdTypeSearch.and("type", VolumeIdTypeSearch.entity().getsnapshotType(), SearchCriteria.Op.EQ); VolumeIdTypeSearch.and("type", VolumeIdTypeSearch.entity().getsnapshotType(), SearchCriteria.Op.EQ);
VolumeIdTypeSearch.done(); VolumeIdTypeSearch.done();
VolumeIdVersionSearch = createSearchBuilder(); VolumeIdVersionSearch = createSearchBuilder();
VolumeIdVersionSearch.and("volumeId", VolumeIdVersionSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); VolumeIdVersionSearch.and("volumeId", VolumeIdVersionSearch.entity().getVolumeId(), SearchCriteria.Op.EQ);
VolumeIdVersionSearch.and("version", VolumeIdVersionSearch.entity().getVersion(), SearchCriteria.Op.EQ); VolumeIdVersionSearch.and("version", VolumeIdVersionSearch.entity().getVersion(), SearchCriteria.Op.EQ);
VolumeIdVersionSearch.done(); VolumeIdVersionSearch.done();
ParentIdSearch = createSearchBuilder(); ParentIdSearch = createSearchBuilder();
ParentIdSearch.and("prevSnapshotId", ParentIdSearch.entity().getPrevSnapshotId(), SearchCriteria.Op.EQ); ParentIdSearch.and("prevSnapshotId", ParentIdSearch.entity().getPrevSnapshotId(), SearchCriteria.Op.EQ);
ParentIdSearch.done(); ParentIdSearch.done();
backupUuidSearch = createSearchBuilder(); backupUuidSearch = createSearchBuilder();
backupUuidSearch.and("backupUuid", backupUuidSearch.entity().getBackupSnapshotId(), SearchCriteria.Op.EQ); backupUuidSearch.and("backupUuid", backupUuidSearch.entity().getBackupSnapshotId(), SearchCriteria.Op.EQ);
backupUuidSearch.done(); backupUuidSearch.done();
@ -180,18 +162,18 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements
AccountIdSearch = createSearchBuilder(); AccountIdSearch = createSearchBuilder();
AccountIdSearch.and("accountId", AccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ); AccountIdSearch.and("accountId", AccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
AccountIdSearch.done(); AccountIdSearch.done();
StatusSearch = createSearchBuilder(); StatusSearch = createSearchBuilder();
StatusSearch.and("volumeId", StatusSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); StatusSearch.and("volumeId", StatusSearch.entity().getVolumeId(), SearchCriteria.Op.EQ);
StatusSearch.and("status", StatusSearch.entity().getState(), SearchCriteria.Op.IN); StatusSearch.and("status", StatusSearch.entity().getState(), SearchCriteria.Op.IN);
StatusSearch.done(); StatusSearch.done();
CountSnapshotsByAccount = createSearchBuilder(Long.class); 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("account", CountSnapshotsByAccount.entity().getAccountId(), SearchCriteria.Op.EQ);
CountSnapshotsByAccount.and("removed", CountSnapshotsByAccount.entity().getRemoved(), SearchCriteria.Op.NULL); CountSnapshotsByAccount.and("removed", CountSnapshotsByAccount.entity().getRemoved(), SearchCriteria.Op.NULL);
CountSnapshotsByAccount.done(); CountSnapshotsByAccount.done();
InstanceIdSearch = createSearchBuilder(); InstanceIdSearch = createSearchBuilder();
InstanceIdSearch.and("status", InstanceIdSearch.entity().getState(), SearchCriteria.Op.IN); InstanceIdSearch.and("status", InstanceIdSearch.entity().getState(), SearchCriteria.Op.IN);
@ -227,7 +209,7 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements
} }
} catch (Exception ex) { } catch (Exception ex) {
} }
return null; return null;
} }
@Override @Override
public long getLastSnapshot(long volumeId, long snapId) { public long getLastSnapshot(long volumeId, long snapId) {
@ -265,7 +247,7 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements
} }
return 0; return 0;
} }
@Override @Override
public long updateSnapshotSecHost(long dcId, long secHostId) { public long updateSnapshotSecHost(long dcId, long secHostId) {
Transaction txn = Transaction.currentTxn(); Transaction txn = Transaction.currentTxn();
@ -289,20 +271,20 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements
sc.setParameters("account", accountId); sc.setParameters("account", accountId);
return customSearch(sc, null).get(0); return customSearch(sc, null).get(0);
} }
@Override @Override
public List<SnapshotVO> listByInstanceId(long instanceId, Snapshot.State... status) { public List<SnapshotVO> listByInstanceId(long instanceId, Snapshot.State... status) {
SearchCriteria<SnapshotVO> sc = this.InstanceIdSearch.create(); SearchCriteria<SnapshotVO> sc = this.InstanceIdSearch.create();
if (status != null && status.length != 0) { if (status != null && status.length != 0) {
sc.setParameters("status", (Object[])status); sc.setParameters("status", (Object[])status);
} }
sc.setJoinParameters("instanceSnapshots", "state", Volume.State.Ready); sc.setJoinParameters("instanceSnapshots", "state", Volume.State.Ready);
sc.setJoinParameters("instanceVolumes", "instanceId", instanceId); sc.setJoinParameters("instanceVolumes", "instanceId", instanceId);
return listBy(sc, null); return listBy(sc, null);
} }
@Override @Override
public List<SnapshotVO> listByStatus(long volumeId, Snapshot.State... status) { public List<SnapshotVO> listByStatus(long volumeId, Snapshot.State... status) {
SearchCriteria<SnapshotVO> sc = this.StatusSearch.create(); SearchCriteria<SnapshotVO> sc = this.StatusSearch.create();
@ -310,7 +292,7 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements
sc.setParameters("status", (Object[])status); sc.setParameters("status", (Object[])status);
return listBy(sc, null); return listBy(sc, null);
} }
@Override @Override
@DB @DB
public boolean remove(Long id) { public boolean remove(Long id) {
@ -324,7 +306,7 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements
txn.commit(); txn.commit();
return result; return result;
} }
@Override @Override
public List<SnapshotVO> listAllByStatus(Snapshot.State... status) { public List<SnapshotVO> listAllByStatus(Snapshot.State... status) {
SearchCriteria<SnapshotVO> sc = this.StatusSearch.create(); SearchCriteria<SnapshotVO> sc = this.StatusSearch.create();

View File

@ -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.DeleteSnapshotPoliciesCmd;
import org.apache.cloudstack.api.command.user.snapshot.ListSnapshotPoliciesCmd; import org.apache.cloudstack.api.command.user.snapshot.ListSnapshotPoliciesCmd;
import org.apache.cloudstack.api.command.user.snapshot.ListSnapshotsCmd; 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.DataStoreManager;
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory; import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo; 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.VolumeDataFactory;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; 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.StoragePoolVO;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -79,6 +82,7 @@ import com.cloud.projects.Project.ListProjectResourcesCriteria;
import com.cloud.server.ResourceTag.TaggedResourceType; import com.cloud.server.ResourceTag.TaggedResourceType;
import com.cloud.storage.Snapshot; import com.cloud.storage.Snapshot;
import com.cloud.storage.Snapshot.Type; import com.cloud.storage.Snapshot.Type;
import com.cloud.storage.DataStoreRole;
import com.cloud.storage.SnapshotPolicyVO; import com.cloud.storage.SnapshotPolicyVO;
import com.cloud.storage.SnapshotScheduleVO; import com.cloud.storage.SnapshotScheduleVO;
import com.cloud.storage.SnapshotVO; import com.cloud.storage.SnapshotVO;
@ -146,6 +150,8 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
@Inject @Inject
protected SnapshotDao _snapshotDao; protected SnapshotDao _snapshotDao;
@Inject @Inject
protected SnapshotDataStoreDao _snapshotStoreDao;
@Inject
protected PrimaryDataStoreDao _storagePoolDao; protected PrimaryDataStoreDao _storagePoolDao;
@Inject @Inject
protected EventDao _eventDao; 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 @Override
public String getSecondaryStorageURL(SnapshotVO snapshot) { public String getSecondaryStorageURL(SnapshotVO snapshot) {
HostVO secHost = getSecondaryStorageHost(snapshot); SnapshotDataStoreVO snapshotStore = this._snapshotStoreDao.findBySnapshot(snapshot.getId());
if (secHost != null) { if (snapshotStore != null){
return secHost.getStorageUrl(); 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 @Override