mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Remove SnapshotVO.getSecHostId and SnapshotVO.setSecHostId references
from codebase to use SnapshotDataStoreVO.
This commit is contained in:
parent
792fc471a2
commit
8d29cdf804
@ -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;
|
||||
|
||||
@ -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());
|
||||
}
|
||||
// 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);
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
@ -111,19 +111,6 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements
|
||||
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
|
||||
public List<SnapshotVO> listByVolumeIdIncludingRemoved(long volumeId) {
|
||||
SearchCriteria<SnapshotVO> sc = VolumeIdSearch.create();
|
||||
@ -154,11 +141,6 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements
|
||||
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);
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user