Search in sources :

Example 36 with SnapshotDataStoreVO

use of org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO in project cloudstack by apache.

the class SnapshotDataStoreDaoImpl method updateStoreRoleToCache.

@Override
public void updateStoreRoleToCache(long storeId) {
    SearchCriteria<SnapshotDataStoreVO> sc = storeSearch.create();
    sc.setParameters("store_id", storeId);
    sc.setParameters("destroyed", false);
    List<SnapshotDataStoreVO> snaps = listBy(sc);
    if (snaps != null) {
        s_logger.info("Update to cache store role for " + snaps.size() + " entries in snapshot_store_ref");
        for (SnapshotDataStoreVO snap : snaps) {
            snap.setRole(DataStoreRole.ImageCache);
            update(snap.getId(), snap);
        }
    }
}
Also used : SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)

Example 37 with SnapshotDataStoreVO

use of org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO in project cloudstack by apache.

the class XenserverSnapshotStrategy method backupSnapshot.

@Override
public SnapshotInfo backupSnapshot(SnapshotInfo snapshot) {
    SnapshotInfo parentSnapshot = snapshot.getParent();
    if (parentSnapshot != null && snapshot.getPath().equalsIgnoreCase(parentSnapshot.getPath())) {
        s_logger.debug("backup an empty snapshot");
        // don't need to backup this snapshot
        SnapshotDataStoreVO parentSnapshotOnBackupStore = snapshotStoreDao.findBySnapshot(parentSnapshot.getId(), DataStoreRole.Image);
        if (parentSnapshotOnBackupStore != null && parentSnapshotOnBackupStore.getState() == State.Ready) {
            DataStore store = dataStoreMgr.getDataStore(parentSnapshotOnBackupStore.getDataStoreId(), parentSnapshotOnBackupStore.getRole());
            SnapshotInfo snapshotOnImageStore = (SnapshotInfo) store.create(snapshot);
            snapshotOnImageStore.processEvent(Event.CreateOnlyRequested);
            SnapshotObjectTO snapTO = new SnapshotObjectTO();
            snapTO.setPath(parentSnapshotOnBackupStore.getInstallPath());
            CreateObjectAnswer createSnapshotAnswer = new CreateObjectAnswer(snapTO);
            snapshotOnImageStore.processEvent(Event.OperationSuccessed, createSnapshotAnswer);
            SnapshotObject snapObj = (SnapshotObject) snapshot;
            try {
                snapObj.processEvent(Snapshot.Event.OperationNotPerformed);
            } catch (NoTransitionException e) {
                s_logger.debug("Failed to change state: " + snapshot.getId() + ": " + e.toString());
                throw new CloudRuntimeException(e.toString());
            }
            return snapshotDataFactory.getSnapshot(snapObj.getId(), store);
        } else {
            s_logger.debug("parent snapshot hasn't been backed up yet");
        }
    }
    // determine full snapshot backup or not
    boolean fullBackup = true;
    SnapshotDataStoreVO parentSnapshotOnBackupStore = snapshotStoreDao.findLatestSnapshotForVolume(snapshot.getVolumeId(), DataStoreRole.Image);
    SnapshotDataStoreVO parentSnapshotOnPrimaryStore = snapshotStoreDao.findLatestSnapshotForVolume(snapshot.getVolumeId(), DataStoreRole.Primary);
    HypervisorType hypervisorType = snapshot.getBaseVolume().getHypervisorType();
    if (parentSnapshotOnPrimaryStore != null && parentSnapshotOnBackupStore != null && hypervisorType == Hypervisor.HypervisorType.XenServer) {
        // CS does incremental backup only for XenServer
        // In case of volume migration from one pool to other pool, CS should take full snapshot to avoid any issues with delta chain,
        // to check if this is a migrated volume, compare the current pool id of volume and store_id of oldest snapshot on primary for this volume.
        // Why oldest? Because at this point CS has two snapshot on primary entries for same volume, one with old pool_id and other one with
        // current pool id. So, verify and if volume found to be migrated, delete snapshot entry with previous pool store_id.
        SnapshotDataStoreVO oldestSnapshotOnPrimary = snapshotStoreDao.findOldestSnapshotForVolume(snapshot.getVolumeId(), DataStoreRole.Primary);
        VolumeVO volume = volumeDao.findById(snapshot.getVolumeId());
        if (oldestSnapshotOnPrimary != null) {
            if (oldestSnapshotOnPrimary.getDataStoreId() == volume.getPoolId() && oldestSnapshotOnPrimary.getId() != parentSnapshotOnPrimaryStore.getId()) {
                int _deltaSnapshotMax = NumbersUtil.parseInt(configDao.getValue("snapshot.delta.max"), SnapshotManager.DELTAMAX);
                int deltaSnap = _deltaSnapshotMax;
                int i;
                for (i = 1; i < deltaSnap; i++) {
                    Long prevBackupId = parentSnapshotOnBackupStore.getParentSnapshotId();
                    if (prevBackupId == 0) {
                        break;
                    }
                    parentSnapshotOnBackupStore = snapshotStoreDao.findBySnapshot(prevBackupId, DataStoreRole.Image);
                    if (parentSnapshotOnBackupStore == null) {
                        break;
                    }
                }
                if (i >= deltaSnap) {
                    fullBackup = true;
                } else {
                    fullBackup = false;
                }
            } else if (oldestSnapshotOnPrimary.getId() != parentSnapshotOnPrimaryStore.getId()) {
                // if there is an snapshot entry for previousPool(primary storage) of migrated volume, delete it becasue CS created one more snapshot entry for current pool
                snapshotStoreDao.remove(oldestSnapshotOnPrimary.getId());
            }
        }
    }
    snapshot.addPayload(fullBackup);
    return snapshotSvr.backupSnapshot(snapshot);
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) VolumeVO(com.cloud.storage.VolumeVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) NoTransitionException(com.cloud.utils.fsm.NoTransitionException)

