use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class DefaultChocoSchedulerTest method testGetStatisticsWithNoSolution.
@Test
public void testGetStatisticsWithNoSolution() throws SchedulerException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
VM v = mo.newVM();
Node n = mo.newNode();
map.addReadyVM(v);
map.addOfflineNode(n);
ChocoScheduler cra = new DefaultChocoScheduler();
ReconfigurationPlan p = cra.solve(mo, Arrays.asList(new Running(v), new Offline(n)));
Assert.assertNull(p);
SolvingStatistics stats = cra.getStatistics();
Assert.assertNotNull(stats);
Assert.assertTrue(stats.getSolutions().isEmpty());
// Assert.assertFalse(stats.hitTimeout());
}
use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testMinimize.
/**
* Test a minimization problem: use the minimum number of nodes.
*
* @throws org.btrplace.scheduler.SchedulerException
*/
@Test
public void testMinimize() throws SchedulerException {
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);
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 testMaintainState.
@Test
public void testMaintainState() 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();
Node n1 = mo.newNode();
Mapping map = mo.getMapping();
map.addOnlineNode(n1);
map.addRunningVM(vm1, n1);
map.addReadyVM(vm2);
map.addSleepingVM(vm3, n1);
map.addReadyVM(vm5);
ShareableResource rc = new ShareableResource("foo");
rc.setConsumption(vm1, 5);
rc.setConsumption(vm2, 7);
mo.getAttributes().put(vm4, "template", "small");
mo.attach(rc);
ReconfigurationProblem rp = new DefaultReconfigurationProblem(mo, new DefaultParameters(), Collections.singleton(vm4), Collections.singleton(vm5), Collections.singleton(vm1), Collections.emptySet(), map.getAllVMs());
Assert.assertTrue(rp.getFutureSleepingVMs().contains(vm1));
Assert.assertTrue(rp.getFutureReadyVMs().contains(vm2));
Assert.assertTrue(rp.getFutureSleepingVMs().contains(vm3));
Assert.assertTrue(rp.getFutureReadyVMs().contains(vm4));
Assert.assertTrue(rp.getFutureRunningVMs().contains(vm5));
}
use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testSimplestInstantiation.
/*private static Model defaultModel() {
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);
return mo;
} */
/**
* Just test the state definition of the actions.
*
* @throws org.btrplace.scheduler.SchedulerException should not occur
*/
@Test
public void testSimplestInstantiation() 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);
VM vm7 = mo.newVM();
Set<VM> toRun = new HashSet<>();
Set<VM> toWait = new HashSet<>();
toWait.add(vm6);
toWait.add(vm7);
toRun.add(vm5);
toRun.add(vm4);
toRun.add(vm1);
mo.getAttributes().put(vm7, "template", "small");
Parameters ps = new DefaultParameters();
DurationEvaluators dEval = ps.getDurationEvaluators();
DefaultReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(toWait, toRun, Collections.singleton(vm3), Collections.singleton(vm2)).setParams(ps).build();
Assert.assertEquals(dEval, rp.getDurationEvaluators());
Assert.assertEquals(rp.getFutureReadyVMs(), toWait);
Assert.assertEquals(rp.getFutureRunningVMs(), toRun);
Assert.assertEquals(rp.getFutureSleepingVMs(), Collections.singleton(vm3));
Assert.assertEquals(rp.getFutureKilledVMs(), Collections.singleton(vm2));
Assert.assertEquals(rp.getVMs().size(), 7);
Assert.assertEquals(rp.getNodes().size(), 3);
Assert.assertEquals(rp.getManageableVMs().size(), rp.getVMs().size(), rp.getManageableVMs().toString());
Assert.assertTrue(rp.getStart().isInstantiated() && rp.getStart().getValue() == 0);
// Test the index values of the nodes and the VMs.
for (int i = 0; i < rp.getVMs().size(); i++) {
VM vm = rp.getVM(i);
Assert.assertEquals(i, rp.getVM(vm));
}
Assert.assertEquals(rp.getVM(mo.newVM()), -1);
for (int i = 0; i < rp.getNodes().size(); i++) {
Node n = rp.getNode(i);
Assert.assertEquals(i, rp.getNode(n));
}
Assert.assertEquals(rp.getNode(mo.newNode()), -1);
}
use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testVMStayRunning.
@Test
public void testVMStayRunning() 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);
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(RelocatableVM.class, a.getClass());
}
Aggregations