use of org.btrplace.model.constraint.Ready in project scheduler by btrplace.
the class ReadyBuilderTest method testGoodSignatures.
@Test(dataProvider = "goodReadys")
public void testGoodSignatures(String str, int nbVMs, 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;" + str).getConstraints();
Assert.assertEquals(cstrs.size(), nbVMs);
Set<VM> vms = new HashSet<>();
for (SatConstraint x : cstrs) {
Assert.assertTrue(x instanceof Ready);
Assert.assertTrue(vms.addAll(x.getInvolvedVMs()));
Assert.assertEquals(x.isContinuous(), c);
}
}
use of org.btrplace.model.constraint.Ready in project scheduler by btrplace.
the class InstanceSolverRunner method buildRP.
private ReconfigurationProblem buildRP() throws SchedulerException {
// Build the RP. As VM state management is not possible
// We extract VM-state related constraints first.
// For other constraint, we just create the right choco constraint
Set<VM> toRun = new HashSet<>();
Set<VM> toForge = new HashSet<>();
Set<VM> toKill = new HashSet<>();
Set<VM> toSleep = new HashSet<>();
cConstraints = new ArrayList<>();
for (SatConstraint cstr : cstrs) {
checkNodesExistence(origin, cstr.getInvolvedNodes());
// (when they will be forged)
if (!(cstrs instanceof Ready)) {
checkUnknownVMsInMapping(origin, cstr.getInvolvedVMs());
}
if (cstr instanceof Running) {
toRun.addAll(cstr.getInvolvedVMs());
} else if (cstr instanceof Sleeping) {
toSleep.addAll(cstr.getInvolvedVMs());
} else if (cstr instanceof Ready) {
checkUnknownVMsInMapping(origin, cstr.getInvolvedVMs());
toForge.addAll(cstr.getInvolvedVMs());
} else if (cstr instanceof Killed) {
checkUnknownVMsInMapping(origin, cstr.getInvolvedVMs());
toKill.addAll(cstr.getInvolvedVMs());
}
cConstraints.add(build(cstr));
}
cConstraints.add(build(obj));
views = makeViews();
DefaultReconfigurationProblemBuilder rpb = new DefaultReconfigurationProblemBuilder(origin).setNextVMsStates(toForge, toRun, toSleep, toKill).setParams(params);
if (params.doRepair()) {
Set<VM> toManage = new HashSet<>();
cConstraints.forEach(c -> toManage.addAll(c.getMisPlacedVMs(instance)));
views.forEach(v -> toManage.addAll(v.getMisPlacedVMs(instance)));
rpb.setManageableVMs(toManage);
}
// The core views have been instantiated and available through rp.getViews()
// Set the maximum duration
ReconfigurationProblem p = rpb.build();
try {
p.getEnd().updateUpperBound(params.getMaxEnd(), Cause.Null);
} catch (ContradictionException e) {
p.getLogger().error("Unable to restrict the maximum plan duration to " + params.getMaxEnd(), e);
return null;
}
return p;
}
use of org.btrplace.model.constraint.Ready in project scheduler by btrplace.
the class DefaultChocoSchedulerTest method testNonHomogeneousIncrease.
/**
* Issue #14
*
* @throws org.btrplace.scheduler.SchedulerException
*/
@Test
public void testNonHomogeneousIncrease() throws SchedulerException {
ShareableResource cpu = new ShareableResource("cpu");
ShareableResource mem = new ShareableResource("mem");
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
VM vm4 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
cpu.setCapacity(n1, 10);
mem.setCapacity(n1, 10);
cpu.setCapacity(n2, 10);
mem.setCapacity(n2, 10);
cpu.setConsumption(vm1, 5);
mem.setConsumption(vm1, 4);
cpu.setConsumption(vm2, 3);
mem.setConsumption(vm2, 8);
cpu.setConsumption(vm3, 5);
cpu.setConsumption(vm3, 4);
cpu.setConsumption(vm4, 4);
cpu.setConsumption(vm4, 5);
// vm1 requires more cpu resources, but fewer mem resources
Preserve pCPU = new Preserve(vm1, "cpu", 7);
Preserve pMem = new Preserve(vm1, "mem", 2);
mo.getMapping().on(n1, n2).run(n1, vm1).run(n2, vm3, vm4).ready(vm2);
mo.attach(cpu);
mo.attach(mem);
ChocoScheduler cra = new DefaultChocoScheduler();
cra.setMaxEnd(5);
ReconfigurationPlan p = cra.solve(mo, Arrays.asList(pCPU, pMem, new Online(n1), new Running(vm2), new Ready(vm3)));
Assert.assertNotNull(p);
}
use of org.btrplace.model.constraint.Ready in project scheduler by btrplace.
the class ReadyConverterTest method testViables.
@Test
public void testViables() throws JSONConverterException {
Model mo = new DefaultModel();
ConstraintsConverter conv = new ConstraintsConverter();
conv.register(new ReadyConverter());
Ready d = new Ready(mo.newVM());
Assert.assertEquals(conv.fromJSON(mo, conv.toJSON(d)), d);
System.out.println(conv.toJSON(d));
}
use of org.btrplace.model.constraint.Ready in project scheduler by btrplace.
the class CReadyTest method testGetMisplaced.
@Test
public void testGetMisplaced() {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
Node n1 = mo.newNode();
mo.getMapping().ready(vm1).on(n1).run(n1, vm2, vm3);
Instance i = new Instance(mo, Collections.emptyList(), new MinMTTR());
CReady k = new CReady(new Ready(vm1));
Assert.assertEquals(0, k.getMisPlacedVMs(i).size());
k = new CReady(new Ready(vm2));
Assert.assertEquals(1, k.getMisPlacedVMs(i).size());
Assert.assertTrue(k.getMisPlacedVMs(i).contains(vm2));
}
Aggregations