Search in sources :

Example 11 with SnapshotInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo in project cloudstack by apache.

the class SnapshotServiceImpl method syncToRegionStoreAsync.

private AsyncCallFuture<SnapshotResult> syncToRegionStoreAsync(SnapshotInfo snapshot, DataStore store) {
    AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<SnapshotResult>();
    // no need to create entry on snapshot_store_ref here, since entries are already created when updateCloudToUseObjectStore is invoked.
    // But we need to set default install path so that sync can be done in the right s3 path
    SnapshotInfo snapshotOnStore = _snapshotFactory.getSnapshot(snapshot, store);
    String installPath = TemplateConstants.DEFAULT_SNAPSHOT_ROOT_DIR + "/" + snapshot.getAccountId() + "/" + snapshot.getVolumeId();
    ((SnapshotObject) snapshotOnStore).setPath(installPath);
    CopySnapshotContext<CommandResult> context = new CopySnapshotContext<CommandResult>(null, snapshot, snapshotOnStore, future);
    AsyncCallbackDispatcher<SnapshotServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().syncSnapshotCallBack(null, null)).setContext(context);
    motionSrv.copyAsync(snapshot, snapshotOnStore, caller);
    return future;
}
Also used : AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) SnapshotResult(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Example 12 with SnapshotInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo in project cloudstack by apache.

the class StorageSystemSnapshotStrategy method takeSnapshot.

@Override
@DB
public SnapshotInfo takeSnapshot(SnapshotInfo snapshotInfo) {
    VolumeInfo volumeInfo = snapshotInfo.getBaseVolume();
    if (volumeInfo.getFormat() != ImageFormat.VHD) {
        throw new CloudRuntimeException("Only the " + ImageFormat.VHD.toString() + " image type is currently supported.");
    }
    SnapshotVO snapshotVO = snapshotDao.acquireInLockTable(snapshotInfo.getId());
    if (snapshotVO == null) {
        throw new CloudRuntimeException("Failed to acquire lock on the following snapshot: " + snapshotInfo.getId());
    }
    SnapshotResult result = null;
    SnapshotInfo snapshotOnPrimary = null;
    SnapshotInfo backedUpSnapshot = null;
    try {
        volumeInfo.stateTransit(Volume.Event.SnapshotRequested);
        // only XenServer is currently supported
        HostVO hostVO = getHost(volumeInfo.getId());
        boolean canStorageSystemCreateVolumeFromSnapshot = canStorageSystemCreateVolumeFromSnapshot(volumeInfo.getPoolId());
        boolean computeClusterSupportsResign = clusterDao.getSupportsResigning(hostVO.getClusterId());
        if (canStorageSystemCreateVolumeFromSnapshot && computeClusterSupportsResign) {
            SnapshotDetailsVO snapshotDetail = new SnapshotDetailsVO(snapshotInfo.getId(), "takeSnapshot", Boolean.TRUE.toString(), false);
            snapshotDetailsDao.persist(snapshotDetail);
        }
        result = snapshotSvr.takeSnapshot(snapshotInfo);
        if (result.isFailed()) {
            s_logger.debug("Failed to take a snapshot: " + result.getResult());
            throw new CloudRuntimeException(result.getResult());
        }
        if (!canStorageSystemCreateVolumeFromSnapshot || !computeClusterSupportsResign) {
            performSnapshotAndCopyOnHostSide(volumeInfo, snapshotInfo);
        }
        snapshotOnPrimary = result.getSnapshot();
        backedUpSnapshot = backupSnapshot(snapshotOnPrimary);
        updateLocationTypeInDb(backedUpSnapshot);
    } finally {
        if (result != null && result.isSuccess()) {
            volumeInfo.stateTransit(Volume.Event.OperationSucceeded);
            if (snapshotOnPrimary != null && snapshotInfo.getLocationType() == Snapshot.LocationType.SECONDARY) {
                // remove the snapshot on primary storage
                try {
                    snapshotSvr.deleteSnapshot(snapshotOnPrimary);
                } catch (Exception e) {
                    s_logger.warn("Failed to clean up snapshot on primary Id:" + snapshotOnPrimary.getId() + " " + e.getMessage());
                }
            }
        } else {
            volumeInfo.stateTransit(Volume.Event.OperationFailed);
        }
    }
    snapshotDao.releaseFromLockTable(snapshotInfo.getId());
    return backedUpSnapshot;
}
Also used : SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) SnapshotVO(com.cloud.storage.SnapshotVO) SnapshotResult(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) SnapshotDetailsVO(com.cloud.storage.dao.SnapshotDetailsVO) HostVO(com.cloud.host.HostVO) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DB(com.cloud.utils.db.DB)

Example 13 with SnapshotInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo in project cloudstack by apache.

