Search in sources :

Example 1 with DiskLunMap

use of org.ovirt.engine.core.common.businessentities.storage.DiskLunMap in project ovirt-engine by oVirt.

the class VmDevicesConverter method parseDisks.

private List<Map<String, Object>> parseDisks(XmlDocument document, List<VmDevice> devices) {
    List<VmDevice> dbDevices = filterDevices(devices, VmDeviceGeneralType.DISK);
    MemoizingSupplier<Map<Guid, String>> diskToLunSupplier = new MemoizingSupplier<>(() -> diskLunMapDao.getAll().stream().collect(Collectors.toMap(DiskLunMap::getDiskId, DiskLunMap::getLunId)));
    List<Map<String, Object>> result = new ArrayList<>();
    for (XmlNode node : selectNodes(document, VmDeviceGeneralType.DISK)) {
        Map<String, Object> dev = new HashMap<>();
        dev.put(VdsProperties.Type, VmDeviceGeneralType.DISK.getValue());
        String diskType = parseAttribute(node, DEVICE);
        dev.put(VdsProperties.Device, diskType);
        dev.put(VdsProperties.Address, parseAddress(node));
        dev.put(VdsProperties.Alias, parseAlias(node));
        String path = parseDiskPath(node);
        VmDevice dbDev = correlate(dev, dbDevices, device -> findDiskDeviceInDbByPath(dbDevices, diskType, path, diskToLunSupplier));
        if (dbDev == null) {
            log.warn("unmanaged disk with path '{}' is ignored", path);
            continue;
        }
        dbDevices.remove(dbDev);
        dev.put(VdsProperties.ImageId, parseImageIdFromPath(path));
        dev.put(VdsProperties.DeviceId, dbDev.getDeviceId().toString());
        dev.put(VdsProperties.SpecParams, dbDev.getSpecParams());
        List<Map<String, Object>> volumeChain = parseVolumeChain(node);
        if (!volumeChain.isEmpty()) {
            dev.put(VdsProperties.VolumeChain, volumeChain.toArray());
        }
        result.add(dev);
    }
    return result;
}
Also used : XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) HashMap(java.util.HashMap) DiskLunMap(org.ovirt.engine.core.common.businessentities.storage.DiskLunMap) Map(java.util.Map) DiskLunMap(org.ovirt.engine.core.common.businessentities.storage.DiskLunMap) MemoizingSupplier(org.ovirt.engine.core.utils.MemoizingSupplier)

Example 2 with DiskLunMap

use of org.ovirt.engine.core.common.businessentities.storage.DiskLunMap in project ovirt-engine by oVirt.

the class ImportVmCommand method addVmExternalLuns.

protected void addVmExternalLuns() {
    if (getParameters().getVm().getDiskMap() != null) {
        List<LunDisk> lunDisks = DisksFilter.filterLunDisks(getParameters().getVm().getDiskMap().values());
        for (LunDisk lun : lunDisks) {
            StorageType storageType = StorageType.UNKNOWN;
            if (lun.getLun().getLunConnections() != null && !lun.getLun().getLunConnections().isEmpty()) {
                // We set the storage type based on the first connection since connections should be with the same
                // storage type
                storageType = lun.getLun().getLunConnections().get(0).getStorageType();
            }
            lunHelper.proceedDirectLUNInDb(lun.getLun(), storageType);
            // Only if the LUN disk does not exists in the setup add it.
            if (baseDiskDao.get(lun.getId()) == null) {
                baseDiskDao.save(lun);
            }
            if (diskLunMapDao.get(new DiskLunMapId(lun.getId(), lun.getLun().getLUNId())) == null) {
                diskLunMapDao.save(new DiskLunMap(lun.getId(), lun.getLun().getLUNId()));
            }
            // Add disk VM element to attach the disk to the VM.
            DiskVmElement diskVmElement = lun.getDiskVmElementForVm(getVmId());
            diskVmElementDao.save(diskVmElement);
            getVmDeviceUtils().addDiskDevice(getVmId(), lun.getId(), diskVmElement.isPlugged(), diskVmElement.isReadOnly());
        }
    }
}
Also used : StorageType(org.ovirt.engine.core.common.businessentities.storage.StorageType) DiskStorageType(org.ovirt.engine.core.common.businessentities.storage.DiskStorageType) DiskLunMapId(org.ovirt.engine.core.common.businessentities.storage.DiskLunMapId) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) DiskLunMap(org.ovirt.engine.core.common.businessentities.storage.DiskLunMap)

Example 3 with DiskLunMap

use of org.ovirt.engine.core.common.businessentities.storage.DiskLunMap in project ovirt-engine by oVirt.

the class SyncDirectLunsCommandTest method setUp.

