Search in sources :

Example 86 with SnapshotVO

use of com.cloud.storage.SnapshotVO in project cloudstack by apache.

the class SolidFirePrimaryDataStoreDriver method deleteSolidFireVolume.

private void deleteSolidFireVolume(SolidFireUtil.SolidFireConnection sfConnection, long csVolumeId, long sfVolumeId) {
    List<SnapshotVO> lstSnapshots = getNonDestroyedSnapshots(csVolumeId);
    boolean deleteVolume = true;
    for (SnapshotVO snapshot : lstSnapshots) {
        SnapshotDetailsVO snapshotDetails = snapshotDetailsDao.findDetail(snapshot.getId(), SolidFireUtil.SNAPSHOT_ID);
        if (snapshotDetails != null && snapshotDetails.getValue() != null) {
            deleteVolume = false;
            break;
        }
    }
    if (deleteVolume) {
        SolidFireUtil.deleteVolume(sfConnection, sfVolumeId);
    }
}
Also used : SnapshotVO(com.cloud.storage.SnapshotVO) SnapshotDetailsVO(com.cloud.storage.dao.SnapshotDetailsVO)

Example 87 with SnapshotVO

use of com.cloud.storage.SnapshotVO in project cloudstack by apache.

the class SnapshotDaoImpl method updateState.

@Override
public boolean updateState(State currentState, Event event, State nextState, SnapshotVO snapshot, Object data) {
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    SnapshotVO snapshotVO = snapshot;
    snapshotVO.setState(nextState);
    super.update(snapshotVO.getId(), snapshotVO);
    txn.commit();
    return true;
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) SnapshotVO(com.cloud.storage.SnapshotVO)

Example 88 with SnapshotVO

use of com.cloud.storage.SnapshotVO in project cloudstack by apache.

the class SnapshotDaoImpl method remove.

@Override
@DB
public boolean remove(Long id) {
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    SnapshotVO entry = findById(id);
    if (entry != null) {
        _tagsDao.removeByIdAndType(id, ResourceObjectType.Snapshot);
    }
    boolean result = super.remove(id);
    txn.commit();
    return result;
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) SnapshotVO(com.cloud.storage.SnapshotVO) DB(com.cloud.utils.db.DB)

Example 89 with SnapshotVO

use of com.cloud.storage.SnapshotVO in project cloudstack by apache.

the class StorageSystemDataMotionStrategy method handleCreateManagedVolumeFromNonManagedSnapshot.

/**
 * Creates a managed volume on the storage from a snapshot that resides on the secondary storage (archived snapshot).
 * @param snapshotInfo snapshot on secondary
 * @param volumeInfo volume to be created on the storage
 * @param callback for async
 */
private void handleCreateManagedVolumeFromNonManagedSnapshot(SnapshotInfo snapshotInfo, VolumeInfo volumeInfo, AsyncCompletionCallback<CopyCommandResult> callback) {
    String errMsg = null;
    CopyCmdAnswer copyCmdAnswer = null;
    try {
        // at this point, the snapshotInfo and volumeInfo should have the same disk offering ID (so either one should be OK to get a DiskOfferingVO instance)
        DiskOfferingVO diskOffering = _diskOfferingDao.findByIdIncludingRemoved(volumeInfo.getDiskOfferingId());
        SnapshotVO snapshot = _snapshotDao.findById(snapshotInfo.getId());
        // update the volume's hv_ss_reserve (hypervisor snapshot reserve) from a disk offering (used for managed storage)
        _volumeService.updateHypervisorSnapshotReserveForVolume(diskOffering, volumeInfo.getId(), snapshot.getHypervisorType());
        HostVO hostVO;
        // create a volume on the storage
        AsyncCallFuture<VolumeApiResult> future = _volumeService.createVolumeAsync(volumeInfo, volumeInfo.getDataStore());
        VolumeApiResult result = future.get();
        if (result.isFailed()) {
            LOGGER.error("Failed to create a volume: " + result.getResult());
            throw new CloudRuntimeException(result.getResult());
        }
        volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore());
        volumeInfo.processEvent(Event.MigrationRequested);
        volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore());
        handleQualityOfServiceForVolumeMigration(volumeInfo, PrimaryDataStoreDriver.QualityOfServiceState.MIGRATION);
        hostVO = getHost(snapshotInfo.getDataCenterId(), snapshotInfo.getHypervisorType(), false);
        // copy the volume from secondary via the hypervisor
        if (HypervisorType.XenServer.equals(snapshotInfo.getHypervisorType())) {
            copyCmdAnswer = performCopyOfVdi(volumeInfo, snapshotInfo, hostVO);
        } else {
            copyCmdAnswer = copyImageToVolume(snapshotInfo, volumeInfo, hostVO);
        }
        if (copyCmdAnswer == null || !copyCmdAnswer.getResult()) {
            if (copyCmdAnswer != null && StringUtils.isNotEmpty(copyCmdAnswer.getDetails())) {
                throw new CloudRuntimeException(copyCmdAnswer.getDetails());
            } else {
                throw new CloudRuntimeException("Unable to create volume from snapshot");
            }
        }
    } catch (Exception ex) {
        errMsg = "Copy operation failed in 'StorageSystemDataMotionStrategy.handleCreateManagedVolumeFromNonManagedSnapshot': " + ex.getMessage();
        throw new CloudRuntimeException(errMsg);
    } finally {
        handleQualityOfServiceForVolumeMigration(volumeInfo, PrimaryDataStoreDriver.QualityOfServiceState.NO_MIGRATION);
        if (copyCmdAnswer == null) {
            copyCmdAnswer = new CopyCmdAnswer(errMsg);
        }
        CopyCommandResult result = new CopyCommandResult(null, copyCmdAnswer);
        result.setResult(errMsg);
        callback.complete(result);
    }
}
Also used : SnapshotVO(com.cloud.storage.SnapshotVO) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeApiResult(org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) HostVO(com.cloud.host.HostVO) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 90 with SnapshotVO

use of com.cloud.storage.SnapshotVO in project cloudstack by apache.

the class SnapshotServiceImpl method cleanupVolumeDuringSnapshotFailure.

@Override
public void cleanupVolumeDuringSnapshotFailure(Long volumeId, Long snapshotId) {
    SnapshotVO snaphsot = _snapshotDao.findById(snapshotId);
    if (snaphsot != null) {
        if (snaphsot.getState() != Snapshot.State.BackedUp) {
            List<SnapshotDataStoreVO> snapshotDataStoreVOs = _snapshotStoreDao.findBySnapshotId(snapshotId);
            for (SnapshotDataStoreVO snapshotDataStoreVO : snapshotDataStoreVOs) {
                s_logger.debug("Remove snapshot " + snapshotId + ", status " + snapshotDataStoreVO.getState() + " on snapshot_store_ref table with id: " + snapshotDataStoreVO.getId());
                _snapshotStoreDao.remove(snapshotDataStoreVO.getId());
            }
            s_logger.debug("Remove snapshot " + snapshotId + " status " + snaphsot.getState() + " from snapshot table");
            _snapshotDao.remove(snapshotId);
        }
    }
}
Also used : SnapshotVO(com.cloud.storage.SnapshotVO) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)

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