use of com.cloud.storage.SnapshotVO in project cloudstack by apache.
the class ObjectInDataStoreManagerImpl method create.
@Override
public DataObject create(DataObject obj, DataStore dataStore) {
if (dataStore.getRole() == DataStoreRole.Primary) {
if (obj.getType() == DataObjectType.TEMPLATE) {
VMTemplateStoragePoolVO vo = new VMTemplateStoragePoolVO(dataStore.getId(), obj.getId(), null);
vo = templatePoolDao.persist(vo);
} else if (obj.getType() == DataObjectType.SNAPSHOT) {
SnapshotInfo snapshotInfo = (SnapshotInfo) obj;
SnapshotDataStoreVO ss = new SnapshotDataStoreVO();
ss.setSnapshotId(obj.getId());
ss.setDataStoreId(dataStore.getId());
ss.setRole(dataStore.getRole());
ss.setVolumeId(snapshotInfo.getVolumeId());
// this is the virtual size of snapshot in primary storage.
ss.setSize(snapshotInfo.getSize());
// this physical size will get updated with actual size once the snapshot backup is done.
ss.setPhysicalSize(snapshotInfo.getSize());
SnapshotDataStoreVO snapshotDataStoreVO = snapshotDataStoreDao.findParent(dataStore.getRole(), dataStore.getId(), snapshotInfo.getVolumeId());
if (snapshotDataStoreVO != null) {
// Double check the snapshot is removed or not
SnapshotVO parentSnap = snapshotDao.findById(snapshotDataStoreVO.getSnapshotId());
if (parentSnap != null) {
ss.setParentSnapshotId(snapshotDataStoreVO.getSnapshotId());
} else {
s_logger.debug("find inconsistent db for snapshot " + snapshotDataStoreVO.getSnapshotId());
}
}
ss.setState(ObjectInDataStoreStateMachine.State.Allocated);
ss = snapshotDataStoreDao.persist(ss);
}
} else {
// Image store
switch(obj.getType()) {
case TEMPLATE:
TemplateDataStoreVO ts = new TemplateDataStoreVO();
ts.setTemplateId(obj.getId());
ts.setDataStoreId(dataStore.getId());
ts.setDataStoreRole(dataStore.getRole());
String installPath = TemplateConstants.DEFAULT_TMPLT_ROOT_DIR + "/" + TemplateConstants.DEFAULT_TMPLT_FIRST_LEVEL_DIR + templateDao.findById(obj.getId()).getAccountId() + "/" + obj.getId();
if (dataStore.getTO() instanceof S3TO) {
TemplateInfo tmpl = (TemplateInfo) obj;
// for S3, we
installPath += "/" + tmpl.getUniqueName();
// append
// template name
// in the path
// for template
// sync since we
// don't have
// template.properties
// there
}
ts.setInstallPath(installPath);
ts.setState(ObjectInDataStoreStateMachine.State.Allocated);
ts = templateDataStoreDao.persist(ts);
break;
case SNAPSHOT:
SnapshotInfo snapshot = (SnapshotInfo) obj;
SnapshotDataStoreVO ss = new SnapshotDataStoreVO();
ss.setSnapshotId(obj.getId());
ss.setDataStoreId(dataStore.getId());
ss.setRole(dataStore.getRole());
ss.setSize(snapshot.getSize());
ss.setVolumeId(snapshot.getVolumeId());
SnapshotDataStoreVO snapshotDataStoreVO = snapshotDataStoreDao.findParent(dataStore.getRole(), dataStore.getId(), snapshot.getVolumeId());
if (snapshotDataStoreVO != null) {
ss.setParentSnapshotId(snapshotDataStoreVO.getSnapshotId());
}
ss.setInstallPath(TemplateConstants.DEFAULT_SNAPSHOT_ROOT_DIR + "/" + snapshotDao.findById(obj.getId()).getAccountId() + "/" + snapshot.getVolumeId());
ss.setState(ObjectInDataStoreStateMachine.State.Allocated);
ss = snapshotDataStoreDao.persist(ss);
break;
case VOLUME:
VolumeDataStoreVO vs = new VolumeDataStoreVO();
vs.setVolumeId(obj.getId());
vs.setDataStoreId(dataStore.getId());
vs.setInstallPath(TemplateConstants.DEFAULT_VOLUME_ROOT_DIR + "/" + volumeDao.findById(obj.getId()).getAccountId() + "/" + obj.getId());
vs.setState(ObjectInDataStoreStateMachine.State.Allocated);
vs = volumeDataStoreDao.persist(vs);
break;
}
}
return this.get(obj, dataStore, null);
}
use of com.cloud.storage.SnapshotVO in project cloudstack by apache.
the class SnapshotDataStoreDaoImpl method isSnapshotChainingRequired.
private boolean isSnapshotChainingRequired(long volumeId) {
hypervisorsSupportingSnapshotsChaining.add(Hypervisor.HypervisorType.XenServer);
SearchCriteria<SnapshotVO> sc = snapshotVOSearch.create();
sc.setParameters("volume_id", volumeId);
SnapshotVO volSnapshot = _snapshotDao.findOneBy(sc);
if (volSnapshot != null && hypervisorsSupportingSnapshotsChaining.contains(volSnapshot.getHypervisorType())) {
return true;
}
return false;
}
use of com.cloud.storage.SnapshotVO in project cloudstack by apache.
the class SolidFirePrimaryDataStoreDriver method getNonDestroyedSnapshots.
private List<SnapshotVO> getNonDestroyedSnapshots(long csVolumeId) {
List<SnapshotVO> lstSnapshots = snapshotDao.listByVolumeId(csVolumeId);
if (lstSnapshots == null) {
lstSnapshots = new ArrayList<>();
}
List<SnapshotVO> lstSnapshots2 = new ArrayList<>();
for (SnapshotVO snapshot : lstSnapshots) {
if (!State.Destroyed.equals(snapshot.getState())) {
lstSnapshots2.add(snapshot);
}
}
return lstSnapshots2;
}
use of com.cloud.storage.SnapshotVO in project cloudstack by apache.
the class SolidFirePrimaryDataStoreLifeCycle method deleteDataStore.
// invoked to delete primary storage that is based on the SolidFire plug-in
@Override
public boolean deleteDataStore(DataStore dataStore) {
long storagePoolId = dataStore.getId();
List<SnapshotVO> lstSnapshots = _snapshotDao.listAll();
if (lstSnapshots != null) {
for (SnapshotVO snapshot : lstSnapshots) {
SnapshotDetailsVO snapshotDetails = _snapshotDetailsDao.findDetail(snapshot.getId(), SolidFireUtil.STORAGE_POOL_ID);
// if this snapshot belongs to the storagePool that was passed in
if (snapshotDetails != null && snapshotDetails.getValue() != null && Long.parseLong(snapshotDetails.getValue()) == storagePoolId) {
throw new CloudRuntimeException("This primary storage cannot be deleted because it currently contains one or more snapshots.");
}
}
}
List<VMTemplateStoragePoolVO> lstTemplatePoolRefs = _tmpltPoolDao.listByPoolId(storagePoolId);
if (lstTemplatePoolRefs != null) {
for (VMTemplateStoragePoolVO templatePoolRef : lstTemplatePoolRefs) {
try {
SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePoolId, _storagePoolDetailsDao);
long sfTemplateVolumeId = Long.parseLong(templatePoolRef.getLocalDownloadPath());
SolidFireUtil.deleteVolume(sfConnection, sfTemplateVolumeId);
} catch (Exception ex) {
s_logger.error(ex.getMessage() != null ? ex.getMessage() : "Error deleting SolidFire template volume");
}
_tmpltPoolDao.remove(templatePoolRef.getId());
}
}
StoragePoolVO storagePool = _storagePoolDao.findById(storagePoolId);
storagePool.setUsedBytes(0);
_storagePoolDao.update(storagePoolId, storagePool);
_storagePoolDetailsDao.removeDetails(storagePoolId);
return _dataStoreHelper.deletePrimaryDataStore(dataStore);
}
use of com.cloud.storage.SnapshotVO in project cloudstack by apache.
the class SolidFirePrimaryDataStoreDriver method deleteSolidFireSnapshot.
private void deleteSolidFireSnapshot(SolidFireUtil.SolidFireConnection sfConnection, long csSnapshotId, long sfSnapshotId) {
SolidFireUtil.deleteSnapshot(sfConnection, sfSnapshotId);
final long volumeId;
final VolumeVO volume;
SnapshotVO snapshot = snapshotDao.findById(csSnapshotId);
SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(csSnapshotId, SolidFireUtil.ORIG_CS_VOLUME_ID);
if (snapshotDetails != null && snapshotDetails.getValue() != null) {
volumeId = Long.valueOf(snapshotDetails.getValue());
} else {
volumeId = snapshot.getVolumeId();
}
volume = volumeDao.findById(volumeId);
if (volume == null) {
// if the CloudStack volume has been deleted
List<SnapshotVO> lstSnapshots = getNonDestroyedSnapshots(snapshot.getVolumeId());
List<SnapshotVO> lstSnapshots2 = new ArrayList<>();
for (SnapshotVO snapshotVo : lstSnapshots) {
// sure snapshotVo.getId() != csSnapshotId when determining if any volume snapshots remain for the given CloudStack volume.
if (snapshotVo.getId() != csSnapshotId) {
snapshotDetails = snapshotDetailsDao.findDetail(snapshotVo.getId(), SolidFireUtil.SNAPSHOT_ID);
// that make use of SolidFire volumes).
if (snapshotDetails != null && snapshotDetails.getValue() != null) {
lstSnapshots2.add(snapshotVo);
}
}
}
if (lstSnapshots2.isEmpty()) {
VolumeVO volumeToDelete = volumeDao.findByIdIncludingRemoved(volumeId);
SolidFireUtil.deleteVolume(sfConnection, Long.parseLong(volumeToDelete.getFolder()));
}
}
}
Aggregations