Search in sources :

Example 6 with KeyValuePairCompat

use of org.ovirt.engine.core.compat.KeyValuePairCompat in project ovirt-engine by oVirt.

the class AsyncDataProvider method cacheConfigValues.

/**
 * Cache configuration values [raw (not converted) values from vdc_options table].
 */
private void cacheConfigValues(AsyncQuery<Map<KeyValuePairCompat<ConfigValues, String>, Object>> aQuery) {
    aQuery.converterCallback = returnValue -> {
        if (returnValue != null) {
            cachedConfigValuesPreConvert.putAll((HashMap<KeyValuePairCompat<ConfigValues, String>, Object>) returnValue);
        }
        return cachedConfigValuesPreConvert;
    };
    Frontend.getInstance().runQuery(QueryType.GetConfigurationValues, new QueryParametersBase(), aQuery);
}
Also used : KeyValuePairCompat(org.ovirt.engine.core.compat.KeyValuePairCompat) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) StorageServerConnectionQueryParametersBase(org.ovirt.engine.core.common.queries.StorageServerConnectionQueryParametersBase) RefObject(org.ovirt.engine.core.compat.RefObject)

Example 7 with KeyValuePairCompat

use of org.ovirt.engine.core.compat.KeyValuePairCompat in project ovirt-engine by oVirt.

the class GetConfigurationValuesQuery method executeQueryCommand.

@Override
protected void executeQueryCommand() {
    Map<KeyValuePairCompat<ConfigValues, String>, Object> configValuesMap = new HashMap<>();
    for (ConfigValues configValue : ConfigValues.values()) {
        // Ignore an admin configuration value on filtered mode
        if (!shouldReturnValue(configValue) || configValue == ConfigValues.Invalid) {
            continue;
        }
        Map<String, Object> values = Config.getValuesForAllVersions(configValue);
        for (Map.Entry<String, Object> entry : values.entrySet()) {
            KeyValuePairCompat<ConfigValues, String> key = new KeyValuePairCompat<>(configValue, entry.getKey());
            configValuesMap.put(key, entry.getValue());
        }
    }
    getQueryReturnValue().setReturnValue(configValuesMap);
}
Also used : KeyValuePairCompat(org.ovirt.engine.core.compat.KeyValuePairCompat) HashMap(java.util.HashMap) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) Map(java.util.Map) HashMap(java.util.HashMap)

Example 8 with KeyValuePairCompat

use of org.ovirt.engine.core.compat.KeyValuePairCompat in project ovirt-engine by oVirt.

the class ExportVmCommand method updateCopyVmInSpm.

