use of org.btrplace.model.constraint.Preserve in project scheduler by btrplace.
the class CMinMigrationsTest method simpleTest.
@Test
public void simpleTest() {
Model mo = new DefaultModel();
Node n0 = mo.newNode();
Node n1 = mo.newNode();
VM vm0 = mo.newVM();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
mo.getMapping().on(n0, n1).run(n0, vm0, vm1, vm2);
ShareableResource mem = new ShareableResource("mem", 5, 1);
// cpu dimension to create the violation
ShareableResource cpu = new ShareableResource("cpu", 5, 1);
// VM0 as the big VM
mem.setConsumption(vm0, 3);
mo.attach(cpu);
mo.attach(mem);
List<SatConstraint> cstrs = new ArrayList<>();
// The 3 VMs no longer feet on n0
cstrs.add(new Preserve(vm0, "cpu", 5));
ChocoScheduler s = new DefaultChocoScheduler();
s.doOptimize(true);
ReconfigurationPlan p = s.solve(mo, cstrs, new MinMigrations());
System.out.println(s.getStatistics());
System.out.println(p);
// VM0 to n1
Assert.assertEquals(p.getActions().size(), 1);
// VM0 to n1
Assert.assertEquals(p.getResult().getMapping().getVMLocation(vm0), n1);
}
use of org.btrplace.model.constraint.Preserve in project scheduler by btrplace.
the class PreserveBuilderTest method testGoodSignatures.
@Test(dataProvider = "goodPreserves")
public void testGoodSignatures(String str, int nbVMs, String rcId, int a) 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(), nbVMs);
Set<VM> vms = new HashSet<>();
for (SatConstraint x : cstrs) {
Assert.assertTrue(x instanceof Preserve);
Assert.assertTrue(vms.addAll(x.getInvolvedVMs()));
Assert.assertEquals(x.isContinuous(), false);
Assert.assertEquals(((Preserve) x).getResource(), rcId);
Assert.assertEquals(((Preserve) x).getAmount(), a);
}
}
use of org.btrplace.model.constraint.Preserve 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.Preserve in project scheduler by btrplace.
the class PreserveConverterTest method testViables.
@Test
public void testViables() throws JSONConverterException {
Model mo = new DefaultModel();
ConstraintsConverter conv = new ConstraintsConverter();
conv.register(new PreserveConverter());
Preserve d = new Preserve(mo.newVM(), "cpu", 5);
Assert.assertEquals(conv.fromJSON(mo, conv.toJSON(d)), d);
System.out.println(conv.toJSON(d));
}
use of org.btrplace.model.constraint.Preserve in project scheduler by btrplace.
the class SolverTuning method run.
@Override
@SuppressWarnings("squid:S1166")
public void run() {
// Make a default model with 500 nodes hosting 3,000 VMs
Model model = makeModel();
Set<SatConstraint> constraints = new HashSet<>();
// We allow memory over-commitment with a overbooking ratio of 50%
// i.e. 1MB physical RAM for 1.5MB virtual RAM
constraints.addAll(Overbook.newOverbooks(model.getMapping().getAllNodes(), "mem", 1.5));
/**
* On 10 nodes, 4 of the 6 hosted VMs ask now for a 4GB bandwidth
*/
for (int i = 0; i < 5; i++) {
Node n = nodes.get(i);
Set<VM> vmsOnN = model.getMapping().getRunningVMs(n);
Iterator<VM> ite = vmsOnN.iterator();
for (int j = 0; ite.hasNext() && j < 4; j++) {
VM v = ite.next();
constraints.add(new Preserve(v, "bandwidth", 4));
}
}
ChocoScheduler cra = new DefaultChocoScheduler();
// Customize the estimated duration of actions
cra.getDurationEvaluators().register(MigrateVM.class, new LinearToAResourceActionDuration<VM>("mem", 1, 3));
// We want the best possible solution, computed in up to 5 sec.
cra.doOptimize(true);
cra.setTimeLimit(5);
// We solve without the repair mode
cra.doRepair(false);
try {
solve(cra, model, constraints);
} catch (@SuppressWarnings("unused") SchedulerException ex) {
// Just in case the testing environment is not performant enough
// It does not matter that much if there is no enough time to get a solution here
}
// Re-solve using the repair mode to check for the improvement
cra.doRepair(true);
solve(cra, model, constraints);
}
Aggregations