Search in sources :

Example 81 with VolumeVO

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

the class UserVmManagerImpl method migrateVirtualMachineWithVolume.

@Override
@ActionEvent(eventType = EventTypes.EVENT_VM_MIGRATE, eventDescription = "migrating VM", async = true)
public VirtualMachine migrateVirtualMachineWithVolume(Long vmId, Host destinationHost, Map<String, String> volumeToPool) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException {
    // Access check - only root administrator can migrate VM.
    Account caller = CallContext.current().getCallingAccount();
    if (!_accountMgr.isRootAdmin(caller.getId())) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Caller is not a root admin, permission denied to migrate the VM");
        }
        throw new PermissionDeniedException("No permission to migrate VM, Only Root Admin can migrate a VM!");
    }
    VMInstanceVO vm = _vmInstanceDao.findById(vmId);
    if (vm == null) {
        throw new InvalidParameterValueException("Unable to find the vm by id " + vmId);
    }
    if (vm.getState() != State.Running) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("VM is not Running, unable to migrate the vm " + vm);
        }
        CloudRuntimeException ex = new CloudRuntimeException("VM is not Running, unable to migrate the vm with" + " specified id");
        ex.addProxyObject(vm.getUuid(), "vmId");
        throw ex;
    }
    if (serviceOfferingDetailsDao.findDetail(vm.getServiceOfferingId(), GPU.Keys.pciDevice.toString()) != null) {
        throw new InvalidParameterValueException("Live Migration of GPU enabled VM is not supported");
    }
    if (!vm.getHypervisorType().equals(HypervisorType.XenServer) && !vm.getHypervisorType().equals(HypervisorType.VMware) && !vm.getHypervisorType().equals(HypervisorType.KVM) && !vm.getHypervisorType().equals(HypervisorType.Ovm) && !vm.getHypervisorType().equals(HypervisorType.Hyperv) && !vm.getHypervisorType().equals(HypervisorType.Simulator)) {
        throw new InvalidParameterValueException("Unsupported hypervisor type for vm migration, we support" + " XenServer/VMware/KVM only");
    }
    long srcHostId = vm.getHostId();
    Host srcHost = _resourceMgr.getHost(srcHostId);
    if (srcHost == null) {
        throw new InvalidParameterValueException("Cannot migrate VM, there is not Host with id: " + srcHostId);
    }
    // Check if src and destination hosts are valid and migrating to same host
    if (destinationHost.getId() == srcHostId) {
        throw new InvalidParameterValueException("Cannot migrate VM, VM is already present on this host, please" + " specify valid destination host to migrate the VM");
    }
    // Check if the source and destination hosts are of the same type and support storage motion.
    if (!(srcHost.getHypervisorType().equals(destinationHost.getHypervisorType()))) {
        throw new CloudRuntimeException("The source and destination hosts are not of the same type. " + "Source hypervisor type and version: " + srcHost.getHypervisorType().toString() + " " + srcHost.getHypervisorVersion() + ", Destination hypervisor type and version: " + destinationHost.getHypervisorType().toString() + " " + destinationHost.getHypervisorVersion());
    }
    HypervisorCapabilitiesVO capabilities = _hypervisorCapabilitiesDao.findByHypervisorTypeAndVersion(srcHost.getHypervisorType(), srcHost.getHypervisorVersion());
    if (!capabilities.isStorageMotionSupported()) {
        throw new CloudRuntimeException("Migration with storage isn't supported on hypervisor " + srcHost.getHypervisorType() + " of version " + srcHost.getHypervisorVersion());
    }
    // Check if destination host is up.
    if (destinationHost.getState() != com.cloud.host.Status.Up || destinationHost.getResourceState() != ResourceState.Enabled) {
        throw new CloudRuntimeException("Cannot migrate VM, destination host is not in correct state, has " + "status: " + destinationHost.getState() + ", state: " + destinationHost.getResourceState());
    }
    // Check that Vm does not have VM Snapshots
    if (_vmSnapshotDao.findByVm(vmId).size() > 0) {
        throw new InvalidParameterValueException("VM with VM Snapshots cannot be migrated with storage, please remove all VM snapshots");
    }
    List<VolumeVO> vmVolumes = _volsDao.findUsableVolumesForInstance(vm.getId());
    Map<Long, Long> volToPoolObjectMap = new HashMap<Long, Long>();
    if (!isVMUsingLocalStorage(vm) && destinationHost.getClusterId().equals(srcHost.getClusterId())) {
        if (volumeToPool.isEmpty()) {
            // then fail the call. migrateVirtualMachine api should have been used.
            throw new InvalidParameterValueException("Migration of the vm " + vm + "from host " + srcHost + " to destination host " + destinationHost + " doesn't involve migrating the volumes.");
        }
    }
    if (!volumeToPool.isEmpty()) {
        // Check if all the volumes and pools passed as parameters are valid.
        for (Map.Entry<String, String> entry : volumeToPool.entrySet()) {
            VolumeVO volume = _volsDao.findByUuid(entry.getKey());
            StoragePoolVO pool = _storagePoolDao.findByUuid(entry.getValue());
            if (volume == null) {
                throw new InvalidParameterValueException("There is no volume present with the given id " + entry.getKey());
            } else if (pool == null) {
                throw new InvalidParameterValueException("There is no storage pool present with the given id " + entry.getValue());
            } else if (pool.isInMaintenance()) {
                throw new InvalidParameterValueException("Cannot migrate volume " + volume + "to the destination storage pool " + pool.getName() + " as the storage pool is in maintenance mode.");
            } else {
                // Verify the volume given belongs to the vm.
                if (!vmVolumes.contains(volume)) {
                    throw new InvalidParameterValueException("There volume " + volume + " doesn't belong to " + "the virtual machine " + vm + " that has to be migrated");
                }
                volToPoolObjectMap.put(Long.valueOf(volume.getId()), Long.valueOf(pool.getId()));
            }
        }
    }
    // Check if all the volumes are in the correct state.
    for (VolumeVO volume : vmVolumes) {
        if (volume.getState() != Volume.State.Ready) {
            throw new CloudRuntimeException("Volume " + volume + " of the VM is not in Ready state. Cannot " + "migrate the vm with its volumes.");
        }
    }
    // Check max guest vm limit for the destinationHost.
    HostVO destinationHostVO = _hostDao.findById(destinationHost.getId());
    if (_capacityMgr.checkIfHostReachMaxGuestLimit(destinationHostVO)) {
        throw new VirtualMachineMigrationException("Host name: " + destinationHost.getName() + ", hostId: " + destinationHost.getId() + " already has max running vms (count includes system VMs). Cannot" + " migrate to this host");
    }
    checkHostsDedication(vm, srcHostId, destinationHost.getId());
    _itMgr.migrateWithStorage(vm.getUuid(), srcHostId, destinationHost.getId(), volToPoolObjectMap);
    return _vmDao.findById(vm.getId());
}
Also used : HypervisorCapabilitiesVO(com.cloud.hypervisor.HypervisorCapabilitiesVO) Account(com.cloud.user.Account) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Host(com.cloud.host.Host) HostVO(com.cloud.host.HostVO) VolumeVO(com.cloud.storage.VolumeVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) VirtualMachineMigrationException(com.cloud.exception.VirtualMachineMigrationException) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ActionEvent(com.cloud.event.ActionEvent)

