Search in sources :

Example 16 with StoragePoolVO

use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.

the class StorageSystemDataMotionStrategy method handleVolumeMigrationForKVM.

private void handleVolumeMigrationForKVM(VolumeInfo srcVolumeInfo, VolumeInfo destVolumeInfo) {
    VirtualMachine vm = srcVolumeInfo.getAttachedVM();
    if (vm != null && vm.getState() != VirtualMachine.State.Stopped) {
        throw new CloudRuntimeException("Currently, if a volume to migrate from non-managed storage to managed storage on KVM is attached to " + "a VM, the VM must be in the Stopped state.");
    }
    destVolumeInfo.getDataStore().getDriver().createAsync(destVolumeInfo.getDataStore(), destVolumeInfo, null);
    VolumeVO volumeVO = _volumeDao.findById(destVolumeInfo.getId());
    volumeVO.setPath(volumeVO.get_iScsiName());
    _volumeDao.update(volumeVO.getId(), volumeVO);
    destVolumeInfo = _volumeDataFactory.getVolume(destVolumeInfo.getId(), destVolumeInfo.getDataStore());
    long srcStoragePoolId = srcVolumeInfo.getPoolId();
    StoragePoolVO srcStoragePoolVO = _storagePoolDao.findById(srcStoragePoolId);
    HostVO hostVO;
    if (srcStoragePoolVO.getClusterId() != null) {
        hostVO = getHostInCluster(srcStoragePoolVO.getClusterId());
    } else {
        hostVO = getHost(destVolumeInfo.getDataCenterId(), HypervisorType.KVM, false);
    }
    // migrate the volume via the hypervisor
    migrateVolumeForKVM(srcVolumeInfo, destVolumeInfo, hostVO, "Unable to migrate the volume from non-managed storage to managed storage");
    volumeVO = _volumeDao.findById(destVolumeInfo.getId());
    volumeVO.setFormat(ImageFormat.QCOW2);
    _volumeDao.update(volumeVO.getId(), volumeVO);
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) HostVO(com.cloud.host.HostVO) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 17 with StoragePoolVO

use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.

the class StorageSystemDataMotionStrategy method internalCanHandle.

/**
 * Handles migrating volumes on managed Storage.
 */
protected StrategyPriority internalCanHandle(Map<VolumeInfo, DataStore> volumeMap, Host srcHost, Host destHost) {
    Set<VolumeInfo> volumeInfoSet = volumeMap.keySet();
    for (VolumeInfo volumeInfo : volumeInfoSet) {
        StoragePoolVO storagePoolVO = _storagePoolDao.findById(volumeInfo.getPoolId());
        if (storagePoolVO.isManaged()) {
            return StrategyPriority.HIGHEST;
        }
    }
    Collection<DataStore> dataStores = volumeMap.values();
    for (DataStore dataStore : dataStores) {
        StoragePoolVO storagePoolVO = _storagePoolDao.findById(dataStore.getId());
        if (storagePoolVO.isManaged()) {
            return StrategyPriority.HIGHEST;
        }
    }
    return StrategyPriority.CANT_HANDLE;
}
Also used : DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)

Example 18 with StoragePoolVO

use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.

the class StorageSystemDataMotionStrategy method verifyFormat.

private void verifyFormat(SnapshotInfo snapshotInfo) {
    long volumeId = snapshotInfo.getVolumeId();
    VolumeVO volumeVO = _volumeDao.findByIdIncludingRemoved(volumeId);
    StoragePoolVO storagePoolVO = _storagePoolDao.findById(volumeVO.getPoolId());
    verifyFormatWithPoolType(volumeVO.getFormat(), storagePoolVO.getPoolType());
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO)

Example 19 with StoragePoolVO

use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.

the class StorageSystemDataMotionStrategy method getModifyTargetsCommand.

private ModifyTargetsCommand getModifyTargetsCommand(long storagePoolId, String iqn, boolean add) {
    StoragePoolVO storagePool = _storagePoolDao.findById(storagePoolId);
    Map<String, String> details = new HashMap<>();
    details.put(ModifyTargetsCommand.IQN, iqn);
    details.put(ModifyTargetsCommand.STORAGE_TYPE, storagePool.getPoolType().name());
    details.put(ModifyTargetsCommand.STORAGE_UUID, storagePool.getUuid());
    details.put(ModifyTargetsCommand.STORAGE_HOST, storagePool.getHostAddress());
    details.put(ModifyTargetsCommand.STORAGE_PORT, String.valueOf(storagePool.getPort()));
    ModifyTargetsCommand cmd = new ModifyTargetsCommand();
    List<Map<String, String>> targets = new ArrayList<>();
    targets.add(details);
    cmd.setTargets(targets);
    cmd.setApplyToAllHostsInCluster(true);
    cmd.setAdd(add);
    cmd.setTargetTypeToRemove(ModifyTargetsCommand.TargetTypeToRemove.DYNAMIC);
    return cmd;
}
Also used : HashMap(java.util.HashMap) ModifyTargetsCommand(com.cloud.agent.api.ModifyTargetsCommand) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 20 with StoragePoolVO

use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.

the class StorageSystemDataMotionStrategy method isSourceAndDestinationPoolTypeOfNfs.

/**
 * Returns true if at least one of the entries on the map 'volumeDataStoreMap' has both source and destination storage pools of Network Filesystem (NFS).
 */
protected boolean isSourceAndDestinationPoolTypeOfNfs(Map<VolumeInfo, DataStore> volumeDataStoreMap) {
    for (Map.Entry<VolumeInfo, DataStore> entry : volumeDataStoreMap.entrySet()) {
        VolumeInfo srcVolumeInfo = entry.getKey();
        DataStore destDataStore = entry.getValue();
        StoragePoolVO destStoragePool = _storagePoolDao.findById(destDataStore.getId());
        StoragePoolVO sourceStoragePool = _storagePoolDao.findById(srcVolumeInfo.getPoolId());
        if (sourceStoragePool.getPoolType() == StoragePoolType.NetworkFilesystem && destStoragePool.getPoolType() == StoragePoolType.NetworkFilesystem) {
            return true;
        }
    }
    return false;
}
Also used : DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)276 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)106 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)75 ArrayList (java.util.ArrayList)54 VolumeVO (com.cloud.storage.VolumeVO)53 HostVO (com.cloud.host.HostVO)46 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)45 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)45 HashMap (java.util.HashMap)44 Answer (com.cloud.agent.api.Answer)38 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)35 StoragePool (com.cloud.storage.StoragePool)33 Test (org.junit.Test)33 VMInstanceVO (com.cloud.vm.VMInstanceVO)25 Map (java.util.Map)25 Account (com.cloud.user.Account)24 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)20 ExecutionException (java.util.concurrent.ExecutionException)20 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)19 ClusterVO (com.cloud.dc.ClusterVO)18