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;
}
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;
}
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;
}
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());
}
}
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);
}
Aggregations