public static VolumeVO findVolumeById(Long volumeId) { return s_volumeDao.findByIdIncludingRemoved(volumeId); }
@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 boolean checkStatusOfVolumeSnapshots(long vmId, Volume.Type type) { List<VolumeVO> listVolumes = null; if (type == Volume.Type.ROOT) { listVolumes = _volsDao.findByInstanceAndType(vmId, type); } else if (type == Volume.Type.DATADISK) { listVolumes = _volsDao.findByInstanceAndType(vmId, type); } else { listVolumes = _volsDao.findByInstance(vmId); } s_logger.debug("Found "+listVolumes.size()+" no. of volumes of type "+type+" for vm with VM ID "+vmId); for (VolumeVO volume : listVolumes) { Long volumeId = volume.getId(); s_logger.debug("Checking status of snapshots for Volume with Volume Id: "+volumeId); List<SnapshotVO> ongoingSnapshots = _snapshotDao.listByStatus(volumeId, Snapshot.State.Creating, Snapshot.State.CreatedOnPrimary, Snapshot.State.BackingUp); int ongoingSnapshotsCount = ongoingSnapshots.size(); s_logger.debug("The count of ongoing Snapshots for VM with ID "+vmId+" and disk type "+type+" is "+ongoingSnapshotsCount); if (ongoingSnapshotsCount > 0) { s_logger.debug("Found "+ongoingSnapshotsCount+" no. of snapshots, on volume of type "+type+", which snapshots are not yet backed up"); return true; } } return false; }
private void cleanupVolumeDuringMigrationFailure(Long volumeId, Long destPoolId) { StoragePool destPool = (StoragePool)dataStoreMgr.getDataStore(destPoolId, DataStoreRole.Primary); if (destPool == null) { return; } VolumeVO volume = _volsDao.findById(volumeId); if (volume.getState() == Volume.State.Migrating) { VolumeVO duplicateVol = _volsDao.findByPoolIdName(destPoolId, volume.getName()); if (duplicateVol != null) { s_logger.debug("Remove volume " + duplicateVol.getId() + " on storage pool " + destPoolId); _volsDao.remove(duplicateVol.getId()); } s_logger.debug("change volume state to ready from migrating in case migration failure for vol: " + volumeId); volume.setState(Volume.State.Ready); _volsDao.update(volumeId, volume); } }
@Override protected Volume retrieve() { return _volsDao.findById(_volumeId); } }
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); } }
private void markVolumesInPool(VMInstanceVO vm, StoragePool destPool, Answer[] hypervisorMigrationResults) { MigrateVmToPoolAnswer relevantAnswer = null; for (Answer answer : hypervisorMigrationResults) { if (s_logger.isTraceEnabled()) { s_logger.trace(String.format("received an %s: %s", answer.getClass().getSimpleName(), answer)); } if (answer instanceof MigrateVmToPoolAnswer) { relevantAnswer = (MigrateVmToPoolAnswer) answer; } } if (relevantAnswer == null) { throw new CloudRuntimeException("no relevant migration results found"); } List<VolumeVO> volumes = _volsDao.findUsableVolumesForInstance(vm.getId()); if(s_logger.isDebugEnabled()) { String msg = String.format("found %d volumes for VM %s(uuid:%s, id:%d)", volumes.size(), vm.getInstanceName(), vm.getUuid(), vm.getId()); s_logger.debug(msg); } for (VolumeObjectTO result : relevantAnswer.getVolumeTos() ) { if(s_logger.isDebugEnabled()) { s_logger.debug(String.format("updating volume (%d) with path '%s' on pool '%d'", result.getId(), result.getPath(), destPool.getId())); } VolumeVO volume = _volsDao.findById(result.getId()); volume.setPath(result.getPath()); volume.setPoolId(destPool.getId()); _volsDao.update(volume.getId(), volume); } }
private void updateVolumePath(List<VolumeObjectTO> volumeTOs) { for (VolumeObjectTO volume : volumeTOs) { if (volume.getPath() != null) { VolumeVO volumeVO = volumeDao.findById(volume.getId()); volumeVO.setPath(volume.getPath()); volumeVO.setVmSnapshotChainSize(volume.getSize()); volumeDao.persist(volumeVO); } } }
VMTemplateVO privateTemplate = null; if (volumeId != null) { // create template from volume volume = _volumeDao.findById(volumeId); if (volume == null) { throw new InvalidParameterValueException("Failed to create private template record, unable to find volume " + volumeId); hyperType = _volumeDao.getHypervisorType(volumeId); if (HypervisorType.LXC.equals(hyperType)) { throw new InvalidParameterValueException("Template creation is not supported for LXC volume: " + volumeId); volume = _volumeDao.findByIdIncludingRemoved(snapshot.getVolumeId());
volume = volumeDao.findById(volumeId); VolumeVO volumeToDelete = volumeDao.findByIdIncludingRemoved(volumeId);
VolumeVO vol = volumeDao.findByUuid(snapshotTO.getVolume().getUuid()); if (vol != null) { s_logger.info("Update volume path change due to snapshot operation, volume " + vol.getId() + " path: " + vol.getPath() + "->" + snapshotTO.getVolume().getPath()); vol.setPath(snapshotTO.getVolume().getPath()); volumeDao.update(vol.getId(), vol); } else { s_logger.error("Cound't find the original volume with uuid: " + snapshotTO.getVolume().getUuid());
protected VolumeVO duplicateVolumeOnAnotherStorage(Volume volume, StoragePool pool) { Long lastPoolId = volume.getPoolId(); String folder = pool.getPath(); // For SMB, pool credentials are also stored in the uri query string. We trim the query string // part here to make sure the credentials do not get stored in the db unencrypted. if (pool.getPoolType() == StoragePoolType.SMB && folder != null && folder.contains("?")) { folder = folder.substring(0, folder.indexOf("?")); } VolumeVO newVol = new VolumeVO(volume); newVol.setInstanceId(null); newVol.setChainInfo(null); newVol.setPath(null); newVol.setFolder(folder); newVol.setPodId(pool.getPodId()); newVol.setPoolId(pool.getId()); newVol.setLastPoolId(lastPoolId); newVol.setPodId(pool.getPodId()); return volDao.persist(newVol); }
_volumeStoreDao.update(volStoreVO.getId(), updateBuilder); VolumeVO volUpdater = volumeDao.createForUpdate(); volUpdater.setSize(answer.getTemplateSize()); volumeDao.update(obj.getId(), volUpdater);
@Override public void updateDisplay(Volume volume, Boolean displayVolume) { // 1. Resource limit changes updateResourceCount(volume, displayVolume); // 2. generate usage event if not in destroyed state saveUsageEvent(volume, displayVolume); // 3. Set the flag if (displayVolume != null && displayVolume != volume.isDisplayVolume()) { // FIXME - Confused - typecast for now. ((VolumeVO)volume).setDisplayVolume(displayVolume); _volsDao.update(volume.getId(), (VolumeVO)volume); } }
@DB @Override @ActionEvent(eventType = EventTypes.EVENT_VOLUME_DELETE, eventDescription = "deleting volume") /** * Executes the removal of the volume. If the volume is only allocated we do not try to remove it from primary and secondary storage. * Otherwise, after the removal in the database, we will try to remove the volume from both primary and secondary storage. */ public boolean deleteVolume(long volumeId, Account caller) throws ConcurrentOperationException { VolumeVO volume = retrieveAndValidateVolume(volumeId, caller); try { destroyVolumeIfPossible(volume); // 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; } expungeVolumesInPrimaryStorageIfNeeded(volume); expungeVolumesInSecondaryStorageIfNeeded(volume); cleanVolumesCache(volume); return true; } catch (InterruptedException | ExecutionException | NoTransitionException e) { s_logger.warn("Failed to expunge volume: " + volume.getUuid(), e); return false; } }
SearchBuilder<VolumeVO> volumeSearch = _volumeDao.createSearchBuilder(); volumeSearch.and("volumeType", volumeSearch.entity().getVolumeType(), SearchCriteria.Op.EQ); volumeSearch.and("poolId", volumeSearch.entity().getPoolId(), SearchCriteria.Op.EQ);
private void addVolumeMetrics(final List<Item> metricsList, final long dcId, final String zoneName, final String zoneUuid) { int total = 0; int ready = 0; int destroyed = 0; for (final VolumeVO volume : volumeDao.findByDc(dcId)) { if (volume == null) { continue; } total++; if (volume.getState() == Volume.State.Ready) { ready++; } else if (volume.getState() == Volume.State.Destroy) { destroyed++; } } metricsList.add(new ItemVolume(zoneName, zoneUuid, Volume.State.Ready.name().toLowerCase(), ready)); metricsList.add(new ItemVolume(zoneName, zoneUuid, Volume.State.Destroy.name().toLowerCase(), destroyed)); metricsList.add(new ItemVolume(zoneName, zoneUuid, TOTAL, total)); }
@Override public boolean isLocalStorageActiveOnHost(Long hostId) { List<StoragePoolHostVO> storagePoolHostRefs = _storagePoolHostDao.listByHostId(hostId); for (StoragePoolHostVO storagePoolHostRef : storagePoolHostRefs) { StoragePoolVO PrimaryDataStoreVO = _storagePoolDao.findById(storagePoolHostRef.getPoolId()); if (PrimaryDataStoreVO.getPoolType() == StoragePoolType.LVM || PrimaryDataStoreVO.getPoolType() == StoragePoolType.EXT) { SearchBuilder<VolumeVO> volumeSB = _volsDao.createSearchBuilder(); volumeSB.and("poolId", volumeSB.entity().getPoolId(), SearchCriteria.Op.EQ); volumeSB.and("removed", volumeSB.entity().getRemoved(), SearchCriteria.Op.NULL); volumeSB.and("state", volumeSB.entity().getState(), SearchCriteria.Op.NIN); SearchBuilder<VMInstanceVO> activeVmSB = _vmInstanceDao.createSearchBuilder(); activeVmSB.and("state", activeVmSB.entity().getState(), SearchCriteria.Op.IN); volumeSB.join("activeVmSB", activeVmSB, volumeSB.entity().getInstanceId(), activeVmSB.entity().getId(), JoinBuilder.JoinType.INNER); SearchCriteria<VolumeVO> volumeSC = volumeSB.create(); volumeSC.setParameters("poolId", PrimaryDataStoreVO.getId()); volumeSC.setParameters("state", Volume.State.Expunging, Volume.State.Destroy); volumeSC.setJoinParameters("activeVmSB", "state", State.Starting, State.Running, State.Stopping, State.Migrating); List<VolumeVO> volumes = _volsDao.search(volumeSC, null); if (volumes.size() > 0) { return true; } } } return false; }