use of org.btrplace.model.constraint.Running in project scheduler by btrplace.
the class RunningSplitterTest method simpleTest.
@Test
public void simpleTest() {
RunningSplitter splitter = new RunningSplitter();
List<Instance> instances = new ArrayList<>();
Model origin = new DefaultModel();
Node n1 = origin.newNode();
Node n2 = origin.newNode();
VM vm1 = origin.newVM();
VM vm2 = origin.newVM();
VM vm3 = origin.newVM();
VM vm4 = origin.newVM();
/**
* READY: vm1
* n1 vm2
* n2 (vm3) vm4
*/
origin.getMapping().addOnlineNode(n1);
origin.getMapping().addReadyVM(vm1);
origin.getMapping().addRunningVM(vm2, n1);
origin.getMapping().addOnlineNode(n2);
origin.getMapping().addSleepingVM(vm3, n2);
origin.getMapping().addRunningVM(vm4, n2);
Model m0 = new DefaultModel();
m0.newNode(n1.id());
m0.newVM(vm1.id());
m0.newVM(vm2.id());
m0.getMapping().addOnlineNode(n1);
m0.getMapping().addReadyVM(vm1);
m0.getMapping().addRunningVM(vm2, n1);
Model m1 = new DefaultModel();
m1.newNode(n2.id());
m1.newVM(vm3.id());
m1.newVM(vm4.id());
m1.getMapping().addOnlineNode(n2);
m1.getMapping().addSleepingVM(vm3, n2);
m1.getMapping().addRunningVM(vm4, n2);
instances.add(new Instance(m0, new ArrayList<>(), new MinMTTR()));
instances.add(new Instance(m1, new ArrayList<>(), new MinMTTR()));
Set<VM> all = new HashSet<>(m0.getMapping().getAllVMs());
all.addAll(m1.getMapping().getAllVMs());
TIntIntHashMap index = Instances.makeVMIndex(instances);
// Only VMs in m0
Running single = new Running(vm1);
Assert.assertTrue(splitter.split(single, null, instances, index, new TIntIntHashMap()));
Assert.assertTrue(instances.get(0).getSatConstraints().contains(single));
Assert.assertFalse(instances.get(1).getSatConstraints().contains(single));
}
use of org.btrplace.model.constraint.Running in project scheduler by btrplace.
the class VectorPackingTest method testSlotFilteringWithUniformVMs.
/**
* 1GB free on every node and only 2GB VMs. We ask for booting a 2GB VM. No
* solution detected immediately if the hosting capacity is capped to the
* max number of VMs per node (100) as their sum will not exceed the
* number of running VMs.
*/
@Test
public void testSlotFilteringWithUniformVMs() {
int capa = 201;
DefaultModel mo = new DefaultModel();
Mapping map = mo.getMapping();
ShareableResource mem = new ShareableResource("mem");
ShareableResource cpu = new ShareableResource("cpu");
ShareableResource ctrl = new ShareableResource("ctrl");
mo.attach(mem);
mo.attach(cpu);
mo.attach(ctrl);
Instance ii = new Instance(mo, new ArrayList<>(), new MinMigrations());
for (int i = 0; i < 500; i++) {
final Node no = mo.newNode();
map.on(no);
mem.setCapacity(no, capa);
cpu.setCapacity(no, capa);
ctrl.setCapacity(no, capa);
// 1 left on every node.
for (int j = 0; j < capa / 2; j++) {
final VM vm = mo.newVM();
map.run(no, vm);
mem.setConsumption(vm, 2);
cpu.setConsumption(vm, 2);
ctrl.setConsumption(vm, 2);
}
final VM vm = mo.newVM();
map.run(no, vm);
mem.setConsumption(vm, 0);
cpu.setConsumption(vm, 0);
ctrl.setConsumption(vm, 0);
}
final VM p = mo.newVM();
mem.setConsumption(p, 2);
cpu.setConsumption(p, 2);
ctrl.setConsumption(p, 2);
map.addReadyVM(p);
final ChocoScheduler sched = new DefaultChocoScheduler();
ii.getSatConstraints().add(new Running(p));
sched.doRepair(false);
ReconfigurationPlan plan = sched.solve(ii);
Assert.assertNull(plan);
// The problem is stated during the initial propagation.
SolvingStatistics stats = sched.getStatistics();
Assert.assertEquals(0, stats.getMetrics().nodes());
// With 0 size VMs, same conclusion.
for (Node no : map.getOnlineNodes()) {
final VM vm = mo.newVM();
map.run(no, vm);
mem.setConsumption(vm, 0);
ctrl.setConsumption(vm, 0);
cpu.setConsumption(vm, 0);
}
plan = sched.solve(ii);
Assert.assertNull(plan);
// The problem is stated during the initial propagation.
stats = sched.getStatistics();
Assert.assertEquals(0, stats.getMetrics().nodes());
System.out.println(stats);
}
use of org.btrplace.model.constraint.Running in project scheduler by btrplace.
the class BootableNodeTest method testRequiredOnline.
@Test
public void testRequiredOnline() throws SchedulerException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
VM vm1 = mo.newVM();
Node n1 = mo.newNode();
map.addOfflineNode(n1);
map.addReadyVM(vm1);
ChocoScheduler s = new DefaultChocoScheduler();
Parameters ps = s.getParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(BootNode.class, new ConstantActionDuration<>(5));
dev.register(BootVM.class, new ConstantActionDuration<>(2));
ReconfigurationPlan plan = s.solve(mo, Collections.singleton(new Running(vm1)));
Assert.assertNotNull(plan);
Assert.assertEquals(plan.getSize(), 2);
for (Action a : plan.getActions()) {
if (a instanceof BootNode) {
Assert.assertEquals(a.getStart(), 0);
Assert.assertEquals(a.getEnd(), 5);
} else {
Assert.assertEquals(a.getStart(), 5);
Assert.assertEquals(a.getEnd(), 7);
}
}
}
use of org.btrplace.model.constraint.Running in project scheduler by btrplace.
the class CSeqTest method testWithVMsWithNoTransitions.
@Test
public void testWithVMsWithNoTransitions() throws SchedulerException {
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();
mo.getMapping().on(n1, n2).ready(vm1).run(n1, vm2, vm4).run(n2, vm3);
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.add(new Running(vm1));
cstrs.add(new Running(vm2));
cstrs.add(new Running(vm3));
cstrs.add(new Ready(vm4));
ChocoScheduler cra = new DefaultChocoScheduler();
List<VM> seq = Arrays.asList(vm1, vm2, vm3, vm4);
cstrs.add(new Seq(seq));
ReconfigurationPlan plan = cra.solve(mo, cstrs);
Assert.assertNotNull(plan);
// System.out.println(plan);
}
use of org.btrplace.model.constraint.Running in project scheduler by btrplace.
the class CResourceCapacityTest method testCapacityEstimation.
/**
* Test how CResourceCapacity notifies the view about the future capacity.
*/
@Test
public void testCapacityEstimation() {
final Model mo = new DefaultModel();
final Node n0 = mo.newNode();
final Node n1 = mo.newNode();
final VM vm = mo.newVM();
final ShareableResource cpu = new ShareableResource("cpu");
mo.attach(cpu);
cpu.setCapacity(n0, 5).setCapacity(n1, 7);
cpu.setConsumption(vm, 3);
mo.getMapping().on(n0, n1).ready(vm);
final List<SatConstraint> cstrs = new ArrayList<>();
cstrs.add(new Running(vm));
final Instance i = new Instance(mo, cstrs, new MinMTTR());
// Because of the worst-fit approach, the VM will go on n1 which has the
// highest capacity.
final ChocoScheduler sched = new DefaultChocoScheduler();
ReconfigurationPlan res = sched.solve(i);
Assert.assertEquals(n1, res.getResult().getMapping().getVMLocation(vm));
// With a ResourceCapacity, we restrict n1 so that now n0 is the node
// that will have the highest capacity. So the wort-fit approach inside
// MinMTTR() should pick n0.
i.getSatConstraints().add(new ResourceCapacity(n1, "cpu", 4));
res = sched.solve(i);
Assert.assertEquals(n0, res.getResult().getMapping().getVMLocation(vm));
}
Aggregations