Search in sources :

Example 11 with DiskOffering

use of com.cloud.offering.DiskOffering in project cloudstack by apache.

the class VolumeOrchestrator method getTasks.

private List<VolumeTask> getTasks(List<VolumeVO> vols, Map<Volume, StoragePool> destVols, VirtualMachineProfile vm) throws StorageUnavailableException {
    boolean recreate = RecreatableSystemVmEnabled.value();
    List<VolumeTask> tasks = new ArrayList<VolumeTask>();
    for (VolumeVO vol : vols) {
        StoragePoolVO assignedPool = null;
        if (destVols != null) {
            StoragePool pool = destVols.get(vol);
            if (pool != null) {
                assignedPool = _storagePoolDao.findById(pool.getId());
            }
        }
        if (assignedPool == null && recreate) {
            assignedPool = _storagePoolDao.findById(vol.getPoolId());
        }
        if (assignedPool != null) {
            Volume.State state = vol.getState();
            if (state == Volume.State.Allocated || state == Volume.State.Creating) {
                VolumeTask task = new VolumeTask(VolumeTaskType.RECREATE, vol, null);
                tasks.add(task);
            } else {
                if (vol.isRecreatable()) {
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug("Volume " + vol + " will be recreated on storage pool " + assignedPool + " assigned by deploymentPlanner");
                    }
                    VolumeTask task = new VolumeTask(VolumeTaskType.RECREATE, vol, null);
                    tasks.add(task);
                } else {
                    if (assignedPool.getId() != vol.getPoolId()) {
                        if (s_logger.isDebugEnabled()) {
                            s_logger.debug("Mismatch in storage pool " + assignedPool + " assigned by deploymentPlanner and the one associated with volume " + vol);
                        }
                        DiskOffering diskOffering = _entityMgr.findById(DiskOffering.class, vol.getDiskOfferingId());
                        if (diskOffering.getUseLocalStorage()) {
                            // Currently migration of local volume is not supported so bail out
                            if (s_logger.isDebugEnabled()) {
                                s_logger.debug("Local volume " + vol + " cannot be recreated on storagepool " + assignedPool + " assigned by deploymentPlanner");
                            }
                            throw new CloudRuntimeException("Local volume " + vol + " cannot be recreated on storagepool " + assignedPool + " assigned by deploymentPlanner");
                        } else {
                            //Check if storage migration is enabled in config
                            Boolean isHAOperation = (Boolean) vm.getParameter(VirtualMachineProfile.Param.HaOperation);
                            Boolean storageMigrationEnabled = true;
                            if (isHAOperation != null && isHAOperation) {
                                storageMigrationEnabled = StorageHAMigrationEnabled.value();
                            } else {
                                storageMigrationEnabled = StorageMigrationEnabled.value();
                            }
                            if (storageMigrationEnabled) {
                                if (s_logger.isDebugEnabled()) {
                                    s_logger.debug("Shared volume " + vol + " will be migrated on storage pool " + assignedPool + " assigned by deploymentPlanner");
                                }
                                VolumeTask task = new VolumeTask(VolumeTaskType.MIGRATE, vol, assignedPool);
                                tasks.add(task);
                            } else {
                                throw new CloudRuntimeException("Cannot migrate volumes. Volume Migration is disabled");
                            }
                        }
                    } else {
                        StoragePoolVO pool = _storagePoolDao.findById(vol.getPoolId());
                        VolumeTask task = new VolumeTask(VolumeTaskType.NOP, vol, pool);
                        tasks.add(task);
                    }
                }
            }
        } else {
            if (vol.getPoolId() == null) {
                throw new StorageUnavailableException("Volume has no pool associate and also no storage pool assigned in DeployDestination, Unable to create " + vol, Volume.class, vol.getId());
            }
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("No need to recreate the volume: " + vol + ", since it already has a pool assigned: " + vol.getPoolId() + ", adding disk to VM");
            }
            StoragePoolVO pool = _storagePoolDao.findById(vol.getPoolId());
            VolumeTask task = new VolumeTask(VolumeTaskType.NOP, vol, pool);
            tasks.add(task);
        }
    }
    return tasks;
}
Also used : StoragePool(com.cloud.storage.StoragePool) DiskOffering(com.cloud.offering.DiskOffering) ArrayList(java.util.ArrayList) VolumeVO(com.cloud.storage.VolumeVO) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) VmWorkMigrateVolume(com.cloud.vm.VmWorkMigrateVolume) VmWorkAttachVolume(com.cloud.vm.VmWorkAttachVolume) Volume(com.cloud.storage.Volume) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO)

