use of org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO in project cloudstack by apache.
the class SnapshotDataFactoryImpl method getSnapshot.
@Override
public SnapshotInfo getSnapshot(long snapshotId, DataStoreRole role) {
SnapshotVO snapshot = snapshotDao.findById(snapshotId);
if (snapshot == null) {
return null;
}
SnapshotDataStoreVO snapshotStore = snapshotStoreDao.findBySnapshot(snapshotId, role);
if (snapshotStore == null) {
snapshotStore = snapshotStoreDao.findByVolume(snapshotId, snapshot.getVolumeId(), role);
if (snapshotStore == null) {
return null;
}
}
DataStore store = storeMgr.getDataStore(snapshotStore.getDataStoreId(), role);
SnapshotObject so = SnapshotObject.getSnapshotObject(snapshot, store);
return so;
}
use of org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO in project cloudstack by apache.
the class SnapshotDataFactoryImpl method getSnapshots.
@Override
public List<SnapshotInfo> getSnapshots(long volumeId, DataStoreRole role) {
List<SnapshotDataStoreVO> allSnapshotsFromVolumeAndDataStore = snapshotStoreDao.listAllByVolumeAndDataStore(volumeId, role);
if (CollectionUtils.isEmpty(allSnapshotsFromVolumeAndDataStore)) {
return new ArrayList<>();
}
List<SnapshotInfo> infos = new ArrayList<>();
for (SnapshotDataStoreVO snapshotDataStoreVO : allSnapshotsFromVolumeAndDataStore) {
DataStore store = storeMgr.getDataStore(snapshotDataStoreVO.getDataStoreId(), role);
SnapshotVO snapshot = snapshotDao.findById(snapshotDataStoreVO.getSnapshotId());
if (snapshot == null) {
// snapshot may have been removed;
continue;
}
SnapshotObject info = SnapshotObject.getSnapshotObject(snapshot, store);
infos.add(info);
}
return infos;
}
use of org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO in project cloudstack by apache.
the class StorageSystemSnapshotStrategy method canHandle.
@Override
public StrategyPriority canHandle(Snapshot snapshot, SnapshotOperation op) {
Snapshot.LocationType locationType = snapshot.getLocationType();
// If the snapshot exists on Secondary Storage, we can't delete it.
if (SnapshotOperation.DELETE.equals(op)) {
if (Snapshot.LocationType.SECONDARY.equals(locationType)) {
return StrategyPriority.CANT_HANDLE;
}
SnapshotDataStoreVO snapshotStore = snapshotStoreDao.findBySnapshot(snapshot.getId(), DataStoreRole.Image);
// If the snapshot exists on Secondary Storage, we can't delete it.
if (snapshotStore != null) {
return StrategyPriority.CANT_HANDLE;
}
snapshotStore = snapshotStoreDao.findBySnapshot(snapshot.getId(), DataStoreRole.Primary);
if (snapshotStore == null) {
return StrategyPriority.CANT_HANDLE;
}
long snapshotStoragePoolId = snapshotStore.getDataStoreId();
boolean storageSystemSupportsCapability = storageSystemSupportsCapability(snapshotStoragePoolId, DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT.toString());
return storageSystemSupportsCapability ? StrategyPriority.HIGHEST : StrategyPriority.CANT_HANDLE;
}
long volumeId = snapshot.getVolumeId();
VolumeVO volumeVO = volumeDao.findByIdIncludingRemoved(volumeId);
long volumeStoragePoolId = volumeVO.getPoolId();
if (SnapshotOperation.REVERT.equals(op)) {
boolean baseVolumeExists = volumeVO.getRemoved() == null;
if (baseVolumeExists) {
boolean acceptableFormat = isAcceptableRevertFormat(volumeVO);
if (acceptableFormat) {
SnapshotDataStoreVO snapshotStore = snapshotStoreDao.findBySnapshot(snapshot.getId(), DataStoreRole.Primary);
boolean usingBackendSnapshot = usingBackendSnapshotFor(snapshot.getId());
if (usingBackendSnapshot) {
if (snapshotStore != null) {
long snapshotStoragePoolId = snapshotStore.getDataStoreId();
boolean storageSystemSupportsCapability = storageSystemSupportsCapability(snapshotStoragePoolId, DataStoreCapabilities.CAN_REVERT_VOLUME_TO_SNAPSHOT.toString());
if (storageSystemSupportsCapability) {
return StrategyPriority.HIGHEST;
}
storageSystemSupportsCapability = storageSystemSupportsCapability(volumeStoragePoolId, DataStoreCapabilities.CAN_REVERT_VOLUME_TO_SNAPSHOT.toString());
if (storageSystemSupportsCapability) {
return StrategyPriority.HIGHEST;
}
}
} else {
if (snapshotStore != null) {
long snapshotStoragePoolId = snapshotStore.getDataStoreId();
StoragePoolVO storagePoolVO = storagePoolDao.findById(snapshotStoragePoolId);
if (storagePoolVO.isManaged()) {
return StrategyPriority.HIGHEST;
}
}
StoragePoolVO storagePoolVO = storagePoolDao.findById(volumeStoragePoolId);
if (storagePoolVO.isManaged()) {
return StrategyPriority.HIGHEST;
}
}
}
}
return StrategyPriority.CANT_HANDLE;
}
boolean storageSystemSupportsCapability = storageSystemSupportsCapability(volumeStoragePoolId, DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT.toString());
return storageSystemSupportsCapability ? StrategyPriority.HIGHEST : StrategyPriority.CANT_HANDLE;
}
use of org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO in project cloudstack by apache.
the class StorageSystemSnapshotStrategy method revertSnapshot.
@Override
public boolean revertSnapshot(SnapshotInfo snapshotInfo) {
VolumeInfo volumeInfo = snapshotInfo.getBaseVolume();
verifyFormat(volumeInfo);
verifyDiskTypeAndHypervisor(volumeInfo);
verifySnapshotType(snapshotInfo);
SnapshotDataStoreVO snapshotStore = snapshotStoreDao.findBySnapshot(snapshotInfo.getId(), DataStoreRole.Primary);
if (snapshotStore != null) {
long snapshotStoragePoolId = snapshotStore.getDataStoreId();
if (!volumeInfo.getPoolId().equals(snapshotStoragePoolId)) {
String errMsg = "Storage pool mismatch";
s_logger.error(errMsg);
throw new CloudRuntimeException(errMsg);
}
}
boolean storageSystemSupportsCapability = storageSystemSupportsCapability(volumeInfo.getPoolId(), DataStoreCapabilities.CAN_REVERT_VOLUME_TO_SNAPSHOT.toString());
if (!storageSystemSupportsCapability) {
String errMsg = "Storage pool revert capability not supported";
s_logger.error(errMsg);
throw new CloudRuntimeException(errMsg);
}
executeRevertSnapshot(snapshotInfo, volumeInfo);
return true;
}
use of org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO in project cloudstack by apache.
the class SnapshotDataFactoryImplTest method getSnapshotsByVolumeAndDataStoreTest.
@Test
@PrepareForTest({ ComponentContext.class })
public void getSnapshotsByVolumeAndDataStoreTest() {
PowerMockito.mockStatic(ComponentContext.class);
PowerMockito.when(ComponentContext.inject(SnapshotObject.class)).thenReturn(new SnapshotObject());
SnapshotDataStoreVO snapshotDataStoreVoMock = Mockito.mock(SnapshotDataStoreVO.class);
Mockito.doReturn(volumeMockId).when(snapshotDataStoreVoMock).getVolumeId();
long snapshotId = 1223;
long dataStoreId = 34567;
Mockito.doReturn(snapshotId).when(snapshotDataStoreVoMock).getSnapshotId();
Mockito.doReturn(dataStoreId).when(snapshotDataStoreVoMock).getDataStoreId();
SnapshotVO snapshotVoMock = Mockito.mock(SnapshotVO.class);
Mockito.doReturn(snapshotId).when(snapshotVoMock).getId();
DataStoreRole dataStoreRole = DataStoreRole.Primary;
DataStore dataStoreMock = Mockito.mock(DataStore.class);
Mockito.doReturn(dataStoreId).when(dataStoreMock).getId();
Mockito.doReturn(dataStoreRole).when(dataStoreMock).getRole();
List<SnapshotDataStoreVO> snapshotDataStoreVOs = new ArrayList<>();
snapshotDataStoreVOs.add(snapshotDataStoreVoMock);
Mockito.doReturn(snapshotDataStoreVOs).when(snapshotStoreDaoMock).listAllByVolumeAndDataStore(volumeMockId, dataStoreRole);
Mockito.doReturn(dataStoreMock).when(dataStoreManagerMock).getDataStore(dataStoreId, dataStoreRole);
Mockito.doReturn(snapshotVoMock).when(snapshotDaoMock).findById(snapshotId);
List<SnapshotInfo> snapshots = snapshotDataFactoryImpl.getSnapshots(volumeMockId, dataStoreRole);
Assert.assertEquals(1, snapshots.size());
SnapshotInfo snapshotInfo = snapshots.get(0);
Assert.assertEquals(dataStoreMock, snapshotInfo.getDataStore());
Assert.assertEquals(snapshotVoMock, ((SnapshotObject) snapshotInfo).getSnapshotVO());
PowerMockito.verifyStatic(ComponentContext.class);
ComponentContext.inject(SnapshotObject.class);
}
Aggregations