Search in sources :

Example 6 with VdsNumaNode

use of org.ovirt.engine.core.common.businessentities.VdsNumaNode in project ovirt-engine by oVirt.

the class NumaSupportModel method initFirstLevelDistanceSetList.

private void initFirstLevelDistanceSetList() {
    firstLevelDistanceSetList = new ArrayList<>();
    for (VdsNumaNode node : getNumaNodeList()) {
        Map<Integer, Set<VdsNumaNode>> distances = new HashMap<>();
        for (Entry<Integer, Integer> entry : node.getNumaNodeDistances().entrySet()) {
            Set<VdsNumaNode> sameDistanceNodes = distances.get(entry.getValue());
            if (sameDistanceNodes == null) {
                sameDistanceNodes = new HashSet<>();
                sameDistanceNodes.add(getNodeByIndex(entry.getKey()));
                distances.put(entry.getValue(), sameDistanceNodes);
            }
            sameDistanceNodes.add(node);
        }
        Entry<Integer, Set<VdsNumaNode>> minDistance = null;
        for (Entry<Integer, Set<VdsNumaNode>> entry : distances.entrySet()) {
            if (minDistance == null || entry.getKey() < minDistance.getKey()) {
                minDistance = entry;
            }
        }
        boolean found = false;
        for (Pair<Integer, Set<VdsNumaNode>> group : firstLevelDistanceSetList) {
            // 'true' if the two specified collections have no elements in common
            boolean isDisjoint = Collections.disjoint(group.getSecond(), minDistance.getValue());
            if (group.getFirst().equals(minDistance.getKey()) && !isDisjoint) {
                group.getSecond().addAll(minDistance.getValue());
                found = true;
                break;
            }
        }
        if (!found && minDistance != null) {
            firstLevelDistanceSetList.add(new Pair<>(minDistance.getKey(), minDistance.getValue()));
        }
    }
}
Also used : HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) HashMap(java.util.HashMap) VdsNumaNode(org.ovirt.engine.core.common.businessentities.VdsNumaNode)

Example 7 with VdsNumaNode

use of org.ovirt.engine.core.common.businessentities.VdsNumaNode in project ovirt-engine by oVirt.

the class BackendHostNumaNodesResource method list.

@Override
public NumaNodes list() {
    NumaNodes ret = new NumaNodes();
    List<VdsNumaNode> nodes = getCollection();
    for (VdsNumaNode node : nodes) {
        NumaNode numanode = populate(map(node, null), node);
        ret.getNumaNodes().add(addLinks(numanode));
    }
    return ret;
}
Also used : VdsNumaNode(org.ovirt.engine.core.common.businessentities.VdsNumaNode) NumaNodes(org.ovirt.engine.api.model.NumaNodes) NumaNode(org.ovirt.engine.api.model.NumaNode) VdsNumaNode(org.ovirt.engine.core.common.businessentities.VdsNumaNode)

Example 8 with VdsNumaNode

use of org.ovirt.engine.core.common.businessentities.VdsNumaNode in project ovirt-engine by oVirt.

the class NumaMapper method map.

@Mapping(from = VdsNumaNode.class, to = NumaNode.class)
public static NumaNode map(VdsNumaNode entity, NumaNode template) {
    NumaNode model = template != null ? template : new NumaNode();
    if (entity.getId() != null) {
        model.setId(entity.getId().toString());
    }
    model.setIndex(entity.getIndex());
    model.setMemory(entity.getMemTotal());
    if (entity.getCpuIds() != null && entity.getCpuIds().size() > 0) {
        Cpu cpu = new Cpu();
        Cores cores = new Cores();
        for (int id : entity.getCpuIds()) {
            Core core = new Core();
            core.setIndex(id);
            cores.getCores().add(core);
        }
        cpu.setCores(cores);
        model.setCpu(cpu);
    }
    if (entity.getNumaNodeDistances() != null && entity.getNumaNodeDistances().size() > 0) {
        model.setNodeDistance(StringUtils.join(entity.getNumaNodeDistances().values(), " "));
    }
    return model;
}
Also used : Cores(org.ovirt.engine.api.model.Cores) Cpu(org.ovirt.engine.api.model.Cpu) VmNumaNode(org.ovirt.engine.core.common.businessentities.VmNumaNode) NumaNode(org.ovirt.engine.api.model.NumaNode) VdsNumaNode(org.ovirt.engine.core.common.businessentities.VdsNumaNode) VirtualNumaNode(org.ovirt.engine.api.model.VirtualNumaNode) Core(org.ovirt.engine.api.model.Core)

Example 9 with VdsNumaNode

use of org.ovirt.engine.core.common.businessentities.VdsNumaNode in project ovirt-engine by oVirt.

