use of org.btrplace.scheduler.choco.duration.DurationEvaluators in project scheduler by btrplace.
the class ShutdownableNodeTest method testSwitchState.
@Test
public void testSwitchState() throws ContradictionException, SchedulerException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
map.addOnlineNode(n1);
map.addOfflineNode(n2);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(BootNode.class, new ConstantActionDuration<>(2));
dev.register(ShutdownNode.class, new ConstantActionDuration<>(5));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).build();
ShutdownableNode ma1 = (ShutdownableNode) rp.getNodeAction(n1);
BootableNode ma2 = (BootableNode) rp.getNodeAction(n2);
ma1.getState().instantiateTo(0, Cause.Null);
ma2.getState().instantiateTo(1, Cause.Null);
rp.getModel().post(rp.getModel().arithm(ma1.getEnd(), "=", ma2.getStart()));
ReconfigurationPlan p = rp.solve(0, false);
// ChocoLogging.flushLogs();
Assert.assertNotNull(p);
System.out.println(p);
System.out.flush();
}
use of org.btrplace.scheduler.choco.duration.DurationEvaluators in project scheduler by btrplace.
the class ShutdownableNodeTest method testActionDurationSimple.
@Test
public void testActionDurationSimple() throws SchedulerException, ContradictionException {
Model model = new DefaultModel();
Mapping map = model.getMapping();
Node n1 = model.newNode();
Node n4 = model.newNode();
map.addOnlineNode(n1);
map.addOfflineNode(n4);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(ShutdownNode.class, new ConstantActionDuration<>(5));
dev.register(BootNode.class, new ConstantActionDuration<>(3));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(model).setParams(ps).build();
ShutdownableNode sn1 = (ShutdownableNode) rp.getNodeAction(n1);
sn1.getState().instantiateTo(0, Cause.Null);
BootableNode bn4 = (BootableNode) rp.getNodeAction(n4);
bn4.getState().instantiateTo(0, Cause.Null);
ReconfigurationPlan p = rp.solve(0, false);
Assert.assertNotNull(p);
System.out.println(p);
Assert.assertEquals(rp.getStart().getValue(), 0);
Assert.assertEquals(bn4.getStart().getValue(), 0);
Assert.assertEquals(bn4.getDuration().getValue(), 0);
Assert.assertEquals(bn4.getEnd().getValue(), 0);
Assert.assertEquals(bn4.getHostingStart().getValue(), 0);
Assert.assertEquals(bn4.getHostingEnd().getValue(), 0);
Assert.assertEquals(p.getSize(), 1);
Model res = p.getResult();
Assert.assertTrue(res.getMapping().getOfflineNodes().contains(n1));
Assert.assertTrue(res.getMapping().getOfflineNodes().contains(n4));
}
use of org.btrplace.scheduler.choco.duration.DurationEvaluators 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.duration.DurationEvaluators 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.duration.DurationEvaluators 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());
}
Aggregations