Search in sources :

Example 1 with InsufficientStorageCapacityException

use of com.cloud.exception.InsufficientStorageCapacityException in project cloudstack by apache.

the class VolumeOrchestrator method prepare.

@Override
public void prepare(VirtualMachineProfile vm, DeployDestination dest) throws StorageUnavailableException, InsufficientStorageCapacityException, ConcurrentOperationException, StorageAccessException {
    if (dest == null) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("DeployDestination cannot be null, cannot prepare Volumes for the vm: " + vm);
        }
        throw new CloudRuntimeException("Unable to prepare Volume for vm because DeployDestination is null, vm:" + vm);
    }
    // don't allow to start vm that doesn't have a root volume
    if (_volsDao.findByInstanceAndType(vm.getId(), Volume.Type.ROOT).isEmpty()) {
        throw new CloudRuntimeException("Unable to prepare volumes for vm as ROOT volume is missing");
    }
    List<VolumeVO> vols = _volsDao.findUsableVolumesForInstance(vm.getId());
    List<VolumeTask> tasks = getTasks(vols, dest.getStorageForDisks(), vm);
    Volume vol = null;
    StoragePool pool;
    for (VolumeTask task : tasks) {
        if (task.type == VolumeTaskType.NOP) {
            vol = task.volume;
            pool = (StoragePool) dataStoreMgr.getDataStore(task.pool.getId(), DataStoreRole.Primary);
            // cluster. In that case, make sure that the volume is in the right access group.
            if (pool.isManaged()) {
                Host lastHost = _hostDao.findById(vm.getVirtualMachine().getLastHostId());
                Host host = _hostDao.findById(vm.getVirtualMachine().getHostId());
                long lastClusterId = lastHost == null || lastHost.getClusterId() == null ? -1 : lastHost.getClusterId();
                long clusterId = host == null || host.getClusterId() == null ? -1 : host.getClusterId();
                if (lastClusterId != clusterId) {
                    if (lastHost != null) {
                        storageMgr.removeStoragePoolFromCluster(lastHost.getId(), vol.get_iScsiName(), pool);
                        DataStore storagePool = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
                        volService.revokeAccess(volFactory.getVolume(vol.getId()), lastHost, storagePool);
                    }
                    try {
                        volService.grantAccess(volFactory.getVolume(vol.getId()), host, (DataStore) pool);
                    } catch (Exception e) {
                        throw new StorageAccessException("Unable to grant access to volume: " + vol.getId() + " on host: " + host.getId());
                    }
                } else {
                    // This might impact other managed storages, grant access for PowerFlex storage pool only
                    if (pool.getPoolType() == Storage.StoragePoolType.PowerFlex) {
                        try {
                            volService.grantAccess(volFactory.getVolume(vol.getId()), host, (DataStore) pool);
                        } catch (Exception e) {
                            throw new StorageAccessException("Unable to grant access to volume: " + vol.getId() + " on host: " + host.getId());
                        }
                    }
                }
            }
        } else if (task.type == VolumeTaskType.MIGRATE) {
            pool = (StoragePool) dataStoreMgr.getDataStore(task.pool.getId(), DataStoreRole.Primary);
            vol = migrateVolume(task.volume, pool);
        } else if (task.type == VolumeTaskType.RECREATE) {
            Pair<VolumeVO, DataStore> result = recreateVolume(task.volume, vm, dest);
            pool = (StoragePool) dataStoreMgr.getDataStore(result.second().getId(), DataStoreRole.Primary);
            vol = result.first();
        }
        VolumeInfo volumeInfo = volFactory.getVolume(vol.getId());
        DataTO volTO = volumeInfo.getTO();
        DiskTO disk = storageMgr.getDiskWithThrottling(volTO, vol.getVolumeType(), vol.getDeviceId(), vol.getPath(), vm.getServiceOfferingId(), vol.getDiskOfferingId());
        DataStore dataStore = dataStoreMgr.getDataStore(vol.getPoolId(), DataStoreRole.Primary);
        disk.setDetails(getDetails(volumeInfo, dataStore));
        vm.addDisk(disk);
        // If hypervisor is vSphere, check for clone type setting.
        if (vm.getHypervisorType().equals(HypervisorType.VMware)) {
            // retrieve clone flag.
            UserVmCloneType cloneType = UserVmCloneType.linked;
            Boolean value = CapacityManager.VmwareCreateCloneFull.valueIn(vol.getPoolId());
            if (value != null && value) {
                cloneType = UserVmCloneType.full;
            }
            UserVmCloneSettingVO cloneSettingVO = _vmCloneSettingDao.findByVmId(vm.getId());
            if (cloneSettingVO != null) {
                if (!cloneSettingVO.getCloneType().equals(cloneType.toString())) {
                    cloneSettingVO.setCloneType(cloneType.toString());
                    _vmCloneSettingDao.update(cloneSettingVO.getId(), cloneSettingVO);
                }
            } else {
                UserVmCloneSettingVO vmCloneSettingVO = new UserVmCloneSettingVO(vm.getId(), cloneType.toString());
                _vmCloneSettingDao.persist(vmCloneSettingVO);
            }
        }
    }
}
Also used : StoragePool(com.cloud.storage.StoragePool) Host(com.cloud.host.Host) StorageAccessException(com.cloud.exception.StorageAccessException) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) UserVmCloneSettingVO(com.cloud.vm.UserVmCloneSettingVO) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) InsufficientStorageCapacityException(com.cloud.exception.InsufficientStorageCapacityException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StorageAccessException(com.cloud.exception.StorageAccessException) ExecutionException(java.util.concurrent.ExecutionException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ConfigurationException(javax.naming.ConfigurationException) DataTO(com.cloud.agent.api.to.DataTO) VolumeVO(com.cloud.storage.VolumeVO) VmWorkMigrateVolume(com.cloud.vm.VmWorkMigrateVolume) VmWorkAttachVolume(com.cloud.vm.VmWorkAttachVolume) Volume(com.cloud.storage.Volume) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) DiskTO(com.cloud.agent.api.to.DiskTO)

Aggregations

DataTO (com.cloud.agent.api.to.DataTO)1 DiskTO (com.cloud.agent.api.to.DiskTO)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 InsufficientStorageCapacityException (com.cloud.exception.InsufficientStorageCapacityException)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 StorageAccessException (com.cloud.exception.StorageAccessException)1 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)1 Host (com.cloud.host.Host)1 StoragePool (com.cloud.storage.StoragePool)1 Volume (com.cloud.storage.Volume)1 VolumeVO (com.cloud.storage.VolumeVO)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)1 UserVmCloneSettingVO (com.cloud.vm.UserVmCloneSettingVO)1 VmWorkAttachVolume (com.cloud.vm.VmWorkAttachVolume)1 VmWorkMigrateVolume (com.cloud.vm.VmWorkMigrateVolume)1 ExecutionException (java.util.concurrent.ExecutionException)1 ConfigurationException (javax.naming.ConfigurationException)1 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)1 PrimaryDataStore (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)1