use of org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR 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.constraint.mttr.CMinMTTR 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.constraint.mttr.CMinMTTR in project scheduler by btrplace.
the class RelocatableVMTest method testForcedReInstantiation.
@Test
public void testForcedReInstantiation() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
final VM vm10 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
map.addOnlineNode(n1);
map.addOnlineNode(n2);
// Not using vm1 because intPool starts at 0 so their will be multiple (0,1) VMs.
map.addRunningVM(vm10, n1);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(MigrateVM.class, new ConstantActionDuration<>(20));
dev.register(org.btrplace.plan.event.ForgeVM.class, new ConstantActionDuration<>(3));
dev.register(org.btrplace.plan.event.BootVM.class, new ConstantActionDuration<>(2));
dev.register(org.btrplace.plan.event.ShutdownVM.class, new ConstantActionDuration<>(1));
mo.getAttributes().put(vm10, "template", "small");
mo.getAttributes().put(vm10, "clone", true);
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(Collections.emptySet(), map.getAllVMs(), Collections.emptySet(), Collections.emptySet()).setParams(ps).setManageableVMs(map.getAllVMs()).build();
RelocatableVM am = (RelocatableVM) rp.getVMAction(vm10);
am.getRelocationMethod().instantiateTo(1, Cause.Null);
am.getDSlice().getHoster().instantiateTo(rp.getNode(n2), Cause.Null);
new CMinMTTR().inject(ps, rp);
ReconfigurationPlan p = rp.solve(10, true);
Assert.assertNotNull(p);
Assert.assertTrue(am.getRelocationMethod().isInstantiatedTo(1));
Assert.assertEquals(p.getSize(), 3);
Model res = p.getResult();
// Check the VM has been relocated
Assert.assertEquals(res.getMapping().getRunningVMs(n1).size(), 0);
Assert.assertEquals(res.getMapping().getRunningVMs(n2).size(), 1);
Assert.assertNotNull(p);
// Check for the actions duration
for (Action a : p) {
if (a instanceof org.btrplace.plan.event.ForgeVM) {
Assert.assertEquals(a.getEnd() - a.getStart(), 3);
} else if (a instanceof org.btrplace.plan.event.ShutdownVM) {
Assert.assertEquals(a.getEnd() - a.getStart(), 1);
} else if (a instanceof org.btrplace.plan.event.BootVM) {
Assert.assertEquals(a.getEnd() - a.getStart(), 2);
} else {
Assert.fail();
}
}
}
use of org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR in project scheduler by btrplace.
the class ShutdownVMTest method testBasic.
@Test
public void testBasic() throws ContradictionException, 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);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(org.btrplace.plan.event.ShutdownVM.class, new ConstantActionDuration<>(5));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(map.getAllVMs(), new HashSet<>(), new HashSet<>(), new HashSet<>()).build();
rp.getNodeActions().get(0).getState().instantiateTo(1, Cause.Null);
ShutdownVM m = (ShutdownVM) 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.ShutdownVM a = (org.btrplace.plan.event.ShutdownVM) p.getActions().iterator().next();
Assert.assertEquals(vm1, a.getVM());
Assert.assertEquals(5, a.getEnd() - a.getStart());
}
Aggregations