private void updateVolumePath(long volumeId, String path) { VolumeVO volumeVO = _volumeDao.findById(volumeId); volumeVO.setPath(path); _volumeDao.update(volumeId, volumeVO); }
public void update() { volumeDao.update(volumeVO.getId(), volumeVO); volumeVO = volumeDao.findById(volumeVO.getId()); }
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); } }
/** * 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); }
private void performBasicDelete(SolidFireUtil.SolidFireConnection sfConnection, long volumeId) { Long sfVolumeId = getBasicSfVolumeId(volumeId); Preconditions.checkNotNull(sfVolumeId, "'sfVolumeId' should not be 'null'."); String iqn = getBasicIqn(volumeId); Preconditions.checkNotNull(iqn, "'iqn' should not be 'null'."); VolumeVO volumeVO = volumeDao.findById(volumeId); deleteSolidFireVolume(sfConnection, volumeId, Long.parseLong(volumeVO.getFolder())); volumeVO.setFolder(String.valueOf(sfVolumeId)); volumeVO.set_iScsiName(iqn); volumeDao.update(volumeId, volumeVO); volumeDetailsDao.removeDetail(volumeId, BASIC_SF_ID); volumeDetailsDao.removeDetail(volumeId, BASIC_IQN); volumeDetailsDao.removeDetail(volumeId, BASIC_DELETE); }
private void setCertainVolumeValuesNull(long volumeId) { VolumeVO volumeVO = _volumeDao.findById(volumeId); volumeVO.set_iScsiName(null); volumeVO.setMinIops(null); volumeVO.setMaxIops(null); volumeVO.setHypervisorSnapshotReserve(null); _volumeDao.update(volumeId, volumeVO); }
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); } }
@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); } }
@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); } }
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 public void updateVolumeDiskChain(long volumeId, String path, String chainInfo) { VolumeVO vol = _volsDao.findById(volumeId); boolean needUpdate = false; // Volume path is not getting updated in the DB, need to find reason and fix the issue. if (vol.getPath() == null) { return; } if (!vol.getPath().equalsIgnoreCase(path)) { needUpdate = true; } if (chainInfo != null && (vol.getChainInfo() == null || !chainInfo.equalsIgnoreCase(vol.getChainInfo()))) { needUpdate = true; } if (needUpdate) { s_logger.info("Update volume disk chain info. vol: " + vol.getId() + ", " + vol.getPath() + " -> " + path + ", " + vol.getChainInfo() + " -> " + chainInfo); vol.setPath(path); vol.setChainInfo(chainInfo); _volsDao.update(volumeId, vol); } } }
volDao.update(volume.getId(), volumeVO); updated = true; break;
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 handlePath(final DiskTO[] disks, final HypervisorType hypervisorType) { if (hypervisorType != HypervisorType.KVM) { return; } if (disks != null) { for (final DiskTO disk : disks) { final Map<String, String> details = disk.getDetails(); final boolean isManaged = details != null && Boolean.parseBoolean(details.get(DiskTO.MANAGED)); if (isManaged && disk.getPath() == null) { final Long volumeId = disk.getData().getId(); final VolumeVO volume = _volsDao.findById(volumeId); disk.setPath(volume.get_iScsiName()); if (disk.getData() instanceof VolumeObjectTO) { final VolumeObjectTO volTo = (VolumeObjectTO)disk.getData(); volTo.setPath(volume.get_iScsiName()); } volume.setPath(volume.get_iScsiName()); _volsDao.update(volumeId, volume); } } } }
volumeVO.setLastPoolId(oldPoolId); volDao.update(volumeInfo.getId(), volumeVO);
private void handleFailedVolumeMigration(VolumeInfo srcVolumeInfo, VolumeInfo destVolumeInfo, HostVO hostVO) { try { _volumeService.revokeAccess(destVolumeInfo, hostVO, destVolumeInfo.getDataStore()); } catch (Exception ex) { LOGGER.warn("Failed to revoke access to the volume with the following ID: " + destVolumeInfo.getId()); } try { VolumeDetailVO volumeDetailVO = new VolumeDetailVO(destVolumeInfo.getId(), PrimaryDataStoreDriver.BASIC_DELETE_BY_FOLDER, Boolean.TRUE.toString(), false); volumeDetailsDao.persist(volumeDetailVO); destVolumeInfo.getDataStore().getDriver().deleteAsync(destVolumeInfo.getDataStore(), destVolumeInfo, null); volumeDetailsDao.removeDetails(srcVolumeInfo.getId()); } catch (Exception ex) { LOGGER.warn(ex.getMessage()); } VolumeVO volumeVO = _volumeDao.findById(srcVolumeInfo.getId()); volumeVO.setPoolId(srcVolumeInfo.getPoolId()); volumeVO.setLastPoolId(srcVolumeInfo.getLastPoolId()); volumeVO.setFolder(srcVolumeInfo.getFolder()); volumeVO.set_iScsiName(srcVolumeInfo.get_iScsiName()); _volumeDao.update(srcVolumeInfo.getId(), volumeVO); }
private void handleManagedVolumePostMigration(VolumeInfo volumeInfo, Host srcHost, VolumeObjectTO volumeTO) { final Map<String, String> details = new HashMap<>(); details.put(DeleteStoragePoolCommand.DATASTORE_NAME, volumeInfo.get_iScsiName()); final DeleteStoragePoolCommand cmd = new DeleteStoragePoolCommand(); cmd.setDetails(details); cmd.setRemoveDatastore(true); final Answer answer = agentMgr.easySend(srcHost.getId(), cmd); if (answer == null || !answer.getResult()) { String errMsg = "Error interacting with host (related to DeleteStoragePoolCommand)" + (StringUtils.isNotBlank(answer.getDetails()) ? ": " + answer.getDetails() : ""); s_logger.error(errMsg); throw new CloudRuntimeException(errMsg); } final PrimaryDataStoreDriver pdsd = (PrimaryDataStoreDriver)volumeInfo.getDataStore().getDriver(); pdsd.revokeAccess(volumeInfo, srcHost, volumeInfo.getDataStore()); VolumeDetailVO volumeDetailVo = new VolumeDetailVO(volumeInfo.getId(), PrimaryDataStoreDriver.BASIC_DELETE, Boolean.TRUE.toString(), false); volumeDetailsDao.persist(volumeDetailVo); pdsd.deleteAsync(volumeInfo.getDataStore(), volumeInfo, null); VolumeVO volumeVO = volDao.findById(volumeInfo.getId()); volumeVO.setPath(volumeTO.getPath()); volDao.update(volumeVO.getId(), volumeVO); }
private void handleSuccessfulVolumeMigration(VolumeInfo srcVolumeInfo, StoragePool destPool, MigrateVolumeAnswer migrateVolumeAnswer) { VolumeVO volumeVO = _volumeDao.findById(srcVolumeInfo.getId()); volumeVO.setPath(migrateVolumeAnswer.getVolumePath()); String chainInfo = migrateVolumeAnswer.getVolumeChainInfo(); if (chainInfo != null) { volumeVO.setChainInfo(chainInfo); } volumeVO.setPodId(destPool.getPodId()); volumeVO.setPoolId(destPool.getId()); volumeVO.setLastPoolId(srcVolumeInfo.getPoolId()); _volumeDao.update(srcVolumeInfo.getId(), volumeVO); }
private void handleVolumeMigrationForKVM(VolumeInfo srcVolumeInfo, VolumeInfo destVolumeInfo) { VirtualMachine vm = srcVolumeInfo.getAttachedVM(); if (vm != null && vm.getState() != VirtualMachine.State.Stopped) { throw new CloudRuntimeException("Currently, if a volume to migrate from non-managed storage to managed storage on KVM is attached to " + "a VM, the VM must be in the Stopped state."); } destVolumeInfo.getDataStore().getDriver().createAsync(destVolumeInfo.getDataStore(), destVolumeInfo, null); VolumeVO volumeVO = _volumeDao.findById(destVolumeInfo.getId()); volumeVO.setPath(volumeVO.get_iScsiName()); _volumeDao.update(volumeVO.getId(), volumeVO); destVolumeInfo = _volumeDataFactory.getVolume(destVolumeInfo.getId(), destVolumeInfo.getDataStore()); long srcStoragePoolId = srcVolumeInfo.getPoolId(); StoragePoolVO srcStoragePoolVO = _storagePoolDao.findById(srcStoragePoolId); HostVO hostVO; if (srcStoragePoolVO.getClusterId() != null) { hostVO = getHostInCluster(srcStoragePoolVO.getClusterId()); } else { hostVO = getHost(destVolumeInfo.getDataCenterId(), HypervisorType.KVM, false); } // migrate the volume via the hypervisor migrateVolumeForKVM(srcVolumeInfo, destVolumeInfo, hostVO, "Unable to migrate the volume from non-managed storage to managed storage"); volumeVO = _volumeDao.findById(destVolumeInfo.getId()); volumeVO.setFormat(ImageFormat.QCOW2); _volumeDao.update(volumeVO.getId(), volumeVO); }
protected Void managedCopyBaseImageCallback(AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, ManagedCreateBaseImageContext<VolumeApiResult> context) { CopyCommandResult result = callback.getResult(); VolumeInfo volumeInfo = context.getVolumeInfo(); VolumeApiResult res = new VolumeApiResult(volumeInfo); if (result.isSuccess()) { // volumeInfo.processEvent(Event.OperationSuccessed, result.getAnswer()); VolumeVO volume = volDao.findById(volumeInfo.getId()); CopyCmdAnswer answer = (CopyCmdAnswer)result.getAnswer(); TemplateObjectTO templateObjectTo = (TemplateObjectTO)answer.getNewData(); volume.setPath(templateObjectTo.getPath()); if (templateObjectTo.getFormat() != null) { volume.setFormat(templateObjectTo.getFormat()); } volDao.update(volume.getId(), volume); } else { volumeInfo.processEvent(Event.DestroyRequested); res.setResult(result.getResult()); } AsyncCallFuture<VolumeApiResult> future = context.getFuture(); future.complete(res); return null; }