the class SnapshotDataFactoryImpl method listSnapshotOnCache.

@Override
public List<SnapshotInfo> listSnapshotOnCache(long snapshotId) {
    List<SnapshotDataStoreVO> cacheSnapshots = snapshotStoreDao.listOnCache(snapshotId);
    List<SnapshotInfo> snapObjs = new ArrayList<SnapshotInfo>();
    for (SnapshotDataStoreVO cacheSnap : cacheSnapshots) {
        long storeId = cacheSnap.getDataStoreId();
        DataStore store = storeMgr.getDataStore(storeId, DataStoreRole.ImageCache);
        SnapshotInfo tmplObj = getSnapshot(snapshotId, store);
        snapObjs.add(tmplObj);
    }
    return snapObjs;
}
Also used : SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO) ArrayList(java.util.ArrayList)

Example 14 with SnapshotInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo in project cloudstack by apache.

the class SnapshotTestWithFakeData method testTakeSnapshot.

//@Test
public void testTakeSnapshot() throws URISyntaxException {
    SnapshotVO snapshotVO = createSnapshotInDb();
    DataStore store = createDataStore();
    try {
        SnapshotInfo snapshotInfo = snapshotDataFactory.getSnapshot(snapshotVO.getId(), store);
        SnapshotResult result = snapshotService.takeSnapshot(snapshotInfo);
        Assert.assertTrue(result.isSuccess());
        SnapshotDataStoreVO storeRef = snapshotDataStoreDao.findByStoreSnapshot(store.getRole(), store.getId(), snapshotVO.getId());
        Assert.assertTrue(storeRef != null);
        Assert.assertTrue(storeRef.getState() == ObjectInDataStoreStateMachine.State.Ready);
        snapshotInfo = result.getSnashot();
        boolean deletResult = snapshotService.deleteSnapshot(snapshotInfo);
        Assert.assertTrue(deletResult);
        snapshotDataStoreDao.expunge(storeRef.getId());
    } finally {
        snapshotDao.expunge(snapshotVO.getId());
        primaryDataStoreDao.remove(store.getId());
    }
}
Also used : SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) SnapshotVO(com.cloud.storage.SnapshotVO) SnapshotResult(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)

Example 15 with SnapshotInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo in project cloudstack by apache.

the class SnapshotTest method createSnapshot.

@Test
public void createSnapshot() throws InterruptedException, ExecutionException {
    VolumeInfo vol = createCopyBaseImage();
    SnapshotVO snapshotVO = createSnapshotInDb(vol);
    SnapshotInfo snapshot = this.snapshotFactory.getSnapshot(snapshotVO.getId(), vol.getDataStore());
    SnapshotInfo newSnapshot = null;
    SnapshotStrategy snapshotStrategy = storageStrategyFactory.getSnapshotStrategy(snapshot, SnapshotOperation.TAKE);
    if (snapshotStrategy != null) {
        newSnapshot = snapshotStrategy.takeSnapshot(snapshot);
    }
    AssertJUnit.assertNotNull(newSnapshot);
    LocalHostEndpoint ep = new MockLocalHostEndPoint();
    ep.setResource(new MockLocalNfsSecondaryStorageResource());
    Mockito.when(epSelector.select(Matchers.any(DataStore.class))).thenReturn(ep);
    try {
        for (SnapshotStrategy strategy : this.snapshotStrategies) {
            if (strategy.canHandle(snapshot, SnapshotOperation.DELETE) != StrategyPriority.CANT_HANDLE) {
                boolean res = strategy.deleteSnapshot(newSnapshot.getId());
                Assert.assertTrue(res);
            }
        }
    } finally {
        Mockito.when(epSelector.select(Matchers.any(DataStore.class))).thenReturn(remoteEp);
    }
}
Also used : LocalHostEndpoint(org.apache.cloudstack.storage.LocalHostEndpoint) SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) SnapshotVO(com.cloud.storage.SnapshotVO) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) MockLocalNfsSecondaryStorageResource(org.apache.cloudstack.storage.MockLocalNfsSecondaryStorageResource) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) SnapshotStrategy(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy) Test(org.testng.annotations.Test)

Aggregations

SnapshotInfo (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo)40 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)23 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)17 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)16 SnapshotVO (com.cloud.storage.SnapshotVO)15 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)11 SnapshotResult (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult)11 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)10 ExecutionException (java.util.concurrent.ExecutionException)10 SnapshotDataStoreVO (org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)10 SnapshotStrategy (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy)9 DB (com.cloud.utils.db.DB)8 CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)8 VolumeVO (com.cloud.storage.VolumeVO)7 TemplateInfo (org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo)6 CommandResult (org.apache.cloudstack.storage.command.CommandResult)6 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)5 Answer (com.cloud.agent.api.Answer)4 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)4 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)4