Search in sources :

Example 56 with Volume

use of com.cloud.storage.Volume 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 57 with Volume

use of com.cloud.storage.Volume 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 58 with Volume

use of com.cloud.storage.Volume in project cloudstack by apache.

the class UploadVolumeCmdByAdmin method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    Volume volume = _volumeService.uploadVolume(this);
    if (volume != null) {
        VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, volume);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to upload volume");
    }
}
Also used : VolumeResponse(org.apache.cloudstack.api.response.VolumeResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) Volume(com.cloud.storage.Volume)

Example 59 with Volume

use of com.cloud.storage.Volume in project cloudstack by apache.

the class AttachVolumeCmdByAdmin method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("Volume Id: " + getId() + " VmId: " + getVirtualMachineId());
    Volume result = _volumeService.attachVolumeToVM(this);
    if (result != null) {
        VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to attach volume");
    }
}
Also used : VolumeResponse(org.apache.cloudstack.api.response.VolumeResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) Volume(com.cloud.storage.Volume)

Example 60 with Volume

use of com.cloud.storage.Volume in project cloudstack by apache.

the class DetachVolumeCmdByAdmin method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("Volume Id: " + getId() + " VmId: " + getVirtualMachineId());
    Volume result = _volumeService.detachVolumeFromVM(this);
    if (result != null) {
        VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, result);
        response.setResponseName("volume");
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to detach volume");
    }
}
Also used : VolumeResponse(org.apache.cloudstack.api.response.VolumeResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) Volume(com.cloud.storage.Volume)

Aggregations

Volume (com.cloud.storage.Volume)70 StoragePool (com.cloud.storage.StoragePool)21 ServerApiException (org.apache.cloudstack.api.ServerApiException)16 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)15 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)15 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)14 VolumeResponse (org.apache.cloudstack.api.response.VolumeResponse)14 ArrayList (java.util.ArrayList)12 Account (com.cloud.user.Account)11 VolumeVO (com.cloud.storage.VolumeVO)10 DiskProfile (com.cloud.vm.DiskProfile)10 StoragePoolAllocator (org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator)10 Test (org.junit.Test)10 DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)9 HashMap (java.util.HashMap)9 DeploymentPlan (com.cloud.deploy.DeploymentPlan)8 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)8 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)8 Project (com.cloud.projects.Project)7 VmWorkAttachVolume (com.cloud.vm.VmWorkAttachVolume)7