Search in sources :

Example 51 with SnapshotDataStoreVO

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;
}
Also used : SnapshotVO(com.cloud.storage.SnapshotVO) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)

Example 52 with SnapshotDataStoreVO

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;
}
Also used : SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) SnapshotVO(com.cloud.storage.SnapshotVO) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO) ArrayList(java.util.ArrayList)

Example 53 with SnapshotDataStoreVO

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;
}
Also used : VMSnapshot(com.cloud.vm.snapshot.VMSnapshot) Snapshot(com.cloud.storage.Snapshot) VolumeVO(com.cloud.storage.VolumeVO) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO)

Example 54 with SnapshotDataStoreVO

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;
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)

Example 55 with SnapshotDataStoreVO

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);
}
Also used : DataStoreRole(com.cloud.storage.DataStoreRole) SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) SnapshotVO(com.cloud.storage.SnapshotVO) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO) ArrayList(java.util.ArrayList) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

SnapshotDataStoreVO (org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)60 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)22 SnapshotInfo (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo)19 SnapshotVO (com.cloud.storage.SnapshotVO)16 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)14 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)11 VolumeVO (com.cloud.storage.VolumeVO)11 VolumeDataStoreVO (org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO)10 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)9 TemplateDataStoreVO (org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO)9 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)7 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)7 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)6 DB (com.cloud.utils.db.DB)6 ArrayList (java.util.ArrayList)6 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)5 Date (java.util.Date)5 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)4 Account (com.cloud.user.Account)4 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)4