use of org.btrplace.model.DefaultModel in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testViewAddition.
@Test
public void testViewAddition() throws SchedulerException {
Model mo = new DefaultModel();
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).build();
MockCView view = new MockCView();
Assert.assertTrue(rp.addView(view));
Assert.assertEquals(rp.getView(view.getIdentifier()), view);
Assert.assertFalse(rp.addView(view));
}
use of org.btrplace.model.DefaultModel in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testVMCounting.
/**
* Check the consistency between the variables counting the number of VMs on
* each node, and the placement variable.
*
* @throws org.btrplace.scheduler.SchedulerException
* @throws ContradictionException
*/
@Test
public void testVMCounting() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
Node n3 = mo.newNode();
Node n2 = mo.newNode();
Mapping map = mo.getMapping();
for (int i = 0; i < 7; i++) {
VM v = mo.newVM();
map.addReadyVM(v);
}
map.addOnlineNode(n3);
map.addOnlineNode(n2);
Parameters ps = new DefaultParameters();
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(new HashSet<>(), map.getAllVMs(), new HashSet<>(), new HashSet<>()).build();
// Restrict the capacity to 5 at most
for (IntVar capa : rp.getNbRunningVMs()) {
capa.updateUpperBound(5, Cause.Null);
}
new CMinMTTR().inject(ps, rp);
ReconfigurationPlan p = rp.solve(-1, false);
Assert.assertNotNull(p);
// Check consistency between the counting and the hoster variables
int[] counts = new int[map.getAllNodes().size()];
for (Node n : map.getOnlineNodes()) {
int nIdx = rp.getNode(n);
counts[nIdx] = rp.getNbRunningVMs().get(nIdx).getValue();
}
for (VM vm : rp.getFutureRunningVMs()) {
VMTransition vmo = rp.getVMActions().get(rp.getVM(vm));
int on = vmo.getDSlice().getHoster().getValue();
counts[on]--;
}
for (int count : counts) {
Assert.assertEquals(count, 0);
}
}
use of org.btrplace.model.DefaultModel in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testManageableVMs.
@Test
public void testManageableVMs() 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);
Set<VM> runnings = new HashSet<>(map.getRunningVMs());
runnings.add(vm6);
runnings.add(vm5);
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(Collections.emptySet(), runnings, map.getSleepingVMs(), Collections.emptySet()).setManageableVMs(map.getRunningVMs(n1)).build();
/*
vm1: running -> running
vm2: running-> running
vm3: running -> running
vm4: sleeping -> sleeping
vm5: ready -> running
vm6: ready -> running
* manageable_runnings: vm1, vm2
* manageable: vm1, vm2, vm5, vm6 (with ids: vm#0, vm#1, vm#4, vm#5)
*/
Set<VM> manageable = rp.getManageableVMs();
Assert.assertEquals(manageable.size(), 4, manageable.toString());
Assert.assertTrue(manageable.containsAll(Arrays.asList(vm6, vm5, vm1, vm2)));
// Check the action model that has been used for each of the VM.
for (VM vm : map.getAllVMs()) {
Assert.assertEquals(manageable.contains(vm), rp.getVMAction(vm).isManaged());
}
}
use of org.btrplace.model.DefaultModel in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testVMToShutdown.
@Test
public void testVMToShutdown() 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(Collections.singleton(vm1), new HashSet<>(), new HashSet<>(), new HashSet<>()).build();
VMTransition a = rp.getVMActions().get(0);
Assert.assertEquals(a, rp.getVMAction(vm1));
Assert.assertEquals(ShutdownVM.class, a.getClass());
}
use of org.btrplace.model.DefaultModel in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testVMStaySleeping.
@Test
public void testVMStaySleeping() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
Node n1 = mo.newNode();
mo.getMapping().addOnlineNode(n1);
mo.getMapping().addSleepingVM(vm1, n1);
DefaultReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(new HashSet<>(), new HashSet<>(), Collections.singleton(vm1), new HashSet<>()).build();
VMTransition a = rp.getVMActions().get(0);
Assert.assertEquals(a, rp.getVMAction(vm1));
Assert.assertEquals(StayAwayVM.class, a.getClass());
}
Aggregations