public VolumeObjectTO(VolumeInfo volume) { uuid = volume.getUuid(); path = volume.getPath(); accountId = volume.getAccountId(); if (volume.getDataStore() != null) { dataStore = volume.getDataStore().getTO(); } else { dataStore = null; } vmName = volume.getAttachedVmName(); size = volume.getSize(); setVolumeId(volume.getId()); chainInfo = volume.getChainInfo(); volumeType = volume.getVolumeType(); name = volume.getName(); setId(volume.getId()); format = volume.getFormat(); provisioningType = volume.getProvisioningType(); bytesReadRate = volume.getBytesReadRate(); bytesWriteRate = volume.getBytesWriteRate(); iopsReadRate = volume.getIopsReadRate(); iopsWriteRate = volume.getIopsWriteRate(); cacheMode = volume.getCacheMode(); hypervisorType = volume.getHypervisorType(); setDeviceId(volume.getDeviceId()); }
@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 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); }
@Override public long getDataObjectSizeIncludingHypervisorSnapshotReserve(DataObject dataObject, StoragePool pool) { VolumeInfo volume = (VolumeInfo)dataObject; long volumeSize = volume.getSize(); Integer hypervisorSnapshotReserve = volume.getHypervisorSnapshotReserve(); if (hypervisorSnapshotReserve != null) { if (hypervisorSnapshotReserve < 25) { hypervisorSnapshotReserve = 25; } volumeSize += volumeSize * (hypervisorSnapshotReserve / 100f); } return volumeSize; }
private void deleteSolidFireVolume(SolidFireUtil.SolidFireConnection sfConnection, VolumeInfo volumeInfo) { Long storagePoolId = volumeInfo.getPoolId(); if (storagePoolId == null) { return; // this volume was never assigned to a storage pool, so no SAN volume should exist for it } long sfVolumeId = Long.parseLong(volumeInfo.getFolder()); deleteSolidFireVolume(sfConnection, volumeInfo.getId(), sfVolumeId); }
/** * Returns the iScsi connection path. */ protected String generateDestPath(VirtualMachineTO vmTO, VolumeVO srcVolume, Host destHost, StoragePoolVO destStoragePool, VolumeInfo destVolumeInfo) { return connectHostToVolume(destHost, destVolumeInfo.getPoolId(), destVolumeInfo.get_iScsiName()); }
Account owner = _accountMgr.getAccount(volume.getAccountId()); _resourceLimitMgr.checkResourceLimit(owner, ResourceType.secondary_storage, new Long(volume.getSize()).longValue()); } catch (ResourceAllocationException e) { if (snapshotType != Type.MANUAL) { VMInstanceVO vmInstance = _vmDao.findById(volume.getInstanceId()); String vmDisplayName = "detached"; if (vmInstance != null) { snapshotName = vmDisplayName + "_" + volume.getName() + "_" + timeString; StoragePoolVO storagePool = _storagePoolDao.findById(volume.getDataStore().getId()); if (storagePool.getScope() == ScopeType.ZONE) { hypervisorType = storagePool.getHypervisor(); if (ImageFormat.VHD.equals(volume.getFormat())) { hypervisorType = HypervisorType.XenServer; else if (ImageFormat.OVA.equals(volume.getFormat())) { hypervisorType = HypervisorType.VMware; else if (ImageFormat.QCOW2.equals(volume.getFormat())) { hypervisorType = HypervisorType.KVM; hypervisorType = volume.getHypervisorType(); new SnapshotVO(volume.getDataCenterId(), volume.getAccountId(), volume.getDomainId(), volume.getId(), volume.getDiskOfferingId(), snapshotName, (short)snapshotType.ordinal(), snapshotType.name(), volume.getSize(), volume.getMinIops(), volume.getMaxIops(), hypervisorType, locationType);
if (volumeInfo.getFormat() == ImageFormat.VHD) { hostVO = getHost(volumeInfo.getDataCenterId(), HypervisorType.XenServer, true); volumeInfo.getDataCenterId()); else if (volumeInfo.getFormat() == ImageFormat.OVA) { hostVO = getHost(volumeInfo.getDataCenterId(), HypervisorType.VMware, false); volumeInfo.getDataCenterId()); VolumeDetailVO volumeDetail = new VolumeDetailVO(volumeInfo.getId(), "cloneOfTemplate", String.valueOf(templateInfo.getId()), AsyncCallFuture<VolumeApiResult> future = _volumeService.createVolumeAsync(volumeInfo, volumeInfo.getDataStore()); volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore()); volumeInfo.processEvent(Event.MigrationRequested); volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore()); disconnectHostFromVolume(hostVO, volumeInfo.getPoolId(), volumeInfo.get_iScsiName()); newVolume.setSize(volumeInfo.getSize()); newVolume.setPath(volumeInfo.getPath()); newVolume.setFormat(volumeInfo.getFormat()); volumeInfo.getDataStore().getDriver().deleteAsync(volumeInfo.getDataStore(), volumeInfo, null);
protected VolumeVO createVolumeFromSnapshot(VolumeVO volume, long snapshotId, Long vmId) throws StorageUnavailableException { VolumeInfo createdVolume = null; SnapshotVO snapshot = _snapshotDao.findById(snapshotId); snapshot.getVolumeId(); UserVmVO vm = null; if (vmId != null) { vm = _userVmDao.findById(vmId); } // sync old snapshots to region store if necessary createdVolume = _volumeMgr.createVolumeFromSnapshot(volume, snapshot, vm); VolumeVO volumeVo = _volsDao.findById(createdVolume.getId()); UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE, createdVolume.getAccountId(), createdVolume.getDataCenterId(), createdVolume.getId(), createdVolume.getName(), createdVolume.getDiskOfferingId(), null, createdVolume.getSize(), Volume.class.getName(), createdVolume.getUuid(), volumeVo.isDisplayVolume()); return volumeVo; }
volumeDetail = new VolumeDetailVO(volumeInfo.getId(), "cloneOfSnapshot", String.valueOf(snapshotInfo.getId()), DiskOfferingVO diskOffering = _diskOfferingDao.findByIdIncludingRemoved(volumeInfo.getDiskOfferingId()); SnapshotVO snapshot = _snapshotDao.findById(snapshotInfo.getId()); _volumeService.updateHypervisorSnapshotReserveForVolume(diskOffering, volumeInfo.getId(), snapshot.getHypervisorType()); AsyncCallFuture<VolumeApiResult> future = _volumeService.createVolumeAsync(volumeInfo, volumeInfo.getDataStore()); VolumeApiResult result = future.get(); volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore()); volumeInfo.processEvent(Event.MigrationRequested); volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore()); disconnectHostFromVolume(hostVO, volumeInfo.getPoolId(), volumeInfo.get_iScsiName()); VolumeObjectTO newVolume = new VolumeObjectTO(); newVolume.setSize(volumeInfo.getSize()); newVolume.setPath(volumeInfo.get_iScsiName()); newVolume.setFormat(volumeInfo.getFormat());
if (volumeToAttach == null || !(volumeToAttach.getVolumeType() == Volume.Type.DATADISK || volumeToAttach.getVolumeType() == Volume.Type.ROOT)) { throw new InvalidParameterValueException("Please specify a volume with the valid type: " + Volume.Type.ROOT.toString() + " or " + Volume.Type.DATADISK.toString()); if (volumeToAttach.getInstanceId() != null) { throw new InvalidParameterValueException("Please specify a volume that is not attached to any VM."); if (volumeToAttach.getState() == Volume.State.Destroy) { throw new InvalidParameterValueException("Please specify a volume that is not destroyed."); if (vm.getDataCenterId() != volumeToAttach.getDataCenterId()) { throw new InvalidParameterValueException("Please specify a VM that is in the same zone as the volume."); validateRootVolumeDetachAttach(_volsDao.findById(volumeToAttach.getId()), vm); if (volumeToAttach.getState() == Volume.State.Uploaded) { throw new InvalidParameterValueException("No support for Root volume attach in state " + Volume.State.Uploaded); DataCenterVO dataCenter = _dcDao.findById(volumeToAttach.getDataCenterId()); if (!dataCenter.isLocalStorageEnabled()) { DiskOfferingVO diskOffering = _diskOfferingDao.findById(volumeToAttach.getDiskOfferingId()); if (diskOffering.isUseLocalStorage()) { throw new InvalidParameterValueException("Zone is not configured to use local storage but volume's disk offering " + diskOffering.getName() + " uses it"); if (!(Volume.State.Allocated.equals(volumeToAttach.getState()) || Volume.State.Ready.equals(volumeToAttach.getState()) || Volume.State.Uploaded.equals(volumeToAttach.getState()))) { throw new InvalidParameterValueException("Volume state must be in Allocated, Ready or in Uploaded state"); Account owner = _accountDao.findById(volumeToAttach.getAccountId()); if (!(volumeToAttach.getState() == Volume.State.Allocated || volumeToAttach.getState() == Volume.State.Ready)) {
if (!ImageFormat.QCOW2.equals(srcVolumeInfo.getFormat())) { throw new CloudRuntimeException("Currently, only the KVM hypervisor type is supported for the migration of a volume " + "from managed storage to non-managed storage."); VirtualMachine vm = srcVolumeInfo.getAttachedVM(); long destStoragePoolId = destVolumeInfo.getPoolId(); StoragePoolVO destStoragePoolVO = _storagePoolDao.findById(destStoragePoolId); hostVO = getHost(destVolumeInfo.getDataCenterId(), hypervisorType, false); setCertainVolumeValuesNull(destVolumeInfo.getId()); updateVolumePath(destVolumeInfo.getId(), path); destVolumeInfo = _volumeDataFactory.getVolume(destVolumeInfo.getId(), destVolumeInfo.getDataStore()); DataTO dataTO = destVolumeInfo.getTO();
private void handleVolumeMigrationForXenServer(VolumeInfo srcVolumeInfo, VolumeInfo destVolumeInfo) { VirtualMachine vm = srcVolumeInfo.getAttachedVM(); destVolumeInfo.getDataStore().getDriver().createAsync(destVolumeInfo.getDataStore(), destVolumeInfo, null); destVolumeInfo = _volumeDataFactory.getVolume(destVolumeInfo.getId(), destVolumeInfo.getDataStore()); _volumeService.grantAccess(destVolumeInfo, hostVO, destVolumeInfo.getDataStore()); StoragePool destPool = (StoragePool)dataStoreMgr.getDataStore(destVolumeInfo.getDataStore().getId(), DataStoreRole.Primary); MigrateVolumeCommand command = new MigrateVolumeCommand(srcVolumeInfo.getId(), srcVolumeInfo.getPath(), destPool, srcVolumeInfo.getAttachedVmName(), srcVolumeInfo.getVolumeType(), waitInterval); details.put(DiskTO.IQN, destVolumeInfo.get_iScsiName()); details.put(DiskTO.STORAGE_HOST, destPool.getHostAddress()); handleFailedVolumeMigration(srcVolumeInfo, destVolumeInfo, hostVO); throw new CloudRuntimeException("Failed to migrate volume with ID " + srcVolumeInfo.getId() + " to storage pool with ID " + destPool.getId()); } else { handleSuccessfulVolumeMigration(srcVolumeInfo, destPool, (MigrateVolumeAnswer)answer);
private String copyManagedVolumeToSecondaryStorage(VolumeInfo srcVolumeInfo, VolumeInfo destVolumeInfo, HostVO hostVO, String errMsg) { boolean srcVolumeDetached = srcVolumeInfo.getAttachedVM() == null; StoragePoolVO storagePoolVO = _storagePoolDao.findById(srcVolumeInfo.getPoolId()); Map<String, String> srcDetails = getVolumeDetails(srcVolumeInfo); CopyVolumeCommand copyVolumeCommand = new CopyVolumeCommand(srcVolumeInfo.getId(), destVolumeInfo.getPath(), storagePoolVO, destVolumeInfo.getDataStore().getUri(), true, StorageManager.KvmStorageOfflineMigrationWait.value(), true); copyVolumeCommand.setSrcData(srcVolumeInfo.getTO()); copyVolumeCommand.setSrcDetails(srcDetails); _volumeService.grantAccess(srcVolumeInfo, hostVO, srcVolumeInfo.getDataStore()); _volumeService.revokeAccess(srcVolumeInfo, hostVO, srcVolumeInfo.getDataStore());
VolumeInfo volumeInfo = (VolumeInfo)dataObject; iqn = volumeInfo.get_iScsiName(); long storagePoolId = volumeInfo.getPoolId(); long sfVolumeId = Long.parseLong(volumeInfo.getFolder()); ResizeVolumePayload payload = (ResizeVolumePayload)volumeInfo.getpayload(); long newSize = payload.newSize != null ? payload.newSize : volumeInfo.getSize(); verifySufficientBytesForStoragePool(storagePoolId, volumeInfo.getId(), newSize, payload.newHypervisorSnapshotReserve); Integer hsr = volumeInfo.getHypervisorSnapshotReserve(); mapAttributes.put(SolidFireUtil.CloudStackVolumeId, String.valueOf(volumeInfo.getId())); mapAttributes.put(SolidFireUtil.CloudStackVolumeSize, NumberFormat.getInstance().format(payload.newSize)); newMinIops, newMaxIops, getDefaultBurstIops(storagePoolId, newMaxIops)); VolumeVO volume = volumeDao.findById(volumeInfo.getId());
private void handleCreateTemplateFromManagedVolume(VolumeInfo volumeInfo, TemplateInfo templateInfo, AsyncCompletionCallback<CopyCommandResult> callback) { boolean srcVolumeDetached = volumeInfo.getAttachedVM() == null; if (!ImageFormat.QCOW2.equals(volumeInfo.getFormat())) { throw new CloudRuntimeException("When using managed storage, you can only create a template from a volume on KVM currently."); volumeInfo.processEvent(Event.MigrationRequested); HostVO hostVO = getHost(volumeInfo.getDataCenterId(), HypervisorType.KVM, false); DataStore srcDataStore = volumeInfo.getDataStore(); CopyCommand copyCommand = new CopyCommand(volumeInfo.getTO(), templateInfo.getTO(), primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value()); String msg = "Failed to create template from volume (Volume ID = " + volumeInfo.getId() + ") : "; LOGGER.warn("Error revoking access to volume (Volume ID = " + volumeInfo.getId() + "): " + ex.getMessage(), ex); volumeInfo.processEvent(Event.OperationSuccessed); volumeInfo.processEvent(Event.OperationFailed);
vol.addPayload(payload); String url = ImageStoreUtil.generatePostUploadUrl(ssvmUrlDomain, ep.getPublicAddr(), vol.getUuid()); response.setPostURL(new URL(url)); VolumeDataStoreVO volumeStore = _volumeStoreDao.findByVolume(vol.getId()); assert (volumeStore != null) : "sincle volume is registered, volumestore cannot be null at this stage"; volumeStore.setExtractUrl(url); _volumeStoreDao.persist(volumeStore); response.setId(UUID.fromString(vol.getUuid())); TemplateOrVolumePostUploadCommand command = new TemplateOrVolumePostUploadCommand(vol.getId(), vol.getUuid(), volumeStore.getInstallPath(), cmd.getChecksum(), vol.getType().toString(), vol.getName(), vol.getFormat().toString(), dataObject.getDataStore().getUri(), dataObject.getDataStore().getRole().toString()); command.setLocalPath(volumeStore.getLocalDownloadPath()); command.setMaxUploadSize(_configDao.getValue(Config.MaxUploadVolumeSize.key())); command.setDefaultMaxAccountSecondaryStorage(_configDao.getValue(Config.DefaultMaxAccountSecondaryStorage.key())); command.setAccountId(vol.getAccountId()); Gson gson = new GsonBuilder().create(); String metadata = EncryptionUtil.encodeData(gson.toJson(command), key);
volumeInfo = volFactory.getVolume(volumeInfo.getId(), primaryDataStore); details.put(PrimaryDataStore.STORAGE_PORT, String.valueOf(primaryDataStore.getPort())); details.put(PrimaryDataStore.MANAGED_STORE_TARGET, volumeInfo.get_iScsiName()); details.put(PrimaryDataStore.MANAGED_STORE_TARGET_ROOT_VOLUME, volumeInfo.getName()); details.put(PrimaryDataStore.VOLUME_SIZE, String.valueOf(volumeInfo.getSize())); String errMsg = t.toString(); volumeInfo.processEvent(Event.DestroyRequested);
@Override @DB public SnapshotInfo takeSnapshot(VolumeInfo volume) throws ResourceAllocationException { CreateSnapshotPayload payload = (CreateSnapshotPayload)volume.getpayload(); updateSnapshotPayload(volume.getPoolId(), payload); SnapshotInfo snapshot = snapshotFactory.getSnapshot(snapshotId, volume.getDataStore()); snapshot.addPayload(payload); try { postCreateSnapshot(volume.getId(), snapshotId, payload.getSnapshotPolicyId()); null, null, snapshotStoreRef.getPhysicalSize(), volume.getSize(), snapshot.getClass().getName(), snapshot.getUuid()); _resourceLimitMgr.decrementResourceCount(snapshotOwner.getId(), ResourceType.secondary_storage, new Long(volume.getSize() - snapshotStoreRef.getPhysicalSize())); } catch (Exception e) { s_logger.debug("post process snapshot failed", e); _resourceLimitMgr.decrementResourceCount(snapshotOwner.getId(), ResourceType.secondary_storage, new Long(volume.getSize())); throw cre; } catch (Exception e) { _resourceLimitMgr.decrementResourceCount(snapshotOwner.getId(), ResourceType.secondary_storage, new Long(volume.getSize())); throw new CloudRuntimeException("Failed to create snapshot", e);
@Override public VolumeInfo createVolumeOnPrimaryStorage(VirtualMachine vm, VolumeInfo volume, HypervisorType rootDiskHyperType, StoragePool storagePool) throws NoTransitionException { VirtualMachineTemplate rootDiskTmplt = _entityMgr.findById(VirtualMachineTemplate.class, vm.getTemplateId()); DataCenter dcVO = _entityMgr.findById(DataCenter.class, vm.getDataCenterId()); Pod pod = _entityMgr.findById(Pod.class, storagePool.getPodId()); ServiceOffering svo = _entityMgr.findById(ServiceOffering.class, vm.getServiceOfferingId()); DiskOffering diskVO = _entityMgr.findById(DiskOffering.class, volume.getDiskOfferingId()); Long clusterId = storagePool.getClusterId(); VolumeInfo vol = null; if (volume.getState() == Volume.State.Allocated) { vol = createVolume(volume, vm, rootDiskTmplt, dcVO, pod, clusterId, svo, diskVO, new ArrayList<StoragePool>(), volume.getSize(), rootDiskHyperType); } else if (volume.getState() == Volume.State.Uploaded) { vol = copyVolume(storagePool, volume, vm, rootDiskTmplt, dcVO, pod, diskVO, svo, rootDiskHyperType); if (vol != null) { // Moving of Volume is successful, decrement the volume resource count from secondary for an account and increment it into primary storage under same account. _resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.secondary_storage, volume.getSize()); _resourceLimitMgr.incrementResourceCount(volume.getAccountId(), ResourceType.primary_storage, volume.getSize()); } } if (vol == null) { throw new CloudRuntimeException("Volume shouldn't be null " + volume.getId()); } VolumeVO volVO = _volsDao.findById(vol.getId()); if (volVO.getFormat() == null) { volVO.setFormat(getSupportedImageFormatForCluster(rootDiskHyperType)); } _volsDao.update(volVO.getId(), volVO); return volFactory.getVolume(volVO.getId()); }