Search in sources :

Example 51 with VolumeInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.

the class VolumeDataFactoryImpl method listVolumeOnCache.

@Override
public List<VolumeInfo> listVolumeOnCache(long volumeId) {
    List<VolumeInfo> cacheVols = new ArrayList<VolumeInfo>();
    // find all image cache stores for this zone scope
    List<DataStore> cacheStores = storeMgr.listImageCacheStores();
    if (cacheStores == null || cacheStores.size() == 0) {
        return cacheVols;
    }
    for (DataStore store : cacheStores) {
        // check if the volume is stored there
        VolumeDataStoreVO volStore = volumeStoreDao.findByStoreVolume(store.getId(), volumeId);
        if (volStore != null) {
            VolumeInfo vol = getVolume(volumeId, store);
            cacheVols.add(vol);
        }
    }
    return cacheVols;
}
Also used : DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) ArrayList(java.util.ArrayList) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)

Example 52 with VolumeInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.

the class PrimaryDataStoreImpl method getVolumes.

@Override
public List<VolumeInfo> getVolumes() {
    List<VolumeVO> volumes = volumeDao.findByPoolId(getId());
    List<VolumeInfo> volumeInfos = new ArrayList<VolumeInfo>();
    for (VolumeVO volume : volumes) {
        volumeInfos.add(VolumeObject.getVolumeObject(this, volume));
    }
    return volumeInfos;
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) ArrayList(java.util.ArrayList) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)

Example 53 with VolumeInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.

the class VMSnapshotHelperImpl method getVolumeTOList.

@Override
public List<VolumeObjectTO> getVolumeTOList(Long vmId) {
    List<VolumeObjectTO> volumeTOs = new ArrayList<VolumeObjectTO>();
    List<VolumeVO> volumeVos = volumeDao.findByInstance(vmId);
    VolumeInfo volumeInfo = null;
    for (VolumeVO volume : volumeVos) {
        volumeInfo = volumeDataFactory.getVolume(volume.getId());
        volumeTOs.add((VolumeObjectTO) volumeInfo.getTO());
    }
    return volumeTOs;
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) ArrayList(java.util.ArrayList) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)

Example 54 with VolumeInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.

the class VolumeApiServiceImpl method orchestrateTakeVolumeSnapshot.

private Snapshot orchestrateTakeVolumeSnapshot(Long volumeId, Long policyId, Long snapshotId, Account account, boolean quiescevm, Snapshot.LocationType locationType) throws ResourceAllocationException {
    VolumeInfo volume = volFactory.getVolume(volumeId);
    if (volume == null) {
        throw new InvalidParameterValueException("Creating snapshot failed due to volume:" + volumeId + " doesn't exist");
    }
    if (volume.getState() != Volume.State.Ready) {
        throw new InvalidParameterValueException("VolumeId: " + volumeId + " is not in " + Volume.State.Ready + " state but " + volume.getState() + ". Cannot take snapshot.");
    }
    CreateSnapshotPayload payload = new CreateSnapshotPayload();
    payload.setSnapshotId(snapshotId);
    payload.setSnapshotPolicyId(policyId);
    payload.setAccount(account);
    payload.setQuiescevm(quiescevm);
    payload.setLocationType(locationType);
    volume.addPayload(payload);
    return volService.takeSnapshot(volume);
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)

Example 55 with VolumeInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.

