use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.
the class ShutdownableNodeTest method testForcedOffline.
@Test
public void testForcedOffline() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
Node n1 = mo.newNode();
map.addOnlineNode(n1);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(ShutdownNode.class, new ConstantActionDuration<>(5));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).build();
ShutdownableNode ma = (ShutdownableNode) rp.getNodeAction(n1);
ma.getState().instantiateTo(0, Cause.Null);
ReconfigurationPlan p = rp.solve(0, false);
Assert.assertNotNull(p);
Assert.assertEquals(ma.getDuration().getValue(), 5);
Assert.assertEquals(ma.getStart().getValue(), 0);
Assert.assertEquals(ma.getEnd().getValue(), 5);
Assert.assertEquals(ma.getHostingStart().getValue(), 0);
Assert.assertEquals(ma.getHostingEnd().getValue(), 0);
Assert.assertEquals(p.getSize(), 1);
Model res = p.getResult();
Assert.assertTrue(res.getMapping().getOfflineNodes().contains(n1));
}
use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.
the class SuspendVMTest method testSuspendSequences.
/**
* Test that check that the action duration is lesser than
* the cSlice duration. This allows actions scheduling
* In practice, for this test, 2 suspend actions have to be executed sequentially
*/
@Test
public void testSuspendSequences() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
Node n1 = mo.newNode();
Mapping map = mo.getMapping();
map.addOnlineNode(n1);
map.addRunningVM(vm1, n1);
map.addRunningVM(vm2, n1);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(org.btrplace.plan.event.SuspendVM.class, new ConstantActionDuration<>(5));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(new HashSet<>(), new HashSet<>(), map.getAllVMs(), new HashSet<>()).build();
SuspendVM m1 = (SuspendVM) rp.getVMActions().get(rp.getVM(vm1));
SuspendVM m2 = (SuspendVM) rp.getVMActions().get(rp.getVM(vm2));
rp.getNodeActions().get(0).getState().instantiateTo(1, Cause.Null);
org.chocosolver.solver.Model csp = rp.getModel();
csp.post(csp.arithm(m2.getStart(), ">=", m1.getEnd()));
new CMinMTTR().inject(ps, rp);
ReconfigurationPlan p = rp.solve(0, false);
Assert.assertNotNull(p);
Iterator<Action> ite = p.iterator();
org.btrplace.plan.event.SuspendVM b1 = (org.btrplace.plan.event.SuspendVM) ite.next();
org.btrplace.plan.event.SuspendVM b2 = (org.btrplace.plan.event.SuspendVM) ite.next();
Assert.assertEquals(vm1, b1.getVM());
Assert.assertEquals(vm2, b2.getVM());
Assert.assertTrue(b1.getEnd() <= b2.getStart());
Assert.assertEquals(5, b1.getEnd() - b1.getStart());
Assert.assertEquals(5, b2.getEnd() - b2.getStart());
}
use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.
the class SuspendVMTest method testBasic.
@Test
public void testBasic() throws ContradictionException, SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
Node n1 = mo.newNode();
Mapping map = mo.getMapping();
map.addOnlineNode(n1);
map.addRunningVM(vm1, n1);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(org.btrplace.plan.event.SuspendVM.class, new ConstantActionDuration<>(5));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(new HashSet<>(), new HashSet<>(), map.getAllVMs(), new HashSet<>()).build();
rp.getNodeActions().get(0).getState().instantiateTo(1, Cause.Null);
SuspendVM m = (SuspendVM) rp.getVMActions().get(0);
Assert.assertEquals(vm1, m.getVM());
Assert.assertNull(m.getDSlice());
Assert.assertTrue(m.getDuration().isInstantiatedTo(5));
Assert.assertTrue(m.getState().isInstantiatedTo(0));
Assert.assertTrue(m.getCSlice().getHoster().isInstantiatedTo(0));
new CMinMTTR().inject(ps, rp);
ReconfigurationPlan p = rp.solve(0, false);
org.btrplace.plan.event.SuspendVM a = (org.btrplace.plan.event.SuspendVM) p.getActions().iterator().next();
Assert.assertEquals(n1, a.getSourceNode());
Assert.assertEquals(vm1, a.getVM());
Assert.assertEquals(5, a.getEnd() - a.getStart());
}
use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.
the class CShareableResourceTest method testDefaultOverbookRatio.
/**
* The default overbooking ratio of 1 will make this problem having no solution.
*/
@Test
public void testDefaultOverbookRatio() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
Node n1 = mo.newNode();
mo.getMapping().on(n1).run(n1, vm1, vm2);
ShareableResource rc = new ShareableResource("foo", 0, 0);
rc.setConsumption(vm1, 2);
rc.setConsumption(vm2, 3);
rc.setCapacity(n1, 5);
mo.attach(rc);
ChocoScheduler s = new DefaultChocoScheduler();
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.add(new Fence(vm1, n1));
cstrs.add(new Preserve(vm2, "foo", 4));
// rp.solve(0, false);
ReconfigurationPlan p = s.solve(mo, cstrs);
Assert.assertNull(p);
}
use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.
the class CShareableResourceTest method testInsertAction.
/**
* Reproduce issue#145.
*/
/*@Test*/
public void testInsertAction() {
Model mo = new DefaultModel();
ShareableResource cpu = new ShareableResource("cpu");
ShareableResource mem = new ShareableResource("mem");
mo.attach(cpu);
mo.attach(mem);
Node node = mo.newNode();
Node node2 = mo.newNode();
mo.getMapping().on(node, node2);
cpu.setCapacity(node, 100000);
mem.setCapacity(node, 100000);
cpu.setCapacity(node2, 100000);
mem.setCapacity(node2, 100000);
for (int i = 0; i < 10000; i++) {
VM vm = mo.newVM();
mo.getMapping().run(node, vm);
cpu.setConsumption(vm, 1);
mem.setConsumption(vm, 1);
}
ChocoScheduler sched = new DefaultChocoScheduler();
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.addAll(Running.newRunning(mo.getMapping().getAllVMs()));
cstrs.addAll(NoDelay.newNoDelay(mo.getMapping().getAllVMs()));
cstrs.addAll(Fence.newFence(mo.getMapping().getAllVMs(), Arrays.asList(node2)));
cstrs.addAll(Preserve.newPreserve(mo.getMapping().getAllVMs(), "cpu", 2));
cstrs.addAll(Preserve.newPreserve(mo.getMapping().getAllVMs(), "mem", 2));
ReconfigurationPlan plan = sched.solve(mo, cstrs);
System.out.println(plan);
System.out.println(sched.getStatistics());
}
Aggregations