Search in sources :

Example 21 with SnapshotVO

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);
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) SnapshotVO(com.cloud.storage.SnapshotVO) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO) TemplateDataStoreVO(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO) S3TO(com.cloud.agent.api.to.S3TO)

Example 22 with SnapshotVO

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;
}
Also used : SnapshotVO(com.cloud.storage.SnapshotVO)

Example 23 with SnapshotVO

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;
}
Also used : SnapshotVO(com.cloud.storage.SnapshotVO) ArrayList(java.util.ArrayList)

Example 24 with SnapshotVO

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);
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) SnapshotVO(com.cloud.storage.SnapshotVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) SolidFireUtil(org.apache.cloudstack.storage.datastore.util.SolidFireUtil) SnapshotDetailsVO(com.cloud.storage.dao.SnapshotDetailsVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 25 with SnapshotVO

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()));
        }
    }
}
Also used : SnapshotVO(com.cloud.storage.SnapshotVO) VolumeVO(com.cloud.storage.VolumeVO) ArrayList(java.util.ArrayList) SnapshotDetailsVO(com.cloud.storage.dao.SnapshotDetailsVO)

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