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;
}
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());
}
}
}
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();
}
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);
}
}
}
}
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);
}
Aggregations