Search in sources :

Example 1 with VmIconIdSizePair

use of org.ovirt.engine.core.common.queries.VmIconIdSizePair in project ovirt-engine by oVirt.

the class OvfManager method initIcons.

private void initIcons(VmBase vmBase) {
    final int osId = vmBase.getOsId();
    final int fallbackOsId = OsRepository.DEFAULT_X86_OS;
    final Map<Integer, VmIconIdSizePair> vmIconDefaults = iconDefaultsProvider.getVmIconDefaults();
    final VmIconIdSizePair iconPair = vmIconDefaults.containsKey(osId) ? vmIconDefaults.get(osId) : vmIconDefaults.get(fallbackOsId);
    vmBase.setSmallIconId(iconPair.getSmall());
    vmBase.setLargeIconId(iconPair.getLarge());
}
Also used : VmIconIdSizePair(org.ovirt.engine.core.common.queries.VmIconIdSizePair)

Example 2 with VmIconIdSizePair

use of org.ovirt.engine.core.common.queries.VmIconIdSizePair in project ovirt-engine by oVirt.

the class OvfVmIconDefaultsProvider method getVmIconDefaults.

public Map<Integer, VmIconIdSizePair> getVmIconDefaults() {
    final Map<Integer, VmIconIdSizePair> result = new HashMap<>();
    final List<VmIconDefault> iconDefaults = vmIconDefaultDao.getAll();
    for (VmIconDefault iconDefault : iconDefaults) {
        result.put(iconDefault.getOsId(), new VmIconIdSizePair(iconDefault.getSmallIconId(), iconDefault.getLargeIconId()));
    }
    if (!result.containsKey(OsRepository.DEFAULT_X86_OS)) {
        throw new EngineException(EngineError.DefaultIconPairNotFound);
    }
    return result;
}
Also used : VmIconIdSizePair(org.ovirt.engine.core.common.queries.VmIconIdSizePair) HashMap(java.util.HashMap) EngineException(org.ovirt.engine.core.common.errors.EngineException) VmIconDefault(org.ovirt.engine.core.common.businessentities.VmIconDefault)

Example 3 with VmIconIdSizePair

use of org.ovirt.engine.core.common.queries.VmIconIdSizePair in project ovirt-engine by oVirt.

the class IconUtils method ensureIconPairInDatabase.

public VmIconIdSizePair ensureIconPairInDatabase(String largeIconDataUrl) {
    final String smallIconDataUrl = IconUtils.computeSmallIcon(largeIconDataUrl);
    Guid largeIconId = vmIconDao.ensureIconInDatabase(largeIconDataUrl);
    Guid smallIconId = vmIconDao.ensureIconInDatabase(smallIconDataUrl);
    return new VmIconIdSizePair(smallIconId, largeIconId);
}
Also used : VmIconIdSizePair(org.ovirt.engine.core.common.queries.VmIconIdSizePair) Guid(org.ovirt.engine.core.compat.Guid)

Example 4 with VmIconIdSizePair

use of org.ovirt.engine.core.common.queries.VmIconIdSizePair in project ovirt-engine by oVirt.

the class IconLoader method ensureIconsInDatabase.

private VmIconIdSizePair ensureIconsInDatabase(String osName) {
    final Guid smallIconId = ensureIconInDatabase(SMALL_ICON_DIR, osName);
    final Guid largeIconId = ensureIconInDatabase(LARGE_ICON_DIR, osName);
    if (smallIconId != null && largeIconId != null) {
        return new VmIconIdSizePair(smallIconId, largeIconId);
    }
    return null;
}
Also used : VmIconIdSizePair(org.ovirt.engine.core.common.queries.VmIconIdSizePair) Guid(org.ovirt.engine.core.compat.Guid)

Example 5 with VmIconIdSizePair

use of org.ovirt.engine.core.common.queries.VmIconIdSizePair in project ovirt-engine by oVirt.

the class OvfManagerTest method setUp.

@Before
public void setUp() throws Exception {
    final HashMap<Integer, String> osIdsToNames = new HashMap<>();
    osIdsToNames.put(DEFAULT_OS_ID, "os_name_a");
    osIdsToNames.put(EXISTING_OS_ID, "os_name_b");
    final List<Pair<GraphicsType, DisplayType>> gndDefaultOs = new ArrayList<>();
    gndDefaultOs.add(new Pair<>(GraphicsType.SPICE, DisplayType.cirrus));
    gndDefaultOs.add(new Pair<>(GraphicsType.VNC, DisplayType.cirrus));
    final List<Pair<GraphicsType, DisplayType>> gndExistingOs = new ArrayList<>();
    gndExistingOs.add(new Pair<>(GraphicsType.SPICE, DisplayType.cirrus));
    when(osRepository.getArchitectureFromOS(anyInt())).thenReturn(ArchitectureType.x86_64);
    when(osRepository.getUniqueOsNames()).thenReturn(osIdsToNames);
    when(osRepository.getOsIdByUniqueName(any())).thenAnswer(invocation -> osIdsToNames.entrySet().stream().filter(k -> invocation.getArguments()[0].equals(k.getValue())).map(Map.Entry::getKey).findFirst().orElse(0));
    when(osRepository.getGraphicsAndDisplays(eq(DEFAULT_OS_ID), any())).thenReturn(gndDefaultOs);
    when(osRepository.getGraphicsAndDisplays(eq(EXISTING_OS_ID), any())).thenReturn(gndExistingOs);
    doNothing().when(manager).updateBootOrderOnDevices(any(), anyBoolean());
    Map<Integer, VmIconIdSizePair> iconDefaults = new HashMap<>();
    iconDefaults.put(DEFAULT_OS_ID, new VmIconIdSizePair(SMALL_DEFAULT_ICON_ID, LARGE_DEFAULT_ICON_ID));
    iconDefaults.put(EXISTING_OS_ID, new VmIconIdSizePair(SMALL_ICON_ID, LARGE_ICON_ID));
    when(iconDefaultsProvider.getVmIconDefaults()).thenReturn(iconDefaults);
}
Also used : HashMap(java.util.HashMap) VmIconIdSizePair(org.ovirt.engine.core.common.queries.VmIconIdSizePair) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) VmIconIdSizePair(org.ovirt.engine.core.common.queries.VmIconIdSizePair) Pair(org.ovirt.engine.core.common.utils.Pair) Before(org.junit.Before)

Aggregations

VmIconIdSizePair (org.ovirt.engine.core.common.queries.VmIconIdSizePair)12 HashMap (java.util.HashMap)3 Map (java.util.Map)2 VmIconDefault (org.ovirt.engine.core.common.businessentities.VmIconDefault)2 Guid (org.ovirt.engine.core.compat.Guid)2 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 OperatingSystemInfo (org.ovirt.engine.api.model.OperatingSystemInfo)1 OperatingSystemInfos (org.ovirt.engine.api.model.OperatingSystemInfos)1 AddVmParameters (org.ovirt.engine.core.common.action.AddVmParameters)1 VmRngDevice (org.ovirt.engine.core.common.businessentities.VmRngDevice)1 VmStatic (org.ovirt.engine.core.common.businessentities.VmStatic)1 EngineException (org.ovirt.engine.core.common.errors.EngineException)1 OsRepository (org.ovirt.engine.core.common.osinfo.OsRepository)1 Pair (org.ovirt.engine.core.common.utils.Pair)1