Search in sources :

Example 31 with VolumeInfo

use of com.cloud.engine.subsystem.api.storage.VolumeInfo in project cosmic by MissionCriticalCloud.

the class VolumeOrchestrator method prepare.

@Override
public void prepare(final VirtualMachineProfile vm, final DeployDestination dest) throws StorageUnavailableException, InsufficientStorageCapacityException, ConcurrentOperationException {
    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");
    }
    final List<VolumeVO> vols = _volsDao.findUsableVolumesForInstance(vm.getId());
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Checking if we need to prepare " + vols.size() + " volumes for " + vm);
    }
    final List<VolumeTask> tasks = getTasks(vols, dest.getStorageForDisks(), vm);
    Volume vol = null;
    StoragePool pool = null;
    for (final VolumeTask task : tasks) {
        if (task.type == VolumeTaskType.NOP) {
            pool = (StoragePool) dataStoreMgr.getDataStore(task.pool.getId(), DataStoreRole.Primary);
            vol = task.volume;
        } 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) {
            final Pair<VolumeVO, DataStore> result = recreateVolume(task.volume, vm, dest);
            pool = (StoragePool) dataStoreMgr.getDataStore(result.second().getId(), DataStoreRole.Primary);
            vol = result.first();
        }
        final DataTO volumeTO = volFactory.getVolume(vol.getId()).getTO();
        final DiskTO disk = new DiskTO(volumeTO, vol.getDeviceId(), vol.getPath(), vol.getVolumeType());
        final VolumeInfo volumeInfo = volFactory.getVolume(vol.getId());
        final DataStore dataStore = dataStoreMgr.getDataStore(vol.getPoolId(), DataStoreRole.Primary);
        disk.setDetails(getDetails(volumeInfo, dataStore));
        vm.addDisk(disk);
    }
}
Also used : StoragePool(com.cloud.storage.StoragePool) 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) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) DiskTO(com.cloud.agent.api.to.DiskTO)

Example 32 with VolumeInfo

use of com.cloud.engine.subsystem.api.storage.VolumeInfo in project cosmic by MissionCriticalCloud.

the class VolumeOrchestrator method revokeAccess.

@Override
public void revokeAccess(final long vmId, final long hostId) {
    final HostVO host = _hostDao.findById(hostId);
    final List<VolumeVO> volumesForVm = _volsDao.findByInstance(vmId);
    if (volumesForVm != null) {
        for (final VolumeVO volumeForVm : volumesForVm) {
            final VolumeInfo volumeInfo = volFactory.getVolume(volumeForVm.getId());
            // pool id can be null for the VM's volumes in Allocated state
            if (volumeForVm.getPoolId() != null) {
                final DataStore dataStore = dataStoreMgr.getDataStore(volumeForVm.getPoolId(), DataStoreRole.Primary);
                volService.revokeAccess(volumeInfo, host, dataStore);
            }
        }
    }
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) HostVO(com.cloud.host.HostVO)

Example 33 with VolumeInfo

use of com.cloud.engine.subsystem.api.storage.VolumeInfo in project cosmic by MissionCriticalCloud.

the class VolumeOrchestrator method liveMigrateVolume.

@DB
protected Volume liveMigrateVolume(final Volume volume, final StoragePool destPool) {
    final VolumeInfo vol = volFactory.getVolume(volume.getId());
    final AsyncCallFuture<VolumeService.VolumeApiResult> future = volService.migrateVolume(vol, (DataStore) destPool);
    try {
        final VolumeService.VolumeApiResult result = future.get();
        if (result.isFailed()) {
            s_logger.debug("migrate volume failed:" + result.getResult());
            return null;
        }
        return result.getVolume();
    } catch (final InterruptedException e) {
        s_logger.debug("migrate volume failed", e);
        return null;
    } catch (final ExecutionException e) {
        s_logger.debug("migrate volume failed", e);
        return null;
    }
}
Also used : VolumeService(com.cloud.engine.subsystem.api.storage.VolumeService) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) ExecutionException(java.util.concurrent.ExecutionException) DB(com.cloud.utils.db.DB)

Example 34 with VolumeInfo

use of com.cloud.engine.subsystem.api.storage.VolumeInfo in project cosmic by MissionCriticalCloud.

the class VolumeOrchestrator method prepareForMigration.

