Search in sources :

Example 96 with SnapshotVO

use of com.cloud.storage.SnapshotVO in project cloudstack by apache.

the class SnapshotDataFactoryImpl method getSnapshot.

@Override
public SnapshotInfo getSnapshot(DataObject obj, DataStore store) {
    SnapshotVO snapshot = snapshotDao.findById(obj.getId());
    if (snapshot == null) {
        throw new CloudRuntimeException("Can't find snapshot: " + obj.getId());
    }
    SnapshotObject so = SnapshotObject.getSnapshotObject(snapshot, store);
    return so;
}
Also used : SnapshotVO(com.cloud.storage.SnapshotVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 97 with SnapshotVO

use of com.cloud.storage.SnapshotVO 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 98 with SnapshotVO

use of com.cloud.storage.SnapshotVO 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 99 with SnapshotVO

use of com.cloud.storage.SnapshotVO in project cloudstack by apache.

the class StorageSystemSnapshotStrategy method executeRevertSnapshot.

/**
 * Executes the SnapshotStrategyBase.revertSnapshot(SnapshotInfo) method, and handles the SnapshotVO table update and the Volume.Event state machine (RevertSnapshotRequested).
 */
protected void executeRevertSnapshot(SnapshotInfo snapshotInfo, VolumeInfo volumeInfo) {
    Long hostId = null;
    boolean success = false;
    SnapshotVO snapshotVO = snapshotDao.acquireInLockTable(snapshotInfo.getId());
    if (snapshotVO == null) {
        String errMsg = "Failed to acquire lock on the following snapshot: " + snapshotInfo.getId();
        s_logger.error(errMsg);
        throw new CloudRuntimeException(errMsg);
    }
    try {
        volumeInfo.stateTransit(Volume.Event.RevertSnapshotRequested);
        if (getHypervisorRequiresResignature(volumeInfo)) {
            hostId = getHostId(volumeInfo);
            if (hostId != null) {
                HostVO hostVO = hostDao.findById(hostId);
                DataStore dataStore = dataStoreMgr.getDataStore(volumeInfo.getPoolId(), DataStoreRole.Primary);
                volService.revokeAccess(volumeInfo, hostVO, dataStore);
                modifyTarget(false, volumeInfo, hostId);
            }
        }
        success = snapshotSvr.revertSnapshot(snapshotInfo);
        if (!success) {
            String errMsg = String.format("Failed to revert volume [name:%s, format:%s] to snapshot [id:%s] state", volumeInfo.getName(), volumeInfo.getFormat(), snapshotInfo.getSnapshotId());
            s_logger.error(errMsg);
            throw new CloudRuntimeException(errMsg);
        }
    } finally {
        if (getHypervisorRequiresResignature(volumeInfo)) {
            if (hostId != null) {
                HostVO hostVO = hostDao.findById(hostId);
                DataStore dataStore = dataStoreMgr.getDataStore(volumeInfo.getPoolId(), DataStoreRole.Primary);
                volService.grantAccess(volumeInfo, hostVO, dataStore);
                modifyTarget(true, volumeInfo, hostId);
            }
        }
        if (success) {
            volumeInfo.stateTransit(Volume.Event.OperationSucceeded);
        } else {
            volumeInfo.stateTransit(Volume.Event.OperationFailed);
        }
        snapshotDao.releaseFromLockTable(snapshotInfo.getId());
    }
}
Also used : VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) SnapshotVO(com.cloud.storage.SnapshotVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) HostVO(com.cloud.host.HostVO)

Example 100 with SnapshotVO

use of com.cloud.storage.SnapshotVO in project cloudstack by apache.

the class StorageSystemSnapshotStrategy method deleteSnapshot.

@Override
public boolean deleteSnapshot(Long snapshotId) {
    Preconditions.checkArgument(snapshotId != null, "'snapshotId' cannot be 'null'.");
    SnapshotVO snapshotVO = snapshotDao.findById(snapshotId);
    if (Snapshot.State.Destroyed.equals(snapshotVO.getState())) {
        return true;
    }
    if (Snapshot.State.Error.equals(snapshotVO.getState())) {
        snapshotDao.remove(snapshotId);
        return true;
    }
    if (!Snapshot.State.BackedUp.equals(snapshotVO.getState())) {
        throw new InvalidParameterValueException("Unable to delete snapshot '" + snapshotId + "' because it is in the following state: " + snapshotVO.getState());
    }
    return cleanupSnapshotOnPrimaryStore(snapshotId);
}
Also used : VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) SnapshotVO(com.cloud.storage.SnapshotVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException)

Aggregations

SnapshotVO (com.cloud.storage.SnapshotVO)105 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)46 VMSnapshotVO (com.cloud.vm.snapshot.VMSnapshotVO)29 VolumeVO (com.cloud.storage.VolumeVO)28 Account (com.cloud.user.Account)22 SnapshotInfo (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo)22 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)18 ArrayList (java.util.ArrayList)17 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)16 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)16 SnapshotDataStoreVO (org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)16 HostVO (com.cloud.host.HostVO)15 VMTemplateVO (com.cloud.storage.VMTemplateVO)15 DB (com.cloud.utils.db.DB)14 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)12 ConfigurationException (javax.naming.ConfigurationException)12 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)11 UserVmVO (com.cloud.vm.UserVmVO)10 VMInstanceVO (com.cloud.vm.VMInstanceVO)10 ActionEvent (com.cloud.event.ActionEvent)9