use of org.btrplace.scheduler.choco.ReconfigurationProblem in project scheduler by btrplace.
the class ShutdownableNodeTest method testShutdownable.
@Test
public void testShutdownable() throws SchedulerException, ContradictionException {
Model model = new DefaultModel();
Mapping map = model.getMapping();
Node n1 = model.newNode();
Node n4 = model.newNode();
map.addOnlineNode(n1);
map.addOnlineNode(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);
sn1.getStart().instantiateTo(2, Cause.Null);
ShutdownableNode sn4 = (ShutdownableNode) rp.getNodeAction(n4);
sn4.getState().instantiateTo(1, Cause.Null);
ReconfigurationPlan p = rp.solve(0, false);
Assert.assertNotNull(p);
System.out.println(p);
Assert.assertEquals(rp.getStart().getValue(), 0);
Assert.assertEquals(rp.getEnd().getValue(), 7);
Assert.assertEquals(sn1.getStart().getValue(), 2);
Assert.assertEquals(sn1.getDuration().getValue(), 5);
Assert.assertEquals(sn1.getEnd().getValue(), 7);
Assert.assertEquals(sn1.getHostingStart().getValue(), 0);
Assert.assertEquals(sn1.getHostingEnd().getValue(), 2);
Assert.assertEquals(rp.getStart().getValue(), 0);
Assert.assertEquals(sn4.getStart().getValue(), 0);
Assert.assertEquals(sn4.getDuration().getValue(), 0);
Assert.assertEquals(sn4.getEnd().getValue(), 0);
Assert.assertEquals(sn4.getHostingStart().getValue(), 0);
Assert.assertEquals(sn4.getHostingEnd().getValue(), 7);
Assert.assertEquals(p.getSize(), 1);
Model res = p.getResult();
Assert.assertTrue(res.getMapping().isOnline(n4));
Assert.assertTrue(res.getMapping().getOfflineNodes().contains(n1));
}
use of org.btrplace.scheduler.choco.ReconfigurationProblem in project scheduler by btrplace.
the class ShutdownableNodeTest method testForcedOnline.
@Test
public void testForcedOnline() throws SchedulerException, ContradictionException {
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(ShutdownNode.class, new ConstantActionDuration<>(5));
dev.register(BootNode.class, new ConstantActionDuration<>(10));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).build();
ShutdownableNode ma = (ShutdownableNode) rp.getNodeAction(n1);
// stay online
ma.getState().instantiateTo(1, Cause.Null);
// To make the result plan 10 seconds long
BootableNode ma2 = (BootableNode) rp.getNodeAction(n2);
// go online
ma2.getState().instantiateTo(1, Cause.Null);
ReconfigurationPlan p = rp.solve(0, false);
Assert.assertNotNull(p);
System.out.println(p);
Assert.assertEquals(ma.getDuration().getValue(), 0);
Assert.assertEquals(ma.getStart().getValue(), 0);
Assert.assertEquals(ma.getEnd().getValue(), 0);
Assert.assertEquals(ma.getHostingStart().getValue(), 0);
Assert.assertEquals(ma.getHostingEnd().getValue(), 10);
Assert.assertEquals(p.getSize(), 1);
Model res = p.getResult();
Assert.assertTrue(res.getMapping().isOnline(n1));
}
use of org.btrplace.scheduler.choco.ReconfigurationProblem in project scheduler by btrplace.
the class ShutdownableNodeTest method testShutdownBeforeVMsLeave.
@Test
public void testShutdownBeforeVMsLeave() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
final VM vm1 = mo.newVM();
Node n1 = mo.newNode();
map.addOnlineNode(n1);
map.addRunningVM(vm1, n1);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(ShutdownVM.class, new ConstantActionDuration<>(2));
dev.register(ShutdownNode.class, new ConstantActionDuration<>(5));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(Collections.singleton(vm1), Collections.emptySet(), Collections.emptySet(), Collections.emptySet()).setParams(ps).build();
ShutdownableNode ma1 = (ShutdownableNode) rp.getNodeAction(n1);
ma1.getState().instantiateTo(0, Cause.Null);
ma1.getHostingEnd().instantiateTo(0, Cause.Null);
rp.getEnd().updateUpperBound(10, Cause.Null);
ReconfigurationPlan p = rp.solve(0, false);
Assert.assertNull(p);
}
use of org.btrplace.scheduler.choco.ReconfigurationProblem in project scheduler by btrplace.
the class ShutdownableNodeTest method testScheduledShutdown.
@Test
public void testScheduledShutdown() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
final VM vm1 = mo.newVM();
Node n1 = mo.newNode();
map.addOnlineNode(n1);
map.addRunningVM(vm1, n1);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(ShutdownVM.class, new ConstantActionDuration<>(2));
dev.register(ShutdownNode.class, new ConstantActionDuration<>(5));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(Collections.singleton(vm1), Collections.emptySet(), Collections.emptySet(), Collections.emptySet()).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.getState().getValue(), 0);
Assert.assertEquals(ma.getDuration().getValue(), 5);
Assert.assertEquals(ma.getStart().getValue(), 2);
Assert.assertEquals(ma.getEnd().getValue(), 7);
Assert.assertEquals(ma.getHostingStart().getValue(), 0);
Assert.assertEquals(ma.getHostingEnd().getValue(), 2);
Model res = p.getResult();
Assert.assertTrue(res.getMapping().getOfflineNodes().contains(n1));
}
use of org.btrplace.scheduler.choco.ReconfigurationProblem in project scheduler by btrplace.
the class StayAwayVMTest method testBasic.
@Test
public void testBasic() 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.addSleepingVM(vm1, n1);
map.addReadyVM(vm2);
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).build();
rp.getNodeAction(n1).getState().instantiateTo(1, Cause.Null);
StayAwayVM ma1 = (StayAwayVM) rp.getVMAction(vm1);
StayAwayVM ma2 = (StayAwayVM) rp.getVMAction(vm2);
Assert.assertEquals(vm1, ma1.getVM());
Assert.assertEquals(vm2, ma2.getVM());
for (VMTransition am : rp.getVMActions()) {
Assert.assertTrue(am.getState().isInstantiatedTo(0));
Assert.assertNull(am.getCSlice());
Assert.assertNull(am.getDSlice());
Assert.assertTrue(am.getStart().isInstantiatedTo(0));
Assert.assertTrue(am.getEnd().isInstantiatedTo(0));
Assert.assertTrue(am.getDuration().isInstantiatedTo(0));
}
ReconfigurationPlan p = rp.solve(0, false);
Assert.assertNotNull(p);
Assert.assertEquals(0, p.getSize());
}
Aggregations