@Override
public void prepareForMigration(final VirtualMachineProfile vm, final DeployDestination dest) {
    final List<VolumeVO> vols = _volsDao.findUsableVolumesForInstance(vm.getId());
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Preparing " + vols.size() + " volumes for " + vm);
    }
    for (final VolumeVO vol : vols) {
        final DataTO volTO = volFactory.getVolume(vol.getId()).getTO();
        final DiskTO disk = new DiskTO(volTO, vol.getDeviceId(), vol.getPath(), vol.getVolumeType());
        final VolumeInfo volumeInfo = volFactory.getVolume(vol.getId());
        final DataStore dataStore = dataStoreMgr.getDataStore(vol.getPoolId(), DataStoreRole.Primary);
        disk.setDetails(getDetails(volumeInfo, dataStore));
        vm.addDisk(disk);
    }
    // if (vm.getType() == VirtualMachine.Type.User && vm.getTemplate().getFormat() == ImageFormat.ISO) {
    if (vm.getType() == VirtualMachine.Type.User) {
        _tmpltMgr.prepareIsoForVmProfile(vm);
    // DataTO dataTO = tmplFactory.getTemplate(vm.getTemplate().getId(), DataStoreRole.Image, vm.getVirtualMachine().getDataCenterId()).getTO();
    // DiskTO iso = new DiskTO(dataTO, 3L, null, Volume.Type.ISO);
    // vm.addDisk(iso);
    }
}
Also used : DataTO(com.cloud.agent.api.to.DataTO) VolumeVO(com.cloud.storage.VolumeVO) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) DiskTO(com.cloud.agent.api.to.DiskTO)

Example 35 with VolumeInfo

use of com.cloud.engine.subsystem.api.storage.VolumeInfo in project cosmic by MissionCriticalCloud.

the class VolumeOrchestrator method migrateVolumes.

@Override
public void migrateVolumes(final VirtualMachine vm, final VirtualMachineTO vmTo, final Host srcHost, final Host destHost, final Map<Volume, StoragePool> volumeToPool) {
    // Check if all the vms being migrated belong to the vm.
    // Check if the storage pool is of the right type.
    // Create a VolumeInfo to DataStore map too.
    final Map<VolumeInfo, DataStore> volumeMap = new HashMap<>();
    for (final Map.Entry<Volume, StoragePool> entry : volumeToPool.entrySet()) {
        final Volume volume = entry.getKey();
        final StoragePool storagePool = entry.getValue();
        final StoragePool destPool = (StoragePool) dataStoreMgr.getDataStore(storagePool.getId(), DataStoreRole.Primary);
        if (volume.getInstanceId() != vm.getId()) {
            throw new CloudRuntimeException("Volume " + volume + " that has to be migrated doesn't belong to the" + " instance " + vm);
        }
        if (destPool == null) {
            throw new CloudRuntimeException("Failed to find the destination storage pool " + storagePool.getId());
        }
        volumeMap.put(volFactory.getVolume(volume.getId()), (DataStore) destPool);
    }
    final AsyncCallFuture<CommandResult> future = volService.migrateVolumes(volumeMap, vmTo, srcHost, destHost);
    try {
        final CommandResult result = future.get();
        if (result.isFailed()) {
            s_logger.debug("Failed to migrated vm " + vm + " along with its volumes. " + result.getResult());
            throw new CloudRuntimeException("Failed to migrated vm " + vm + " along with its volumes. ");
        }
    } catch (final InterruptedException | ExecutionException e) {
        s_logger.debug("Failed to migrated vm " + vm + " along with its volumes.", e);
    }
}
Also used : StoragePool(com.cloud.storage.StoragePool) HashMap(java.util.HashMap) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) CommandResult(com.cloud.storage.command.CommandResult) VmWorkMigrateVolume(com.cloud.vm.VmWorkMigrateVolume) VmWorkAttachVolume(com.cloud.vm.VmWorkAttachVolume) Volume(com.cloud.storage.Volume) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)63 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)39 ExecutionException (java.util.concurrent.ExecutionException)26 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)21 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)19 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)19 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)17 VolumeVO (com.cloud.storage.VolumeVO)14 CopyCommandResult (com.cloud.engine.subsystem.api.storage.CopyCommandResult)12 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)12 DB (com.cloud.utils.db.DB)12 StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)9 Account (com.cloud.user.Account)9 ArrayList (java.util.ArrayList)9 PrimaryDataStore (com.cloud.engine.subsystem.api.storage.PrimaryDataStore)8 SnapshotInfo (com.cloud.engine.subsystem.api.storage.SnapshotInfo)8 ActionEvent (com.cloud.event.ActionEvent)8 VolumeDataStoreVO (com.cloud.storage.datastore.db.VolumeDataStoreVO)8 AsyncCallFuture (com.cloud.framework.async.AsyncCallFuture)7 StoragePool (com.cloud.storage.StoragePool)7