use of org.btrplace.model.constraint.RunningCapacity in project scheduler by btrplace.
the class RunningCapacityConverterTest method testViables.
@Test
public void testViables() throws JSONConverterException {
ConstraintsConverter conv = new ConstraintsConverter();
conv.register(new RunningCapacityConverter());
Model mo = new DefaultModel();
RunningCapacity d = new RunningCapacity(new HashSet<>(Arrays.asList(mo.newNode(), mo.newNode(), mo.newNode())), 5);
Assert.assertEquals(conv.fromJSON(mo, conv.toJSON(d)), d);
System.out.println(conv.toJSON(d));
}
use of org.btrplace.model.constraint.RunningCapacity in project scheduler by btrplace.
the class ModelCustomization method makeConstraints.
private List<SatConstraint> makeConstraints(Model model) {
List<SatConstraint> cstrs = new ArrayList<>();
// No more than 5 VMs per node
for (Node n : model.getMapping().getAllNodes()) {
cstrs.add(new RunningCapacity(n, 5));
}
// vm1 and vm10 on the same node
cstrs.add(new Gather(Arrays.asList(vms.get(0), vms.get(9))));
// (vm1, vm2, vm4) and (vm5, vm6, vm8) must not share node
Collection<VM> g1 = Arrays.asList(vms.get(0), vms.get(1), vms.get(3));
Collection<VM> g2 = Arrays.asList(vms.get(4), vms.get(5), vms.get(7));
cstrs.add(new Split(Arrays.asList(g1, g2)));
// vm10 must be running
cstrs.add(new Running(vms.get(9)));
return cstrs;
}
use of org.btrplace.model.constraint.RunningCapacity in project scheduler by btrplace.
the class ScriptTest method testConstraints.
public void testConstraints() {
Script v = new Script();
Model mo = new DefaultModel();
VM vm2 = mo.newVM();
v.addConstraint(new Gather(Collections.singleton(vm2)));
v.addConstraint(new RunningCapacity(Collections.singleton(mo.newNode()), 5));
Assert.assertEquals(v.getConstraints().size(), 2);
}
use of org.btrplace.model.constraint.RunningCapacity in project scheduler by btrplace.
the class IssuesTest method testIssue86.
@Test
public void testIssue86() throws Exception {
Model mo = new DefaultModel();
mo.getMapping().addReadyVM(mo.newVM());
mo.getMapping().addReadyVM(mo.newVM());
mo.getMapping().addReadyVM(mo.newVM());
mo.getMapping().addOnlineNode(mo.newNode());
mo.getMapping().addOnlineNode(mo.newNode());
mo.getMapping().addOnlineNode(mo.newNode());
List<SatConstraint> cstrs = mo.getMapping().getAllVMs().stream().map(Running::new).collect(Collectors.toList());
cstrs.add(new Spread(mo.getMapping().getAllVMs(), false));
cstrs.addAll(mo.getMapping().getOnlineNodes().stream().map(n -> new RunningCapacity(n, 1)).collect(Collectors.toList()));
Instance i = new Instance(mo, cstrs, new MinMTTR());
ChocoScheduler s = new DefaultChocoScheduler();
s.doOptimize(false);
s.doRepair(false);
ReconfigurationPlan p = s.solve(i.getModel(), i.getSatConstraints(), i.getOptConstraint());
Assert.assertNotNull(p);
Assert.assertEquals(3, p.getActions().size());
s.doRepair(true);
p = s.solve(i.getModel(), i.getSatConstraints(), i.getOptConstraint());
Assert.assertNotNull(p);
Assert.assertEquals(3, p.getActions().size());
}
use of org.btrplace.model.constraint.RunningCapacity in project scheduler by btrplace.
the class RunningCapacityBuilderTest method testGoodSignatures.
@Test(dataProvider = "goodCapacities")
public void testGoodSignatures(String str, int nbNodes, int capa, boolean c) throws Exception {
ScriptBuilder b = new ScriptBuilder(new DefaultModel());
Set<SatConstraint> cstrs = b.build("namespace test; VM[1..10] : tiny;\n@N[1..20] : defaultNode;\n" + str).getConstraints();
Assert.assertEquals(cstrs.size(), 1);
RunningCapacity x = (RunningCapacity) cstrs.iterator().next();
Assert.assertEquals(x.getInvolvedNodes().size(), nbNodes);
Assert.assertEquals(x.getAmount(), capa);
Assert.assertEquals(x.isContinuous(), c);
}
Aggregations