use of org.ovirt.engine.core.common.businessentities.storage.LunDisk 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.LunDisk in project ovirt-engine by oVirt.
the class DrMappingHelper method mapExternalLunDisks.
public void mapExternalLunDisks(List<LunDisk> luns, Map<String, Object> externalLunMap) {
luns.forEach(lunDisk -> {
if (externalLunMap != null) {
LunDisk targetLunDisk = (LunDisk) externalLunMap.get(lunDisk.getLun().getId());
if (targetLunDisk != null) {
log.info("Mapping LUN disk '{}' to '{}'", lunDisk.getLun().getLUNId(), targetLunDisk.getLun().getLUNId());
lunDisk.setLun(targetLunDisk.getLun());
lunDisk.getLun().getLunConnections().forEach(conn -> conn.setStorageType(lunDisk.getLun().getLunType()));
} else {
log.warn("No LUN disk will be mapped, LUN id '{}' has no mapping LUN disk", lunDisk.getLun().getId());
}
}
});
}
use of org.ovirt.engine.core.common.businessentities.storage.LunDisk in project ovirt-engine by oVirt.
the class ProcessOvfUpdateForStoragePoolCommand method populateVmsMetadataForOvfUpdate.
/**
* Create and returns map contains valid vms metadata
*/
protected Map<Guid, KeyValuePairCompat<String, List<Guid>>> populateVmsMetadataForOvfUpdate(List<Guid> idsToProcess) {
Map<Guid, KeyValuePairCompat<String, List<Guid>>> vmsAndTemplateMetadata = new HashMap<>();
List<VM> vms = vmDao.getVmsByIds(idsToProcess);
for (VM vm : vms) {
if (VMStatus.ImageLocked != vm.getStatus()) {
updateVmDisksFromDb(vm);
if (!verifyImagesStatus(vm.getDiskList())) {
continue;
}
ArrayList<DiskImage> vmImages = ovfUpdateProcessHelper.getVmImagesFromDb(vm);
if (!verifyImagesStatus(vmImages)) {
continue;
}
vm.setSnapshots(snapshotDao.getAllWithConfiguration(vm.getId()));
if (!verifySnapshotsStatus(vm.getSnapshots())) {
continue;
}
ovfUpdateProcessHelper.loadVmData(vm);
Long currentDbGeneration = vmStaticDao.getDbGeneration(vm.getId());
if (currentDbGeneration == null) {
log.warn("currentDbGeneration of VM (name: '{}', id: '{}') is null, probably because the VM was deleted during the run of OvfDataUpdater.", vm.getName(), vm.getId());
continue;
}
if (vm.getStaticData().getDbGeneration() == currentDbGeneration) {
List<LunDisk> lunDisks = DisksFilter.filterLunDisks(vm.getDiskMap().values());
for (LunDisk lun : lunDisks) {
lun.getLun().setLunConnections(new ArrayList<>(storageServerConnectionDao.getAllForLun(lun.getLun().getId())));
}
List<AffinityGroup> affinityGroups = affinityGroupDao.getAllAffinityGroupsByVmId(vm.getId());
List<Label> affinityLabels = labelDao.getAllByEntityIds(Collections.singletonList(vm.getId()));
Set<DbUser> dbUsers = new HashSet<>(dbUserDao.getAllForVm(vm.getId()));
FullEntityOvfData fullEntityOvfData = new FullEntityOvfData(vm);
fullEntityOvfData.setDiskImages(vmImages);
fullEntityOvfData.setLunDisks(lunDisks);
fullEntityOvfData.setAffinityGroups(affinityGroups);
fullEntityOvfData.setAffinityLabels(affinityLabels);
fullEntityOvfData.setDbUsers(dbUsers);
ovfHelper.populateUserToRoles(fullEntityOvfData, vm.getId());
proccessedOvfConfigurationsInfo.add(ovfUpdateProcessHelper.buildMetadataDictionaryForVm(vm, vmsAndTemplateMetadata, fullEntityOvfData));
proccessedIdsInfo.add(vm.getId());
proccessedOvfGenerationsInfo.add(vm.getStaticData().getDbGeneration());
proccessDisksDomains(vm.getDiskList());
}
}
}
return vmsAndTemplateMetadata;
}
use of org.ovirt.engine.core.common.businessentities.storage.LunDisk in project ovirt-engine by oVirt.
the class RunVmCommandTest method dontConnectFCLuns.
@Test
public void dontConnectFCLuns() {
// FC luns are connected physically, they don't have StorageServerConnection set.
// Make sure if we have an FC lun connection we don't try to connect
// otherwise NPE will be thrown.
command.setVm(new VM());
// create 2 FC lun disks
LunDisk fcLunDisk = new LunDisk();
LUNs lun1 = new LUNs();
lun1.setLUNId("id1");
fcLunDisk.setLun(lun1);
LunDisk isciDisk = new LunDisk();
LUNs lun2 = new LUNs();
lun2.setLUNId("id2");
isciDisk.setLun(lun2);
// add luns to the vm
command.getVm().getDiskMap().put(Guid.newGuid(), fcLunDisk);
command.getVm().getDiskMap().put(Guid.newGuid(), isciDisk);
List<StorageServerConnections> iscsiLunConnections = new ArrayList<>();
iscsiLunConnections.add(new StorageServerConnections("path/to/iscsi/connection", "id1", null, null, StorageType.ISCSI, null, null, null));
when(storageServerConnectionDao.getAllForLun("id1")).thenReturn(Collections.emptyList());
when(storageServerConnectionDao.getAllForLun("id2")).thenReturn(iscsiLunConnections);
ArgumentCaptor<StorageServerConnectionManagementVDSParameters> captor = ArgumentCaptor.forClass(StorageServerConnectionManagementVDSParameters.class);
doReturn(succesfull()).when(command).runVdsCommand(eq(ConnectStorageServer), any(StorageServerConnectionManagementVDSParameters.class));
boolean connectSucceeded = command.connectLunDisks(Guid.newGuid());
// for different targets, make sure we connect all but not FC.
verify(command).runVdsCommand(eq(ConnectStorageServer), captor.capture());
assertThat(captor.getValue().getConnectionList().size(), is(1));
assertEquals(captor.getValue().getStorageType(), StorageType.ISCSI);
assertTrue(connectSucceeded);
}
use of org.ovirt.engine.core.common.businessentities.storage.LunDisk in project ovirt-engine by oVirt.
the class RunVmCommandTest method oneConnectFailed.
@Test
public void oneConnectFailed() {
command.setVm(new VM());
// create 2 lun disks
LunDisk lunDisk1 = new LunDisk();
LUNs lun1 = new LUNs();
lun1.setLUNId("id1");
lunDisk1.setLun(lun1);
// add luns to the vm
command.getVm().getDiskMap().put(Guid.newGuid(), lunDisk1);
List<StorageServerConnections> connections = new ArrayList<>();
// luns have the same backing targets
connections.add(new StorageServerConnections("/path/to/con1", "id1", null, null, StorageType.ISCSI, null, null, null));
when(storageServerConnectionDao.getAllForLun("id1")).thenReturn(connections);
ArgumentCaptor<StorageServerConnectionManagementVDSParameters> captor = ArgumentCaptor.forClass(StorageServerConnectionManagementVDSParameters.class);
doReturn(new VDSReturnValue()).when(command).runVdsCommand(eq(ConnectStorageServer), any(StorageServerConnectionManagementVDSParameters.class));
boolean connectSucceeded = command.connectLunDisks(Guid.newGuid());
// for same targets, connect only once
verify(command).runVdsCommand(eq(ConnectStorageServer), captor.capture());
assertThat(captor.getValue().getConnectionList().size(), is(1));
assertFalse(connectSucceeded);
}
Aggregations