use of org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder in project scheduler by btrplace.
the class ForgeVMTest method testResolution.
@Test
public void testResolution() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
Mapping m = mo.getMapping();
final VM vm1 = mo.newVM();
Node n1 = mo.newNode();
m.addOnlineNode(n1);
mo.getAttributes().put(vm1, "template", "small");
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(org.btrplace.plan.event.ForgeVM.class, new ConstantActionDuration<>(7));
dev.register(ShutdownNode.class, new ConstantActionDuration<>(20));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(Collections.singleton(vm1), Collections.emptySet(), Collections.emptySet(), Collections.emptySet()).build();
// Force the node to get offline
ShutdownableNode n = (ShutdownableNode) rp.getNodeAction(n1);
n.getState().instantiateTo(0, Cause.Null);
new CMinMTTR().inject(ps, rp);
ReconfigurationPlan p = rp.solve(0, false);
Assert.assertNotNull(p);
Assert.assertEquals(p.getDuration(), 20);
for (Action a : p) {
if (a instanceof org.btrplace.plan.event.ForgeVM) {
org.btrplace.plan.event.ForgeVM action = (org.btrplace.plan.event.ForgeVM) a;
Assert.assertTrue(p.getResult().getMapping().isReady(vm1));
Assert.assertEquals(action.getVM(), vm1);
Assert.assertEquals(action.getEnd(), 7);
Assert.assertEquals(action.getStart(), 0);
}
}
}
use of org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder in project scheduler by btrplace.
the class ForgeVMTest method testBasics.
@Test
public void testBasics() throws SchedulerException {
Model mo = new DefaultModel();
final VM vm1 = mo.newVM();
mo.getAttributes().put(vm1, "template", "small");
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(org.btrplace.plan.event.ForgeVM.class, new ConstantActionDuration<>(7));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(Collections.singleton(vm1), Collections.emptySet(), Collections.emptySet(), Collections.emptySet()).build();
ForgeVM ma = (ForgeVM) rp.getVMAction(vm1);
Assert.assertEquals(vm1, ma.getVM());
Assert.assertEquals(ma.getTemplate(), "small");
Assert.assertTrue(ma.getDuration().isInstantiatedTo(7));
Assert.assertFalse(ma.getStart().isInstantiated());
Assert.assertFalse(ma.getEnd().isInstantiated());
Assert.assertTrue(ma.getState().isInstantiatedTo(0));
Assert.assertNull(ma.getCSlice());
Assert.assertNull(ma.getDSlice());
}
use of org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder in project scheduler by btrplace.
the class BootableNodeTest method testForcingOffline.
@Test
public void testForcingOffline() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
Node n1 = mo.newNode();
map.addOfflineNode(n1);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(BootNode.class, new ConstantActionDuration<>(5));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).build();
BootableNode na = (BootableNode) rp.getNodeAction(n1);
na.getState().instantiateTo(0, Cause.Null);
ReconfigurationPlan p = rp.solve(0, false);
Assert.assertNotNull(p);
Assert.assertEquals(na.getDuration().getValue(), 0);
Assert.assertEquals(na.getStart().getValue(), 0);
Assert.assertEquals(na.getEnd().getValue(), 0);
Assert.assertEquals(na.getHostingStart().getValue(), rp.getEnd().getValue());
Assert.assertEquals(na.getHostingEnd().getValue(), rp.getEnd().getValue());
Assert.assertNotNull(p);
Assert.assertEquals(p.getSize(), 0);
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 BootableNodeTest method testDelayedBooting.
@Test
public void testDelayedBooting() throws ContradictionException, SchedulerException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
Node n2 = mo.newNode();
map.addOfflineNode(n2);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(BootNode.class, new ConstantActionDuration<>(2));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).build();
BootableNode ma2 = (BootableNode) rp.getNodeAction(n2);
ma2.getState().instantiateTo(1, Cause.Null);
ma2.getStart().updateLowerBound(5, Cause.Null);
new CMinMTTR().inject(ps, rp);
ReconfigurationPlan p = rp.solve(0, false);
// ChocoLogging.flushLogs();
Assert.assertNotNull(p);
}
use of org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder in project scheduler by btrplace.
the class BootableNodeTest method testActionDurationSimple.
/**
* Unit test for issue #3
*/
@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);
new CMinMTTR().inject(ps, rp);
ReconfigurationPlan p = rp.solve(0, false);
Assert.assertNotNull(p);
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