Example 82 with VolumeVO

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

the class VMSnapshotManagerImpl method orchestrateCreateVMSnapshot.

private VMSnapshot orchestrateCreateVMSnapshot(Long vmId, Long vmSnapshotId, Boolean quiescevm) {
    UserVmVO userVm = _userVMDao.findById(vmId);
    if (userVm == null) {
        throw new InvalidParameterValueException("Create vm to snapshot failed due to vm: " + vmId + " is not found");
    }
    List<VolumeVO> volumeVos = _volumeDao.findByInstanceAndType(vmId, Type.ROOT);
    if (volumeVos == null || volumeVos.isEmpty()) {
        throw new CloudRuntimeException("Create vm to snapshot failed due to no root disk found");
    }
    VolumeVO rootVolume = volumeVos.get(0);
    if (!rootVolume.getState().equals(Volume.State.Ready)) {
        throw new CloudRuntimeException("Create vm to snapshot failed due to vm: " + vmId + " has root disk in " + rootVolume.getState() + " state");
    }
    VMSnapshotVO vmSnapshot = _vmSnapshotDao.findById(vmSnapshotId);
    if (vmSnapshot == null) {
        throw new CloudRuntimeException("VM snapshot id: " + vmSnapshotId + " can not be found");
    }
    VMSnapshotOptions options = new VMSnapshotOptions(quiescevm);
    vmSnapshot.setOptions(options);
    try {
        VMSnapshotStrategy strategy = findVMSnapshotStrategy(vmSnapshot);
        VMSnapshot snapshot = strategy.takeVMSnapshot(vmSnapshot);
        return snapshot;
    } catch (Exception e) {
        s_logger.debug("Failed to create vm snapshot: " + vmSnapshotId, e);
        return null;
    }
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) VolumeVO(com.cloud.storage.VolumeVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VMSnapshotOptions(org.apache.cloudstack.engine.subsystem.api.storage.VMSnapshotOptions) VMSnapshotStrategy(org.apache.cloudstack.engine.subsystem.api.storage.VMSnapshotStrategy) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) TransactionCallbackWithException(com.cloud.utils.db.TransactionCallbackWithException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VirtualMachineMigrationException(com.cloud.exception.VirtualMachineMigrationException) ManagementServerException(com.cloud.exception.ManagementServerException)

Example 83 with VolumeVO

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

the class VMSnapshotManagerImpl method getVolumeTOList.

private List<VolumeObjectTO> getVolumeTOList(Long vmId) {
    List<VolumeObjectTO> volumeTOs = new ArrayList<VolumeObjectTO>();
    List<VolumeVO> volumeVos = _volumeDao.findByInstance(vmId);
    VolumeInfo volumeInfo = null;
    for (VolumeVO volume : volumeVos) {
        volumeInfo = volumeDataFactory.getVolume(volume.getId());
        volumeTOs.add((VolumeObjectTO) volumeInfo.getTO());
    }
    return volumeTOs;
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) ArrayList(java.util.ArrayList) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)

