use of org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder in project scheduler by btrplace.
the class RelocatableVMTest method testForcedToMove.
@Test
public void testForcedToMove() 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.addRunningVM(vm1, n1);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(MigrateVM.class, new ConstantActionDuration<>(5));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(Collections.emptySet(), map.getAllVMs(), Collections.emptySet(), Collections.emptySet()).setParams(ps).build();
rp.getNodeActions().get(0).getState().instantiateTo(1, Cause.Null);
rp.getNodeActions().get(1).getState().instantiateTo(1, Cause.Null);
RelocatableVM am = (RelocatableVM) rp.getVMAction(vm1);
Assert.assertTrue(am.getRelocationMethod().isInstantiatedTo(0));
Assert.assertEquals(vm1, am.getVM());
Assert.assertEquals(2, am.getDuration().getDomainSize());
Assert.assertEquals(0, am.getDuration().getLB());
Assert.assertEquals(5, am.getDuration().getUB());
Assert.assertFalse(am.getStart().isInstantiated());
Assert.assertFalse(am.getEnd().isInstantiated());
Assert.assertNotNull(am.getCSlice());
Assert.assertTrue(am.getCSlice().getHoster().isInstantiatedTo(rp.getNode(n1)));
Assert.assertTrue(am.getState().isInstantiatedTo(1));
Assert.assertNotNull(am.getDSlice());
Assert.assertFalse(am.getDSlice().getHoster().isInstantiated());
// No VMs on n1, discrete mode
rp.getModel().post(rp.getModel().arithm(rp.getNbRunningVMs().get(rp.getNode(n1)), "=", 0));
new CMinMTTR().inject(new DefaultParameters(), rp);
ReconfigurationPlan p = rp.solve(0, false);
Assert.assertNotNull(p);
Model m = p.getResult();
Assert.assertEquals(n2, m.getMapping().getVMLocation(vm1));
MigrateVM a = (MigrateVM) p.getActions().iterator().next();
Assert.assertEquals(0, a.getStart());
Assert.assertEquals(5, a.getEnd());
Assert.assertEquals(n1, a.getSourceNode());
Assert.assertEquals(n2, a.getDestinationNode());
Assert.assertEquals(vm1, a.getVM());
}
use of org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder in project scheduler by btrplace.
the class RelocatableVMTest method testStayRunning.
@Test
public void testStayRunning() throws SchedulerException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
final VM vm1 = mo.newVM();
Node n1 = mo.newNode();
map.addOnlineNode(n1);
map.addRunningVM(vm1, n1);
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(new DefaultParameters()).setManageableVMs(Collections.emptySet()).build();
Assert.assertEquals(rp.getVMAction(vm1).getClass(), RelocatableVM.class);
RelocatableVM m1 = (RelocatableVM) rp.getVMAction(vm1);
Assert.assertNotNull(m1.getCSlice());
Assert.assertNotNull(m1.getDSlice());
Assert.assertTrue(m1.getCSlice().getHoster().isInstantiatedTo(rp.getNode(n1)));
Assert.assertTrue(m1.getDSlice().getHoster().isInstantiatedTo(rp.getNode(n1)));
Assert.assertTrue(m1.getDuration().isInstantiatedTo(0));
Assert.assertTrue(m1.getStart().isInstantiatedTo(0));
Assert.assertTrue(m1.getEnd().isInstantiatedTo(0));
ReconfigurationPlan p = rp.solve(0, false);
Assert.assertNotNull(p);
Assert.assertEquals(p.getSize(), 0);
}
use of org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder in project scheduler by btrplace.
the class RelocatableVMTest method testForcedToStay.
@Test
public void testForcedToStay() 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.addRunningVM(vm1, n1);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(MigrateVM.class, new ConstantActionDuration<>(5));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(Collections.emptySet(), map.getAllVMs(), Collections.emptySet(), Collections.emptySet()).setParams(ps).build();
rp.getNodeActions().get(0).getState().instantiateTo(1, Cause.Null);
rp.getNodeActions().get(1).getState().instantiateTo(1, Cause.Null);
RelocatableVM am = (RelocatableVM) rp.getVMAction(vm1);
// No VMs on n2
rp.getNbRunningVMs().get(rp.getNode(n2)).instantiateTo(0, Cause.Null);
new CMinMTTR().inject(new DefaultParameters(), rp);
ReconfigurationPlan p = rp.solve(0, false);
Assert.assertNotNull(p);
Assert.assertEquals(0, p.getSize());
Assert.assertTrue(am.getDuration().isInstantiatedTo(0));
Assert.assertTrue(am.getDSlice().getHoster().isInstantiatedTo(rp.getNode(n1)));
Assert.assertTrue(am.getStart().isInstantiatedTo(0));
Assert.assertTrue(am.getEnd().isInstantiatedTo(0));
Model m = p.getResult();
Assert.assertEquals(n1, m.getMapping().getVMLocation(vm1));
}
use of org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder in project scheduler by btrplace.
the class ResumeVMTest method testResumeSequence.
/**
* Test that check when the action is shorter than the end of
* the reconfiguration process.
* In practice, 2 resume actions have to be executed sequentially
*/
@Test
public void testResumeSequence() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
map.addOnlineNode(n1);
map.addOnlineNode(n2);
map.addSleepingVM(vm1, n1);
map.addSleepingVM(vm2, n2);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(org.btrplace.plan.event.ResumeVM.class, new ConstantActionDuration<>(5));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(new HashSet<>(), map.getAllVMs(), new HashSet<>(), new HashSet<>()).build();
ResumeVM m1 = (ResumeVM) rp.getVMActions().get(rp.getVM(vm1));
ResumeVM m2 = (ResumeVM) 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()));
ReconfigurationPlan p = rp.solve(0, false);
Assert.assertNotNull(p);
Iterator<Action> ite = p.iterator();
org.btrplace.plan.event.ResumeVM b1 = (org.btrplace.plan.event.ResumeVM) ite.next();
org.btrplace.plan.event.ResumeVM b2 = (org.btrplace.plan.event.ResumeVM) 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 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));
}
Aggregations