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;
}
Aggregations