/** * Performs the validations required for replacing the disk offering while migrating the volume of storage. If no new disk offering is provided, we do not execute any validation. * If a disk offering is informed, we then proceed with the following checks. * <ul> * <li>We check if the given volume is of ROOT type. We cannot change the disk offering of a ROOT volume. Therefore, we thrown an {@link InvalidParameterValueException}; * <li>We the disk is being migrated to shared storage and the new disk offering is for local storage (or vice versa), we throw an {@link InvalidParameterValueException}. Bear in mind that we are validating only the new disk offering. If none is provided we can override the current disk offering. This means, placing a volume with shared disk offering in local storage and vice versa; * <li>We then proceed checking the target storage pool supports the new disk offering {@link #doesTargetStorageSupportNewDiskOffering(StoragePool, DiskOfferingVO)}. * </ul> * * If all of the above validations pass, we check if the size of the new disk offering is different from the volume. If it is, we log a warning message. */ protected void validateConditionsToReplaceDiskOfferingOfVolume(VolumeVO volume, DiskOfferingVO newDiskOffering, StoragePool destPool) { if (newDiskOffering == null) { return; } if ((destPool.isShared() && newDiskOffering.isUseLocalStorage()) || destPool.isLocal() && newDiskOffering.isShared()) { throw new InvalidParameterValueException("You cannot move the volume to a shared storage and assing a disk offering for local storage and vice versa."); } if (!doesTargetStorageSupportDiskOffering(destPool, newDiskOffering)) { throw new InvalidParameterValueException(String.format("Target Storage [id=%s] tags [%s] does not match new disk offering [id=%s] tags [%s].", destPool.getUuid(), getStoragePoolTags(destPool), newDiskOffering.getUuid(), newDiskOffering.getTags())); } if (volume.getSize() != newDiskOffering.getDiskSize()) { DiskOfferingVO oldDiskOffering = this._diskOfferingDao.findById(volume.getDiskOfferingId()); s_logger.warn(String.format( "You are migrating a volume [id=%s] and changing the disk offering[from id=%s to id=%s] to reflect this migration. However, the sizes of the volume and the new disk offering are different.", volume.getUuid(), oldDiskOffering.getUuid(), newDiskOffering.getUuid())); } s_logger.info(String.format("Changing disk offering to [uuid=%s] while migrating volume [uuid=%s, name=%s].", newDiskOffering.getUuid(), volume.getUuid(), volume.getName())); }
protected DiskOfferingDaoImpl() { DomainIdSearch = createSearchBuilder(); DomainIdSearch.and("domainId", DomainIdSearch.entity().getDomainId(), SearchCriteria.Op.EQ); DomainIdSearch.and("removed", DomainIdSearch.entity().getRemoved(), SearchCriteria.Op.NULL); DomainIdSearch.done(); PrivateDiskOfferingSearch = createSearchBuilder(); PrivateDiskOfferingSearch.and("diskSize", PrivateDiskOfferingSearch.entity().getDiskSize(), SearchCriteria.Op.EQ); PrivateDiskOfferingSearch.done(); PublicDiskOfferingSearch = createSearchBuilder(); PublicDiskOfferingSearch.and("domainId", PublicDiskOfferingSearch.entity().getDomainId(), SearchCriteria.Op.NULL); PublicDiskOfferingSearch.and("system", PublicDiskOfferingSearch.entity().isSystemUse(), SearchCriteria.Op.EQ); PublicDiskOfferingSearch.and("removed", PublicDiskOfferingSearch.entity().getRemoved(), SearchCriteria.Op.NULL); PublicDiskOfferingSearch.done(); UniqueNameSearch = createSearchBuilder(); UniqueNameSearch.and("name", UniqueNameSearch.entity().getUniqueName(), SearchCriteria.Op.EQ); UniqueNameSearch.done(); _typeAttr = _allAttributes.get("type"); }
public static DiskOfferingVO findDiskOfferingById(Long diskOfferingId) { DiskOfferingVO off = s_diskOfferingDao.findByIdIncludingRemoved(diskOfferingId); if (off.getType() == DiskOfferingVO.Type.Disk) { return off; } return null; }
private DiskOfferingVO createdefaultDiskOffering(Long domainId, String name, String description, ProvisioningType provisioningType, int numGibibytes, String tags, boolean isCustomized, boolean isSystemUse) { long diskSize = numGibibytes; diskSize = diskSize * 1024 * 1024 * 1024; tags = cleanupTags(tags); DiskOfferingVO newDiskOffering = new DiskOfferingVO(domainId, name, description, provisioningType, diskSize, tags, isCustomized, null, null, null); newDiskOffering.setUniqueName("Cloud.Com-" + name); // leaving the above reference to cloud.com in as it is an identifyer and has no real world relevance newDiskOffering.setSystemUse(isSystemUse); newDiskOffering = _diskOfferingDao.persistDeafultDiskOffering(newDiskOffering); return newDiskOffering; }
tags = newTags.toString(); DiskOfferingVO diskOffering = new DiskOfferingVO(domainId, name, displayText, provisioningType, diskSpace, tags, false, null, null, null); diskOffering.setUseLocalStorage(local); diskOffering.setBytesReadRate(bytesReadRate); Long bytesWriteRate = Long.parseLong(_currentObjectParams.get("bytesWriteRate")); if (bytesWriteRate != null && (bytesWriteRate > 0)) diskOffering.setBytesWriteRate(bytesWriteRate); Long iopsReadRate = Long.parseLong(_currentObjectParams.get("iopsReadRate")); if (iopsReadRate != null && (iopsReadRate > 0)) diskOffering.setIopsReadRate(iopsReadRate); Long iopsWriteRate = Long.parseLong(_currentObjectParams.get("iopsWriteRate")); if (iopsWriteRate != null && (iopsWriteRate > 0)) diskOffering.setIopsWriteRate(iopsWriteRate);
if (!diskOffering.isCustomized() && !volume.getVolumeType().equals(Volume.Type.ROOT)) { throw new InvalidParameterValueException("To change a volume's size without providing a new disk offering, its current disk offering must be " + "customizable or it must be a root volume (if providing a disk offering, make sure it is different from the current disk offering)."); if (!volume.getVolumeType().equals(Volume.Type.ROOT) && (diskOffering.isCustomizedIops() == null || !diskOffering.isCustomizedIops())) { throw new InvalidParameterValueException("The current disk offering does not support customization of the 'Min IOPS' parameter."); if (!volume.getVolumeType().equals(Volume.Type.ROOT) && (diskOffering.isCustomizedIops() == null || !diskOffering.isCustomizedIops())) { throw new InvalidParameterValueException("The current disk offering does not support customization of the 'Max IOPS' parameter."); if (newDiskOffering.getRemoved() != null) { throw new InvalidParameterValueException("Requested disk offering has been removed."); if (!DiskOfferingVO.Type.Disk.equals(newDiskOffering.getType())) { throw new InvalidParameterValueException("Requested disk offering type is invalid."); if (diskOffering.getTags() != null) { if (!StringUtils.areTagsEqual(diskOffering.getTags(), newDiskOffering.getTags())) { throw new InvalidParameterValueException("The tags on the new and old disk offerings must match."); } else if (newDiskOffering.getTags() != null) { throw new InvalidParameterValueException("There are no tags on the current disk offering. The new disk offering needs to have no tags, as well."); if (newDiskOffering.getDomainId() != null) { if (newDiskOffering.isCustomized()) { newSize = cmd.getSize(); newSize = newDiskOffering.getDiskSize();
if ((diskOffering == null) || diskOffering.getRemoved() != null || !DiskOfferingVO.Type.Disk.equals(diskOffering.getType())) { throw new InvalidParameterValueException("Please specify a valid disk offering."); if (diskOffering.isCustomized()) { if (size == null) { throw new InvalidParameterValueException("This disk offering requires a custom size specified"); if (!diskOffering.isCustomized() && size != null) { throw new InvalidParameterValueException("This disk offering does not allow custom size"); if (diskOffering.getDomainId() == null) { if (diskOffering.getDiskSize() > 0) { size = diskOffering.getDiskSize(); Boolean isCustomizedIops = diskOffering.isCustomizedIops(); minIops = diskOffering.getMinIops(); maxIops = diskOffering.getMaxIops(); provisioningType = diskOffering.getProvisioningType(); maxIops = snapshotCheck.getMaxIops(); provisioningType = diskOffering.getProvisioningType(); if (!zone.isLocalStorageEnabled() && diskOffering.isUseLocalStorage()) { throw new InvalidParameterValueException("Zone is not configured to use local storage but volume's disk offering " + diskOffering.getName() + " uses it");
final DiskOfferingVO newDiskOffering = new DiskOfferingVO(domainId, name, description, typedProvisioningType, diskSize, tags, isCustomized, isCustomizedIops, minIops, maxIops); newDiskOffering.setUseLocalStorage(localStorageRequired); newDiskOffering.setDisplayOffering(isDisplayOfferingEnabled); newDiskOffering.setBytesReadRate(bytesReadRate); newDiskOffering.setBytesWriteRate(bytesWriteRate); newDiskOffering.setIopsReadRate(iopsReadRate); newDiskOffering.setIopsWriteRate(iopsWriteRate); newDiskOffering.setHypervisorSnapshotReserve(hypervisorSnapshotReserve); CallContext.current().setEventDetails("Disk offering id=" + newDiskOffering.getId()); final DiskOfferingVO offering = _diskOfferingDao.persist(newDiskOffering); if (offering != null) { CallContext.current().setEventDetails("Disk offering id=" + newDiskOffering.getId()); return offering; } else {
if ((diskOffering == null) || diskOffering.getRemoved() != null || !DiskOfferingVO.Type.Disk.equals(diskOffering.getType())) { throw new InvalidParameterValueException("Please specify a valid disk offering."); if (!diskOffering.isCustomized()) { throw new InvalidParameterValueException("Please specify a custom sized disk offering."); if (diskOffering.getDomainId() == null) {
if (diskOffering.getDiskSize() == 0) { size = diskSize; if (size == null) { rootDiskOfferingInfo.setSize(size); if (diskOffering.isCustomizedIops() != null && diskOffering.isCustomizedIops()) { Map<String, String> userVmDetails = _userVmDetailsDao.listDetailsKeyPairs(vm.getId());
DiskOfferingVO diskOfferingVO = _diskOfferingDao.findByUniqueName("Cloud.com-Custom"); if (diskOfferingVO != null) { long defaultDiskOfferingId = diskOfferingVO.getId(); volume.setDiskOfferingId(defaultDiskOfferingId); Boolean isCustomizedIops = diskOfferingVO != null && diskOfferingVO.isCustomizedIops() != null ? diskOfferingVO.isCustomizedIops() : false; volume.setMinIops(diskOfferingVO.getMinIops()); volume.setMaxIops(diskOfferingVO.getMaxIops());
diskOffering.setName(name); diskOffering.setDisplayText(displayText); diskOffering.setSortKey(sortKey); diskOffering.setDisplayOffering(displayDiskOffering); CallContext.current().setEventDetails("Disk offering id=" + diskOffering.getId()); return _diskOfferingDao.findById(diskOfferingId); } else {
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()); }
if (offering.getDomainId() == null) { throw new InvalidParameterValueException("Unable to delete public disk offering by id " + userId + " because it is domain-admin"); if (! _domainDao.isChildDomain(account.getDomainId(), offering.getDomainId() )) { throw new InvalidParameterValueException("Unable to delete disk offering by another domain admin with id " + userId); offering.setState(DiskOffering.State.Inactive); if (_diskOfferingDao.update(offering.getId(), offering)) { CallContext.current().setEventDetails("Disk offering id=" + diskOfferingId); return true;
@Override @Transient public String[] getTagsArray() { String tags = getTags(); if (tags == null || tags.isEmpty()) { return new String[0]; } return tags.split(","); }
rootVolumeOfVm.setDiskOfferingId(newROOTDiskOffering.getId()); ResizeVolumeCmd resizeVolumeCmd = new ResizeVolumeCmd(rootVolumeOfVm.getId(), newROOTDiskOffering.getMinIops(), newROOTDiskOffering.getMaxIops());
if (diskOffering != null && diskOffering.isCustomized()) { if (diskSize == null) { throw new InvalidParameterValueException("This disk offering requires a custom size specified"); size += _diskOfferingDao.findById(diskOfferingId).getDiskSize();
private Volume orchestrateMigrateVolume(VolumeVO volume, StoragePool destPool, boolean liveMigrateVolume, DiskOfferingVO newDiskOffering) { Volume newVol = null; try { if (liveMigrateVolume) { newVol = liveMigrateVolume(volume, destPool); } else { newVol = _volumeMgr.migrateVolume(volume, destPool); } if (newDiskOffering != null) { _volsDao.updateDiskOffering(newVol.getId(), newDiskOffering.getId()); } } catch (StorageUnavailableException e) { s_logger.debug("Failed to migrate volume", e); throw new CloudRuntimeException(e.getMessage()); } catch (Exception e) { s_logger.debug("Failed to migrate volume", e); throw new CloudRuntimeException(e.getMessage()); } return newVol; }
/** * Retrieves the new disk offering UUID that might be sent to replace the current one in the volume being migrated. * If no disk offering UUID is provided we return null. Otherwise, we perform the following checks. * <ul> * <li>Is the disk offering UUID entered valid? If not, an {@link InvalidParameterValueException} is thrown; * <li>If the disk offering was already removed, we thrown an {@link InvalidParameterValueException} is thrown; * <li>We then check if the user executing the operation has access to the given disk offering. * </ul> * * If all checks pass, we move forward returning the disk offering object. */ private DiskOfferingVO retrieveAndValidateNewDiskOffering(MigrateVolumeCmd cmd) { String newDiskOfferingUuid = cmd.getNewDiskOfferingUuid(); if (org.apache.commons.lang.StringUtils.isBlank(newDiskOfferingUuid)) { return null; } DiskOfferingVO newDiskOffering = _diskOfferingDao.findByUuid(newDiskOfferingUuid); if (newDiskOffering == null) { throw new InvalidParameterValueException(String.format("The disk offering informed is not valid [id=%s].", newDiskOfferingUuid)); } if (newDiskOffering.getRemoved() != null) { throw new InvalidParameterValueException(String.format("We cannot assign a removed disk offering [id=%s] to a volume. ", newDiskOffering.getUuid())); } Account caller = CallContext.current().getCallingAccount(); _accountMgr.checkAccess(caller, newDiskOffering); return newDiskOffering; }
@Override public Long getBytesReadRate() { DiskOfferingVO diskOfferingVO = getDiskOfferingVO(); if (diskOfferingVO != null) { return diskOfferingVO.getBytesReadRate(); } return null; }