Example 38 with SnapshotDataStoreVO

use of org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO in project cloudstack by apache.

the class SnapshotServiceImpl method cleanupVolumeDuringSnapshotFailure.

@Override
public void cleanupVolumeDuringSnapshotFailure(Long volumeId, Long snapshotId) {
    SnapshotVO snaphsot = _snapshotDao.findById(snapshotId);
    if (snaphsot != null) {
        if (snaphsot.getState() != Snapshot.State.BackedUp) {
            List<SnapshotDataStoreVO> snapshotDataStoreVOs = _snapshotStoreDao.findBySnapshotId(snapshotId);
            for (SnapshotDataStoreVO snapshotDataStoreVO : snapshotDataStoreVOs) {
                s_logger.debug("Remove snapshot " + snapshotId + ", status " + snapshotDataStoreVO.getState() + " on snapshot_store_ref table with id: " + snapshotDataStoreVO.getId());
                _snapshotStoreDao.remove(snapshotDataStoreVO.getId());
            }
            s_logger.debug("Remove snapshot " + snapshotId + " status " + snaphsot.getState() + " from snapshot table");
            _snapshotDao.remove(snapshotId);
        }
    }
}
Also used : SnapshotVO(com.cloud.storage.SnapshotVO) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)

Aggregations

SnapshotDataStoreVO (org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)38 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)15 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 SnapshotVO (com.cloud.storage.SnapshotVO)10 SnapshotInfo (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo)10 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)9 VolumeDataStoreVO (org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO)8 TemplateDataStoreVO (org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO)6 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)5 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)5 VolumeVO (com.cloud.storage.VolumeVO)5 Date (java.util.Date)5 ConfigurationException (javax.naming.ConfigurationException)5 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)4 DB (com.cloud.utils.db.DB)4 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)3 Account (com.cloud.user.Account)3 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)3 VMSnapshotVO (com.cloud.vm.snapshot.VMSnapshotVO)3 SnapshotResult (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult)3