@Before
public void setUp() {
    lun1 = new LUNs();
    lun1.setLUNId("lun1");
    lun1.setDiskId(Guid.newGuid());
    lun1.setVolumeGroupId("");
    disk1Lun1Map = new DiskLunMap(lun1.getDiskId(), lun1.getLUNId());
    lun2 = new LUNs();
    lun2.setLUNId("lun2");
    lun2.setDiskId(Guid.newGuid());
    lun2.setVolumeGroupId("");
    lun3 = new LUNs();
    lun3.setLUNId("lun3");
    lun3.setDiskId(Guid.newGuid());
    lun3.setVolumeGroupId("");
    mockLunDao();
}
Also used : LUNs(org.ovirt.engine.core.common.businessentities.storage.LUNs) DiskLunMap(org.ovirt.engine.core.common.businessentities.storage.DiskLunMap) Before(org.junit.Before)

Example 4 with DiskLunMap

use of org.ovirt.engine.core.common.businessentities.storage.DiskLunMap in project ovirt-engine by oVirt.

the class UpdateStoragePoolCommand method syncAllUsedLunsInStoragePool.

/**
 * Synchronizes all the direct luns that are attached to a vm in the storage pool,
 * and all the active block storage domains' luns.
 */
private void syncAllUsedLunsInStoragePool() {
    if (discardInformationWasIntroduced() || reduceDeviceFromStorageDomainWasIntroduced()) {
        if (getOldStoragePool().getStatus() == StoragePoolStatus.Up) {
            /*
                - We don't want to fail the whole storage pool upgrade because some of the
                  luns could not be synced, so SyncAllUsedLuns only logs errors on such cases.
                 */
            runInternalAction(ActionType.SyncAllUsedLuns, new SyncLunsParameters(getStoragePoolId()));
        } else {
            List<DiskLunMap> diskLunMapsForVmsInPool = diskLunMapDao.getDiskLunMapsForVmsInPool(getStoragePoolId());
            if (!diskLunMapsForVmsInPool.isEmpty()) {
                addCustomValue("DirectLunDisksIds", diskLunMapsForVmsInPool.stream().map(DiskLunMap::getDiskId).map(Guid::toString).collect(Collectors.joining(", ")));
                auditLogDirector.log(this, AuditLogType.DIRECT_LUNS_COULD_NOT_BE_SYNCED);
            }
        }
    }
}
Also used : SyncLunsParameters(org.ovirt.engine.core.common.action.SyncLunsParameters) Guid(org.ovirt.engine.core.compat.Guid) DiskLunMap(org.ovirt.engine.core.common.businessentities.storage.DiskLunMap)

Example 5 with DiskLunMap

use of org.ovirt.engine.core.common.businessentities.storage.DiskLunMap in project ovirt-engine by oVirt.

the class AddDiskCommand method createDiskBasedOnLun.

private void createDiskBasedOnLun() {
    final LUNs lun;
    if (lunFromStorage == null) {
        lun = ((LunDisk) getParameters().getDiskInfo()).getLun();
    } else {
        lun = lunFromStorage;
    }
    TransactionSupport.executeInNewTransaction(() -> {
        lunHelper.proceedDirectLUNInDb(lun, lun.getLunType());
        baseDiskDao.save(getParameters().getDiskInfo());
        diskLunMapDao.save(new DiskLunMap(getParameters().getDiskInfo().getId(), lun.getLUNId()));
        if (getVm() != null) {
            // The disk VM element has to be added before the VM device since as a part of the VM device creation the
            // boot order is determined so the VM device creation depends on the existence of the disk VM element
            addDiskVmElementForDisk(getDiskVmElement());
            addManagedDeviceForDisk(getParameters().getDiskInfo().getId());
            vmStaticDao.incrementDbGeneration(getVmId());
        }
        return null;
    });
    getReturnValue().setActionReturnValue(getParameters().getDiskInfo().getId());
    plugDiskToVmIfNeeded();
    setSucceeded(true);
}
Also used : LUNs(org.ovirt.engine.core.common.businessentities.storage.LUNs) DiskLunMap(org.ovirt.engine.core.common.businessentities.storage.DiskLunMap)

Aggregations

DiskLunMap (org.ovirt.engine.core.common.businessentities.storage.DiskLunMap)5 LUNs (org.ovirt.engine.core.common.businessentities.storage.LUNs)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Before (org.junit.Before)1 SyncLunsParameters (org.ovirt.engine.core.common.action.SyncLunsParameters)1 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)1 DiskLunMapId (org.ovirt.engine.core.common.businessentities.storage.DiskLunMapId)1 DiskStorageType (org.ovirt.engine.core.common.businessentities.storage.DiskStorageType)1 DiskVmElement (org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)1 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)1 StorageType (org.ovirt.engine.core.common.businessentities.storage.StorageType)1 Guid (org.ovirt.engine.core.compat.Guid)1 MemoizingSupplier (org.ovirt.engine.core.utils.MemoizingSupplier)1 XmlNode (org.ovirt.engine.core.utils.ovf.xml.XmlNode)1