private void updateCopyVmInSpm(Guid storagePoolId, VM vm, Guid storageDomainId) {
    HashMap<Guid, KeyValuePairCompat<String, List<Guid>>> vmsAndMetaDictionary = new HashMap<>();
    List<DiskImage> vmImages = new ArrayList<>();
    List<LunDisk> lunDisks = new ArrayList<>();
    List<VmNetworkInterface> interfaces = vm.getInterfaces();
    if (interfaces != null) {
        // TODO remove this when the API changes
        interfaces.clear();
        interfaces.addAll(vmNetworkInterfaceDao.getAllForVm(vm.getId()));
    }
    List<Guid> imageGroupIds = new ArrayList<>();
    for (Disk disk : getDisksBasedOnImage()) {
        DiskImage diskImage = (DiskImage) disk;
        diskImage.setParentId(VmTemplateHandler.BLANK_VM_TEMPLATE_ID);
        diskImage.setImageTemplateId(VmTemplateHandler.BLANK_VM_TEMPLATE_ID);
        diskImage.setStorageIds(new ArrayList<>(Collections.singletonList(storageDomainId)));
        DiskImage diskForVolumeInfo = getDiskForVolumeInfo(diskImage);
        diskImage.setVolumeFormat(diskForVolumeInfo.getVolumeFormat());
        diskImage.setVolumeType(diskForVolumeInfo.getVolumeType());
        VDSReturnValue vdsReturnValue = runVdsCommand(VDSCommandType.GetImageInfo, new GetImageInfoVDSCommandParameters(storagePoolId, storageDomainId, diskImage.getId(), diskImage.getImageId()));
        if (vdsReturnValue != null && vdsReturnValue.getSucceeded()) {
            DiskImage fromVdsm = (DiskImage) vdsReturnValue.getReturnValue();
            diskImage.setActualSizeInBytes(fromVdsm.getActualSizeInBytes());
        }
        vmImages.add(diskImage);
        imageGroupIds.add(disk.getId());
    }
    if (StringUtils.isEmpty(vm.getVmtName())) {
        VmTemplate t = vmTemplateDao.get(vm.getVmtGuid());
        vm.setVmtName(t.getName());
    }
    lunDisks.addAll(DisksFilter.filterLunDisks(getVm().getDiskMap().values(), ONLY_NOT_SHAREABLE));
    lunDisks.forEach(lun -> lun.getLun().setLunConnections(new ArrayList<>(storageServerConnectionDao.getAllForLun(lun.getLun().getId()))));
    getVm().setVmtGuid(VmTemplateHandler.BLANK_VM_TEMPLATE_ID);
    FullEntityOvfData fullEntityOvfData = new FullEntityOvfData(vm);
    fullEntityOvfData.setClusterName(vm.getClusterName());
    fullEntityOvfData.setDiskImages(vmImages);
    fullEntityOvfData.setLunDisks(lunDisks);
    String vmMeta = ovfManager.exportVm(vm, fullEntityOvfData, clusterUtils.getCompatibilityVersion(vm));
    vmsAndMetaDictionary.put(vm.getId(), new KeyValuePairCompat<>(vmMeta, imageGroupIds));
    UpdateVMVDSCommandParameters tempVar = new UpdateVMVDSCommandParameters(storagePoolId, vmsAndMetaDictionary);
    tempVar.setStorageDomainId(storageDomainId);
    runVdsCommand(VDSCommandType.UpdateVM, tempVar);
}
Also used : GetImageInfoVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.GetImageInfoVDSCommandParameters) KeyValuePairCompat(org.ovirt.engine.core.compat.KeyValuePairCompat) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UpdateVMVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.UpdateVMVDSCommandParameters) 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) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk)

Example 9 with KeyValuePairCompat

use of org.ovirt.engine.core.compat.KeyValuePairCompat in project ovirt-engine by oVirt.

the class ProcessOvfUpdateForStoragePoolCommandTest method mockAnswers.

