Search in sources :

Example 1 with LunDisk

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());
        }
    }
}
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 2 with LunDisk

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());
            }
        }
    });
}
Also used : LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk)

Example 3 with LunDisk

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;
}
Also used : KeyValuePairCompat(org.ovirt.engine.core.compat.KeyValuePairCompat) HashMap(java.util.HashMap) Label(org.ovirt.engine.core.common.businessentities.Label) Guid(org.ovirt.engine.core.compat.Guid) FullEntityOvfData(org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) AffinityGroup(org.ovirt.engine.core.common.scheduling.AffinityGroup) VM(org.ovirt.engine.core.common.businessentities.VM) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) HashSet(java.util.HashSet)

Example 4 with LunDisk

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);
}
Also used : StorageServerConnections(org.ovirt.engine.core.common.businessentities.StorageServerConnections) StorageServerConnectionManagementVDSParameters(org.ovirt.engine.core.common.vdscommands.StorageServerConnectionManagementVDSParameters) VM(org.ovirt.engine.core.common.businessentities.VM) ArrayList(java.util.ArrayList) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) LUNs(org.ovirt.engine.core.common.businessentities.storage.LUNs) Test(org.junit.Test)

Example 5 with LunDisk

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);
}
Also used : StorageServerConnections(org.ovirt.engine.core.common.businessentities.StorageServerConnections) StorageServerConnectionManagementVDSParameters(org.ovirt.engine.core.common.vdscommands.StorageServerConnectionManagementVDSParameters) VM(org.ovirt.engine.core.common.businessentities.VM) ArrayList(java.util.ArrayList) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) LUNs(org.ovirt.engine.core.common.businessentities.storage.LUNs) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) Test(org.junit.Test)

Aggregations

LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)62 Test (org.junit.Test)29 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)21 CinderDisk (org.ovirt.engine.core.common.businessentities.storage.CinderDisk)18 BaseCommandTest (org.ovirt.engine.core.bll.BaseCommandTest)16 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)13 LUNs (org.ovirt.engine.core.common.businessentities.storage.LUNs)13 VM (org.ovirt.engine.core.common.businessentities.VM)10 ArrayList (java.util.ArrayList)9 StorageServerConnections (org.ovirt.engine.core.common.businessentities.StorageServerConnections)7 Guid (org.ovirt.engine.core.compat.Guid)7 DiskVmElement (org.ovirt.engine.core.common.businessentities.storage.DiskVmElement)6 HashMap (java.util.HashMap)5 VDS (org.ovirt.engine.core.common.businessentities.VDS)5 StorageServerConnectionManagementVDSParameters (org.ovirt.engine.core.common.vdscommands.StorageServerConnectionManagementVDSParameters)5 HashSet (java.util.HashSet)3 FullEntityOvfData (org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData)3 StorageType (org.ovirt.engine.core.common.businessentities.storage.StorageType)3 ImageResource (com.google.gwt.resources.client.ImageResource)2 List (java.util.List)2