Example 84 with VolumeVO

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

the class ElastistorPrimaryDataStoreDriver method createAsync.

@Override
public void createAsync(DataStore dataStore, DataObject dataObject, AsyncCompletionCallback<CreateCmdResult> callback) {
    String iqn = null;
    String errMsg = null;
    CreateCmdResult result = new CreateCmdResult(iqn, new Answer(null, errMsg == null, errMsg));
    if (dataObject.getType() == DataObjectType.VOLUME) {
        VolumeInfo volumeInfo = (VolumeInfo) dataObject;
        long storagePoolId = dataStore.getId();
        String volumeName = volumeInfo.getName();
        Long Iops = volumeInfo.getMaxIops();
        // quota size of the cloudbyte volume will be increased with the given HypervisorSnapshotReserve
        Long quotaSize = getDataObjectSizeIncludingHypervisorSnapshotReserve(volumeInfo, _storagePoolDao.findById(storagePoolId));
        StoragePoolVO storagePool = _storagePoolDao.findById(dataStore.getId());
        VolumeVO volume = _volumeDao.findById(volumeInfo.getId());
        // calling super(default) that creates a vdi(disk) only.
        if (!(storagePool.isManaged())) {
            super.createAsync(dataStore, dataObject, callback);
            // update the volume property
            volume.setPoolType(storagePool.getPoolType());
            _volumeDao.update(volume.getId(), volume);
            return;
        }
        DiskOfferingVO diskOffering = _diskOfferingDao.findById(volumeInfo.getDiskOfferingId());
        long capacityIops = storagePool.getCapacityIops();
        capacityIops = capacityIops - Iops;
        if (capacityIops < 0) {
            throw new CloudRuntimeException("IOPS not available. [pool:" + storagePool.getName() + "] [availiops:" + capacityIops + "] [requirediops:" + Iops + "]");
        }
        String protocoltype = null;
        StoragePoolVO dataStoreVO = _storagePoolDao.findById(storagePoolId);
        String desc = diskOffering.getDisplayText();
        if (desc.toLowerCase().contains("iscsi")) {
            protocoltype = "iscsi";
        } else if (dataStoreVO.getPoolType().equals(StoragePoolType.NetworkFilesystem) || dataStoreVO.getPoolType().equals(StoragePoolType.Filesystem)) {
            protocoltype = "nfs";
        } else {
            protocoltype = "iscsi";
        }
        FileSystem esvolume = null;
        try {
            esvolume = ElastistorUtil.createElastistorVolume(volumeName, dataStoreVO.getUuid(), quotaSize, Iops, protocoltype, volumeName);
        } catch (Throwable e) {
            s_logger.error(e.toString(), e);
            result.setResult(e.toString());
            callback.complete(result);
            throw new CloudRuntimeException(e.getMessage());
        }
        if (esvolume.getNfsenabled().equalsIgnoreCase("true")) {
            volume.set_iScsiName(esvolume.getPath());
            volume.setPoolType(StoragePoolType.NetworkFilesystem);
        } else {
            iqn = esvolume.getIqn();
            String modifiediqn = "/" + iqn + "/0";
            volume.set_iScsiName(modifiediqn);
            volume.setPoolType(StoragePoolType.IscsiLUN);
        }
        volume.setFolder(String.valueOf(esvolume.getUuid()));
        volume.setPoolId(storagePoolId);
        volume.setUuid(esvolume.getUuid());
        volume.setPath(null);
        _volumeDao.update(volume.getId(), volume);
        // create new volume details for the volume
        //updateVolumeDetails(volume, esvolume);
        long capacityBytes = storagePool.getCapacityBytes();
        long usedBytes = storagePool.getUsedBytes();
        Long inbytes = volume.getSize();
        usedBytes += inbytes;
        storagePool.setCapacityIops(capacityIops);
        storagePool.setUsedBytes(usedBytes > capacityBytes ? capacityBytes : usedBytes);
        _storagePoolDao.update(storagePoolId, storagePool);
        s_logger.info("Elastistor volume creation complete.");
    } else {
        errMsg = "Invalid DataObjectType (" + dataObject.getType() + ") passed to createAsync";
        s_logger.error(errMsg);
    }
    result.setResult(errMsg);
    callback.complete(result);
}
Also used : CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) Answer(com.cloud.agent.api.Answer) VolumeVO(com.cloud.storage.VolumeVO) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) FileSystem(org.apache.cloudstack.storage.datastore.util.ElastistorUtil.FileSystem) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)

