use of com.cloud.storage.dao.SnapshotDetailsVO in project cloudstack by apache.
the class DateraPrimaryDataStoreDriver method deleteSnapshot.
/**
* Deletes snapshot on Datera
* @param snapshotInfo snapshot information
* @param storagePoolId primary storage
* @throws UnsupportedEncodingException
* @throws DateraObject.DateraError
*/
private void deleteSnapshot(SnapshotInfo snapshotInfo, long storagePoolId) throws UnsupportedEncodingException, DateraObject.DateraError {
long csSnapshotId = snapshotInfo.getId();
try {
DateraObject.DateraConnection conn = DateraUtil.getDateraConnection(storagePoolId, _storagePoolDetailsDao);
SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, DateraUtil.SNAPSHOT_ID);
if (snapshotDetails != null && snapshotDetails.getValue() != null) {
// Native snapshot being used, delete that
String snapshotName = snapshotDetails.getValue();
DateraUtil.deleteVolumeSnapshot(conn, snapshotName);
// check if the underlying volume needs to be deleted
SnapshotVO snapshot = _snapshotDao.findById(csSnapshotId);
VolumeVO volume = _volumeDao.findById(snapshot.getVolumeId());
if (volume == null) {
// deleted from Cloudstack. Check if other snapshots are using this volume
volume = _volumeDao.findByIdIncludingRemoved(snapshot.getVolumeId());
if (shouldDeleteVolume(snapshot.getVolumeId(), snapshot.getId())) {
DateraUtil.deleteAppInstance(conn, volume.getFolder());
}
}
} else {
// An App Instance is being used to support the CloudStack volume snapshot.
snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, DateraUtil.VOLUME_ID);
String appInstanceName = snapshotDetails.getValue();
DateraUtil.deleteAppInstance(conn, appInstanceName);
}
snapshotDetailsDao.removeDetails(csSnapshotId);
StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId);
// getUsedBytes(StoragePool) will not include the snapshot to delete because it
// has already been deleted by this point
long usedBytes = getUsedBytes(storagePool);
storagePool.setUsedBytes(usedBytes < 0 ? 0 : usedBytes);
storagePoolDao.update(storagePoolId, storagePool);
} catch (Exception ex) {
s_logger.debug("Error in 'deleteSnapshot(SnapshotInfo, long)'. CloudStack snapshot ID: " + csSnapshotId, ex);
throw ex;
}
}
use of com.cloud.storage.dao.SnapshotDetailsVO in project cloudstack by apache.
the class DateraPrimaryDataStoreDriver method addTempVolumeToDb.
/**
* Adding temp volume to the snapshot_details table. This is used if we are
* using a native snapshot and we want to create a template out of the snapshot
*
* @param csSnapshotId Source snasphot
* @param tempVolumeName temp volume app instance on Datera
*/
private void addTempVolumeToDb(long csSnapshotId, String tempVolumeName) {
SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, DateraUtil.VOLUME_ID);
if (snapshotDetails == null || snapshotDetails.getValue() == null) {
throw new CloudRuntimeException("'addTempVolumeId' should not be invoked unless " + DateraUtil.VOLUME_ID + " exists.");
}
String originalVolumeId = snapshotDetails.getValue();
handleSnapshotDetails(csSnapshotId, DateraUtil.TEMP_VOLUME_ID, originalVolumeId);
handleSnapshotDetails(csSnapshotId, DateraUtil.VOLUME_ID, tempVolumeName);
}
use of com.cloud.storage.dao.SnapshotDetailsVO in project cloudstack by apache.
the class DateraPrimaryDataStoreDriver method removeTempVolumeFromDb.
private void removeTempVolumeFromDb(long csSnapshotId) {
SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, DateraUtil.TEMP_VOLUME_ID);
if (snapshotDetails == null || snapshotDetails.getValue() == null) {
throw new CloudRuntimeException("'removeTempVolumeId' should not be invoked unless " + DateraUtil.TEMP_VOLUME_ID + " exists.");
}
String originalVolumeId = snapshotDetails.getValue();
handleSnapshotDetails(csSnapshotId, DateraUtil.VOLUME_ID, originalVolumeId);
snapshotDetailsDao.remove(snapshotDetails.getId());
}
use of com.cloud.storage.dao.SnapshotDetailsVO in project cloudstack by apache.
the class LinstorPrimaryDataStoreDriverImpl method removeTempVolumeFromDb.
private void removeTempVolumeFromDb(long csSnapshotId) {
SnapshotDetailsVO snapshotDetails = _snapshotDetailsDao.findDetail(csSnapshotId, LinstorUtil.TEMP_VOLUME_ID);
if (snapshotDetails == null || snapshotDetails.getValue() == null) {
throw new CloudRuntimeException("'removeTempVolumeId' should not be invoked unless " + LinstorUtil.TEMP_VOLUME_ID + " exists.");
}
String originalVolumeId = snapshotDetails.getValue();
handleSnapshotDetails(csSnapshotId, LinstorUtil.TEMP_VOLUME_ID, originalVolumeId);
_snapshotDetailsDao.remove(snapshotDetails.getId());
}
use of com.cloud.storage.dao.SnapshotDetailsVO in project cloudstack by apache.
the class LinstorPrimaryDataStoreDriverImpl method createVolumeFromSnapshot.
private void createVolumeFromSnapshot(SnapshotInfo snapshotInfo, StoragePoolVO storagePoolVO) {
long csSnapshotId = snapshotInfo.getId();
SnapshotDetailsVO snapshotDetails = _snapshotDetailsDao.findDetail(csSnapshotId, "tempVolume");
if (snapshotDetails != null && snapshotDetails.getValue() != null && snapshotDetails.getValue().equalsIgnoreCase("create")) {
final String csName = "Temp-" + snapshotInfo.getUuid();
final String tempRscName = LinstorUtil.RSC_PREFIX + csName;
createResourceFromSnapshot(csSnapshotId, tempRscName, storagePoolVO);
s_logger.debug("Temp resource created: " + tempRscName);
addTempVolumeToDb(csSnapshotId, csName);
} else if (snapshotDetails != null && snapshotDetails.getValue() != null && snapshotDetails.getValue().equalsIgnoreCase("delete")) {
snapshotDetails = _snapshotDetailsDao.findDetail(csSnapshotId, LinstorUtil.TEMP_VOLUME_ID);
deleteResourceDefinition(storagePoolVO, snapshotDetails.getValue());
s_logger.debug("Temp resource deleted: " + snapshotDetails.getValue());
removeTempVolumeFromDb(csSnapshotId);
} else {
throw new CloudRuntimeException("Invalid state in 'createVolumeFromSnapshot(SnapshotInfo, StoragePoolVO)'");
}
}
Aggregations