Example 12 with DiskOffering

use of com.cloud.offering.DiskOffering in project cloudstack by apache.

the class VolumeOrchestrator method moveVolume.

@Override
public VolumeInfo moveVolume(VolumeInfo volume, long destPoolDcId, Long destPoolPodId, Long destPoolClusterId, HypervisorType dataDiskHyperType) throws ConcurrentOperationException, StorageUnavailableException {
    // Find a destination storage pool with the specified criteria
    DiskOffering diskOffering = _entityMgr.findById(DiskOffering.class, volume.getDiskOfferingId());
    DiskProfile dskCh = new DiskProfile(volume.getId(), volume.getVolumeType(), volume.getName(), diskOffering.getId(), diskOffering.getDiskSize(), diskOffering.getTagsArray(), diskOffering.getUseLocalStorage(), diskOffering.isRecreatable(), null);
    dskCh.setHyperType(dataDiskHyperType);
    storageMgr.setDiskProfileThrottling(dskCh, null, diskOffering);
    DataCenter destPoolDataCenter = _entityMgr.findById(DataCenter.class, destPoolDcId);
    Pod destPoolPod = _entityMgr.findById(Pod.class, destPoolPodId);
    StoragePool destPool = findStoragePool(dskCh, destPoolDataCenter, destPoolPod, destPoolClusterId, null, null, new HashSet<StoragePool>());
    if (destPool == null) {
        throw new CloudRuntimeException("Failed to find a storage pool with enough capacity to move the volume to.");
    }
    Volume newVol = migrateVolume(volume, destPool);
    return volFactory.getVolume(newVol.getId());
}
Also used : DiskOffering(com.cloud.offering.DiskOffering) DataCenter(com.cloud.dc.DataCenter) StoragePool(com.cloud.storage.StoragePool) Pod(com.cloud.dc.Pod) VmWorkMigrateVolume(com.cloud.vm.VmWorkMigrateVolume) VmWorkAttachVolume(com.cloud.vm.VmWorkAttachVolume) Volume(com.cloud.storage.Volume) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DiskProfile(com.cloud.vm.DiskProfile)

Example 13 with DiskOffering

use of com.cloud.offering.DiskOffering in project cloudstack by apache.

the class VolumeOrchestrator method createVolumeOnPrimaryStorage.

@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());
}
Also used : DataCenter(com.cloud.dc.DataCenter) DiskOffering(com.cloud.offering.DiskOffering) VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) Pod(com.cloud.dc.Pod) VolumeVO(com.cloud.storage.VolumeVO) ServiceOffering(com.cloud.offering.ServiceOffering) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)

Example 14 with DiskOffering

use of com.cloud.offering.DiskOffering in project cloudstack by apache.

the class CreateDiskOfferingCmd method execute.

@Override
public void execute() {
    DiskOffering offering = _configService.createDiskOffering(this);
    if (offering != null) {
        DiskOfferingResponse response = _responseGenerator.createDiskOfferingResponse(offering);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create disk offering");
    }
}
Also used : DiskOffering(com.cloud.offering.DiskOffering) ServerApiException(org.apache.cloudstack.api.ServerApiException) DiskOfferingResponse(org.apache.cloudstack.api.response.DiskOfferingResponse)

Aggregations

DiskOffering (com.cloud.offering.DiskOffering)14 DataCenter (com.cloud.dc.DataCenter)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)4 ServiceOffering (com.cloud.offering.ServiceOffering)4 StoragePool (com.cloud.storage.StoragePool)4 VolumeVO (com.cloud.storage.VolumeVO)4 Account (com.cloud.user.Account)4 ServerApiException (com.cloud.api.ServerApiException)3 DiskOfferingResponse (com.cloud.api.response.DiskOfferingResponse)3 Pod (com.cloud.dc.Pod)3 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)3 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)3 ArrayList (java.util.ArrayList)3 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)3 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)3 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)2 Host (com.cloud.host.Host)2 Volume (com.cloud.storage.Volume)2 UserVm (com.cloud.uservm.UserVm)2