Search in sources :

Example 1 with ResourceRelated

use of org.btrplace.model.view.ResourceRelated in project scheduler by btrplace.

the class CShareableResource method getMisPlacedVMs.

/**
 * {@inheritDoc}
 *
 * @param i the model to use to inspect the VMs.
 * @return the set of VMs that cannot have their associated {@link Preserve} constraint satisfy with regards
 * to a possible {@link Overbook} and single-node {@link ResourceCapacity} constraint.
 */
@Override
public Set<VM> getMisPlacedVMs(Instance i) {
    final TObjectDoubleMap<Node> wantedRatios = new TObjectDoubleHashMap<>();
    final int nbVMs = i.getModel().getMapping().getNbVMs();
    final int nbNodes = i.getModel().getMapping().getNbNodes();
    final IntMap wantedAmount = new IntMap(0, nbVMs);
    final IntMap wantedCapacity = new IntMap(0, nbNodes);
    for (SatConstraint c : i.getSatConstraints()) {
        if (!(c instanceof ResourceRelated && ((ResourceRelated) c).getResource().equals(rc.getResourceIdentifier()))) {
            continue;
        }
        if (c instanceof Preserve) {
            // We guarantee the highest request so far.
            VM v = c.getInvolvedVMs().iterator().next();
            int qty = ((Preserve) c).getAmount();
            wantedAmount.put(v.id(), Math.max(wantedAmount.get(v.id()), qty));
        } else if (c instanceof Overbook) {
            Node n = c.getInvolvedNodes().iterator().next();
            double min = ((Overbook) c).getRatio();
            if (wantedRatios.containsKey(n)) {
                min = Math.min(min, wantedRatios.get(n));
            }
            wantedRatios.put(n, min);
        } else if (c instanceof ResourceCapacity && c.getInvolvedNodes().size() == 1) {
            Node n = c.getInvolvedNodes().iterator().next();
            int qty = ((ResourceCapacity) c).getAmount();
            wantedCapacity.put(n.id(), Math.max(qty, wantedCapacity.get(n.id())));
        }
    }
    Mapping m = i.getModel().getMapping();
    Set<VM> candidates = new HashSet<>();
    for (Node n : m.getOnlineNodes()) {
        Set<VM> running = m.getRunningVMs(n);
        if (overloaded(wantedRatios, wantedAmount, wantedCapacity, running, n)) {
            candidates.addAll(running);
        }
    }
    return candidates;
}
Also used : SatConstraint(org.btrplace.model.constraint.SatConstraint) SatConstraint(org.btrplace.model.constraint.SatConstraint) Preserve(org.btrplace.model.constraint.Preserve) TObjectDoubleHashMap(gnu.trove.map.hash.TObjectDoubleHashMap) ResourceCapacity(org.btrplace.model.constraint.ResourceCapacity) ResourceRelated(org.btrplace.model.view.ResourceRelated) Overbook(org.btrplace.model.constraint.Overbook) TObjectIntMap(gnu.trove.map.TObjectIntMap) IntMap(org.btrplace.util.IntMap)

Aggregations

TObjectIntMap (gnu.trove.map.TObjectIntMap)1 TObjectDoubleHashMap (gnu.trove.map.hash.TObjectDoubleHashMap)1 Overbook (org.btrplace.model.constraint.Overbook)1 Preserve (org.btrplace.model.constraint.Preserve)1 ResourceCapacity (org.btrplace.model.constraint.ResourceCapacity)1 SatConstraint (org.btrplace.model.constraint.SatConstraint)1 ResourceRelated (org.btrplace.model.view.ResourceRelated)1 IntMap (org.btrplace.util.IntMap)1