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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations