use of org.btrplace.model.constraint.Preserve in project scheduler by btrplace.
the class CPreserveTest method testPreserveWithoutOverbook.
/*@Test
public void testGetMisplaced() {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Mapping map = mo.getMapping().on(n1, n2).run(n1, vm1, vm2).run(n2, vm3).get();
ShareableResource rc = new ShareableResource("cpu", 7, 7);
rc.setConsumption(vm1, 3);
rc.setConsumption(vm2, 3);
rc.setConsumption(vm3, 5);
Preserve p = new Preserve(vm1, "cpu", 5);
mo.attach(rc);
//Assert.assertEquals(SatConstraint.Sat.UNSATISFIED, p.isSatisfied(mo));
CPreserve cp = new CPreserve(p);
Instance i = new Instance(mo, Collections.emptyList(), new MinMTTR());
Set<VM> bads = cp.getMisPlacedVMs(i);
Assert.assertEquals(1, bads.size());
Assert.assertEquals(vm1, bads.iterator().next());
}*/
/**
* A preserve constraint asks for a minimum amount of resources but
* their is no overbook ratio so, the default value of 1 is used
* and vm1 or vm2 is moved to n2
*
* @throws org.btrplace.scheduler.SchedulerException
*/
@Test
public void testPreserveWithoutOverbook() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Mapping map = mo.getMapping().on(n1, n2).run(n1, vm1, vm2).run(n2, vm3);
ShareableResource rc = new ShareableResource("cpu", 10, 10);
rc.setCapacity(n1, 7);
rc.setConsumption(vm1, 3);
rc.setConsumption(vm2, 3);
rc.setConsumption(vm3, 5);
Preserve pr = new Preserve(vm2, "cpu", 5);
ChocoScheduler cra = new DefaultChocoScheduler();
mo.attach(rc);
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.addAll(Online.newOnline(map.getAllNodes()));
cstrs.add(pr);
ReconfigurationPlan p = cra.solve(mo, cstrs);
Assert.assertNotNull(p);
}
use of org.btrplace.model.constraint.Preserve in project scheduler by btrplace.
the class PreserveSplitterTest method simpleTest.
@Test
public void simpleTest() {
PreserveSplitter splitter = new PreserveSplitter();
List<Instance> instances = new ArrayList<>();
Model m0 = new DefaultModel();
VM v = m0.newVM(1);
m0.getMapping().addReadyVM(v);
m0.getMapping().addRunningVM(m0.newVM(2), m0.newNode(1));
Model m1 = new DefaultModel();
m1.getMapping().addReadyVM(m1.newVM(3));
m1.getMapping().addSleepingVM(m1.newVM(4), m1.newNode(2));
m1.getMapping().addRunningVM(m1.newVM(5), m1.newNode(3));
instances.add(new Instance(m0, new ArrayList<>(), new MinMTTR()));
instances.add(new Instance(m1, new ArrayList<>(), new MinMTTR()));
TIntIntHashMap index = Instances.makeVMIndex(instances);
Set<VM> all = new HashSet<>(m0.getMapping().getAllVMs());
all.addAll(m1.getMapping().getAllVMs());
// Only VMs in m0
Preserve single = new Preserve(v, "foo", 3);
Assert.assertTrue(splitter.split(single, null, instances, index, new TIntIntHashMap()));
Assert.assertTrue(instances.get(0).getSatConstraints().contains(single));
Assert.assertFalse(instances.get(1).getSatConstraints().contains(single));
}
Aggregations