Example 85 with VolumeVO

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

the class DeploymentPlanningManagerImpl method findVMStorageRequirements.

private Pair<Boolean, Boolean> findVMStorageRequirements(VirtualMachineProfile vmProfile) {
    boolean requiresShared = false, requiresLocal = false;
    List<VolumeVO> volumesTobeCreated = _volsDao.findUsableVolumesForInstance(vmProfile.getId());
    // for each volume find whether shared or local pool is required
    for (VolumeVO toBeCreated : volumesTobeCreated) {
        DiskOfferingVO diskOffering = _diskOfferingDao.findById(toBeCreated.getDiskOfferingId());
        if (diskOffering != null) {
            if (diskOffering.getUseLocalStorage()) {
                requiresLocal = true;
            } else {
                requiresShared = true;
            }
        }
    }
    return new Pair<Boolean, Boolean>(requiresShared, requiresLocal);
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) Pair(com.cloud.utils.Pair)

Aggregations

VolumeVO (com.cloud.storage.VolumeVO)156 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)44 ArrayList (java.util.ArrayList)39 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)36 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)30 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)26 HostVO (com.cloud.host.HostVO)24 VMInstanceVO (com.cloud.vm.VMInstanceVO)24 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)22 Account (com.cloud.user.Account)19 HashMap (java.util.HashMap)17 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)16 VolumeApiResult (org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult)16 StoragePool (com.cloud.storage.StoragePool)15 HostPodVO (com.cloud.dc.HostPodVO)14 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)13 Pair (com.cloud.utils.Pair)13 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)11 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)11 DiskOfferingVO (com.cloud.storage.DiskOfferingVO)11