the class NumaSupportModel method initVNumaNodes.

protected void initVNumaNodes() {
    unassignedNumaNodes = new LinkedHashSet<>();
    assignedNumaNodes = new HashMap<>();
    final Set<Integer> hostIndices = new HashSet<>();
    for (VdsNumaNode numaNode : numaNodeList) {
        hostIndices.add(numaNode.getIndex());
    }
    for (final VM vm : getVmsWithvNumaNodeList()) {
        numaModelsPerVm.put(vm.getId(), new HashMap<Integer, VNodeModel>());
        for (VmNumaNode vmNumaNode : vm.getvNumaNodeList()) {
            VNodeModel vNodeModel = new VNodeModel(vm, vmNumaNode);
            numaModelsPerVm.get(vm.getId()).put(vNodeModel.getIndex(), vNodeModel);
            if (vNodeModel.isPinned()) {
                if (!hostIndices.contains(vNodeModel.getHostNodeIndex())) {
                    // host numa node does not exist. Unpin the numa node and update the configuration
                    vNodeModel.unpin();
                    vmsToUpdate.add(vm.getId());
                }
            }
            if (!vNodeModel.isPinned()) {
                // virtual numa node is not assigned to any host numa node
                unassignedNumaNodes.add(vNodeModel);
            } else {
                // virtual numa node is assigned to a host numa node
                assignVNumaToPhysicalNuma(vNodeModel);
            }
        }
    }
}
Also used : VdsNumaNode(org.ovirt.engine.core.common.businessentities.VdsNumaNode) VmNumaNode(org.ovirt.engine.core.common.businessentities.VmNumaNode) VM(org.ovirt.engine.core.common.businessentities.VM) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 10 with VdsNumaNode

use of org.ovirt.engine.core.common.businessentities.VdsNumaNode in project ovirt-engine by oVirt.

the class VdsManager method updateNumaData.

/**
 * Save or update numa data to DB
 */
public void updateNumaData(final VDS vds) {
    if (vds.getNumaNodeList() == null || vds.getNumaNodeList().isEmpty()) {
        return;
    }
    final List<VdsNumaNode> numaNodesToSave = new ArrayList<>();
    final List<VdsNumaNode> numaNodesToUpdate = new ArrayList<>();
    final List<Guid> numaNodesToRemove = new ArrayList<>();
    List<VdsNumaNode> dbVdsNumaNodes = vdsNumaNodeDao.getAllVdsNumaNodeByVdsId(vds.getId());
    for (VdsNumaNode node : vds.getNumaNodeList()) {
        VdsNumaNode searchNode = NumaUtils.getVdsNumaNodeByIndex(dbVdsNumaNodes, node.getIndex());
        if (searchNode != null) {
            node.setId(searchNode.getId());
            numaNodesToUpdate.add(node);
            dbVdsNumaNodes.remove(searchNode);
        } else {
            node.setId(Guid.newGuid());
            numaNodesToSave.add(node);
        }
    }
    for (VdsNumaNode node : dbVdsNumaNodes) {
        numaNodesToRemove.add(node.getId());
    }
    // The database operation should be in one transaction
    TransactionSupport.executeInScope(TransactionScopeOption.Required, () -> {
        if (!numaNodesToRemove.isEmpty()) {
            vdsNumaNodeDao.massRemoveNumaNodeByNumaNodeId(numaNodesToRemove);
        }
        if (!numaNodesToUpdate.isEmpty()) {
            vdsNumaNodeDao.massUpdateNumaNode(numaNodesToUpdate);
        }
        if (!numaNodesToSave.isEmpty()) {
            vdsNumaNodeDao.massSaveNumaNode(numaNodesToSave, vds.getId());
        }
        return null;
    });
}
Also used : VdsNumaNode(org.ovirt.engine.core.common.businessentities.VdsNumaNode) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid)

Aggregations

VdsNumaNode (org.ovirt.engine.core.common.businessentities.VdsNumaNode)22 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)6 VmNumaNode (org.ovirt.engine.core.common.businessentities.VmNumaNode)6 Map (java.util.Map)3 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 Test (org.junit.Test)2 NumaNode (org.ovirt.engine.api.model.NumaNode)2 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)2 CpuStatistics (org.ovirt.engine.core.common.businessentities.CpuStatistics)2 NumaNodeStatistics (org.ovirt.engine.core.common.businessentities.NumaNodeStatistics)2 Guid (org.ovirt.engine.core.compat.Guid)2 HTML (com.google.gwt.user.client.ui.HTML)1 DecimalFormat (java.text.DecimalFormat)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Set (java.util.Set)1 Core (org.ovirt.engine.api.model.Core)1 Cores (org.ovirt.engine.api.model.Cores)1