use of org.btrplace.model.constraint.Overbook in project scheduler by btrplace.
the class COverbookTest method testGetMisplaced.
@Test
public void testGetMisplaced() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
VM vm4 = mo.newVM();
VM vm5 = mo.newVM();
VM vm6 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
mo.getMapping().on(n1, n2, n3).run(n1, vm1).run(n2, vm2, vm3).run(n3, vm4, vm5, vm6);
ShareableResource rcCPU = new ShareableResource("cpu", 1, 1);
mo.attach(rcCPU);
Overbook o1 = new Overbook(n1, "cpu", 1);
Overbook o2 = new Overbook(n2, "cpu", 2);
Overbook o3 = new Overbook(n3, "cpu", 3);
COverbook co1 = new COverbook(o1);
COverbook co2 = new COverbook(o2);
COverbook co3 = new COverbook(o3);
Instance i = new Instance(mo, Collections.emptyList(), new MinMTTR());
Assert.assertTrue(co1.getMisPlacedVMs(i).isEmpty());
Assert.assertTrue(co2.getMisPlacedVMs(i).isEmpty());
Assert.assertEquals(o3.getInvolvedVMs(), co3.getMisPlacedVMs(i));
}
use of org.btrplace.model.constraint.Overbook in project scheduler by btrplace.
the class COverbookTest method testNoSolution.
@Test
public void testNoSolution() throws SchedulerException {
Node[] nodes = new Node[2];
VM[] vms = new VM[7];
Model mo = new DefaultModel();
Mapping m = mo.getMapping();
ShareableResource rcMem = new ShareableResource("mem");
for (int i = 0; i < vms.length; i++) {
if (i < nodes.length) {
nodes[i] = mo.newNode();
rcMem.setCapacity(nodes[i], 3);
m.addOnlineNode(nodes[i]);
}
vms[i] = mo.newVM();
rcMem.setConsumption(vms[i], 1);
m.addReadyVM(vms[i]);
}
mo.attach(rcMem);
Collection<SatConstraint> c = new HashSet<>();
c.add(new Overbook(nodes[0], "mem", 1));
c.add(new Overbook(nodes[1], "mem", 1));
c.addAll(Running.newRunning(m.getAllVMs()));
for (VM v : vms) {
c.add(new Preserve(v, "mem", 1));
}
ChocoScheduler cra = new DefaultChocoScheduler();
cra.getDurationEvaluators().register(BootVM.class, new LinearToAResourceActionDuration<VM>("mem", 2, 3));
Assert.assertNull(cra.solve(mo, c));
}
use of org.btrplace.model.constraint.Overbook in project scheduler by btrplace.
the class COverbookTest method testMultipleOverbook.
/**
* One overbook factor per node.
*
* @throws org.btrplace.scheduler.SchedulerException should not occur
*/
@Test
public void testMultipleOverbook() throws SchedulerException {
Node[] nodes = new Node[3];
VM[] vms = new VM[11];
Model mo = new DefaultModel();
Mapping m = mo.getMapping();
ShareableResource rcCPU = new ShareableResource("cpu");
for (int i = 0; i < vms.length; i++) {
if (i < nodes.length) {
nodes[i] = mo.newNode();
rcCPU.setCapacity(nodes[i], 2);
m.addOnlineNode(nodes[i]);
}
vms[i] = mo.newVM();
rcCPU.setConsumption(vms[i], 1);
m.addReadyVM(vms[i]);
}
mo.attach(rcCPU);
Collection<SatConstraint> c = new HashSet<>();
c.add(new Overbook(nodes[0], "cpu", 1));
c.add(new Overbook(nodes[1], "cpu", 2));
c.add(new Overbook(nodes[2], "cpu", 3));
c.addAll(Running.newRunning(m.getAllVMs()));
c.add(new Preserve(vms[0], "cpu", 1));
DefaultChocoScheduler cra = new DefaultChocoScheduler();
cra.setTimeLimit(-1);
ReconfigurationPlan p = cra.solve(mo, c);
Assert.assertNotNull(p);
}
use of org.btrplace.model.constraint.Overbook in project scheduler by btrplace.
the class OverbookBuilderTest method testGoodSignatures.
@Test(dataProvider = "goodOverbooks")
public void testGoodSignatures(String str, int nbNodes, String rcId, double ratio) 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(), nbNodes);
Set<Node> nodes = new HashSet<>();
for (SatConstraint s : cstrs) {
Assert.assertTrue(s instanceof Overbook);
Assert.assertTrue(nodes.addAll(s.getInvolvedNodes()));
Assert.assertEquals(s.getInvolvedNodes().size(), 1);
Assert.assertEquals(((Overbook) s).getResource(), rcId);
Assert.assertEquals(((Overbook) s).getRatio(), ratio);
Assert.assertEquals(s.isContinuous(), !str.startsWith(">>"));
}
}
use of org.btrplace.model.constraint.Overbook in project scheduler by btrplace.
the class OverbookConverterTest method testViables.
@Test
public void testViables() throws JSONConverterException {
Model mo = new DefaultModel();
ConstraintsConverter conv = new ConstraintsConverter();
conv.register(new OverbookConverter());
Overbook d = new Overbook(mo.newNode(), "foo", 1.4);
Assert.assertEquals(conv.fromJSON(mo, conv.toJSON(d)), d);
System.out.println(conv.toJSON(d));
}
Aggregations