private void mockAnswers() {
    doAnswer(invocation -> {
        VM vm = (VM) invocation.getArguments()[0];
        return vm.getId().toString();
    }).when(ovfUpdateProcessHelper).generateVmMetadata(any(), any());
    doAnswer(invocation -> {
        VmTemplate template = (VmTemplate) ((FullEntityOvfData) invocation.getArguments()[0]).getVmBase();
        return template.getId().toString();
    }).when(ovfUpdateProcessHelper).generateVmTemplateMetadata(any());
    doAnswer(invocation -> {
        List<Guid> neededIds = (List<Guid>) invocation.getArguments()[0];
        return neededIds.stream().map(id -> vms.get(id)).collect(Collectors.toList());
    }).when(vmDao).getVmsByIds(any());
    doAnswer(invocation -> {
        List<Guid> neededIds = (List<Guid>) invocation.getArguments()[0];
        return neededIds.stream().map(id -> templates.get(id)).collect(Collectors.toList());
    }).when(vmTemplateDao).getVmTemplatesByIds(any());
    doAnswer(invocation -> {
        Map<Guid, KeyValuePairCompat<String, List<Guid>>> updateMap = (Map<Guid, KeyValuePairCompat<String, List<Guid>>>) invocation.getArguments()[1];
        assertTrue("too many ovfs were sent in one vdsm call", updateMap.size() <= ITEMS_COUNT_PER_UPDATE);
        return true;
    }).when(ovfUpdateProcessHelper).executeUpdateVmInSpmCommand(any(), any(), any());
    doReturn(true).when(ovfUpdateProcessHelper).executeRemoveVmInSpm(any(), any(), any());
    doAnswer(invocation -> {
        List<Guid> ids = (List<Guid>) invocation.getArguments()[0];
        List<Long> values = (List<Long>) invocation.getArguments()[1];
        assertFalse("update of ovf version in db shouldn't be called with an empty value list", values.isEmpty());
        assertTrue("update of ovf version in db shouldn't be called with more items then MAX_ITEMS_PER_SQL_STATEMENT", values.size() <= StorageConstants.OVF_MAX_ITEMS_PER_SQL_STATEMENT);
        assertEquals("the size of the list of ids for update is not the same as the size of the " + "list with the new ovf values", values.size(), ids.size());
        Guid[] ids_array = ids.toArray(new Guid[ids.size()]);
        Long[] values_array = values.toArray(new Long[values.size()]);
        for (int i = 0; i < ids_array.length; i++) {
            executedUpdatedOvfGenerationIdsInDb.put(ids_array[i], values_array[i]);
        }
        return null;
    }).when(vmAndTemplatesGenerationsDao).updateOvfGenerations(any(), any(), any());
    doAnswer(invocation -> {
        StoragePoolStatus desiredStatus = (StoragePoolStatus) invocation.getArguments()[0];
        return buildStoragePoolsList().stream().filter(p -> desiredStatus.equals(p.getStatus())).collect(Collectors.toList());
    }).when(storagePoolDao).getAllByStatus(any());
    doReturn(poolDomainsOvfInfo.values().stream().map(Pair::getSecond).collect(Collectors.toList())).when(storageDomainDao).getAllForStoragePool(any());
    doAnswer(invocation -> {
        Guid domainId = (Guid) invocation.getArguments()[0];
        Pair<List<StorageDomainOvfInfo>, StorageDomain> pair = poolDomainsOvfInfo.get(domainId);
        if (pair != null) {
            return pair.getFirst();
        }
        return null;
    }).when(storageDomainOvfInfoDao).getAllForDomain(any());
}
Also used : ClusterDao(org.ovirt.engine.core.dao.ClusterDao) SnapshotDao(org.ovirt.engine.core.dao.SnapshotDao) VmTemplateDao(org.ovirt.engine.core.dao.VmTemplateDao) VmStaticDao(org.ovirt.engine.core.dao.VmStaticDao) KeyValuePairCompat(org.ovirt.engine.core.compat.KeyValuePairCompat) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) Spy(org.mockito.Spy) Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) StorageDomainOvfInfoDao(org.ovirt.engine.core.dao.StorageDomainOvfInfoDao) StoragePoolDao(org.ovirt.engine.core.dao.StoragePoolDao) ClassRule(org.junit.ClassRule) Mockito.doReturn(org.mockito.Mockito.doReturn) MockConfigRule.mockConfig(org.ovirt.engine.core.utils.MockConfigRule.mockConfig) Collection(java.util.Collection) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) StorageConstants(org.ovirt.engine.core.common.constants.StorageConstants) Set(java.util.Set) Mockito.doNothing(org.mockito.Mockito.doNothing) Collectors(java.util.stream.Collectors) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) VmDao(org.ovirt.engine.core.dao.VmDao) ProcessOvfUpdateParameters(org.ovirt.engine.core.common.action.ProcessOvfUpdateParameters) DbUserDao(org.ovirt.engine.core.dao.DbUserDao) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) VmAndTemplatesGenerationsDao(org.ovirt.engine.core.dao.VmAndTemplatesGenerationsDao) LabelDao(org.ovirt.engine.core.dao.LabelDao) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IntStream(java.util.stream.IntStream) MockConfigRule(org.ovirt.engine.core.utils.MockConfigRule) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) Mock(org.mockito.Mock) Guid(org.ovirt.engine.core.compat.Guid) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StorageDomainOvfInfo(org.ovirt.engine.core.common.businessentities.StorageDomainOvfInfo) HashMap(java.util.HashMap) StorageDomainStatus(org.ovirt.engine.core.common.businessentities.StorageDomainStatus) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) ArrayList(java.util.ArrayList) ImageStatus(org.ovirt.engine.core.common.businessentities.storage.ImageStatus) CollectionUtils(org.apache.commons.collections.CollectionUtils) AffinityGroupDao(org.ovirt.engine.core.dao.scheduling.AffinityGroupDao) StorageDomainOvfInfoStatus(org.ovirt.engine.core.common.businessentities.StorageDomainOvfInfoStatus) LinkedList(java.util.LinkedList) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) Pair(org.ovirt.engine.core.common.utils.Pair) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) StoragePoolStatus(org.ovirt.engine.core.common.businessentities.StoragePoolStatus) FullEntityOvfData(org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData) VmTemplateStatus(org.ovirt.engine.core.common.businessentities.VmTemplateStatus) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) PermissionDao(org.ovirt.engine.core.dao.PermissionDao) BaseCommandTest(org.ovirt.engine.core.bll.BaseCommandTest) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) VM(org.ovirt.engine.core.common.businessentities.VM) StorageDomainDao(org.ovirt.engine.core.dao.StorageDomainDao) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) VMStatus(org.ovirt.engine.core.common.businessentities.VMStatus) StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) KeyValuePairCompat(org.ovirt.engine.core.compat.KeyValuePairCompat) StoragePoolStatus(org.ovirt.engine.core.common.businessentities.StoragePoolStatus) Guid(org.ovirt.engine.core.compat.Guid) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) VM(org.ovirt.engine.core.common.businessentities.VM) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Map(java.util.Map) HashMap(java.util.HashMap) StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 10 with KeyValuePairCompat

