use of com.cloud.engine.subsystem.api.storage.SnapshotInfo in project cosmic by MissionCriticalCloud.
the class ObjectInDataStoreManagerImpl method create.
@Override
public DataObject create(final DataObject obj, final DataStore dataStore) {
if (dataStore.getRole() == DataStoreRole.Primary) {
if (obj.getType() == DataObjectType.TEMPLATE) {
VMTemplateStoragePoolVO vo = new VMTemplateStoragePoolVO(dataStore.getId(), obj.getId());
vo = templatePoolDao.persist(vo);
} else if (obj.getType() == DataObjectType.SNAPSHOT) {
final 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());
final SnapshotDataStoreVO snapshotDataStoreVO = snapshotDataStoreDao.findParent(dataStore.getRole(), dataStore.getId(), snapshotInfo.getVolumeId());
if (snapshotDataStoreVO != null) {
// Double check the snapshot is removed or not
final 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();
ts.setInstallPath(installPath);
ts.setState(ObjectInDataStoreStateMachine.State.Allocated);
ts = templateDataStoreDao.persist(ts);
break;
case SNAPSHOT:
final 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());
final 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);
}
use of com.cloud.engine.subsystem.api.storage.SnapshotInfo in project cosmic by MissionCriticalCloud.
the class DefaultEndPointSelector method select.
@Override
public EndPoint select(final DataObject object, final StorageAction action) {
if (StorageAction.TAKESNAPSHOT.equals(action)) {
final SnapshotInfo snapshotInfo = (SnapshotInfo) object;
if (Hypervisor.HypervisorType.KVM.equals(snapshotInfo.getHypervisorType())) {
final VolumeInfo volumeInfo = snapshotInfo.getBaseVolume();
final VirtualMachine vm = volumeInfo.getAttachedVM();
if (vm != null && VirtualMachine.State.Running.equals(vm.getState())) {
final Long hostId = vm.getHostId();
return getEndPointFromHostId(hostId);
}
}
} else if (StorageAction.MIGRATEVOLUME.equals(action)) {
final VolumeInfo volumeInfo = (VolumeInfo) object;
if (Hypervisor.HypervisorType.KVM.equals(volumeInfo.getHypervisorType())) {
final VirtualMachine vm = volumeInfo.getAttachedVM();
if (vm != null && VirtualMachine.State.Running.equals(vm.getState()) && volumeInfo.isToBeLiveMigrated()) {
final Long hostId = vm.getHostId();
return getEndPointFromHostId(hostId);
}
}
}
return select(object);
}
use of com.cloud.engine.subsystem.api.storage.SnapshotInfo in project cosmic by MissionCriticalCloud.
the class StorageManagerImpl method cleanupSecondaryStorage.
@Override
@DB
public void cleanupSecondaryStorage(final boolean recurring) {
// so here we don't need to issue DeleteCommand to resource anymore, only need to remove db entry.
try {
// Cleanup templates in template_store_ref
final List<DataStore> imageStores = _dataStoreMgr.getImageStoresByScope(new ZoneScope(null));
for (final DataStore store : imageStores) {
try {
final long storeId = store.getId();
final List<TemplateDataStoreVO> destroyedTemplateStoreVOs = _templateStoreDao.listDestroyed(storeId);
s_logger.debug("Secondary storage garbage collector found " + destroyedTemplateStoreVOs.size() + " templates to cleanup on template_store_ref for store: " + store.getName());
for (final TemplateDataStoreVO destroyedTemplateStoreVO : destroyedTemplateStoreVOs) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Deleting template store DB entry: " + destroyedTemplateStoreVO);
}
_templateStoreDao.remove(destroyedTemplateStoreVO.getId());
}
} catch (final Exception e) {
s_logger.warn("problem cleaning up templates in template_store_ref for store: " + store.getName(), e);
}
}
// CleanUp snapshots on snapshot_store_ref
for (final DataStore store : imageStores) {
try {
final List<SnapshotDataStoreVO> destroyedSnapshotStoreVOs = _snapshotStoreDao.listDestroyed(store.getId());
s_logger.debug("Secondary storage garbage collector found " + destroyedSnapshotStoreVOs.size() + " snapshots to cleanup on snapshot_store_ref for store: " + store.getName());
for (final SnapshotDataStoreVO destroyedSnapshotStoreVO : destroyedSnapshotStoreVOs) {
// check if this snapshot has child
final SnapshotInfo snap = snapshotFactory.getSnapshot(destroyedSnapshotStoreVO.getSnapshotId(), store);
if (snap.getChild() != null) {
s_logger.debug("Skip snapshot on store: " + destroyedSnapshotStoreVO + " , because it has child");
continue;
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Deleting snapshot store DB entry: " + destroyedSnapshotStoreVO);
}
_snapshotDao.remove(destroyedSnapshotStoreVO.getSnapshotId());
final SnapshotDataStoreVO snapshotOnPrimary = _snapshotStoreDao.findBySnapshot(destroyedSnapshotStoreVO.getSnapshotId(), DataStoreRole.Primary);
if (snapshotOnPrimary != null) {
_snapshotStoreDao.remove(snapshotOnPrimary.getId());
}
_snapshotStoreDao.remove(destroyedSnapshotStoreVO.getId());
}
} catch (final Exception e2) {
s_logger.warn("problem cleaning up snapshots in snapshot_store_ref for store: " + store.getName(), e2);
}
}
// CleanUp volumes on volume_store_ref
for (final DataStore store : imageStores) {
try {
final List<VolumeDataStoreVO> destroyedStoreVOs = _volumeStoreDao.listDestroyed(store.getId());
s_logger.debug("Secondary storage garbage collector found " + destroyedStoreVOs.size() + " volumes to cleanup on volume_store_ref for store: " + store.getName());
for (final VolumeDataStoreVO destroyedStoreVO : destroyedStoreVOs) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Deleting volume store DB entry: " + destroyedStoreVO);
}
_volumeStoreDao.remove(destroyedStoreVO.getId());
}
} catch (final Exception e2) {
s_logger.warn("problem cleaning up volumes in volume_store_ref for store: " + store.getName(), e2);
}
}
} catch (final Exception e3) {
s_logger.warn("problem cleaning up secondary storage DB entries. ", e3);
}
}
Aggregations