use of org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder 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.scheduler.choco.DefaultReconfigurationProblemBuilder 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.scheduler.choco.DefaultReconfigurationProblemBuilder 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.scheduler.choco.DefaultReconfigurationProblemBuilder in project scheduler by btrplace.
the class ShutdownVMTest method testShutdownSequence.
/**
* Test that check that the action duration is lesser than
* the cSlice duration. This allows actions scheduling
* In practice, for this test, 2 shutdown actions have to be executed sequentially
*/
@Test
public void testShutdownSequence() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
final VM vm1 = mo.newVM();
final VM vm2 = mo.newVM();
Node n1 = mo.newNode();
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.ShutdownVM.class, new ConstantActionDuration<>(5));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(map.getAllVMs(), new HashSet<>(), new HashSet<>(), new HashSet<>()).build();
ShutdownVM m1 = (ShutdownVM) rp.getVMActions().get(rp.getVM(vm1));
ShutdownVM m2 = (ShutdownVM) rp.getVMActions().get(rp.getVM(vm2));
rp.getNodeActions().get(0).getState().instantiateTo(1, Cause.Null);
rp.getModel().post(rp.getModel().arithm(m2.getStart(), ">=", m1.getEnd()));
// System.out.println(s);
new CMinMTTR().inject(ps, rp);
ReconfigurationPlan p = rp.solve(0, false);
Assert.assertNotNull(p);
// System.out.println(p);
Iterator<Action> ite = p.iterator();
org.btrplace.plan.event.ShutdownVM b1 = (org.btrplace.plan.event.ShutdownVM) ite.next();
org.btrplace.plan.event.ShutdownVM b2 = (org.btrplace.plan.event.ShutdownVM) 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.scheduler.choco.DefaultReconfigurationProblemBuilder in project scheduler by btrplace.
the class BootVMTest method testBootSequence.
/**
* Test that check when the action is shorter than the end of
* the reconfiguration process.
* In practice, 2 boot actions have to be executed sequentially
*/
@Test
public void testBootSequence() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
final VM vm1 = mo.newVM();
final VM vm2 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
map.addOnlineNode(n1);
map.addOnlineNode(n2);
map.addReadyVM(vm1);
map.addReadyVM(vm2);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(org.btrplace.plan.event.BootVM.class, new ConstantActionDuration<>(5));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(new HashSet<>(), map.getAllVMs(), new HashSet<>(), new HashSet<>()).build();
BootVM m1 = (BootVM) rp.getVMActions().get(rp.getVM(vm1));
BootVM m2 = (BootVM) rp.getVMActions().get(rp.getVM(vm2));
rp.getNodeActions().get(0).getState().instantiateTo(1, Cause.Null);
rp.getNodeActions().get(1).getState().instantiateTo(1, Cause.Null);
rp.getModel().post(rp.getModel().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.BootVM b1 = (org.btrplace.plan.event.BootVM) ite.next();
org.btrplace.plan.event.BootVM b2 = (org.btrplace.plan.event.BootVM) 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());
}
Aggregations