use of org.ovirt.engine.core.compat.KeyValuePairCompat in project ovirt-engine by oVirt.

the class GetStoragePoolInfoVDSCommand method executeIrsBrokerCommand.

@Override
protected void executeIrsBrokerCommand() {
    result = getIrsProxy().getStoragePoolInfo(getParameters().getStoragePoolId().toString());
    proceedProxyReturnValue();
    StoragePool sp = VdsBrokerObjectsBuilder.buildStoragePool(result.storagePoolInfo);
    Guid masterId = Guid.Empty;
    if (result.storagePoolInfo.containsKey("master_uuid")) {
        masterId = new Guid(result.storagePoolInfo.get("master_uuid").toString());
    }
    sp.setId(getParameters().getStoragePoolId());
    ArrayList<StorageDomain> domList = parseStorageDomainList(result.domainsList, masterId);
    KeyValuePairCompat<StoragePool, List<StorageDomain>> list = new KeyValuePairCompat<>(sp, domList);
    setReturnValue(list);
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) KeyValuePairCompat(org.ovirt.engine.core.compat.KeyValuePairCompat) ArrayList(java.util.ArrayList) List(java.util.List) Guid(org.ovirt.engine.core.compat.Guid)

Aggregations

KeyValuePairCompat (org.ovirt.engine.core.compat.KeyValuePairCompat)12 Guid (org.ovirt.engine.core.compat.Guid)10 HashMap (java.util.HashMap)8 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 FullEntityOvfData (org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData)4 List (java.util.List)3 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)2 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)2 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)2 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)2 LunDisk (org.ovirt.engine.core.common.businessentities.storage.LunDisk)2 ConfigValues (org.ovirt.engine.core.common.config.ConfigValues)2 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)2