@Override public long getId() { return volumeVO.getId(); }
public long getVolumeId() { return volumeVO.getId(); }
@Override public HypervisorType getHypervisorType() { return volumeDao.getHypervisorType(volumeVO.getId()); }
/** * We will check if the given volume is in the primary storage. If it is, we will execute an asynchronous call to delete it there. * If the volume is not in the primary storage, we do nothing here. */ protected void expungeVolumesInPrimaryStorageIfNeeded(VolumeVO volume) throws InterruptedException, ExecutionException { 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(); } }
private void detachVolumesFromVm(List<VolumeVO> volumes) { for (VolumeVO volume : volumes) { Volume detachResult = _volumeService.detachVolumeViaDestroyVM(volume.getInstanceId(), volume.getId()); if (detachResult == null) { s_logger.error("DestroyVM remove volume - failed to detach and delete volume " + volume.getInstanceId() + " from instance " + volume.getId()); } } }
private void deleteVolumesFromVm(List<VolumeVO> volumes) { for (VolumeVO volume : volumes) { boolean deleteResult = _volumeService.deleteVolume(volume.getId(), CallContext.current().getCallingAccount()); if (!deleteResult) { s_logger.error("DestroyVM remove volume - failed to delete volume " + volume.getInstanceId() + " from instance " + volume.getId()); } } } }
@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; }
private 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; }
private void cleanupVolumeDuringSnapshotFailure(Long volumeId, Long snapshotId) { _snapshotSrv.cleanupVolumeDuringSnapshotFailure(volumeId, snapshotId); VolumeVO volume = _volsDao.findById(volumeId); if (volume.getState() == Volume.State.Snapshotting) { s_logger.debug("change volume state back to Ready: " + volume.getId()); volume.setState(Volume.State.Ready); _volsDao.update(volume.getId(), volume); } }
/** * Clean volumes cache entries (if they exist). */ protected void cleanVolumesCache(VolumeVO volume) { List<VolumeInfo> cacheVols = volFactory.listVolumeOnCache(volume.getId()); if (CollectionUtils.isEmpty(cacheVols)) { return; } for (VolumeInfo volOnCache : cacheVols) { s_logger.info("Delete volume from image cache store: " + volOnCache.getDataStore().getName()); volOnCache.delete(); } }
/** * We will check if the given volume is in the secondary storage. If the volume is not in the primary storage, we do nothing here. * If it is, we will execute an asynchronous call to delete it there. Then, we decrement the {@link ResourceType#secondary_storage} for the account that owns the volume. */ protected void expungeVolumesInSecondaryStorageIfNeeded(VolumeVO volume) throws InterruptedException, ExecutionException { 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(); _resourceLimitMgr.decrementResourceCount(volOnSecondary.getAccountId(), ResourceType.secondary_storage, volOnSecondary.getSize()); } }
public void updateVolumeDetails(VolumeVO volume, FileSystem esvolume) { VolumeDetailVO compression = new VolumeDetailVO(volume.getId(), "compression", esvolume.getCompression(), false); _volumeDetailsDao.persist(compression); VolumeDetailVO deduplication = new VolumeDetailVO(volume.getId(), "deduplication", esvolume.getDeduplication(), false); _volumeDetailsDao.persist(deduplication); VolumeDetailVO sync = new VolumeDetailVO(volume.getId(), "sync", esvolume.getSync(), false); _volumeDetailsDao.persist(sync); VolumeDetailVO graceallowed = new VolumeDetailVO(volume.getId(), "graceallowed", esvolume.getGraceallowed(), false); _volumeDetailsDao.persist(graceallowed); }
@Override public long getSolidFireVolumeSize(String volumeUuid) { VolumeVO volume = volumeDao.findByUuid(volumeUuid); VolumeDetailVO volumeDetail = volumeDetailsDao.findDetail(volume.getId(), SolidFireUtil.VOLUME_SIZE); if (volumeDetail != null && volumeDetail.getValue() != null) { return Long.parseLong(volumeDetail.getValue()); } throw new CloudRuntimeException("Unable to determine the size of the SolidFire volume"); } }
private void cleanupVolumeDuringAttachFailure(Long volumeId, Long vmId) { VolumeVO volume = _volsDao.findById(volumeId); if (volume == null) { return; } if (volume.getState().equals(Volume.State.Creating)) { s_logger.debug("Remove volume: " + volume.getId() + ", as it's leftover from last mgt server stop"); _volsDao.remove(volume.getId()); } if (volume.getState().equals(Volume.State.Attaching)) { s_logger.warn("Vol: " + volume.getName() + " failed to attach to VM: " + _userVmDao.findById(vmId).getHostName() + " on last mgt server stop, changing state back to Ready"); volume.setState(Volume.State.Ready); _volsDao.update(volumeId, volume); } }
/** * Offline Vmware volume migration * Cleanup volumes after failed migrations and reset state of source volume * * @param srcData * @param destData */ private void cleanUpVolumesForFailedMigrations(DataObject srcData, DataObject destData) { VolumeVO destinationVO = volDao.findById(destData.getId()); VolumeVO sourceVO = volDao.findById(srcData.getId()); sourceVO.setState(Volume.State.Ready); volDao.update(sourceVO.getId(), sourceVO); destinationVO.setState(Volume.State.Expunged); destinationVO.setRemoved(new Date()); volDao.update(destinationVO.getId(), destinationVO); }
@Override public VolumeInfo updateHypervisorSnapshotReserveForVolume(DiskOffering diskOffering, long volumeId, HypervisorType hyperType) { if (diskOffering != null && hyperType != null) { Integer hypervisorSnapshotReserve = diskOffering.getHypervisorSnapshotReserve(); if (hyperType == HypervisorType.KVM) { hypervisorSnapshotReserve = null; } else if (hypervisorSnapshotReserve == null || hypervisorSnapshotReserve < 0) { hypervisorSnapshotReserve = 0; } VolumeVO volume = volDao.findById(volumeId); volume.setHypervisorSnapshotReserve(hypervisorSnapshotReserve); volDao.update(volume.getId(), volume); } return volFactory.getVolume(volumeId); } }
@Override public void revokeAccess(long vmId, long hostId) { HostVO host = _hostDao.findById(hostId); List<VolumeVO> volumesForVm = _volsDao.findByInstance(vmId); if (volumesForVm != null) { for (VolumeVO volumeForVm : volumesForVm) { VolumeInfo volumeInfo = volFactory.getVolume(volumeForVm.getId()); // pool id can be null for the VM's volumes in Allocated state if (volumeForVm.getPoolId() != null) { DataStore dataStore = dataStoreMgr.getDataStore(volumeForVm.getPoolId(), DataStoreRole.Primary); volService.revokeAccess(volumeInfo, host, dataStore); } } } }
private void publishUsageEvent(String type, VMSnapshot vmSnapshot, UserVm userVm, VolumeObjectTO volumeTo) { VolumeVO volume = volumeDao.findById(volumeTo.getId()); Long diskOfferingId = volume.getDiskOfferingId(); Long offeringId = null; if (diskOfferingId != null) { DiskOfferingVO offering = diskOfferingDao.findById(diskOfferingId); if (offering != null && (offering.getType() == DiskOfferingVO.Type.Disk)) { offeringId = offering.getId(); } } UsageEventUtils.publishUsageEvent(type, vmSnapshot.getAccountId(), userVm.getDataCenterId(), userVm.getId(), vmSnapshot.getName(), offeringId, volume.getId(), // save volume's id into templateId field volumeTo.getSize(), VMSnapshot.class.getName(), vmSnapshot.getUuid()); }
@Override public String getUri() { if (dataStore == null) { throw new CloudRuntimeException("datastore must be set before using this object"); } DataObjectInStore obj = objectInStoreMgr.findObject(volumeVO.getId(), DataObjectType.VOLUME, dataStore.getId(), dataStore.getRole()); if (obj.getState() != ObjectInDataStoreStateMachine.State.Ready) { return dataStore.getUri() + "&" + EncodingType.OBJTYPE + "=" + DataObjectType.VOLUME + "&" + EncodingType.SIZE + "=" + volumeVO.getSize() + "&" + EncodingType.NAME + "=" + volumeVO.getName(); } else { return dataStore.getUri() + "&" + EncodingType.OBJTYPE + "=" + DataObjectType.VOLUME + "&" + EncodingType.PATH + "=" + obj.getInstallPath(); } }