use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testTimeout.
/**
* Test the report of a timeout.
*/
@Test(expectedExceptions = { UnstatableProblemException.class })
public void testTimeout() throws UnstatableProblemException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
for (int i = 0; i < 10; i++) {
Node n = mo.newNode();
VM vm = mo.newVM();
map.addOnlineNode(n);
map.addRunningVM(vm, n);
}
Parameters ps = new DefaultParameters();
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).build();
Solver s = rp.getSolver();
IntVar nbNodes = rp.getModel().intVar("nbNodes", 1, map.getAllNodes().size(), true);
Stream<Slice> dSlices = rp.getVMActions().stream().filter(t -> t.getDSlice() != null).map(VMTransition::getDSlice);
IntVar[] hosters = dSlices.map(Slice::getHoster).toArray(IntVar[]::new);
rp.getModel().post(rp.getModel().atMostNValues(hosters, nbNodes, true));
rp.setObjective(true, nbNodes);
// 1 ms
rp.getSolver().limitTime(1);
// -1 will be ignored as it is a negative value (assumed no timeout)
ReconfigurationPlan plan = rp.solve(-1, true);
Assert.assertNotNull(plan);
Assert.assertEquals(s.getMeasures().getSolutionCount(), 1);
Mapping dst = plan.getResult().getMapping();
Assert.assertEquals(usedNodes(dst), 1);
}
use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testWaitingVMToRun.
@Test
public void testWaitingVMToRun() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
VM vm4 = mo.newVM();
VM vm5 = mo.newVM();
VM vm6 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
Mapping map = mo.getMapping();
map.addOnlineNode(n1);
map.addOnlineNode(n2);
map.addOfflineNode(n3);
map.addRunningVM(vm1, n1);
map.addRunningVM(vm2, n1);
map.addRunningVM(vm3, n2);
map.addSleepingVM(vm4, n2);
map.addReadyVM(vm5);
map.addReadyVM(vm6);
Mapping m = mo.getMapping();
m.addReadyVM(vm1);
DefaultReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(new HashSet<>(), Collections.singleton(vm1), new HashSet<>(), new HashSet<>()).build();
VMTransition a = rp.getVMActions().get(0);
Assert.assertEquals(a, rp.getVMAction(vm1));
Assert.assertEquals(BootVM.class, a.getClass());
}
use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testNodeOn.
@Test
public void testNodeOn() throws SchedulerException {
Model mo = new DefaultModel();
Mapping m = mo.getMapping();
Node n1 = mo.newNode();
m.addOnlineNode(n1);
DefaultReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(new HashSet<>(), new HashSet<>(), new HashSet<>(), new HashSet<>()).build();
NodeTransition a = rp.getNodeActions().get(0);
Assert.assertEquals(a, rp.getNodeAction(n1));
Assert.assertEquals(ShutdownableNode.class, a.getClass());
}
use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testVMToWaiting.
@Test
public void testVMToWaiting() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
VM vm4 = mo.newVM();
VM vm5 = mo.newVM();
VM vm6 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
Mapping map = mo.getMapping();
map.addOnlineNode(n1);
map.addOnlineNode(n2);
map.addOfflineNode(n3);
// map.addRunningVM(vm1, n1);
map.addRunningVM(vm2, n1);
map.addRunningVM(vm3, n2);
map.addSleepingVM(vm4, n2);
map.addReadyVM(vm5);
map.addReadyVM(vm6);
mo.getAttributes().put(vm1, "template", "small");
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(Collections.singleton(vm1), new HashSet<>(), new HashSet<>(), new HashSet<>()).build();
VMTransition a = rp.getVMActions().get(rp.getVM(vm1));
Assert.assertEquals(a, rp.getVMAction(vm1));
Assert.assertEquals(ForgeVM.class, a.getClass());
}
use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testVMsToKill.
@Test
public void testVMsToKill() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
VM vm4 = mo.newVM();
VM vm5 = mo.newVM();
VM vm6 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
Mapping map = mo.getMapping();
map.addOnlineNode(n1);
map.addOnlineNode(n2);
map.addOfflineNode(n3);
map.addRunningVM(vm1, n1);
map.addRunningVM(vm2, n1);
map.addRunningVM(vm3, n2);
map.addSleepingVM(vm4, n2);
map.addReadyVM(vm5);
map.addReadyVM(vm6);
Mapping m = mo.getMapping();
m.addOnlineNode(n1);
m.addRunningVM(vm1, n1);
m.addSleepingVM(vm2, n1);
m.addReadyVM(vm3);
DefaultReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(new HashSet<>(), new HashSet<>(), new HashSet<>(), m.getAllVMs()).build();
for (VMTransition a : rp.getVMActions()) {
Assert.assertEquals(a.getClass(), KillVM.class);
}
}
Aggregations