use of org.btrplace.model.constraint.ResourceCapacity in project scheduler by btrplace.
the class ResourceCapacityBuilder method buildConstraint.
@Override
public List<? extends SatConstraint> buildConstraint(BtrPlaceTree t, List<BtrpOperand> args) {
if (!checkConformance(t, args)) {
return Collections.emptyList();
}
@SuppressWarnings("unchecked") List<Node> ns = (List<Node>) params[0].transform(this, t, args.get(0));
String rcId = (String) params[1].transform(this, t, args.get(1));
BtrpNumber n = (BtrpNumber) args.get(2);
if (!n.isInteger()) {
t.ignoreError("Parameter '" + params[2].getName() + "' expects an integer");
return Collections.emptyList();
}
int v = n.getIntValue();
if (v < 0) {
t.ignoreError("Parameter '" + params[2].getName() + "' expects a positive integer (" + v + " given)");
return Collections.emptyList();
}
return ns != null ? Collections.singletonList(new ResourceCapacity(new HashSet<>(ns), rcId, v)) : Collections.emptyList();
}
use of org.btrplace.model.constraint.ResourceCapacity 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) {
for (SatConstraint c : i.getSatConstraints()) {
if (!(c instanceof ResourceRelated && ((ResourceRelated) c).getResource().equals(rc.getResourceIdentifier()))) {
continue;
}
if (c instanceof Preserve) {
VM v = c.getInvolvedVMs().iterator().next();
wantedAmount.put(v, consumption(v, ((Preserve) c).getAmount()));
} else if (c instanceof Overbook) {
Node n = c.getInvolvedNodes().iterator().next();
wantedRatios.put(n, ratio(n, ((Overbook) c).getRatio()));
} else if (c instanceof ResourceCapacity && c.getInvolvedNodes().size() == 1) {
Node n = c.getInvolvedNodes().iterator().next();
wantedCapacity.put(n, capacity(n, ((ResourceCapacity) c).getAmount()));
}
}
Mapping m = i.getModel().getMapping();
Set<VM> candidates = new HashSet<>();
for (Node n : m.getOnlineNodes()) {
if (overloaded(m, n)) {
candidates.addAll(m.getRunningVMs(n));
}
}
return candidates;
}
use of org.btrplace.model.constraint.ResourceCapacity in project scheduler by btrplace.
the class ResourceCapacityConverterTest method testViables.
@Test
public void testViables() throws JSONConverterException {
ConstraintsConverter conv = new ConstraintsConverter();
conv.register(new ResourceCapacityConverter());
Model mo = new DefaultModel();
ResourceCapacity d = new ResourceCapacity(new HashSet<>(Arrays.asList(mo.newNode(), mo.newNode(), mo.newNode())), "cpu", 5, false);
ResourceCapacity c = new ResourceCapacity(new HashSet<>(Arrays.asList(mo.newNode(), mo.newNode())), "mem", 5, true);
Assert.assertEquals(conv.fromJSON(mo, conv.toJSON(d)), d);
Assert.assertEquals(conv.fromJSON(mo, conv.toJSON(c)), c);
System.out.println(conv.toJSON(d));
}
use of org.btrplace.model.constraint.ResourceCapacity in project scheduler by btrplace.
the class ResourceCapacityBuilderTest method testGoodSignatures.
@Test(dataProvider = "goodResources")
public void testGoodSignatures(String str, int nbNodes, String rcId, int capa, boolean c) throws Exception {
ScriptBuilder b = new ScriptBuilder(new DefaultModel());
ResourceCapacity x = (ResourceCapacity) b.build("namespace test; VM[1..10] : tiny;\n@N[1..20] : defaultNode;\n" + str).getConstraints().iterator().next();
Assert.assertEquals(x.getInvolvedNodes().size(), nbNodes);
Assert.assertEquals(x.getResource(), rcId);
Assert.assertEquals(x.getAmount(), capa);
Assert.assertEquals(x.isContinuous(), c);
}
Aggregations