use of org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder in project scheduler by btrplace.
the class ResumeVMTest method testBasics.
/**
* Just resume a VM on its current node.
*/
@Test
public void testBasics() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
final VM vm1 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
map.addOnlineNode(n1);
map.addOnlineNode(n2);
map.addSleepingVM(vm1, n1);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(org.btrplace.plan.event.ResumeVM.class, new ConstantActionDuration<>(10));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(new HashSet<>(), map.getAllVMs(), new HashSet<>(), new HashSet<>()).build();
rp.getNodeActions().get(0).getState().instantiateTo(1, Cause.Null);
rp.getNodeActions().get(1).getState().instantiateTo(1, Cause.Null);
ResumeVM m = (ResumeVM) rp.getVMActions().get(0);
Assert.assertEquals(vm1, m.getVM());
Assert.assertNull(m.getCSlice());
Assert.assertTrue(m.getDuration().isInstantiatedTo(10));
Assert.assertTrue(m.getState().isInstantiatedTo(1));
Assert.assertFalse(m.getDSlice().getHoster().isInstantiated());
Assert.assertFalse(m.getDSlice().getStart().isInstantiated());
Assert.assertFalse(m.getDSlice().getEnd().isInstantiated());
ReconfigurationPlan p = rp.solve(0, false);
Assert.assertNotNull(p);
org.btrplace.plan.event.ResumeVM a = (org.btrplace.plan.event.ResumeVM) p.getActions().iterator().next();
Node dest = rp.getNode(m.getDSlice().getHoster().getValue());
Assert.assertEquals(vm1, a.getVM());
Assert.assertEquals(dest, a.getDestinationNode());
Assert.assertEquals(n1, a.getSourceNode());
Assert.assertEquals(10, a.getEnd() - a.getStart());
}
use of org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder in project scheduler by btrplace.
the class ShutdownableNodeTest method testBasics.
@Test
public void testBasics() throws SchedulerException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
Node n1 = mo.newNode();
map.addOnlineNode(n1);
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).build();
ShutdownableNode ma = (ShutdownableNode) rp.getNodeAction(n1);
Assert.assertEquals(ma.getNode(), n1);
Assert.assertEquals(ma.getHostingStart(), rp.getStart());
}
use of org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder 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.DefaultReconfigurationProblemBuilder in project scheduler by btrplace.
the class ShutdownableNodeTest method testCascadedShutdown.
/**
* The 2 nodes are set offline but n2 will consume being offline after n1
*
* @throws org.btrplace.scheduler.SchedulerException
* @throws ContradictionException
*/
@Test
public void testCascadedShutdown() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
map.addOnlineNode(n1);
map.addOnlineNode(n2);
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).build();
ShutdownableNode ma1 = (ShutdownableNode) rp.getNodeAction(n1);
ShutdownableNode ma2 = (ShutdownableNode) rp.getNodeAction(n2);
ma1.getState().instantiateTo(0, Cause.Null);
ma2.getState().instantiateTo(0, Cause.Null);
rp.getModel().post(rp.getModel().arithm(ma2.getStart(), "=", ma1.getEnd()));
ReconfigurationPlan p = rp.solve(0, false);
Assert.assertNotNull(p);
System.out.println(p);
Assert.assertEquals(ma1.getStart().getValue(), 0);
Assert.assertEquals(ma2.getStart().getValue(), ma1.getEnd().getValue());
Model res = p.getResult();
Assert.assertEquals(res.getMapping().getOfflineNodes().size(), 2);
}
use of org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder 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));
}
Aggregations