use of org.btrplace.scheduler.choco.ReconfigurationProblem in project scheduler by btrplace.
the class CShareableResource method insertActions.
@Override
public boolean insertActions(ReconfigurationProblem r, Solution s, ReconfigurationPlan p) {
Mapping srcMapping = r.getSourceModel().getMapping();
// Encache the VM -> Action to ease the event injection.
Map<VM, Action> actions = new HashMap<>();
p.getActions().stream().filter(RunningVMPlacement.class::isInstance).map(a -> (RunningVMPlacement) a).forEach(a -> actions.put(destVM(a.getVM()), (Action) a));
for (VM vm : r.getFutureRunningVMs()) {
Slice dSlice = r.getVMAction(vm).getDSlice();
Node destNode = r.getNode(s.getIntVal(dSlice.getHoster()));
if (srcMapping.isRunning(vm) && destNode.equals(srcMapping.getVMLocation(vm))) {
// Was running and stay on the same node
// Check if the VM has been cloned
// TODO: might be too late depending on the symmetry breaking on the actions schedule
insertAllocateAction(p, vm, destNode, s.getIntVal(dSlice.getStart()));
} else {
VM dVM = destVM(vm);
Action a = actions.get(dVM);
if (a instanceof MigrateVM) {
// For a migrated VM, we allocate once the migration over
insertAllocateEvent(a, Action.Hook.POST, dVM);
} else {
// Resume or Boot VM
// As the VM was not running, we pre-allocate
insertAllocateEvent(a, Action.Hook.PRE, dVM);
}
}
}
return true;
}
use of org.btrplace.scheduler.choco.ReconfigurationProblem in project scheduler by btrplace.
the class BootVMTest method testBasics.
/**
* Just boot a VM on a 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.addReadyVM(vm1);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(org.btrplace.plan.event.BootVM.class, new ConstantActionDuration<>(5));
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);
BootVM m = (BootVM) rp.getVMActions().get(0);
Assert.assertEquals(vm1, m.getVM());
Assert.assertNull(m.getCSlice());
Assert.assertTrue(m.getDuration().isInstantiatedTo(5));
Assert.assertTrue(m.getState().isInstantiatedTo(1));
Assert.assertFalse(m.getDSlice().getHoster().isInstantiated());
Assert.assertFalse(m.getDSlice().getStart().isInstantiated());
Assert.assertFalse(m.getDSlice().getEnd().isInstantiated());
new CMinMTTR().inject(ps, rp);
ReconfigurationPlan p = rp.solve(0, false);
Assert.assertNotNull(p);
org.btrplace.plan.event.BootVM a = (org.btrplace.plan.event.BootVM) p.getActions().iterator().next();
Node dest = rp.getNode(m.getDSlice().getHoster().getValue());
Assert.assertEquals(vm1, a.getVM());
Assert.assertEquals(dest, a.getDestinationNode());
Assert.assertEquals(5, a.getEnd() - a.getStart());
}
use of org.btrplace.scheduler.choco.ReconfigurationProblem in project scheduler by btrplace.
the class KillVMTest method testBasics.
/**
* Test the action model with different action models.
*
* @throws ContradictionException
* @throws org.btrplace.scheduler.SchedulerException
*/
@Test
public void testBasics() throws ContradictionException, SchedulerException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
Node n1 = mo.newNode();
map.addOnlineNode(n1);
VM vm1 = mo.newVM();
map.addRunningVM(vm1, n1);
VM vm2 = mo.newVM();
map.addReadyVM(vm2);
VM vm3 = mo.newVM();
map.addSleepingVM(vm3, n1);
Set<VM> empty = new HashSet<>();
DurationEvaluators dev = new DurationEvaluators();
dev.register(org.btrplace.plan.event.KillVM.class, new ConstantActionDuration<>(1));
Parameters ps = new DefaultParameters();
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(empty, empty, empty, map.getAllVMs()).setParams(ps).build();
rp.getNodeAction(n1).getState().instantiateTo(rp.getVM(vm1), Cause.Null);
// Common stuff
for (VM vm : map.getAllVMs()) {
KillVM m = (KillVM) rp.getVMAction(vm);
Assert.assertEquals(vm, m.getVM());
Assert.assertTrue(m.getState().isInstantiatedTo(0));
Assert.assertNull(m.getDSlice());
Assert.assertTrue(m.getDuration().isInstantiatedTo(1));
Assert.assertTrue(m.getStart().isInstantiatedTo(0));
Assert.assertTrue(m.getEnd().isInstantiatedTo(1));
}
// The waiting and the sleeping VM have no CSlice
Assert.assertNull(rp.getVMAction(vm2).getCSlice());
Assert.assertNull(rp.getVMAction(vm3).getCSlice());
// The running VM has a CSlice
Assert.assertNotNull(rp.getVMAction(vm1).getCSlice());
Assert.assertTrue(rp.getVMAction(vm1).getCSlice().getHoster().isInstantiatedTo(rp.getNode(n1)));
new CMinMTTR().inject(ps, rp);
ReconfigurationPlan p = rp.solve(0, false);
Assert.assertNotNull(p);
for (Action a : p) {
if (a instanceof org.btrplace.plan.event.KillVM) {
org.btrplace.plan.event.KillVM vma = (org.btrplace.plan.event.KillVM) a;
Assert.assertEquals(1, a.getEnd());
Assert.assertEquals(0, a.getStart());
if (vma.getVM().equals(vm1) || vma.getVM().equals(vm3)) {
Assert.assertEquals(vma.getNode(), n1);
} else if (vma.getVM().equals(vm2)) {
Assert.assertNull(vma.getNode());
} else {
Assert.fail();
}
}
}
}
use of org.btrplace.scheduler.choco.ReconfigurationProblem 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.ReconfigurationProblem 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));
}
Aggregations