the class VolumeApiServiceImpl method deleteVolume.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_VOLUME_DELETE, eventDescription = "deleting volume")
public boolean deleteVolume(long volumeId, Account caller) throws ConcurrentOperationException {
    VolumeVO volume = _volsDao.findById(volumeId);
    if (volume == null) {
        throw new InvalidParameterValueException("Unable to find volume with ID: " + volumeId);
    }
    if (!_snapshotMgr.canOperateOnVolume(volume)) {
        throw new InvalidParameterValueException("There are snapshot operations in progress on the volume, unable to delete it");
    }
    _accountMgr.checkAccess(caller, null, true, volume);
    if (volume.getInstanceId() != null) {
        throw new InvalidParameterValueException("Please specify a volume that is not attached to any VM.");
    }
    if (volume.getState() == Volume.State.UploadOp) {
        VolumeDataStoreVO volumeStore = _volumeStoreDao.findByVolume(volume.getId());
        if (volumeStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS) {
            throw new InvalidParameterValueException("Please specify a volume that is not uploading");
        }
    }
    if (volume.getState() == Volume.State.NotUploaded || volume.getState() == Volume.State.UploadInProgress) {
        throw new InvalidParameterValueException("The volume is either getting uploaded or it may be initiated shortly, please wait for it to be completed");
    }
    try {
        if (volume.getState() != Volume.State.Destroy && volume.getState() != Volume.State.Expunging && volume.getState() != Volume.State.Expunged) {
            Long instanceId = volume.getInstanceId();
            if (!volService.destroyVolume(volume.getId())) {
                return false;
            }
            VMInstanceVO vmInstance = _vmInstanceDao.findById(instanceId);
            if (instanceId == null || (vmInstance.getType().equals(VirtualMachine.Type.User))) {
                // Decrement the resource count for volumes and primary storage belonging user VM's only
                _resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.volume, volume.isDisplayVolume());
            }
        }
        // Mark volume as removed if volume has not been created on primary or secondary
        if (volume.getState() == Volume.State.Allocated) {
            _volsDao.remove(volumeId);
            stateTransitTo(volume, Volume.Event.DestroyRequested);
            return true;
        }
        // expunge volume from primary if volume is on primary
        VolumeInfo volOnPrimary = volFactory.getVolume(volume.getId(), DataStoreRole.Primary);
        if (volOnPrimary != null) {
            s_logger.info("Expunging volume " + volume.getId() + " from primary data store");
            AsyncCallFuture<VolumeApiResult> future = volService.expungeVolumeAsync(volOnPrimary);
            future.get();
            //decrement primary storage count
            _resourceLimitMgr.recalculateResourceCount(volume.getAccountId(), volume.getDomainId(), ResourceType.primary_storage.getOrdinal());
        }
        // expunge volume from secondary if volume is on image store
        VolumeInfo volOnSecondary = volFactory.getVolume(volume.getId(), DataStoreRole.Image);
        if (volOnSecondary != null) {
            s_logger.info("Expunging volume " + volume.getId() + " from secondary data store");
            AsyncCallFuture<VolumeApiResult> future2 = volService.expungeVolumeAsync(volOnSecondary);
            future2.get();
            //decrement secondary storage count
            _resourceLimitMgr.recalculateResourceCount(volume.getAccountId(), volume.getDomainId(), ResourceType.secondary_storage.getOrdinal());
        }
        // delete all cache entries for this volume
        List<VolumeInfo> cacheVols = volFactory.listVolumeOnCache(volume.getId());
        for (VolumeInfo volOnCache : cacheVols) {
            s_logger.info("Delete volume from image cache store: " + volOnCache.getDataStore().getName());
            volOnCache.delete();
        }
    } catch (InterruptedException | ExecutionException | NoTransitionException e) {
        s_logger.warn("Failed to expunge volume:", e);
        return false;
    }
    return true;
}
Also used : VMInstanceVO(com.cloud.vm.VMInstanceVO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) VolumeApiResult(org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO) ExecutionException(java.util.concurrent.ExecutionException) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Aggregations

VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)112 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)51 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)50 VolumeVO (com.cloud.storage.VolumeVO)36 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)23 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)22 ExecutionException (java.util.concurrent.ExecutionException)22 VolumeApiResult (org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult)22 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)19 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)19 CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)18 SnapshotInfo (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo)17 ArrayList (java.util.ArrayList)15 HashMap (java.util.HashMap)15 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)13 Map (java.util.Map)13 SnapshotVO (com.cloud.storage.SnapshotVO)12 DB (com.cloud.utils.db.DB)12 Test (org.testng.annotations.Test)12 Account (com.cloud.user.Account)11